Skip to content

Commit 466fa6f

Browse files
author
Me No Dev
committed
Get pin levels at time of interrupt, rather than the time of calling the handler
current implementation can cause false readings if previous handlers take more time than the pin holds the level
1 parent 5d49085 commit 466fa6f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cores/esp8266/core_esp8266_wiring_digital.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static uint32_t interrupt_reg = 0;
111111

112112
void interrupt_handler(void *arg) {
113113
uint32_t status = GPIE;
114+
uint32_t levels = GPI;
114115
GPIEC = status;//clear them interrupts
115116
if(status == 0 || interrupt_reg == 0) return;
116117
ETS_GPIO_INTR_DISABLE();
@@ -122,7 +123,7 @@ void interrupt_handler(void *arg) {
122123
interrupt_handler_t *handler = &interrupt_handlers[i];
123124
if (handler->fn &&
124125
(handler->mode == CHANGE ||
125-
(handler->mode & 1) == digitalRead(i))) {
126+
(handler->mode & 1) == !!(levels & (1 << i)))) {
126127
// to make ISR compatible to Arduino AVR model where interrupts are disabled
127128
// we disable them before we call the client ISR
128129
uint32_t savedPS = xt_rsil(15); // stop other interrupts

0 commit comments

Comments
 (0)