Skip to content

Commit cbb0585

Browse files
hollerdawgMaureenHelm
authored andcommitted
drivers: sensor: fxos8700: Keep current power mode when setting ODR
Setting the power mode to enabled causes other initialization to not occur. Restore the power mode set upon entry when exiting. Signed-off-by: Ryan Holleran <[email protected]>
1 parent a80b59e commit cbb0585

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/sensor/fxos8700/fxos8700.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static int fxos8700_set_odr(const struct device *dev,
2424
const struct fxos8700_config *config = dev->config;
2525
struct fxos8700_data *data = dev->data;
2626
uint8_t dr;
27+
enum fxos8700_power power;
2728

2829
#ifdef CONFIG_FXOS8700_MODE_HYBRID
2930
/* ODR is halved in hybrid mode */
@@ -72,18 +73,24 @@ static int fxos8700_set_odr(const struct device *dev,
7273

7374
/*
7475
* Modify FXOS8700_REG_CTRLREG1 can only occur when the device
75-
* is in standby mode.
76+
* is in standby mode. Get the current power mode to restore it later.
7677
*/
78+
if (fxos8700_get_power(dev, &power)) {
79+
LOG_ERR("Could not get power mode");
80+
return -EIO;
81+
}
82+
83+
/* Set standby power mode */
7784
if (fxos8700_set_power(dev, FXOS8700_POWER_STANDBY)) {
7885
LOG_ERR("Could not set standby");
7986
return -EIO;
8087
}
8188

82-
/* Change the attribute and activate the device. */
89+
/* Change the attribute and restore power mode. */
8390
return i2c_reg_update_byte(data->i2c, config->i2c_address,
8491
FXOS8700_REG_CTRLREG1,
8592
FXOS8700_CTRLREG1_DR_MASK | FXOS8700_CTRLREG1_ACTIVE_MASK,
86-
dr | FXOS8700_POWER_ACTIVE);
93+
dr | power);
8794
}
8895

8996
static int fxos8700_set_mt_ths(const struct device *dev,

0 commit comments

Comments
 (0)