42#define CHIP_NAME                 "Bosch BME680"         
   43#define MANUFACTURER_NAME         "Bosch"                
   44#define SUPPLY_VOLTAGE_MIN        1.71f                  
   45#define SUPPLY_VOLTAGE_MAX        3.6f                   
   46#define MAX_CURRENT               0.849f                 
   47#define TEMPERATURE_MIN           -40.0f                 
   48#define TEMPERATURE_MAX           85.0f                  
   49#define DRIVER_VERSION            1000                   
   54#define BME680_REG_NVM_PAR_T1_L        0xE9         
   55#define BME680_REG_NVM_PAR_T1_H        0xEA         
   56#define BME680_REG_NVM_PAR_T2_L        0x8A         
   57#define BME680_REG_NVM_PAR_T2_H        0x8B         
   58#define BME680_REG_NVM_PAR_T3          0x8C         
   59#define BME680_REG_NVM_PAR_P1_L        0x8E         
   60#define BME680_REG_NVM_PAR_P1_H        0x8F         
   61#define BME680_REG_NVM_PAR_P2_L        0x90         
   62#define BME680_REG_NVM_PAR_P2_H        0x91         
   63#define BME680_REG_NVM_PAR_P3          0x92         
   64#define BME680_REG_NVM_PAR_P4_L        0x94         
   65#define BME680_REG_NVM_PAR_P4_H        0x95         
   66#define BME680_REG_NVM_PAR_P5_L        0x96         
   67#define BME680_REG_NVM_PAR_P5_H        0x97         
   68#define BME680_REG_NVM_PAR_P6          0x99         
   69#define BME680_REG_NVM_PAR_P7          0x98         
   70#define BME680_REG_NVM_PAR_P8_L        0x9C         
   71#define BME680_REG_NVM_PAR_P8_H        0x9D         
   72#define BME680_REG_NVM_PAR_P9_L        0x9E         
   73#define BME680_REG_NVM_PAR_P9_H        0x9F         
   74#define BME680_REG_NVM_PAR_P10         0xA0         
   75#define BME680_REG_NVM_PAR_H1_L        0xE2         
   76#define BME680_REG_NVM_PAR_H1_H        0xE3         
   77#define BME680_REG_NVM_PAR_H2_L        0xE2         
   78#define BME680_REG_NVM_PAR_H2_H        0xE1         
   79#define BME680_REG_NVM_PAR_H3          0xE4         
   80#define BME680_REG_NVM_PAR_H4          0xE5         
   81#define BME680_REG_NVM_PAR_H5          0xE6         
   82#define BME680_REG_NVM_PAR_H6          0xE7         
   83#define BME680_REG_NVM_PAR_H7          0xE8         
   84#define BME680_REG_NVM_PAR_G1          0xED         
   85#define BME680_REG_NVM_PAR_G2_L        0xEB         
   86#define BME680_REG_NVM_PAR_G2_H        0xEC         
   87#define BME680_REG_NVM_PAR_G3          0xEE         
   88#define BME680_REG_NVM_RES_HEAT_RANGE  0x02         
   89#define BME680_REG_NVM_RES_HEAT_VAL    0x00         
   90#define BME680_REG_NVM_RANGE_SWITCH    0x04         
   91#define BME680_REG_STATUS              0x73         
   92#define BME680_REG_RESET               0xE0         
   93#define BME680_REG_ID                  0xD0         
   94#define BME680_REG_CONFIG              0x75         
   95#define BME680_REG_CTRL_MEAS           0x74         
   96#define BME680_REG_CTRL_HUM            0x72         
   97#define BME680_REG_CTRL_GAS_1          0x71         
   98#define BME680_REG_CTRL_GAS_0          0x70         
   99#define BME680_REG_GAS_WAIT_X          0x64         
  100#define BME680_REG_RES_HEAT_X          0x5A         
  101#define BME680_REG_IDAC_HEAT_X         0x50         
  102#define BME680_REG_GAS_R_LSB           0x2B         
  103#define BME680_REG_GAS_R_MSB           0x2A         
  104#define BME680_REG_HUM_LSB             0x26         
  105#define BME680_REG_HUM_MSB             0x25         
  106#define BME680_REG_TEMP_XLSB           0x24         
  107#define BME680_REG_TEMP_LSB            0x23         
  108#define BME680_REG_TEMP_MSB            0x22         
  109#define BME680_REG_PRESS_XLSB          0x21         
  110#define BME680_REG_PRESS_LSB           0x20         
  111#define BME680_REG_PRESS_MSB           0x1F         
  112#define BME680_REG_EAS_STATUS_0        0x1D         
  123static uint8_t a_bme680_change_spi_page(
bme680_handle_t *handle, uint8_t page)
 
  130    if (handle->
spi_read(reg, buf, 1) != 0)         
 
  163static uint8_t a_bme680_iic_spi_read(
bme680_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 
  178            if (handle->
page != 0)                                         
 
  180                if (a_bme680_change_spi_page(handle, 0) != 0)              
 
  187            if (handle->
spi_read(reg, buf, len) != 0)                      
 
  194            if (handle->
page == 0)                                         
 
  196                if (a_bme680_change_spi_page(handle, 1) != 0)              
 
  202            if (handle->
spi_read(reg, buf, len) != 0)                      
 
  223static uint8_t a_bme680_iic_spi_write(
bme680_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
 
  238            if (handle->
page != 0)                                         
 
  240                if (a_bme680_change_spi_page(handle, 0) != 0)              
 
  247            if (handle->
spi_write(reg, buf, len) != 0)                     
 
  254            if (handle->
page == 0)                                         
 
  256                if (a_bme680_change_spi_page(handle, 1) != 0)              
 
  262            if (handle->
spi_write(reg, buf, len) != 0)                     
 
  287        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  291    handle->
par_t1 = (uint16_t)buf[1] << 8 | buf[0];                                           
 
  294        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  298    handle->
par_t2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  301        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  305    handle->
par_t3 = (int8_t)(reg);                                                            
 
  308        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  312    handle->
par_p1 = (uint16_t)buf[1] <<8 | buf[0];                                            
 
  315        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  319    handle->
par_p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  322        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  326    handle->
par_p3 = (int8_t)(reg);                                                            
 
  329        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  333    handle->
par_p4 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  336        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  340    handle->
par_p5 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  343        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  347    handle->
par_p6 = (int8_t)(reg);                                                            
 
  350        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  354    handle->
par_p7 = (int8_t)(reg);                                                            
 
  357        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  361    handle->
par_p8 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  364        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  368    handle->
par_p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                                
 
  371        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  375    handle->
par_p10 = (uint8_t)(reg);                                                          
 
  378        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  382    handle->
par_h1 = (uint16_t)((uint16_t)buf[1] << 4 | buf[0] & 0xF);                         
 
  385        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  389    handle->
par_h2 = (uint16_t)((uint16_t)buf[0] << 4 | ((buf[1] >> 4) & 0xF));                
 
  392        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  396    handle->
par_h3 = (int8_t)reg;                                                              
 
  399        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  403    handle->
par_h4 = (int8_t)reg;                                                              
 
  406        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  410    handle->
par_h5 = (int8_t)reg;                                                              
 
  413        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  417    handle->
par_h6 = (int8_t)reg;                                                              
 
  420        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  424    handle->
par_h7 = (int8_t)reg;                                                              
 
  427        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  434        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  438    handle->
par_gh2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);                               
 
  441        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  448        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  455        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  462        handle->
debug_print(
"bme680: get calibration data failed.\n");                         
 
  483static uint8_t a_bme680_compensate_temperature(
bme680_handle_t *handle, uint32_t raw, 
float *output)
 
  488    var1 = ((((float)raw / 16384.0f) - ((float)handle->
par_t1 / 1024.0f)) * ((float)handle->
par_t2));                 
 
  489    var2 = (((((float)raw / 131072.0f) - ((float)handle->
par_t1 / 8192.0f)) *
 
  490           (((float)raw / 131072.0f) - ((float)handle->
par_t1 / 8192.0f))) * ((float)handle->
par_t3 * 16.0f));        
 
  491    handle->
t_fine = (var1 + var2);                                                                                   
 
  492    *output = ((handle->
t_fine) / 5120.0f);                                                                           
 
  507static uint8_t a_bme680_compensate_pressure(
bme680_handle_t *handle, uint32_t raw, 
float *output)
 
  514    var1 = (((float)handle->
t_fine / 2.0f) - 64000.0f);                                                        
 
  515    var2 = var1 * var1 * (((float)handle->
par_p6) / (131072.0f));                                              
 
  516    var2 = var2 + (var1 * ((float)handle->
par_p5) * 2.0f);                                                     
 
  517    var2 = (var2 / 4.0f) + (((
float)handle->
par_p4) * 65536.0f);                                               
 
  518    var1 = (((((float)handle->
par_p3 * var1 * var1) / 16384.0f) + 
 
  519           ((float)handle->
par_p2 * var1)) / 524288.0f);                                                       
 
  520    var1 = ((1.0f + (var1 / 32768.0f)) * ((float)handle->
par_p1));                                             
 
  521    calc_pres = (1048576.0f - ((float)raw));                                                                   
 
  522    if ((int32_t)var1 != 0)                                                                                    
 
  524        calc_pres = (((calc_pres - (var2 / 4096.0f)) * 6250.0f) / var1);                                       
 
  525        var1 = (((float)handle->
par_p9) * calc_pres * calc_pres) / 2147483648.0f;                              
 
  526        var2 = calc_pres * (((float)handle->
par_p8) / 32768.0f);                                               
 
  527        var3 = ((calc_pres / 256.0f) * (calc_pres / 256.0f) * (calc_pres / 256.0f) * 
 
  528               ((float)handle->
par_p10 / 131072.0f));                                                          
 
  529        calc_pres = (calc_pres + (var1 + var2 + var3 + ((float)handle->
par_p7 * 128.0f)) / 16.0f);             
 
  550static uint8_t a_bme680_compensate_humidity(
bme680_handle_t *handle, uint16_t raw, 
float *output)
 
  559    temp_comp = ((handle->
t_fine) / 5120.0f);                                                       
 
  560    var1 = (float)((
float)raw) -
 
  561           (((float)handle->
par_h1 * 16.0f) + (((float)handle->
par_h3 / 2.0f) * temp_comp));        
 
  562    var2 = var1 * ((float)(((float)handle->
par_h2 / 262144.0f) *
 
  563           (1.0f + (((float)handle->
par_h4 / 16384.0f) * temp_comp) +
 
  564           (((float)handle->
par_h5 / 1048576.0f) * temp_comp * temp_comp))));                       
 
  565    var3 = (float)handle->
par_h6 / 16384.0f;                                                        
 
  566    var4 = (float)handle->
par_h7 / 2097152.0f;                                                      
 
  567    calc_hum = var2 + ((var3 + (var4 * temp_comp)) * var2 * var2);                                  
 
  568    if (calc_hum > 100.0f)                                                                          
 
  572    else if (calc_hum < 0.0f)                                                                       
 
  595static uint8_t a_bme680_compensate_heat(
bme680_handle_t *handle, 
float temp, uint8_t *reg)
 
  608    var1 = (((float)handle->
par_gh1 / (16.0f)) + 49.0f);                                    
 
  609    var2 = ((((float)handle->
par_gh2 / (32768.0f)) * (0.0005f)) + 0.00235f);                
 
  610    var3 = ((float)handle->
par_gh3 / (1024.0f));                                            
 
  611    var4 = (var1 * (1.0f + (var2 * (float)temp)));                                          
 
  612    var5 = (var4 + (var3 * (float)handle->
amb_temp));                                       
 
  613    res_heat = (uint8_t)(3.4f * ((var5 * (4 / (4 + (
float)handle->
res_heat_range)) *
 
  614               (1 / (1 + ((
float)handle->
res_heat_val * 0.002f)))) - 25));                  
 
  631static uint8_t a_bme680_compensate_gas_resistance(
bme680_handle_t *handle, uint16_t gas_res_adc, uint8_t gas_range, 
float *ohms)
 
  637    float gas_res_f = (float)gas_res_adc;
 
  638    float gas_range_f = (float)(1U << gas_range);
 
  639    const float lookup_k1_range[16] =
 
  641        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, -0.8f, 0.0f, 0.0f, -0.2f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f
 
  643    const float lookup_k2_range[16] =
 
  645        0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.7f, 0.0f, -0.8f, -0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f
 
  649    var2 = (var1) * (1.0f + lookup_k1_range[gas_range] / 100.0f);              
 
  650    var3 = 1.0f + (lookup_k2_range[gas_range] / 100.0f);                       
 
  651    calc_gas_res = 1.0f / (float)(var3 * (0.000000125f) * gas_range_f * 
 
  652                   (((gas_res_f - 512.0f) / var2) + 1.0f));                    
 
  653    *ohms = calc_gas_res;                                                      
 
  674    handle->
iic_addr = (uint8_t)addr_pin;        
 
 
  716    handle->
iic_spi = (uint8_t)interface;      
 
 
  770        handle->
debug_print(
"bme680: iic_init is null.\n");                          
 
  776        handle->
debug_print(
"bme680: iic_deinit is null.\n");                        
 
  782        handle->
debug_print(
"bme680: iic_read is null.\n");                          
 
  788        handle->
debug_print(
"bme680: iic_write is null.\n");                         
 
  794        handle->
debug_print(
"bme680: spi_init is null.\n");                          
 
  800        handle->
debug_print(
"bme680: spi_deinit is null.\n");                        
 
  806        handle->
debug_print(
"bme680: spi_read is null.\n");                          
 
  812        handle->
debug_print(
"bme680: spi_write is null.\n");                         
 
  818        handle->
debug_print(
"bme680: delay_ms is null.\n");                          
 
  840        if (a_bme680_change_spi_page(handle, 0) != 0)                                
 
  842            handle->
debug_print(
"bme680: change spi page failed.\n");                
 
  848    if (a_bme680_iic_spi_read(handle, 
BME680_REG_ID, (uint8_t *)&
id, 1) != 0)        
 
  871    if (a_bme680_get_nvm_calibration(handle) != 0)                                   
 
 
  908        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                    
 
  916        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                   
 
  924            handle->
debug_print(
"bme680: iic deinit failed.\n");                    
 
  933            handle->
debug_print(
"bme680: spi deinit failed.\n");                    
 
 
  978        handle->
debug_print(
"bme680: write idac heat failed.\n");                             
 
 
 1018        handle->
debug_print(
"bme680: read idac heat failed.\n");                           
 
 
 1061        handle->
debug_print(
"bme680: write resistance heat failed.\n");                      
 
 
 1101        handle->
debug_print(
"bme680: read resistance heat failed.\n");                    
 
 
 1144        handle->
debug_print(
"bme680: write gas wait failed.\n");                             
 
 
 1184        handle->
debug_print(
"bme680: read gas wait failed.\n");                           
 
 
 1253        handle->
debug_print(
"bme680: read status failed.\n");                       
 
 
 1288        handle->
debug_print(
"bme680: read status failed.\n");                       
 
 
 1323        handle->
debug_print(
"bme680: read status failed.\n");                       
 
 
 1358        handle->
debug_print(
"bme680: read status failed.\n");                       
 
 1362    *index = (prev & 0xF);                                                          
 
 
 1393        handle->
debug_print(
"bme680: read gas lsb failed.\n");                   
 
 
 1428        handle->
debug_print(
"bme680: read gas lsb failed.\n");                   
 
 
 1463        handle->
debug_print(
"bme680: read ctrl hum failed.\n");                
 
 1468    prev |= enable << 6;                                                       
 
 1471        handle->
debug_print(
"bme680: write ctrl hum failed.\n");               
 
 
 1505        handle->
debug_print(
"bme680: read ctrl hum failed.\n");                
 
 
 1540        handle->
debug_print(
"bme680: read ctrl hum failed.\n");                
 
 1545    prev |= oversampling << 0;                                                 
 
 1548        handle->
debug_print(
"bme680: write ctrl hum failed.\n");               
 
 
 1582        handle->
debug_print(
"bme680: read ctrl hum failed.\n");                
 
 
 1617        handle->
debug_print(
"bme680: read ctrl meas failed.\n");               
 
 1622    prev |= oversampling << 5;                                                 
 
 1625        handle->
debug_print(
"bme680: write ctrl meas failed.\n");              
 
 
 1659        handle->
debug_print(
"bme680: read ctrl meas failed.\n");               
 
 
 1694        handle->
debug_print(
"bme680: read ctrl meas failed.\n");               
 
 1699    prev |= oversampling << 2;                                                 
 
 1702        handle->
debug_print(
"bme680: write ctrl meas failed.\n");              
 
 
 1736        handle->
debug_print(
"bme680: read ctrl meas failed.\n");               
 
 
 1771        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                    
 
 1779        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                   
 
 
 1813        handle->
debug_print(
"bme680: read ctrl meas failed.\n");               
 
 
 1848        handle->
debug_print(
"bme680: read config failed.\n");                    
 
 1853    prev |= (filter & 0x07) << 2;                                                
 
 1856        handle->
debug_print(
"bme680: write config failed.\n");                   
 
 
 1890        handle->
debug_print(
"bme680: read config failed.\n");                    
 
 
 1925        handle->
debug_print(
"bme680: read config failed.\n");                    
 
 1933        handle->
debug_print(
"bme680: write config failed.\n");                   
 
 
 1967        handle->
debug_print(
"bme680: read config failed.\n");                    
 
 
 2002        handle->
debug_print(
"bme680: read ctrl gas0 failed.\n");                 
 
 2007    prev |= enable << 3;                                                         
 
 2010        handle->
debug_print(
"bme680: write ctrl gas0 failed.\n");                
 
 
 2044        handle->
debug_print(
"bme680: read ctrl gas0 failed.\n");                 
 
 
 2079        handle->
debug_print(
"bme680: read ctrl gas1 failed.\n");                 
 
 2084    prev |= enable << 4;                                                         
 
 2087        handle->
debug_print(
"bme680: write ctrl gas1 failed.\n");                
 
 
 2121        handle->
debug_print(
"bme680: read ctrl gas1 failed.\n");                 
 
 
 2163        handle->
debug_print(
"bme680: read ctrl gas1 failed.\n");                 
 
 2167    prev &= ~(0x0F << 0);                                                        
 
 2168    prev |= (index & 0x0F) << 0;                                                 
 
 2171        handle->
debug_print(
"bme680: write ctrl gas1 failed.\n");                
 
 
 2205        handle->
debug_print(
"bme680: read ctrl gas1 failed.\n");                 
 
 2209    *index = prev & 0x0F;                                                        
 
 
 2236    (void)a_bme680_compensate_heat(handle, degree_celsius, reg);        
 
 
 2263    *reg = ((uint8_t)(ma * 8) - 1) << 1;        
 
 
 2290    *ma = (float)(((reg >> 1) + 1) / 8);        
 
 
 2334        *reg = (uint8_t)(ms + (factor * 64));                  
 
 
 2376        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2384        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2388    timeout = 10 * 1000;                                                                   
 
 2389    while (timeout != 0)                                                                   
 
 2393            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2397        if ((prev & 0x03) == 0)                                                            
 
 2417    if ((buf[1] & (1 << 5)) == 0)                                                          
 
 2423    if ((buf[1] & (1 << 4)) == 0)                                                          
 
 2425        handle->
debug_print(
"bme680: heater is not stable.\n");                            
 
 2429    *adc_raw = (((uint16_t)buf[0]) << 2) | ((buf[1] >> 6) & 0x03);                         
 
 2430    *adc_range = buf[1] & 0x0F;                                                            
 
 2431    res = a_bme680_compensate_gas_resistance(handle, *adc_raw , *adc_range, ohms);         
 
 2434        handle->
debug_print(
"bme680: compensate gas resistance failed.\n");                
 
 2440        handle->
debug_print(
"bme680: read status failed.\n");                              
 
 2444    *index = (prev & 0xF);                                                                 
 
 
 2468    uint32_t temperature_raw;
 
 2469    float temperature_c;
 
 2483        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2491        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2495    timeout = 10 * 1000;                                                                   
 
 2496    while (timeout != 0)                                                                   
 
 2500            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2504        if ((prev & 0x03) == 0)                                                            
 
 2524    temperature_raw = ((((uint32_t)(buf[3])) << 12) |
 
 2525                      (((uint32_t)(buf[4])) << 4) |
 
 2526                      ((uint32_t)buf[5] >> 4));                                            
 
 2527    res = a_bme680_compensate_temperature(handle, temperature_raw, &temperature_c);        
 
 2530        handle->
debug_print(
"bme680: compensate temperature failed.\n");                   
 
 2534    *pressure_raw = ((((int32_t)(buf[0])) << 12) |
 
 2535                    (((int32_t)(buf[1])) << 4) |
 
 2536                    (((int32_t)(buf[2])) >> 4));                                           
 
 2537    res = a_bme680_compensate_pressure(handle, *pressure_raw, pressure_pa);                
 
 2540        handle->
debug_print(
"bme680: compensate pressure failed.\n");                      
 
 
 2580        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2588        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2592    timeout = 10 * 1000;                                                                   
 
 2593    while (timeout != 0)                                                                   
 
 2597            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2601        if ((prev & 0x03) == 0)                                                            
 
 2621    *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
 
 2622                       (((uint32_t)(buf[4])) << 4) |
 
 2623                       ((uint32_t)buf[5] >> 4));                                           
 
 2624    res = a_bme680_compensate_temperature(handle, *temperature_raw, temperature_c);        
 
 2627        handle->
