diff --git a/arch/arm/src/nrf52/nrf52_gpiote.c b/arch/arm/src/nrf52/nrf52_gpiote.c index e3a5b6e21d..f2bf33855a 100644 --- a/arch/arm/src/nrf52/nrf52_gpiote.c +++ b/arch/arm/src/nrf52/nrf52_gpiote.c @@ -432,6 +432,61 @@ void nrf52_gpiote_set_ch_event(uint32_t pinset, int channel, leave_critical_section(flags); } +/**************************************************************************** + * Name: nrf52_gpiote_set_event + * + * Description: + * Configures a GPIOTE channel in EVENT mode, assigns it to a given pin + * and sets a handler for the first availalbe GPIOTE channel + * + * Input Parameters: + * - pinset: GPIO pin configuration + * - risingedge: Enables interrupt on rising edges + * - fallingedge: Enables interrupt on falling edges + * - func: When non-NULL, generate interrupt + * - arg: Argument passed to the interrupt callback + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. + * + ****************************************************************************/ + +int nrf52_gpiote_set_event(uint32_t pinset, + bool risingedge, bool fallingedge, + xcpt_t func, void *arg) +{ + irqstate_t flags; + int ret = -ENOMEM; + int i = 0; + + flags = enter_critical_section(); + + /* Get free channel */ + + for (i = 0; i < GPIOTE_CHANNELS; i++) + { + if (g_gpiote_ch_callbacks[i].callback == NULL) + { + /* Configure channel */ + + nrf52_gpiote_set_ch_event(pinset, i, + risingedge, fallingedge, + func, arg); + + /* Return the channel index */ + + ret = i; + + break; + } + } + + leave_critical_section(flags); + + return ret; +} + /**************************************************************************** * Name: nrf52_gpio_set_task * diff --git a/arch/arm/src/nrf52/nrf52_gpiote.h b/arch/arm/src/nrf52/nrf52_gpiote.h index a7f61769b0..49a1bd4d76 100644 --- a/arch/arm/src/nrf52/nrf52_gpiote.h +++ b/arch/arm/src/nrf52/nrf52_gpiote.h @@ -69,6 +69,30 @@ void nrf52_gpiote_set_ch_event(uint32_t pinset, int channel, bool risingedge, bool fallingedge, xcpt_t func, void *arg); +/**************************************************************************** + * Name: nrf52_gpiote_set_event + * + * Description: + * Configures a GPIOTE channel in EVENT mode, assigns it to a given pin + * and sets a handler for the first availalbe GPIOTE channel + * + * Input Parameters: + * - pinset: GPIO pin configuration + * - risingedge: Enables interrupt on rising edges + * - fallingedge: Enables interrupt on falling edges + * - func: When non-NULL, generate interrupt + * - arg: Argument passed to the interrupt callback + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. + * + ****************************************************************************/ + +int nrf52_gpiote_set_event(uint32_t pinset, + bool risingedge, bool fallingedge, + xcpt_t func, void *arg); + #ifdef CONFIG_NRF52_PER_PIN_INTERRUPTS /**************************************************************************** * Name: nrf52_gpiote_set_pin_event