@@ -123,45 +123,17 @@ extern "C" {
123
123
interrupt_handler_t ()
124
124
{
125
125
mode = 0 ;
126
- isFunctional = false ;
127
- fn = nullptr ;
128
- arg = nullptr ;
129
126
}
130
127
~interrupt_handler_t ()
131
128
{
132
- using std::function;
133
- if (isFunctional)
134
- functional.~function<void ()>();
135
129
}
136
130
uint8_t mode;
137
- bool isFunctional;
138
- union {
139
- struct {
140
- voidFuncPtrArg fn;
141
- void * arg;
142
- };
143
- std::function<void ()> functional;
144
- };
131
+ Delegate<void , void *> userFunc;
145
132
};
146
133
147
134
static interrupt_handler_t interrupt_handlers[16 ];
148
135
static uint32_t interrupt_reg = 0 ;
149
136
150
- void ICACHE_RAM_ATTR set_interrupt_handlers (uint8_t pin, voidFuncPtrArg userFunc, void * arg, uint8_t mode)
151
- {
152
- using std::function;
153
- interrupt_handler_t & handler = interrupt_handlers[pin];
154
- if (handler.isFunctional )
155
- {
156
- handler.functional .~function<void ()>();
157
- handler.isFunctional = false ;
158
- }
159
- handler.fn = userFunc;
160
- handler.arg = arg;
161
- if (handler.fn )
162
- handler.mode = mode;
163
- }
164
-
165
137
void ICACHE_RAM_ATTR interrupt_handler (void *arg, void *frame)
166
138
{
167
139
(void ) arg;
@@ -184,10 +156,7 @@ extern "C" {
184
156
// to make ISR compatible to Arduino AVR model where interrupts are disabled
185
157
// we disable them before we call the client ISR
186
158
esp8266::InterruptLock irqLock; // stop other interrupts
187
- if (handler.isFunctional )
188
- handler.functional ();
189
- else
190
- handler.fn (handler.arg );
159
+ handler.userFunc ();
191
160
}
192
161
++i;
193
162
}
@@ -219,13 +188,7 @@ extern "C" {
219
188
extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg const userFunc, void * const arg, int mode)
220
189
{
221
190
isr_iram_assertion ((uint32_t )userFunc);
222
- if (pin < 16 )
223
- {
224
- ETS_GPIO_INTR_DISABLE ();
225
- set_interrupt_handlers (pin, userFunc, arg, mode);
226
- set_interrupt_reg (pin, mode);
227
- ETS_GPIO_INTR_ENABLE ();
228
- }
191
+ attachInterrupt (pin, Delegate<void , void *>(userFunc, arg), mode);
229
192
}
230
193
231
194
extern void __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode)
@@ -241,7 +204,9 @@ extern "C" {
241
204
GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
242
205
GPIEC = (1 << pin); // Clear Interrupt for this pin
243
206
interrupt_reg &= ~(1 << pin);
244
- set_interrupt_handlers (pin, nullptr , nullptr , 0 );
207
+ interrupt_handler_t & handler = interrupt_handlers[pin];
208
+ handler.userFunc = nullptr ;
209
+ handler.mode = 0 ;
245
210
if (interrupt_reg)
246
211
{
247
212
ETS_GPIO_INTR_ENABLE ();
@@ -278,21 +243,16 @@ extern "C" {
278
243
279
244
namespace
280
245
{
281
- void set_interrupt_handlers (uint8_t pin, std::function <void () >&& userFunc, uint8_t mode)
246
+ void ICACHE_RAM_ATTR set_interrupt_handlers (uint8_t pin, Delegate <void , void * >&& userFunc, uint8_t mode)
282
247
{
283
248
interrupt_handler_t & handler = interrupt_handlers[pin];
284
- if (!handler.isFunctional )
285
- {
286
- new (&handler.functional ) std::function<void ()>();
287
- handler.isFunctional = true ;
288
- }
289
- if (userFunc)
249
+ handler.userFunc = std::move (userFunc);
250
+ if (handler.userFunc )
290
251
handler.mode = mode;
291
- handler.functional = std::move (userFunc);
292
252
}
293
253
}
294
254
295
- extern void attachInterrupt (uint8_t pin, std::function <void () > userFunc, int mode)
255
+ extern void attachInterrupt (uint8_t pin, Delegate <void , void * > userFunc, int mode)
296
256
{
297
257
if (pin < 16 )
298
258
{
0 commit comments