Add BME680 stub and update submodules
This commit is contained in:
parent
7d8e2261d2
commit
e4e6c76546
7 changed files with 86 additions and 3 deletions
5
components/i2c-bme680/CMakeLists.txt
Normal file
5
components/i2c-bme680/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
idf_component_register(
|
||||||
|
SRCS "bme680.c"
|
||||||
|
INCLUDE_DIRS include
|
||||||
|
REQUIRES "bus-i2c"
|
||||||
|
)
|
47
components/i2c-bme680/bme680.c
Normal file
47
components/i2c-bme680/bme680.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2022 Nicolai Electronics
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sdkconfig.h>
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include "bme680.h"
|
||||||
|
#include "managed_i2c.h"
|
||||||
|
|
||||||
|
static const char *TAG = "BME680";
|
||||||
|
|
||||||
|
esp_err_t bme680_check_id(BME680* device) {
|
||||||
|
uint8_t chip_id;
|
||||||
|
esp_err_t res = i2c_read_reg(device->i2c_bus, device->i2c_address, BME680_REG_CHIP_ID, &chip_id, 1);
|
||||||
|
if (res != ESP_OK) return res;
|
||||||
|
if (chip_id != BME680_CHIP_ID) {
|
||||||
|
ESP_LOGE(TAG, "Unexpected chip id value 0x%02X, expected 0x%02X", chip_id, BME680_CHIP_ID);
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t bme680_reset(BME680* device) {
|
||||||
|
uint8_t value = 0xFF;
|
||||||
|
esp_err_t res = i2c_write_reg_n(device->i2c_bus, device->i2c_address, BME680_REG_RESET, &value, 1);
|
||||||
|
if (res != ESP_OK) return res;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t bme680_init(BME680* device) {
|
||||||
|
esp_err_t res = bme680_reset(device);
|
||||||
|
if (res != ESP_OK) return res;
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
res = bme680_check_id(device);
|
||||||
|
if (res != ESP_OK) return res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t bme680_deinit(BME680* device) {
|
||||||
|
return bme680_reset(device);
|
||||||
|
}
|
19
components/i2c-bme680/include/bme680.h
Normal file
19
components/i2c-bme680/include/bme680.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <esp_err.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BME680_REG_RESET 0xE0
|
||||||
|
#define BME680_REG_CHIP_ID 0xD0
|
||||||
|
|
||||||
|
#define BME680_CHIP_ID 0x61
|
||||||
|
|
||||||
|
typedef struct BME680 {
|
||||||
|
int i2c_bus;
|
||||||
|
int i2c_address;
|
||||||
|
} BME680;
|
||||||
|
|
||||||
|
esp_err_t bme680_init(BME680* device);
|
||||||
|
esp_err_t bme680_deinit(BME680* device);
|
||||||
|
esp_err_t bme680_check_id(BME680* device);
|
||||||
|
esp_err_t bme680_reset(BME680* device);
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4ba1bb512e096d6b9ed2e07142c69037cfcdfe3c
|
Subproject commit aa0214c069b1b05a0392331c89dfa202a0fa61b1
|
|
@ -1 +1 @@
|
||||||
Subproject commit a7a07046cd8748cb29725559a3f6ee095301521b
|
Subproject commit 108625c65834d6cdfef60f4725be8c53c3ad6d61
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8fe7ca9876e2afed472c5d01170d4e76acdf6399
|
Subproject commit 62f7cef36fc12c626eca56764695673e15bcb539
|
12
main/main.c
12
main/main.c
|
@ -686,6 +686,18 @@ void app_main(void) {
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bsp_bme680_init() != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to initialize the BME680 position sensor");
|
||||||
|
display_fatal_error(pax_buffer, ili9341, "Failed to initialize", "BME680 sensor error", "Check I2C bus", "Remove SAO and try again");
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
BME680* bme680 = get_bme680();
|
||||||
|
if (bme680 == NULL) {
|
||||||
|
ESP_LOGE(TAG, "bme680 is NULL");
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
/* Start AppFS */
|
/* Start AppFS */
|
||||||
res = appfs_init();
|
res = appfs_init();
|
||||||
if (res != ESP_OK) {
|
if (res != ESP_OK) {
|
||||||
|
|
Loading…
Reference in a new issue