@@ -74,6 +74,7 @@ typedef void (*voidFuncPtrArg)(void*);
74
74
typedef struct {
75
75
voidFuncPtr fn;
76
76
void* arg;
77
+ bool functional;
77
78
} InterruptHandle_t;
78
79
static InterruptHandle_t __pinInterruptHandlers[GPIO_PIN_COUNT] = {0,};
79
80
@@ -238,16 +239,26 @@ static void IRAM_ATTR __onPinInterrupt()
238
239
}
239
240
}
240
241
241
- extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type)
242
+ extern void cleanupFunctional(void* arg);
243
+
244
+ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type, bool functional)
242
245
{
243
246
static bool interrupt_initialized = false;
244
-
247
+
245
248
if(!interrupt_initialized) {
246
249
interrupt_initialized = true;
247
250
esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle);
248
251
}
252
+
253
+ // if new attach without detach remove old info
254
+ if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg)
255
+ {
256
+ cleanupFunctional(__pinInterruptHandlers[pin].arg);
257
+ }
249
258
__pinInterruptHandlers[pin].fn = (voidFuncPtr)userFunc;
250
259
__pinInterruptHandlers[pin].arg = arg;
260
+ __pinInterruptHandlers[pin].functional = functional;
261
+
251
262
esp_intr_disable(gpio_intr_handle);
252
263
if(esp_intr_get_cpu(gpio_intr_handle)) { //APP_CPU
253
264
GPIO.pin[pin].int_ena = 1;
@@ -258,15 +269,26 @@ extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * ar
258
269
esp_intr_enable(gpio_intr_handle);
259
270
}
260
271
272
+ extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type)
273
+ {
274
+ __attachInterruptFunctionalArg(pin, userFunc, arg, intr_type, false);
275
+ }
276
+
261
277
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) {
262
- __attachInterruptArg (pin, (voidFuncPtrArg)userFunc, NULL, intr_type);
278
+ __attachInterruptFunctionalArg (pin, (voidFuncPtrArg)userFunc, NULL, intr_type, false );
263
279
}
264
280
265
281
extern void __detachInterrupt(uint8_t pin)
266
282
{
267
283
esp_intr_disable(gpio_intr_handle);
284
+ if (__pinInterruptHandlers[pin].functional && __pinInterruptHandlers[pin].arg)
285
+ {
286
+ cleanupFunctional(__pinInterruptHandlers[pin].arg);
287
+ }
268
288
__pinInterruptHandlers[pin].fn = NULL;
269
289
__pinInterruptHandlers[pin].arg = NULL;
290
+ __pinInterruptHandlers[pin].arg = false;
291
+
270
292
GPIO.pin[pin].int_ena = 0;
271
293
GPIO.pin[pin].int_type = 0;
272
294
esp_intr_enable(gpio_intr_handle);
0 commit comments