From 9029e1caf929165d005a7be57b49ed609a15c424 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 2 Nov 2021 11:12:22 +0100 Subject: [PATCH 1/2] drivers/bmp180: migrate to ztimer --- drivers/bmp180/Kconfig | 3 ++- drivers/bmp180/Makefile.dep | 3 ++- drivers/bmp180/bmp180.c | 16 ++++++++-------- drivers/bmp180/bmp180_saul.c | 1 - drivers/bmp180/include/bmp180_internals.h | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/bmp180/Kconfig b/drivers/bmp180/Kconfig index b3b9bb2a87..110993d6db 100644 --- a/drivers/bmp180/Kconfig +++ b/drivers/bmp180/Kconfig @@ -10,4 +10,5 @@ config MODULE_BMP180 depends on HAS_PERIPH_I2C depends on TEST_KCONFIG select MODULE_PERIPH_I2C - select MODULE_XTIMER + select MODULE_ZTIMER + select MODULE_ZTIMER_MSEC diff --git a/drivers/bmp180/Makefile.dep b/drivers/bmp180/Makefile.dep index 9508a8aff7..40e4e2276c 100644 --- a/drivers/bmp180/Makefile.dep +++ b/drivers/bmp180/Makefile.dep @@ -1,2 +1,3 @@ FEATURES_REQUIRED += periph_i2c -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec diff --git a/drivers/bmp180/bmp180.c b/drivers/bmp180/bmp180.c index 041813914a..337cbad1a6 100644 --- a/drivers/bmp180/bmp180.c +++ b/drivers/bmp180/bmp180.c @@ -25,7 +25,7 @@ #include "bmp180_internals.h" #include "bmp180_params.h" #include "periph/i2c.h" -#include "xtimer.h" +#include "ztimer.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -65,7 +65,7 @@ int bmp180_init(bmp180_t *dev, const bmp180_params_t *params) } /* adding delay before reading calibration values to avoid timing issues */ - xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS); uint8_t buffer[22] = {0}; /* Read calibration values, using contiguous register addresses */ @@ -187,7 +187,7 @@ static int _read_ut(const bmp180_t *dev, int32_t *output) uint8_t ut[2] = {0}; uint8_t control[2] = { BMP180_REGISTER_CONTROL, BMP180_TEMPERATURE_COMMAND }; i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); - xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS); if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, ut, 2, 0) < 0) { DEBUG("[Error] Cannot read uncompensated temperature.\n"); i2c_release(DEV_I2C); @@ -209,19 +209,19 @@ static int _read_up(const bmp180_t *dev, int32_t *output) i2c_write_bytes(DEV_I2C, DEV_ADDR, control, 2, 0); switch (OVERSAMPLING) { case BMP180_ULTRALOWPOWER: - xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS); break; case BMP180_STANDARD: - xtimer_usleep(BMP180_STANDARD_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_STANDARD_DELAY_MS); break; case BMP180_HIGHRES: - xtimer_usleep(BMP180_HIGHRES_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_HIGHRES_DELAY_MS); break; case BMP180_ULTRAHIGHRES: - xtimer_usleep(BMP180_ULTRAHIGHRES_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRAHIGHRES_DELAY_MS); break; default: - xtimer_usleep(BMP180_ULTRALOWPOWER_DELAY); + ztimer_sleep(ZTIMER_MSEC, BMP180_ULTRALOWPOWER_DELAY_MS); break; } if (i2c_read_regs(DEV_I2C, DEV_ADDR, BMP180_REGISTER_DATA, up, 3, 0) < 0) { diff --git a/drivers/bmp180/bmp180_saul.c b/drivers/bmp180/bmp180_saul.c index 7a5076d44f..fe82a4baf6 100644 --- a/drivers/bmp180/bmp180_saul.c +++ b/drivers/bmp180/bmp180_saul.c @@ -23,7 +23,6 @@ #include "saul.h" #include "bmp180.h" -#include "xtimer.h" static int read_temperature(const void *dev, phydat_t *res) { diff --git a/drivers/bmp180/include/bmp180_internals.h b/drivers/bmp180/include/bmp180_internals.h index 5fd8007765..768f459f4f 100644 --- a/drivers/bmp180/include/bmp180_internals.h +++ b/drivers/bmp180/include/bmp180_internals.h @@ -47,10 +47,10 @@ extern "C" { * @name Oversampling modes delays (micros) * @{ */ -#define BMP180_ULTRALOWPOWER_DELAY (5000UL) -#define BMP180_STANDARD_DELAY (8000UL) -#define BMP180_HIGHRES_DELAY (14000UL) -#define BMP180_ULTRAHIGHRES_DELAY (26000UL) +#define BMP180_ULTRALOWPOWER_DELAY_MS (5UL) /**< Ultra low power delay (ms) */ +#define BMP180_STANDARD_DELAY_MS (8UL) /**< Standard resolution delay (ms) */ +#define BMP180_HIGHRES_DELAY_MS (14UL) /**< High resolution delay (ms) */ +#define BMP180_ULTRAHIGHRES_DELAY_MS (26UL) /**< Ultra high resolution delay (ms) */ /** @} */ #ifdef __cplusplus From 546283fd05fb896f98bc35e8b8f871d644259e7c Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 2 Nov 2021 11:12:33 +0100 Subject: [PATCH 2/2] tests/driver_bmp180: migrate to ztimer --- tests/driver_bmp180/Makefile | 3 ++- tests/driver_bmp180/app.config.test | 3 ++- tests/driver_bmp180/main.c | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/driver_bmp180/Makefile b/tests/driver_bmp180/Makefile index 9e707a856f..c26d71004f 100644 --- a/tests/driver_bmp180/Makefile +++ b/tests/driver_bmp180/Makefile @@ -1,7 +1,8 @@ include ../Makefile.tests_common USEMODULE += bmp180 -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec # set default altitude TEST_ALTITUDE ?= 158 # altitude in Polytechnique School campus diff --git a/tests/driver_bmp180/app.config.test b/tests/driver_bmp180/app.config.test index 16ee22e6da..f20a36fb0a 100644 --- a/tests/driver_bmp180/app.config.test +++ b/tests/driver_bmp180/app.config.test @@ -1,4 +1,5 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. CONFIG_MODULE_BMP180=y -CONFIG_MODULE_XTIMER=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_MSEC=y diff --git a/tests/driver_bmp180/main.c b/tests/driver_bmp180/main.c index 27fc00ee21..3e86ab34d0 100644 --- a/tests/driver_bmp180/main.c +++ b/tests/driver_bmp180/main.c @@ -24,7 +24,8 @@ #include "bmp180.h" #include "bmp180_params.h" -#include "xtimer.h" +#include "timex.h" +#include "ztimer.h" #include "board.h" int main(void) @@ -84,7 +85,7 @@ int main(void) (unsigned long)pressure_0 / 100, (int)(pressure_0 % 100), (int)altitude); - xtimer_sleep(2); + ztimer_sleep(ZTIMER_MSEC, 2 * MS_PER_SEC); } return 0;