gpio_interrupt_handler() can now be overriden

This commit is contained in:
UncleRus 2016-11-30 02:54:07 +05:00
parent a61af52d96
commit c3b6aff41d
2 changed files with 33 additions and 3 deletions

View file

@ -58,7 +58,7 @@ void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep)
static gpio_interrupt_handler_t gpio_interrupt_handlers[16] = { 0 };
static void IRAM _gpio_intr_internal_handler(void)
void __attribute__((weak)) IRAM gpio_interrupt_handler(void)
{
uint32_t status_reg = GPIO.STATUS;
GPIO.STATUS_CLEAR = status_reg;
@ -82,8 +82,8 @@ void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int_type, g
gpio_interrupt_handlers[gpio_num] = handler;
GPIO.CONF[gpio_num] = SET_FIELD(GPIO.CONF[gpio_num], GPIO_CONF_INTTYPE, int_type);
if(int_type != GPIO_INTTYPE_NONE && handler) {
_xt_isr_attach(INUM_GPIO, _gpio_intr_internal_handler);
if(int_type != GPIO_INTTYPE_NONE) {
_xt_isr_attach(INUM_GPIO, gpio_interrupt_handler);
_xt_isr_unmask(1<<INUM_GPIO);
}
}

View file

@ -129,6 +129,36 @@ static inline bool gpio_read(const uint8_t gpio_num)
typedef void (* gpio_interrupt_handler_t)(uint8_t gpio_num);
/*
* You can implement GPIO interrupt handlers in either of two ways:
* - Implement handler and use it with the gpio_set_interrupt()
*
* Example:
*
* void my_intr_handler(uint8_t gpio_num) {
* // Do something when GPIO changes
* }
* ...
* gpio_set_interrupt(MY_GPIO_NUM, GPIO_INTTYPE_EDGE_ANY, my_intr_handler);
*
* OR
*
* - Implement a single function named gpio_interrupt_handler(). This
* will need to manually check GPIO.STATUS and clear any status
* bits after handling interrupts. This gives you full control, but
* you can't combine it with the first approach.
*
* Example:
*
* void IRAM gpio_interrupt_handler(void) {
* // check GPIO.STATUS
* // write GPIO.STATUS_CLEAR
* // Do something when GPIO changes
* }
* ...
* gpio_set_interrupt(MY_GPIO_NUM, GPIO_INTTYPE_EDGE_ANY, NULL);
*/
/* Set the interrupt type for a given pin
*
* If int_type is not GPIO_INTTYPE_NONE, the gpio_interrupt_handler will be