26
26
#include " ets_sys.h"
27
27
#include " user_interface.h"
28
28
#include " core_esp8266_waveform.h"
29
- #include " interrupts.h"
30
29
31
30
extern " C" {
32
31
@@ -54,17 +53,17 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
54
53
GPEC = (1 << pin); // Disable
55
54
GPC (pin) = (GPC (pin) & (0xF << GPCI)) | (1 << GPCD); // SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
56
55
if (mode == INPUT_PULLUP) {
57
- GPF (pin) |= (1 << GPFPU); // Enable Pullup
56
+ GPF (pin) |= (1 << GPFPU); // Enable Pullup
58
57
}
59
58
} else if (mode == WAKEUP_PULLUP || mode == WAKEUP_PULLDOWN){
60
59
GPF (pin) = GPFFS (GPFFS_GPIO (pin));// Set mode to GPIO
61
60
GPEC = (1 << pin); // Disable
62
61
if (mode == WAKEUP_PULLUP) {
63
- GPF (pin) |= (1 << GPFPU); // Enable Pullup
64
- GPC (pin) = (1 << GPCD) | (4 << GPCI) | (1 << GPCWE); // SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(LOW) | WAKEUP_ENABLE(ENABLED)
62
+ GPF (pin) |= (1 << GPFPU); // Enable Pullup
63
+ GPC (pin) = (1 << GPCD) | (4 << GPCI) | (1 << GPCWE); // SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(LOW) | WAKEUP_ENABLE(ENABLED)
65
64
} else {
66
- GPF (pin) |= (1 << GPFPD); // Enable Pulldown
67
- GPC (pin) = (1 << GPCD) | (5 << GPCI) | (1 << GPCWE); // SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(HIGH) | WAKEUP_ENABLE(ENABLED)
65
+ GPF (pin) |= (1 << GPFPD); // Enable Pulldown
66
+ GPC (pin) = (1 << GPCD) | (5 << GPCI) | (1 << GPCWE); // SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(HIGH) | WAKEUP_ENABLE(ENABLED)
68
67
}
69
68
}
70
69
} else if (pin == 16 ){
@@ -111,23 +110,10 @@ typedef void (*voidFuncPtrArg)(void*);
111
110
typedef struct {
112
111
uint8_t mode;
113
112
voidFuncPtr fn;
114
- void * arg;
115
- bool functional;
113
+ void * arg;
116
114
} interrupt_handler_t ;
117
115
118
- // duplicate from functionalInterrupt.h keep in sync
119
- typedef struct InterruptInfo {
120
- uint8_t pin;
121
- uint8_t value;
122
- uint32_t micro;
123
- } InterruptInfo;
124
-
125
- typedef struct {
126
- InterruptInfo* interruptInfo;
127
- void * functionInfo;
128
- } ArgStructure;
129
-
130
- static interrupt_handler_t interrupt_handlers[16 ] = { {0 , 0 , 0 , 0 }, };
116
+ static interrupt_handler_t interrupt_handlers[16 ] = { {0 , 0 , 0 }, };
131
117
static uint32_t interrupt_reg = 0 ;
132
118
133
119
void ICACHE_RAM_ATTR interrupt_handler (void *arg, void *frame)
@@ -144,53 +130,27 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
144
130
while (changedbits){
145
131
while (!(changedbits & (1 << i))) i++;
146
132
changedbits &= ~(1 << i);
147
- interrupt_handler_t * handler = &interrupt_handlers[i];
133
+ interrupt_handler_t * handler = &interrupt_handlers[i];
148
134
if (handler->fn &&
149
- (handler->mode == CHANGE ||
150
- (handler->mode & 1 ) == !!(levels & (1 << i)))) {
135
+ (handler->mode == CHANGE ||
136
+ (handler->mode & 1 ) == !!(levels & (1 << i)))) {
151
137
// to make ISR compatible to Arduino AVR model where interrupts are disabled
152
138
// we disable them before we call the client ISR
153
139
esp8266::InterruptLock irqLock; // stop other interrupts
154
- if (handler->functional )
155
- {
156
- ArgStructure* localArg = (ArgStructure*)handler->arg ;
157
- if (localArg && localArg->interruptInfo )
158
- {
159
- localArg->interruptInfo ->pin = i;
160
- localArg->interruptInfo ->value = __digitalRead (i);
161
- localArg->interruptInfo ->micro = micros ();
162
- }
163
- }
164
- if (handler->arg )
165
- {
166
- ((voidFuncPtrArg)handler->fn )(handler->arg );
167
- }
168
- else
169
- {
170
- handler->fn ();
171
- }
140
+ if (handler->arg )
141
+ {
142
+ ((voidFuncPtrArg)handler->fn )(handler->arg );
172
143
}
144
+ else
145
+ {
146
+ handler->fn ();
147
+ }
148
+ }
173
149
}
174
150
ETS_GPIO_INTR_ENABLE ();
175
151
}
176
152
177
- extern void cleanupFunctional (void * arg);
178
-
179
- static void ICACHE_RAM_ATTR set_interrupt_handlers (uint8_t pin, voidFuncPtr userFunc, void * arg, uint8_t mode, bool functional)
180
- {
181
- interrupt_handler_t * handler = &interrupt_handlers[pin];
182
- handler->mode = mode;
183
- handler->fn = userFunc;
184
- if (handler->functional && handler->arg ) // Clean when new attach without detach
185
- {
186
- cleanupFunctional (handler->arg );
187
- }
188
- handler->arg = arg;
189
- handler->functional = functional;
190
- }
191
-
192
- extern void __attachInterruptFunctionalArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode, bool functional)
193
- {
153
+ extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode) {
194
154
// #5780
195
155
// https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map
196
156
if ((uint32_t )userFunc >= 0x40200000 )
@@ -202,7 +162,10 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
202
162
203
163
if (pin < 16 ) {
204
164
ETS_GPIO_INTR_DISABLE ();
205
- set_interrupt_handlers (pin, (voidFuncPtr)userFunc, arg, mode, functional);
165
+ interrupt_handler_t * handler = &interrupt_handlers[pin];
166
+ handler->mode = mode;
167
+ handler->fn = (voidFuncPtr)userFunc;
168
+ handler->arg = arg;
206
169
interrupt_reg |= (1 << pin);
207
170
GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
208
171
GPIEC = (1 << pin); // Clear Interrupt for this pin
@@ -212,29 +175,23 @@ extern void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtrArg userFunc,
212
175
}
213
176
}
214
177
215
- extern void __attachInterruptArg (uint8_t pin, voidFuncPtrArg userFunc, void * arg, int mode)
216
- {
217
- __attachInterruptFunctionalArg (pin, userFunc, arg, mode, false );
218
- }
219
-
220
- extern void ICACHE_RAM_ATTR __detachInterrupt (uint8_t pin) {
221
- if (pin < 16 )
222
- {
223
- ETS_GPIO_INTR_DISABLE ();
224
- GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
225
- GPIEC = (1 << pin); // Clear Interrupt for this pin
226
- interrupt_reg &= ~(1 << pin);
227
- set_interrupt_handlers (pin, nullptr , nullptr , 0 , false );
228
- if (interrupt_reg)
229
- {
230
- ETS_GPIO_INTR_ENABLE ();
231
- }
232
- }
178
+ extern void __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode ) {
179
+ __attachInterruptArg (pin, (voidFuncPtrArg)userFunc, 0 , mode);
233
180
}
234
181
235
- extern void __attachInterrupt (uint8_t pin, voidFuncPtr userFunc, int mode)
236
- {
237
- __attachInterruptFunctionalArg (pin, (voidFuncPtrArg)userFunc, 0 , mode, false );
182
+ extern void __detachInterrupt (uint8_t pin) {
183
+ if (pin < 16 ) {
184
+ ETS_GPIO_INTR_DISABLE ();
185
+ GPC (pin) &= ~(0xF << GPCI);// INT mode disabled
186
+ GPIEC = (1 << pin); // Clear Interrupt for this pin
187
+ interrupt_reg &= ~(1 << pin);
188
+ interrupt_handler_t * handler = &interrupt_handlers[pin];
189
+ handler->mode = 0 ;
190
+ handler->fn = 0 ;
191
+ handler->arg = 0 ;
192
+ if (interrupt_reg)
193
+ ETS_GPIO_INTR_ENABLE ();
194
+ }
238
195
}
239
196
240
197
extern void __resetPins () {
@@ -258,7 +215,7 @@ extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pi
258
215
extern void digitalWrite (uint8_t pin, uint8_t val) __attribute__ ((weak, alias(" __digitalWrite" )));
259
216
extern int digitalRead (uint8_t pin) __attribute__ ((weak, alias(" __digitalRead" ), nothrow));
260
217
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" )));
218
+ extern void attachInterruptArg (uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__ ((weak, alias(" __attachInterruptArg" )));
262
219
extern void detachInterrupt (uint8_t pin) __attribute__ ((weak, alias(" __detachInterrupt" )));
263
220
264
221
};
0 commit comments