@@ -109,8 +109,9 @@ typedef void (*voidFuncPtrArg)(void*);
109
109
110
110
typedef struct {
111
111
uint8_t mode;
112
- void (*fn)(void );
113
- void * arg;
112
+ voidFuncPtr fn;
113
+ void * arg;
114
+ bool functional;
114
115
} interrupt_handler_t ;
115
116
116
117
// duplicate from functionalInterrupt.h keep in sync
@@ -125,11 +126,10 @@ typedef struct {
125
126
void * functionInfo;
126
127
} ArgStructure;
127
128
128
- static interrupt_handler_t interrupt_handlers[16 ];
129
+ static interrupt_handler_t interrupt_handlers[16 ] = { { 0 , 0 , 0 , 0 }, } ;
129
130
static uint32_t interrupt_reg = 0 ;
130
131
131
- void ICACHE_RAM_ATTR interrupt_handler (void *arg) {
132
- (void ) arg;
132
+ void ICACHE_RAM_ATTR interrupt_handler (void *) {
133
133
uint32_t status = GPIE;
134
134
GPIEC = status;// clear them interrupts
135
135
uint32_t levels = GPI;
@@ -147,13 +147,16 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
147
147
// to make ISR compatible to Arduino AVR model where interrupts are disabled
148
148
// we disable them before we call the client ISR
149
149
uint32_t savedPS = xt_rsil (15 ); // stop other interrupts
150
- ArgStructure* localArg = (ArgStructure*)handler->arg ;
151
- if (localArg && localArg->interruptInfo )
152
- {
153
- localArg->interruptInfo ->pin = i;
154
- localArg->interruptInfo ->value = __digitalRead (i);
155
- localArg->interruptInfo ->micro = micros ();
156
- }
150
+ if (handler->functional )
151
+ {
152
+ ArgStructure* localArg = (ArgStructure*)handler->arg ;
153
+ if (localArg && localArg->interruptInfo )
154
+ {
155
+ localArg->interruptInfo ->pin = i;
156
+ localArg->interruptInfo ->value = __digitalRead (i);
157
+ localArg->interruptInfo ->micro = micros ();
158
+ }
159
+ }
157
160
if (handler->arg )
158
161
{
159
162
((voidFuncPtrArg)handler->fn )(handler->arg );
@@ -170,8 +173,7 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
170
173
171
174
extern void cleanupFunctional (void * arg);
172
175
173
- extern void ICACHE_RAM_ATTR __attachInterruptArg (uint8_t pin, voidFuncPtr userFunc, void *arg, int mode) {
174
-
176
+ extern void __attachInterruptFunctionalArg (uint8_t pin, voidFuncPtrArg userFunc, void *arg, int mode, bool functional) {
175
177
// #5780
176
178
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
177
179
if ((uint32_t )userFunc >= 0x40200000 )
@@ -185,12 +187,13 @@ extern void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFu
185
187
ETS_GPIO_INTR_DISABLE ();
186
188
interrupt_handler_t *handler = &interrupt_handlers[pin];
187
189
handler->mode = mode;
188
- handler->fn = userFunc;
189
- if (handler->arg ) // Clean when new attach without detach
190
+ handler->fn = (voidFuncPtr) userFunc;
191
+ if (handler->functional && handler-> arg ) // Clean when new attach without detach
190
192
{
191
193
cleanupFunctional (handler->arg );
192
194
}
193
195
handler->arg = arg;
196
+ handler->functional = functional;
194
197
interrupt_reg |= (1 << pin);
195
198
GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
196
199
GPIEC = (1 << pin); // Clear Interrupt for this pin
@@ -200,12 +203,16 @@ extern void ICACHE_RAM_ATTR __attachInterruptArg(uint8_t pin, voidFuncPtr userFu
200
203
}
201
204
}
202
205
203
- extern void ICACHE_RAM_ATTR __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode )
206
+ extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode)
204
207
{
205
- __attachInterruptArg (pin, userFunc, 0 , mode);
208
+ __attachInterruptFunctionalArg (pin, userFunc, arg, mode, false );
209
+ }
210
+
211
+ extern void __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode ) {
212
+ __attachInterruptFunctionalArg (pin, (voidFuncPtrArg)userFunc, 0 , mode, false );
206
213
}
207
214
208
- extern void ICACHE_RAM_ATTR __detachInterrupt (uint8_t pin) {
215
+ extern void __detachInterrupt (uint8_t pin) {
209
216
if (pin < 16 ) {
210
217
ETS_GPIO_INTR_DISABLE ();
211
218
GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
@@ -214,11 +221,12 @@ extern void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin) {
214
221
interrupt_handler_t *handler = &interrupt_handlers[pin];
215
222
handler->mode = 0 ;
216
223
handler->fn = 0 ;
217
- if (handler->arg )
224
+ if (handler->functional && handler-> arg )
218
225
{
219
226
cleanupFunctional (handler->arg );
220
227
}
221
228
handler->arg = 0 ;
229
+ handler->functional = false ;
222
230
if (interrupt_reg)
223
231
ETS_GPIO_INTR_ENABLE ();
224
232
}
@@ -243,6 +251,7 @@ extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pi
243
251
extern void digitalWrite (uint8_t pin, uint8_t val) __attribute__ ((weak, alias(" __digitalWrite" )));
244
252
extern int digitalRead (uint8_t pin) __attribute__ ((weak, alias(" __digitalRead" )));
245
253
extern void attachInterrupt (uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias(" __attachInterrupt" )));
254
+ extern void attachInterruptArg (uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__ ((weak, alias(" __attachInterruptArg" )));
246
255
extern void detachInterrupt (uint8_t pin) __attribute__ ((weak, alias(" __detachInterrupt" )));
247
256
248
257
};
0 commit comments