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 
9 #pragma once
10 
19 #include <stdint.h>
20 #include "periph/gpio.h"
21 #include "periph/i2c.h"
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
32 #define CCS811_I2C_ADDRESS_1 (0x5A)
33 #define CCS811_I2C_ADDRESS_2 (0x5B)
40 #define CCS811_ECO2_RANGE_MIN (400)
41 #define CCS811_ECO2_RANGE_MAX (8192)
42 #define CCS811_TVOC_RANGE_MIN (0)
43 #define CCS811_TVOC_RANGE_MAX (1187)
49 typedef enum {
68 
72 typedef enum {
79 
83 typedef enum {
88 
92 typedef struct {
93 
95  uint8_t i2c_addr;
97 #if MODULE_CCS811_FULL || DOXYGEN
98  gpio_t int_pin;
100 #endif
101  gpio_t wake_pin;
102  gpio_t reset_pin;
104 
108 typedef struct {
110 } ccs811_t;
111 
135 int ccs811_init (ccs811_t *dev, const ccs811_params_t *params);
136 
163 int ccs811_read_iaq (const ccs811_t *dev,
164  uint16_t *iaq_tvoc, uint16_t *iaq_eco2,
165  uint16_t *raw_i, uint16_t *raw_v);
166 
167 #if MODULE_CCS811_FULL || DOXYGEN
168 
191 int ccs811_read_ntc (const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc);
192 
193 #endif /* MODULE_CCS811_FULL || DOXYGEN */
194 
207 int ccs811_data_ready (const ccs811_t *dev);
208 
229 
252 
291 
292 #if MODULE_CCS811_FULL || DOXYGEN
319 
335  int16_t temp, int16_t hum);
336 
362  uint16_t low, uint16_t high, uint8_t hyst);
363 
379 int ccs811_get_baseline (const ccs811_t *dev, uint16_t *baseline);
380 
398 int ccs811_set_baseline (const ccs811_t *dev, uint16_t baseline);
399 #endif /* MODULE_CCS811_FULL || DOXYGEN */
400 
401 #ifdef __cplusplus
402 }
403 #endif
404 
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:49
@ CCS811_ERROR_NO_DEV
device not available
Definition: ccs811.h:52
@ CCS811_ERROR_MEASMODE_INV
invalid measurement mode
Definition: ccs811.h:58
@ CCS811_ERROR_NO_INT_PIN
nINT signal pin not configured
Definition: ccs811.h:63
@ CCS811_ERROR_HEATER_FAULT
heater current not in range
Definition: ccs811.h:61
@ CCS811_ERROR_NO_APP
could not start application
Definition: ccs811.h:53
@ CCS811_ERROR_THRESH_INV
invalid threshold parameters
Definition: ccs811.h:59
@ CCS811_ERROR_I2C
I2C communication failure.
Definition: ccs811.h:51
@ CCS811_ERROR_NO_NEW_DATA
no new data (last valid data returned)
Definition: ccs811.h:54
@ CCS811_ERROR_READ_REG_INV
invalid register address on read
Definition: ccs811.h:57
@ CCS811_ERROR_NOT_SUPPORTED
function is not supported
Definition: ccs811.h:66
@ CCS811_ERROR_HEATER_SUPPLY
heater voltage not applied correctly
Definition: ccs811.h:62
@ CCS811_ERROR_WRITE_REG_INV
invalid register address on write
Definition: ccs811.h:56
@ CCS811_ERROR_MAX_RESISTANCE
maximum sensor resistance exceeded
Definition: ccs811.h:60
@ CCS811_ERROR_NO_WAKE_PIN
nWAKE signal pin not configured
Definition: ccs811.h:64
@ CCS811_OK
no error
Definition: ccs811.h:50
@ CCS811_ERROR_NO_IAQ_DATA
IAQ data not available in this mode.
Definition: ccs811.h:55
@ CCS811_ERROR_NO_RESET_PIN
nRESET signal pin not configured
Definition: ccs811.h:65
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:83
@ CCS811_INT_THRESHOLD
nINT signal when new data reach thresholds
Definition: ccs811.h:86
@ CCS811_INT_NONE
interrupt generation is disabled (default)
Definition: ccs811.h:84
@ CCS811_INT_DATA_READY
nINT signal when new data are reade to read
Definition: ccs811.h:85
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:72
@ CCS811_MODE_250MS
Constant Power mode, only RAW data every 250 ms.
Definition: ccs811.h:77
@ CCS811_MODE_1S
Constant Power mode, IAQ values every 1 s.
Definition: ccs811.h:74
@ CCS811_MODE_IDLE
Idle, low current mode.
Definition: ccs811.h:73
@ CCS811_MODE_10S
Pulse Heating mode, IAQ values every 10 s.
Definition: ccs811.h:75
@ CCS811_MODE_60S
Low Power Pulse Heating, IAQ values every 60 s.
Definition: ccs811.h:76
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:144
Low-level I2C peripheral driver interface definition.
CCS811 device initialization parameters.
Definition: ccs811.h:92
gpio_t reset_pin
nRESET signal pin (default GPIO_UNDEF)
Definition: ccs811.h:102
i2c_t i2c_dev
I2C device, clock stretching required (default I2C_DEV(0))
Definition: ccs811.h:94
uint8_t i2c_addr
I2C address (default CCS811_I2C_ADDRESS_1)
Definition: ccs811.h:95
ccs811_mode_t mode
measurement mode used (default CCS811_MODE_IDLE)
Definition: ccs811.h:96
gpio_t int_pin
nINT signal pin (default GPIO_PIN(0, 0)
Definition: ccs811.h:98
gpio_t wake_pin
nWAKE signal pin (default GPIO_UNDEF)
Definition: ccs811.h:101
ccs811_int_mode_t int_mode
interrupt mode used (default CCS811_INT_NONE)
Definition: ccs811.h:99
CCS811 sensor device data structure.
Definition: ccs811.h:108
ccs811_params_t params
device initialization parameters
Definition: ccs811.h:109