drivers: sensor: ccs811: provide access to sensor results

Expose the entire content of the ALG_RESULT_DATA block to the
application, primarily so the status and error flags can be seen.  With
those available the application has the ability to detect that a stale
result has been provided so sensor_fetch_sample() can return -EAGAIN in
this case instead of -EIO, and it doesn't need to block which is
annoying.

This should also make the sensor usable on older Nordic Thingy:52
devices with outdated CCS811 application firmware that doesn't properly
implement the DATA_READY bit.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2018-11-23 05:56:17 -06:00 committed by Maureen Helm
commit cb84836745
3 changed files with 92 additions and 63 deletions

View file

@ -22,6 +22,65 @@ extern "C" {
#include <device.h>
#include <drivers/sensor.h>
/* Status register fields */
#define CCS811_STATUS_ERROR BIT(0)
#define CCS811_STATUS_DATA_READY BIT(3)
#define CCS811_STATUS_APP_VALID BIT(4)
#define CCS811_STATUS_FW_MODE BIT(7)
/* Error register fields */
#define CCS811_ERROR_WRITE_REG_INVALID BIT(0)
#define CCS811_ERROR_READ_REG_INVALID BIT(1)
#define CCS811_ERROR_MEASMODE_INVALID BIT(2)
#define CCS811_ERROR_MAX_RESISTANCE BIT(3)
#define CCS811_ERROR_HEATER_FAULT BIT(4)
#define CCS811_ERROR_HEATER_SUPPLY BIT(5)
/* Measurement mode constants */
#define CCS811_MODE_IDLE 0x00
#define CCS811_MODE_IAQ_1SEC 0x10
#define CCS811_MODE_IAQ_10SEC 0x20
#define CCS811_MODE_IAQ_60SEC 0x30
#define CCS811_MODE_IAQ_RAW_250MSEC 0x40
/** @brief Information collected from the sensor on each fetch. */
struct ccs811_result_type {
/** Equivalent carbon dioxide in parts-per-million volume (ppmv). */
u16_t co2;
/**
* Equivalent total volatile organic compounts in
* parts-per-billion volume.
*/
u16_t voc;
/** Raw voltage and current measured by sensor. */
u16_t raw;
/** Sensor status at completion of most recent fetch. */
u8_t status;
/**
* Sensor error flags at completion of most recent fetch.
*
* Note that errors are cleared when read.
*/
u8_t error;
};
/**
* @brief Access storage for the most recent data read from the sensor.
*
* This content of the object referenced is updated by
* sensor_fetch_sample(), except for ccs811_result_type::mode which is
* set on driver initialization.
*
* @param dev Pointer to the sensor device
*
* @return a pointer to the result information.
*/
const struct ccs811_result_type *ccs811_result(struct device *dev);
/**
* @brief Fetch the current value of the BASELINE register.
*