66
77#include <zephyr/drivers/uart.h>
88#include <zephyr/drivers/gpio.h>
9+ #include <zephyr/drivers/gpio/gpio_nrf.h>
910#include <hal/nrf_gpio.h>
1011#include <hal/nrf_gpiote.h>
1112#include <nrfx_gpiote.h>
13+ #include <gpiote_nrfx.h>
1214#include <zephyr/logging/log.h>
1315#include <zephyr/sys/onoff.h>
1416#include <zephyr/drivers/clock_control/nrf_clock_control.h>
@@ -132,18 +134,18 @@ static inline const struct lpuart_config *get_dev_config(const struct device *de
132134}
133135
134136#define GPIOTE_NODE (gpio_node ) DT_PHANDLE(gpio_node, gpiote_instance)
135- #define GPIOTE_INST_AND_COMMA (gpio_node ) \
136- IF_ENABLED (DT_NODE_HAS_PROP(gpio_node, gpiote_instance), ( \
137- [DT_PROP( gpio_node, port)] = \
138- NRFX_GPIOTE_INSTANCE(DT_PROP(GPIOTE_NODE(gpio_node), instance)),))
137+ #define GPIOTE_INST_AND_COMMA (gpio_node ) [DT_PROP(gpio_node, port)] = \
138+ COND_CODE_1 (DT_NODE_HAS_PROP(gpio_node, gpiote_instance), \
139+ (&GPIOTE_NRFX_INST_BY_NODE(GPIOTE_NODE( gpio_node))), \
140+ (NULL)),
139141
140- static const nrfx_gpiote_t * get_gpiote (nrfx_gpiote_pin_t pin )
142+ static nrfx_gpiote_t * get_gpiote (nrfx_gpiote_pin_t pin )
141143{
142- static const nrfx_gpiote_t gpiote [GPIO_COUNT ] = {
144+ static nrfx_gpiote_t * const gpiote_per_port [GPIO_COUNT ] = {
143145 DT_FOREACH_STATUS_OKAY (nordic_nrf_gpio , GPIOTE_INST_AND_COMMA )
144146 };
145147
146- return & gpiote [ pin >> 5 ];
148+ return gpiote_per_port [ NRF_PIN_NUMBER_TO_PORT ( pin ) ];
147149}
148150
149151/* Called when uart transfer is finished to indicate to the receiver that it
@@ -194,7 +196,7 @@ static void req_pin_arm(struct lpuart_data *data)
194196static int req_pin_init (struct lpuart_data * data , nrfx_gpiote_pin_t pin )
195197{
196198 uint8_t ch ;
197- nrfx_err_t err ;
199+ int err ;
198200 nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLDOWN ;
199201 nrfx_gpiote_trigger_config_t trigger_config = {
200202 .trigger = NRFX_GPIOTE_TRIGGER_HITOLO ,
@@ -211,13 +213,13 @@ static int req_pin_init(struct lpuart_data *data, nrfx_gpiote_pin_t pin)
211213 };
212214
213215 err = nrfx_gpiote_channel_alloc (get_gpiote (pin ), & ch );
214- if (err != NRFX_SUCCESS ) {
215- return - ENOMEM ;
216+ if (err < 0 ) {
217+ return err ;
216218 }
217219
218220 err = nrfx_gpiote_input_configure (get_gpiote (pin ), pin , & input_config );
219- if (err != NRFX_SUCCESS ) {
220- return - EINVAL ;
221+ if (err < 0 ) {
222+ return err ;
221223 }
222224
223225 data -> req_pin = pin ;
@@ -238,7 +240,7 @@ static void rdy_pin_suspend(struct lpuart_data *data)
238240
239241static int rdy_pin_init (struct lpuart_data * data , nrfx_gpiote_pin_t pin )
240242{
241- nrfx_err_t err ;
243+ int err ;
242244 nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_NOPULL ;
243245 nrfx_gpiote_handler_config_t handler_config = {
244246 .handler = rdy_pin_handler ,
@@ -251,14 +253,14 @@ static int rdy_pin_init(struct lpuart_data *data, nrfx_gpiote_pin_t pin)
251253 };
252254
253255 err = nrfx_gpiote_channel_alloc (get_gpiote (pin ), & data -> rdy_ch );
254- if (err != NRFX_SUCCESS ) {
255- return - ENOMEM ;
256+ if (err < 0 ) {
257+ return err ;
256258 }
257259
258260 err = nrfx_gpiote_input_configure (get_gpiote (pin ), pin , & input_config );
259- if (err != NRFX_SUCCESS ) {
260- LOG_ERR ("err:%08x " , err );
261- return - EINVAL ;
261+ if (err < 0 ) {
262+ LOG_ERR ("err: %d " , err );
263+ return err ;
262264 }
263265
264266 data -> rdy_pin = pin ;
@@ -270,7 +272,7 @@ static int rdy_pin_init(struct lpuart_data *data, nrfx_gpiote_pin_t pin)
270272/* Pin activated to detect high state (using SENSE). */
271273static void rdy_pin_idle (struct lpuart_data * data )
272274{
273- nrfx_err_t err ;
275+ int err ;
274276 nrfx_gpiote_trigger_config_t trigger_config = {
275277 .trigger = NRFX_GPIOTE_TRIGGER_HIGH
276278 };
@@ -279,10 +281,10 @@ static void rdy_pin_idle(struct lpuart_data *data)
279281 .p_trigger_config = & trigger_config ,
280282 .p_handler_config = NULL
281283 };
282- const nrfx_gpiote_t * gpiote = get_gpiote (data -> rdy_pin );
284+ nrfx_gpiote_t * gpiote = get_gpiote (data -> rdy_pin );
283285
284286 err = nrfx_gpiote_input_configure (gpiote , data -> rdy_pin , & input_config );
285- __ASSERT (err == NRFX_SUCCESS , "Unexpected err: %08x/%d" , err , err );
287+ __ASSERT (err == 0 , "Unexpected err: %d" , err );
286288
287289 nrfx_gpiote_trigger_enable (gpiote , data -> rdy_pin , true);
288290}
@@ -295,7 +297,7 @@ static void rdy_pin_idle(struct lpuart_data *data)
295297 */
296298static bool rdy_pin_blink (struct lpuart_data * data )
297299{
298- nrfx_err_t err ;
300+ int err ;
299301 nrfx_gpiote_trigger_config_t trigger_config = {
300302 .trigger = NRFX_GPIOTE_TRIGGER_HITOLO ,
301303 .p_in_channel = & data -> rdy_ch
@@ -307,14 +309,14 @@ static bool rdy_pin_blink(struct lpuart_data *data)
307309 };
308310 const nrf_gpio_pin_dir_t dir_in = NRF_GPIO_PIN_DIR_INPUT ;
309311 const nrf_gpio_pin_dir_t dir_out = NRF_GPIO_PIN_DIR_OUTPUT ;
310- const nrfx_gpiote_t * gpiote = get_gpiote (data -> rdy_pin );
312+ nrfx_gpiote_t * gpiote = get_gpiote (data -> rdy_pin );
311313 bool ret ;
312314
313315 /* Drive low for a moment */
314316 nrf_gpio_reconfigure (data -> rdy_pin , & dir_out , NULL , NULL , NULL , NULL );
315317
316318 err = nrfx_gpiote_input_configure (gpiote , data -> rdy_pin , & input_config );
317- __ASSERT (err == NRFX_SUCCESS , "Unexpected err: %08x/%d" , err , err );
319+ __ASSERT (err == 0 , "Unexpected err: %d" , err );
318320
319321 nrfx_gpiote_trigger_enable (gpiote , data -> rdy_pin , true);
320322
0 commit comments