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 
maximum sensor resistance exceeded
Definition: ccs811.h:61
no error
Definition: ccs811.h:51
ccs811_int_mode_t int_mode
interrupt mode used (default CCS811_INT_NONE)
Definition: ccs811.h:100
gpio_t wake_pin
nWAKE signal pin (default GPIO_UNDEF)
Definition: ccs811.h:102
uint8_t i2c_addr
I2C address (default CCS811_I2C_ADDRESS_1)
Definition: ccs811.h:96
Constant Power mode, only RAW data every 250 ms.
Definition: ccs811.h:78
int ccs811_set_eco2_thresholds(const ccs811_t *dev, uint16_t low, uint16_t high, uint8_t hyst)
Set eCO2 thresholds for threshold interrupts.
nINT signal when new data reach thresholds
Definition: ccs811.h:87
Low-level GPIO peripheral driver interface definitions.
I2C communication failure.
Definition: ccs811.h:52
nWAKE signal pin not configured
Definition: ccs811.h:65
Low Power Pulse Heating, IAQ values every 60 s.
Definition: ccs811.h:77
gpio_t reset_pin
nRESET signal pin (default GPIO_UNDEF)
Definition: ccs811.h:103
device not available
Definition: ccs811.h:53
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
CCS811 device initialization parameters.
Definition: ccs811.h:93
invalid measurement mode
Definition: ccs811.h:59
ccs811_params_t params
device initialization parameters
Definition: ccs811.h:110
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.
heater voltage not applied correctly
Definition: ccs811.h:63
ccs811_error_codes_t
Driver error codes (returned as negative values)
Definition: ccs811.h:50
interrupt generation is disabled (default)
Definition: ccs811.h:85
nINT signal when new data are reade to read
Definition: ccs811.h:86
i2c_t i2c_dev
I2C device, clock stretching required (default I2C_DEV(0))
Definition: ccs811.h:95
ccs811_mode_t
CCS811 operation modes.
Definition: ccs811.h:73
int ccs811_data_ready(const ccs811_t *dev)
Data-ready status function.
no new data (last valid data returned)
Definition: ccs811.h:55
IAQ data not available in this mode.
Definition: ccs811.h:56
ccs811_int_mode_t
CCS811 interrupt mode.
Definition: ccs811.h:84
nRESET signal pin not configured
Definition: ccs811.h:66
CCS811 sensor device data structure.
Definition: ccs811.h:109
nINT signal pin not configured
Definition: ccs811.h:64
heater current not in range
Definition: ccs811.h:62
int ccs811_power_down(ccs811_t *dev)
Power down the sensor.
int ccs811_get_baseline(const ccs811_t *dev, uint16_t *baseline)
Get the current baseline value from sensor.
int ccs811_set_baseline(const ccs811_t *dev, uint16_t baseline)
Write a previously stored baseline value to the sensor.
int ccs811_set_mode(ccs811_t *dev, ccs811_mode_t mode)
Set the operation mode of the sensor.
int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
Initialize a CCS811 sensor device.
Pulse Heating mode, IAQ values every 10 s.
Definition: ccs811.h:76
could not start application
Definition: ccs811.h:54
invalid threshold parameters
Definition: ccs811.h:60
invalid register address on write
Definition: ccs811.h:57
int ccs811_power_up(ccs811_t *dev)
Power up the sensor.
Constant Power mode, IAQ values every 1 s.
Definition: ccs811.h:75
function is not supported
Definition: ccs811.h:67
int ccs811_set_environmental_data(const ccs811_t *dev, int16_t temp, int16_t hum)
Set environmental data.
int ccs811_set_int_mode(ccs811_t *dev, ccs811_int_mode_t mode)
Enable/disable data ready or threshold interrupt signal nINT
gpio_t int_pin
nINT signal pin (default GPIO_PIN(0, 0)
Definition: ccs811.h:99
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_t mode
measurement mode used (default CCS811_MODE_IDLE)
Definition: ccs811.h:97
Idle, low current mode.
Definition: ccs811.h:74
Low-level I2C peripheral driver interface definition.
invalid register address on read
Definition: ccs811.h:58