/* byte_5 == (byte_1 + byte_2 + byte_3 + btye_4) & 0xFF Wait specified time for pin to go to a specified state. If timeout is reached and pin doesn't go to a requested state false is returned. The elapsed time is returned in pointer 'duration' if it is not NULL.  */
static bool dht_await_pin_state(uint8_t pin, uint32_t timeout, bool expected_pin_state, uint32_t *duration)
/* byte_5 == (byte_1 + byte_2 + byte_3 + btye_4) & 0xFF Wait specified time for pin to go to a specified state. If timeout is reached and pin doesn't go to a requested state false is returned. The elapsed time is returned in pointer 'duration' if it is not NULL.  */
static bool dht_await_pin_state(uint8_t pin, uint32_t timeout, bool expected_pin_state, uint32_t *duration)
{
    for (uint32_t i = 0; i < timeout; i += DHT_TIMER_INTERVAL) {
        sdk_os_delay_us(DHT_TIMER_INTERVAL);
        if (gpio_read(pin) == expected_pin_state) {
            if (duration) {
                *duration = i;
            }
            return true;
        }
    }
    return false;
}