From 50b060ab323b810874a85b7097289af1129dfe6c Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Tue, 11 Oct 2016 12:29:06 +0300 Subject: [PATCH] really fix attachInterrupt to work on either core --- cores/esp32/esp32-hal-gpio.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 15e33da7..e879afab 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -187,16 +187,23 @@ static void IRAM_ATTR __onPinInterrupt(void *arg) extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) { static bool interrupt_initialized = false; + static int core_id = 0; + if(!interrupt_initialized) { interrupt_initialized = true; + core_id = xPortGetCoreID(); ESP_INTR_DISABLE(ETS_GPIO_INUM); - intr_matrix_set(xPortGetCoreID(), ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM); + intr_matrix_set(core_id, ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM); xt_set_interrupt_handler(ETS_GPIO_INUM, &__onPinInterrupt, NULL); ESP_INTR_ENABLE(ETS_GPIO_INUM); } __pinInterruptHandlers[pin] = userFunc; ESP_INTR_DISABLE(ETS_GPIO_INUM); - GPIO.pin[pin].int_ena = 1; + if(core_id) { //APP_CPU + GPIO.pin[pin].int_ena = 1; + } else { //PRO_CPU + GPIO.pin[pin].int_ena = 4; + } GPIO.pin[pin].int_type = intr_type; ESP_INTR_ENABLE(ETS_GPIO_INUM); }