picofuse

bme680.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <picofuse/hw.h>
10 #include <stdbool.h>
11 #include <stdint.h>
12 
14 // CONSTANTS
15 
21 #define DEV_BME680_I2C_ADDR_PRIMARY 0x76
22 
28 #define DEV_BME680_I2C_ADDR_SECONDARY 0x77
29 
36 #define DEV_BME680_CHIP_ID 0x61
37 
43 #define DEV_BME680_REG_CHIP_ID 0xD0u
44 
51 #define DEV_BME680_REG_VARIANT_ID 0xF0u
52 
59 #define DEV_BME680_REG_SOFT_RESET 0xE0u
60 
66 #define DEV_BME680_REG_FIELD0 0x1Du
67 
73 #define DEV_BME680_REG_RES_HEAT0 0x5Au
74 
80 #define DEV_BME680_REG_GAS_WAIT0 0x64u
81 
87 #define DEV_BME680_REG_CTRL_GAS_0 0x70u
88 
94 #define DEV_BME680_REG_CTRL_GAS_1 0x71u
95 
101 #define DEV_BME680_REG_CTRL_HUM 0x72u
102 
108 #define DEV_BME680_REG_CTRL_MEAS 0x74u
109 
115 #define DEV_BME680_REG_CONFIG 0x75u
116 
122 #define DEV_BME680_REG_COEFF1 0x8Au
123 
129 #define DEV_BME680_REG_COEFF2 0xE1u
130 
136 #define DEV_BME680_REG_COEFF3 0x00u
137 
144 #define DEV_BME680_SOFT_RESET_CMD 0xB6u
145 
152 #define DEV_BME680_VARIANT_GAS_LOW 0x00u
153 
160 #define DEV_BME680_VARIANT_GAS_HIGH 0x01u
161 
163 // TYPES
164 
169 typedef struct dev_bme680_t dev_bme680_t;
170 
176 typedef enum {
177  dev_bme680_oversampling_skip = 0,
178  dev_bme680_oversampling_1x = 1,
179  dev_bme680_oversampling_2x = 2,
180  dev_bme680_oversampling_4x = 3,
181  dev_bme680_oversampling_8x = 4,
182  dev_bme680_oversampling_16x = 5,
184 
190 typedef enum {
191  dev_bme680_iir_filter_off = 0,
192  dev_bme680_iir_filter_1 = 1,
193  dev_bme680_iir_filter_3 = 2,
194  dev_bme680_iir_filter_7 = 3,
195  dev_bme680_iir_filter_15 = 4,
196  dev_bme680_iir_filter_31 = 5,
197  dev_bme680_iir_filter_63 = 6,
198  dev_bme680_iir_filter_127 = 7,
200 
206 typedef enum {
207  dev_bme680_heater_temp_200c = 200,
208  dev_bme680_heater_temp_250c = 250,
209  dev_bme680_heater_temp_300c = 300,
210  dev_bme680_heater_temp_320c = 320,
211  dev_bme680_heater_temp_350c = 350,
212  dev_bme680_heater_temp_400c = 400,
214 
220 typedef enum {
221  dev_bme680_heater_dur_50ms = 50,
222  dev_bme680_heater_dur_100ms = 100,
223  dev_bme680_heater_dur_120ms = 120,
224  dev_bme680_heater_dur_150ms = 150,
225  dev_bme680_heater_dur_200ms = 200,
227 
233 typedef enum {
234  dev_bme680_ambient_temp_0c = 0,
235  dev_bme680_ambient_temp_10c = 10,
236  dev_bme680_ambient_temp_20c = 20,
237  dev_bme680_ambient_temp_25c = 25,
238  dev_bme680_ambient_temp_30c = 30,
239  dev_bme680_ambient_temp_35c = 35,
240  dev_bme680_ambient_temp_40c = 40,
242 
247 typedef enum {
248  dev_bme680_gas_disabled = 0,
249  dev_bme680_gas_enabled = 1,
251 
256 typedef struct {
258  float pressure_pa;
259  float humidity_pct;
262 
269 typedef struct {
277  dev_bme680_gas_mode_t gas_mode;
281 
283 // LIFECYCLE
284 
294 
305  const dev_bme680_config_t *config);
306 
315 void dev_bme680_deinit(dev_bme680_t *bme680);
316 
319 // PROPERTIES
321 
331 uint8_t dev_bme680_chip_id(const dev_bme680_t *bme680);
332 
349 
352 // METHODS
354 
366 bool dev_bme680_read(dev_bme680_t *bme680, dev_bme680_data_t *data);
367 
dev_bme680_iir_filter_t
IIR filter coefficient applied to BME680 temperature/pressure readings.
Definition: bme680.h:190
dev_bme680_ambient_temp_t
Ambient temperature used by the BME680 to compute gas heater control parameters, in degrees Celsius...
Definition: bme680.h:233
dev_bme680_iir_filter_t iir_filter
IIR filter coefficient.
Definition: bme680.h:273
struct hw_deviceio_t hw_deviceio_t
Opaque device I/O handle.
Definition: deviceio.h:48
BME680 measurement values.
Definition: bme680.h:256
dev_bme680_gas_mode_t
Whether the BME680&#39;s gas heater is enabled.
Definition: bme680.h:247
BME680 runtime configuration.
Definition: bme680.h:269
dev_bme680_heater_duration_t
Gas heater conditioning duration for the BME680 gas sensor, in milliseconds.
Definition: bme680.h:220
float pressure_pa
Pressure in pascals.
Definition: bme680.h:258
dev_bme680_heater_temp_t
Target heater plate temperature for the BME680 gas sensor, in degrees Celsius.
Definition: bme680.h:206
float humidity_pct
Relative humidity in percent.
Definition: bme680.h:259
float temperature_c
Temperature in degrees Celsius.
Definition: bme680.h:257
float gas_resistance_ohms
Gas resistance in ohms.
Definition: bme680.h:260
struct dev_bme680_t dev_bme680_t
Opaque BME680 handle.
Definition: bme680.h:169
dev_bme680_oversampling_t os_temp
Temperature oversampling.
Definition: bme680.h:270
dev_bme680_ambient_temp_t ambient_temp_c
Ambient temperature, used by the heater resistance calculation.
Definition: bme680.h:276
Hardware abstraction headers for on-board peripherals.
bool dev_bme680_read(dev_bme680_t *bme680, dev_bme680_data_t *data)
Read sensor data from BME680.
uint32_t dev_bme680_measurement_duration_ms(const dev_bme680_config_t *config)
Calculate how long a measurement takes to complete for a given configuration.
dev_bme680_heater_temp_t heater_temp_c
Gas heater target temperature.
Definition: bme680.h:274
dev_bme680_oversampling_t os_hum
Humidity oversampling.
Definition: bme680.h:272
dev_bme680_heater_duration_t heater_duration_ms
Gas heater duration.
Definition: bme680.h:275
void dev_bme680_default_config(dev_bme680_config_t *config)
Fill a BME680 config struct with safe defaults.
dev_bme680_oversampling_t os_press
Pressure oversampling.
Definition: bme680.h:271
dev_bme680_t * dev_bme680_init(hw_deviceio_t *device, const dev_bme680_config_t *config)
Initialize a BME680 sensor.
void dev_bme680_deinit(dev_bme680_t *bme680)
Deinitialize a BME680 sensor.
uint8_t dev_bme680_chip_id(const dev_bme680_t *bme680)
Get the detected chip ID.
dev_bme680_oversampling_t
Oversampling rate for a BME680 measurement channel (temperature, pressure, or humidity).
Definition: bme680.h:176