Skip to content
Snippets Groups Projects
Commit cbd7d42e authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

drivers: mpu9150: use xtimer

parent 3edc40e4
No related branches found
No related tags found
No related merge requests found
...@@ -350,3 +350,7 @@ endif ...@@ -350,3 +350,7 @@ endif
ifneq (,$(filter lm75a,$(USEMODULE))) ifneq (,$(filter lm75a,$(USEMODULE)))
USEMODULE += xtimer USEMODULE += xtimer
endif endif
ifneq (,$(filter mpu9150,$(USEMODULE)))
USEMODULE += xtimer
endif
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "mpu9150.h" #include "mpu9150.h"
#include "mpu9150-regs.h" #include "mpu9150-regs.h"
#include "periph/i2c.h" #include "periph/i2c.h"
#include "hwtimer.h" #include "xtimer.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
...@@ -73,7 +73,7 @@ int mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr, ...@@ -73,7 +73,7 @@ int mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr,
/* Reset MPU9150 registers and afterwards wake up the chip */ /* Reset MPU9150 registers and afterwards wake up the chip */
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_RESET); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_RESET);
hwtimer_wait(HWTIMER_TICKS(MPU9150_RESET_SLEEP_US)); xtimer_usleep(MPU9150_RESET_SLEEP_US);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP);
/* 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 mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr, ...@@ -103,7 +103,7 @@ int mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr,
temp &= ~(MPU9150_PWR_ACCEL | MPU9150_PWR_GYRO); temp &= ~(MPU9150_PWR_ACCEL | MPU9150_PWR_GYRO);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, temp); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, temp);
i2c_release(dev->i2c_dev); i2c_release(dev->i2c_dev);
hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US)); xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
return 0; return 0;
} }
...@@ -144,7 +144,7 @@ int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf) ...@@ -144,7 +144,7 @@ int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
i2c_release(dev->i2c_dev); i2c_release(dev->i2c_dev);
dev->conf.accel_pwr = pwr_conf; dev->conf.accel_pwr = pwr_conf;
hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US)); xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
return 0; return 0;
} }
...@@ -192,7 +192,7 @@ int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf) ...@@ -192,7 +192,7 @@ int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
i2c_release(dev->i2c_dev); i2c_release(dev->i2c_dev);
dev->conf.gyro_pwr = pwr_conf; dev->conf.gyro_pwr = pwr_conf;
hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US)); xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
return 0; return 0;
} }
...@@ -237,7 +237,7 @@ int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf) ...@@ -237,7 +237,7 @@ int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
i2c_release(dev->i2c_dev); i2c_release(dev->i2c_dev);
dev->conf.compass_pwr = pwr_conf; dev->conf.compass_pwr = pwr_conf;
hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US)); xtimer_usleep(MPU9150_PWR_CHANGE_SLEEP_US);
return 0; return 0;
} }
...@@ -514,10 +514,10 @@ static int compass_init(mpu9150_t *dev) ...@@ -514,10 +514,10 @@ static int compass_init(mpu9150_t *dev)
/* Configure Power Down mode */ /* Configure Power Down mode */
i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN); i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN);
hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
/* Configure Fuse ROM access */ /* Configure Fuse ROM access */
i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_FUSE_ROM); i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_FUSE_ROM);
hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
/* Read sensitivity adjustment values from Fuse ROM */ /* Read sensitivity adjustment values from Fuse ROM */
i2c_read_regs(dev->i2c_dev, dev->comp_addr, COMPASS_ASAX_REG, data, 3); i2c_read_regs(dev->i2c_dev, dev->comp_addr, COMPASS_ASAX_REG, data, 3);
dev->conf.compass_x_adj = data[0]; dev->conf.compass_x_adj = data[0];
...@@ -525,7 +525,7 @@ static int compass_init(mpu9150_t *dev) ...@@ -525,7 +525,7 @@ static int compass_init(mpu9150_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, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN); i2c_write_reg(dev->i2c_dev, dev->comp_addr, COMPASS_CNTL_REG, MPU9150_COMP_POWER_DOWN);
hwtimer_wait(HWTIMER_TICKS(MPU9150_COMP_MODE_SLEEP_US)); xtimer_usleep(MPU9150_COMP_MODE_SLEEP_US);
/* 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);
...@@ -575,13 +575,13 @@ static void conf_bypass(mpu9150_t *dev, uint8_t bypass_enable) ...@@ -575,13 +575,13 @@ static void conf_bypass(mpu9150_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, dev->hw_addr, MPU9150_USER_CTRL_REG, data); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, data);
hwtimer_wait(HWTIMER_TICKS(MPU9150_BYPASS_SLEEP_US)); xtimer_usleep(MPU9150_BYPASS_SLEEP_US);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN);
} }
else { else {
data |= BIT_I2C_MST_EN; data |= BIT_I2C_MST_EN;
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, data); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, data);
hwtimer_wait(HWTIMER_TICKS(MPU9150_BYPASS_SLEEP_US)); xtimer_usleep(MPU9150_BYPASS_SLEEP_US);
i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, REG_RESET); i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, REG_RESET);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment