From aa65feab257640d5cb9a6ec435494a8a6f492046 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 1 Dec 2021 17:13:38 +0100 Subject: [PATCH] drivers/si114x: migrate to ztimer --- drivers/si114x/Kconfig | 3 ++- drivers/si114x/Makefile.dep | 3 ++- drivers/si114x/include/si114x_internals.h | 4 ++-- drivers/si114x/si114x.c | 8 ++++---- tests/driver_si114x/Makefile | 3 +++ tests/driver_si114x/app.config.test | 3 +++ tests/driver_si114x/main.c | 5 +++-- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/si114x/Kconfig b/drivers/si114x/Kconfig index e6eb07c3b9..099f545860 100644 --- a/drivers/si114x/Kconfig +++ b/drivers/si114x/Kconfig @@ -31,6 +31,7 @@ config MODULE_SI114X bool depends on HAS_PERIPH_I2C select MODULE_PERIPH_I2C - select MODULE_XTIMER + select MODULE_ZTIMER + select MODULE_ZTIMER_MSEC endif # TEST_KCONFIG diff --git a/drivers/si114x/Makefile.dep b/drivers/si114x/Makefile.dep index 095389d9a5..f053614553 100644 --- a/drivers/si114x/Makefile.dep +++ b/drivers/si114x/Makefile.dep @@ -1,2 +1,3 @@ -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec FEATURES_REQUIRED += periph_i2c diff --git a/drivers/si114x/include/si114x_internals.h b/drivers/si114x/include/si114x_internals.h index bb7081b921..c7b71d46e8 100644 --- a/drivers/si114x/include/si114x_internals.h +++ b/drivers/si114x/include/si114x_internals.h @@ -161,8 +161,8 @@ extern "C" { #define SI1145_ID (0x45) #define SI1146_ID (0x46) #define SI1147_ID (0x47) -#define SI114X_STARTUP_TIME (25000UL) /* 25ms */ -#define SI114X_WAIT_10MS (10000UL) /* 10ms */ +#define SI114X_STARTUP_TIME_MS (25UL) /**< startup time (25ms) */ +#define SI114X_WAIT_10MS (10UL) /* 10ms */ #define SI114X_INIT_VALUE (0x17) #define SI114X_UCOEF0_DEFAULT (0x29) #define SI114X_UCOEF1_DEFAULT (0x89) diff --git a/drivers/si114x/si114x.c b/drivers/si114x/si114x.c index bf4e1f41f9..e3d98bac67 100644 --- a/drivers/si114x/si114x.c +++ b/drivers/si114x/si114x.c @@ -24,7 +24,7 @@ #include #include -#include "xtimer.h" +#include "ztimer.h" #include "periph/i2c.h" @@ -50,7 +50,7 @@ int8_t si114x_init(si114x_t *dev, const si114x_params_t *params) dev->params = *params; /* wait before sensor is ready */ - xtimer_usleep(SI114X_STARTUP_TIME); + ztimer_sleep(ZTIMER_MSEC, SI114X_STARTUP_TIME_MS); /* acquire exclusive access */ i2c_acquire(DEV_I2C); @@ -178,12 +178,12 @@ void _reset(si114x_t *dev) /* perform RESET command */ i2c_write_reg(DEV_I2C, SI114X_ADDR, SI114X_REG_COMMAND, SI114X_RESET, 0); - xtimer_usleep(SI114X_WAIT_10MS); + ztimer_sleep(ZTIMER_MSEC, SI114X_WAIT_10MS); /* write HW_KEY for proper operation */ i2c_write_reg(DEV_I2C, SI114X_ADDR, SI114X_REG_HW_KEY, SI114X_INIT_VALUE, 0); - xtimer_usleep(SI114X_WAIT_10MS); + ztimer_sleep(ZTIMER_MSEC, SI114X_WAIT_10MS); } void _initialize(si114x_t *dev) diff --git a/tests/driver_si114x/Makefile b/tests/driver_si114x/Makefile index 2392aab53e..6a83ecc53f 100644 --- a/tests/driver_si114x/Makefile +++ b/tests/driver_si114x/Makefile @@ -1,5 +1,8 @@ include ../Makefile.tests_common +USEMODULE += ztimer +USEMODULE += ztimer_msec + # This test should also work with Si1146 and Si1147 variants. USEMODULE += si1145 diff --git a/tests/driver_si114x/app.config.test b/tests/driver_si114x/app.config.test index bfa15577a7..810a7a6bdb 100644 --- a/tests/driver_si114x/app.config.test +++ b/tests/driver_si114x/app.config.test @@ -1,5 +1,8 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_MSEC=y + # This test should also work with Si1146 and Si1147 variants. CONFIG_MODULE_SI1145=y diff --git a/tests/driver_si114x/main.c b/tests/driver_si114x/main.c index 57dfdf47f8..0c7d4eb8c2 100644 --- a/tests/driver_si114x/main.c +++ b/tests/driver_si114x/main.c @@ -25,7 +25,8 @@ #include "si114x.h" #include "si114x_params.h" -#include "xtimer.h" +#include "timex.h" +#include "ztimer.h" #include "board.h" static si114x_t dev; @@ -63,7 +64,7 @@ int main(void) si114x_read_response(&dev)); /* 2 seconds delay between measures */ - xtimer_sleep(2); + ztimer_sleep(ZTIMER_MSEC, 2 * MS_PER_SEC); } return 0;