From 4478477775f180eb0ed6086410b82dc373c518ab Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 21:14:40 +0800 Subject: [PATCH 1/3] 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. --- .../cores/esp8266/core_esp8266_wiring_digital.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c index 5654e5f123..7ed1dcb26d 100644 --- a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c @@ -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); + } } } From b105c803921871693be44ad3201a8efa402f1084 Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 22:04:58 +0800 Subject: [PATCH 2/3] Update core_esp8266_wiring_digital.c Ugh, I don't know how that happened. --- .../esp8266/cores/esp8266/core_esp8266_wiring_digital.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c index 7ed1dcb26d..2df6952c6b 100644 --- a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c @@ -77,11 +77,13 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { + if (pin == 16) { if(val == LOW) { GP16O &= ~1; } else { GP16O |= 1; } + } else if ((pin >= 0) && (pin <= 15)) { if(val == LOW) { GPOC = digitalPinToBitMask(pin); } else { From 2456067df9e474cf34230b64a66092feaf568413 Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 22:24:49 +0800 Subject: [PATCH 3/3] Update core_esp8266_wiring_digital.c --- .../esp8266/core_esp8266_wiring_digital.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c index 2df6952c6b..5be065af51 100644 --- a/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c +++ b/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c @@ -77,18 +77,12 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { - if (pin == 16) { - if(val == LOW) { - GP16O &= ~1; - } else { - GP16O |= 1; - } - } else if ((pin >= 0) && (pin <= 15)) { - if(val == LOW) { - GPOC = digitalPinToBitMask(pin); - } else { - GPOS = digitalPinToBitMask(pin); - } + if(pin < 16){ + if(val) GPOS = (1 << pin); + else GPOC = (1 << pin); + } else if(pin == 16){ + if(val) GP16O |= 1; + else GP16O &= ~1; } }