arch/nrf52/gpiote: add an interface automatically selecting a free GPIOTE channel for pin interrupts

This commit is contained in:
raiden00pl 2023-03-14 14:19:27 +01:00 committed by Alan Carvalho de Assis
parent bf531fa24a
commit b15244d4b2
2 changed files with 79 additions and 0 deletions

View File

@ -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
*

View File

@ -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