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 
11 #pragma once
12 
75 #include <stdint.h>
76 #include "saul.h"
77 
78 #if defined(MODULE_BME280_SPI) || defined(MODULE_BMP280_SPI)
79 #define BMX280_USE_SPI
80 #include "periph/spi.h"
81 #else
82 #include "periph/i2c.h"
83 #endif
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
92 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
93 #define BMX280_RAW_LEN (8U)
94 #else
95 #define BMX280_RAW_LEN (6U)
96 #endif
97 
103 typedef struct {
104  uint16_t dig_T1;
105  int16_t dig_T2;
106  int16_t dig_T3;
108  uint16_t dig_P1;
109  int16_t dig_P2;
110  int16_t dig_P3;
111  int16_t dig_P4;
112  int16_t dig_P5;
113  int16_t dig_P6;
114  int16_t dig_P7;
115  int16_t dig_P8;
116  int16_t dig_P9;
118  uint8_t dig_H1;
119  int16_t dig_H2;
120  uint8_t dig_H3;
121  int16_t dig_H4;
122  int16_t dig_H5;
123  int8_t dig_H6;
125 
129 typedef enum {
130  BMX280_SB_0_5 = 0x00,
131  BMX280_SB_62_5 = 0x20,
132  BMX280_SB_125 = 0x40,
133  BMX280_SB_250 = 0x60,
134  BMX280_SB_500 = 0x80,
135  BMX280_SB_1000 = 0xa0,
136  BMX280_SB_10 = 0xc0,
137  BMX280_SB_20 = 0xe0,
138 } bmx280_t_sb_t;
139 
143 typedef enum {
144  BMX280_FILTER_OFF = 0x00,
145  BMX280_FILTER_2 = 0x04,
146  BMX280_FILTER_4 = 0x08,
147  BMX280_FILTER_8 = 0x0c,
148  BMX280_FILTER_16 = 0x10,
150 
154 typedef enum {
155  BMX280_MODE_SLEEP = 0x00,
156  BMX280_MODE_FORCED = 0x01,
157  BMX280_MODE_NORMAL = 0x03,
158 } bmx280_mode_t;
159 
168 typedef enum {
169  BMX280_OSRS_SKIPPED = 0x00,
170  BMX280_OSRS_X1 = 0x01,
171  BMX280_OSRS_X2 = 0x02,
172  BMX280_OSRS_X4 = 0x03,
173  BMX280_OSRS_X8 = 0x04,
174  BMX280_OSRS_X16 = 0x05,
175 } bmx280_osrs_t;
176 
182 typedef struct {
183 #ifdef BMX280_USE_SPI
184  /* SPI configuration */
185  spi_t spi;
186  spi_clk_t clk;
187  gpio_t cs;
188 #else
189  /* I2C details */
191  uint8_t i2c_addr;
192 #endif
193 
194  /* Config Register */
198  /* ctrl_meas */
203  /* ctrl_hum */
206 
210 typedef struct {
213  int32_t t_fine;
214  uint8_t last_reading[BMX280_RAW_LEN];
215 } bmx280_t;
216 
220 enum {
221  BMX280_OK = 0,
224 };
225 
230 
235 
236 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C)
240 extern const saul_driver_t bme280_relative_humidity_saul_driver;
241 #endif
242 
253 int bmx280_init(bmx280_t* dev, const bmx280_params_t* params);
254 
266 
284 
285 #if defined(MODULE_BME280_SPI) || defined(MODULE_BME280_I2C) || defined(DOXYGEN)
303 #endif
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
spi_clk_t
Definition: periph_cpu.h:351
uint16_t bme280_read_humidity(bmx280_t *dev)
Read humidity value from the given BME280 device.
bmx280_osrs_t
Values for oversampling settings.
Definition: bmx280.h:168
int16_t bmx280_read_temperature(bmx280_t *dev)
Read temperature value from the given BMX280 device.
const saul_driver_t bmx280_temperature_saul_driver
Export of SAUL interface for temperature sensor.
const saul_driver_t bmx280_pressure_saul_driver
Export of SAUL interface for pressure sensor.
uint32_t bmx280_read_pressure(bmx280_t *dev)
Read air pressure value from the given BMX280 device.
bmx280_mode_t
Values for mode field of the BMX280 ctrl_meas register.
Definition: bmx280.h:154
int bmx280_init(bmx280_t *dev, const bmx280_params_t *params)
Initialize the given BMX280 device.
#define BMX280_RAW_LEN
Select the number or raw data bytes depending on the device type.
Definition: bmx280.h:95
bmx280_t_sb_t
Values for t_sb field of the BMX280 config register.
Definition: bmx280.h:129
bmx280_filter_t
Values for filter field of the BMX280 config register.
Definition: bmx280.h:143
@ BMX280_ERR_BUS
bus error
Definition: bmx280.h:222
@ BMX280_ERR_NODEV
did not detect BME280 or BMP280
Definition: bmx280.h:223
@ BMX280_OK
everything was fine
Definition: bmx280.h:221
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
Low-level I2C peripheral driver interface definition.
Low-level SPI peripheral driver interface definition.
Calibration struct for the BMX280 sensor.
Definition: bmx280.h:103
int16_t dig_P8
P8 coefficient.
Definition: bmx280.h:115
int16_t dig_P9
P9 coefficient.
Definition: bmx280.h:116
int16_t dig_P7
P7 coefficient.
Definition: bmx280.h:114
uint16_t dig_T1
T1 coefficient.
Definition: bmx280.h:104
int16_t dig_T3
T3 coefficient.
Definition: bmx280.h:106
uint8_t dig_H3
H3 coefficient.
Definition: bmx280.h:120
uint8_t dig_H1
H1 coefficient.
Definition: bmx280.h:118
int8_t dig_H6
H6 coefficient.
Definition: bmx280.h:123
int16_t dig_H2
H2 coefficient.
Definition: bmx280.h:119
uint16_t dig_P1
P1 coefficient.
Definition: bmx280.h:108
int16_t dig_P4
P4 coefficient.
Definition: bmx280.h:111
int16_t dig_T2
T2 coefficient.
Definition: bmx280.h:105
int16_t dig_P2
P2 coefficient.
Definition: bmx280.h:109
int16_t dig_H4
H4 coefficient.
Definition: bmx280.h:121
int16_t dig_H5
H5 coefficient.
Definition: bmx280.h:122
int16_t dig_P6
P6 coefficient.
Definition: bmx280.h:113
int16_t dig_P3
P3 coefficient.
Definition: bmx280.h:110
int16_t dig_P5
P5 coefficient.
Definition: bmx280.h:112
Parameters for the BMX280 sensor.
Definition: bmx280.h:182
i2c_t i2c_dev
I2C device which is used.
Definition: bmx280.h:190
bmx280_osrs_t temp_oversample
ctrl_meas osrs_t
Definition: bmx280.h:200
uint8_t i2c_addr
I2C address.
Definition: bmx280.h:191
bmx280_mode_t run_mode
ctrl_meas mode
Definition: bmx280.h:199
bmx280_t_sb_t t_sb
standby
Definition: bmx280.h:195
bmx280_osrs_t humid_oversample
ctrl_hum osrs_h
Definition: bmx280.h:204
bmx280_filter_t filter
filter coefficient
Definition: bmx280.h:196
bmx280_osrs_t press_oversample
ctrl_meas osrs_p
Definition: bmx280.h:201
Device descriptor for the BMX280 sensor.
Definition: bmx280.h:210
bmx280_params_t params
Device Parameters.
Definition: bmx280.h:211
int32_t t_fine
temperature compensation value
Definition: bmx280.h:213
bmx280_calibration_t calibration
Calibration Data.
Definition: bmx280.h:212
Definition of the RIOT actuator/sensor interface.
Definition: saul.h:283
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.