drivers: sensor: ccs811: add interface for BASELINE management
Proper use of the CCS811 requires maintenance of the BASELINE register value measured in clean air at various points in the sensor life cycle. The sensor driver abstraction has no facility to support this, so add an application header with functions to fetch and update the register value. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
parent
403a7ab2c5
commit
af0c69fb9f
3 changed files with 94 additions and 1 deletions
|
@ -70,6 +70,40 @@ static inline u8_t error_from_status(int status)
|
|||
return status >> 8;
|
||||
}
|
||||
|
||||
int ccs811_baseline_fetch(struct device *dev)
|
||||
{
|
||||
const u8_t cmd = CCS811_REG_BASELINE;
|
||||
struct ccs811_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
u16_t baseline;
|
||||
|
||||
set_wake(drv_data, true);
|
||||
|
||||
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
|
||||
&cmd, sizeof(cmd),
|
||||
(u8_t *)&baseline, sizeof(baseline));
|
||||
set_wake(drv_data, false);
|
||||
if (rc <= 0) {
|
||||
rc = baseline;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int ccs811_baseline_update(struct device *dev,
|
||||
u16_t baseline)
|
||||
{
|
||||
struct ccs811_data *drv_data = dev->driver_data;
|
||||
u8_t buf[1 + sizeof(baseline)];
|
||||
int rc;
|
||||
|
||||
buf[0] = CCS811_REG_BASELINE;
|
||||
memcpy(buf + 1, &baseline, sizeof(baseline));
|
||||
set_wake(drv_data, true);
|
||||
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_0_AMS_CCS811_BASE_ADDRESS);
|
||||
set_wake(drv_data, false);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
|
||||
{
|
||||
struct ccs811_data *drv_data = dev->driver_data;
|
||||
|
@ -285,7 +319,7 @@ int ccs811_set_thresholds(struct device *dev)
|
|||
|
||||
#endif /* CONFIG_CCS811_TRIGGER */
|
||||
|
||||
int ccs811_init(struct device *dev)
|
||||
static int ccs811_init(struct device *dev)
|
||||
{
|
||||
struct ccs811_data *drv_data = dev->driver_data;
|
||||
int ret = 0;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define CCS811_REG_ALG_RESULT_DATA 0x02
|
||||
#define CCS811_REG_RAW_DATA 0x03
|
||||
#define CCS811_REG_THRESHOLDS 0x10
|
||||
#define CCS811_REG_BASELINE 0x11
|
||||
#define CCS811_REG_HW_ID 0x20
|
||||
#define CCS811_REG_HW_VERSION 0x21
|
||||
#define CCS811_REG_HW_VERSION_MASK 0xF0
|
||||
|
|
58
include/drivers/sensor/ccs811.h
Normal file
58
include/drivers/sensor/ccs811.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Peter Bigot Consulting, LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Extended public API for CCS811 Indoor Air Quality Sensor
|
||||
*
|
||||
* Some capabilities and operational requirements for this sensor
|
||||
* cannot be expressed within the sensor driver abstraction.
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_CCS811_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_CCS811_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <device.h>
|
||||
|
||||
/**
|
||||
* @brief Fetch the current value of the BASELINE register.
|
||||
*
|
||||
* The BASELINE register encodes data used to correct sensor readings
|
||||
* based on individual device configuration and variation over time.
|
||||
*
|
||||
* For proper management of the BASELINE register see AN000370
|
||||
* "Baseline Save and Restore on CCS811".
|
||||
*
|
||||
* @param dev Pointer to the sensor device
|
||||
*
|
||||
* @return a non-negative 16-bit register value, or a negative errno
|
||||
* code on failure.
|
||||
*/
|
||||
int ccs811_baseline_fetch(struct device *dev);
|
||||
|
||||
/**
|
||||
* @brief Update the BASELINE register.
|
||||
*
|
||||
* For proper management of the BASELINE register see AN000370
|
||||
* "Baseline Save and Restore on CCS811".
|
||||
*
|
||||
* @param dev Pointer to the sensor device
|
||||
*
|
||||
* @param baseline the value to be stored in the BASELINE register.
|
||||
*
|
||||
* @return 0 if successful, negative errno code if failure.
|
||||
*/
|
||||
int ccs811_baseline_update(struct device *dev, u16_t baseline);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_CCS811_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue