Loading...
Searching...
No Matches
ccs811.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
15
16#include <stdint.h>
17#include "periph/gpio.h"
18#include "periph/i2c.h"
19
20#ifdef __cplusplus
21extern "C"
22{
23#endif
24
29#define CCS811_I2C_ADDRESS_1 (0x5A)
30#define CCS811_I2C_ADDRESS_2 (0x5B)
32
37#define CCS811_ECO2_RANGE_MIN (400)
38#define CCS811_ECO2_RANGE_MAX (8192)
39#define CCS811_TVOC_RANGE_MIN (0)
40#define CCS811_TVOC_RANGE_MAX (1187)
42
65
76
85
89typedef struct {
90
92 uint8_t i2c_addr;
94#if MODULE_CCS811_FULL || DOXYGEN
95 gpio_t int_pin;
97#endif
98 gpio_t wake_pin;
99 gpio_t reset_pin;
101
105typedef struct {
107} ccs811_t;
108
132int ccs811_init (ccs811_t *dev, const ccs811_params_t *params);
133
160int ccs811_read_iaq (const ccs811_t *dev,
161 uint16_t *iaq_tvoc, uint16_t *iaq_eco2,
162 uint16_t *raw_i, uint16_t *raw_v);
163
164#if MODULE_CCS811_FULL || DOXYGEN
165
188int ccs811_read_ntc (const ccs811_t *dev, uint32_t r_ref, uint32_t *r_ntc);
189
190#endif /* MODULE_CCS811_FULL || DOXYGEN */
191
205
226
249
288
289#if MODULE_CCS811_FULL || DOXYGEN
316
332 int16_t temp, int16_t hum);
333
359 uint16_t low, uint16_t high, uint8_t hyst);
360
376int ccs811_get_baseline (const ccs811_t *dev, uint16_t *baseline);
377
395int ccs811_set_baseline (const ccs811_t *dev, uint16_t baseline);
396#endif /* MODULE_CCS811_FULL || DOXYGEN */
397
398#ifdef __cplusplus
399}
400#endif
401
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:46
@ CCS811_ERROR_NO_DEV
device not available
Definition ccs811.h:49
@ CCS811_ERROR_MEASMODE_INV
invalid measurement mode
Definition ccs811.h:55
@ CCS811_ERROR_NO_INT_PIN
nINT signal pin not configured
Definition ccs811.h:60
@ CCS811_ERROR_HEATER_FAULT
heater current not in range
Definition ccs811.h:58
@ CCS811_ERROR_NO_APP
could not start application
Definition ccs811.h:50
@ CCS811_ERROR_THRESH_INV
invalid threshold parameters
Definition ccs811.h:56
@ CCS811_ERROR_I2C
I2C communication failure.
Definition ccs811.h:48
@ CCS811_ERROR_NO_NEW_DATA
no new data (last valid data returned)
Definition ccs811.h:51
@ CCS811_ERROR_READ_REG_INV
invalid register address on read
Definition ccs811.h:54
@ CCS811_ERROR_NOT_SUPPORTED
function is not supported
Definition ccs811.h:63
@ CCS811_ERROR_HEATER_SUPPLY
heater voltage not applied correctly
Definition ccs811.h:59
@ CCS811_ERROR_WRITE_REG_INV
invalid register address on write
Definition ccs811.h:53
@ CCS811_ERROR_MAX_RESISTANCE
maximum sensor resistance exceeded
Definition ccs811.h:57
@ CCS811_ERROR_NO_WAKE_PIN
nWAKE signal pin not configured
Definition ccs811.h:61
@ CCS811_OK
no error
Definition ccs811.h:47
@ CCS811_ERROR_NO_IAQ_DATA
IAQ data not available in this mode.
Definition ccs811.h:52
@ CCS811_ERROR_NO_RESET_PIN
nRESET signal pin not configured
Definition ccs811.h:62
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:80
@ CCS811_INT_THRESHOLD
nINT signal when new data reach thresholds
Definition ccs811.h:83
@ CCS811_INT_NONE
interrupt generation is disabled (default)
Definition ccs811.h:81
@ CCS811_INT_DATA_READY
nINT signal when new data are reade to read
Definition ccs811.h:82
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:69
@ CCS811_MODE_250MS
Constant Power mode, only RAW data every 250 ms.
Definition ccs811.h:74
@ CCS811_MODE_1S
Constant Power mode, IAQ values every 1 s.
Definition ccs811.h:71
@ CCS811_MODE_IDLE
Idle, low current mode.
Definition ccs811.h:70
@ CCS811_MODE_10S
Pulse Heating mode, IAQ values every 10 s.
Definition ccs811.h:72
@ CCS811_MODE_60S
Low Power Pulse Heating, IAQ values every 60 s.
Definition ccs811.h:73
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:155
Low-level I2C peripheral driver interface definition.
CCS811 device initialization parameters.
Definition ccs811.h:89
gpio_t reset_pin
nRESET signal pin (default GPIO_UNDEF)
Definition ccs811.h:99
i2c_t i2c_dev
I2C device, clock stretching required (default I2C_DEV(0))
Definition ccs811.h:91
uint8_t i2c_addr
I2C address (default CCS811_I2C_ADDRESS_1)
Definition ccs811.h:92
ccs811_mode_t mode
measurement mode used (default CCS811_MODE_IDLE)
Definition ccs811.h:93
gpio_t int_pin
nINT signal pin (default GPIO_PIN(0, 0)
Definition ccs811.h:95
gpio_t wake_pin
nWAKE signal pin (default GPIO_UNDEF)
Definition ccs811.h:98
ccs811_int_mode_t int_mode
interrupt mode used (default CCS811_INT_NONE)
Definition ccs811.h:96
CCS811 sensor device data structure.
Definition ccs811.h:105
ccs811_params_t params
device initialization parameters
Definition ccs811.h:106