drivers: sensor: ccs811: reset sensor when driver is initialized
The CCS811 has a measurement lifecycle that includes certain timing constraints, including that calibration constants should not be applied until the conditioning period has completed. If a device resets but the CCS811 remains the process of inspecting current state and initializing the device properly can be complicated. Simplify this by forcing a reset of the device when the driver is initialized. Should this cause hardship the necessary logic and infrastructure to record time-of-last-reset across reboots and verify measurement mode/baseline consistency can be added at that point. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
parent
ff5ef271ee
commit
21e68d4b81
1 changed files with 24 additions and 0 deletions
|
@ -297,6 +297,30 @@ int ccs811_init(struct device *dev)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Reset the device. This saves having to deal with detecting
|
||||
* and validating any errors or configuration inconsistencies
|
||||
* after a reset that left the device running.
|
||||
*/
|
||||
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN
|
||||
gpio_pin_write(drv_data->gpio, DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN, 0);
|
||||
k_busy_wait(15); /* t_RESET */
|
||||
gpio_pin_write(drv_data->gpio, DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN, 1);
|
||||
#else
|
||||
{
|
||||
static u8_t const reset_seq[] = {
|
||||
0xFF, 0x11, 0xE5, 0x72, 0x8A,
|
||||
};
|
||||
|
||||
if (i2c_write(drv_data->i2c, reset_seq, sizeof(reset_seq),
|
||||
DT_INST_0_AMS_CCS811_BASE_ADDRESS) < 0) {
|
||||
LOG_ERR("Failed to issue SW reset");
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
k_sleep(20); /* t_START assuming recent power-on */
|
||||
|
||||
/* Switch device to application mode */
|
||||
ret = switch_to_app_mode(drv_data->i2c);
|
||||
if (ret) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue