drivers: fxos8700: Fix sensor_attr_set behavior

It is necessary to put the device in standby to change the contents of
CTRL_REG1. This register is used to change the sampling frequency.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-06-14 22:41:12 -07:00 committed by Maureen Helm
commit e31d2ab6b4

View file

@ -69,9 +69,20 @@ int fxos8700_set_odr(const struct device *dev, const struct sensor_value *val)
LOG_DBG("Set ODR to 0x%x", (uint8_t)dr);
/*
* Modify FXOS8700_REG_CTRLREG1 can only occur when the device
* is in standby mode.
*/
if (fxos8700_set_power(dev, FXOS8700_POWER_STANDBY)) {
LOG_ERR("Could not set standby");
return -EIO;
}
/* Change the attribute and activate the device. */
return i2c_reg_update_byte(data->i2c, config->i2c_address,
FXOS8700_REG_CTRLREG1,
FXOS8700_CTRLREG1_DR_MASK, (uint8_t)dr);
FXOS8700_REG_CTRLREG1,
FXOS8700_CTRLREG1_DR_MASK | FXOS8700_CTRLREG1_ACTIVE_MASK,
(uint8_t)dr | FXOS8700_POWER_ACTIVE);
}
static int fxos8700_set_mt_ths(const struct device *dev,