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)
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 
164 int ccs811_read_iaq (const ccs811_t *dev,
165  uint16_t *iaq_tvoc, uint16_t *iaq_eco2,
166  uint16_t *raw_i, uint16_t *raw_v);
167 
168 #if MODULE_CCS811_FULL || DOXYGEN
169 
192 int ccs811_read_ntc (const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc);
193 
194 #endif /* MODULE_CCS811_FULL || DOXYGEN */
195 
208 int ccs811_data_ready (const ccs811_t *dev);
209 
230 
253 
292 
293 #if MODULE_CCS811_FULL || DOXYGEN
320 
336  int16_t temp, int16_t hum);
337 
363  uint16_t low, uint16_t high, uint8_t hyst);
364 
380 int ccs811_get_baseline (const ccs811_t *dev, uint16_t *baseline);
381 
399 int ccs811_set_baseline (const ccs811_t *dev, uint16_t baseline);
400 #endif /* MODULE_CCS811_FULL || DOXYGEN */
401 
402 #ifdef __cplusplus
403 }
404 #endif
405 
406 #endif /* CCS811_H */
int ccs811_set_int_mode(ccs811_t *dev, ccs811_int_mode_t mode)
Enable/disable data ready or threshold interrupt signal nINT
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_error_codes_t
Driver error codes (returned as negative values)
Definition: ccs811.h:50
@ CCS811_ERROR_NO_DEV
device not available
Definition: ccs811.h:53
@ CCS811_ERROR_MEASMODE_INV
invalid measurement mode
Definition: ccs811.h:59
@ CCS811_ERROR_NO_INT_PIN
nINT signal pin not configured
Definition: ccs811.h:64
@ CCS811_ERROR_HEATER_FAULT
heater current not in range
Definition: ccs811.h:62
@ CCS811_ERROR_NO_APP
could not start application
Definition: ccs811.h:54
@ CCS811_ERROR_THRESH_INV
invalid threshold parameters
Definition: ccs811.h:60
@ CCS811_ERROR_I2C
I2C communication failure.
Definition: ccs811.h:52
@ CCS811_ERROR_NO_NEW_DATA
no new data (last valid data returned)
Definition: ccs811.h:55
@ CCS811_ERROR_READ_REG_INV
invalid register address on read
Definition: ccs811.h:58
@ CCS811_ERROR_NOT_SUPPORTED
function is not supported
Definition: ccs811.h:67
@ CCS811_ERROR_HEATER_SUPPLY
heater voltage not applied correctly
Definition: ccs811.h:63
@ CCS811_ERROR_WRITE_REG_INV
invalid register address on write
Definition: ccs811.h:57
@ CCS811_ERROR_MAX_RESISTANCE
maximum sensor resistance exceeded
Definition: ccs811.h:61
@ CCS811_ERROR_NO_WAKE_PIN
nWAKE signal pin not configured
Definition: ccs811.h:65
@ CCS811_OK
no error
Definition: ccs811.h:51
@ CCS811_ERROR_NO_IAQ_DATA
IAQ data not available in this mode.
Definition: ccs811.h:56
@ CCS811_ERROR_NO_RESET_PIN
nRESET signal pin not configured
Definition: ccs811.h:66
int ccs811_power_up(ccs811_t *dev)
Power up the sensor.
int ccs811_data_ready(const ccs811_t *dev)
Data-ready status function.
int ccs811_set_environmental_data(const ccs811_t *dev, int16_t temp, int16_t hum)
Set environmental data.
ccs811_int_mode_t
CCS811 interrupt mode.
Definition: ccs811.h:84
@ CCS811_INT_THRESHOLD
nINT signal when new data reach thresholds
Definition: ccs811.h:87
@ CCS811_INT_NONE
interrupt generation is disabled (default)
Definition: ccs811.h:85
@ CCS811_INT_DATA_READY
nINT signal when new data are reade to read
Definition: ccs811.h:86
int ccs811_init(ccs811_t *dev, const ccs811_params_t *params)
Initialize a CCS811 sensor device.
int ccs811_set_mode(ccs811_t *dev, ccs811_mode_t mode)
Set the operation mode of the sensor.
ccs811_mode_t
CCS811 operation modes.
Definition: ccs811.h:73
@ CCS811_MODE_250MS
Constant Power mode, only RAW data every 250 ms.
Definition: ccs811.h:78
@ CCS811_MODE_1S
Constant Power mode, IAQ values every 1 s.
Definition: ccs811.h:75
@ CCS811_MODE_IDLE
Idle, low current mode.
Definition: ccs811.h:74
@ CCS811_MODE_10S
Pulse Heating mode, IAQ values every 10 s.
Definition: ccs811.h:76
@ CCS811_MODE_60S
Low Power Pulse Heating, IAQ values every 60 s.
Definition: ccs811.h:77
int ccs811_get_baseline(const ccs811_t *dev, uint16_t *baseline)
Get the current baseline value from sensor.
int ccs811_set_eco2_thresholds(const ccs811_t *dev, uint16_t low, uint16_t high, uint8_t hyst)
Set eCO2 thresholds for threshold interrupts.
int ccs811_read_ntc(const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc)
Read the resistance of connected NTC thermistor.
int ccs811_power_down(ccs811_t *dev)
Power down the sensor.
int ccs811_set_baseline(const ccs811_t *dev, uint16_t baseline)
Write a previously stored baseline value to the sensor.
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:145
Low-level I2C peripheral driver interface definition.
CCS811 device initialization parameters.
Definition: ccs811.h:93
gpio_t reset_pin
nRESET signal pin (default GPIO_UNDEF)
Definition: ccs811.h:103
i2c_t i2c_dev
I2C device, clock stretching required (default I2C_DEV(0))
Definition: ccs811.h:95
uint8_t i2c_addr
I2C address (default CCS811_I2C_ADDRESS_1)
Definition: ccs811.h:96
ccs811_mode_t mode
measurement mode used (default CCS811_MODE_IDLE)
Definition: ccs811.h:97
gpio_t int_pin
nINT signal pin (default GPIO_PIN(0, 0)
Definition: ccs811.h:99
gpio_t wake_pin
nWAKE signal pin (default GPIO_UNDEF)
Definition: ccs811.h:102
ccs811_int_mode_t int_mode
interrupt mode used (default CCS811_INT_NONE)
Definition: ccs811.h:100
CCS811 sensor device data structure.
Definition: ccs811.h:109
ccs811_params_t params
device initialization parameters
Definition: ccs811.h:110