Initial commit
This commit is contained in:
139
BME68x_manager.h
Normal file
139
BME68x_manager.h
Normal file
@@ -0,0 +1,139 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// I2C configuration - can be overridden in config.h
|
||||
#ifndef I2C_MASTER_SCL_IO
|
||||
#define I2C_MASTER_SCL_IO 7 /*!< Default GPIO for I2C master clock */
|
||||
#endif
|
||||
#ifndef I2C_MASTER_SDA_IO
|
||||
#define I2C_MASTER_SDA_IO 6 /*!< Default GPIO for I2C master data */
|
||||
#endif
|
||||
#ifndef I2C_MASTER_NUM
|
||||
#define I2C_MASTER_NUM I2C_NUM_0 /*!< Default I2C port number */
|
||||
#endif
|
||||
#ifndef I2C_MASTER_FREQ_HZ
|
||||
#define I2C_MASTER_FREQ_HZ 100000 /*!< Default I2C frequency */
|
||||
#endif
|
||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_TIMEOUT_MS 1000
|
||||
|
||||
// BME68x I2C address (can be 0x76 or 0x77 depending on SDO pin)
|
||||
#define BME68x_I2C_ADDR_PRIMARY 0x76
|
||||
#define BME68x_I2C_ADDR_SECONDARY 0x77
|
||||
|
||||
// BME68x register addresses
|
||||
#define BME68x_REG_CHIP_ID 0xD0
|
||||
#define BME68x_CHIP_ID 0x61
|
||||
#define BME68x_REG_CTRL_MEAS 0x74
|
||||
#define BME68x_REG_CTRL_HUM 0x72
|
||||
#define BME68x_REG_CONFIG 0x75
|
||||
#define BME68x_REG_MEAS_STATUS_0 0x1D
|
||||
#define BME68x_REG_PRESS_MSB 0x1F
|
||||
#define BME68x_REG_TEMP_MSB 0x22
|
||||
#define BME68x_REG_HUM_MSB 0x25
|
||||
#define BME68x_REG_GAS_R_MSB 0x2A
|
||||
#define BME68x_REG_GAS_R_LSB 0x2B
|
||||
#define BME68x_REG_CTRL_GAS_1 0x71
|
||||
#define BME68x_REG_GAS_WAIT_0 0x64
|
||||
#define BME68x_REG_RES_HEAT_0 0x5A
|
||||
|
||||
// Calibration coefficient addresses
|
||||
#define BME68x_COEFF_ADDR1 0x89
|
||||
#define BME68x_COEFF_ADDR2 0xE1
|
||||
|
||||
// BME68x oversampling definitions
|
||||
#define BME68x_OS_NONE 0x00
|
||||
#define BME68x_OS_1X 0x01
|
||||
#define BME68x_OS_2X 0x02
|
||||
#define BME68x_OS_4X 0x03
|
||||
#define BME68x_OS_8X 0x04
|
||||
#define BME68x_OS_16X 0x05
|
||||
|
||||
// BME68x field bit positions
|
||||
#define BME68x_OST_SEL 5
|
||||
#define BME68x_OSP_SEL 2
|
||||
#define BME68x_OSH_SEL 0
|
||||
#define BME68x_FILTER_SEL 2
|
||||
|
||||
// BME68x IIR filter definitions
|
||||
#define BME68x_FILTER_SIZE_3 0x02
|
||||
|
||||
// Gas sensor definitions
|
||||
#define BME68x_DISABLE_GAS_MEAS 0x00
|
||||
#define BME68x_ENABLE_GAS_MEAS 0x01
|
||||
#define BME68x_RUN_GAS_SEL 4
|
||||
#define BME68x_NB_CONV_SEL 0
|
||||
|
||||
// BME68x sensor data structure
|
||||
typedef struct
|
||||
{
|
||||
float temperature;
|
||||
float pressure;
|
||||
float humidity;
|
||||
float gas_resistance;
|
||||
uint8_t gas_valid;
|
||||
uint8_t heat_stab;
|
||||
uint8_t air_quality_score;
|
||||
} BME68x_data_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize I2C master interface
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_i2c_init(void);
|
||||
|
||||
/**
|
||||
* @brief Perform I2C bus recovery
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_i2c_recovery(void);
|
||||
|
||||
/**
|
||||
* @brief Scan I2C bus for devices
|
||||
*/
|
||||
void bme68x_i2c_scan(void);
|
||||
|
||||
/**
|
||||
* @brief Test BME68x sensor connection and read chip ID
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_test_connection(void);
|
||||
|
||||
/**
|
||||
* @brief Perform soft reset of BME68x sensor
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_soft_reset(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize BME68x sensor
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_init(void);
|
||||
|
||||
/**
|
||||
* @brief Read sensor data from BME68x
|
||||
* @param data Pointer to BME68x_data_t structure to store the data
|
||||
* @return ESP_OK on success, error code on failure
|
||||
*/
|
||||
esp_err_t bme68x_read_data(BME68x_data_t *data);
|
||||
|
||||
/**
|
||||
* @brief Get current I2C address being used
|
||||
* @return Current I2C address (0x76 or 0x77)
|
||||
*/
|
||||
uint8_t bme68x_get_current_address(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user