drivers: sht11: use xtimer

This commit is contained in:
Kaspar Schleiser 2015-08-14 13:30:49 +02:00
parent cbd7d42e06
commit 4445d940ea
3 changed files with 30 additions and 26 deletions

View File

@ -354,3 +354,7 @@ endif
ifneq (,$(filter mpu9150,$(USEMODULE))) ifneq (,$(filter mpu9150,$(USEMODULE)))
USEMODULE += xtimer USEMODULE += xtimer
endif endif
ifneq (,$(filter sht11,$(USEMODULE)))
USEMODULE += xtimer
endif

View File

@ -37,9 +37,9 @@ extern "C" {
#define SHT11_RESET (0x1E) //000 1111 0 #define SHT11_RESET (0x1E) //000 1111 0
/* time to wait after toggling the data line */ /* 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 */ /* 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 */ /* set measurement timeout to 1 second */
#define SHT11_MEASURE_TIMEOUT (1000) #define SHT11_MEASURE_TIMEOUT (1000)

View File

@ -25,7 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include "hwtimer.h" #include "xtimer.h"
#include "mutex.h" #include "mutex.h"
#include "sht11.h" #include "sht11.h"
#include "sht11-board.h" #include "sht11-board.h"
@ -84,9 +84,9 @@ mutex_t sht11_mutex = MUTEX_INIT;
static inline void clk_signal(void) static inline void clk_signal(void)
{ {
SHT11_SCK_HIGH; SHT11_SCK_HIGH;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
SHT11_SCK_LOW; 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++) { for (i = 0; i < 8; i++) {
if (value & BIT7) { if (value & BIT7) {
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
} }
else { else {
SHT11_DATA_LOW; SHT11_DATA_LOW;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
} }
/* trigger clock signal */ /* trigger clock signal */
@ -117,7 +117,7 @@ static uint8_t write_byte(uint8_t value)
/* wait for ack */ /* wait for ack */
SHT11_DATA_IN; SHT11_DATA_IN;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
ack = SHT11_DATA; ack = SHT11_DATA;
clk_signal(); clk_signal();
@ -131,13 +131,13 @@ static uint8_t read_byte(uint8_t ack)
uint8_t value = 0; uint8_t value = 0;
SHT11_DATA_IN; SHT11_DATA_IN;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
/* read value bit by bit */ /* read value bit by bit */
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
value = value << 1; value = value << 1;
SHT11_SCK_HIGH; SHT11_SCK_HIGH;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
if (SHT11_DATA) { if (SHT11_DATA) {
/* increase data by one when DATA is high */ /* increase data by one when DATA is high */
@ -145,7 +145,7 @@ static uint8_t read_byte(uint8_t ack)
} }
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
} }
/* send ack if necessary */ /* send ack if necessary */
@ -153,11 +153,11 @@ static uint8_t read_byte(uint8_t ack)
if (ack) { if (ack) {
SHT11_DATA_LOW; SHT11_DATA_LOW;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
} }
else { else {
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
} }
clk_signal(); clk_signal();
@ -179,27 +179,27 @@ static void transmission_start(void)
/* set initial state */ /* set initial state */
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
SHT11_SCK_HIGH; SHT11_SCK_HIGH;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
SHT11_DATA_LOW; SHT11_DATA_LOW;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
SHT11_SCK_HIGH; SHT11_SCK_HIGH;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void connection_reset(void) static void connection_reset(void)
@ -211,9 +211,9 @@ static void connection_reset(void)
*/ */
uint8_t i; uint8_t i;
SHT11_DATA_HIGH; SHT11_DATA_HIGH;
hwtimer_wait(SHT11_DATA_WAIT); xtimer_usleep(SHT11_DATA_WAIT);
SHT11_SCK_LOW; SHT11_SCK_LOW;
hwtimer_wait(SHT11_CLK_WAIT); xtimer_usleep(SHT11_CLK_WAIT);
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
clk_signal(); clk_signal();
@ -231,7 +231,7 @@ static uint8_t measure(uint8_t *p_value, uint8_t *p_checksum, uint8_t mode)
transmission_start(); transmission_start();
error = write_byte(mode); error = write_byte(mode);
hwtimer_wait(HWTIMER_TICKS(1000)); xtimer_usleep(1000);
/* wait untile sensor has finished measurement or timeout */ /* wait untile sensor has finished measurement or timeout */
for (i = 0; (i < SHT11_MEASURE_TIMEOUT) && (!error); i++) { 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; break;
} }
hwtimer_wait(HWTIMER_TICKS(1000)); xtimer_usleep(1000);
} }
error += ack; error += ack;
@ -260,7 +260,7 @@ void sht11_init(void)
{ {
sht11_temperature_offset = 0; sht11_temperature_offset = 0;
SHT11_INIT; 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) uint8_t sht11_read_status(uint8_t *p_value, uint8_t *p_checksum)