@@ -111,22 +111,9 @@ typedef struct {
111
111
uint8_t mode;
112
112
voidFuncPtr fn;
113
113
void * arg;
114
- bool functional;
115
114
} interrupt_handler_t ;
116
115
117
- // duplicate from functionalInterrupt.h keep in sync
118
- typedef struct InterruptInfo {
119
- uint8_t pin;
120
- uint8_t value;
121
- uint32_t micro;
122
- } InterruptInfo;
123
-
124
- typedef struct {
125
- InterruptInfo* interruptInfo;
126
- void * functionInfo;
127
- } ArgStructure;
128
-
129
- static interrupt_handler_t interrupt_handlers[16 ] = { {0 , 0 , 0 , 0 }, };
116
+ static interrupt_handler_t interrupt_handlers[16 ] = { {0 , 0 , 0 }, };
130
117
static uint32_t interrupt_reg = 0 ;
131
118
132
119
void ICACHE_RAM_ATTR interrupt_handler (void *)
@@ -145,77 +132,55 @@ void ICACHE_RAM_ATTR interrupt_handler(void*)
145
132
if (handler->fn &&
146
133
(handler->mode == CHANGE ||
147
134
(handler->mode & 1 ) == !!(levels & (1 << i)))) {
148
- // to make ISR compatible to Arduino AVR model where interrupts are disabled
149
- // we disable them before we call the client ISR
150
- uint32_t savedPS = xt_rsil (15 ); // stop other interrupts
151
- if (handler->functional )
152
- {
153
- ArgStructure* localArg = (ArgStructure*)handler->arg ;
154
- if (localArg && localArg->interruptInfo )
155
- {
156
- localArg->interruptInfo ->pin = i;
157
- localArg->interruptInfo ->value = __digitalRead (i);
158
- localArg->interruptInfo ->micro = micros ();
159
- }
160
- }
161
- if (handler->arg )
162
- {
163
- ((voidFuncPtrArg)handler->fn )(handler->arg );
164
- }
165
- else
166
- {
167
- handler->fn ();
168
- }
169
- xt_wsr_ps (savedPS);
135
+ // to make ISR compatible to Arduino AVR model where interrupts are disabled
136
+ // we disable them before we call the client ISR
137
+ uint32_t savedPS = xt_rsil (15 ); // stop other interrupts
138
+ if (handler->arg )
139
+ {
140
+ ((voidFuncPtrArg)handler->fn )(handler->arg );
141
+ }
142
+ else
143
+ {
144
+ handler->fn ();
170
145
}
146
+ xt_wsr_ps (savedPS);
147
+ }
171
148
}
172
149
ETS_GPIO_INTR_ENABLE ();
173
150
}
174
151
175
- extern void cleanupFunctional (void * arg);
176
-
177
- extern void __attachInterruptFunctionalArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode, bool functional)
152
+ extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode)
178
153
{
179
- // #5780
180
- // https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
181
- if ((uint32_t )userFunc >= 0x40200000 )
182
- {
183
- // ISR not in IRAM
184
- ::printf ((PGM_P)F(" ISR not in IRAM!\r\n " ));
185
- abort ();
186
- }
187
-
188
- if (pin < 16 ) {
189
- ETS_GPIO_INTR_DISABLE ();
190
- interrupt_handler_t * handler = &interrupt_handlers[pin];
191
- handler->mode = mode;
192
- handler->fn = (voidFuncPtr)userFunc;
193
- if (handler->functional && handler->arg ) // Clean when new attach without detach
154
+ // #5780
155
+ // https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
156
+ if ((uint32_t )userFunc >= 0x40200000 )
194
157
{
195
- cleanupFunctional (handler->arg );
158
+ // ISR not in IRAM
159
+ ::printf ((PGM_P)F(" ISR not in IRAM!\r\n " ));
160
+ abort ();
196
161
}
197
- handler->arg = arg;
198
- handler->functional = functional;
199
- interrupt_reg |= (1 << pin);
200
- GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
201
- GPIEC = (1 << pin); // Clear Interrupt for this pin
202
- GPC (pin) |= ((mode & 0xF ) << GPCI);// INT mode "mode"
203
- ETS_GPIO_INTR_ATTACH (interrupt_handler, &interrupt_reg);
204
- ETS_GPIO_INTR_ENABLE ();
205
- }
206
- }
207
162
208
- extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode)
209
- {
210
- __attachInterruptFunctionalArg (pin, userFunc, arg, mode, false );
163
+ if (pin < 16 ) {
164
+ ETS_GPIO_INTR_DISABLE ();
165
+ interrupt_handler_t * handler = &interrupt_handlers[pin];
166
+ handler->mode = mode;
167
+ handler->fn = (voidFuncPtr)userFunc;
168
+ handler->arg = arg;
169
+ interrupt_reg |= (1 << pin);
170
+ GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
171
+ GPIEC = (1 << pin); // Clear Interrupt for this pin
172
+ GPC (pin) |= ((mode & 0xF ) << GPCI);// INT mode "mode"
173
+ ETS_GPIO_INTR_ATTACH (interrupt_handler, &interrupt_reg);
174
+ ETS_GPIO_INTR_ENABLE ();
175
+ }
211
176
}
212
177
213
178
extern void __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode)
214
179
{
215
- __attachInterruptFunctionalArg (pin, (voidFuncPtrArg)userFunc, 0 , mode, false );
180
+ __attachInterruptArg (pin, (voidFuncPtrArg)userFunc, 0 , mode);
216
181
}
217
182
218
- extern void ICACHE_RAM_ATTR __detachInterrupt (uint8_t pin)
183
+ extern void __detachInterrupt (uint8_t pin)
219
184
{
220
185
if (pin < 16 )
221
186
{
@@ -225,40 +190,43 @@ extern void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin)
225
190
interrupt_reg &= ~(1 << pin);
226
191
interrupt_handler_t * handler = &interrupt_handlers[pin];
227
192
handler->mode = 0 ;
228
- handler->fn = 0 ;
229
- if (handler->functional && handler->arg )
230
- {
231
- cleanupFunctional (handler->arg );
232
- }
233
- handler->arg = 0 ;
234
- handler->functional = false ;
193
+ handler->fn = nullptr ;
194
+ handler->arg = nullptr ;
235
195
if (interrupt_reg)
236
196
{
237
197
ETS_GPIO_INTR_ENABLE ();
238
198
}
239
199
}
240
200
}
241
201
202
+ extern void * __detachInterruptArg (uint8_t pin)
203
+ {
204
+ void * arg = (pin < 16 ) ? interrupt_handlers[pin].arg : nullptr ;
205
+ __detachInterrupt (pin);
206
+ return arg;
207
+ }
208
+
242
209
void initPins () {
243
- // Disable UART interrupts
244
- system_set_os_print (0 );
245
- U0IE = 0 ;
246
- U1IE = 0 ;
210
+ // Disable UART interrupts
211
+ system_set_os_print (0 );
212
+ U0IE = 0 ;
213
+ U1IE = 0 ;
247
214
248
- for (int i = 0 ; i <= 5 ; ++i) {
249
- pinMode (i, INPUT);
250
- }
251
- // pins 6-11 are used for the SPI flash interface
252
- for (int i = 12 ; i <= 16 ; ++i) {
253
- pinMode (i, INPUT);
254
- }
215
+ for (int i = 0 ; i <= 5 ; ++i) {
216
+ pinMode (i, INPUT);
217
+ }
218
+ // pins 6-11 are used for the SPI flash interface
219
+ for (int i = 12 ; i <= 16 ; ++i) {
220
+ pinMode (i, INPUT);
221
+ }
255
222
}
256
223
257
224
extern void pinMode (uint8_t pin, uint8_t mode) __attribute__ ((weak, alias(" __pinMode" )));
258
225
extern void digitalWrite (uint8_t pin, uint8_t val) __attribute__ ((weak, alias(" __digitalWrite" )));
259
226
extern int digitalRead (uint8_t pin) __attribute__ ((weak, alias(" __digitalRead" )));
260
227
extern void attachInterrupt (uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias(" __attachInterrupt" )));
261
- extern void attachInterruptArg (uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__((weak, alias(" __attachInterruptArg" )));
262
228
extern void detachInterrupt (uint8_t pin) __attribute__ ((weak, alias(" __detachInterrupt" )));
229
+ extern void attachInterruptArg (uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__((weak, alias(" __attachInterruptArg" )));
230
+ extern void * detachInterruptArg (uint8_t pin) __attribute__ ((weak, alias(" __detachInterruptArg" )));
263
231
264
232
};
0 commit comments