1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-28 23:09:46 +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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
adcxx1c drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
ads101x doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
adt7310 drivers/adt7310: Update kconfig model 2022-03-02 14:03:28 +01:00
adxl345 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
aip31068 drivers/aip31068: Update kconfig model 2022-03-02 14:03:29 +01:00
apa102 drivers/apa102: Update kconfig model 2022-03-02 14:03:29 +01:00
apds99xx drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 Merge pull request #17255 from MrKevinWeiss/pr/kconfig/sam54 2021-11-29 23:22:23 +01:00
at25xxx doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
at30tse75x drivers/at30tse75x: Update kconfig model 2022-03-04 14:15:32 +01:00
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 drivers/bh1750fvi: Update kconfig model 2022-03-04 14:16:01 +01:00
bh1900nux drivers/bh1900nux: Update kconfig model 2022-03-04 14:15:32 +01:00
bme680 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
bmp180 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
bmx055 drivers/bmx055: fix crazy use of FPU 2023-05-31 16:32:14 +02:00
bmx280 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
bq2429x tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
can_trx drivers/can_trx: add module to Kconfig 2020-11-25 12:00:37 +01:00
cc1xxx_common treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
cst816s drivers/cst816s: use gpio_is_valid where appropriate 2022-04-14 11:31:36 +02:00
dac_dds doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
dcf77 drivers/dcf77: Update kconfig model 2022-03-04 14:15:35 +01:00
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 drivers/disp_dev: use struct to store display area coordinates 2022-04-13 12:49:58 +02:00
dose drivers/dose: make use of checksum module 2022-10-06 17:48:47 +02:00
ds18 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
ds75lx drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
ds1307 drivers/ds1307: Update kconfig model 2022-03-04 14:15:36 +01:00
ds3231 drivers/ds3231 fix docs, alarms are supported 2022-12-27 17:21:55 +01:00
ds3234 drivers/ds3234: Update kconfig model 2022-03-04 14:15:37 +01:00
dsp0401 drivers/dsp0401: Update kconfig model 2022-03-04 14:15:38 +01:00
dynamixel treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
edbg_eui drivers/edbg_eui: Update kconfig model 2022-03-04 14:15:38 +01:00
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 drivers/feetech: remove useless xtimer include 2021-12-01 10:06:24 +01:00
ft5x06 drivers/ft5x06: remove unnecessary pseudomodules 2022-01-21 14:13:49 +01:00
fxos8700 sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
gp2y10xx drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
hmc5883l sys/phydat: Fix unit confusion 2023-02-23 16:44:24 +01:00
hsc drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
hts221 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
ili9341 drivers/lcd: rework rotation modes and enable it with st7735 2022-04-19 16:22:10 +02:00
ina2xx drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
ina3221 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
isl29125 drivers/isl29125: Update kconfig model 2022-03-04 14:15:44 +01:00
itg320x doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
jc42 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 Merge pull request #17925 from aabadie/pr/drivers/lcd_params_rework 2022-04-19 16:21:42 +02:00
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 drivers/lpd8808: Update kconfig model 2022-03-04 14:15:45 +01:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/motor_driver: Use irq_restore 2021-12-21 18:23:11 +01:00
mpl3115a2 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/mtd_{mci,sdcard}: Pages need to be written at once 2022-03-31 10:58:52 +02:00
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 drivers/my9221: Update kconfig model 2022-03-04 14:15:47 +01:00
ncv7356 drivers/ncv7356: Update kconfig model 2022-03-04 14:16:01 +01:00
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 drivers/nvram: add module to Kconfig 2021-01-18 10:42:35 +01:00
nvram_spi drivers/nvmram_spi: convert to ztimer_usec 2022-01-18 16:27:44 +01:00
opt3001 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
pca9633 drivers/pca9633: Update kconfig model 2022-03-04 14:15:48 +01:00
pca9685 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
pcd8544 drivers/pcd8544: Update kconfig model 2022-03-04 14:15:49 +01:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
pir drivers/pir: Add missing doc and fix doccheck 2023-01-05 14:25:18 +01:00
pn532 drivers/pn532: Update kconfig model 2022-03-04 14:15:50 +01:00
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 treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
sdcard_spi drivers/sdcard_spi: remove copy of sdcard_spi_params_t from device 2023-05-01 14:36:25 +02:00
sdp3x drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
sds011 doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
seesaw_soil drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
si114x drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
si1133 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
srf02 drivers/srf02: Update kconfig model 2022-03-04 14:15:57 +01:00
srf04 boards: add some missing whitespaces for static tests 2022-09-14 15:11:14 +02:00
srf08 drivers/srf08: Update kconfig model 2022-03-04 14:15:58 +01:00
st7735 drivers/st7735/kconfig: add hardware feature symbol 2022-05-24 17:45:58 +02:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
tja1042 drivers/tja1042: Update kconfig model 2022-03-04 14:16:02 +01:00
tmp00x drivers/tmp00x: Add missing doc and fix doccheck 2023-01-05 14:25:19 +01:00
touch_dev drivers/{disp,touch}_dev: pull auto_init_screen by default 2021-05-25 14:21:58 +02:00
tps6274x drivers/tps6274x: Update kconfig model 2022-03-04 14:15:58 +01:00
tsl2561 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
tsl4531x drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
uart_half_duplex drivers/uart_half_duplex: add module to Kconfig 2020-12-02 10:13:50 +01:00
usbdev_mock usbdev_mock: Adapt to xmit API 2021-11-16 20:16:59 +01:00
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 drivers/saul: use const qualifier for data to write 2022-05-23 08:35:27 +02:00
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 drivers: Added doc group drivers_multimedia 2020-06-26 13:09:33 +02:00
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 sys/auto_init: allow delayed initialisation of SAUL 2020-03-04 16:13:40 +01:00
Makefile.dep drivers/servo: Fix missing dep 2023-04-26 15:15:53 +02:00