1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/include
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
..
at25xxx drivers/at25xxx: add MTD wrapper for AT25XXX EEPROMs 2020-05-05 13:37:51 +01:00
can drivers/candev: fix non matching argument in doc 2022-01-03 09:51:40 +01:00
net drivers/netdev: add tinyUSB netdev 2023-02-01 21:57:23 +01:00
periph Merge #19610 #19670 #19678 #19679 #19680 #19681 2023-05-30 17:11:06 +00:00
saul treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
ad7746.h many typo fixes 2019-11-23 22:39:07 +01:00
adcxx1c.h drivers/adcxx1c: add clear alert function 2020-08-31 15:53:53 +02:00
ads101x.h drivers/ads101x : Add CONFIG_ 2020-04-17 16:43:16 +05:30
adt7310.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
adxl345.h drivers/adxk345: include copy of params in dev struct 2019-01-06 17:24:24 +01:00
aip31068.h driver/aip31068: add new driver 2020-09-29 14:42:15 +02:00
apa102.h drivers: add driver for apa102 RGB LEDs 2017-09-01 09:37:31 +02:00
apds99xx.h drivers: add APDS99XX ALS and proximity 2020-03-11 14:21:47 +01:00
at24cxxx.h drivers/at24cxxx: merge mtd driver with at24cxxx.c 2023-02-17 10:55:21 +01:00
at24mac.h drivers/at24mac: fix grouping in doc 2020-02-27 08:46:40 +01:00
at25xxx.h drivers/at25xxx: export page-wise write function 2020-08-18 17:25:40 +02:00
at30tse75x.h codespell: fix remaining issues 2022-09-16 14:00:35 +02:00
at86rf2xx.h drivers/at86rf2xx: move TX power logic to netdev 2022-12-06 15:40:43 +01:00
at86rf215.h doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
at.h drivers/at: add a function read a response plus the OK 2022-10-16 14:05:31 +02:00
ata8520e.h drivers/ata8520e: migrate to ztimer 2021-11-05 12:49:37 +01:00
atwinc15x0.h drivers/atwinc15x0: register with netdev 2022-03-30 16:07:29 +02:00
bh1750fvi.h drivers/bh1750fvi: change prototype of bh1750fvi_init 2019-01-07 21:37:02 +01:00
bh1900nux.h Add bh1900nux driver 2020-02-12 07:34:22 +01:00
bme680.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
bmp180.h many typo fixes 2019-11-23 22:39:07 +01:00
bmx055.h drivers/bmx055 : Expose to Kconfig 2020-05-04 18:18:00 +05:30
bmx280.h drivers/bmx280: remove unused parameter spi3w_en #15954 2021-02-16 09:04:08 +09:00
bq2429x.h drivers: add bq2429x power management IC driver 2021-01-22 19:30:12 +01:00
candev_mcp2515.h drivers/mcp2515: use ztimer 2022-04-20 09:23:50 +02:00
cc1xxx_common.h drivers/cc110x: add weak function cc1xxx_eui_get() 2021-04-08 10:38:16 +02:00
cc110x.h Merge pull request #16232 from maribu/drivers/cc110x 2021-07-06 12:24:26 +02:00
cc2420.h drivers/cc2420: register with netdev 2021-04-27 17:37:52 +02:00
ccs811.h drivers/ccs811: small cleanups in documentation 2021-12-04 13:43:31 +01:00
cst816s.h drivers/cst816s: add touch_dev interface 2022-04-14 11:31:35 +02:00
dac_dds.h drivers/dac_dds: add module to play sample buffer over a DAC 2020-12-04 23:12:32 +01:00
dcf77.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
dfplayer.h drivers/dfplayer: fix bug in utility function 2023-05-19 21:51:44 +02:00
dht.h drivers/dht: busy wait reimplementation 2023-06-20 12:07:48 +02:00
diskio.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
disp_dev.h drivers/disp_dev: use struct to store display area coordinates 2022-04-13 12:49:58 +02:00
dose.h drivers/dose: make RX buffer size configurable 2022-05-15 14:43:47 +02:00
ds18.h drivers/ds18.h: add missing stdint.h include 2021-11-09 21:48:48 +01:00
ds75lx.h many typo fixes 2019-11-23 22:39:07 +01:00
ds1307.h drivers/include/ds1307.h : Remove ifndef for I2C 2020-04-17 14:07:58 +05:30
ds3231.h drivers/ds3231 fix docs, alarms are supported 2022-12-27 17:21:55 +01:00
ds3234.h drivers/ds3234: Fix doxygen group 2019-03-14 14:32:28 +01:00
dsp0401.h dsp0401: move to display devices doxygen group 2020-02-10 14:10:18 +01:00
dynamixel.h drivers: doxygen cleanup 2017-09-01 15:12:20 +02:00
edbg_eui.h drivers/edbg_eui: add note on edbg startup time 2020-09-28 20:18:43 +02:00
enc28j60.h drivers: add anchor to doc to allow stable references 2021-10-13 17:37:16 +02:00
encx24j600.h drivers/encx24j600: introduce setup function with index 2022-03-24 09:32:10 +01:00
epd_bw_spi_disp_dev.h epd_bw_spi: add implementation for disp_dev 2023-01-31 19:50:11 +01:00
epd_bw_spi.h epd_bw_spi: add implementation for disp_dev 2023-01-31 19:50:11 +01:00
ethos.h doc: sort all stdio implementations into sys_stdio group 2023-01-13 11:08:22 +01:00
feetech.h drivers: doxygen cleanup 2017-09-01 15:12:20 +02:00
ft5x06.h drivers/ft5x06: allow multiple device types 2022-01-21 13:13:09 +01:00
fxos8700.h drivers/fxos8700 : Add CONFIG_ 2020-04-29 14:32:00 +05:30
gp2y10xx.h drivers: add gp2y10xx dust sensor 2020-11-18 09:13:56 +01:00
grove_ledbar.h drivers*: add saul doc group to related drivers 2018-08-27 11:32:20 +02:00
hd44780.h hd44780: move to display devices doxygen group 2020-02-10 14:10:46 +01:00
hdc1000.h drivers/hdc1000 : Add CONFIG_ 2020-04-16 17:17:27 +05:30
hih6130.h drivers/hih6130: avoid using floats 2023-06-08 14:33:38 +02:00
hm330x.h drivers/hms330x: initial import 2021-12-16 15:19:44 +01:00
hmc5883l.h drivers: add hmc5883l device driver 2020-04-01 13:37:22 +02:00
hsc.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
hts221.h drivers/include/hts221.h : Remove ifndef for I2C 2020-04-17 14:07:58 +05:30
ili9341.h drivers/lcd: rework rotation modes and enable it with st7735 2022-04-19 16:22:10 +02:00
ina2xx.h drivers/ina2xx: Match RIOT's driver design goals 2019-11-22 20:28:57 +01:00
ina3221.h drivers/ina3221: refactor 2021-07-07 08:40:02 +02:00
io1_xplained.h many typo fixes 2019-11-23 22:39:07 +01:00
ir_nec.h drivers/ir_nec: ir remote implementation 2022-05-31 17:58:39 +02:00
isl29020.h drivers/isl29020 : Expose to Kconfig 2020-05-08 18:07:27 +05:30
isl29125.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
itg320x.h drivers: add driver for ITG320X 3-axis gyroscope 2020-01-11 08:02:34 +01:00
jc42.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
kw2xrf.h drivers/kw2xrf: remove unused kw2xrf_setup function 2022-08-25 15:44:34 +02:00
kw41zrf.h drivers/kw41zrf: register with netdev 2020-10-08 16:19:23 +02:00
l3g4200d.h drivers/l3g4200d : Expose to Kconfig 2020-05-05 13:19:49 +05:30
l3gxxxx.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
lc709203f.h drivers/lc709203f: fix typo 'Invlid' -> 'Invalid' 2020-10-02 08:05:00 +02:00
lcd.h drivers/lcd: rework rotation modes and enable it with st7735 2022-04-19 16:22:10 +02:00
led.h drivers: doxygen cleanup 2017-09-01 15:12:20 +02:00
lis2dh12.h drivers/lis2dh12: fix missing stdbool include 2022-01-06 12:07:41 +01:00
lis3dh.h drivers/lis3dh: fix unaligned memory access 2021-11-06 20:05:05 +01:00
lis3mdl.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
lm75.h doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
lpd8808.h drivers: use const device descriptor 2017-06-21 17:05:45 +02:00
lpsxxx.h driver/lpsxxx: adding lps22ch support 2022-03-09 15:23:51 +01:00
lsm6dsl.h drivers*: add saul doc group to related drivers 2018-08-27 11:32:20 +02:00
lsm303dlhc.h drivers*: add saul doc group to related drivers 2018-08-27 11:32:20 +02:00
ltc4150.h drivers/ltc4150: migrate to ztimer64 2022-01-18 16:27:44 +01:00
mag3110.h drivers/mag3110 : Add CONFIG_ 2020-04-23 15:49:55 +05:30
matrix_keypad.h matrix_keypad: Move documentation to doxygen group 2023-02-23 11:39:11 +01:00
mcp47xx.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
mfrc522.h drivers/mfrc522: add new driver 2023-01-31 21:05:07 +01:00
mhz19.h drivers/mhz19: initial support 2020-06-17 08:41:41 +02:00
mii.h drivers/mii: add Interrupt Control/Status register 2023-06-05 12:46:08 +02:00
mma8x5x.h drivers/mma8x5x : Add CONFIG_ 2020-04-22 21:57:05 +05:30
mma7660.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
motor_driver.h drivers/motor_driver : Add CONFIG_ 2020-04-23 15:21:17 +05:30
mpl3115a2.h drivers/include/mpl3115a2.h : Remove ifndef for I2C 2020-04-17 15:45:37 +05:30
mpu9x50.h drivers/mpu9x50: Fix prameter placement for docs 2020-01-13 12:50:13 +01:00
mq3.h drivers/mq3: avoid use of floats 2023-06-01 16:52:26 +02:00
mrf24j40.h drivers/mrf24j40: add note about missing wake pin handling 2023-06-07 15:10:33 +02:00
mtd_at24cxxx.h drivers/at24cxxx: add MTD wrapper for at24cxxx EEPROMs 2020-05-20 19:20:05 +02:00
mtd_default.h drivers/mtd_default: add external declarations for mtd* 2023-05-02 23:07:29 +02:00
mtd_emulated.h drivers/mtd_emulatd: MTD emulated in RAM for testing 2023-04-11 17:42:10 +02:00
mtd_flashpage.h drivers/mtd_flashpage: implement pagewise API 2023-02-16 15:50:52 +01:00
mtd_mapper.h drivers/mtd_mapper: Add write_size 2022-03-31 10:58:52 +02:00
mtd_sdcard.h drivers/mtd_sdcard: implement erase_sector() 2022-02-07 11:40:27 +01:00
mtd_spi_nor.h drivers/mtd_spi_nor: drop addr_width from mtd_spi_nor_params_t 2022-02-04 12:17:17 +01:00
mtd.h drivers/mtd: small fixes in doc 2023-04-11 17:42:10 +02:00
my9221.h drivers: add my9221 led controller 2017-08-30 09:06:03 +02:00
ncv7356.h drivers/ncv7356: Add documentation 2019-11-27 13:35:57 +01:00
nrf24l01p_ng.h tree wide: fix typos in comments found by codespell 2023-05-02 09:52:06 +02:00
nrf24l01p.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
nvram-spi.h drivers: doxygen cleanup 2017-09-01 15:12:20 +02:00
nvram.h drivers: doxygen cleanup 2017-09-01 15:12:20 +02:00
opt3001.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
pca9633.h drivers/pca9633: make enum anonymous 2020-07-17 15:05:32 +02:00
pca9685.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
pcd8544.h pcd8544: move to display devices doxygen group 2020-02-10 14:11:17 +01:00
pcf857x.h drivers/pcf857x: allow to define PCF857x_BASE_ADDR at compile time 2023-06-14 05:38:20 +02:00
ph_oem.h drivers/ph_oem: Initial implementation of the pH OEM sensor 2019-09-05 12:47:10 +02:00
pir.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
pn532.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
pulse_counter.h drivers/pulse_counter: Use C11 atomics & bugfix 2019-11-26 14:04:42 +01:00
qmc5883l.h drivers: add support for QMC5883L mag sensors 2019-11-13 12:56:26 +01:00
rgbled.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
rn2xx3.h drivers/rn2xx3: migrate to ztimer 2021-11-04 10:39:36 +01:00
rtt_rtc.h rtt_rtc: clarify documentation about epoch 2021-09-28 15:12:14 +02:00
saul.h drivers/saul: use flash_utils 2023-02-27 12:31:04 +01:00
scd30.h drivers/scd30: Add reset function to Sensirion scd30 sensor 2020-10-14 15:07:01 +02:00
screen_dev.h drivers/screen_dev: add a bit of documentation 2021-03-03 18:04:42 +01:00
sdcard_spi.h drivers/sdcard_spi: doc cleanup to fit in 100 characters per line 2023-05-01 14:36:25 +02:00
sdp3x.h drivers/sdp3x: Driver for sensirion sdp3x sensor 2020-06-29 20:50:41 +02:00
sds011.h drivers/include: fix typos 2019-11-23 22:39:40 +01:00
seesaw_soil.h Add support for Adafruit Seesaw Soil moisture sensor (#14835) 2020-09-23 17:35:33 +02:00
servo.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
sgp30.h driver/sgp30: initial import 2021-04-08 10:14:30 +02:00
sht1x.h drivers/sht1x: fix doccheck 2022-09-16 11:12:27 +02:00
sht2x.h drivers/sht2x: fix measurement duration 2022-12-14 21:47:32 +01:00
sht3x.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
shtcx.h drivers/shtcx: integration of shtc3 sensor 2022-03-10 21:35:25 +01:00
si70xx.h drivers/si70xx: Add support for Si705x sensors 2021-04-17 20:14:35 +00:00
si114x.h treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
si1133.h drivers/si1133: New SI1133 UV/IR/Ambient light driver 2020-12-14 03:13:23 +00:00
slipdev.h doc: sort all stdio implementations into sys_stdio group 2023-01-13 11:08:22 +01:00
sm_pwm_01c.h drivers/sm_pwm_01c: initial import 2021-04-07 12:05:09 +02:00
soft_spi.h drivers/soft_spi: remove nanosleep 2021-11-30 10:31:22 +01:00
soft_uart.h drivers/soft_uart: fix typo in eMail address 2021-04-26 17:15:17 +02:00
sps30.h drivers/sps30: Add sleep mode 2020-08-25 16:20:18 +02:00
srf02.h drivers/srf02: Update to new i2c API 2018-07-25 12:01:38 +02:00
srf04.h drivers/sfr04: Use uncrustify 2020-11-22 23:12:40 +01:00
srf08.h drivers/srf08: refactor driver configuration 2020-02-25 21:24:02 +01:00
st7735.h drivers/lcd: rework rotation modes and enable it with st7735 2022-04-19 16:22:10 +02:00
stm32_eth.h stm32_eth: Multiple Improvements of the original codebase 2019-07-04 15:27:26 +02:00
stmpe811.h drivers/stmpe811: add spi mode 2021-12-03 17:12:03 +01:00
sx126x.h drivers/sx126x: add tx_pa_mode 2021-11-08 18:42:05 +01:00
sx127x.h Revert "drivers/sx127x: fix size of rx symbol timeout" 2021-07-13 21:14:28 +02:00
sx1280.h drivers/sx1280: initial import 2022-05-18 17:06:12 +02:00
tcs37727.h drivers/tcs37727 : Expose to Kconfig 2020-05-07 23:55:32 +05:30
tja1042.h drivers: fix doxygen grouping 2018-06-11 19:10:40 +02:00
tmp00x.h doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
touch_dev.h drivers/touch_dev: extend API to set event callback function 2021-03-03 18:00:49 +01:00
tps6274x.h drivers: Initial support for TPS6274x converter 2019-01-10 00:00:02 +01:00
tsl2561.h drivers*: add saul doc group to related drivers 2018-08-27 11:32:20 +02:00
tsl4531x.h drivers/include: fix typos 2019-11-23 22:39:40 +01:00
usbdev_mock.h doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
usbdev_synopsys_dwc2.h drivers/usbdev_synopsys_dwc2: set USBDEV_SET_ADDR_AFTER_STATUS 2023-04-16 17:14:08 +02:00
vcnl40x0.h drivers/vcnl40x0: initial implementation 2018-10-15 11:44:10 +02:00
veml6070.h drivers*: add saul doc group to related drivers 2018-08-27 11:32:20 +02:00
vl6180x.h treewide: replace occurrences of tests/driver_ with new path 2023-05-06 15:38:21 +02:00
w5100.h doc: fix unbalaced grouping 2022-09-14 15:05:25 +02:00
ws281x.h drivers/ws281x: Extended doc 2020-04-09 13:34:51 +02:00
xbee.h codespell: fix remaining issues 2022-09-16 14:00:35 +02:00