1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

drivers/lsm6dsl: add power up/down functions

This commit is contained in:
Vincent Dupont 2017-08-09 09:53:05 +02:00
parent 39426bba7d
commit e75868db32
2 changed files with 146 additions and 0 deletions

View File

@ -173,6 +173,46 @@ int lsm6dsl_read_gyro(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data);
*/
int lsm6dsl_read_temp(const lsm6dsl_t *dev, int16_t *data);
/**
* @brief Power down accelerometer
*
* @param[in] dev device to power down
*
* @return LSM6DSL_OK on success
* @return < 0 on error
*/
int lsm6dsl_acc_power_down(const lsm6dsl_t *dev);
/**
* @brief Power down gyroscope
*
* @param[in] dev device to power down
*
* @return LSM6DSL_OK on success
* @return < 0 on error
*/
int lsm6dsl_gyro_power_down(const lsm6dsl_t *dev);
/**
* @brief Power up accelerometer
*
* @param[in] dev device to power up
*
* @return LSM6DSL_OK on success
* @return < 0 on error
*/
int lsm6dsl_acc_power_up(const lsm6dsl_t *dev);
/**
* @brief Power up gyroscope
*
* @param[in] dev device to power up
*
* @return LSM6DSL_OK on success
* @return < 0 on error
*/
int lsm6dsl_gyro_power_up(const lsm6dsl_t *dev);
#ifdef __cplusplus
}
#endif

View File

@ -195,3 +195,109 @@ int lsm6dsl_read_temp(const lsm6dsl_t *dev, int16_t *data)
return LSM6DSL_OK;
}
int lsm6dsl_acc_power_down(const lsm6dsl_t *dev)
{
int res;
uint8_t tmp;
i2c_acquire(BUS);
res = i2c_read_reg(BUS, ADDR, LSM6DSL_REG_CTRL1_XL, &tmp);
if (res != 1) {
i2c_release(BUS);
DEBUG("[ERROR] lsm6dsl_acc_power_down\n");
return -LSM6DSL_ERROR_BUS;
}
tmp &= ~(LSM6DSL_CTRL_ODR_MASK);
res = i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL1_XL, tmp);
i2c_release(BUS);
if (res != 1) {
DEBUG("[ERROR] lsm6dsl_acc_power_down\n");
return -LSM6DSL_ERROR_BUS;
}
return LSM6DSL_OK;
}
int lsm6dsl_gyro_power_down(const lsm6dsl_t *dev)
{
int res;
uint8_t tmp;
i2c_acquire(BUS);
res = i2c_read_reg(BUS, ADDR, LSM6DSL_REG_CTRL2_G, &tmp);
if (res != 1) {
i2c_release(BUS);
DEBUG("[ERROR] lsm6dsl_gyro_power_down\n");
return -LSM6DSL_ERROR_BUS;
}
tmp &= ~(LSM6DSL_CTRL_ODR_MASK);
res = i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL2_G, tmp);
i2c_release(BUS);
if (res != 1) {
DEBUG("[ERROR] lsm6dsl_gyro_power_down\n");
return -LSM6DSL_ERROR_BUS;
}
return LSM6DSL_OK;
}
int lsm6dsl_acc_power_up(const lsm6dsl_t *dev)
{
int res;
uint8_t tmp;
i2c_acquire(BUS);
res = i2c_read_reg(BUS, ADDR, LSM6DSL_REG_CTRL1_XL, &tmp);
if (res != 1) {
i2c_release(BUS);
DEBUG("[ERROR] lsm6dsl_acc_power_up\n");
return -LSM6DSL_ERROR_BUS;
}
tmp &= ~(LSM6DSL_CTRL_ODR_MASK);
tmp |= dev->params.acc_odr << LSM6DSL_CTRL_ODR_SHIFT;
res = i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL1_XL, tmp);
i2c_release(BUS);
if (res != 1) {
DEBUG("[ERROR] lsm6dsl_acc_power_up\n");
return -LSM6DSL_ERROR_BUS;
}
return LSM6DSL_OK;
}
int lsm6dsl_gyro_power_up(const lsm6dsl_t *dev)
{
int res;
uint8_t tmp;
i2c_acquire(BUS);
res = i2c_read_reg(BUS, ADDR, LSM6DSL_REG_CTRL2_G, &tmp);
if (res != 1) {
i2c_release(BUS);
DEBUG("[ERROR] lsm6dsl_gyro_power_up\n");
return -LSM6DSL_ERROR_BUS;
}
tmp &= ~(LSM6DSL_CTRL_ODR_MASK);
tmp |= dev->params.gyro_odr << LSM6DSL_CTRL_ODR_SHIFT;
res = i2c_write_reg(BUS, ADDR, LSM6DSL_REG_CTRL2_G, tmp);
i2c_release(BUS);
if (res != 1) {
DEBUG("[ERROR] lsm6dsl_gyro_power_up\n");
return -LSM6DSL_ERROR_BUS;
}
return LSM6DSL_OK;
}