From 92fc3e8bcba948e7ef02c9a7831cdf3765ae46ee Mon Sep 17 00:00:00 2001 From: UncleRus Date: Mon, 22 Jul 2019 02:21:27 +0500 Subject: [PATCH] Support for Itead Si7021 --- extras/dht/dht.c | 6 +++--- extras/dht/dht.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/extras/dht/dht.c b/extras/dht/dht.c index dee04f2..34e7a07 100644 --- a/extras/dht/dht.c +++ b/extras/dht/dht.c @@ -81,14 +81,14 @@ static bool dht_await_pin_state(uint8_t pin, uint32_t timeout, * The function call should be protected from task switching. * Return false if error occurred. */ -static inline bool dht_fetch_data(uint8_t pin, bool bits[DHT_DATA_BITS]) +static inline bool dht_fetch_data(dht_sensor_type_t sensor_type, uint8_t pin, bool bits[DHT_DATA_BITS]) { uint32_t low_duration; uint32_t high_duration; // Phase 'A' pulling signal low to initiate read sequence gpio_write(pin, 0); - sdk_os_delay_us(20000); + sdk_os_delay_us(sensor_type == DHT_TYPE_SI7021 ? 500 : 20000); gpio_write(pin, 1); // Step through Phase 'B', 40us @@ -155,7 +155,7 @@ bool dht_read_data(dht_sensor_type_t sensor_type, uint8_t pin, int16_t *humidity gpio_enable(pin, GPIO_OUT_OPEN_DRAIN); taskENTER_CRITICAL(); - result = dht_fetch_data(pin, bits); + result = dht_fetch_data(sensor_type, pin, bits); taskEXIT_CRITICAL(); if (!result) { diff --git a/extras/dht/dht.h b/extras/dht/dht.h index 664e95c..3236902 100644 --- a/extras/dht/dht.h +++ b/extras/dht/dht.h @@ -21,7 +21,8 @@ extern "C" { typedef enum { DHT_TYPE_DHT11 = 0, //!< DHT11 - DHT_TYPE_DHT22 //!< DHT22 + DHT_TYPE_DHT22, //!< DHT22 + DHT_TYPE_SI7021 //!< Itead SI7021 } dht_sensor_type_t; /**