Skip to content
Snippets Groups Projects
Commit ada06e9d authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

drivers: dht: adapt to xtimer

parent 7d2286e3
No related branches found
No related tags found
No related merge requests found
...@@ -341,3 +341,7 @@ endif ...@@ -341,3 +341,7 @@ endif
ifneq (,$(filter srf02,$(USEMODULE))) ifneq (,$(filter srf02,$(USEMODULE)))
USEMODULE += xtimer USEMODULE += xtimer
endif endif
ifneq (,$(filter dht,$(USEMODULE)))
USEMODULE += xtimer
endif
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <stdint.h> #include <stdint.h>
#include "hwtimer.h" #include "xtimer.h"
#include "timex.h" #include "timex.h"
#include "periph/gpio.h" #include "periph/gpio.h"
...@@ -79,9 +79,9 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum) ...@@ -79,9 +79,9 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum)
{ {
/* send init signal to device */ /* send init signal to device */
gpio_clear(dev); gpio_clear(dev);
hwtimer_wait(HWTIMER_TICKS(20 * MS_IN_USEC)); xtimer_usleep(20 * MS_IN_USEC);
gpio_set(dev); gpio_set(dev);
hwtimer_wait(HWTIMER_TICKS(40)); xtimer_usleep(40);
/* sync on device */ /* sync on device */
gpio_init(dev, GPIO_DIR_IN, GPIO_PULLUP); gpio_init(dev, GPIO_DIR_IN, GPIO_PULLUP);
...@@ -101,14 +101,14 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum) ...@@ -101,14 +101,14 @@ static void dht_read_data(gpio_t dev, uint32_t *data, uint8_t *checksum)
we must not shift the last bit */ we must not shift the last bit */
/* wait for start of bit */ /* wait for start of bit */
while (!gpio_read(dev)) ; while (!gpio_read(dev)) ;
unsigned long start = hwtimer_now(); unsigned long start = xtimer_now();
/* wait for end of bit */ /* wait for end of bit */
while (gpio_read(dev)) ; while (gpio_read(dev)) ;
/* calculate bit length (long 1, short 0) */ /* calculate bit length (long 1, short 0) */
unsigned long stop = hwtimer_now(); unsigned long stop = xtimer_now();
/* compensate for overflow if needed */ /* compensate for overflow if needed */
if (stop < start) { if (stop < start) {
stop = HWTIMER_MAXTICKS - stop; stop = UINT32_MAX - stop;
start = 0; start = 0;
} }
if ((stop - start) > 40) { if ((stop - start) > 40) {
...@@ -143,7 +143,7 @@ int dht_init(dht_t *dev, dht_type_t type, gpio_t gpio) ...@@ -143,7 +143,7 @@ int dht_init(dht_t *dev, dht_type_t type, gpio_t gpio)
} }
gpio_set(gpio); gpio_set(gpio);
hwtimer_wait(HWTIMER_TICKS(2000 * MS_IN_USEC)); xtimer_usleep(2000 * MS_IN_USEC);
DEBUG("dht_init: success\n"); DEBUG("dht_init: success\n");
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment