driver: sensor: aosong,dht: fix sensor protocol broken since change #83192

A recent change 9eeb60c improperly removed a critical line in the driver.

This commit replaces that line and moves an irq_lock to above any pin

value manipulation since the timing is sensitive with the DHT protocol.

This should also fix the timing issue 9eeb60c attempted to fix.

Signed-off-by: John Shelton <moosery@gmail.com>
This commit is contained in:
John Shelton 2025-05-09 12:25:37 -05:00 committed by Benjamin Cabé
commit 7af55237da

View file

@ -67,21 +67,26 @@ static int dht_sample_fetch(const struct device *dev,
uint8_t buf[5]; uint8_t buf[5];
unsigned int i, j; unsigned int i, j;
#if defined(CONFIG_DHT_LOCK_IRQS)
int lock;
#endif
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
#if defined(CONFIG_DHT_LOCK_IRQS)
/* Get the lock before any pin interaction since irq_lock has a */
/* potential of causing delays itself. */
int lock = irq_lock();
#endif
/* assert to send start signal */ /* assert to send start signal */
gpio_pin_set_dt(&cfg->dio_gpio, true); gpio_pin_set_dt(&cfg->dio_gpio, true);
#if defined(CONFIG_DHT_LOCK_IRQS)
lock = irq_lock();
#endif
k_busy_wait(DHT_START_SIGNAL_DURATION); k_busy_wait(DHT_START_SIGNAL_DURATION);
/* set the state back to logic LOW (voltage HIGH) so that the */
/* subsequent call to dht_measure_signal duration waits for the */
/* DHT sensor to set it back to HIGH (voltage LOW). */
/* Failure to do this would cause that subsequent call to */
/* return immediately. */
gpio_pin_set_dt(&cfg->dio_gpio, false);
/* switch to DIR_IN to read sensor signals */ /* switch to DIR_IN to read sensor signals */
gpio_pin_configure_dt(&cfg->dio_gpio, GPIO_INPUT); gpio_pin_configure_dt(&cfg->dio_gpio, GPIO_INPUT);