2 * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
\r
6 * Redistribution and use in source and binary forms, with or without
\r
7 * modification, are permitted provided that the following conditions are met:
\r
9 * 1. Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\r
12 * 2. Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in the
\r
14 * documentation and/or other materials provided with the distribution.
\r
16 * 3. Neither the name of the copyright holder nor the names of its
\r
17 * contributors may be used to endorse or promote products derived from
\r
18 * this software without specific prior written permission.
\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
\r
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
\r
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
\r
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
31 * POSSIBILITY OF SUCH DAMAGE.
\r
33 * @file bme280_defs.h
\r
39 /*! @file bme280_defs.h
\r
40 * @brief Sensor driver for BME280 sensor
\r
44 * @defgroup BME280 SENSOR API
\r
47 #ifndef BME280_DEFS_H_
\r
48 #define BME280_DEFS_H_
\r
50 /********************************************************/
\r
51 /* header includes */
\r
53 #include <linux/types.h>
\r
54 #include <linux/kernel.h>
\r
60 /********************************************************/
\r
61 /*! @name Common macros */
\r
62 /********************************************************/
\r
64 #if !defined(UINT8_C) && !defined(INT8_C)
\r
65 #define INT8_C(x) S8_C(x)
\r
66 #define UINT8_C(x) U8_C(x)
\r
69 #if !defined(UINT16_C) && !defined(INT16_C)
\r
70 #define INT16_C(x) S16_C(x)
\r
71 #define UINT16_C(x) U16_C(x)
\r
74 #if !defined(INT32_C) && !defined(UINT32_C)
\r
75 #define INT32_C(x) S32_C(x)
\r
76 #define UINT32_C(x) U32_C(x)
\r
79 #if !defined(INT64_C) && !defined(UINT64_C)
\r
80 #define INT64_C(x) S64_C(x)
\r
81 #define UINT64_C(x) U64_C(x)
\r
85 /**\name C standard macros */
\r
90 #define NULL ((void *) 0)
\r
94 /********************************************************/
\r
96 #ifndef BME280_64BIT_ENABLE /* Check if 64-bit integer (using BME280_64BIT_ENABLE) is enabled */
\r
97 #ifndef BME280_32BIT_ENABLE /* Check if 32-bit integer (using BME280_32BIT_ENABLE) is enabled */
\r
98 #ifndef BME280_FLOAT_ENABLE /* If any of the integer data types not enabled then enable BME280_FLOAT_ENABLE */
\r
99 #define BME280_FLOAT_ENABLE
\r
105 #define TRUE UINT8_C(1)
\r
108 #define FALSE UINT8_C(0)
\r
111 /**\name I2C addresses */
\r
112 #define BME280_I2C_ADDR_PRIM UINT8_C(0x76)
\r
113 #define BME280_I2C_ADDR_SEC UINT8_C(0x77)
\r
115 /**\name BME280 chip identifier */
\r
116 #define BME280_CHIP_ID UINT8_C(0x60)
\r
118 /**\name Register Address */
\r
119 #define BME280_CHIP_ID_ADDR UINT8_C(0xD0)
\r
120 #define BME280_RESET_ADDR UINT8_C(0xE0)
\r
121 #define BME280_TEMP_PRESS_CALIB_DATA_ADDR UINT8_C(0x88)
\r
122 #define BME280_HUMIDITY_CALIB_DATA_ADDR UINT8_C(0xE1)
\r
123 #define BME280_PWR_CTRL_ADDR UINT8_C(0xF4)
\r
124 #define BME280_CTRL_HUM_ADDR UINT8_C(0xF2)
\r
125 #define BME280_CTRL_MEAS_ADDR UINT8_C(0xF4)
\r
126 #define BME280_CONFIG_ADDR UINT8_C(0xF5)
\r
127 #define BME280_DATA_ADDR UINT8_C(0xF7)
\r
129 /**\name API success code */
\r
130 #define BME280_OK INT8_C(0)
\r
132 /**\name API error codes */
\r
133 #define BME280_E_NULL_PTR INT8_C(-1)
\r
134 #define BME280_E_DEV_NOT_FOUND INT8_C(-2)
\r
135 #define BME280_E_INVALID_LEN INT8_C(-3)
\r
136 #define BME280_E_COMM_FAIL INT8_C(-4)
\r
137 #define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
\r
138 #define BME280_E_NVM_COPY_FAILED INT8_C(-6)
\r
140 /**\name API warning codes */
\r
141 #define BME280_W_INVALID_OSR_MACRO INT8_C(1)
\r
143 /**\name Macros related to size */
\r
144 #define BME280_TEMP_PRESS_CALIB_DATA_LEN UINT8_C(26)
\r
145 #define BME280_HUMIDITY_CALIB_DATA_LEN UINT8_C(7)
\r
146 #define BME280_P_T_H_DATA_LEN UINT8_C(8)
\r
148 /**\name Sensor power modes */
\r
149 #define BME280_SLEEP_MODE UINT8_C(0x00)
\r
150 #define BME280_FORCED_MODE UINT8_C(0x01)
\r
151 #define BME280_NORMAL_MODE UINT8_C(0x03)
\r
153 /**\name Macro to combine two 8 bit data's to form a 16 bit data */
\r
154 #define BME280_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
\r
156 #define BME280_SET_BITS(reg_data, bitname, data) \
\r
157 ((reg_data & ~(bitname##_MSK)) | \
\r
158 ((data << bitname##_POS) & bitname##_MSK))
\r
159 #define BME280_SET_BITS_POS_0(reg_data, bitname, data) \
\r
160 ((reg_data & ~(bitname##_MSK)) | \
\r
161 (data & bitname##_MSK))
\r
163 #define BME280_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
\r
165 #define BME280_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
\r
167 /**\name Macros for bit masking */
\r
168 #define BME280_SENSOR_MODE_MSK UINT8_C(0x03)
\r
169 #define BME280_SENSOR_MODE_POS UINT8_C(0x00)
\r
171 #define BME280_CTRL_HUM_MSK UINT8_C(0x07)
\r
172 #define BME280_CTRL_HUM_POS UINT8_C(0x00)
\r
174 #define BME280_CTRL_PRESS_MSK UINT8_C(0x1C)
\r
175 #define BME280_CTRL_PRESS_POS UINT8_C(0x02)
\r
177 #define BME280_CTRL_TEMP_MSK UINT8_C(0xE0)
\r
178 #define BME280_CTRL_TEMP_POS UINT8_C(0x05)
\r
180 #define BME280_FILTER_MSK UINT8_C(0x1C)
\r
181 #define BME280_FILTER_POS UINT8_C(0x02)
\r
183 #define BME280_STANDBY_MSK UINT8_C(0xE0)
\r
184 #define BME280_STANDBY_POS UINT8_C(0x05)
\r
186 /**\name Sensor component selection macros
\r
187 * These values are internal for API implementation. Don't relate this to
\r
190 #define BME280_PRESS UINT8_C(1)
\r
191 #define BME280_TEMP UINT8_C(1 << 1)
\r
192 #define BME280_HUM UINT8_C(1 << 2)
\r
193 #define BME280_ALL UINT8_C(0x07)
\r
195 /**\name Settings selection macros */
\r
196 #define BME280_OSR_PRESS_SEL UINT8_C(1)
\r
197 #define BME280_OSR_TEMP_SEL UINT8_C(1 << 1)
\r
198 #define BME280_OSR_HUM_SEL UINT8_C(1 << 2)
\r
199 #define BME280_FILTER_SEL UINT8_C(1 << 3)
\r
200 #define BME280_STANDBY_SEL UINT8_C(1 << 4)
\r
201 #define BME280_ALL_SETTINGS_SEL UINT8_C(0x1F)
\r
203 /**\name Oversampling macros */
\r
204 #define BME280_NO_OVERSAMPLING UINT8_C(0x00)
\r
205 #define BME280_OVERSAMPLING_1X UINT8_C(0x01)
\r
206 #define BME280_OVERSAMPLING_2X UINT8_C(0x02)
\r
207 #define BME280_OVERSAMPLING_4X UINT8_C(0x03)
\r
208 #define BME280_OVERSAMPLING_8X UINT8_C(0x04)
\r
209 #define BME280_OVERSAMPLING_16X UINT8_C(0x05)
\r
211 /**\name Measurement delay calculation macros */
\r
212 #define BME280_MEAS_OFFSET UINT16_C(1250)
\r
213 #define BME280_MEAS_DUR UINT16_C(2300)
\r
214 #define BME280_PRES_HUM_MEAS_OFFSET UINT16_C(575)
\r
215 #define BME280_MEAS_SCALING_FACTOR UINT16_C(1000)
\r
217 /**\name Standby duration selection macros */
\r
218 #define BME280_STANDBY_TIME_0_5_MS (0x00)
\r
219 #define BME280_STANDBY_TIME_62_5_MS (0x01)
\r
220 #define BME280_STANDBY_TIME_125_MS (0x02)
\r
221 #define BME280_STANDBY_TIME_250_MS (0x03)
\r
222 #define BME280_STANDBY_TIME_500_MS (0x04)
\r
223 #define BME280_STANDBY_TIME_1000_MS (0x05)
\r
224 #define BME280_STANDBY_TIME_10_MS (0x06)
\r
225 #define BME280_STANDBY_TIME_20_MS (0x07)
\r
227 /**\name Filter coefficient selection macros */
\r
228 #define BME280_FILTER_COEFF_OFF (0x00)
\r
229 #define BME280_FILTER_COEFF_2 (0x01)
\r
230 #define BME280_FILTER_COEFF_4 (0x02)
\r
231 #define BME280_FILTER_COEFF_8 (0x03)
\r
232 #define BME280_FILTER_COEFF_16 (0x04)
\r
234 #define BME280_STATUS_REG_ADDR (0xF3)
\r
235 #define BME280_SOFT_RESET_COMMAND (0xB6)
\r
236 #define BME280_STATUS_IM_UPDATE (0x01)
\r
239 * @brief Interface selection Enums
\r
242 /*! SPI interface */
\r
245 /*! I2C interface */
\r
250 * @brief Type definitions
\r
252 typedef int8_t (*bme280_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
\r
253 typedef void (*bme280_delay_fptr_t)(uint32_t period);
\r
256 * @brief Calibration data
\r
258 struct bme280_calib_data
\r
289 * @brief bme280 sensor structure which comprises of temperature, pressure and
\r
292 #ifdef BME280_FLOAT_ENABLE
\r
295 /*! Compensated pressure */
\r
298 /*! Compensated temperature */
\r
299 double temperature;
\r
301 /*! Compensated humidity */
\r
307 /*! Compensated pressure */
\r
310 /*! Compensated temperature */
\r
311 int32_t temperature;
\r
313 /*! Compensated humidity */
\r
316 #endif /* BME280_USE_FLOATING_POINT */
\r
319 * @brief bme280 sensor structure which comprises of uncompensated temperature,
\r
320 * pressure and humidity data
\r
322 struct bme280_uncomp_data
\r
324 /*! un-compensated pressure */
\r
327 /*! un-compensated temperature */
\r
328 uint32_t temperature;
\r
330 /*! un-compensated humidity */
\r
335 * @brief bme280 sensor settings structure which comprises of mode,
\r
336 * oversampling and filter settings.
\r
338 struct bme280_settings
\r
340 /*! pressure oversampling */
\r
343 /*! temperature oversampling */
\r
346 /*! humidity oversampling */
\r
349 /*! filter coefficient */
\r
352 /*! standby time */
\r
353 uint8_t standby_time;
\r
357 * @brief bme280 device structure
\r
367 /*! SPI/I2C interface */
\r
368 enum bme280_intf intf;
\r
370 /*! Read function pointer */
\r
371 bme280_com_fptr_t read;
\r
373 /*! Write function pointer */
\r
374 bme280_com_fptr_t write;
\r
376 /*! Delay function pointer */
\r
377 bme280_delay_fptr_t delay_ms;
\r
380 struct bme280_calib_data calib_data;
\r
382 /*! Sensor settings */
\r
383 struct bme280_settings settings;
\r
386 #endif /* BME280_DEFS_H_ */
\r