42#define CHIP_NAME                 "AMS CCS811"         
   43#define MANUFACTURER_NAME         "AMS"                
   44#define SUPPLY_VOLTAGE_MIN        1.8f                 
   45#define SUPPLY_VOLTAGE_MAX        3.6f                 
   46#define MAX_CURRENT               54.0f                
   47#define TEMPERATURE_MIN           -40.0f               
   48#define TEMPERATURE_MAX           85.0f                
   49#define DRIVER_VERSION            1000                 
   54#define CCS811_REG_STATUS                  0x00         
   55#define CCS811_REG_MEAS_MODE               0x01         
   56#define CCS811_REG_ALG_RESULT_DATA         0x02         
   57#define CCS811_REG_RAW_DATA                0x03         
   58#define CCS811_REG_ENV_DATA                0x05         
   59#define CCS811_REG_THRESHOLDS              0x10         
   60#define CCS811_REG_BASELINE                0x11         
   61#define CCS811_REG_APP_ERASE               0xF1         
   62#define CCS811_REG_APP_DATA                0xF2         
   63#define CCS811_REG_APP_VERIFY              0xF3         
   64#define CCS811_REG_APP_START               0xF4         
   65#define CCS811_REG_HW_ID                   0x20         
   66#define CCS811_REG_HW_VERSION              0x21         
   67#define CCS811_REG_FW_BOOT_VERSION         0x23         
   68#define CCS811_REG_FW_APP_VERSION          0x24         
   69#define CCS811_REG_ERROR_ID                0xE0         
   70#define CCS811_REG_SW_RESET                0xFF         
   83static uint8_t a_ccs811_iic_read(
ccs811_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
 
  104static uint8_t a_ccs811_iic_write(
ccs811_handle_t *handle, uint8_t reg, uint8_t *data, uint16_t len)
 
  130    handle->
iic_addr = (uint8_t)addr_pin;        
 
 
  183        handle->
debug_print(
"ccs811: get status failed.\n");              
 
 
  219        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
  228        handle->
debug_print(
"ccs811: set meas mode failed.\n");             
 
 
  264        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
 
  301        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
  310        handle->
debug_print(
"ccs811: set meas mode failed.\n");             
 
 
  346        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
 
  383        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
  392        handle->
debug_print(
"ccs811: set meas mode failed.\n");             
 
 
  428        handle->
debug_print(
"ccs811: get meas mode failed.\n");             
 
 
  481        *eco2_ppm = (((uint16_t)buf[0]) << 8) | buf[1];                         
 
  482        *tvoc_ppb = (((uint16_t)buf[2]) << 8) | buf[3];                         
 
  483        *raw = (((uint16_t)buf[6]) << 8) | buf[7];                              
 
  487        handle->
debug_print(
"ccs811: data is not ready.\n");                    
 
 
  529        handle->
debug_print(
"ccs811: get status failed.\n");                     
 
  548        *raw = (((uint16_t)buf[0]) << 8) | buf[1];                               
 
  550        *adc_raw = (uint16_t)(((uint16_t)(buf[0] & 0x03)) << 8) | buf[1];        
 
  551        *adc_v = (*adc_raw) * 1.65f / 1023.0f;                                   
 
  555        handle->
debug_print(
"ccs811: data is not ready.\n");                     
 
 
  589    buf[0] = (humidity_raw >> 8) & 0xFF;                                      
 
  590    buf[1] = (humidity_raw >> 0) & 0xFF;                                      
 
  591    buf[2] = (temperature_raw >> 8) & 0xFF;                                   
 
  592    buf[3] = (temperature_raw >> 0) & 0xFF;                                   
 
  596        handle->
debug_print(
"ccs811: set environment data failed.\n");        
 
 
  631    buf[0] = (low_medium_ppm >> 8) & 0xFF;                                  
 
  632    buf[1] = (low_medium_ppm >> 0) & 0xFF;                                  
 
  633    buf[2] = (medium_high_ppm >> 8) & 0xFF;                                 
 
  634    buf[3] = (medium_high_ppm >> 0) & 0xFF;                                 
 
  639        handle->
debug_print(
"ccs811: set threshold failed.\n");             
 
 
  672    buf[0] = (baseline >> 8) & 0xFF;                                      
 
  673    buf[1] = (baseline >> 0) & 0xFF;                                      
 
  677        handle->
debug_print(
"ccs811: set baseline failed.\n");            
 
 
  713        handle->
debug_print(
"ccs811: get baseline failed.\n");           
 
  717    *baseline = ((uint16_t)buf[0]) << 8 | buf[1];                        
 
 
  749        handle->
debug_print(
"ccs811: get hardware id failed.\n");        
 
 
  784        handle->
debug_print(
"ccs811: get hardware version failed.\n");         
 
 
  822        handle->
debug_print(
"ccs811: get version failed.\n");                   
 
  826    *major = (buf[0] >> 4) & 0xFF;                                              
 
  827    *minor = (buf[0] >> 0) & 0xFF;                                              
 
 
  863        handle->
debug_print(
"ccs811: get version failed.\n");                  
 
  867    *major = (buf[0] >> 4) & 0xFF;                                             
 
  868    *minor = (buf[0] >> 0) & 0xFF;                                             
 
 
  901        handle->
debug_print(
"ccs811: get error id failed.\n");          
 
 
  922    uint8_t cmd[] = {0x11, 0xE5, 0x72, 0x8A};
 
  936        handle->
debug_print(
"ccs811: soft reset failed.\n");              
 
 
  961    uint32_t timeout_ms = 5000;
 
  962    uint8_t cmd[] = {0xE7, 0xA7, 0xE6, 0x09};
 
  976        handle->
debug_print(
"ccs811: app erase failed.\n");                    
 
  981    for (i = 0; i < timeout_ms; i++)                                           
 
  986            handle->
debug_print(
"ccs811: get status failed.\n");               
 
  990        if ((status & (1 << 6)) != 0)                                          
 
 
 1017    uint32_t timeout_ms = 5000;
 
 1031        handle->
debug_print(
"ccs811: app verify failed.\n");                   
 
 1036    for (i = 0; i < timeout_ms; i++)                                           
 
 1041            handle->
debug_print(
"ccs811: get status failed.\n");               
 
 1045        if ((status & (1 << 5)) != 0)                                          
 
 
 1072    uint32_t timeout_ms = 1000;
 
 1086        handle->
debug_print(
"ccs811: app start failed.\n");                    
 
 1091    for (i = 0; i < timeout_ms; i++)                                           
 
 1096            handle->
debug_print(
"ccs811: get status failed.\n");               
 
 1100        if ((status & (1 << 4)) != 0)                                          
 
 
 1144    for (i = 0; i < len; i += 8)
 
 1149            handle->
debug_print(
"ccs811: app program failed.\n");                 
 
 
 1271    *reg = (uint16_t)(humidity * 512.0f);        
 
 
 1298    *humidity = (float)(reg) / 512.0f;        
 
 
 1325    *reg = (uint16_t)((temperature + 25.0f) * 512.0f);        
 
 
 1352    *temperature = (float)(reg) / 512.0f - 25.0f;        
 
 
 1377    uint32_t timeout_ms;
 
 1380    uint8_t cmd_erase[] = {0xE7, 0xA7, 0xE6, 0x09};
 
 1394        handle->
debug_print(
"ccs811: bin init failed.\n");                                    
 
 1398    if ((size % 8) != 0)                                                                      
 
 1400        handle->
debug_print(
"ccs811: size is invalid.\n");                                    
 
 1411        handle->
debug_print(
"ccs811: app erase failed.\n");                                   
 
 1417    for (i = 0; i < timeout_ms; i++)                                                          
 
 1422            handle->
debug_print(
"ccs811: get status failed.\n");                              
 
 1427        if ((status & (1 << 6)) != 0)                                                         
 
 1443    for (i = 0; i < size; i += 256)                                                           
 
 1445        len = ((size - i) >= 256) ? 256 : (size - i);                                         
 
 1449            handle->
debug_print(
"ccs811: bin read failed.\n");                                
 
 1455        for (j = 0; j < len; j += 8)                                                          
 
 1460                handle->
debug_print(
"ccs811: app program failed.\n");                         
 
 1474        handle->
debug_print(
"ccs811: app verify failed.\n");                                  
 
 1480    for (i = 0; i < timeout_ms; i++)                                                          
 
 1485            handle->
debug_print(
"ccs811: get status failed.\n");                              
 
 1490        if ((status & (1 << 5)) != 0)                                                         
 
 1508        handle->
debug_print(
"ccs811: bin deinit failed.\n");                                  
 
 
 1534    uint8_t cmd_reset[] = {0x11, 0xE5, 0x72, 0x8A};
 
 1546        handle->
debug_print(
"ccs811: iic_init is null.\n");                  
 
 1552        handle->
debug_print(
"ccs811: iic_deinit is null.\n");                
 
 1558        handle->
debug_print(
"ccs811: iic_write is null.\n");                 
 
 1564        handle->
debug_print(
"ccs811: iic_read is null.\n");                  
 
 1570        handle->
debug_print(
"ccs811: gpio_wake_init is null.\n");            
 
 1576        handle->
debug_print(
"ccs811: gpio_wake_deinit is null.\n");          
 
 1582        handle->
debug_print(
"ccs811: gpio_wake_write is null.\n");           
 
 1588        handle->
debug_print(
"ccs811: gpio_reset_init is null.\n");           
 
 1594        handle->
debug_print(
"ccs811: gpio_reset_deinit is null.\n");         
 
 1600        handle->
debug_print(
"ccs811: gpio_reset_write is null.\n");          
 
 1606        handle->
debug_print(
"ccs811: bin_read_init is null.\n");             
 
 1612        handle->
debug_print(
"ccs811: bin_read is null.\n");                  
 
 1618        handle->
debug_print(
"ccs811: bin_read_deinit is null.\n");           
 
 1624        handle->
debug_print(
"ccs811: delay_ms is null.\n");                  
 
 1631        handle->
debug_print(
"ccs811: iic init failed.\n");                   
 
 1637        handle->
debug_print(
"ccs811: gpio wake init failed.\n");             
 
 1644        handle->
debug_print(
"ccs811: gpio reset init failed.\n");            
 
 1688        handle->
debug_print(
"ccs811: get hardware id failed.\n");            
 
 1708        handle->
debug_print(
"ccs811: soft reset failed.\n");                 
 
 1716    for (i = 0; i < 1000; i++)                                               
 
 1721            handle->
debug_print(
"ccs811: get status failed.\n");             
 
 1728        if ((status & (1 << 4)) != 0)                                        
 
 1736        handle->
debug_print(
"ccs811: firmware loaded failed.\n");            
 
 
 1763    uint8_t cmd_reset[] = {0x11, 0xE5, 0x72, 0x8A};
 
 1775        handle->
debug_print(
"ccs811: iic_init is null.\n");                  
 
 1781        handle->
debug_print(
"ccs811: iic_deinit is null.\n");                
 
 1787        handle->
debug_print(
"ccs811: iic_write is null.\n");                 
 
 1793        handle->
debug_print(
"ccs811: iic_read is null.\n");                  
 
 1799        handle->
debug_print(
"ccs811: gpio_wake_init is null.\n");            
 
 1805        handle->
debug_print(
"ccs811: gpio_wake_deinit is null.\n");          
 
 1811        handle->
debug_print(
"ccs811: gpio_wake_write is null.\n");           
 
 1817        handle->
debug_print(
"ccs811: gpio_reset_init is null.\n");           
 
 1823        handle->
debug_print(
"ccs811: gpio_reset_deinit is null.\n");         
 
 1829        handle->
debug_print(
"ccs811: gpio_reset_write is null.\n");          
 
 1835        handle->
debug_print(
"ccs811: bin_read_init is null.\n");             
 
 1841        handle->
debug_print(
"ccs811: bin_read is null.\n");                  
 
 1847        handle->
debug_print(
"ccs811: bin_read_deinit is null.\n");           
 
 1853        handle->
debug_print(
"ccs811: delay_ms is null.\n");                  
 
 1860        handle->
debug_print(
"ccs811: iic init failed.\n");                   
 
 1866        handle->
debug_print(
"ccs811: gpio wake init failed.\n");             
 
 1873        handle->
debug_print(
"ccs811: gpio reset init failed.\n");            
 
 1917        handle->
debug_print(
"ccs811: get hardware id failed.\n");            
 
 1937        handle->
debug_print(
"ccs811: soft reset failed.\n");                 
 
 
 1991        handle->
debug_print(
"ccs811: gpio reset deinit failed.\n");        
 
 1997        handle->
debug_print(
"ccs811: gpio wake deinit failed.\n");         
 
 2003        handle->
debug_print(
"ccs811: iic close failed.\n");                
 
 
 2036    return a_ccs811_iic_write(handle, reg, buf, len);        
 
 
 2063    return a_ccs811_iic_read(handle, reg, buf, len);        
 
 
#define CCS811_REG_ENV_DATA
#define CCS811_REG_APP_DATA
#define CCS811_REG_HW_VERSION
#define CCS811_REG_SW_RESET
#define CCS811_REG_ALG_RESULT_DATA
#define CCS811_REG_FW_APP_VERSION
#define SUPPLY_VOLTAGE_MAX
#define CCS811_REG_ERROR_ID
#define CCS811_REG_THRESHOLDS
#define CCS811_REG_FW_BOOT_VERSION
#define CCS811_REG_APP_START
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CCS811_REG_MEAS_MODE
#define CCS811_REG_BASELINE
#define CCS811_REG_APP_VERIFY
#define CHIP_NAME
chip information definition
#define CCS811_REG_APP_ERASE
#define CCS811_REG_STATUS
chip register definition
#define CCS811_REG_RAW_DATA
driver ccs811 header file
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
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
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
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_DATA_READY
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
uint8_t(* gpio_reset_deinit)(void)
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)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v