debug_print(
"bme680: compensate temperature failed.\n");                   
 
 
 2654    uint32_t temperature_raw;
 
 2655    float temperature_c;
 
 2669        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2677        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2681    timeout = 10 * 1000;                                                                   
 
 2682    while (timeout != 0)                                                                   
 
 2686            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2690        if ((prev & 0x03) == 0)                                                            
 
 2710    temperature_raw = ((((uint32_t)(buf[3])) << 12) |
 
 2711                      (((uint32_t)(buf[4])) << 4) |
 
 2712                      ((uint32_t)buf[5] >> 4));                                            
 
 2713    res = a_bme680_compensate_temperature(handle, temperature_raw, &temperature_c);        
 
 2716        handle->
debug_print(
"bme680: compensate temperature failed.\n");                   
 
 2720    *humidity_raw = (uint32_t)buf[6] << 8 | buf[7];                                        
 
 2721    res = a_bme680_compensate_humidity(handle, *humidity_raw, humidity_percentage);        
 
 2724        handle->
debug_print(
"bme680: compensate humidity failed.\n");                      
 
 
 2751                                                  uint32_t *pressure_raw, 
float *pressure_pa,
 
 2752                                                  uint32_t *humidity_raw, 
float *humidity_percentage)
 
 2770        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2778        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2782    timeout = 10 * 1000;                                                                   
 
 2783    while (timeout != 0)                                                                   
 
 2787            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2791        if ((prev & 0x03) == 0)                                                            
 
 2811    *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
 
 2812                       (((uint32_t)(buf[4])) << 4) |
 
 2813                       ((uint32_t)buf[5] >> 4));                                           
 
 2814    res = a_bme680_compensate_temperature(handle, *temperature_raw, temperature_c);        
 
 2817        handle->
