diff --git a/drivers/mpu9x50/Kconfig b/drivers/mpu9x50/Kconfig index 27d2c7ffa9..54213effac 100644 --- a/drivers/mpu9x50/Kconfig +++ b/drivers/mpu9x50/Kconfig @@ -28,6 +28,7 @@ config MODULE_MPU9X50 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/mpu9x50/Makefile.dep b/drivers/mpu9x50/Makefile.dep index 9508a8aff7..40e4e2276c 100644 --- a/drivers/mpu9x50/Makefile.dep +++ b/drivers/mpu9x50/Makefile.dep @@ -1,2 +1,3 @@ FEATURES_REQUIRED += periph_i2c -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec diff --git a/drivers/mpu9x50/include/mpu9x50_internal.h b/drivers/mpu9x50/include/mpu9x50_internal.h index 3c03479c4b..27ded883a3 100644 --- a/drivers/mpu9x50/include/mpu9x50_internal.h +++ b/drivers/mpu9x50/include/mpu9x50_internal.h @@ -43,10 +43,10 @@ extern "C" { * @name Sleep times in microseconds * @{ */ -#define MPU9X50_COMP_MODE_SLEEP_US (1000) -#define MPU9X50_BYPASS_SLEEP_US (3000) -#define MPU9X50_PWR_CHANGE_SLEEP_US (50000) -#define MPU9X50_RESET_SLEEP_US (100000) +#define MPU9X50_COMP_MODE_SLEEP_MS (1) /**< 1ms sleep for comp mode */ +#define MPU9X50_BYPASS_SLEEP_MS (3) /**< 3ms sleep for bypass */ +#define MPU9X50_PWR_CHANGE_SLEEP_MS (50) /**< 50ms sleep to change power */ +#define MPU9X50_RESET_SLEEP_MS (100) /**< 100ms sleep during driver reset */ /** @} */ /** diff --git a/drivers/mpu9x50/mpu9x50.c b/drivers/mpu9x50/mpu9x50.c index 20017a998b..fcb9be2f83 100644 --- a/drivers/mpu9x50/mpu9x50.c +++ b/drivers/mpu9x50/mpu9x50.c @@ -24,7 +24,7 @@ #include "mpu9x50_regs.h" #include "mpu9x50_internal.h" #include "periph/i2c.h" -#include "xtimer.h" +#include "ztimer.h" #include "byteorder.h" #define ENABLE_DEBUG 0 @@ -73,7 +73,7 @@ int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params) /* Reset MPU9X50 registers and afterwards wake up the chip */ i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_RESET, 0); - xtimer_usleep(MPU9X50_RESET_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_RESET_SLEEP_MS); i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_1_REG, MPU9X50_PWR_WAKEUP, 0); /* Release the bus, it is acquired again inside each function */ @@ -103,7 +103,7 @@ int mpu9x50_init(mpu9x50_t *dev, const mpu9x50_params_t *params) temp &= ~(MPU9X50_PWR_ACCEL | MPU9X50_PWR_GYRO); i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, temp, 0); i2c_release(DEV_I2C); - xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS); return 0; } @@ -142,7 +142,7 @@ int mpu9x50_set_accel_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf) i2c_release(DEV_I2C); dev->conf.accel_pwr = pwr_conf; - xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS); return 0; } @@ -188,7 +188,7 @@ int mpu9x50_set_gyro_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf) i2c_release(DEV_I2C); dev->conf.gyro_pwr = pwr_conf; - xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS); return 0; } @@ -231,7 +231,7 @@ int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf) i2c_release(DEV_I2C); dev->conf.compass_pwr = pwr_conf; - xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS); return 0; } @@ -492,10 +492,10 @@ static int compass_init(mpu9x50_t *dev) /* Configure Power Down mode */ i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0); - xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_COMP_MODE_SLEEP_MS); /* Configure Fuse ROM access */ i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_FUSE_ROM, 0); - xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_COMP_MODE_SLEEP_MS); /* Read sensitivity adjustment values from Fuse ROM */ i2c_read_regs(DEV_I2C, DEV_COMP_ADDR, COMPASS_ASAX_REG, data, 3, 0); dev->conf.compass_x_adj = data[0]; @@ -503,7 +503,7 @@ static int compass_init(mpu9x50_t *dev) dev->conf.compass_z_adj = data[2]; /* Configure Power Down mode again */ i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0); - xtimer_usleep(MPU9X50_COMP_MODE_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_COMP_MODE_SLEEP_MS); /* Disable Bypass Mode to configure MPU as master to the compass */ conf_bypass(dev, 0); @@ -553,13 +553,13 @@ static void conf_bypass(const mpu9x50_t *dev, uint8_t bypass_enable) if (bypass_enable) { data &= ~(BIT_I2C_MST_EN); i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0); - xtimer_usleep(MPU9X50_BYPASS_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_BYPASS_SLEEP_MS); i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN, 0); } else { data |= BIT_I2C_MST_EN; i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0); - xtimer_usleep(MPU9X50_BYPASS_SLEEP_US); + ztimer_sleep(ZTIMER_MSEC, MPU9X50_BYPASS_SLEEP_MS); i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, REG_RESET, 0); } } diff --git a/tests/driver_mpu9x50/Makefile b/tests/driver_mpu9x50/Makefile index 262299eb8c..840ab47517 100644 --- a/tests/driver_mpu9x50/Makefile +++ b/tests/driver_mpu9x50/Makefile @@ -3,6 +3,7 @@ include ../Makefile.tests_common DRIVER ?= mpu9150 USEMODULE += $(DRIVER) -USEMODULE += xtimer +USEMODULE += ztimer +USEMODULE += ztimer_msec include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_mpu9x50/app.config.test b/tests/driver_mpu9x50/app.config.test index 7ae4813113..edb625451b 100644 --- a/tests/driver_mpu9x50/app.config.test +++ b/tests/driver_mpu9x50/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_MPU9150=y -CONFIG_MODULE_XTIMER=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_MSEC=y diff --git a/tests/driver_mpu9x50/main.c b/tests/driver_mpu9x50/main.c index cc94aee703..6e5b5a6ff9 100644 --- a/tests/driver_mpu9x50/main.c +++ b/tests/driver_mpu9x50/main.c @@ -23,14 +23,13 @@ #include #include -#include "xtimer.h" +#include "timex.h" +#include "ztimer.h" #include "board.h" #include "mpu9x50.h" #include "mpu9x50_params.h" -#define SLEEP_USEC (1000 * 1000u) - int main(void) { mpu9x50_t dev; @@ -92,7 +91,7 @@ int main(void) printf("Temperature [milli deg] : %"PRId32"\n", temperature); printf("\n+-------------------------------------+\n"); - xtimer_usleep(SLEEP_USEC); + ztimer_sleep(ZTIMER_MSEC, MS_PER_SEC); /* 1s delay */ } return 0;