LibDriver CCS811
Loading...
Searching...
No Matches
driver_ccs811.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_CCS811_H
38#define DRIVER_CCS811_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
64 CCS811_ADDRESS_GND = (0x5A << 1),
65 CCS811_ADDRESS_VCC = (0x5B << 1),
67
71typedef enum
72{
76
88
99
108
121
125typedef struct ccs811_handle_s
126{
127 uint8_t (*iic_init)(void);
128 uint8_t (*iic_deinit)(void);
129 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
130 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
131 uint8_t (*gpio_wake_init)(void);
132 uint8_t (*gpio_wake_deinit)(void);
133 uint8_t (*gpio_wake_write)(uint8_t level);
134 uint8_t (*gpio_reset_init)(void);
135 uint8_t (*gpio_reset_deinit)(void);
136 uint8_t (*gpio_reset_write)(uint8_t level);
137 void (*delay_ms)(uint32_t ms);
138 void (*debug_print)(const char *const fmt, ...);
139 uint8_t (*bin_read_init)(char *name, uint32_t *size);
140 uint8_t (*bin_read)(uint32_t addr, uint16_t size, uint8_t *buffer);
141 uint8_t (*bin_read_deinit)(void);
142 uint8_t inited;
143 uint8_t iic_addr;
144 uint8_t buf[256];
146
162
166
173
180#define DRIVER_CCS811_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
181
188#define DRIVER_CCS811_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
189
196#define DRIVER_CCS811_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
197
204#define DRIVER_CCS811_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
205
212#define DRIVER_CCS811_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
213
220#define DRIVER_CCS811_LINK_GPIO_WAKE_INIT(HANDLE, FUC) (HANDLE)->gpio_wake_init = FUC
221
228#define DRIVER_CCS811_LINK_GPIO_WAKE_DEINIT(HANDLE, FUC) (HANDLE)->gpio_wake_deinit = FUC
229
236#define DRIVER_CCS811_LINK_GPIO_WAKE_WRITE(HANDLE, FUC) (HANDLE)->gpio_wake_write = FUC
237
244#define DRIVER_CCS811_LINK_GPIO_RESET_INIT(HANDLE, FUC) (HANDLE)->gpio_reset_init = FUC
245
252#define DRIVER_CCS811_LINK_GPIO_RESET_DEINIT(HANDLE, FUC) (HANDLE)->gpio_reset_deinit = FUC
253
260#define DRIVER_CCS811_LINK_GPIO_RESET_WRITE(HANDLE, FUC) (HANDLE)->gpio_reset_write = FUC
261
268#define DRIVER_CCS811_LINK_BIN_READ_INIT(HANDLE, FUC) (HANDLE)->bin_read_init = FUC
269
276#define DRIVER_CCS811_LINK_BIN_READ_DEINIT(HANDLE, FUC) (HANDLE)->bin_read_deinit = FUC
277
284#define DRIVER_CCS811_LINK_BIN_READ(HANDLE, FUC) (HANDLE)->bin_read = FUC
285
292#define DRIVER_CCS811_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
293
300#define DRIVER_CCS811_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
301
305
312
321uint8_t ccs811_info(ccs811_info_t *info);
322
332uint8_t ccs811_set_addr_pin(ccs811_handle_t *handle, ccs811_address_t addr_pin);
333
343uint8_t ccs811_get_addr_pin(ccs811_handle_t *handle, ccs811_address_t *addr_pin);
344
357uint8_t ccs811_init(ccs811_handle_t *handle);
358
370uint8_t ccs811_deinit(ccs811_handle_t *handle);
371
387uint8_t ccs811_read(ccs811_handle_t *handle, uint16_t *eco2_ppm, uint16_t *tvoc_ppb, uint16_t *raw);
388
405uint8_t ccs811_get_raw_data(ccs811_handle_t *handle, uint16_t *raw, uint8_t *ua, uint16_t *adc_raw, float *adc_v);
406
418uint8_t ccs811_get_status(ccs811_handle_t *handle, uint8_t *status);
419
431uint8_t ccs811_set_mode(ccs811_handle_t *handle, ccs811_mode_t mode);
432
444uint8_t ccs811_get_mode(ccs811_handle_t *handle, ccs811_mode_t *mode);
445
458
471
484
497
510uint8_t ccs811_set_environment_data(ccs811_handle_t *handle, uint16_t humidity_raw, uint16_t temperature_raw);
511
525uint8_t ccs811_set_eco2_threshold(ccs811_handle_t *handle, uint16_t low_medium_ppm, uint16_t medium_high_ppm, uint8_t hysteresis);
526
538uint8_t ccs811_set_baseline(ccs811_handle_t *handle, uint16_t baseline);
539
551uint8_t ccs811_get_baseline(ccs811_handle_t *handle, uint16_t *baseline);
552
564uint8_t ccs811_get_error_id(ccs811_handle_t *handle, uint8_t *id);
565
577uint8_t ccs811_get_hardware_id(ccs811_handle_t *handle, uint8_t *id);
578
590uint8_t ccs811_get_hardware_version(ccs811_handle_t *handle, uint8_t *version);
591
605uint8_t ccs811_get_firmware_bootloader_version(ccs811_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *trivial);
606
620uint8_t ccs811_get_firmware_application_version(ccs811_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *trivial);
621
632uint8_t ccs811_soft_reset(ccs811_handle_t *handle);
633
645uint8_t ccs811_wake_up(ccs811_handle_t *handle, ccs811_bool_t enable);
646
657uint8_t ccs811_hard_reset(ccs811_handle_t *handle);
658
670uint8_t ccs811_environment_humidity_convert_to_register(ccs811_handle_t *handle, float humidity, uint16_t *reg);
671
683uint8_t ccs811_environment_humidity_convert_to_data(ccs811_handle_t *handle, uint16_t reg, float *humidity);
684
696uint8_t ccs811_environment_temperature_convert_to_register(ccs811_handle_t *handle, float temperature, uint16_t *reg);
697
709uint8_t ccs811_environment_temperature_convert_to_data(ccs811_handle_t *handle, uint16_t reg, float *temperature);
710
714
721
733uint8_t ccs811_app_erase(ccs811_handle_t *handle);
734
746uint8_t ccs811_app_verify(ccs811_handle_t *handle);
747
759uint8_t ccs811_app_start(ccs811_handle_t *handle);
760
774uint8_t ccs811_app_program(ccs811_handle_t *handle, uint8_t *rom, uint32_t len);
775
788
802uint8_t ccs811_app_firmware_update(ccs811_handle_t *handle, char *path);
803
807
814
828uint8_t ccs811_set_reg(ccs811_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
829
843uint8_t ccs811_get_reg(ccs811_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
844
848
852
853#ifdef __cplusplus
854}
855#endif
856
857#endif
uint8_t ccs811_app_firmware_update(ccs811_handle_t *handle, char *path)
app firmware update
uint8_t ccs811_app_program(ccs811_handle_t *handle, uint8_t *rom, uint32_t len)
app program
uint8_t ccs811_app_start(ccs811_handle_t *handle)
app start
uint8_t ccs811_app_erase(ccs811_handle_t *handle)
app erase
uint8_t ccs811_app_verify(ccs811_handle_t *handle)
app verify
uint8_t ccs811_app_firmware_init(ccs811_handle_t *handle)
app firmware initialize
struct ccs811_info_s ccs811_info_t
ccs811 information structure definition
uint8_t ccs811_set_addr_pin(ccs811_handle_t *handle, ccs811_address_t addr_pin)
set address pin
struct ccs811_handle_s ccs811_handle_t
ccs811 handle structure definition
ccs811_status_t
ccs811 status enumeration definition
uint8_t ccs811_get_addr_pin(ccs811_handle_t *handle, ccs811_address_t *addr_pin)
get address pin
uint8_t ccs811_set_eco2_threshold(ccs811_handle_t *handle, uint16_t low_medium_ppm, uint16_t medium_high_ppm, uint8_t hysteresis)
set eco2 threshold
ccs811_address_t
ccs811 address enumeration definition
uint8_t ccs811_get_interrupt_threshold(ccs811_handle_t *handle, ccs811_bool_t *enable)
get interrupt threshold status
uint8_t ccs811_hard_reset(ccs811_handle_t *handle)
hard reset
uint8_t ccs811_environment_temperature_convert_to_register(ccs811_handle_t *handle, float temperature, uint16_t *reg)
convert real data format to register data format
uint8_t ccs811_get_hardware_version(ccs811_handle_t *handle, uint8_t *version)
get hardware version
uint8_t ccs811_environment_humidity_convert_to_data(ccs811_handle_t *handle, uint16_t reg, float *humidity)
convert register data to real data format
ccs811_error_t
ccs811 error enumeration definition
uint8_t ccs811_set_baseline(ccs811_handle_t *handle, uint16_t baseline)
set baseline
uint8_t ccs811_environment_humidity_convert_to_register(ccs811_handle_t *handle, float humidity, uint16_t *reg)
convert real data format to register data format
uint8_t ccs811_get_error_id(ccs811_handle_t *handle, uint8_t *id)
get error id
uint8_t ccs811_set_mode(ccs811_handle_t *handle, ccs811_mode_t mode)
set mode
uint8_t ccs811_get_firmware_bootloader_version(ccs811_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *trivial)
get firmware bootloader version
uint8_t ccs811_soft_reset(ccs811_handle_t *handle)
soft reset
ccs811_bool_t
ccs811 bool enumeration definition
uint8_t ccs811_get_interrupt_data_ready(ccs811_handle_t *handle, ccs811_bool_t *enable)
get interrupt data ready status
uint8_t ccs811_get_baseline(ccs811_handle_t *handle, uint16_t *baseline)
get baseline
uint8_t ccs811_set_environment_data(ccs811_handle_t *handle, uint16_t humidity_raw, uint16_t temperature_raw)
set environment data
uint8_t ccs811_set_interrupt_data_ready(ccs811_handle_t *handle, ccs811_bool_t enable)
enable or disable interrupt data ready
uint8_t ccs811_read(ccs811_handle_t *handle, uint16_t *eco2_ppm, uint16_t *tvoc_ppb, uint16_t *raw)
read data
ccs811_interrupt
ccs811 interrupt enumeration definition
uint8_t ccs811_get_firmware_application_version(ccs811_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *trivial)
get firmware application version
uint8_t ccs811_environment_temperature_convert_to_data(ccs811_handle_t *handle, uint16_t reg, float *temperature)
convert register data to real data format
uint8_t ccs811_set_interrupt_threshold(ccs811_handle_t *handle, ccs811_bool_t enable)
enable or disable interrupt threshold
uint8_t ccs811_info(ccs811_info_t *info)
get chip information
uint8_t ccs811_get_hardware_id(ccs811_handle_t *handle, uint8_t *id)
get hardware id
uint8_t ccs811_init(ccs811_handle_t *handle)
initialize the chip
uint8_t ccs811_deinit(ccs811_handle_t *handle)
close the chip
uint8_t ccs811_get_mode(ccs811_handle_t *handle, ccs811_mode_t *mode)
get mode
ccs811_mode_t
ccs811 mode enumeration definition
uint8_t ccs811_get_status(ccs811_handle_t *handle, uint8_t *status)
get status
uint8_t ccs811_get_raw_data(ccs811_handle_t *handle, uint16_t *raw, uint8_t *ua, uint16_t *adc_raw, float *adc_v)
get raw data
uint8_t ccs811_wake_up(ccs811_handle_t *handle, ccs811_bool_t enable)
wake up
@ CCS811_STATUS_FW_MODE
@ CCS811_STATUS_APP_VALID
@ CCS811_STATUS_ERROR
@ CCS811_STATUS_DATA_READY
@ CCS811_ADDRESS_VCC
@ CCS811_ADDRESS_GND
@ CCS811_ERROR_HEATER_FAULT
@ CCS811_ERROR_WRITE_REG_INVALID
@ CCS811_ERROR_HEATER_SUPPLY
@ CCS811_ERROR_READ_REG_INVALID
@ CCS811_ERROR_MAX_RESISTANCE
@ CCS811_ERROR_MEASMODE_INVALID
@ CCS811_BOOL_TRUE
@ CCS811_BOOL_FALSE
@ CCS811_INTERRUPT_THRESHOLD
@ CCS811_INTERRUPT_READY
@ CCS811_MODE_LOW_POWER_PULSE_HEATING
@ CCS811_MODE_IDLE
@ CCS811_MODE_CONSTANT_POWER
@ CCS811_MODE_PULSE_HEATING
@ CCS811_MODE_HIGH_CONSTANT_POWER
uint8_t ccs811_set_reg(ccs811_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t ccs811_get_reg(ccs811_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
ccs811 handle structure definition
uint8_t(* gpio_reset_deinit)(void)
uint8_t buf[256]
uint8_t(* gpio_wake_init)(void)
uint8_t(* gpio_wake_write)(uint8_t level)
uint8_t(* gpio_wake_deinit)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* bin_read_init)(char *name, uint32_t *size)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* bin_read)(uint32_t addr, uint16_t size, uint8_t *buffer)
uint8_t(* gpio_reset_write)(uint8_t level)
uint8_t(* bin_read_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* gpio_reset_init)(void)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
ccs811 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]