drivers: sensor: ccs811: accommodate old firmware
The firmware version on the CCS811 on nrf52_pca20020 is generally version 1.1, which does not set the data ready bit in the status register. Assume that a non-zero CO2 measurement on that version is fresh for the purposes of determining the fetch status. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
45f9efe02f
commit
f041570188
2 changed files with 28 additions and 4 deletions
|
@ -231,7 +231,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
struct ccs811_result_type *rp = &drv_data->result;
|
struct ccs811_result_type *rp = &drv_data->result;
|
||||||
const u8_t cmd = CCS811_REG_ALG_RESULT_DATA;
|
const u8_t cmd = CCS811_REG_ALG_RESULT_DATA;
|
||||||
int rc;
|
int rc;
|
||||||
u16_t buf[4];
|
u16_t buf[4] = { 0 };
|
||||||
unsigned int status;
|
unsigned int status;
|
||||||
|
|
||||||
set_wake(drv_data, true);
|
set_wake(drv_data, true);
|
||||||
|
@ -250,8 +250,16 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||||
rp->error = error_from_status(status);
|
rp->error = error_from_status(status);
|
||||||
rp->raw = sys_be16_to_cpu(buf[3]);
|
rp->raw = sys_be16_to_cpu(buf[3]);
|
||||||
|
|
||||||
/* @todo APP FW 1.1 may not set DATA_READY. */
|
/* APP FW 1.1 does not set DATA_READY, but it does set CO2 to
|
||||||
return (rp->status & CCS811_STATUS_DATA_READY) ? 0 : -EAGAIN;
|
* zero while it's starting up. Assume a non-zero CO2 with
|
||||||
|
* old firmware is valid for the purposes of claiming the
|
||||||
|
* fetch was fresh.
|
||||||
|
*/
|
||||||
|
if ((drv_data->app_fw_ver <= 0x11)
|
||||||
|
&& (rp->co2 != 0)) {
|
||||||
|
status |= CCS811_STATUS_DATA_READY;
|
||||||
|
}
|
||||||
|
return (status & CCS811_STATUS_DATA_READY) ? 0 : -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ccs811_channel_get(struct device *dev,
|
static int ccs811_channel_get(struct device *dev,
|
||||||
|
@ -421,8 +429,10 @@ static int ccs811_init(struct device *dev)
|
||||||
{
|
{
|
||||||
struct ccs811_data *drv_data = dev->driver_data;
|
struct ccs811_data *drv_data = dev->driver_data;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u8_t hw_id;
|
|
||||||
int status;
|
int status;
|
||||||
|
u16_t fw_ver;
|
||||||
|
u8_t cmd;
|
||||||
|
u8_t hw_id;
|
||||||
|
|
||||||
*drv_data = (struct ccs811_data){ 0 };
|
*drv_data = (struct ccs811_data){ 0 };
|
||||||
drv_data->i2c = device_get_binding(DT_INST_0_AMS_CCS811_BUS_NAME);
|
drv_data->i2c = device_get_binding(DT_INST_0_AMS_CCS811_BUS_NAME);
|
||||||
|
@ -518,6 +528,19 @@ static int ccs811_init(struct device *dev)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check application firmware version (first byte) */
|
||||||
|
cmd = CCS811_REG_FW_APP_VERSION;
|
||||||
|
if (i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
|
||||||
|
&cmd, sizeof(cmd),
|
||||||
|
&fw_ver, sizeof(fw_ver)) < 0) {
|
||||||
|
LOG_ERR("Failed to read App Firmware Version register");
|
||||||
|
ret = -EIO;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
fw_ver = sys_be16_to_cpu(fw_ver);
|
||||||
|
LOG_INF("App FW %04x", fw_ver);
|
||||||
|
drv_data->app_fw_ver = fw_ver >> 8U;
|
||||||
|
|
||||||
/* Configure measurement mode */
|
/* Configure measurement mode */
|
||||||
u8_t meas_mode = CCS811_MODE_IDLE;
|
u8_t meas_mode = CCS811_MODE_IDLE;
|
||||||
#ifdef CONFIG_CCS811_DRIVE_MODE_1
|
#ifdef CONFIG_CCS811_DRIVE_MODE_1
|
||||||
|
|
|
@ -79,6 +79,7 @@ struct ccs811_data {
|
||||||
#endif
|
#endif
|
||||||
struct ccs811_result_type result;
|
struct ccs811_result_type result;
|
||||||
u8_t mode;
|
u8_t mode;
|
||||||
|
u8_t app_fw_ver;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_CCS811_TRIGGER
|
#ifdef CONFIG_CCS811_TRIGGER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue