ccs811.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
17 #ifndef CCS811_H
18 #define CCS811_H
19 
20 #include <stdint.h>
21 #include "periph/gpio.h"
22 #include "periph/i2c.h"
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
33 #define CCS811_I2C_ADDRESS_1 (0x5A)
34 #define CCS811_I2C_ADDRESS_2 (0x5B)
35 
41 #define CCS811_ECO2_RANGE_MIN (400)
42 #define CCS811_ECO2_RANGE_MAX (8192)
43 #define CCS811_TVOC_RANGE_MIN (0)
44 #define CCS811_TVOC_RANGE_MAX (1187)
50 typedef enum {
69 
73 typedef enum {
80 
84 typedef enum {
89 
93 typedef struct {
94 
96  uint8_t i2c_addr;
98 #if MODULE_CCS811_FULL || DOXYGEN
99  gpio_t int_pin;
101 #endif
102  gpio_t wake_pin;
103  gpio_t reset_pin;
105 
109 typedef struct {
111 } ccs811_t;
112 
136 int ccs811_init (ccs811_t *dev, const ccs811_params_t *params);
137 
167 int ccs811_read_iaq (const ccs811_t *dev,
168  uint16_t *iaq_tvoc, uint16_t *iaq_eco2,
169  uint16_t *raw_i, uint16_t *raw_v);
170 
171 #if MODULE_CCS811_FULL || DOXYGEN
172 
195 int ccs811_read_ntc (const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc);
196 
197 #endif /* MODULE_CCS811_FULL || DOXYGEN */
198 
211 int ccs811_data_ready (const ccs811_t *dev);
212 
232 int ccs811_power_down (ccs811_t *dev);
233 
255 int ccs811_power_up (ccs811_t *dev);
256 
294 int ccs811_set_mode (ccs811_t *dev, ccs811_mode_t mode);
295 
296 #if MODULE_CCS811_FULL || DOXYGEN
297 
323 
339  int16_t temp, int16_t hum);
340 
365 int ccs811_set_eco2_thresholds (const ccs811_t *dev,
366  uint16_t low, uint16_t high, uint8_t hyst);
367 
383 int ccs811_get_baseline (const ccs811_t *dev, uint16_t *baseline);
384 
402 int ccs811_set_baseline (const ccs811_t *dev, uint16_t baseline);
403 #endif /* MODULE_CCS811_FULL || DOXYGEN */
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 
409 #endif /* CCS811_H */
410 
CCS811_ERROR_NOT_SUPPORTED
@ CCS811_ERROR_NOT_SUPPORTED
function is not supported
Definition: ccs811.h:67
CCS811_ERROR_NO_NEW_DATA
@ CCS811_ERROR_NO_NEW_DATA
no new data (last valid data returned)
Definition: ccs811.h:55
ccs811_power_up
int ccs811_power_up(ccs811_t *dev)
Power up the sensor.
CCS811_MODE_60S
@ CCS811_MODE_60S
Low Power Pulse Heating, IAQ values every 60 s.
Definition: ccs811.h:77
ccs811_t::params
ccs811_params_t params
device initialization parameters
Definition: ccs811.h:110
CCS811_MODE_10S
@ CCS811_MODE_10S
Pulse Heating mode, IAQ values every 10 s.
Definition: ccs811.h:76
CCS811_ERROR_NO_DEV
@ CCS811_ERROR_NO_DEV
device not available
Definition: ccs811.h:53
CCS811_ERROR_NO_APP
@ CCS811_ERROR_NO_APP
could not start application
Definition: ccs811.h:54
ccs811_set_int_mode
int ccs811_set_int_mode(ccs811_t *dev, ccs811_int_mode_t mode)
Enable/disable data ready or threshold interrupt signal nINT
ccs811_params_t::i2c_dev
i2c_t i2c_dev
I2C device, clock stretching required (default I2C_DEV(0))
Definition: ccs811.h:95
ccs811_params_t::reset_pin
gpio_t reset_pin
nRESET signal pin (default GPIO_UNDEF)
Definition: ccs811.h:103
CCS811_ERROR_NO_INT_PIN
@ CCS811_ERROR_NO_INT_PIN
nINT signal pin not configured
Definition: ccs811.h:64
ccs811_params_t::mode
ccs811_mode_t mode
measurement mode used (default CCS811_MODE_IDLE)
Definition: ccs811.h:97
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
ccs811_read_ntc
int ccs811_read_ntc(const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc)
Read the resistance of connected NTC thermistor.
CCS811_MODE_IDLE
@ CCS811_MODE_IDLE
Idle, low current mode.
Definition: ccs811.h:74
CCS811_ERROR_I2C
@ CCS811_ERROR_I2C
I2C communication failure.
Definition: ccs811.h:52
CCS811_ERROR_MAX_RESISTANCE
@ CCS811_ERROR_MAX_RESISTANCE
maximum sensor resistance exceeded
Definition: ccs811.h:61
ccs811_params_t::i2c_addr
uint8_t i2c_addr
I2C address (default CCS811_I2C_ADDRESS_1)
Definition: ccs811.h:96
CCS811_MODE_1S
@ CCS811_MODE_1S
Constant Power mode, IAQ values every 1 s.
Definition: ccs811.h:75
ccs811_t
CCS811 sensor device data structure.
Definition: ccs811.h:109
ccs811_power_down
int ccs811_power_down(ccs811_t *dev)
Power down the sensor.
ccs811_get_baseline
int ccs811_get_baseline(const ccs811_t *dev, uint16_t *baseline)
Get the current baseline value from sensor.
ccs811_init
int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
Initialize a CCS811 sensor device.
ccs811_set_mode
int ccs811_set_mode(ccs811_t *dev, ccs811_mode_t mode)
Set the operation mode of the sensor.
CCS811_ERROR_MEASMODE_INV
@ CCS811_ERROR_MEASMODE_INV
invalid measurement mode
Definition: ccs811.h:59
ccs811_set_baseline
int ccs811_set_baseline(const ccs811_t *dev, uint16_t baseline)
Write a previously stored baseline value to the sensor.
ccs811_params_t::int_pin
gpio_t int_pin
nINT signal pin (default GPIO_PIN(0, 0)
Definition: ccs811.h:99
CCS811_ERROR_WRITE_REG_INV
@ CCS811_ERROR_WRITE_REG_INV
invalid register address on write
Definition: ccs811.h:57
ccs811_set_environmental_data
int ccs811_set_environmental_data(const ccs811_t *dev, int16_t temp, int16_t hum)
Set environmental data.
CCS811_ERROR_HEATER_SUPPLY
@ CCS811_ERROR_HEATER_SUPPLY
heater voltage not applied correctly
Definition: ccs811.h:63
CCS811_ERROR_HEATER_FAULT
@ CCS811_ERROR_HEATER_FAULT
heater current not in range
Definition: ccs811.h:62
ccs811_params_t::int_mode
ccs811_int_mode_t int_mode
interrupt mode used (default CCS811_INT_NONE)
Definition: ccs811.h:100
ccs811_read_iaq
int ccs811_read_iaq(const ccs811_t *dev, uint16_t *iaq_tvoc, uint16_t *iaq_eco2, uint16_t *raw_i, uint16_t *raw_v)
Read IAQ sensor values and/or RAW sensor data.
ccs811_params_t::wake_pin
gpio_t wake_pin
nWAKE signal pin (default GPIO_UNDEF)
Definition: ccs811.h:102
CCS811_ERROR_THRESH_INV
@ CCS811_ERROR_THRESH_INV
invalid threshold parameters
Definition: ccs811.h:60
CCS811_MODE_250MS
@ CCS811_MODE_250MS
Constant Power mode, only RAW data every 250 ms.
Definition: ccs811.h:78
CCS811_ERROR_NO_RESET_PIN
@ CCS811_ERROR_NO_RESET_PIN
nRESET signal pin not configured
Definition: ccs811.h:66
CCS811_INT_THRESHOLD
@ CCS811_INT_THRESHOLD
nINT signal when new data reach thresholds
Definition: ccs811.h:87
gpio.h
Low-level GPIO peripheral driver interface definitions.
CCS811_INT_NONE
@ CCS811_INT_NONE
interrupt generation is disabled (default)
Definition: ccs811.h:85
ccs811_error_codes_t
ccs811_error_codes_t
Driver error codes (returned as negative values)
Definition: ccs811.h:50
ccs811_set_eco2_thresholds
int ccs811_set_eco2_thresholds(const ccs811_t *dev, uint16_t low, uint16_t high, uint8_t hyst)
Set eCO2 thresholds for threshold interrupts.
ccs811_mode_t
ccs811_mode_t
CCS811 operation modes.
Definition: ccs811.h:73
ccs811_data_ready
int ccs811_data_ready(const ccs811_t *dev)
Data-ready status function.
CCS811_ERROR_NO_WAKE_PIN
@ CCS811_ERROR_NO_WAKE_PIN
nWAKE signal pin not configured
Definition: ccs811.h:65
CCS811_ERROR_READ_REG_INV
@ CCS811_ERROR_READ_REG_INV
invalid register address on read
Definition: ccs811.h:58
CCS811_ERROR_NO_IAQ_DATA
@ CCS811_ERROR_NO_IAQ_DATA
IAQ data not available in this mode.
Definition: ccs811.h:56
i2c.h
Low-level I2C peripheral driver interface definition.
ccs811_params_t
CCS811 device initialization parameters.
Definition: ccs811.h:93
CCS811_OK
@ CCS811_OK
no error
Definition: ccs811.h:51
ccs811_int_mode_t
ccs811_int_mode_t
CCS811 interrupt mode.
Definition: ccs811.h:84
CCS811_INT_DATA_READY
@ CCS811_INT_DATA_READY
nINT signal when new data are reade to read
Definition: ccs811.h:86