Skip to content

Commit 4478477

Browse files
committed
digitalWrite cleanup and more compliant with behavior on AVR
I rewrote digitalWrite because the existing version was breaking functionality as compared to how it behaves on the AVR,. specifically, I could not use digitalWrite for a library that works fine on the AVR. Instead I had to resort to fiddling with GPOC and GPOS and bit masks, but this rewrite made all of that unnecessary, for whatever reason, it just works better. This version borrows a little from the AVR library in the sense that the same logic is applied to determine whether a pin should be high or low as the AVR version, and yes, it does appear to make a difference.
1 parent 5012228 commit 4478477

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
7777
}
7878

7979
extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
80-
val &= 0x01;
81-
if(pin < 16){
82-
if(val) GPOS = (1 << pin);
83-
else GPOC = (1 << pin);
84-
} else if(pin == 16){
85-
if(val) GP16O |= 1;
86-
else GP16O &= ~1;
80+
if(val == LOW) {
81+
GP16O &= ~1;
82+
} else {
83+
GP16O |= 1;
84+
}
85+
if(val == LOW) {
86+
GPOC = digitalPinToBitMask(pin);
87+
} else {
88+
GPOS = digitalPinToBitMask(pin);
89+
}
8790
}
8891
}
8992

0 commit comments

Comments
 (0)