mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/mpu9x50: migrate to ztimer
This commit is contained in:
parent
f4474ed817
commit
3a8a543a0c
@ -28,6 +28,7 @@ config MODULE_MPU9X50
|
|||||||
bool
|
bool
|
||||||
depends on HAS_PERIPH_I2C
|
depends on HAS_PERIPH_I2C
|
||||||
select MODULE_PERIPH_I2C
|
select MODULE_PERIPH_I2C
|
||||||
select MODULE_XTIMER
|
select MODULE_ZTIMER
|
||||||
|
select MODULE_ZTIMER_MSEC
|
||||||
|
|
||||||
endif # TEST_KCONFIG
|
endif # TEST_KCONFIG
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
FEATURES_REQUIRED += periph_i2c
|
FEATURES_REQUIRED += periph_i2c
|
||||||
USEMODULE += xtimer
|
USEMODULE += ztimer
|
||||||
|
USEMODULE += ztimer_msec
|
||||||
|
@ -43,10 +43,10 @@ extern "C" {
|
|||||||
* @name Sleep times in microseconds
|
* @name Sleep times in microseconds
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define MPU9X50_COMP_MODE_SLEEP_US (1000)
|
#define MPU9X50_COMP_MODE_SLEEP_MS (1) /**< 1ms sleep for comp mode */
|
||||||
#define MPU9X50_BYPASS_SLEEP_US (3000)
|
#define MPU9X50_BYPASS_SLEEP_MS (3) /**< 3ms sleep for bypass */
|
||||||
#define MPU9X50_PWR_CHANGE_SLEEP_US (50000)
|
#define MPU9X50_PWR_CHANGE_SLEEP_MS (50) /**< 50ms sleep to change power */
|
||||||
#define MPU9X50_RESET_SLEEP_US (100000)
|
#define MPU9X50_RESET_SLEEP_MS (100) /**< 100ms sleep during driver reset */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "mpu9x50_regs.h"
|
#include "mpu9x50_regs.h"
|
||||||
#include "mpu9x50_internal.h"
|
#include "mpu9x50_internal.h"
|
||||||
#include "periph/i2c.h"
|
#include "periph/i2c.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer.h"
|
||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
|
|
||||||
#define ENABLE_DEBUG 0
|
#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 */
|
/* 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);
|
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);
|
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 */
|
/* 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);
|
temp &= ~(MPU9X50_PWR_ACCEL | MPU9X50_PWR_GYRO);
|
||||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, temp, 0);
|
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_PWR_MGMT_2_REG, temp, 0);
|
||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ int mpu9x50_set_accel_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
|||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
|
|
||||||
dev->conf.accel_pwr = pwr_conf;
|
dev->conf.accel_pwr = pwr_conf;
|
||||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ int mpu9x50_set_gyro_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
|||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
|
|
||||||
dev->conf.gyro_pwr = pwr_conf;
|
dev->conf.gyro_pwr = pwr_conf;
|
||||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf)
|
|||||||
i2c_release(DEV_I2C);
|
i2c_release(DEV_I2C);
|
||||||
|
|
||||||
dev->conf.compass_pwr = pwr_conf;
|
dev->conf.compass_pwr = pwr_conf;
|
||||||
xtimer_usleep(MPU9X50_PWR_CHANGE_SLEEP_US);
|
ztimer_sleep(ZTIMER_MSEC, MPU9X50_PWR_CHANGE_SLEEP_MS);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -492,10 +492,10 @@ static int compass_init(mpu9x50_t *dev)
|
|||||||
|
|
||||||
/* Configure Power Down mode */
|
/* Configure Power Down mode */
|
||||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0);
|
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 */
|
/* Configure Fuse ROM access */
|
||||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_FUSE_ROM, 0);
|
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 */
|
/* Read sensitivity adjustment values from Fuse ROM */
|
||||||
i2c_read_regs(DEV_I2C, DEV_COMP_ADDR, COMPASS_ASAX_REG, data, 3, 0);
|
i2c_read_regs(DEV_I2C, DEV_COMP_ADDR, COMPASS_ASAX_REG, data, 3, 0);
|
||||||
dev->conf.compass_x_adj = data[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];
|
dev->conf.compass_z_adj = data[2];
|
||||||
/* Configure Power Down mode again */
|
/* Configure Power Down mode again */
|
||||||
i2c_write_reg(DEV_I2C, DEV_COMP_ADDR, COMPASS_CNTL_REG, MPU9X50_COMP_POWER_DOWN, 0);
|
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 */
|
/* Disable Bypass Mode to configure MPU as master to the compass */
|
||||||
conf_bypass(dev, 0);
|
conf_bypass(dev, 0);
|
||||||
@ -553,13 +553,13 @@ static void conf_bypass(const mpu9x50_t *dev, uint8_t bypass_enable)
|
|||||||
if (bypass_enable) {
|
if (bypass_enable) {
|
||||||
data &= ~(BIT_I2C_MST_EN);
|
data &= ~(BIT_I2C_MST_EN);
|
||||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0);
|
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);
|
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data |= BIT_I2C_MST_EN;
|
data |= BIT_I2C_MST_EN;
|
||||||
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_USER_CTRL_REG, data, 0);
|
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);
|
i2c_write_reg(DEV_I2C, DEV_ADDR, MPU9X50_INT_PIN_CFG_REG, REG_RESET, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ include ../Makefile.tests_common
|
|||||||
DRIVER ?= mpu9150
|
DRIVER ?= mpu9150
|
||||||
|
|
||||||
USEMODULE += $(DRIVER)
|
USEMODULE += $(DRIVER)
|
||||||
USEMODULE += xtimer
|
USEMODULE += ztimer
|
||||||
|
USEMODULE += ztimer_msec
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
@ -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_MPU9150=y
|
CONFIG_MODULE_MPU9150=y
|
||||||
CONFIG_MODULE_XTIMER=y
|
CONFIG_MODULE_ZTIMER=y
|
||||||
|
CONFIG_MODULE_ZTIMER_MSEC=y
|
||||||
|
@ -23,14 +23,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "timex.h"
|
||||||
|
#include "ztimer.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#include "mpu9x50.h"
|
#include "mpu9x50.h"
|
||||||
#include "mpu9x50_params.h"
|
#include "mpu9x50_params.h"
|
||||||
|
|
||||||
#define SLEEP_USEC (1000 * 1000u)
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
mpu9x50_t dev;
|
mpu9x50_t dev;
|
||||||
@ -92,7 +91,7 @@ int main(void)
|
|||||||
printf("Temperature [milli deg] : %"PRId32"\n", temperature);
|
printf("Temperature [milli deg] : %"PRId32"\n", temperature);
|
||||||
printf("\n+-------------------------------------+\n");
|
printf("\n+-------------------------------------+\n");
|
||||||
|
|
||||||
xtimer_usleep(SLEEP_USEC);
|
ztimer_sleep(ZTIMER_MSEC, MS_PER_SEC); /* 1s delay */
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user