1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

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.
This commit is contained in:
h4rm0n1c 2015-07-10 21:14:40 +08:00
parent e7b7d6d8b7
commit c77f11906c

View File

@ -77,13 +77,16 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
}
extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
val &= 0x01;
if(pin < 16){
if(val) GPOS = (1 << pin);
else GPOC = (1 << pin);
} else if(pin == 16){
if(val) GP16O |= 1;
else GP16O &= ~1;
if(val == LOW) {
GP16O &= ~1;
} else {
GP16O |= 1;
}
if(val == LOW) {
GPOC = digitalPinToBitMask(pin);
} else {
GPOS = digitalPinToBitMask(pin);
}
}
}