1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/drivers
bors[bot] 561e19303d
Merge #19718 #19737 #19746
19718: drivers/dht: busy wait reimplementation r=benpicco a=hugueslarrive

### Contribution description

In PR #19674, I also provided quick and dirty fixes to restore functionality on esp8266 and enable operation on AVR. While reviewing PR #18591, it became apparent to me that this driver needed a refresh, particularly its migration to ztimer.

The cause of the malfunction on esp8266 was that since the default switch to ztimer as the backend for xtimer, XTIMER_BACKOFF was no longer taken into account. Therefore, the correction I provided in PR #19674 simply made explicit what was previously done implicitly with xtimer and now needs to be done explicitly with ztimer (spinning instead of sleeping).

Moreover, it was unnecessarily complex to measure the pulse duration in a busy-wait implementation, which required 2 calls to ztimer_now() and  32-bit operations expensive on 8-bit architecture. Instead, it is sufficient to read the state of the bus at the threshold moment.

Finally, in practice, it is possible to reduce the read interval (down to less than 0.5s for DHT22) by "harassing" the DHT with start signals until it responds.

This re-implementation brings the following improvements:
- Many backports from `@maribu's` IRQ based implementation (#18591):
  - Use of ztimer
  - Use of errno.h
  - Use of a dht_data structure to pass arguments, to facilitate integration
  - Adaptation of the bit parsing technique to parse bits into the data array
- Reintroduction of DHT11/DHT22 differentiation.
- Separation of `dht_read()` steps into functions for better readability and the ability to share certain functions among different implementations
- Sensor presence check in `dht_init()`
- ~~Automatic adjustment to a minimum data hold time~~
- Default input mode changed to open drain (a pull-up resistor should be placed close to the output if necessary but not close to the input)
- AVR support without platform-specific handling by avoiding  ztimer_spin() and using the overflow of an 8-bit variable as a pre-timeout to minimize time-consuming ztimer_now() calls

Regarding the changes in the start signal sequence and the removal of the `_reset()` function:
![nano_dht_read_2](https://github.com/RIOT-OS/RIOT/assets/67432403/95966813-2b5f-4a0f-a388-8ac630526ab2)

~~In the previous implementation, there was an unnecessary spike at the beginning of the signal sequence, corresponding to START_HIGH_TIME. This spike has been removed in the re-implementation, as it is unnecessary. Instead, the MCU now simply pulls the signal low for START_LOW_TIME and then releases the bus, which is sufficient for initiating communication with the DHT sensor.~~ Actually, it is necessary to raise the bus level; otherwise, the _wait_for_level() called immediately after to check the response of the DHT may read the port before the signal level is raised, resulting in a false positive.

Additionally, the previous implementation had an issue where the MCU switched back to output mode and went high immediately after reading the 40 bits of data. However, the DHT sensor was still transmitting 2 or 3 additional bytes of '0' at that point, causing a conflict. This issue has been resolved in the re-implementation:
![nano_dht_read_optimized](https://github.com/RIOT-OS/RIOT/assets/67432403/ff124839-5ec5-4df3-bab7-5348d8160a25)

~~Regarding the optimization for AVR, I have performed measurements of `_wait_for_level()` until timeout (85 loops):~~
~~- on esp8266-esp-12x: 264 µs, which is 3.11 µs per loop~~
~~- on nucleo-f303k8: 319 µs, which is 3.75 µs per loop~~
~~- on arduino-nano: 3608 µs, which is 42.45 µs per loop~~
~~Duration measurements on the Arduino Nano:~~


19737: dist/tools/openocd: start debug-server in background and wait r=benpicco a=fabian18



19746: buildsystem: Always expose CPU_RAM_BASE & SIZE flags r=benpicco a=Teufelchen1

### Contribution description

Hello 🐧 

This moves the definition of `CPU_RAM_BASE/SIZE` from being only available in certain situation to be always available.
Reason for change is to simplify common code in the cpu folder.

In cooperation with `@benpicco` 

### Testing procedure

Passing CI


### Issues/PRs references

First usage will be in the PMP driver. Although there is more code in RIOT that could be refactored to use these defines instead of hacks / hardcoded values.

Co-authored-by: Hugues Larrive <hlarrive@pm.me>
Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
Co-authored-by: Teufelchen1 <bennet.blischke@outlook.com>
2023-06-20 10:40:01 +00:00
..
ad7746
adcxx1c
ads101x doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
adt7310
adxl345 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
aip31068
apa102
apds99xx
at drivers/at: rename urc_isr_low pseudomodule to lowest 2023-03-21 15:46:35 +01:00
at24cxxx drivers/at24cxxx: merge mtd driver with at24cxxx.c 2023-02-17 10:55:21 +01:00
at24mac
at25xxx doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
at30tse75x
at86rf2xx drivers/at86rf2xx: rx timestamp generation for ATmegaRFR2 2023-05-19 15:33:15 +02:00
at86rf215 at86rf215: respect ack request option 2022-12-14 16:29:01 +01:00
ata8520e doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
atwinc15x0 drivers/atwinc15x0: don't disable interrupts 2022-10-25 14:47:13 +02:00
bh1750fvi
bh1900nux
bme680
bmp180
bmx055 drivers/bmx055: fix crazy use of FPU 2023-05-31 16:32:14 +02:00
bmx280
bq2429x tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
can_trx
cc1xxx_common
cc110x tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
cc2420 netdev_drivers: make sure to signal LINK_UP at least once 2022-09-16 22:57:28 +02:00
ccs811
cst816s
dac_dds doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
dcf77
dfplayer drivers/dfplayer: fix bug in utility function 2023-05-19 21:51:44 +02:00
dht drivers/dht: busy wait reimplementation 2023-06-20 12:07:48 +02:00
disp_dev
dose drivers/dose: make use of checksum module 2022-10-06 17:48:47 +02:00
ds18
ds75lx
ds1307
ds3231 drivers/ds3231 fix docs, alarms are supported 2022-12-27 17:21:55 +01:00
ds3234
dsp0401
dynamixel
edbg_eui
enc28j60 drivers/enc28j60: fix PKTIF issue. 2023-04-11 12:23:18 +02:00
encx24j600 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
epd_bw_spi epd_bw_spi: add implementation for disp_dev 2023-01-31 19:50:11 +01:00
ethos core/init: call vfs_bind_stdio() in early_init() 2023-01-08 22:26:13 +01:00
feetech
ft5x06
fxos8700 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
gp2y10xx
grove_ledbar boards: add some missing whitespaces for static tests 2022-09-14 15:11:14 +02:00
hd44780 Merge pull request #12665 from gschorcht/drivers/hd44780_i2c_pcf857x 2022-06-14 10:23:19 +02:00
hdc1000 drivers/hdc1000: Add missing doc and fix doccheck 2023-01-05 14:25:20 +01:00
hih6130 drivers/hih6130: avoid using floats 2023-06-08 14:33:38 +02:00
hm330x
hmc5883l sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
hsc
hts221
ili9341
ina2xx
ina3221
include Merge #19718 #19737 #19746 2023-06-20 10:40:01 +00:00
io1_xplained boards: add some missing whitespaces for static tests 2022-09-14 15:11:14 +02:00
ir_nec drivers/ir_nec: ir remote implementation 2022-05-31 17:58:39 +02:00
isl29020
isl29125
itg320x doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
jc42
kw2xrf drivers/kw2xrd/Kconfig: fix kconfig model 2022-08-23 10:04:44 +02:00
kw41zrf drivers/kw41zrf: boards/openlabs-kw41z-mini: cleanup Kconfig 2023-06-01 12:19:44 +02:00
l3g4200d doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
l3gxxxx drivers/l3gxxxx: fix check for l3g4200d_ng 2023-04-28 17:24:15 +02:00
lc709203f driver/lc709203f: remove unnecessary use of float 2023-05-24 14:22:24 +02:00
lcd
lis2dh12 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
lis3dh sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
lis3mdl sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
lm75 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
lpd8808
lpsxxx drivers/lpsxxx: avoid float arithmetics 2023-05-19 09:23:30 +02:00
lsm6dsl sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
lsm303agr drivers/lsm303agr: Rename deprecated unit G to GForce 2023-04-25 09:23:21 +02:00
lsm303dlhc sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
ltc4150
mag3110 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
matrix_keypad matrix_keypad: use gpio_is_valid 2023-01-17 11:03:01 +01:00
mcp47xx
mcp2515 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
mfrc522 drivers/mfrc522: add new driver 2023-01-31 21:05:07 +01:00
mhz19 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
mma8x5x sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
mma7660 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
motor_driver
mpl3115a2
mpu9x50 drivers/mpu9x50: clean up code 2023-05-23 21:40:40 +02:00
mq3 drivers/mq3: avoid use of floats 2023-06-01 16:52:26 +02:00
mrf24j40 drivers/mrf24j40: cleanup function 2023-05-20 16:59:25 +02:00
mtd drivers/mtd_emulatd: MTD emulated in RAM for testing 2023-04-11 17:42:10 +02:00
mtd_emulated drivers/mtd_emulatd: MTD emulated in RAM for testing 2023-04-11 17:42:10 +02:00
mtd_flashpage drivers/mtd_flashpage: drop legacy API 2023-02-16 15:50:52 +01:00
mtd_mapper drivers/mtd_mapper: inherit physical properties 2022-06-03 00:22:06 +02:00
mtd_mci
mtd_sdcard drivers/mtd_sdcard: add mtd_sdcard_default module 2023-02-05 19:03:09 +01:00
mtd_spi_nor drivers/mtd_spi_nor: fix hang 2023-05-22 12:22:01 -04:00
my9221
ncv7356
netdev tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
netdev_ieee802154_submac Merge #19053 2022-12-15 10:15:31 +00:00
nrf24l01p drivers/nrf24l01p: model in Kconfig 2023-05-24 10:18:53 +02:00
nrf24l01p_ng netdev_drivers: make sure to signal LINK_UP at least once 2022-09-16 22:57:28 +02:00
nvram
nvram_spi
opt3001 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
pca9633
pca9685
pcd8544
pcf857x drivers/pcf857x: fix error handling 2023-05-19 21:59:40 +02:00
periph_common cpu/rpx0xx: Fix kconfig model 2023-05-24 09:53:23 +02:00
ph_oem
pir drivers/pir: Add missing doc and fix doccheck 2023-01-05 14:25:18 +01:00
pn532
pulse_counter drivers/pulse_counter: Add missing doc and fix doccheck 2023-01-05 14:25:19 +01:00
qmc5883l sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
rgbled
rn2xx3 sys/net/gnrc/netif: allow checking if a netdev is legacy or new API 2022-08-17 12:56:07 +02:00
rtt_rtc drivers/periph/rtc: improve doc on rtc_set_alarm 2023-05-30 17:41:36 +02:00
saul drivers/shtcx: fix assertion and shtcx_saul_info idx 2023-05-31 14:42:44 +02:00
scd30
sdcard_spi drivers/sdcard_spi: remove copy of sdcard_spi_params_t from device 2023-05-01 14:36:25 +02:00
sdp3x
sds011 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
seesaw_soil
servo drivers/servo: Fix typo in comment 2023-03-26 20:54:14 +02:00
sgp30 drivers/sgp30: add missing include 2022-09-26 18:54:40 +02:00
sht1x drivers/sht1x: add missing include for ARRAY_SIZE 2022-11-22 13:39:35 +01:00
sht2x drivers/sht2x: use sys/checksum/crc8 2022-12-14 21:47:32 +01:00
sht3x codespell: fix remaining issues 2022-09-16 14:00:35 +02:00
shtcx drivers/shtcx: releases I2C-line properly 2022-07-20 17:37:33 +02:00
si70xx
si114x
si1133
slipdev drivers/slipdev: fix logic bug 2023-05-19 23:01:30 +02:00
sm_pwm_01c drivers/sm_pwm_01c: add missing include 2022-09-26 18:54:40 +02:00
soft_spi drivers/soft_spi: fix device validation bug 2022-12-14 08:18:45 -05:00
soft_uart tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
sps30
srf02
srf04 boards: add some missing whitespaces for static tests 2022-09-14 15:11:14 +02:00
srf08
st7735
stmpe811 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
sx126x drivers/sx126x: fix argument validation in spreading factor 2023-05-22 15:06:07 +02:00
sx127x drivers/sx127x: reduce use of floats 2023-06-12 13:54:06 +02:00
sx1280 netdev_drivers: make sure to signal LINK_UP at least once 2022-09-16 22:57:28 +02:00
tcs37727
tja1042
tmp00x drivers/tmp00x: Add missing doc and fix doccheck 2023-01-05 14:25:19 +01:00
touch_dev
tps6274x
tsl2561
tsl4531x
uart_half_duplex
usbdev_mock
usbdev_synopsys_dwc2 drivers/usbdev_synopsys_dwc2: add GD32V support 2023-04-16 23:24:23 +02:00
vcnl40x0 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
veml6070
vl6180x Kconfig: integration of VL6180X driver and test app 2023-02-02 02:04:09 +01:00
w5100 netdev_drivers: make sure to signal LINK_UP at least once 2022-09-16 22:57:28 +02:00
ws281x drivers/ws281x: add ESP32x hardware support 2023-03-29 00:47:35 +02:00
xbee netdev_drivers: make sure to signal LINK_UP at least once 2022-09-16 22:57:28 +02:00
doc.txt
Kconfig Kconfig: integration of VL6180X driver and test app 2023-02-02 02:04:09 +01:00
Kconfig.net drivers/nrf24l01p: model in Kconfig 2023-05-24 10:18:53 +02:00
Makefile
Makefile.dep drivers/servo: Fix missing dep 2023-04-26 15:15:53 +02:00