From 7991161f06746af770405578de4d21984cfd5a7d Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Thu, 28 Sep 2017 12:27:10 +0800 Subject: [PATCH] Change Pin Interrupt Allocator --- cores/esp32/esp32-hal-gpio.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cores/esp32/esp32-hal-gpio.c b/cores/esp32/esp32-hal-gpio.c index 6b2f9cc8..0db7b43c 100644 --- a/cores/esp32/esp32-hal-gpio.c +++ b/cores/esp32/esp32-hal-gpio.c @@ -24,8 +24,6 @@ #include "soc/gpio_struct.h" #include "soc/rtc_io_reg.h" -#define ETS_GPIO_INUM 12 - const int8_t esp32_adc2gpio[20] = {36, -1, -1, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ @@ -193,6 +191,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin) return 0; } +static intr_handle_t gpio_intr_handle = NULL; static void IRAM_ATTR __onPinInterrupt(void *arg) { @@ -229,38 +228,29 @@ 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(core_id, ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM); - xt_set_interrupt_handler(ETS_GPIO_INUM, &__onPinInterrupt, NULL); - ESP_INTR_ENABLE(ETS_GPIO_INUM); + esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle); } __pinInterruptHandlers[pin] = userFunc; - //lock gpio - ESP_INTR_DISABLE(ETS_GPIO_INUM); - if(core_id) { //APP_CPU + esp_intr_disable(gpio_intr_handle); + if(esp_intr_get_cpu(gpio_intr_handle)) { //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); - //unlock gpio + esp_intr_enable(gpio_intr_handle); } extern void __detachInterrupt(uint8_t pin) { - //lock gpio - ESP_INTR_DISABLE(ETS_GPIO_INUM); + esp_intr_disable(gpio_intr_handle); __pinInterruptHandlers[pin] = NULL; GPIO.pin[pin].int_ena = 0; GPIO.pin[pin].int_type = 0; - ESP_INTR_ENABLE(ETS_GPIO_INUM); - //unlock gpio + esp_intr_enable(gpio_intr_handle); }