|
|
@ -78,6 +78,10 @@ static BME68X_INTF_RET_TYPE user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, u |
|
|
|
i2c_reg_read(cmd, itf->dev_addr, reg_addr, reg_data, length); |
|
|
|
i2c_reg_read(cmd, itf->dev_addr, reg_addr, reg_data, length); |
|
|
|
esp_err_t ret = i2c_master_cmd_begin(VOC_I2C_NUM, cmd, pdMS_TO_TICKS(VOC_I2C_TO_MS)); |
|
|
|
esp_err_t ret = i2c_master_cmd_begin(VOC_I2C_NUM, cmd, pdMS_TO_TICKS(VOC_I2C_TO_MS)); |
|
|
|
i2c_cmd_link_delete(cmd); |
|
|
|
i2c_cmd_link_delete(cmd); |
|
|
|
|
|
|
|
if (ret != ESP_OK) { |
|
|
|
|
|
|
|
ESP_LOGE(TAG, "I2C read error: %s, devaddr %x, reg %d, len %d", esp_err_to_name(ret), itf->dev_addr, reg_addr, length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ESP_LOG_BUFFER_HEXDUMP(TAG, reg_data, length, ESP_LOG_DEBUG); |
|
|
|
return ret == ESP_OK ? BME68X_OK : BME68X_E_COM_FAIL; |
|
|
|
return ret == ESP_OK ? BME68X_OK : BME68X_E_COM_FAIL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -91,6 +95,9 @@ static BME68X_INTF_RET_TYPE user_i2c_write(uint8_t reg_addr, const uint8_t *reg_ |
|
|
|
i2c_reg_write(cmd, itf->dev_addr, reg_addr, reg_data, length); |
|
|
|
i2c_reg_write(cmd, itf->dev_addr, reg_addr, reg_data, length); |
|
|
|
esp_err_t ret = i2c_master_cmd_begin(VOC_I2C_NUM, cmd, pdMS_TO_TICKS(VOC_I2C_TO_MS)); |
|
|
|
esp_err_t ret = i2c_master_cmd_begin(VOC_I2C_NUM, cmd, pdMS_TO_TICKS(VOC_I2C_TO_MS)); |
|
|
|
i2c_cmd_link_delete(cmd); |
|
|
|
i2c_cmd_link_delete(cmd); |
|
|
|
|
|
|
|
if (ret != ESP_OK) { |
|
|
|
|
|
|
|
ESP_LOGE(TAG, "I2C write error: %s, devaddr %x, reg %d, len %d", esp_err_to_name(ret), itf->dev_addr, reg_addr, length); |
|
|
|
|
|
|
|
} |
|
|
|
return ret == ESP_OK ? BME68X_OK : BME68X_E_COM_FAIL; |
|
|
|
return ret == ESP_OK ? BME68X_OK : BME68X_E_COM_FAIL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -103,7 +110,6 @@ static esp_err_t voc_init(void) { |
|
|
|
gas_sensor.read = user_i2c_read; |
|
|
|
gas_sensor.read = user_i2c_read; |
|
|
|
gas_sensor.write = user_i2c_write; |
|
|
|
gas_sensor.write = user_i2c_write; |
|
|
|
gas_sensor.delay_us = user_delay_us; |
|
|
|
gas_sensor.delay_us = user_delay_us; |
|
|
|
gas_sensor.intf_ptr = &gas_sensor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int retry = 0; retry < 3; retry++) { |
|
|
|
for (int retry = 0; retry < 3; retry++) { |
|
|
|
ESP_LOGD(TAG, "BME680 initializing"); |
|
|
|
ESP_LOGD(TAG, "BME680 initializing"); |
|
|
@ -180,13 +186,13 @@ void voc_read_task(void *param) { |
|
|
|
|
|
|
|
|
|
|
|
if (ESP_OK != voc_init()) { |
|
|
|
if (ESP_OK != voc_init()) { |
|
|
|
ESP_LOGE(TAG, "Fail to init sensor!"); |
|
|
|
ESP_LOGE(TAG, "Fail to init sensor!"); |
|
|
|
return; |
|
|
|
goto abort; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int rv = bsec2_init(&gas_sensor_bsec, &gas_sensor); |
|
|
|
int rv = bsec2_init(&gas_sensor_bsec, &gas_sensor); |
|
|
|
if (rv != 0) { |
|
|
|
if (rv != 0) { |
|
|
|
ESP_LOGE(TAG, "Error in bsec init: %d", rv); |
|
|
|
ESP_LOGE(TAG, "Error in bsec init: %d", rv); |
|
|
|
return; |
|
|
|
goto abort; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bsecSensor sensorList[] = { |
|
|
|
bsecSensor sensorList[] = { |
|
|
@ -214,7 +220,7 @@ void voc_read_task(void *param) { |
|
|
|
|
|
|
|
|
|
|
|
if (false == rv) { |
|
|
|
if (false == rv) { |
|
|
|
ESP_LOGE(TAG, "Fail to update bsec subscriptions!"); |
|
|
|
ESP_LOGE(TAG, "Fail to update bsec subscriptions!"); |
|
|
|
return; |
|
|
|
goto abort; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bsec2_attachCallback(&gas_sensor_bsec, new_data_callback); |
|
|
|
bsec2_attachCallback(&gas_sensor_bsec, new_data_callback); |
|
|
@ -235,4 +241,7 @@ void voc_read_task(void *param) { |
|
|
|
} |
|
|
|
} |
|
|
|
vTaskDelay(pdMS_TO_TICKS(100)); |
|
|
|
vTaskDelay(pdMS_TO_TICKS(100)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abort: |
|
|
|
|
|
|
|
vTaskDelete(NULL); |
|
|
|
} |
|
|
|
} |
|
|
|