From 21e68d4b81d2868f15d6252103c8f21c5c583ee0 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Wed, 21 Nov 2018 08:37:52 -0600 Subject: [PATCH] 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 --- drivers/sensor/ccs811/ccs811.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/sensor/ccs811/ccs811.c b/drivers/sensor/ccs811/ccs811.c index a91daf65615..1ef21eaff14 100644 --- a/drivers/sensor/ccs811/ccs811.c +++ b/drivers/sensor/ccs811/ccs811.c @@ -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) {