From 4445d940eaa92f29d6a1a9e69d5ce685e4fcf680 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser <kaspar@schleiser.de> Date: Fri, 14 Aug 2015 13:30:49 +0200 Subject: [PATCH] drivers: sht11: use xtimer --- Makefile.dep | 4 ++++ drivers/include/sht11.h | 4 ++-- drivers/sht11/sht11.c | 48 ++++++++++++++++++++--------------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index ea69bd9de7..b17ed8e60b 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -354,3 +354,7 @@ endif ifneq (,$(filter mpu9150,$(USEMODULE))) USEMODULE += xtimer endif + +ifneq (,$(filter sht11,$(USEMODULE))) + USEMODULE += xtimer +endif diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index 31ae8db8ba..6dbfd94051 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -37,9 +37,9 @@ extern "C" { #define SHT11_RESET (0x1E) //000 1111 0 /* time to wait after toggling the data line */ -#define SHT11_DATA_WAIT (HWTIMER_TICKS(1)) +#define SHT11_DATA_WAIT (1) /* time to wait after toggling the clock line */ -#define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) +#define SHT11_CLK_WAIT (1) /* set measurement timeout to 1 second */ #define SHT11_MEASURE_TIMEOUT (1000) diff --git a/drivers/sht11/sht11.c b/drivers/sht11/sht11.c index 20445d1a87..9e9c705afa 100644 --- a/drivers/sht11/sht11.c +++ b/drivers/sht11/sht11.c @@ -25,7 +25,7 @@ #include <stdio.h> #include <stdint.h> -#include "hwtimer.h" +#include "xtimer.h" #include "mutex.h" #include "sht11.h" #include "sht11-board.h" @@ -84,9 +84,9 @@ mutex_t sht11_mutex = MUTEX_INIT; static inline void clk_signal(void) { SHT11_SCK_HIGH; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); } /*---------------------------------------------------------------------------*/ @@ -101,11 +101,11 @@ static uint8_t write_byte(uint8_t value) for (i = 0; i < 8; i++) { if (value & BIT7) { SHT11_DATA_HIGH; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); } else { SHT11_DATA_LOW; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); } /* trigger clock signal */ @@ -117,7 +117,7 @@ static uint8_t write_byte(uint8_t value) /* wait for ack */ SHT11_DATA_IN; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); ack = SHT11_DATA; clk_signal(); @@ -131,13 +131,13 @@ static uint8_t read_byte(uint8_t ack) uint8_t value = 0; SHT11_DATA_IN; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); /* read value bit by bit */ for (i = 0; i < 8; i++) { value = value << 1; SHT11_SCK_HIGH; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); if (SHT11_DATA) { /* increase data by one when DATA is high */ @@ -145,7 +145,7 @@ static uint8_t read_byte(uint8_t ack) } SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); } /* send ack if necessary */ @@ -153,11 +153,11 @@ static uint8_t read_byte(uint8_t ack) if (ack) { SHT11_DATA_LOW; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); } else { SHT11_DATA_HIGH; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); } clk_signal(); @@ -179,27 +179,27 @@ static void transmission_start(void) /* set initial state */ SHT11_DATA_HIGH; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); SHT11_SCK_HIGH; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); SHT11_DATA_LOW; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); SHT11_SCK_HIGH; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); SHT11_DATA_HIGH; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); } /*---------------------------------------------------------------------------*/ static void connection_reset(void) @@ -211,9 +211,9 @@ static void connection_reset(void) */ uint8_t i; SHT11_DATA_HIGH; - hwtimer_wait(SHT11_DATA_WAIT); + xtimer_usleep(SHT11_DATA_WAIT); SHT11_SCK_LOW; - hwtimer_wait(SHT11_CLK_WAIT); + xtimer_usleep(SHT11_CLK_WAIT); for (i = 0; i < 9; i++) { clk_signal(); @@ -231,7 +231,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) transmission_start(); error = write_byte(mode); - hwtimer_wait(HWTIMER_TICKS(1000)); + xtimer_usleep(1000); /* wait untile sensor has finished measurement or timeout */ for (i = 0; (i < SHT11_MEASURE_TIMEOUT) && (!error); i++) { @@ -241,7 +241,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode) break; } - hwtimer_wait(HWTIMER_TICKS(1000)); + xtimer_usleep(1000); } error += ack; @@ -260,7 +260,7 @@ void sht11_init(void) { sht11_temperature_offset = 0; SHT11_INIT; - hwtimer_wait(11 * HWTIMER_TICKS(1000)); + xtimer_usleep(11 * 1000); } /*---------------------------------------------------------------------------*/ uint8_t sht11_read_status(uint8_t *p_value, uint8_t *p_checksum) -- GitLab