Skip to content

Commit 7991161

Browse files
committed
Change Pin Interrupt Allocator
1 parent 28b7b4e commit 7991161

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

cores/esp32/esp32-hal-gpio.c

+7-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "soc/gpio_struct.h"
2525
#include "soc/rtc_io_reg.h"
2626

27-
#define ETS_GPIO_INUM 12
28-
2927
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};
3028

3129
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
@@ -193,6 +191,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin)
193191
return 0;
194192
}
195193

194+
static intr_handle_t gpio_intr_handle = NULL;
196195

197196
static void IRAM_ATTR __onPinInterrupt(void *arg)
198197
{
@@ -229,38 +228,29 @@ static void IRAM_ATTR __onPinInterrupt(void *arg)
229228
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type)
230229
{
231230
static bool interrupt_initialized = false;
232-
static int core_id = 0;
233231

234232
if(!interrupt_initialized) {
235233
interrupt_initialized = true;
236-
core_id = xPortGetCoreID();
237-
ESP_INTR_DISABLE(ETS_GPIO_INUM);
238-
intr_matrix_set(core_id, ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM);
239-
xt_set_interrupt_handler(ETS_GPIO_INUM, &__onPinInterrupt, NULL);
240-
ESP_INTR_ENABLE(ETS_GPIO_INUM);
234+
esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle);
241235
}
242236
__pinInterruptHandlers[pin] = userFunc;
243-
//lock gpio
244-
ESP_INTR_DISABLE(ETS_GPIO_INUM);
245-
if(core_id) { //APP_CPU
237+
esp_intr_disable(gpio_intr_handle);
238+
if(esp_intr_get_cpu(gpio_intr_handle)) { //APP_CPU
246239
GPIO.pin[pin].int_ena = 1;
247240
} else { //PRO_CPU
248241
GPIO.pin[pin].int_ena = 4;
249242
}
250243
GPIO.pin[pin].int_type = intr_type;
251-
ESP_INTR_ENABLE(ETS_GPIO_INUM);
252-
//unlock gpio
244+
esp_intr_enable(gpio_intr_handle);
253245
}
254246

255247
extern void __detachInterrupt(uint8_t pin)
256248
{
257-
//lock gpio
258-
ESP_INTR_DISABLE(ETS_GPIO_INUM);
249+
esp_intr_disable(gpio_intr_handle);
259250
__pinInterruptHandlers[pin] = NULL;
260251
GPIO.pin[pin].int_ena = 0;
261252
GPIO.pin[pin].int_type = 0;
262-
ESP_INTR_ENABLE(ETS_GPIO_INUM);
263-
//unlock gpio
253+
esp_intr_enable(gpio_intr_handle);
264254
}
265255

266256

0 commit comments

Comments
 (0)