From c77f11906cf3220989019df70cee66ce4ad65f37 Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 21:14:40 +0800 Subject: [PATCH] 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/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 5654e5f12..7ed1dcb26 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/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); + } } }