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:
parent
1fb86e1470
commit
7af55237da
1 changed files with 13 additions and 8 deletions
|
@ -67,21 +67,26 @@ static int dht_sample_fetch(const struct device *dev,
|
|||
uint8_t buf[5];
|
||||
unsigned int i, j;
|
||||
|
||||
#if defined(CONFIG_DHT_LOCK_IRQS)
|
||||
int lock;
|
||||
#endif
|
||||
|
||||
__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 */
|
||||
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);
|
||||
|
||||
/* 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 */
|
||||
gpio_pin_configure_dt(&cfg->dio_gpio, GPIO_INPUT);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue