pkg/driver_bme680: migrate to ztimer

This commit is contained in:
Alexandre Abadie 2021-12-01 14:59:38 +01:00
parent bb5aaa38ad
commit 25d1e2daa2
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
9 changed files with 23 additions and 14 deletions

View File

@ -9,7 +9,8 @@ menuconfig MODULE_BME680
bool "BME680 Temperature/Humidity/Pressure/Gas sensor" bool "BME680 Temperature/Humidity/Pressure/Gas sensor"
depends on TEST_KCONFIG depends on TEST_KCONFIG
select PACKAGE_DRIVER_BME680 select PACKAGE_DRIVER_BME680
select MODULE_XTIMER if MODULE_SAUL select MODULE_ZTIMER if MODULE_SAUL
select MODULE_ZTIMER_MSEC if MODULE_SAUL
if MODULE_BME680 if MODULE_BME680

View File

@ -1,7 +1,8 @@
USEPKG += driver_bme680 USEPKG += driver_bme680
ifneq (,$(filter saul%,$(USEMODULE))) ifneq (,$(filter saul%,$(USEMODULE)))
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
endif endif
ifneq (,$(filter bme680_i2c,$(USEMODULE))) ifneq (,$(filter bme680_i2c,$(USEMODULE)))

View File

@ -21,7 +21,7 @@
#include "saul.h" #include "saul.h"
#include "bme680.h" #include "bme680.h"
#include "bme680_params.h" #include "bme680_params.h"
#include "xtimer.h" #include "ztimer.h"
extern bme680_t bme680_devs_saul[BME680_NUMOF]; extern bme680_t bme680_devs_saul[BME680_NUMOF];
@ -65,7 +65,7 @@ static int _read(int dev)
if ((drt = bme680_get_duration(&bme680_devs_saul[dev])) < 0) { if ((drt = bme680_get_duration(&bme680_devs_saul[dev])) < 0) {
return BME680_INVALID; return BME680_INVALID;
} }
xtimer_msleep(drt); ztimer_sleep(ZTIMER_MSEC, drt);
bme680_field_data_t data; bme680_field_data_t data;
if ((res = bme680_get_data(&bme680_devs_saul[dev], &data)) != BME680_OK) { if ((res = bme680_get_data(&bme680_devs_saul[dev], &data)) != BME680_OK) {

View File

@ -9,6 +9,8 @@ config PACKAGE_DRIVER_BME680
bool "BME680 sensor driver package" bool "BME680 sensor driver package"
depends on TEST_KCONFIG depends on TEST_KCONFIG
select MODULE_DRIVER_BME680_CONTRIB select MODULE_DRIVER_BME680_CONTRIB
select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC
config MODULE_DRIVER_BME680_CONTRIB config MODULE_DRIVER_BME680_CONTRIB
bool bool

View File

@ -1 +1,3 @@
USEMODULE += ztimer
USEMODULE += ztimer_msec
USEMODULE += driver_bme680_contrib USEMODULE += driver_bme680_contrib

View File

@ -33,7 +33,7 @@
#include "periph/spi.h" #include "periph/spi.h"
#endif #endif
#include "xtimer.h" #include "ztimer.h"
#ifndef BME680_SPI_SPEED #ifndef BME680_SPI_SPEED
#define BME680_SPI_SPEED (SPI_CLK_1MHZ) #define BME680_SPI_SPEED (SPI_CLK_1MHZ)
@ -45,7 +45,7 @@
void bme680_ms_sleep(uint32_t msleep) void bme680_ms_sleep(uint32_t msleep)
{ {
xtimer_msleep(msleep); ztimer_sleep(ZTIMER_MSEC, msleep);
} }
#ifdef MODULE_PERIPH_I2C #ifdef MODULE_PERIPH_I2C

View File

@ -3,7 +3,8 @@ include ../Makefile.tests_common
DRIVER ?= bme680_i2c DRIVER ?= bme680_i2c
USEMODULE += $(DRIVER) USEMODULE += $(DRIVER)
USEMODULE += xtimer USEMODULE += ztimer
USEMODULE += ztimer_msec
ifeq ($(ENABLE_FP),1) ifeq ($(ENABLE_FP),1)
USEMODULE += bme680_fp USEMODULE += bme680_fp

View File

@ -1,4 +1,5 @@
# this file enables modules defined in Kconfig. Do not use this file for # this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration. # application configuration. This is only needed during migration.
CONFIG_MODULE_BME680=y CONFIG_MODULE_BME680=y
CONFIG_MODULE_XTIMER=y CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y

View File

@ -25,15 +25,16 @@
#include "bme680.h" #include "bme680.h"
#include "bme680_params.h" #include "bme680_params.h"
#include "mutex.h" #include "mutex.h"
#include "xtimer.h" #include "timex.h"
#include "ztimer.h"
#define BME680_TEST_PERIOD_US (5 * US_PER_SEC) #define BME680_TEST_PERIOD_MS (5 * MS_PER_SEC) /* 5s */
xtimer_t timer; ztimer_t timer;
static void _timer_cb(void *arg) static void _timer_cb(void *arg)
{ {
xtimer_set(&timer, BME680_TEST_PERIOD_US); ztimer_set(ZTIMER_MSEC, &timer, BME680_TEST_PERIOD_MS);
mutex_unlock(arg); mutex_unlock(arg);
} }
@ -64,7 +65,7 @@ int main(void)
timer.callback = _timer_cb; timer.callback = _timer_cb;
timer.arg = &timer_mtx; timer.arg = &timer_mtx;
xtimer_set(&timer, BME680_TEST_PERIOD_US); ztimer_set(ZTIMER_MSEC, &timer, BME680_TEST_PERIOD_MS);
while (1) while (1)
{ {
@ -76,7 +77,7 @@ int main(void)
/* get the duration for the measurement */ /* get the duration for the measurement */
int duration = bme680_get_duration(&dev[i]); int duration = bme680_get_duration(&dev[i]);
/* wait for the duration */ /* wait for the duration */
xtimer_msleep(duration); ztimer_sleep(ZTIMER_MSEC, duration);
/* read the data */ /* read the data */
int res = bme680_get_data(&dev[i], &data); int res = bme680_get_data(&dev[i], &data);