debug_print(
"bme680: compensate temperature failed.\n");                   
 
 2821    *pressure_raw = ((((int32_t)(buf[0])) << 12) |
 
 2822                    (((int32_t)(buf[1])) << 4) |
 
 2823                    (((int32_t)(buf[2])) >> 4));                                           
 
 2824    res = a_bme680_compensate_pressure(handle, *pressure_raw, pressure_pa);                
 
 2827        handle->
debug_print(
"bme680: compensate pressure failed.\n");                      
 
 2831    *humidity_raw = (uint32_t)buf[6] << 8 | buf[7];                                        
 
 2832    res = a_bme680_compensate_humidity(handle, *humidity_raw, humidity_percentage);        
 
 2835        handle->
debug_print(
"bme680: compensate humidity failed.\n");                      
 
 
 2868                    uint32_t *pressure_raw, 
float *pressure_pa,
 
 2869                    uint32_t *humidity_raw, 
float *humidity_percentage,
 
 2870                    uint16_t *adc_raw, uint8_t *adc_range, 
float *ohms, uint8_t *index)
 
 2888        handle->
debug_print(
"bme680: read ctrl meas failed.\n");                           
 
 2896        handle->
debug_print(
"bme680: write ctrl meas failed.\n");                          
 
 2900    timeout = 10 * 1000;                                                                   
 
 2901    while (timeout != 0)                                                                   
 
 2905            handle->
