2424
2525#if IS_ENABLED (CONFIG_PTT_CLK_OUT )
2626#include <nrfx_gpiote.h>
27+ #include <gpiote_nrfx.h>
2728#endif /* IS_ENABLED(CONFIG_PTT_CLK_OUT) */
2829
2930#if defined(CONFIG_PTT_CACHE_MGMT )
@@ -52,26 +53,18 @@ LOG_MODULE_REGISTER(periph);
5253static nrfx_timer_t clk_timer = NRFX_TIMER_INSTANCE (NRF_TIMER_INST_GET (PTT_CLK_TIMER ));
5354
5455#define GPIOTE_NODE (gpio_node ) DT_PHANDLE(gpio_node, gpiote_instance)
55- #define GPIOTE_INST_AND_COMMA (gpio_node ) \
56- [DT_PROP(gpio_node, port)] = \
57- NRFX_GPIOTE_INSTANCE(DT_PROP(GPIOTE_NODE(gpio_node), instance)),
56+ #define GPIOTE_INST_AND_COMMA (gpio_node ) [DT_PROP(gpio_node, port)] = \
57+ COND_CODE_1(DT_NODE_HAS_PROP(gpio_node, gpiote_instance), \
58+ (&GPIOTE_NRFX_INST_BY_NODE(GPIOTE_NODE(gpio_node))), \
59+ (NULL)),
5860
59- #define COND_GPIOTE_INST_AND_COMMA (gpio_node ) \
60- COND_CODE_1(DT_NODE_HAS_PROP(gpio_node, gpiote_instance), \
61- (GPIOTE_INST_AND_COMMA(gpio_node)), \
62- ())
63-
64- static const nrfx_gpiote_t gpiote_inst [GPIO_COUNT ] = {
65- DT_FOREACH_STATUS_OKAY (nordic_nrf_gpio , COND_GPIOTE_INST_AND_COMMA )
61+ static nrfx_gpiote_t * const gpiote_inst [GPIO_COUNT ] = {
62+ DT_FOREACH_STATUS_OKAY (nordic_nrf_gpio , GPIOTE_INST_AND_COMMA )
6663};
6764
68- #define NRF_GPIOTE_FOR_GPIO (idx ) & gpiote_inst[idx]
69- #define NRF_GPIOTE_FOR_PSEL (psel ) & gpiote_inst[psel >> 5 ]
65+ #define NRF_GPIOTE_FOR_GPIO (idx ) gpiote_inst[idx]
66+ #define NRF_GPIOTE_FOR_PSEL (psel ) gpiote_inst[NRF_PIN_NUMBER_TO_PORT( psel) ]
7067
71- static inline bool gpiote_is_valid (const nrfx_gpiote_t * gpiote )
72- {
73- return gpiote -> p_reg != NULL ;
74- }
7568#endif /* IS_ENABLED(CONFIG_PTT_CLK_OUT) */
7669
7770#define CLOCK_NODE DT_INST(0, nordic_nrf_clock)
@@ -100,7 +93,7 @@ void periph_init(void)
10093 int ret ;
10194
10295#if IS_ENABLED (CONFIG_PTT_CLK_OUT )
103- nrfx_err_t err_code ;
96+ int err_code ;
10497
10598 uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET (clk_timer .p_reg );
10699 nrfx_timer_config_t clk_timer_cfg = NRFX_TIMER_DEFAULT_CONFIG (base_frequency );
@@ -109,15 +102,15 @@ void periph_init(void)
109102 NRFX_ASSERT (err_code );
110103
111104 for (int i = 0 ; i < GPIO_COUNT ; ++ i ) {
112- const nrfx_gpiote_t * gpiote = NRF_GPIOTE_FOR_GPIO (i );
105+ nrfx_gpiote_t * gpiote = NRF_GPIOTE_FOR_GPIO (i );
113106
114- if (! gpiote_is_valid ( gpiote ) ) {
107+ if (gpiote == NULL ) {
115108 continue ;
116109 }
117110
118111 if (!nrfx_gpiote_init_check (gpiote )) {
119112 err_code = nrfx_gpiote_init (gpiote , 0 );
120- NRFX_ASSERT (err_code );
113+ __ASSERT_NO_MSG (err_code == 0 );
121114 }
122115 }
123116#endif
@@ -144,10 +137,10 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
144137#if IS_ENABLED (CONFIG_PTT_CLK_OUT )
145138 uint32_t compare_evt_addr ;
146139 uint32_t tep ;
147- nrfx_err_t err ;
148- const nrfx_gpiote_t * gpiote = NRF_GPIOTE_FOR_PSEL (pin );
140+ int err ;
141+ nrfx_gpiote_t * gpiote = NRF_GPIOTE_FOR_PSEL (pin );
149142
150- if (!nrf_gpio_pin_present_check (pin ) || ! gpiote_is_valid (gpiote )) {
143+ if (!nrf_gpio_pin_present_check (pin ) || (gpiote == NULL )) {
151144 return false;
152145 }
153146
@@ -156,8 +149,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
156149 NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK , false);
157150
158151 err = nrfx_gpiote_channel_alloc (gpiote , & task_channel );
159- if (err != NRFX_SUCCESS ) {
160- LOG_ERR ("nrfx_gpiote_channel_alloc error: %08x " , err );
152+ if (err != 0 ) {
153+ LOG_ERR ("nrfx_gpiote_channel_alloc error: %d " , err );
161154 return false;
162155 }
163156
@@ -172,8 +165,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
172165 * CLR will turn it off and OUT will toggle it.
173166 */
174167 err = nrfx_gpiote_output_configure (gpiote , pin , & config , & out_config );
175- if (err != NRFX_SUCCESS ) {
176- LOG_ERR ("nrfx_gpiote_output_configure error: %08x " , err );
168+ if (err != 0 ) {
169+ LOG_ERR ("nrfx_gpiote_output_configure error: %d " , err );
177170 return false;
178171 }
179172
@@ -206,8 +199,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
206199 nrfx_gpiote_pin_uninit (gpiote , pin );
207200 err = nrfx_gpiote_channel_free (gpiote , task_channel );
208201
209- if (err != NRFX_SUCCESS ) {
210- LOG_ERR ("Failed to disable GPIOTE channel, error: %08x " , err );
202+ if (err != 0 ) {
203+ LOG_ERR ("Failed to disable GPIOTE channel, error: %d " , err );
211204 return false;
212205 }
213206 }
0 commit comments