|
24 | 24 | #include "soc/gpio_struct.h" |
25 | 25 | #include "soc/rtc_io_reg.h" |
26 | 26 |
|
27 | | -#define ETS_GPIO_INUM 12 |
28 | | - |
29 | 27 | 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}; |
30 | 28 |
|
31 | 29 | const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ |
@@ -193,6 +191,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin) |
193 | 191 | return 0; |
194 | 192 | } |
195 | 193 |
|
| 194 | +static intr_handle_t gpio_intr_handle = NULL; |
196 | 195 |
|
197 | 196 | static void IRAM_ATTR __onPinInterrupt(void *arg) |
198 | 197 | { |
@@ -229,38 +228,29 @@ static void IRAM_ATTR __onPinInterrupt(void *arg) |
229 | 228 | extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) |
230 | 229 | { |
231 | 230 | static bool interrupt_initialized = false; |
232 | | - static int core_id = 0; |
233 | 231 |
|
234 | 232 | if(!interrupt_initialized) { |
235 | 233 | 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); |
241 | 235 | } |
242 | 236 | __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 |
246 | 239 | GPIO.pin[pin].int_ena = 1; |
247 | 240 | } else { //PRO_CPU |
248 | 241 | GPIO.pin[pin].int_ena = 4; |
249 | 242 | } |
250 | 243 | GPIO.pin[pin].int_type = intr_type; |
251 | | - ESP_INTR_ENABLE(ETS_GPIO_INUM); |
252 | | - //unlock gpio |
| 244 | + esp_intr_enable(gpio_intr_handle); |
253 | 245 | } |
254 | 246 |
|
255 | 247 | extern void __detachInterrupt(uint8_t pin) |
256 | 248 | { |
257 | | - //lock gpio |
258 | | - ESP_INTR_DISABLE(ETS_GPIO_INUM); |
| 249 | + esp_intr_disable(gpio_intr_handle); |
259 | 250 | __pinInterruptHandlers[pin] = NULL; |
260 | 251 | GPIO.pin[pin].int_ena = 0; |
261 | 252 | GPIO.pin[pin].int_type = 0; |
262 | | - ESP_INTR_ENABLE(ETS_GPIO_INUM); |
263 | | - //unlock gpio |
| 253 | + esp_intr_enable(gpio_intr_handle); |
264 | 254 | } |
265 | 255 |
|
266 | 256 |
|
|
0 commit comments