From 393c78b8e2826e445da7b5641ac7e4e3d2c5652b Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 9 Dec 2021 12:31:11 +0100 Subject: [PATCH] drivers/si1133: migrate to ztimer --- drivers/si1133/Kconfig | 2 +- drivers/si1133/Makefile.dep | 2 +- drivers/si1133/si1133.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/si1133/Kconfig b/drivers/si1133/Kconfig index a87efb8590..75b6500dfe 100644 --- a/drivers/si1133/Kconfig +++ b/drivers/si1133/Kconfig @@ -10,4 +10,4 @@ config MODULE_SI1133 depends on HAS_PERIPH_I2C depends on TEST_KCONFIG select MODULE_PERIPH_I2C - select MODULE_XTIMER + select ZTIMER_USEC diff --git a/drivers/si1133/Makefile.dep b/drivers/si1133/Makefile.dep index 095389d9a5..7211545eb5 100644 --- a/drivers/si1133/Makefile.dep +++ b/drivers/si1133/Makefile.dep @@ -1,2 +1,2 @@ -USEMODULE += xtimer +USEMODULE += ztimer_usec FEATURES_REQUIRED += periph_i2c diff --git a/drivers/si1133/si1133.c b/drivers/si1133/si1133.c index 5195943f96..15cf097500 100644 --- a/drivers/si1133/si1133.c +++ b/drivers/si1133/si1133.c @@ -24,7 +24,8 @@ #include #include -#include "xtimer.h" +#include "timex.h" +#include "ztimer.h" #include "periph/i2c.h" @@ -86,7 +87,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command) if (command == SI1133_CMD_FORCE) { /* Wait for the expected force acquisition time. */ - xtimer_usleep(_si1133_force_time_us(dev)); + ztimer_sleep(ZTIMER_USEC, _si1133_force_time_us(dev)); } if (command == SI1133_CMD_RESET_SW) { @@ -94,7 +95,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command) dev->cmd_counter = 0x0f; /* Reset command puts the device in "Initialization Mode" which requires * us to wait until the device is ready. */ - xtimer_msleep(SI1133_STARTUP_TIME_MS); + ztimer_sleep(ZTIMER_USEC, SI1133_STARTUP_TIME_MS * US_PER_MS); } else if (command == SI1133_CMD_RESET_CMD_CTR) { /* The reset cmd_counter command, well, resets it to 0. */ @@ -106,7 +107,7 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command) } uint8_t new_cmd_ctr; - xtimer_ticks32_t start_time; + ztimer_now_t start_time; bool retry = false; while (1) { ret = i2c_read_reg(dev->i2c_dev, dev->address, SI1133_REG_RESPONSE0, @@ -142,22 +143,21 @@ static int _si1133_run_command(si1133_t *dev, uint8_t command) } /* The command didn't yet finish in this case so it should be in running * state and we need to retry the loop with a timeout. This avoids - * calling xtimer for commands that are immediate. */ + * calling ztimer for commands that are immediate. */ if (retry) { - if (xtimer_usec_from_ticks(xtimer_diff(xtimer_now(), start_time)) - > SI1133_COMMAND_TIMEOUT_USEC) { + if (ztimer_now(ZTIMER_USEC) - start_time > SI1133_COMMAND_TIMEOUT_USEC) { DEBUG("[si1133] Command 0x%.2x timeout.\n", (unsigned)command); return SI1133_ERR_LOGIC; } } else { retry = true; - start_time = xtimer_now(); + start_time = ztimer_now(ZTIMER_USEC); } } if (retry) { DEBUG("[si1133] Command overtime: %" PRIu32 " us.\n", - xtimer_usec_from_ticks(xtimer_diff(xtimer_now(), start_time))); + ztimer_now(ZTIMER_USEC) - start_time); } return SI1133_OK; } @@ -320,7 +320,7 @@ si1133_ret_code_t si1133_init(si1133_t *dev, const si1133_params_t *params) /* After leaving "Off Mode" the SI1133 enters an "Initialization Mode" for * a period of time in which it can't be reached over I2C. After this time * the device will be in Standby Mode. */ - xtimer_msleep(SI1133_STARTUP_TIME_MS); + ztimer_sleep(ZTIMER_USEC, SI1133_STARTUP_TIME_MS * US_PER_MS); i2c_acquire(params->i2c_dev);