debug_print(
"bme680: read ctrl meas failed.\n");                       
 
 2909        if ((prev & 0x03) == 0)                                                            
 
 2929    *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
 
 2930                       (((uint32_t)(buf[4])) << 4) |
 
 2931                       ((uint32_t)buf[5] >> 4));                                           
 
 2932    res = a_bme680_compensate_temperature(handle, *temperature_raw, temperature_c);        
 
 2935        handle->
debug_print(
"bme680: compensate temperature failed.\n");                   
 
 2939    *pressure_raw = ((((int32_t)(buf[0])) << 12) |
 
 2940                    (((int32_t)(buf[1])) << 4) |
 
 2941                    (((int32_t)(buf[2])) >> 4));                                           
 
 2942    res = a_bme680_compensate_pressure(handle, *pressure_raw, pressure_pa);                
 
 2945        handle->
debug_print(
"bme680: compensate pressure failed.\n");                      
 
 2949    *humidity_raw = (uint32_t)buf[6] << 8 | buf[7];                                        
 
 2950    res = a_bme680_compensate_humidity(handle, *humidity_raw, humidity_percentage);        
 
 2953        handle->
debug_print(
"bme680: compensate humidity failed.\n");                      
 
 2965    if ((buf[1] & (1 << 5)) == 0)                                                          
 
 2971    if ((buf[1] & (1 << 4)) == 0)                                                          
 
 2973        handle->
