@@ -70,7 +70,12 @@ const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
70
70
};
71
71
72
72
typedef void (* voidFuncPtr )(void );
73
- static voidFuncPtr __pinInterruptHandlers [GPIO_PIN_COUNT ] = {0 ,};
73
+ typedef void (* voidFuncPtrArg )(void * );
74
+ typedef struct {
75
+ voidFuncPtr fn ;
76
+ void * arg ;
77
+ } InterruptHandle_t ;
78
+ static InterruptHandle_t __pinInterruptHandlers [GPIO_PIN_COUNT ] = {0 ,};
74
79
75
80
#include "driver/rtc_io.h"
76
81
@@ -193,7 +198,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin)
193
198
194
199
static intr_handle_t gpio_intr_handle = NULL ;
195
200
196
- static void IRAM_ATTR __onPinInterrupt (void * arg )
201
+ static void IRAM_ATTR __onPinInterrupt ()
197
202
{
198
203
uint32_t gpio_intr_status_l = 0 ;
199
204
uint32_t gpio_intr_status_h = 0 ;
@@ -207,8 +212,12 @@ static void IRAM_ATTR __onPinInterrupt(void *arg)
207
212
if (gpio_intr_status_l ) {
208
213
do {
209
214
if (gpio_intr_status_l & ((uint32_t )1 << pin )) {
210
- if (__pinInterruptHandlers [pin ]) {
211
- __pinInterruptHandlers [pin ]();
215
+ if (__pinInterruptHandlers [pin ].fn ) {
216
+ if (__pinInterruptHandlers [pin ].arg ){
217
+ ((voidFuncPtrArg )__pinInterruptHandlers [pin ].fn )(__pinInterruptHandlers [pin ].arg );
218
+ } else {
219
+ __pinInterruptHandlers [pin ].fn ();
220
+ }
212
221
}
213
222
}
214
223
} while (++ pin < 32 );
@@ -217,23 +226,28 @@ static void IRAM_ATTR __onPinInterrupt(void *arg)
217
226
pin = 32 ;
218
227
do {
219
228
if (gpio_intr_status_h & ((uint32_t )1 << (pin - 32 ))) {
220
- if (__pinInterruptHandlers [pin ]) {
221
- __pinInterruptHandlers [pin ]();
229
+ if (__pinInterruptHandlers [pin ].fn ) {
230
+ if (__pinInterruptHandlers [pin ].arg ){
231
+ ((voidFuncPtrArg )__pinInterruptHandlers [pin ].fn )(__pinInterruptHandlers [pin ].arg );
232
+ } else {
233
+ __pinInterruptHandlers [pin ].fn ();
234
+ }
222
235
}
223
236
}
224
237
} while (++ pin < GPIO_PIN_COUNT );
225
238
}
226
239
}
227
240
228
- extern void __attachInterrupt (uint8_t pin , voidFuncPtr userFunc , int intr_type )
241
+ extern void __attachInterruptArg (uint8_t pin , voidFuncPtrArg userFunc , void * arg , int intr_type )
229
242
{
230
243
static bool interrupt_initialized = false;
231
244
232
245
if (!interrupt_initialized ) {
233
246
interrupt_initialized = true;
234
247
esp_intr_alloc (ETS_GPIO_INTR_SOURCE , (int )ESP_INTR_FLAG_IRAM , __onPinInterrupt , NULL , & gpio_intr_handle );
235
248
}
236
- __pinInterruptHandlers [pin ] = userFunc ;
249
+ __pinInterruptHandlers [pin ].fn = (voidFuncPtr )userFunc ;
250
+ __pinInterruptHandlers [pin ].arg = arg ;
237
251
esp_intr_disable (gpio_intr_handle );
238
252
if (esp_intr_get_cpu (gpio_intr_handle )) { //APP_CPU
239
253
GPIO .pin [pin ].int_ena = 1 ;
@@ -244,10 +258,15 @@ extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type)
244
258
esp_intr_enable (gpio_intr_handle );
245
259
}
246
260
261
+ extern void __attachInterrupt (uint8_t pin , voidFuncPtr userFunc , int intr_type ) {
262
+ __attachInterruptArg (pin , (voidFuncPtrArg )userFunc , NULL , intr_type );
263
+ }
264
+
247
265
extern void __detachInterrupt (uint8_t pin )
248
266
{
249
267
esp_intr_disable (gpio_intr_handle );
250
- __pinInterruptHandlers [pin ] = NULL ;
268
+ __pinInterruptHandlers [pin ].fn = NULL ;
269
+ __pinInterruptHandlers [pin ].arg = NULL ;
251
270
GPIO .pin [pin ].int_ena = 0 ;
252
271
GPIO .pin [pin ].int_type = 0 ;
253
272
esp_intr_enable (gpio_intr_handle );
@@ -258,5 +277,6 @@ extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pi
258
277
extern void digitalWrite (uint8_t pin , uint8_t val ) __attribute__ ((weak , alias ("__digitalWrite" )));
259
278
extern int digitalRead (uint8_t pin ) __attribute__ ((weak , alias ("__digitalRead" )));
260
279
extern void attachInterrupt (uint8_t pin , voidFuncPtr handler , int mode ) __attribute__ ((weak , alias ("__attachInterrupt" )));
280
+ extern void attachInterruptArg (uint8_t pin , voidFuncPtr handler , void * arg , int mode ) __attribute__ ((weak , alias ("__attachInterruptArg" )));
261
281
extern void detachInterrupt (uint8_t pin ) __attribute__ ((weak , alias ("__detachInterrupt" )));
262
282
0 commit comments