bme680.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Mesotic SAS
3  * 2020 Gunar Schorcht
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
108 #ifndef BME680_H
109 #define BME680_H
110 
111 #include "periph/i2c.h"
112 #include "periph/spi.h"
113 
114 #ifdef MODULE_BME680_FP
115 #define BME680_FLOAT_POINT_COMPENSATION
116 #endif
117 
118 #include "bme680_hal.h"
119 #include "bme680_internal.h"
120 
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124 
128 #define BME680_I2C_ADDR_1 (0x76)
129 
133 #define BME680_I2C_ADDR_2 (0x77)
134 
139 #define BME680_SENSOR(d) (*((struct bme680_dev *)d))
140 
144 enum {
150 };
151 
152 #ifdef DOXYGEN
153 
156 typedef struct bme680_field_data {
157  uint8_t status;
161  uint8_t gas_index;
162  uint8_t meas_index;
163 #ifndef MODULE_BME680_FP
164  int16_t temperature;
165  uint32_t pressure;
166  uint32_t humidity;
167  uint32_t gas_resistance;
168 #else /* MODULE_BME680_FP */
169  float temperature;
170  float pressure;
171  float humidity;
172  float gas_resistance;
173 #endif /* MODULE_BME680_FP */
174 };
175 
176 #endif /* DOXYGEN */
177 
182 
187 typedef struct bme680_dev bme680_dev_t;
188 
192 typedef struct {
194  uint8_t addr;
196 
200 typedef struct {
202  gpio_t nss_pin;
204 
208 typedef union {
211 } bme680_intf_t;
212 
216 typedef struct {
217  uint8_t ifsel;
218  uint8_t temp_os;
219  uint8_t hum_os;
220  uint8_t pres_os;
221  uint8_t filter;
222  uint8_t gas_measure;
223  uint16_t heater_dur;
224  uint16_t heater_temp;
225  uint8_t power_mode;
226  uint8_t settings;
229 
233 typedef struct {
234  struct bme680_dev sensor;
236 } bme680_t;
237 
241 extern bme680_t *bme680_devs[];
242 
246 extern unsigned int bme680_devs_numof;
247 
257 int bme680_init(bme680_t *dev, const bme680_params_t *params);
258 
273 
287 int bme680_get_duration(bme680_t* dev);
288 
305 
318 int bme680_set_ambient_temp(bme680_t* dev, int8_t temp);
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 
324 #endif /* BME680_H */
325 
bme680_params_t::intf
bme680_intf_t intf
Hardware interface parameters.
Definition: bme680.h:227
bme680_intf_i2c_t::addr
uint8_t addr
I2C address.
Definition: bme680.h:194
bme680_force_measurement
int bme680_force_measurement(bme680_t *dev)
Force a single TPHG measurement cycle.
spi.h
Low-level SPI peripheral driver interface definition.
bme680_params_t::pres_os
uint8_t pres_os
Pressure oversampling.
Definition: bme680.h:220
bme680_field_data::temperature
int16_t temperature
Temperature in degree Celsius x 100.
Definition: bme680.h:164
bme680_intf_spi_t::nss_pin
gpio_t nss_pin
Chip Select pin.
Definition: bme680.h:202
bme680_devs_numof
unsigned int bme680_devs_numof
Number of initialized BME680 sensor devices in bme680_devs.
bme680_intf_t::i2c
bme680_intf_i2c_t i2c
I2C specific interface parameters.
Definition: bme680.h:209
bme680_intf_i2c_t
BME680 I2C parameters.
Definition: bme680.h:192
bme680_params_t::hum_os
uint8_t hum_os
Humidity oversampling.
Definition: bme680.h:219
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
BME680_NO_DEV
@ BME680_NO_DEV
Device doesn't exist.
Definition: bme680.h:147
bme680_intf_t::spi
bme680_intf_spi_t spi
SPI specific interface parameters.
Definition: bme680.h:210
bme680_field_data::meas_index
uint8_t meas_index
Measurement index.
Definition: bme680.h:162
bme680_hal.h
Abstraction layer for RIOT adaption.
bme680_params_t::ifsel
uint8_t ifsel
Interface selection.
Definition: bme680.h:217
bme680_params_t
BME680 device initialization parameters.
Definition: bme680.h:216
bme680_intf_spi_t::dev
spi_t dev
SPI device which is used.
Definition: bme680.h:201
bme680_set_ambient_temp
int bme680_set_ambient_temp(bme680_t *dev, int8_t temp)
Set the ambient temperature.
BME680_INVALID
@ BME680_INVALID
Invalid value or length.
Definition: bme680.h:148
bme680_t::intf
bme680_intf_t intf
Device interface.
Definition: bme680.h:235
bme680_field_data
BME680 sensor field data.
Definition: bme680.h:156
bme680_field_data::humidity
uint32_t humidity
Relative humidity in percent x 1000.
Definition: bme680.h:166
bme680_field_data::status
uint8_t status
Status for new data, gas measurement valid and heater stable.
Definition: bme680.h:157
bme680_field_data::gas_index
uint8_t gas_index
Index of used heater profile.
Definition: bme680.h:161
bme680_get_data
int bme680_get_data(bme680_t *dev, bme680_field_data_t *data)
Get results of a TPHG measurement.
bme680_intf_spi_t
BME680 SPI parameters.
Definition: bme680.h:200
bme680_intf_i2c_t::dev
i2c_t dev
I2C device which is used.
Definition: bme680.h:193
BME680_COM_FAILED
@ BME680_COM_FAILED
Communication with the device failed.
Definition: bme680.h:146
bme680_params_t::heater_temp
uint16_t heater_temp
Heater temperature in °C.
Definition: bme680.h:224
bme680_devs
bme680_t * bme680_devs[]
References to BME680 sensor devices used by the HAL functions.
bme680_params_t::filter
uint8_t filter
IIR filter coefficient.
Definition: bme680.h:221
bme680_params_t::settings
uint8_t settings
Settings used.
Definition: bme680.h:226
bme680_get_duration
int bme680_get_duration(bme680_t *dev)
Duration one THPG measurement cycle.
bme680_params_t::temp_os
uint8_t temp_os
Temperature oversampling.
Definition: bme680.h:218
bme680_intf_t
BME680 Hardware interface parameters union.
Definition: bme680.h:208
bme680_params_t::gas_measure
uint8_t gas_measure
Enable gas measurement.
Definition: bme680.h:222
bme680_params_t::power_mode
uint8_t power_mode
Power mode (sleep or forced)
Definition: bme680.h:225
BME680_NULL_PTR
@ BME680_NULL_PTR
NULL pointer check failed.
Definition: bme680.h:145
bme680_init
int bme680_init(bme680_t *dev, const bme680_params_t *params)
Initialize the BME680 sensor.
bme680_dev_t
struct bme680_dev bme680_dev_t
Shortcut type definition for BME680 sensor device structure.
Definition: bme680.h:187
i2c.h
Low-level I2C peripheral driver interface definition.
bme680_params_t::heater_dur
uint16_t heater_dur
Heater duration in ms.
Definition: bme680.h:223
BME680_NO_NEW_DATA
@ BME680_NO_NEW_DATA
No new data.
Definition: bme680.h:149
bme680_t
BME680 device descriptor.
Definition: bme680.h:233
bme680_field_data::gas_resistance
uint32_t gas_resistance
Gas resistance in ohms.
Definition: bme680.h:167
bme680_field_data::pressure
uint32_t pressure
Pressure in Pascal.
Definition: bme680.h:165
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118