debug_print(
"bme680: heater is not stable.\n");                            
 
 2977    *adc_raw = (((uint16_t)buf[0]) << 2) | ((buf[1] >> 6) & 0x03);                         
 
 2978    *adc_range = buf[1] & 0x0F;                                                            
 
 2979    res = a_bme680_compensate_gas_resistance(handle, *adc_raw , *adc_range, ohms);         
 
 2982        handle->
debug_print(
"bme680: compensate gas resistance failed.\n");                
 
 2988        handle->
debug_print(
"bme680: read status failed.\n");                              
 
 2992    *index = (prev & 0xF);                                                                 
 
 
 3021    return a_bme680_iic_spi_write(handle, reg, buf, len);       
 
 
 3048    return a_bme680_iic_spi_read(handle, reg, buf, len);       
 
 
#define BME680_REG_NVM_PAR_G3
#define BME680_REG_NVM_PAR_P1_L
#define BME680_REG_NVM_PAR_P7
#define BME680_REG_NVM_PAR_H5
#define BME680_REG_NVM_PAR_P3
#define BME680_REG_IDAC_HEAT_X
#define BME680_REG_NVM_RES_HEAT_VAL
#define BME680_REG_NVM_PAR_G2_L
#define BME680_REG_CONFIG
#define BME680_REG_NVM_PAR_P8_L
#define BME680_REG_CTRL_GAS_0
#define BME680_REG_NVM_PAR_P6
#define BME680_REG_CTRL_GAS_1
#define SUPPLY_VOLTAGE_MAX
#define BME680_REG_NVM_PAR_T3
#define BME680_REG_NVM_PAR_H7
#define BME680_REG_GAS_WAIT_X
#define BME680_REG_NVM_PAR_H6
#define BME680_REG_NVM_PAR_H1_L
#define BME680_REG_GAS_R_LSB
#define BME680_REG_NVM_PAR_P4_L
#define BME680_REG_PRESS_MSB
#define BME680_REG_EAS_STATUS_0
#define BME680_REG_CTRL_HUM
#define BME680_REG_NVM_PAR_P10
#define BME680_REG_NVM_RES_HEAT_RANGE
#define BME680_REG_NVM_PAR_H3
#define BME680_REG_NVM_PAR_P5_L
#define BME680_REG_NVM_PAR_G1
#define BME680_REG_GAS_R_MSB
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BME680_REG_NVM_PAR_P9_L
#define BME680_REG_CTRL_MEAS
#define BME680_REG_NVM_PAR_H2_H
#define BME680_REG_RES_HEAT_X
#define BME680_REG_NVM_PAR_P2_L
#define BME680_REG_STATUS
#define BME680_REG_NVM_PAR_H4
#define CHIP_NAME
chip information definition
#define BME680_REG_NVM_PAR_T2_L
#define BME680_REG_NVM_RANGE_SWITCH
#define BME680_REG_NVM_PAR_T1_L
chip register definition
driver bme680 header file
uint8_t bme680_set_run_gas(bme680_handle_t *handle, bme680_bool_t enable)
enable or disable run gas
uint8_t bme680_gas_wait_convert_to_register(bme680_handle_t *handle, uint16_t ms, uint8_t *reg)
convert the gas wait to the register raw data
uint8_t bme680_set_filter(bme680_handle_t *handle, bme680_filter_t filter)
set filter
uint8_t bme680_read(bme680_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa, uint32_t *humidity_raw, float *humidity_percentage, uint16_t *adc_raw, uint8_t *adc_range, float *ohms, uint8_t *index)
read the temperature pressure humidity and gas resistance
uint8_t bme680_get_measuring_status(bme680_handle_t *handle, bme680_bool_t *enable)
get measuring status
uint8_t bme680_deinit(bme680_handle_t *handle)
close the chip
uint8_t bme680_get_mode(bme680_handle_t *handle, bme680_mode_t *mode)
get mode
uint8_t bme680_get_gas_measuring_index(bme680_handle_t *handle, uint8_t *index)
get gas measuring index
bme680_filter_t
bme680 filter enumeration definition
uint8_t bme680_set_temperature_oversampling(bme680_handle_t *handle, bme680_oversampling_t oversampling)
set temperature oversampling
uint8_t bme680_set_heat_off(bme680_handle_t *handle, bme680_bool_t enable)
enable or disable heat off
bme680_mode_t
bme680 mode enumeration definition
uint8_t bme680_set_interface(bme680_handle_t *handle, bme680_interface_t interface)
set the interface
uint8_t bme680_set_idac_heat(bme680_handle_t *handle, uint8_t index, uint8_t reg)
set idac heat
uint8_t bme680_set_convert_index(bme680_handle_t *handle, uint8_t index)
set convert index
uint8_t bme680_get_spi_wire_3_data_interrupt(bme680_handle_t *handle, bme680_bool_t *enable)
get spi wire3 data interrupt status
uint8_t bme680_read_pressure(bme680_handle_t *handle, uint32_t *pressure_raw, float *pressure_pa)
read the pressure data
uint8_t bme680_set_spi_wire_3_data_interrupt(bme680_handle_t *handle, bme680_bool_t enable)
enable or disable spi wire3 data interrupt
uint8_t bme680_get_temperature_oversampling(bme680_handle_t *handle, bme680_oversampling_t *oversampling)
get temperature oversampling
uint8_t bme680_get_resistance_heat(bme680_handle_t *handle, uint8_t index, uint8_t *reg)
get resistance heat
uint8_t bme680_get_heat_off(bme680_handle_t *handle, bme680_bool_t *enable)
get heat off status
uint8_t bme680_get_interface(bme680_handle_t *handle, bme680_interface_t *interface)
get the interface
bme680_interface_t
bme680 interface enumeration definition
uint8_t bme680_set_resistance_heat(bme680_handle_t *handle, uint8_t index, uint8_t reg)
set resistance heat
uint8_t bme680_set_gas_wait(bme680_handle_t *handle, uint8_t index, uint8_t reg)
set gas wait
uint8_t bme680_info(bme680_info_t *info)
get chip's information
struct bme680_info_s bme680_info_t
bme680 information structure definition
uint8_t bme680_read_temperature(bme680_handle_t *handle, uint32_t *temperature_raw, float *temperature_c)
read the temperature data
uint8_t bme680_get_idac_heat(bme680_handle_t *handle, uint8_t index, uint8_t *reg)
get idac heat
uint8_t bme680_read_humidity(bme680_handle_t *handle, uint32_t *humidity_raw, float *humidity_percentage)
read the humidity data
uint8_t bme680_get_filter(bme680_handle_t *handle, bme680_filter_t *filter)
get filter
uint8_t bme680_resistance_heat_convert_to_register(bme680_handle_t *handle, float degree_celsius, uint8_t *reg)
convert the resistance heat to the register raw data
uint8_t bme680_init(bme680_handle_t *handle)
initialize the chip
uint8_t bme680_get_spi_wire(bme680_handle_t *handle, bme680_spi_wire_t *spi)
get spi wire
bme680_address_t
bme680 address enumeration definition
uint8_t bme680_read_gas_resistance(bme680_handle_t *handle, uint16_t *adc_raw, uint8_t *adc_range, float *ohms, uint8_t *index)
read the gas resistance
uint8_t bme680_soft_reset(bme680_handle_t *handle)
soft reset
bme680_oversampling_t
bme680 oversampling enumeration definition
uint8_t bme680_get_humidity_oversampling(bme680_handle_t *handle, bme680_oversampling_t *oversampling)
get humidity oversampling
uint8_t bme680_get_new_data_status(bme680_handle_t *handle, bme680_bool_t *enable)
get new data status
uint8_t bme680_idac_heat_convert_to_register(bme680_handle_t *handle, float ma, uint8_t *reg)
convert the idac heat to the register raw data
uint8_t bme680_set_spi_wire(bme680_handle_t *handle, bme680_spi_wire_t spi)
set spi wire
bme680_bool_t
bme680 bool enumeration definition
uint8_t bme680_get_gas_measuring_status(bme680_handle_t *handle, bme680_bool_t *enable)
get gas measuring status
uint8_t bme680_set_addr_pin(bme680_handle_t *handle, bme680_address_t addr_pin)
set the iic address pin
uint8_t bme680_set_pressure_oversampling(bme680_handle_t *handle, bme680_oversampling_t oversampling)
set pressure oversampling
uint8_t bme680_set_mode(bme680_handle_t *handle, bme680_mode_t mode)
set mode
struct bme680_handle_s bme680_handle_t
bme680 handle structure definition
uint8_t bme680_get_run_gas(bme680_handle_t *handle, bme680_bool_t *enable)
get run gas status
bme680_spi_wire_t
bme680 spi wire enumeration definition
uint8_t bme680_read_temperature_pressure_humidity(bme680_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa, uint32_t *humidity_raw, float *humidity_percentage)
read the temperature pressure and humidity data
uint8_t bme680_idac_heat_convert_to_data(bme680_handle_t *handle, uint8_t reg, float *ma)
convert the register raw data to idac heat
uint8_t bme680_get_heater_stability_status(bme680_handle_t *handle, bme680_bool_t *enable)
get heater stability status
uint8_t bme680_set_humidity_oversampling(bme680_handle_t *handle, bme680_oversampling_t oversampling)
set humidity oversampling
uint8_t bme680_get_convert_index(bme680_handle_t *handle, uint8_t *index)
get convert index
uint8_t bme680_get_gas_wait(bme680_handle_t *handle, uint8_t index, uint8_t *reg)
get gas wait
uint8_t bme680_get_gas_valid_status(bme680_handle_t *handle, bme680_bool_t *enable)
get gas valid status
uint8_t bme680_get_addr_pin(bme680_handle_t *handle, bme680_address_t *addr_pin)
get the iic address pin
uint8_t bme680_get_pressure_oversampling(bme680_handle_t *handle, bme680_oversampling_t *oversampling)
get pressure oversampling
uint8_t bme680_get_reg(bme680_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t bme680_set_reg(bme680_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
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