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 #ifndef BME280_DEFS_H_
\r
40 #define BME280_DEFS_H_
\r
42 /********************************************************/
\r
43 /* header includes */
\r
45 #include <linux/types.h>
\r
46 #include <linux/kernel.h>
\r
52 /********************************************************/
\r
53 /*! @name Common macros */
\r
54 /********************************************************/
\r
56 #if !defined(UINT8_C) && !defined(INT8_C)
\r
57 #define INT8_C(x) S8_C(x)
\r
58 #define UINT8_C(x) U8_C(x)
\r
61 #if !defined(UINT16_C) && !defined(INT16_C)
\r
62 #define INT16_C(x) S16_C(x)
\r
63 #define UINT16_C(x) U16_C(x)
\r
66 #if !defined(INT32_C) && !defined(UINT32_C)
\r
67 #define INT32_C(x) S32_C(x)
\r
68 #define UINT32_C(x) U32_C(x)
\r
71 #if !defined(INT64_C) && !defined(UINT64_C)
\r
72 #define INT64_C(x) S64_C(x)
\r
73 #define UINT64_C(x) U64_C(x)
\r
77 /**\name C standard macros */
\r
82 #define NULL ((void *) 0)
\r
86 /********************************************************/
\r
88 #ifndef BME280_64BIT_ENABLE /*< Check if 64-bit integer (using BME280_64BIT_ENABLE) is enabled */
\r
89 #ifndef BME280_32BIT_ENABLE /*< Check if 32-bit integer (using BME280_32BIT_ENABLE) is enabled */
\r
90 #ifndef BME280_FLOAT_ENABLE /*< If any of the integer data types not enabled then enable BME280_FLOAT_ENABLE */
\r
91 #define BME280_FLOAT_ENABLE
\r
97 #define TRUE UINT8_C(1)
\r
100 #define FALSE UINT8_C(0)
\r
104 * BME280_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system.
\r
106 #ifndef BME280_INTF_RET_TYPE
\r
107 #define BME280_INTF_RET_TYPE int8_t
\r
111 * The last error code from read/write interface is stored in the device structure as intf_rslt.
\r
113 #ifndef BME280_INTF_RET_SUCCESS
\r
114 #define BME280_INTF_RET_SUCCESS INT8_C(0)
\r
117 /**\name I2C addresses */
\r
118 #define BME280_I2C_ADDR_PRIM UINT8_C(0x76)
\r
119 #define BME280_I2C_ADDR_SEC UINT8_C(0x77)
\r
121 /**\name BME280 chip identifier */
\r
122 #define BME280_CHIP_ID UINT8_C(0x60)
\r
124 /**\name Register Address */
\r
125 #define BME280_CHIP_ID_ADDR UINT8_C(0xD0)
\r
126 #define BME280_RESET_ADDR UINT8_C(0xE0)
\r
127 #define BME280_TEMP_PRESS_CALIB_DATA_ADDR UINT8_C(0x88)
\r
128 #define BME280_HUMIDITY_CALIB_DATA_ADDR UINT8_C(0xE1)
\r
129 #define BME280_PWR_CTRL_ADDR UINT8_C(0xF4)
\r
130 #define BME280_CTRL_HUM_ADDR UINT8_C(0xF2)
\r
131 #define BME280_CTRL_MEAS_ADDR UINT8_C(0xF4)
\r
132 #define BME280_CONFIG_ADDR UINT8_C(0xF5)
\r
133 #define BME280_DATA_ADDR UINT8_C(0xF7)
\r
135 /**\name API success code */
\r
136 #define BME280_OK INT8_C(0)
\r
138 /**\name API error codes */
\r
139 #define BME280_E_NULL_PTR INT8_C(-1)
\r
140 #define BME280_E_DEV_NOT_FOUND INT8_C(-2)
\r
141 #define BME280_E_INVALID_LEN INT8_C(-3)
\r
142 #define BME280_E_COMM_FAIL INT8_C(-4)
\r
143 #define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
\r
144 #define BME280_E_NVM_COPY_FAILED INT8_C(-6)
\r
146 /**\name API warning codes */
\r
147 #define BME280_W_INVALID_OSR_MACRO INT8_C(1)
\r
149 /**\name Macros related to size */
\r
150 #define BME280_TEMP_PRESS_CALIB_DATA_LEN UINT8_C(26)
\r
151 #define BME280_HUMIDITY_CALIB_DATA_LEN UINT8_C(7)
\r
152 #define BME280_P_T_H_DATA_LEN UINT8_C(8)
\r
154 /**\name Sensor power modes */
\r
155 #define BME280_SLEEP_MODE UINT8_C(0x00)
\r
156 #define BME280_FORCED_MODE UINT8_C(0x01)
\r
157 #define BME280_NORMAL_MODE UINT8_C(0x03)
\r
159 /**\name Macro to combine two 8 bit data's to form a 16 bit data */
\r
160 #define BME280_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
\r
162 #define BME280_SET_BITS(reg_data, bitname, data) \
\r
163 ((reg_data & ~(bitname##_MSK)) | \
\r
164 ((data << bitname##_POS) & bitname##_MSK))
\r
165 #define BME280_SET_BITS_POS_0(reg_data, bitname, data) \
\r
166 ((reg_data & ~(bitname##_MSK)) | \
\r
167 (data & bitname##_MSK))
\r
169 #define BME280_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
\r
171 #define BME280_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
\r
173 /**\name Macros for bit masking */
\r
174 #define BME280_SENSOR_MODE_MSK UINT8_C(0x03)
\r
175 #define BME280_SENSOR_MODE_POS UINT8_C(0x00)
\r
177 #define BME280_CTRL_HUM_MSK UINT8_C(0x07)
\r
178 #define BME280_CTRL_HUM_POS UINT8_C(0x00)
\r
180 #define BME280_CTRL_PRESS_MSK UINT8_C(0x1C)
\r
181 #define BME280_CTRL_PRESS_POS UINT8_C(0x02)
\r
183 #define BME280_CTRL_TEMP_MSK UINT8_C(0xE0)
\r
184 #define BME280_CTRL_TEMP_POS UINT8_C(0x05)
\r
186 #define BME280_FILTER_MSK UINT8_C(0x1C)
\r
187 #define BME280_FILTER_POS UINT8_C(0x02)
\r
189 #define BME280_STANDBY_MSK UINT8_C(0xE0)
\r
190 #define BME280_STANDBY_POS UINT8_C(0x05)
\r
192 /**\name Sensor component selection macros
\r
193 * These values are internal for API implementation. Don't relate this to
\r
196 #define BME280_PRESS UINT8_C(1)
\r
197 #define BME280_TEMP UINT8_C(1 << 1)
\r
198 #define BME280_HUM UINT8_C(1 << 2)
\r
199 #define BME280_ALL UINT8_C(0x07)
\r
201 /**\name Settings selection macros */
\r
202 #define BME280_OSR_PRESS_SEL UINT8_C(1)
\r
203 #define BME280_OSR_TEMP_SEL UINT8_C(1 << 1)
\r
204 #define BME280_OSR_HUM_SEL UINT8_C(1 << 2)
\r
205 #define BME280_FILTER_SEL UINT8_C(1 << 3)
\r
206 #define BME280_STANDBY_SEL UINT8_C(1 << 4)
\r
207 #define BME280_ALL_SETTINGS_SEL UINT8_C(0x1F)
\r
209 /**\name Oversampling macros */
\r
210 #define BME280_NO_OVERSAMPLING UINT8_C(0x00)
\r
211 #define BME280_OVERSAMPLING_1X UINT8_C(0x01)
\r
212 #define BME280_OVERSAMPLING_2X UINT8_C(0x02)
\r
213 #define BME280_OVERSAMPLING_4X UINT8_C(0x03)
\r
214 #define BME280_OVERSAMPLING_8X UINT8_C(0x04)
\r
215 #define BME280_OVERSAMPLING_16X UINT8_C(0x05)
\r
217 /**\name Measurement delay calculation macros */
\r
218 #define BME280_MEAS_OFFSET UINT16_C(1250)
\r
219 #define BME280_MEAS_DUR UINT16_C(2300)
\r
220 #define BME280_PRES_HUM_MEAS_OFFSET UINT16_C(575)
\r
221 #define BME280_MEAS_SCALING_FACTOR UINT16_C(1000)
\r
223 /**\name Standby duration selection macros */
\r
224 #define BME280_STANDBY_TIME_0_5_MS (0x00)
\r
225 #define BME280_STANDBY_TIME_62_5_MS (0x01)
\r
226 #define BME280_STANDBY_TIME_125_MS (0x02)
\r
227 #define BME280_STANDBY_TIME_250_MS (0x03)
\r
228 #define BME280_STANDBY_TIME_500_MS (0x04)
\r
229 #define BME280_STANDBY_TIME_1000_MS (0x05)
\r
230 #define BME280_STANDBY_TIME_10_MS (0x06)
\r
231 #define BME280_STANDBY_TIME_20_MS (0x07)
\r
233 /**\name Filter coefficient selection macros */
\r
234 #define BME280_FILTER_COEFF_OFF (0x00)
\r
235 #define BME280_FILTER_COEFF_2 (0x01)
\r
236 #define BME280_FILTER_COEFF_4 (0x02)
\r
237 #define BME280_FILTER_COEFF_8 (0x03)
\r
238 #define BME280_FILTER_COEFF_16 (0x04)
\r
240 #define BME280_STATUS_REG_ADDR (0xF3)
\r
241 #define BME280_SOFT_RESET_COMMAND (0xB6)
\r
242 #define BME280_STATUS_IM_UPDATE (0x01)
\r
245 * @brief Interface selection Enums
\r
248 /*< SPI interface */
\r
250 /*< I2C interface */
\r
255 * @brief Type definitions
\r
259 * @brief Bus communication function pointer which should be mapped to
\r
260 * the platform specific read functions of the user
\r
262 * @param[in] reg_addr : Register address from which data is read.
\r
263 * @param[out] reg_data : Pointer to data buffer where read data is stored.
\r
264 * @param[in] len : Number of bytes of data to be read.
\r
265 * @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
\r
266 * for interface related call backs.
\r
268 * @retval 0 -> Success.
\r
269 * @retval Non zero value -> Fail.
\r
272 typedef BME280_INTF_RET_TYPE (*bme280_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
\r
275 * @brief Bus communication function pointer which should be mapped to
\r
276 * the platform specific write functions of the user
\r
278 * @param[in] reg_addr : Register address to which the data is written.
\r
279 * @param[in] reg_data : Pointer to data buffer in which data to be written
\r
281 * @param[in] len : Number of bytes of data to be written.
\r
282 * @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
\r
283 * for interface related call backs
\r
285 * @retval 0 -> Success.
\r
286 * @retval Non zero value -> Fail.
\r
289 typedef BME280_INTF_RET_TYPE (*bme280_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len,
\r
293 * @brief Delay function pointer which should be mapped to
\r
294 * delay function of the user
\r
296 * @param[in] period : Delay in microseconds.
\r
297 * @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
\r
298 * for interface related call backs
\r
301 typedef void (*bme280_delay_us_fptr_t)(uint32_t period, void *intf_ptr);
\r
304 * @brief Calibration data
\r
306 struct bme280_calib_data
\r
308 /*< Calibration coefficient for the temperature sensor */
\r
311 /*< Calibration coefficient for the temperature sensor */
\r
314 /*< Calibration coefficient for the temperature sensor */
\r
317 /*< Calibration coefficient for the pressure sensor */
\r
320 /*< Calibration coefficient for the pressure sensor */
\r
323 /*< Calibration coefficient for the pressure sensor */
\r
326 /*< Calibration coefficient for the pressure sensor */
\r
329 /*< Calibration coefficient for the pressure sensor */
\r
332 /*< Calibration coefficient for the pressure sensor */
\r
335 /*< Calibration coefficient for the pressure sensor */
\r
338 /*< Calibration coefficient for the pressure sensor */
\r
341 /*< Calibration coefficient for the pressure sensor */
\r
344 /*< Calibration coefficient for the humidity sensor */
\r
347 /*< Calibration coefficient for the humidity sensor */
\r
350 /*< Calibration coefficient for the humidity sensor */
\r
353 /*< Calibration coefficient for the humidity sensor */
\r
356 /*< Calibration coefficient for the humidity sensor */
\r
359 /*< Calibration coefficient for the humidity sensor */
\r
362 /*< Variable to store the intermediate temperature coefficient */
\r
367 * @brief bme280 sensor structure which comprises of temperature, pressure and
\r
370 #ifdef BME280_FLOAT_ENABLE
\r
373 /*< Compensated pressure */
\r
376 /*< Compensated temperature */
\r
377 double temperature;
\r
379 /*< Compensated humidity */
\r
385 /*< Compensated pressure */
\r
388 /*< Compensated temperature */
\r
389 int32_t temperature;
\r
391 /*< Compensated humidity */
\r
394 #endif /*! BME280_USE_FLOATING_POINT */
\r
397 * @brief bme280 sensor structure which comprises of uncompensated temperature,
\r
398 * pressure and humidity data
\r
400 struct bme280_uncomp_data
\r
402 /*< un-compensated pressure */
\r
405 /*< un-compensated temperature */
\r
406 uint32_t temperature;
\r
408 /*< un-compensated humidity */
\r
413 * @brief bme280 sensor settings structure which comprises of mode,
\r
414 * oversampling and filter settings.
\r
416 struct bme280_settings
\r
418 /*< pressure oversampling */
\r
421 /*< temperature oversampling */
\r
424 /*< humidity oversampling */
\r
427 /*< filter coefficient */
\r
430 /*< standby time */
\r
431 uint8_t standby_time;
\r
435 * @brief bme280 device structure
\r
442 /*< Interface function pointer used to enable the device address for I2C and chip selection for SPI */
\r
445 /*< Interface Selection
\r
446 * For SPI, intf = BME280_SPI_INTF
\r
447 * For I2C, intf = BME280_I2C_INTF
\r
449 enum bme280_intf intf;
\r
451 /*< Read function pointer */
\r
452 bme280_read_fptr_t read;
\r
454 /*< Write function pointer */
\r
455 bme280_write_fptr_t write;
\r
457 /*< Delay function pointer */
\r
458 bme280_delay_us_fptr_t delay_us;
\r
461 struct bme280_calib_data calib_data;
\r
463 /*< Sensor settings */
\r
464 struct bme280_settings settings;
\r
466 /*< Variable to store result of read/write function */
\r
467 BME280_INTF_RET_TYPE intf_rslt;
\r
470 #endif /* BME280_DEFS_H_ */
\r