drivers: sensor: ccs811: provide API to fetch configuration and versions

The application may want to know the configured mode without inspecting
Kconfig macros; this is important for proper management of BASELINE
which is mode-dependent.

It also may need to know the version of the hardware and firmware, as
the behavior of application firmware 2.0 is significantly better than
version 1.1.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2018-11-23 07:16:36 -06:00 committed by Maureen Helm
parent 2dd990ad55
commit ac5acb9530
3 changed files with 74 additions and 2 deletions

View file

@ -77,6 +77,51 @@ const struct ccs811_result_type *ccs811_result(struct device *dev)
return &drv_data->result;
}
int ccs811_configver_fetch(struct device *dev,
struct ccs811_configver_type *ptr)
{
struct ccs811_data *drv_data = dev->driver_data;
u8_t cmd;
int rc;
if (!ptr) {
return -EINVAL;
}
set_wake(drv_data, true);
cmd = CCS811_REG_HW_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
&cmd, sizeof(cmd),
&ptr->hw_version, sizeof(ptr->hw_version));
if (rc == 0) {
cmd = CCS811_REG_FW_BOOT_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
&cmd, sizeof(cmd),
(u8_t *)&ptr->fw_boot_version,
sizeof(ptr->fw_boot_version));
ptr->fw_boot_version = sys_be16_to_cpu(ptr->fw_boot_version);
}
if (rc == 0) {
cmd = CCS811_REG_FW_APP_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
&cmd, sizeof(cmd),
(u8_t *)&ptr->fw_app_version,
sizeof(ptr->fw_app_version));
ptr->fw_app_version = sys_be16_to_cpu(ptr->fw_app_version);
}
if (rc == 0) {
LOG_INF("HW %x FW %x APP %x",
ptr->hw_version, ptr->fw_boot_version,
ptr->fw_app_version);
}
set_wake(drv_data, false);
ptr->mode = drv_data->mode & CCS811_MODE_MSK;
return rc;
}
int ccs811_baseline_fetch(struct device *dev)
{
const u8_t cmd = CCS811_REG_BASELINE;

View file

@ -23,12 +23,13 @@
#define CCS811_REG_BASELINE 0x11
#define CCS811_REG_HW_ID 0x20
#define CCS811_REG_HW_VERSION 0x21
#define CCS811_REG_HW_VERSION_MASK 0xF0
#define CCS811_REG_FW_BOOT_VERSION 0x23
#define CCS811_REG_FW_APP_VERSION 0x24
#define CCS811_REG_ERROR_ID 0xE0
#define CCS811_REG_APP_START 0xF4
#define CCS881_HW_ID 0x81
#define CCS811_HW_VERSION 0x10
#define CCS811_HW_VERSION_MSK 0xF0
/* Measurement modes */
#define CCS811_MODE_RAW_DATA 0x40

View file

@ -42,6 +42,7 @@ extern "C" {
#define CCS811_MODE_IAQ_10SEC 0x20
#define CCS811_MODE_IAQ_60SEC 0x30
#define CCS811_MODE_IAQ_250MSEC 0x40
#define CCS811_MODE_MSK 0x70
/** @brief Information collected from the sensor on each fetch. */
struct ccs811_result_type {
@ -81,6 +82,31 @@ struct ccs811_result_type {
*/
const struct ccs811_result_type *ccs811_result(struct device *dev);
/**
* @brief Get information about static CCS811 state.
*
* This includes the configured operating mode as well as hardware and
* firmware versions.
*/
struct ccs811_configver_type {
u16_t fw_boot_version;
u16_t fw_app_version;
u8_t hw_version;
u8_t mode;
};
/**
* @brief Fetch operating mode and version information.
*
* @param dev Pointer to the sensor device
*
* @param ptr Pointer to where the returned information should be stored
*
* @return 0 on success, or a negative errno code on failure.
*/
int ccs811_configver_fetch(struct device *dev,
struct ccs811_configver_type *ptr);
/**
* @brief Fetch the current value of the BASELINE register.
*