2 * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH
\r
4 * Redistribution and use in source and binary forms, with or without
\r
5 * modification, are permitted provided that the following conditions are met:
\r
7 * Redistributions of source code must retain the above copyright
\r
8 * notice, this list of conditions and the following disclaimer.
\r
10 * Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
14 * Neither the name of the copyright holder nor the names of the
\r
15 * contributors may be used to endorse or promote products derived from
\r
16 * this software without specific prior written permission.
\r
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
\r
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
\r
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
22 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
\r
23 * OR CONTRIBUTORS BE LIABLE FOR ANY
\r
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
\r
25 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
\r
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
31 * ANY WAY OUT OF THE USE OF THIS
\r
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
\r
34 * The information provided is believed to be accurate and reliable.
\r
35 * The copyright holder assumes no responsibility
\r
36 * for the consequences of use
\r
37 * of such information nor for any infringement of patents or
\r
38 * other rights of third parties which may result from its use.
\r
39 * No license is granted by implication or otherwise under any patent or
\r
40 * patent rights of the copyright holder.
\r
42 * @file bme280_defs.h
\r
49 /*! @file bme280_defs.h
\r
50 * @brief Sensor driver for BME280 sensor
\r
54 * @defgroup BME280 SENSOR API
\r
57 #ifndef BME280_DEFS_H_
\r
58 #define BME280_DEFS_H_
\r
60 /********************************************************/
\r
61 /* header includes */
\r
63 #include <linux/types.h>
\r
64 #include <linux/kernel.h>
\r
70 /********************************************************/
\r
71 /*! @name Common macros */
\r
72 /********************************************************/
\r
74 #if !defined(UINT8_C) && !defined(INT8_C)
\r
75 #define INT8_C(x) S8_C(x)
\r
76 #define UINT8_C(x) U8_C(x)
\r
79 #if !defined(UINT16_C) && !defined(INT16_C)
\r
80 #define INT16_C(x) S16_C(x)
\r
81 #define UINT16_C(x) U16_C(x)
\r
84 #if !defined(INT32_C) && !defined(UINT32_C)
\r
85 #define INT32_C(x) S32_C(x)
\r
86 #define UINT32_C(x) U32_C(x)
\r
89 #if !defined(INT64_C) && !defined(UINT64_C)
\r
90 #define INT64_C(x) S64_C(x)
\r
91 #define UINT64_C(x) U64_C(x)
\r
95 /**\name C standard macros */
\r
100 #define NULL ((void *) 0)
\r
104 /********************************************************/
\r
106 #ifndef BME280_FLOAT_ENABLE
\r
108 /* #define BME280_FLOAT_ENABLE */
\r
111 #ifndef BME280_FLOAT_ENABLE
\r
112 #ifndef BME280_64BIT_ENABLE
\r
113 #define BME280_64BIT_ENABLE
\r
118 #define TRUE UINT8_C(1)
\r
121 #define FALSE UINT8_C(0)
\r
124 /**\name I2C addresses */
\r
125 #define BME280_I2C_ADDR_PRIM UINT8_C(0x76)
\r
126 #define BME280_I2C_ADDR_SEC UINT8_C(0x77)
\r
128 /**\name BME280 chip identifier */
\r
129 #define BME280_CHIP_ID UINT8_C(0x60)
\r
131 /**\name Register Address */
\r
132 #define BME280_CHIP_ID_ADDR UINT8_C(0xD0)
\r
133 #define BME280_RESET_ADDR UINT8_C(0xE0)
\r
134 #define BME280_TEMP_PRESS_CALIB_DATA_ADDR UINT8_C(0x88)
\r
135 #define BME280_HUMIDITY_CALIB_DATA_ADDR UINT8_C(0xE1)
\r
136 #define BME280_PWR_CTRL_ADDR UINT8_C(0xF4)
\r
137 #define BME280_CTRL_HUM_ADDR UINT8_C(0xF2)
\r
138 #define BME280_CTRL_MEAS_ADDR UINT8_C(0xF4)
\r
139 #define BME280_CONFIG_ADDR UINT8_C(0xF5)
\r
140 #define BME280_DATA_ADDR UINT8_C(0xF7)
\r
142 /**\name API success code */
\r
143 #define BME280_OK INT8_C(0)
\r
145 /**\name API error codes */
\r
146 #define BME280_E_NULL_PTR INT8_C(-1)
\r
147 #define BME280_E_DEV_NOT_FOUND INT8_C(-2)
\r
148 #define BME280_E_INVALID_LEN INT8_C(-3)
\r
149 #define BME280_E_COMM_FAIL INT8_C(-4)
\r
150 #define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
\r
151 #define BME280_E_NVM_COPY_FAILED INT8_C(-6)
\r
153 /**\name API warning codes */
\r
154 #define BME280_W_INVALID_OSR_MACRO INT8_C(1)
\r
156 /**\name Macros related to size */
\r
157 #define BME280_TEMP_PRESS_CALIB_DATA_LEN UINT8_C(26)
\r
158 #define BME280_HUMIDITY_CALIB_DATA_LEN UINT8_C(7)
\r
159 #define BME280_P_T_H_DATA_LEN UINT8_C(8)
\r
161 /**\name Sensor power modes */
\r
162 #define BME280_SLEEP_MODE UINT8_C(0x00)
\r
163 #define BME280_FORCED_MODE UINT8_C(0x01)
\r
164 #define BME280_NORMAL_MODE UINT8_C(0x03)
\r
166 /**\name Macro to combine two 8 bit data's to form a 16 bit data */
\r
167 #define BME280_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
\r
169 #define BME280_SET_BITS(reg_data, bitname, data) \
\r
170 ((reg_data & ~(bitname##_MSK)) | \
\r
171 ((data << bitname##_POS) & bitname##_MSK))
\r
172 #define BME280_SET_BITS_POS_0(reg_data, bitname, data) \
\r
173 ((reg_data & ~(bitname##_MSK)) | \
\r
174 (data & bitname##_MSK))
\r
176 #define BME280_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
\r
178 #define BME280_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
\r
180 /**\name Macros for bit masking */
\r
181 #define BME280_SENSOR_MODE_MSK UINT8_C(0x03)
\r
182 #define BME280_SENSOR_MODE_POS UINT8_C(0x00)
\r
184 #define BME280_CTRL_HUM_MSK UINT8_C(0x07)
\r
185 #define BME280_CTRL_HUM_POS UINT8_C(0x00)
\r
187 #define BME280_CTRL_PRESS_MSK UINT8_C(0x1C)
\r
188 #define BME280_CTRL_PRESS_POS UINT8_C(0x02)
\r
190 #define BME280_CTRL_TEMP_MSK UINT8_C(0xE0)
\r
191 #define BME280_CTRL_TEMP_POS UINT8_C(0x05)
\r
193 #define BME280_FILTER_MSK UINT8_C(0x1C)
\r
194 #define BME280_FILTER_POS UINT8_C(0x02)
\r
196 #define BME280_STANDBY_MSK UINT8_C(0xE0)
\r
197 #define BME280_STANDBY_POS UINT8_C(0x05)
\r
199 /**\name Sensor component selection macros
\r
200 * These values are internal for API implementation. Don't relate this to
\r
203 #define BME280_PRESS UINT8_C(1)
\r
204 #define BME280_TEMP UINT8_C(1 << 1)
\r
205 #define BME280_HUM UINT8_C(1 << 2)
\r
206 #define BME280_ALL UINT8_C(0x07)
\r
208 /**\name Settings selection macros */
\r
209 #define BME280_OSR_PRESS_SEL UINT8_C(1)
\r
210 #define BME280_OSR_TEMP_SEL UINT8_C(1 << 1)
\r
211 #define BME280_OSR_HUM_SEL UINT8_C(1 << 2)
\r
212 #define BME280_FILTER_SEL UINT8_C(1 << 3)
\r
213 #define BME280_STANDBY_SEL UINT8_C(1 << 4)
\r
214 #define BME280_ALL_SETTINGS_SEL UINT8_C(0x1F)
\r
216 /**\name Oversampling macros */
\r
217 #define BME280_NO_OVERSAMPLING UINT8_C(0x00)
\r
218 #define BME280_OVERSAMPLING_1X UINT8_C(0x01)
\r
219 #define BME280_OVERSAMPLING_2X UINT8_C(0x02)
\r
220 #define BME280_OVERSAMPLING_4X UINT8_C(0x03)
\r
221 #define BME280_OVERSAMPLING_8X UINT8_C(0x04)
\r
222 #define BME280_OVERSAMPLING_16X UINT8_C(0x05)
\r
224 /**\name Standby duration selection macros */
\r
225 #define BME280_STANDBY_TIME_0_5_MS (0x00)
\r
226 #define BME280_STANDBY_TIME_62_5_MS (0x01)
\r
227 #define BME280_STANDBY_TIME_125_MS (0x02)
\r
228 #define BME280_STANDBY_TIME_250_MS (0x03)
\r
229 #define BME280_STANDBY_TIME_500_MS (0x04)
\r
230 #define BME280_STANDBY_TIME_1000_MS (0x05)
\r
231 #define BME280_STANDBY_TIME_10_MS (0x06)
\r
232 #define BME280_STANDBY_TIME_20_MS (0x07)
\r
234 /**\name Filter coefficient selection macros */
\r
235 #define BME280_FILTER_COEFF_OFF (0x00)
\r
236 #define BME280_FILTER_COEFF_2 (0x01)
\r
237 #define BME280_FILTER_COEFF_4 (0x02)
\r
238 #define BME280_FILTER_COEFF_8 (0x03)
\r
239 #define BME280_FILTER_COEFF_16 (0x04)
\r
241 #define BME280_STATUS_REG_ADDR (0xF3)
\r
242 #define BME280_SOFT_RESET_COMMAND (0xB6)
\r
243 #define BME280_STATUS_IM_UPDATE (0x01)
\r
246 * @brief Interface selection Enums
\r
249 /*! SPI interface */
\r
252 /*! I2C interface */
\r
257 * @brief Type definitions
\r
259 typedef int8_t (*bme280_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
\r
260 typedef void (*bme280_delay_fptr_t)(uint32_t period);
\r
263 * @brief Calibration data
\r
265 struct bme280_calib_data
\r
296 * @brief bme280 sensor structure which comprises of temperature, pressure and
\r
299 #ifdef BME280_FLOAT_ENABLE
\r
302 /*! Compensated pressure */
\r
305 /*! Compensated temperature */
\r
306 double temperature;
\r
308 /*! Compensated humidity */
\r
314 /*! Compensated pressure */
\r
317 /*! Compensated temperature */
\r
318 int32_t temperature;
\r
320 /*! Compensated humidity */
\r
323 #endif /* BME280_USE_FLOATING_POINT */
\r
326 * @brief bme280 sensor structure which comprises of uncompensated temperature,
\r
327 * pressure and humidity data
\r
329 struct bme280_uncomp_data
\r
331 /*! un-compensated pressure */
\r
334 /*! un-compensated temperature */
\r
335 uint32_t temperature;
\r
337 /*! un-compensated humidity */
\r
342 * @brief bme280 sensor settings structure which comprises of mode,
\r
343 * oversampling and filter settings.
\r
345 struct bme280_settings
\r
347 /*! pressure oversampling */
\r
350 /*! temperature oversampling */
\r
353 /*! humidity oversampling */
\r
356 /*! filter coefficient */
\r
359 /*! standby time */
\r
360 uint8_t standby_time;
\r
364 * @brief bme280 device structure
\r
374 /*! SPI/I2C interface */
\r
375 enum bme280_intf intf;
\r
377 /*! Read function pointer */
\r
378 bme280_com_fptr_t read;
\r
380 /*! Write function pointer */
\r
381 bme280_com_fptr_t write;
\r
383 /*! Delay function pointer */
\r
384 bme280_delay_fptr_t delay_ms;
\r
387 struct bme280_calib_data calib_data;
\r
389 /*! Sensor settings */
\r
390 struct bme280_settings settings;
\r
393 #endif /* BME280_DEFS_H_ */
\r