Merge pull request #725 from UncleRus/Itead_si7021

Support for Itead Si7021
This commit is contained in:
Ruslan V. Uss 2019-07-24 14:39:07 +05:00 committed by GitHub
commit 53fa634908
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -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. * The function call should be protected from task switching.
* Return false if error occurred. * 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 low_duration;
uint32_t high_duration; uint32_t high_duration;
// Phase 'A' pulling signal low to initiate read sequence // Phase 'A' pulling signal low to initiate read sequence
gpio_write(pin, 0); gpio_write(pin, 0);
sdk_os_delay_us(20000); sdk_os_delay_us(sensor_type == DHT_TYPE_SI7021 ? 500 : 20000);
gpio_write(pin, 1); gpio_write(pin, 1);
// Step through Phase 'B', 40us // 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); gpio_enable(pin, GPIO_OUT_OPEN_DRAIN);
taskENTER_CRITICAL(); taskENTER_CRITICAL();
result = dht_fetch_data(pin, bits); result = dht_fetch_data(sensor_type, pin, bits);
taskEXIT_CRITICAL(); taskEXIT_CRITICAL();
if (!result) { if (!result) {

View file

@ -21,7 +21,8 @@ extern "C" {
typedef enum typedef enum
{ {
DHT_TYPE_DHT11 = 0, //!< DHT11 DHT_TYPE_DHT11 = 0, //!< DHT11
DHT_TYPE_DHT22 //!< DHT22 DHT_TYPE_DHT22, //!< DHT22
DHT_TYPE_SI7021 //!< Itead SI7021
} dht_sensor_type_t; } dht_sensor_type_t;
/** /**