From 463bec174917fe7a9cf8c30b44d71449e513c5a4 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Tue, 20 Nov 2018 08:47:19 -0600 Subject: [PATCH] drivers: sensor: ccs811: bypass APP_START when not in boot mode The CCS811 can be in either boot mode (after powerup) or application mode, and these modes have distinct register maps that share only some content. The register written to switch from boot mode to application mode is not available in application mode, so don't write to it in that case. Also respect the required timeout between APP_START and next I2C operation. Signed-off-by: Peter A. Bigot --- drivers/sensor/ccs811/ccs811.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/sensor/ccs811/ccs811.c b/drivers/sensor/ccs811/ccs811.c index 2c21852c948..d9b7c538ecf 100644 --- a/drivers/sensor/ccs811/ccs811.c +++ b/drivers/sensor/ccs811/ccs811.c @@ -158,6 +158,12 @@ static int switch_to_app_mode(struct device *i2c) return -EINVAL; } + /* Check if already in application mode */ + if (status & CCS811_STATUS_FW_MODE) { + LOG_DBG("CCS811 Already in application mode"); + return 0; + } + buf = CCS811_REG_APP_START; /* Set the device to application mode */ if (i2c_write(i2c, &buf, 1, DT_INST_0_AMS_CCS811_BASE_ADDRESS) < 0) { @@ -165,6 +171,7 @@ static int switch_to_app_mode(struct device *i2c) return -EIO; } + k_sleep(1); /* t_APP_START */ if (i2c_reg_read_byte(i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS, CCS811_REG_STATUS, &status) < 0) { LOG_ERR("Failed to read Status register");