summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-01-22 00:23:51 +1100
committerDamien George <damien.p.george@gmail.com>2019-01-22 00:26:04 +1100
commit18d3a5df260b1e85c3fd2718acbaeac199a33acf (patch)
tree633cba85f10edb05beda5fe319c127b475c1bf7f
parentf102ac54e95ca23f266aea30f3de7fd9a39b18a3 (diff)
esp8266/esp_mphal: Provide mp_hal_pin_od_high_dht so DHT works reliably.
The original behaviour of open-drain-high was to use the open-drain mode of the GPIO pin, and this seems to make driving a DHT more reliable. See issue #4233.
-rw-r--r--ports/esp8266/esp_mphal.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/ports/esp8266/esp_mphal.h b/ports/esp8266/esp_mphal.h
index 56d9fa35f..8712a2a33 100644
--- a/ports/esp8266/esp_mphal.h
+++ b/ports/esp8266/esp_mphal.h
@@ -91,6 +91,11 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin);
if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
else { gpio_output_set(0, 0, 0, 1 << (p)); /* set as input to avoid glitches */ } \
} while (0)
+// The DHT driver requires using the open-drain feature of the GPIO to get it to work reliably
+#define mp_hal_pin_od_high_dht(p) do { \
+ if ((p) == 16) { WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); } \
+ else { gpio_output_set(1 << (p), 0, 1 << (p), 0); } \
+ } while (0)
#define mp_hal_pin_read(p) pin_get(p)
#define mp_hal_pin_write(p, v) pin_set((p), (v))