bmx280.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kees Bakker, SODAQ
3  * 2017 Inria
4  * 2018 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
73 #ifndef BMX280_H
74 #define BMX280_H
75 
76 #include <stdint.h>
77 #include "saul.h"
78 
79 #if defined(MODULE_BME280_SPI) || defined(MODULE_BMP280_SPI)
80 #define BMX280_USE_SPI
81 #include "periph/spi.h"
82 #else
83 #include "periph/i2c.h"
84 #endif
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
93 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
94 #define BMX280_RAW_LEN (8U)
95 #else
96 #define BMX280_RAW_LEN (6U)
97 #endif
98 
104 typedef struct {
105  uint16_t dig_T1;
106  int16_t dig_T2;
107  int16_t dig_T3;
109  uint16_t dig_P1;
110  int16_t dig_P2;
111  int16_t dig_P3;
112  int16_t dig_P4;
113  int16_t dig_P5;
114  int16_t dig_P6;
115  int16_t dig_P7;
116  int16_t dig_P8;
117  int16_t dig_P9;
119  uint8_t dig_H1;
120  int16_t dig_H2;
121  uint8_t dig_H3;
122  int16_t dig_H4;
123  int16_t dig_H5;
124  int8_t dig_H6;
126 
130 typedef enum {
131  BMX280_SB_0_5 = 0x00,
132  BMX280_SB_62_5 = 0x20,
133  BMX280_SB_125 = 0x40,
134  BMX280_SB_250 = 0x60,
135  BMX280_SB_500 = 0x80,
136  BMX280_SB_1000 = 0xa0,
137  BMX280_SB_10 = 0xc0,
138  BMX280_SB_20 = 0xe0,
139 } bmx280_t_sb_t;
140 
144 typedef enum {
145  BMX280_FILTER_OFF = 0x00,
146  BMX280_FILTER_2 = 0x04,
147  BMX280_FILTER_4 = 0x08,
148  BMX280_FILTER_8 = 0x0c,
149  BMX280_FILTER_16 = 0x10,
151 
155 typedef enum {
156  BMX280_MODE_SLEEP = 0x00,
157  BMX280_MODE_FORCED = 0x01,
158  BMX280_MODE_NORMAL = 0x03,
159 } bmx280_mode_t;
160 
169 typedef enum {
170  BMX280_OSRS_SKIPPED = 0x00,
171  BMX280_OSRS_X1 = 0x01,
172  BMX280_OSRS_X2 = 0x02,
173  BMX280_OSRS_X4 = 0x03,
174  BMX280_OSRS_X8 = 0x04,
175  BMX280_OSRS_X16 = 0x05,
176 } bmx280_osrs_t;
177 
183 typedef struct {
184 #ifdef BMX280_USE_SPI
185  /* SPI configuration */
186  spi_t spi;
187  spi_clk_t clk;
188  gpio_t cs;
189 #else
190  /* I2C details */
192  uint8_t i2c_addr;
193 #endif
194 
195  /* Config Register */
198  uint8_t spi3w_en;
200  /* ctrl_meas */
205  /* ctrl_hum */
208 
212 typedef struct {
215  int32_t t_fine;
216  uint8_t last_reading[BMX280_RAW_LEN];
217 } bmx280_t;
218 
222 enum {
223  BMX280_OK = 0,
226 };
227 
232 
237 
238 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
239 
242 extern const saul_driver_t bme280_relative_humidity_saul_driver;
243 #endif
244 
255 int bmx280_init(bmx280_t* dev, const bmx280_params_t* params);
256 
267 int16_t bmx280_read_temperature(bmx280_t* dev);
268 
285 uint32_t bmx280_read_pressure(bmx280_t *dev);
286 
287 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C) || defined(DOXYGEN)
288 
304 uint16_t bme280_read_humidity(bmx280_t *dev);
305 #endif
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 #endif /* BMX280_H */
312 
BMX280_OK
@ BMX280_OK
everything was fine
Definition: bmx280.h:223
bmx280_calibration_t::dig_H5
int16_t dig_H5
H5 coefficient.
Definition: bmx280.h:123
bmx280_params_t::run_mode
bmx280_mode_t run_mode
ctrl_meas mode
Definition: bmx280.h:201
bmx280_calibration_t::dig_H3
uint8_t dig_H3
H3 coefficient.
Definition: bmx280.h:121
bmx280_calibration_t::dig_P6
int16_t dig_P6
P6 coefficient.
Definition: bmx280.h:114
BMX280_ERR_NODEV
@ BMX280_ERR_NODEV
did not detect BME280 or BMP280
Definition: bmx280.h:225
bmx280_calibration_t::dig_P3
int16_t dig_P3
P3 coefficient.
Definition: bmx280.h:111
bmx280_params_t::i2c_addr
uint8_t i2c_addr
I2C address.
Definition: bmx280.h:192
bmx280_calibration_t::dig_H6
int8_t dig_H6
H6 coefficient.
Definition: bmx280.h:124
spi.h
Low-level SPI peripheral driver interface definition.
bmx280_pressure_saul_driver
const saul_driver_t bmx280_pressure_saul_driver
Export of SAUL interface for pressure sensor.
bmx280_calibration_t::dig_P4
int16_t dig_P4
P4 coefficient.
Definition: bmx280.h:112
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
bmx280_params_t::temp_oversample
bmx280_osrs_t temp_oversample
ctrl_meas osrs_t
Definition: bmx280.h:202
BMX280_RAW_LEN
#define BMX280_RAW_LEN
Select the number or raw data bytes depending on the device type.
Definition: bmx280.h:96
bmx280_calibration_t::dig_H4
int16_t dig_H4
H4 coefficient.
Definition: bmx280.h:122
bmx280_read_pressure
uint32_t bmx280_read_pressure(bmx280_t *dev)
Read air pressure value from the given BMX280 device.
bmx280_params_t::spi3w_en
uint8_t spi3w_en
Enables 3-wire SPI interface.
Definition: bmx280.h:198
bmx280_params_t::press_oversample
bmx280_osrs_t press_oversample
ctrl_meas osrs_p
Definition: bmx280.h:203
bmx280_calibration_t::dig_P1
uint16_t dig_P1
P1 coefficient.
Definition: bmx280.h:109
bmx280_t_sb_t
bmx280_t_sb_t
Values for t_sb field of the BMX280 config register.
Definition: bmx280.h:130
bmx280_calibration_t::dig_T2
int16_t dig_T2
T2 coefficient.
Definition: bmx280.h:106
bmx280_calibration_t
Calibration struct for the BMX280 sensor.
Definition: bmx280.h:104
BMX280_ERR_BUS
@ BMX280_ERR_BUS
bus error
Definition: bmx280.h:224
bmx280_osrs_t
bmx280_osrs_t
Values for oversampling settings.
Definition: bmx280.h:169
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
bmx280_read_temperature
int16_t bmx280_read_temperature(bmx280_t *dev)
Read temperature value from the given BMX280 device.
bmx280_t::t_fine
int32_t t_fine
temperature compensation value
Definition: bmx280.h:215
bmx280_calibration_t::dig_P7
int16_t dig_P7
P7 coefficient.
Definition: bmx280.h:115
bmx280_calibration_t::dig_P2
int16_t dig_P2
P2 coefficient.
Definition: bmx280.h:110
saul_driver_t
Definition of the RIOT actuator/sensor interface.
Definition: saul.h:279
bmx280_params_t
Parameters for the BMX280 sensor.
Definition: bmx280.h:183
bmx280_params_t::humid_oversample
bmx280_osrs_t humid_oversample
ctrl_hum osrs_h
Definition: bmx280.h:206
bmx280_temperature_saul_driver
const saul_driver_t bmx280_temperature_saul_driver
Export of SAUL interface for temperature sensor.
bmx280_calibration_t::dig_T1
uint16_t dig_T1
T1 coefficient.
Definition: bmx280.h:105
bmx280_params_t::i2c_dev
i2c_t i2c_dev
I2C device which is used.
Definition: bmx280.h:191
bme280_read_humidity
uint16_t bme280_read_humidity(bmx280_t *dev)
Read humidity value from the given BME280 device.
bmx280_calibration_t::dig_P9
int16_t dig_P9
P9 coefficient.
Definition: bmx280.h:117
bmx280_t
Device descriptor for the BMX280 sensor.
Definition: bmx280.h:212
bmx280_calibration_t::dig_H2
int16_t dig_H2
H2 coefficient.
Definition: bmx280.h:120
bmx280_t::params
bmx280_params_t params
Device Parameters.
Definition: bmx280.h:213
bmx280_params_t::t_sb
bmx280_t_sb_t t_sb
standby
Definition: bmx280.h:196
bmx280_calibration_t::dig_P5
int16_t dig_P5
P5 coefficient.
Definition: bmx280.h:113
saul.h
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
bmx280_calibration_t::dig_H1
uint8_t dig_H1
H1 coefficient.
Definition: bmx280.h:119
bmx280_mode_t
bmx280_mode_t
Values for mode field of the BMX280 ctrl_meas register.
Definition: bmx280.h:155
bmx280_params_t::filter
bmx280_filter_t filter
filter coefficient
Definition: bmx280.h:197
bmx280_filter_t
bmx280_filter_t
Values for filter field of the BMX280 config register.
Definition: bmx280.h:144
i2c.h
Low-level I2C peripheral driver interface definition.
bmx280_calibration_t::dig_T3
int16_t dig_T3
T3 coefficient.
Definition: bmx280.h:107
bmx280_calibration_t::dig_P8
int16_t dig_P8
P8 coefficient.
Definition: bmx280.h:116
bmx280_t::calibration
bmx280_calibration_t calibration
Calibration Data.
Definition: bmx280.h:214
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
bmx280_init
int bmx280_init(bmx280_t *dev, const bmx280_params_t *params)
Initialize the given BMX280 device.