├── LICENSE ├── README.md ├── bmp3.c ├── bmp3.h ├── bmp3_defs.h ├── examples ├── common │ ├── common.c │ └── common.h ├── fifo_full_press │ ├── Makefile │ └── fifo_full_press.c ├── fifo_full_press_temp │ ├── Makefile │ └── fifo_full_press_temp.c ├── fifo_full_press_temp_with_sensortime │ ├── Makefile │ └── fifo_full_press_temp_with_sensortime.c ├── fifo_full_press_with_sensortime │ ├── Makefile │ └── fifo_full_press_with_sensortime.c ├── fifo_full_temp │ ├── Makefile │ └── fifo_full_temp.c ├── fifo_full_temp_with_sensortime │ ├── Makefile │ └── fifo_full_temp_with_sensortime.c ├── fifo_watermark_press │ ├── Makefile │ └── fifo_watermark_press.c ├── fifo_watermark_press_temp │ ├── Makefile │ └── fifo_watermark_press_temp.c ├── fifo_watermark_press_temp_with_sensortime │ ├── Makefile │ └── fifo_watermark_press_temp_with_sensortime.c ├── fifo_watermark_press_with_sensortime │ ├── Makefile │ └── fifo_watermark_press_with_sensortime.c ├── fifo_watermark_temp │ ├── Makefile │ └── fifo_watermark_temp.c ├── fifo_watermark_temp_with_sensortime │ ├── Makefile │ └── fifo_watermark_temp_with_sensortime.c └── read_sensor_data │ ├── Makefile │ └── read_sensor_data.c └── self-test ├── bmp3_selftest.c └── bmp3_selftest.h /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 2 | 3 | BSD-3-Clause 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BMP3 sensor API 2 | 3 | ## Introduction 4 | 5 | This package contains the Bosch Sensortec's BMP3 pressure sensor driver (sensor API) 6 | 7 | The sensor driver package includes bmp3.h, bmp3.c and bmp3_defs.h files 8 | 9 | ## Integration details 10 | 11 | - Integrate bmp3.h, bmp3_defs.h and bmp3.c file in to your project. 12 | - Include the bmp3.h file in your code like below. 13 | 14 | ```c 15 | #include "bmp3.h" 16 | ``` 17 | 18 | ## File information 19 | 20 | - bmp3_defs.h : This header file has the constants, macros and datatype declarations. 21 | - bmp3.h : This header file contains the declarations of the sensor driver APIs. 22 | - bmp3.c : This source file contains the definitions of the sensor driver APIs. 23 | 24 | ## Supported sensor interfaces 25 | 26 | - SPI 4-wire 27 | - I2C 28 | 29 | ## Usage guide 30 | 31 | ### Initializing the sensor 32 | 33 | To initialize the sensor, you will first need to create a device structure. You 34 | can do this by creating an instance of the structure bmp3_dev. Then go on to 35 | fill in the various parameters as shown below. 36 | 37 | Regarding Compensation functions for temperature and pressure, we have two implementations. 38 | 1) Double precision floating point version 39 | 2) Integer version 40 | 41 | If you want to use the floating point version, define the BMP3_FLOAT_COMPENSATION macro in your makefile or uncomment the relevant line in the bmp3_defs.h file. By default, the integer version will be used. Below example code uses floating point representation. 42 | 43 | ### Important links 44 | 45 | - [BMP388 product page](https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/bmp388/) 46 | - [BMP390L product page](https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/bmp390l/) 47 | - [BMP388 datasheet](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf) 48 | - [BMP390L datasheet](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390l-ds001.pdf) 49 | - [BMP3xy shuttle board flyer](https://www.bosch-sensortec.com/media/boschsensortec/downloads/shuttle_board_flyer/bst-mhd-fl001.pdf) 50 | - [Community support page](https://community.bosch-sensortec.com) -------------------------------------------------------------------------------- /bmp3.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * BSD-3-Clause 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * @file bmp3.h 34 | * @date 2022-04-01 35 | * @version v2.0.6 36 | * 37 | */ 38 | 39 | /*! 40 | * @defgroup bmp3 BMP3 41 | */ 42 | 43 | #ifndef _BMP3_H 44 | #define _BMP3_H 45 | 46 | /* Header includes */ 47 | #include "bmp3_defs.h" 48 | 49 | /*! CPP guard */ 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** 55 | * \ingroup bmp3 56 | * \defgroup bmp3ApiInit Initialization 57 | * @brief Initialize the sensor and device structure 58 | */ 59 | 60 | /*! 61 | * \ingroup bmp3ApiInit 62 | * \page bmp3_api_bmp3_init bmp3_init 63 | * \code 64 | * int8_t bmp3_init(struct bmp3_dev *dev); 65 | * \endcode 66 | * @details This API is the entry point. 67 | * Performs the selection of I2C/SPI read mechanism according to the 68 | * selected interface and reads the chip-id and calibration data of the sensor. 69 | * 70 | * @param[in,out] dev : Structure instance of bmp3_dev 71 | * 72 | * @return Result of API execution status 73 | * @retval 0 -> Success 74 | * @retval >0 -> Warning 75 | * @retval <0 -> Error 76 | */ 77 | int8_t bmp3_init(struct bmp3_dev *dev); 78 | 79 | /** 80 | * \ingroup bmp3 81 | * \defgroup bmp3ApiSoftReset Soft reset 82 | * @brief Perform soft reset of the sensor 83 | */ 84 | 85 | /*! 86 | * \ingroup bmp3ApiSoftReset 87 | * \page bmp3_api_bmp3_soft_reset bmp3_soft_reset 88 | * \code 89 | * int8_t bmp3_soft_reset(const struct bmp3_dev *dev); 90 | * \endcode 91 | * @details This API performs the soft reset of the sensor. 92 | * 93 | * @param[in] dev : Structure instance of bmp3_dev. 94 | * 95 | * @return Result of API execution status 96 | * @retval 0 -> Success 97 | * @retval >0 -> Warning 98 | * @retval <0 -> Error 99 | */ 100 | int8_t bmp3_soft_reset(struct bmp3_dev *dev); 101 | 102 | /** 103 | * \ingroup bmp3 104 | * \defgroup bmp3ApiSensorS Sensor settings 105 | * @brief Get / Set sensor settings 106 | */ 107 | 108 | /*! 109 | * \ingroup bmp3ApiSensorS 110 | * \page bmp3_api_bmp3_set_sensor_settings bmp3_set_sensor_settings 111 | * \code 112 | * int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev); 113 | * \endcode 114 | * @details This API sets the power control(pressure enable and 115 | * temperature enable), over sampling, odr and filter 116 | * settings in the sensor. 117 | * 118 | * @param[in] desired_settings : Variable used to select the settings which 119 | * are to be set in the sensor. 120 | * @param[in] settings : Structure instance of bmp3_settings 121 | * @param[in] dev : Structure instance of bmp3_dev. 122 | * 123 | * @note : Below are the macros to be used by the user for selecting the 124 | * desired settings. User can do OR operation of these macros for configuring 125 | * multiple settings. 126 | * 127 | *@verbatim 128 | * ---------------------|---------------------------------------------- 129 | * desired_settings | Functionality 130 | * ---------------------|---------------------------------------------- 131 | * BMP3_SEL_PRESS_EN | Enable/Disable pressure. 132 | * BMP3_SEL_TEMP_EN | Enable/Disable temperature. 133 | * BMP3_SEL_PRESS_OS | Set pressure oversampling. 134 | * BMP3_SEL_TEMP_OS | Set temperature oversampling. 135 | * BMP3_SEL_IIR_FILTER | Set IIR filter. 136 | * BMP3_SEL_ODR | Set ODR. 137 | * BMP3_SEL_OUTPUT_MODE | Set either open drain or push pull 138 | * BMP3_SEL_LEVEL | Set interrupt pad to be active high or low 139 | * BMP3_SEL_LATCH | Set interrupt pad to be latched or nonlatched. 140 | * BMP3_SEL_DRDY_EN | Map/Unmap the drdy interrupt to interrupt pad. 141 | * BMP3_SEL_I2C_WDT_EN | Enable/Disable I2C internal watch dog. 142 | * BMP3_SEL_I2C_WDT | Set I2C watch dog timeout delay. 143 | * ---------------------|---------------------------------------------- 144 | *@endverbatim 145 | * 146 | * @return Result of API execution status 147 | * @retval 0 -> Success 148 | * @retval >0 -> Warning 149 | * @retval <0 -> Error 150 | */ 151 | int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev); 152 | 153 | /*! 154 | * \ingroup bmp3ApiSensorS 155 | * \page bmp3_api_bmp3_get_sensor_settings bmp3_get_sensor_settings 156 | * \code 157 | * int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev); 158 | * \endcode 159 | * @details This API gets the power control(power mode, pressure enable and 160 | * temperature enable), over sampling, odr, filter, interrupt control and 161 | * advance settings from the sensor. 162 | * 163 | * @param[out] settings : Structure instance of bmp3_settings 164 | * @param[in] dev : Structure instance of bmp3_dev. 165 | * 166 | * @return Result of API execution status 167 | * @retval 0 -> Success 168 | * @retval >0 -> Warning 169 | * @retval <0 -> Error 170 | */ 171 | int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev); 172 | 173 | /** 174 | * \ingroup bmp3 175 | * \defgroup bmp3ApiPowermode Power mode 176 | * @brief Set / Get power mode of the sensor 177 | */ 178 | 179 | /*! 180 | * \ingroup bmp3ApiPowermode 181 | * \page bmp3_api_bmp3_set_op_mode bmp3_set_op_mode 182 | * \code 183 | * int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev); 184 | * \endcode 185 | * @details This API sets the power mode of the sensor. 186 | * 187 | * @param[in] settings : Structure instance of bmp3_settings 188 | * @param[in] dev : Structure instance of bmp3_dev. 189 | * 190 | *@verbatim 191 | * ----------------------|------------------- 192 | * dev->settings.op_mode | Macros 193 | * ----------------------|------------------- 194 | * 0 | BMP3_MODE_SLEEP 195 | * 1 | BMP3_MODE_FORCED 196 | * 3 | BMP3_MODE_NORMAL 197 | * ----------------------|------------------- 198 | *@endverbatim 199 | * 200 | * @note : Before setting normal mode, valid odr and osr settings should be set 201 | * in the sensor by using 'bmp3_set_sensor_settings' function. 202 | * 203 | * @return Result of API execution status 204 | * @retval 0 -> Success 205 | * @retval >0 -> Warning 206 | * @retval <0 -> Error 207 | */ 208 | int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev); 209 | 210 | /*! 211 | * \ingroup bmp3ApiPowermode 212 | * \page bmp3_api_bmp3_get_op_mode bmp3_get_op_mode 213 | * \code 214 | * int8_t bmp3_get_op_mode(uint8_t *op_mode, const struct bmp3_dev *dev); 215 | * \endcode 216 | * @details This API gets the power mode of the sensor. 217 | * 218 | * @param[in] dev : Structure instance of bmp3_dev. 219 | * @param[out] op_mode : Pointer variable to store the op-mode. 220 | * 221 | *@verbatim 222 | * ------------------------------------------ 223 | * op_mode | Macros 224 | * ----------------------|------------------- 225 | * 0 | BMP3_MODE_SLEEP 226 | * 1 | BMP3_MODE_FORCED 227 | * 3 | BMP3_MODE_NORMAL 228 | * ------------------------------------------ 229 | *@endverbatim 230 | * 231 | * @return Result of API execution status 232 | * @retval 0 -> Success 233 | * @retval >0 -> Warning 234 | * @retval <0 -> Error 235 | */ 236 | int8_t bmp3_get_op_mode(uint8_t *op_mode, struct bmp3_dev *dev); 237 | 238 | /** 239 | * \ingroup bmp3 240 | * \defgroup bmp3ApiData Sensor Data 241 | * @brief Get Sensor data 242 | */ 243 | 244 | /*! 245 | * \ingroup bmp3ApiData 246 | * \page bmp3_api_bmp3_get_sensor_data bmp3_get_sensor_data 247 | * \code 248 | * int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *data, struct bmp3_dev *dev); 249 | * \endcode 250 | * @details This API reads the pressure, temperature or both data from the 251 | * sensor, compensates the data and store it in the bmp3_data structure 252 | * instance passed by the user. 253 | * 254 | * @param[in] sensor_comp : Variable which selects which data to be read from 255 | * the sensor. 256 | * 257 | *@verbatim 258 | * sensor_comp | Macros 259 | * ------------|------------------- 260 | * 1 | BMP3_PRESS 261 | * 2 | BMP3_TEMP 262 | * 3 | BMP3_ALL 263 | *@endverbatim 264 | * 265 | * @param[out] data : Structure instance of bmp3_data. 266 | * @param[in] dev : Structure instance of bmp3_dev. 267 | * 268 | * @note : For fixed point the compensated temperature and pressure has a multiplication factor of 100. 269 | * Units are degree celsius and Pascal respectively. 270 | * ie. If temperature is 2426 then temperature is 24.26 deg C 271 | * If press is 9528709, then pressure is 95287.09 Pascal. 272 | * 273 | * @return Result of API execution status 274 | * @retval 0 -> Success 275 | * @retval >0 -> Warning 276 | * @retval <0 -> Error 277 | */ 278 | int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *data, struct bmp3_dev *dev); 279 | 280 | /** 281 | * \ingroup bmp3 282 | * \defgroup bmp3ApiRegs Registers 283 | * @brief Read / Write data to the given register address 284 | */ 285 | 286 | /*! 287 | * \ingroup bmp3ApiRegs 288 | * \page bmp3_api_bmp3_set_regs bmp3_set_regs 289 | * \code 290 | * int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bmp3_dev *dev); 291 | * \endcode 292 | * @details This API writes the given data to the register address 293 | * of the sensor. 294 | * 295 | * @param[in] reg_addr : Register address to where the data to be written. 296 | * @param[in] reg_data : Pointer to data buffer which is to be written 297 | * in the sensor. 298 | * @param[in] len : No. of bytes of data to write. 299 | * @param[in] dev : Structure instance of bmp3_dev. 300 | * 301 | * @return Result of API execution status 302 | * @retval 0 -> Success 303 | * @retval >0 -> Warning 304 | * @retval <0 -> Error 305 | */ 306 | int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev); 307 | 308 | /*! 309 | * \ingroup bmp3ApiRegs 310 | * \page bmp3_api_bmp3_get_regs bmp3_get_regs 311 | * \code 312 | * int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, const struct bmp3_dev *dev); 313 | * \endcode 314 | * @details This API reads the data from the given register address of the sensor. 315 | * 316 | * @param[in] reg_addr : Register address from where the data to be read 317 | * @param[out] reg_data : Pointer to data buffer to store the read data. 318 | * @param[in] len : No. of bytes of data to be read. 319 | * @param[in] dev : Structure instance of bmp3_dev. 320 | * 321 | * @return Result of API execution status 322 | * @retval 0 -> Success 323 | * @retval >0 -> Warning 324 | * @retval <0 -> Error 325 | */ 326 | int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev); 327 | 328 | /** 329 | * \ingroup bmp3 330 | * \defgroup bmp3ApiFIFO FIFO 331 | * @brief FIFO operations of the sensor 332 | */ 333 | 334 | /*! 335 | * \ingroup bmp3ApiFIFO 336 | * \page bmp3_api_bmp3_set_fifo_settings bmp3_set_fifo_settings 337 | * \code 338 | * int8_t bmp3_set_fifo_settings(uint16_t desired_settings, struct bmp3_fifo_settings *fifo_settings, 339 | * struct bmp3_dev *dev); 340 | * \endcode 341 | * @details This API sets the fifo_config_1(fifo_mode, 342 | * fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en), 343 | * fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en) 344 | * settings in the sensor. 345 | * 346 | * @param[in] desired_settings : Variable used to select the FIFO settings which 347 | * are to be set in the sensor. 348 | * 349 | * @note : Below are the macros to be used by the user for selecting the 350 | * desired settings. User can do OR operation of these macros for configuring 351 | * multiple settings. 352 | * 353 | *@verbatim 354 | * --------------------------------|--------------------------------------------- 355 | * desired_settings | Functionality 356 | * --------------------------------|--------------------------------------------- 357 | * BMP3_SEL_FIFO_MODE | Enable/Disable FIFO 358 | * BMP3_SEL_FIFO_STOP_ON_FULL_EN | Set FIFO stop on full interrupt 359 | * BMP3_SEL_FIFO_TIME_EN | Enable/Disable FIFO time 360 | * BMP3_SEL_FIFO_PRESS_EN | Enable/Disable pressure 361 | * BMP3_SEL_FIFO_TEMP_EN | Enable/Disable temperature 362 | * BMP3_SEL_FIFO_DOWN_SAMPLING | Set FIFO downsampling 363 | * BMP3_SEL_FIFO_FILTER_EN | Enable/Disable FIFO filter 364 | * BMP3_SEL_FIFO_FWTM_EN | Enable/Disable FIFO watermark interrupt 365 | * BMP3_SEL_FIFO_FFULL_EN | Enable/Disable FIFO full interrupt 366 | * --------------------------------|--------------------------------------------- 367 | *@endverbatim 368 | * 369 | * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings 370 | * @param[in] dev : Structure instance of bmp3_dev. 371 | * 372 | * @return Result of API execution status 373 | * @retval 0 -> Success 374 | * @retval >0 -> Warning 375 | * @retval <0 -> Error 376 | */ 377 | int8_t bmp3_set_fifo_settings(uint16_t desired_settings, 378 | const struct bmp3_fifo_settings *fifo_settings, 379 | struct bmp3_dev *dev); 380 | 381 | /*! 382 | * \ingroup bmp3ApiFIFO 383 | * \page bmp3_api_bmp3_get_fifo_settings bmp3_get_fifo_settings 384 | * \code 385 | * int8_t bmp3_get_fifo_settings(struct bmp3_fifo_settings *fifo_settings, struct bmp3_dev *dev); 386 | * \endcode 387 | * @details This API gets the fifo_config_1(fifo_mode, 388 | * fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en), 389 | * fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en) 390 | * settings from the sensor. 391 | * 392 | * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings 393 | * @param[in] dev : Structure instance of bmp3_dev. 394 | * 395 | * @return Result of API execution status 396 | * @retval 0 -> Success 397 | * @retval >0 -> Warning 398 | * @retval <0 -> Error 399 | */ 400 | int8_t bmp3_get_fifo_settings(struct bmp3_fifo_settings *fifo_settings, struct bmp3_dev *dev); 401 | 402 | /*! 403 | * \ingroup bmp3ApiFIFO 404 | * \page bmp3_api_bmp3_get_fifo_data bmp3_get_fifo_data 405 | * \code 406 | * int8_t bmp3_get_fifo_data(struct bmp3_fifo_data *fifo, 407 | * const struct bmp3_fifo_settings *fifo_settings, 408 | * struct bmp3_dev *dev); 409 | * \endcode 410 | * @details This API gets the fifo data from the sensor. 411 | * 412 | * @param[in,out] fifo : Structure instance of bmp3_fifo_data 413 | * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings 414 | * @param[in] dev : Structure instance of bmp3_dev 415 | * 416 | * @return Result of API execution status. 417 | * @retval 0 -> Success 418 | * @retval >0 -> Warning 419 | * @retval <0 -> Error 420 | */ 421 | int8_t bmp3_get_fifo_data(struct bmp3_fifo_data *fifo, 422 | const struct bmp3_fifo_settings *fifo_settings, 423 | struct bmp3_dev *dev); 424 | 425 | /*! 426 | * \ingroup bmp3ApiFIFO 427 | * \page bmp3_api_bmp3_get_fifo_length bmp3_get_fifo_length 428 | * \code 429 | * int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev); 430 | * \endcode 431 | * @details This API gets the fifo length from the sensor. 432 | * 433 | * @param[out] fifo_length : Variable used to store the fifo length. 434 | * @param[in] dev : Structure instance of bmp3_dev. 435 | * 436 | * @return Result of API execution status. 437 | * @retval 0 -> Success 438 | * @retval >0 -> Warning 439 | * @retval <0 -> Error 440 | */ 441 | int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev); 442 | 443 | /*! 444 | * \ingroup bmp3ApiFIFO 445 | * \page bmp3_api_bmp3_extract_fifo_data bmp3_extract_fifo_data 446 | * \code 447 | * int8_t bmp3_extract_fifo_data(struct bmp3_data *data, struct bmp3_fifo_data *fifo, struct bmp3_dev *dev); 448 | * \endcode 449 | * @details This API extracts the temperature and/or pressure data from the FIFO 450 | * data which is already read from the fifo. 451 | * 452 | * @param[out] data : Array of bmp3_data structures where the temperature 453 | * and pressure frames will be stored. 454 | * @param[in] fifo : Structure instance of bmp3_fifo_data 455 | * @param[in] dev : Structure instance of bmp3_dev 456 | * 457 | * @return Result of API execution status. 458 | * @retval 0 -> Success 459 | * @retval <0 -> Error 460 | */ 461 | int8_t bmp3_extract_fifo_data(struct bmp3_data *data, struct bmp3_fifo_data *fifo, struct bmp3_dev *dev); 462 | 463 | /*! 464 | * \ingroup bmp3ApiFIFO 465 | * \page bmp3_api_bmp3_set_fifo_watermark bmp3_set_fifo_watermark 466 | * \code 467 | * int8_t bmp3_set_fifo_watermark(const struct bmp3_fifo_data *fifo, 468 | * const struct bmp3_fifo_settings *fifo_settings, 469 | * struct bmp3_dev *dev); 470 | * \endcode 471 | * @details This API sets the fifo watermark length according to the frames count 472 | * set by the user in the device structure. Refer below for usage. 473 | * 474 | * @note: fifo.req_frames = 50; 475 | * 476 | * @param[in] fifo : Structure instance of bmp3_fifo_data 477 | * @param[in] fifo_settings : Structure instance of bmp3_fifo_settings 478 | * @param[in] dev : Structure instance of bmp3_dev 479 | * 480 | * @return Result of API execution status. 481 | * @retval 0 -> Success 482 | * @retval <0 -> Error 483 | */ 484 | int8_t bmp3_set_fifo_watermark(const struct bmp3_fifo_data *fifo, 485 | const struct bmp3_fifo_settings *fifo_settings, 486 | struct bmp3_dev *dev); 487 | 488 | /*! 489 | * \ingroup bmp3ApiFIFO 490 | * \page bmp3_api_bmp3_get_fifo_watermark bmp3_get_fifo_watermark 491 | * \code 492 | * int8_t bmp3_get_fifo_watermark(uint16_t *watermark_len, struct bmp3_dev *dev); 493 | * \endcode 494 | * @details This API gets the fifo watermark length according to the frames count 495 | * set by the user in the device structure 496 | * 497 | * @param[in] watermark_len : Watermark level value 498 | * @param[in] dev : Structure instance of bmp3_dev 499 | * 500 | * @return Result of API execution status. 501 | * @retval 0 -> Success 502 | * @retval <0 -> Error 503 | */ 504 | int8_t bmp3_get_fifo_watermark(uint16_t *watermark_len, struct bmp3_dev *dev); 505 | 506 | /*! 507 | * \ingroup bmp3ApiFIFO 508 | * \page bmp3_api_bmp3_fifo_flush bmp3_fifo_flush 509 | * \code 510 | * int8_t bmp3_fifo_flush(const struct bmp3_dev *dev); 511 | * \endcode 512 | * @details This API performs fifo flush 513 | * 514 | * @param[in] dev : Structure instance of bmp3_dev. 515 | * 516 | * @return Result of API execution status 517 | * @retval 0 -> Success 518 | * @retval >0 -> Warning 519 | * @retval <0 -> Error 520 | */ 521 | int8_t bmp3_fifo_flush(struct bmp3_dev *dev); 522 | 523 | /** 524 | * \ingroup bmp3 525 | * \defgroup bmp3ApiStatus Sensor Status 526 | * @brief Read status of the sensor 527 | */ 528 | 529 | /*! 530 | * \ingroup bmp3ApiStatus 531 | * \page bmp3_api_bmp3_get_status bmp3_get_status 532 | * \code 533 | * int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev); 534 | * \endcode 535 | * @details This API gets the command ready, data ready for pressure and 536 | * temperature and interrupt (fifo watermark, fifo full, data ready) and 537 | * error status from the sensor. 538 | * 539 | * @param[out] status : Structure instance of bmp3_status 540 | * @param[in] dev : Structure instance of bmp3_dev 541 | * 542 | * @return Result of API execution status. 543 | * @retval 0 -> Success 544 | * @retval <0 -> Error 545 | */ 546 | int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev); 547 | 548 | #ifdef __cplusplus 549 | } 550 | #endif /* End of CPP guard */ 551 | 552 | #endif /* _BMP3_H */ 553 | -------------------------------------------------------------------------------- /bmp3_defs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * BSD-3-Clause 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * @file bmp3_defs.h 34 | * @date 2022-04-01 35 | * @version v2.0.6 36 | * 37 | */ 38 | 39 | /*! @file bmp3_defs.h 40 | * @brief Sensor driver for BMP3 sensor */ 41 | 42 | #ifndef BMP3_DEFS_H_ 43 | #define BMP3_DEFS_H_ 44 | 45 | /*! CPP guard */ 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /********************************************************/ 51 | /* header includes */ 52 | #ifdef __KERNEL__ 53 | #include 54 | #include 55 | #else 56 | #include 57 | #include 58 | #endif 59 | 60 | /*************************** Common macros *****************************/ 61 | 62 | #if !defined(UINT8_C) && !defined(INT8_C) 63 | #define INT8_C(x) S8_C(x) 64 | #define UINT8_C(x) U8_C(x) 65 | #endif 66 | 67 | #if !defined(UINT16_C) && !defined(INT16_C) 68 | #define INT16_C(x) S16_C(x) 69 | #define UINT16_C(x) U16_C(x) 70 | #endif 71 | 72 | #if !defined(INT32_C) && !defined(UINT32_C) 73 | #define INT32_C(x) S32_C(x) 74 | #define UINT32_C(x) U32_C(x) 75 | #endif 76 | 77 | #if !defined(INT64_C) && !defined(UINT64_C) 78 | #define INT64_C(x) S64_C(x) 79 | #define UINT64_C(x) U64_C(x) 80 | #endif 81 | 82 | /**@}*/ 83 | /**\name C standard macros */ 84 | #ifndef NULL 85 | #ifdef __cplusplus 86 | #define NULL 0 87 | #else 88 | #define NULL ((void *) 0) 89 | #endif 90 | #endif 91 | 92 | #ifndef TRUE 93 | #define TRUE UINT8_C(1) 94 | #endif 95 | 96 | #ifndef FALSE 97 | #define FALSE UINT8_C(0) 98 | #endif 99 | 100 | /********************************************************/ 101 | /**\name Compiler switch macros */ 102 | 103 | #ifndef BMP3_64BIT_COMPENSATION /*< Check if 64bit (using BMP3_64BIT_COMPENSATION) is enabled */ 104 | #ifndef BMP3_FLOAT_COMPENSATION /*< If 64 bit integer data type is not enabled then enable 105 | * BMP3_FLOAT_COMPENSATION */ 106 | #define BMP3_FLOAT_COMPENSATION 107 | #endif 108 | #endif 109 | 110 | /********************************************************/ 111 | /**\name Macro definitions */ 112 | 113 | /** 114 | * BMP3_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system. 115 | */ 116 | #ifndef BMP3_INTF_RET_TYPE 117 | #define BMP3_INTF_RET_TYPE int8_t 118 | #endif 119 | 120 | /** 121 | * The last error code from read/write interface is stored in the device structure as intf_rslt. 122 | */ 123 | #ifndef BMP3_INTF_RET_SUCCESS 124 | #define BMP3_INTF_RET_SUCCESS INT8_C(0) 125 | #endif 126 | 127 | /**\name I2C addresses */ 128 | #define BMP3_ADDR_I2C_PRIM UINT8_C(0x76) 129 | #define BMP3_ADDR_I2C_SEC UINT8_C(0x77) 130 | 131 | /**\name BMP3 chip identifier */ 132 | #define BMP3_CHIP_ID UINT8_C(0x50) 133 | #define BMP390_CHIP_ID UINT8_C(0x60) 134 | 135 | /**\name BMP3 pressure settling time (micro secs)*/ 136 | #define BMP3_SETTLE_TIME_PRESS UINT16_C(392) 137 | 138 | /**\name BMP3 temperature settling time (micro secs) */ 139 | #define BMP3_SETTLE_TIME_TEMP UINT16_C(313) 140 | 141 | /**\name BMP3 adc conversion time (micro secs) */ 142 | #define BMP3_ADC_CONV_TIME UINT16_C(2000) 143 | 144 | /**\name Register Address */ 145 | #define BMP3_REG_CHIP_ID UINT8_C(0x00) 146 | #define BMP3_REG_ERR UINT8_C(0x02) 147 | #define BMP3_REG_SENS_STATUS UINT8_C(0x03) 148 | #define BMP3_REG_DATA UINT8_C(0x04) 149 | #define BMP3_REG_EVENT UINT8_C(0x10) 150 | #define BMP3_REG_INT_STATUS UINT8_C(0x11) 151 | #define BMP3_REG_FIFO_LENGTH UINT8_C(0x12) 152 | #define BMP3_REG_FIFO_DATA UINT8_C(0x14) 153 | #define BMP3_REG_FIFO_WM UINT8_C(0x15) 154 | #define BMP3_REG_FIFO_CONFIG_1 UINT8_C(0x17) 155 | #define BMP3_REG_FIFO_CONFIG_2 UINT8_C(0x18) 156 | #define BMP3_REG_INT_CTRL UINT8_C(0x19) 157 | #define BMP3_REG_IF_CONF UINT8_C(0x1A) 158 | #define BMP3_REG_PWR_CTRL UINT8_C(0x1B) 159 | #define BMP3_REG_OSR UINT8_C(0X1C) 160 | #define BMP3_REG_ODR UINT8_C(0x1D) 161 | #define BMP3_REG_CONFIG UINT8_C(0x1F) 162 | #define BMP3_REG_CALIB_DATA UINT8_C(0x31) 163 | #define BMP3_REG_CMD UINT8_C(0x7E) 164 | 165 | /**\name Error status macros */ 166 | #define BMP3_ERR_FATAL UINT8_C(0x01) 167 | #define BMP3_ERR_CMD UINT8_C(0x02) 168 | #define BMP3_ERR_CONF UINT8_C(0x04) 169 | 170 | /**\name Status macros */ 171 | #define BMP3_CMD_RDY UINT8_C(0x10) 172 | #define BMP3_DRDY_PRESS UINT8_C(0x20) 173 | #define BMP3_DRDY_TEMP UINT8_C(0x40) 174 | 175 | /**\name Power mode macros */ 176 | #define BMP3_MODE_SLEEP UINT8_C(0x00) 177 | #define BMP3_MODE_FORCED UINT8_C(0x01) 178 | #define BMP3_MODE_NORMAL UINT8_C(0x03) 179 | 180 | /**\name FIFO related macros */ 181 | /**\name FIFO enable */ 182 | #define BMP3_ENABLE UINT8_C(0x01) 183 | #define BMP3_DISABLE UINT8_C(0x00) 184 | 185 | /**\name Interrupt pin configuration macros */ 186 | /**\name Open drain */ 187 | #define BMP3_INT_PIN_OPEN_DRAIN UINT8_C(0x01) 188 | #define BMP3_INT_PIN_PUSH_PULL UINT8_C(0x00) 189 | 190 | /**\name Level */ 191 | #define BMP3_INT_PIN_ACTIVE_HIGH UINT8_C(0x01) 192 | #define BMP3_INT_PIN_ACTIVE_LOW UINT8_C(0x00) 193 | 194 | /**\name Latch */ 195 | #define BMP3_INT_PIN_LATCH UINT8_C(0x01) 196 | #define BMP3_INT_PIN_NON_LATCH UINT8_C(0x00) 197 | 198 | /**\name Advance settings */ 199 | /**\name I2c watch dog timer period selection */ 200 | #define BMP3_I2C_WDT_SHORT_1_25_MS UINT8_C(0x00) 201 | #define BMP3_I2C_WDT_LONG_40_MS UINT8_C(0x01) 202 | 203 | /**\name FIFO Sub-sampling macros */ 204 | #define BMP3_FIFO_NO_SUBSAMPLING UINT8_C(0x00) 205 | #define BMP3_FIFO_SUBSAMPLING_2X UINT8_C(0x01) 206 | #define BMP3_FIFO_SUBSAMPLING_4X UINT8_C(0x02) 207 | #define BMP3_FIFO_SUBSAMPLING_8X UINT8_C(0x03) 208 | #define BMP3_FIFO_SUBSAMPLING_16X UINT8_C(0x04) 209 | #define BMP3_FIFO_SUBSAMPLING_32X UINT8_C(0x05) 210 | #define BMP3_FIFO_SUBSAMPLING_64X UINT8_C(0x06) 211 | #define BMP3_FIFO_SUBSAMPLING_128X UINT8_C(0x07) 212 | 213 | /**\name Over sampling macros */ 214 | #define BMP3_NO_OVERSAMPLING UINT8_C(0x00) 215 | #define BMP3_OVERSAMPLING_2X UINT8_C(0x01) 216 | #define BMP3_OVERSAMPLING_4X UINT8_C(0x02) 217 | #define BMP3_OVERSAMPLING_8X UINT8_C(0x03) 218 | #define BMP3_OVERSAMPLING_16X UINT8_C(0x04) 219 | #define BMP3_OVERSAMPLING_32X UINT8_C(0x05) 220 | 221 | /**\name Filter setting macros */ 222 | #define BMP3_IIR_FILTER_DISABLE UINT8_C(0x00) 223 | #define BMP3_IIR_FILTER_COEFF_1 UINT8_C(0x01) 224 | #define BMP3_IIR_FILTER_COEFF_3 UINT8_C(0x02) 225 | #define BMP3_IIR_FILTER_COEFF_7 UINT8_C(0x03) 226 | #define BMP3_IIR_FILTER_COEFF_15 UINT8_C(0x04) 227 | #define BMP3_IIR_FILTER_COEFF_31 UINT8_C(0x05) 228 | #define BMP3_IIR_FILTER_COEFF_63 UINT8_C(0x06) 229 | #define BMP3_IIR_FILTER_COEFF_127 UINT8_C(0x07) 230 | 231 | /**\name Odr setting macros */ 232 | #define BMP3_ODR_200_HZ UINT8_C(0x00) 233 | #define BMP3_ODR_100_HZ UINT8_C(0x01) 234 | #define BMP3_ODR_50_HZ UINT8_C(0x02) 235 | #define BMP3_ODR_25_HZ UINT8_C(0x03) 236 | #define BMP3_ODR_12_5_HZ UINT8_C(0x04) 237 | #define BMP3_ODR_6_25_HZ UINT8_C(0x05) 238 | #define BMP3_ODR_3_1_HZ UINT8_C(0x06) 239 | #define BMP3_ODR_1_5_HZ UINT8_C(0x07) 240 | #define BMP3_ODR_0_78_HZ UINT8_C(0x08) 241 | #define BMP3_ODR_0_39_HZ UINT8_C(0x09) 242 | #define BMP3_ODR_0_2_HZ UINT8_C(0x0A) 243 | #define BMP3_ODR_0_1_HZ UINT8_C(0x0B) 244 | #define BMP3_ODR_0_05_HZ UINT8_C(0x0C) 245 | #define BMP3_ODR_0_02_HZ UINT8_C(0x0D) 246 | #define BMP3_ODR_0_01_HZ UINT8_C(0x0E) 247 | #define BMP3_ODR_0_006_HZ UINT8_C(0x0F) 248 | #define BMP3_ODR_0_003_HZ UINT8_C(0x10) 249 | #define BMP3_ODR_0_001_HZ UINT8_C(0x11) 250 | 251 | /**\name Soft reset command */ 252 | #define BMP3_SOFT_RESET UINT8_C(0xB6) 253 | 254 | /**\name FIFO flush command */ 255 | #define BMP3_FIFO_FLUSH UINT8_C(0xB0) 256 | 257 | /**\name API success code */ 258 | #define BMP3_OK INT8_C(0) 259 | 260 | /**\name API error codes */ 261 | #define BMP3_E_NULL_PTR INT8_C(-1) 262 | #define BMP3_E_COMM_FAIL INT8_C(-2) 263 | #define BMP3_E_INVALID_ODR_OSR_SETTINGS INT8_C(-3) 264 | #define BMP3_E_CMD_EXEC_FAILED INT8_C(-4) 265 | #define BMP3_E_CONFIGURATION_ERR INT8_C(-5) 266 | #define BMP3_E_INVALID_LEN INT8_C(-6) 267 | #define BMP3_E_DEV_NOT_FOUND INT8_C(-7) 268 | #define BMP3_E_FIFO_WATERMARK_NOT_REACHED INT8_C(-8) 269 | 270 | /**\name API warning codes */ 271 | #define BMP3_W_SENSOR_NOT_ENABLED INT8_C(1) 272 | #define BMP3_W_INVALID_FIFO_REQ_FRAME_CNT INT8_C(2) 273 | #define BMP3_W_MIN_TEMP INT8_C(3) 274 | #define BMP3_W_MAX_TEMP INT8_C(4) 275 | #define BMP3_W_MIN_PRES INT8_C(5) 276 | #define BMP3_W_MAX_PRES INT8_C(6) 277 | 278 | /**\name Macros to select the which sensor settings are to be set by the user. 279 | * These values are internal for API implementation. Don't relate this to 280 | * data sheet. */ 281 | #define BMP3_SEL_PRESS_EN UINT16_C(1 << 1) 282 | #define BMP3_SEL_TEMP_EN UINT16_C(1 << 2) 283 | #define BMP3_SEL_DRDY_EN UINT16_C(1 << 3) 284 | #define BMP3_SEL_PRESS_OS UINT16_C(1 << 4) 285 | #define BMP3_SEL_TEMP_OS UINT16_C(1 << 5) 286 | #define BMP3_SEL_IIR_FILTER UINT16_C(1 << 6) 287 | #define BMP3_SEL_ODR UINT16_C(1 << 7) 288 | #define BMP3_SEL_OUTPUT_MODE UINT16_C(1 << 8) 289 | #define BMP3_SEL_LEVEL UINT16_C(1 << 9) 290 | #define BMP3_SEL_LATCH UINT16_C(1 << 10) 291 | #define BMP3_SEL_I2C_WDT_EN UINT16_C(1 << 11) 292 | #define BMP3_SEL_I2C_WDT UINT16_C(1 << 12) 293 | #define BMP3_SEL_ALL UINT16_C(0x7FF) 294 | 295 | /**\name Macros to select the which FIFO settings are to be set by the user 296 | * These values are internal for API implementation. Don't relate this to 297 | * data sheet.*/ 298 | #define BMP3_SEL_FIFO_MODE UINT16_C(1 << 1) 299 | #define BMP3_SEL_FIFO_STOP_ON_FULL_EN UINT16_C(1 << 2) 300 | #define BMP3_SEL_FIFO_TIME_EN UINT16_C(1 << 3) 301 | #define BMP3_SEL_FIFO_PRESS_EN UINT16_C(1 << 4) 302 | #define BMP3_SEL_FIFO_TEMP_EN UINT16_C(1 << 5) 303 | #define BMP3_SEL_FIFO_DOWN_SAMPLING UINT16_C(1 << 6) 304 | #define BMP3_SEL_FIFO_FILTER_EN UINT16_C(1 << 7) 305 | #define BMP3_SEL_FIFO_FWTM_EN UINT16_C(1 << 8) 306 | #define BMP3_SEL_FIFO_FULL_EN UINT16_C(1 << 9) 307 | 308 | /**\name Sensor component selection macros 309 | * These values are internal for API implementation. Don't relate this to 310 | * data sheet.*/ 311 | #define BMP3_PRESS UINT8_C(1) 312 | #define BMP3_TEMP UINT8_C(2) 313 | #define BMP3_PRESS_TEMP UINT8_C(3) 314 | 315 | /**\name Temperature range values in integer and float */ 316 | #define BMP3_MIN_TEMP_INT INT64_C(-4000) 317 | #define BMP3_MAX_TEMP_INT INT64_C(8500) 318 | #define BMP3_MIN_TEMP_DOUBLE -40.0f 319 | #define BMP3_MAX_TEMP_DOUBLE 85.0f 320 | 321 | /**\name Pressure range values in integer and float */ 322 | #define BMP3_MIN_PRES_INT UINT64_C(3000000) 323 | #define BMP3_MAX_PRES_INT UINT64_C(12500000) 324 | #define BMP3_MIN_PRES_DOUBLE 30000.0f 325 | #define BMP3_MAX_PRES_DOUBLE 125000.0f 326 | 327 | /**\name Macros for bit masking */ 328 | #define BMP3_ERR_FATAL_MSK UINT8_C(0x01) 329 | 330 | #define BMP3_ERR_CMD_MSK UINT8_C(0x02) 331 | #define BMP3_ERR_CMD_POS UINT8_C(0x01) 332 | 333 | #define BMP3_ERR_CONF_MSK UINT8_C(0x04) 334 | #define BMP3_ERR_CONF_POS UINT8_C(0x02) 335 | 336 | #define BMP3_STATUS_CMD_RDY_MSK UINT8_C(0x10) 337 | #define BMP3_STATUS_CMD_RDY_POS UINT8_C(0x04) 338 | 339 | #define BMP3_STATUS_DRDY_PRESS_MSK UINT8_C(0x20) 340 | #define BMP3_STATUS_DRDY_PRESS_POS UINT8_C(0x05) 341 | 342 | #define BMP3_STATUS_DRDY_TEMP_MSK UINT8_C(0x40) 343 | #define BMP3_STATUS_DRDY_TEMP_POS UINT8_C(0x06) 344 | 345 | #define BMP3_OP_MODE_MSK UINT8_C(0x30) 346 | #define BMP3_OP_MODE_POS UINT8_C(0x04) 347 | 348 | #define BMP3_PRESS_EN_MSK UINT8_C(0x01) 349 | 350 | #define BMP3_TEMP_EN_MSK UINT8_C(0x02) 351 | #define BMP3_TEMP_EN_POS UINT8_C(0x01) 352 | 353 | #define BMP3_IIR_FILTER_MSK UINT8_C(0x0E) 354 | #define BMP3_IIR_FILTER_POS UINT8_C(0x01) 355 | 356 | #define BMP3_ODR_MSK UINT8_C(0x1F) 357 | 358 | #define BMP3_PRESS_OS_MSK UINT8_C(0x07) 359 | 360 | #define BMP3_TEMP_OS_MSK UINT8_C(0x38) 361 | #define BMP3_TEMP_OS_POS UINT8_C(0x03) 362 | 363 | #define BMP3_FIFO_MODE_MSK UINT8_C(0x01) 364 | 365 | #define BMP3_FIFO_STOP_ON_FULL_MSK UINT8_C(0x02) 366 | #define BMP3_FIFO_STOP_ON_FULL_POS UINT8_C(0x01) 367 | 368 | #define BMP3_FIFO_TIME_EN_MSK UINT8_C(0x04) 369 | #define BMP3_FIFO_TIME_EN_POS UINT8_C(0x02) 370 | 371 | #define BMP3_FIFO_PRESS_EN_MSK UINT8_C(0x08) 372 | #define BMP3_FIFO_PRESS_EN_POS UINT8_C(0x03) 373 | 374 | #define BMP3_FIFO_TEMP_EN_MSK UINT8_C(0x10) 375 | #define BMP3_FIFO_TEMP_EN_POS UINT8_C(0x04) 376 | 377 | #define BMP3_FIFO_FILTER_EN_MSK UINT8_C(0x18) 378 | #define BMP3_FIFO_FILTER_EN_POS UINT8_C(0x03) 379 | 380 | #define BMP3_FIFO_DOWN_SAMPLING_MSK UINT8_C(0x07) 381 | 382 | #define BMP3_FIFO_FWTM_EN_MSK UINT8_C(0x08) 383 | #define BMP3_FIFO_FWTM_EN_POS UINT8_C(0x03) 384 | 385 | #define BMP3_FIFO_FULL_EN_MSK UINT8_C(0x10) 386 | #define BMP3_FIFO_FULL_EN_POS UINT8_C(0x04) 387 | 388 | #define BMP3_INT_OUTPUT_MODE_MSK UINT8_C(0x01) 389 | 390 | #define BMP3_INT_LEVEL_MSK UINT8_C(0x02) 391 | #define BMP3_INT_LEVEL_POS UINT8_C(0x01) 392 | 393 | #define BMP3_INT_LATCH_MSK UINT8_C(0x04) 394 | #define BMP3_INT_LATCH_POS UINT8_C(0x02) 395 | 396 | #define BMP3_INT_DRDY_EN_MSK UINT8_C(0x40) 397 | #define BMP3_INT_DRDY_EN_POS UINT8_C(0x06) 398 | 399 | #define BMP3_I2C_WDT_EN_MSK UINT8_C(0x02) 400 | #define BMP3_I2C_WDT_EN_POS UINT8_C(0x01) 401 | 402 | #define BMP3_I2C_WDT_SEL_MSK UINT8_C(0x04) 403 | #define BMP3_I2C_WDT_SEL_POS UINT8_C(0x02) 404 | 405 | #define BMP3_INT_STATUS_FWTM_MSK UINT8_C(0x01) 406 | 407 | #define BMP3_INT_STATUS_FFULL_MSK UINT8_C(0x02) 408 | #define BMP3_INT_STATUS_FFULL_POS UINT8_C(0x01) 409 | 410 | #define BMP3_INT_STATUS_DRDY_MSK UINT8_C(0x08) 411 | #define BMP3_INT_STATUS_DRDY_POS UINT8_C(0x03) 412 | 413 | /**\name UTILITY MACROS */ 414 | #define BMP3_SET_LOW_BYTE UINT16_C(0x00FF) 415 | #define BMP3_SET_HIGH_BYTE UINT16_C(0xFF00) 416 | 417 | /**\name Macro to combine two 8 bit data's to form a 16 bit data */ 418 | #define BMP3_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb) 419 | 420 | #define BMP3_SET_BITS(reg_data, bitname, data) \ 421 | ((reg_data & ~(bitname##_MSK)) | \ 422 | ((data << bitname##_POS) & bitname##_MSK)) 423 | 424 | /* Macro variant to handle the bitname position if it is zero */ 425 | #define BMP3_SET_BITS_POS_0(reg_data, bitname, data) \ 426 | ((reg_data & ~(bitname##_MSK)) | \ 427 | (data & bitname##_MSK)) 428 | 429 | #define BMP3_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \ 430 | (bitname##_POS)) 431 | 432 | /* Macro variant to handle the bitname position if it is zero */ 433 | #define BMP3_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) 434 | 435 | #define BMP3_GET_LSB(var) (uint8_t)(var & BMP3_SET_LOW_BYTE) 436 | #define BMP3_GET_MSB(var) (uint8_t)((var & BMP3_SET_HIGH_BYTE) >> 8) 437 | 438 | /**\name Macros related to size */ 439 | #define BMP3_LEN_CALIB_DATA UINT8_C(21) 440 | #define BMP3_LEN_P_AND_T_HEADER_DATA UINT8_C(7) 441 | #define BMP3_LEN_P_OR_T_HEADER_DATA UINT8_C(4) 442 | #define BMP3_LEN_P_T_DATA UINT8_C(6) 443 | #define BMP3_LEN_GEN_SETT UINT8_C(7) 444 | #define BMP3_LEN_P_DATA UINT8_C(3) 445 | #define BMP3_LEN_T_DATA UINT8_C(3) 446 | #define BMP3_LEN_SENSOR_TIME UINT8_C(3) 447 | #define BMP3_FIFO_MAX_FRAMES UINT8_C(73) 448 | 449 | /*! Power control settings */ 450 | #define BMP3_POWER_CNTL UINT16_C(0x0006) 451 | 452 | /*! Odr and filter settings */ 453 | #define BMP3_ODR_FILTER UINT16_C(0x00F0) 454 | 455 | /*! Interrupt control settings */ 456 | #define BMP3_INT_CTRL UINT16_C(0x0708) 457 | 458 | /*! Advance settings */ 459 | #define BMP3_ADV_SETT UINT16_C(0x1800) 460 | 461 | /*! FIFO settings */ 462 | 463 | /*! Mask for fifo_mode, fifo_stop_on_full, fifo_time_en, fifo_press_en and 464 | * fifo_temp_en settings */ 465 | #define BMP3_FIFO_CONFIG_1 UINT16_C(0x003E) 466 | 467 | /*! Mask for fifo_sub_sampling and data_select settings */ 468 | #define BMP3_FIFO_CONFIG_2 UINT16_C(0x00C0) 469 | 470 | /*! Mask for fwtm_en and ffull_en settings */ 471 | #define BMP3_FIFO_INT_CTRL UINT16_C(0x0300) 472 | 473 | /*! FIFO Header */ 474 | /*! FIFO temperature pressure header frame */ 475 | #define BMP3_FIFO_TEMP_PRESS_FRAME UINT8_C(0x94) 476 | 477 | /*! FIFO temperature header frame */ 478 | #define BMP3_FIFO_TEMP_FRAME UINT8_C(0x90) 479 | 480 | /*! FIFO pressure header frame */ 481 | #define BMP3_FIFO_PRESS_FRAME UINT8_C(0x84) 482 | 483 | /*! FIFO time header frame */ 484 | #define BMP3_FIFO_TIME_FRAME UINT8_C(0xA0) 485 | 486 | /*! FIFO error header frame */ 487 | #define BMP3_FIFO_ERROR_FRAME UINT8_C(0x44) 488 | 489 | /*! FIFO configuration change header frame */ 490 | #define BMP3_FIFO_CONFIG_CHANGE UINT8_C(0x48) 491 | 492 | /*! FIFO empty frame */ 493 | #define BMP3_FIFO_EMPTY_FRAME UINT8_C(0x80) 494 | 495 | /*! FIFO sensortime overhead byte count */ 496 | #define BMP3_SENSORTIME_OVERHEAD_BYTES UINT8_C(20) 497 | 498 | /********************************************************/ 499 | 500 | /*! 501 | * @brief Interface selection Enums 502 | */ 503 | enum bmp3_intf { 504 | /*! SPI interface */ 505 | BMP3_SPI_INTF, 506 | /*! I2C interface */ 507 | BMP3_I2C_INTF 508 | }; 509 | 510 | /********************************************************/ 511 | 512 | /*! 513 | * @brief Type definitions 514 | */ 515 | 516 | /*! 517 | * @brief Bus communication function pointer which should be mapped to 518 | * the platform specific read functions of the user 519 | * 520 | * @param[in] reg_addr : 8bit register address of the sensor 521 | * @param[out] reg_data : Data from the specified address 522 | * @param[in] length : Length of the reg_data array 523 | * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors 524 | * for interface related callbacks 525 | * @retval 0 for Success 526 | * @retval Non-zero for Failure 527 | */ 528 | typedef BMP3_INTF_RET_TYPE (*bmp3_read_fptr_t)(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr); 529 | 530 | /*! 531 | * @brief Bus communication function pointer which should be mapped to 532 | * the platform specific write functions of the user 533 | * 534 | * @param[in] reg_addr : 8bit register address of the sensor 535 | * @param[out] reg_data : Data to the specified address 536 | * @param[in] length : Length of the reg_data array 537 | * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors 538 | * for interface related callbacks 539 | * @retval 0 for Success 540 | * @retval Non-zero for Failure 541 | * 542 | */ 543 | typedef BMP3_INTF_RET_TYPE (*bmp3_write_fptr_t)(uint8_t reg_addr, const uint8_t *read_data, uint32_t len, 544 | void *intf_ptr); 545 | 546 | /*! 547 | * @brief Delay function pointer which should be mapped to 548 | * delay function of the user 549 | * 550 | * @param[in] period : Delay in microseconds. 551 | * @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors 552 | * for interface related call backs 553 | * 554 | */ 555 | typedef void (*bmp3_delay_us_fptr_t)(uint32_t period, void *intf_ptr); 556 | 557 | /********************************************************/ 558 | 559 | /*! 560 | * @brief Register Trim Variables 561 | */ 562 | struct bmp3_reg_calib_data 563 | { 564 | /*! Trim Variables */ 565 | 566 | uint16_t par_t1; 567 | uint16_t par_t2; 568 | int8_t par_t3; 569 | int16_t par_p1; 570 | int16_t par_p2; 571 | int8_t par_p3; 572 | int8_t par_p4; 573 | uint16_t par_p5; 574 | uint16_t par_p6; 575 | int8_t par_p7; 576 | int8_t par_p8; 577 | int16_t par_p9; 578 | int8_t par_p10; 579 | int8_t par_p11; 580 | int64_t t_lin; 581 | }; 582 | 583 | /*! 584 | * @brief bmp3 advance settings 585 | */ 586 | struct bmp3_adv_settings 587 | { 588 | /*! I2C watchdog enable */ 589 | uint8_t i2c_wdt_en; 590 | 591 | /*! I2C watchdog select */ 592 | uint8_t i2c_wdt_sel; 593 | }; 594 | 595 | /*! 596 | * @brief bmp3 odr and filter settings 597 | */ 598 | struct bmp3_odr_filter_settings 599 | { 600 | /*! Pressure oversampling */ 601 | uint8_t press_os; 602 | 603 | /*! Temperature oversampling */ 604 | uint8_t temp_os; 605 | 606 | /*! IIR filter */ 607 | uint8_t iir_filter; 608 | 609 | /*! Output data rate */ 610 | uint8_t odr; 611 | }; 612 | 613 | /*! 614 | * @brief bmp3 sensor status flags 615 | */ 616 | struct bmp3_sens_status 617 | { 618 | /*! Command ready status */ 619 | uint8_t cmd_rdy; 620 | 621 | /*! Data ready for pressure */ 622 | uint8_t drdy_press; 623 | 624 | /*! Data ready for temperature */ 625 | uint8_t drdy_temp; 626 | }; 627 | 628 | /*! 629 | * @brief bmp3 interrupt status flags 630 | */ 631 | struct bmp3_int_status 632 | { 633 | /*! Fifo watermark interrupt */ 634 | uint8_t fifo_wm; 635 | 636 | /*! Fifo full interrupt */ 637 | uint8_t fifo_full; 638 | 639 | /*! Data ready interrupt */ 640 | uint8_t drdy; 641 | }; 642 | 643 | /*! 644 | * @brief bmp3 error status flags 645 | */ 646 | struct bmp3_err_status 647 | { 648 | /*! Fatal error */ 649 | uint8_t fatal; 650 | 651 | /*! Command error */ 652 | uint8_t cmd; 653 | 654 | /*! Configuration error */ 655 | uint8_t conf; 656 | }; 657 | 658 | /*! 659 | * @brief bmp3 status flags 660 | */ 661 | struct bmp3_status 662 | { 663 | /*! Interrupt status */ 664 | struct bmp3_int_status intr; 665 | 666 | /*! Sensor status */ 667 | struct bmp3_sens_status sensor; 668 | 669 | /*! Error status */ 670 | struct bmp3_err_status err; 671 | 672 | /*! Power on reset status */ 673 | uint8_t pwr_on_rst; 674 | }; 675 | 676 | /*! 677 | * @brief bmp3 interrupt pin settings 678 | */ 679 | struct bmp3_int_ctrl_settings 680 | { 681 | /*! Output mode */ 682 | uint8_t output_mode; 683 | 684 | /*! Active high/low */ 685 | uint8_t level; 686 | 687 | /*! Latched or Non-latched */ 688 | uint8_t latch; 689 | 690 | /*! Data ready interrupt */ 691 | uint8_t drdy_en; 692 | }; 693 | 694 | /*! 695 | * @brief bmp3 device settings 696 | */ 697 | struct bmp3_settings 698 | { 699 | /*! Power mode which user wants to set */ 700 | uint8_t op_mode; 701 | 702 | /*! Enable/Disable pressure sensor */ 703 | uint8_t press_en; 704 | 705 | /*! Enable/Disable temperature sensor */ 706 | uint8_t temp_en; 707 | 708 | /*! ODR and filter configuration */ 709 | struct bmp3_odr_filter_settings odr_filter; 710 | 711 | /*! Interrupt configuration */ 712 | struct bmp3_int_ctrl_settings int_settings; 713 | 714 | /*! Advance settings */ 715 | struct bmp3_adv_settings adv_settings; 716 | }; 717 | 718 | /*! 719 | * @brief bmp3 fifo frame 720 | */ 721 | struct bmp3_fifo_data 722 | { 723 | /*! Data buffer of user defined length is to be mapped here 724 | * 512 + 4 */ 725 | uint8_t *buffer; 726 | 727 | /*! Number of bytes of data read from the fifo */ 728 | uint16_t byte_count; 729 | 730 | /*! Number of frames to be read as specified by the user */ 731 | uint8_t req_frames; 732 | 733 | /*! Will be equal to length when no more frames are there to parse */ 734 | uint16_t start_idx; 735 | 736 | /*! Will contain the no of parsed data frames from fifo */ 737 | uint8_t parsed_frames; 738 | 739 | /*! Configuration error */ 740 | uint8_t config_err; 741 | 742 | /*! Sensor time */ 743 | uint32_t sensor_time; 744 | 745 | /*! FIFO input configuration change */ 746 | uint8_t config_change; 747 | 748 | /*! All available frames are parsed */ 749 | uint8_t frame_not_available; 750 | }; 751 | 752 | /*! 753 | * @brief bmp3 fifo configuration 754 | */ 755 | struct bmp3_fifo_settings 756 | { 757 | /*! enable/disable */ 758 | uint8_t mode; 759 | 760 | /*! stop on full enable/disable */ 761 | uint8_t stop_on_full_en; 762 | 763 | /*! time enable/disable */ 764 | uint8_t time_en; 765 | 766 | /*! pressure enable/disable */ 767 | uint8_t press_en; 768 | 769 | /*! temperature enable/disable */ 770 | uint8_t temp_en; 771 | 772 | /*! down sampling rate */ 773 | uint8_t down_sampling; 774 | 775 | /*! filter enable/disable */ 776 | uint8_t filter_en; 777 | 778 | /*! FIFO watermark enable/disable */ 779 | uint8_t fwtm_en; 780 | 781 | /*! FIFO full enable/disable */ 782 | uint8_t ffull_en; 783 | }; 784 | 785 | #ifdef BMP3_FLOAT_COMPENSATION 786 | 787 | /*! 788 | * @brief Quantized Trim Variables 789 | */ 790 | struct bmp3_quantized_calib_data 791 | { 792 | /*! Quantized Trim Variables */ 793 | 794 | double par_t1; 795 | double par_t2; 796 | double par_t3; 797 | double par_p1; 798 | double par_p2; 799 | double par_p3; 800 | double par_p4; 801 | double par_p5; 802 | double par_p6; 803 | double par_p7; 804 | double par_p8; 805 | double par_p9; 806 | double par_p10; 807 | double par_p11; 808 | double t_lin; 809 | }; 810 | 811 | /*! 812 | * @brief Calibration data 813 | */ 814 | struct bmp3_calib_data 815 | { 816 | /*! Quantized data */ 817 | struct bmp3_quantized_calib_data quantized_calib_data; 818 | 819 | /*! Register data */ 820 | struct bmp3_reg_calib_data reg_calib_data; 821 | }; 822 | 823 | /*! 824 | * @brief bmp3 sensor structure which comprises of temperature and pressure 825 | * data. 826 | */ 827 | struct bmp3_data 828 | { 829 | /*! Compensated temperature */ 830 | double temperature; 831 | 832 | /*! Compensated pressure */ 833 | double pressure; 834 | }; 835 | 836 | #else 837 | 838 | /*! 839 | * @brief bmp3 sensor structure which comprises of temperature and pressure 840 | * data. 841 | */ 842 | struct bmp3_data 843 | { 844 | /*! Compensated temperature */ 845 | int64_t temperature; 846 | 847 | /*! Compensated pressure */ 848 | uint64_t pressure; 849 | }; 850 | 851 | /*! 852 | * @brief Calibration data 853 | */ 854 | struct bmp3_calib_data 855 | { 856 | /*! Register data */ 857 | struct bmp3_reg_calib_data reg_calib_data; 858 | }; 859 | 860 | #endif /* BMP3_FLOAT_COMPENSATION */ 861 | 862 | /*! 863 | * @brief bmp3 sensor structure which comprises of un-compensated temperature 864 | * and pressure data. 865 | */ 866 | struct bmp3_uncomp_data 867 | { 868 | /*! un-compensated pressure */ 869 | uint64_t pressure; 870 | 871 | /*! un-compensated temperature */ 872 | int64_t temperature; 873 | }; 874 | 875 | /*! 876 | * @brief bmp3 device structure 877 | */ 878 | struct bmp3_dev 879 | { 880 | /*! Chip Id */ 881 | uint8_t chip_id; 882 | 883 | /*! 884 | * The interface pointer is used to enable the user 885 | * to link their interface descriptors for reference during the 886 | * implementation of the read and write interfaces to the 887 | * hardware. 888 | */ 889 | void *intf_ptr; 890 | 891 | /*! Interface Selection 892 | * For SPI, interface = BMP3_SPI_INTF 893 | * For I2C, interface = BMP3_I2C_INTF 894 | **/ 895 | enum bmp3_intf intf; 896 | 897 | /*! To store interface pointer error */ 898 | BMP3_INTF_RET_TYPE intf_rslt; 899 | 900 | /*! Decide SPI or I2C read mechanism */ 901 | uint8_t dummy_byte; 902 | 903 | /*! Read function pointer */ 904 | bmp3_read_fptr_t read; 905 | 906 | /*! Write function pointer */ 907 | bmp3_write_fptr_t write; 908 | 909 | /*! Delay function pointer */ 910 | bmp3_delay_us_fptr_t delay_us; 911 | 912 | /*! Trim data */ 913 | struct bmp3_calib_data calib_data; 914 | }; 915 | 916 | #ifdef __cplusplus 917 | } 918 | #endif /* End of CPP guard */ 919 | 920 | #endif /* BMP3_DEFS_H_ */ 921 | -------------------------------------------------------------------------------- /examples/common/common.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "bmp3.h" 12 | #include "coines.h" 13 | #include "common.h" 14 | 15 | /*! BMP3 shuttle board ID */ 16 | #define BMP3_SHUTTLE_ID 0xD3 17 | 18 | /* Variable to store the device address */ 19 | static uint8_t dev_addr; 20 | 21 | /*! 22 | * I2C read function map to COINES platform 23 | */ 24 | BMP3_INTF_RET_TYPE bmp3_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) 25 | { 26 | uint8_t device_addr = *(uint8_t*)intf_ptr; 27 | 28 | (void)intf_ptr; 29 | 30 | return coines_read_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len); 31 | } 32 | 33 | /*! 34 | * I2C write function map to COINES platform 35 | */ 36 | BMP3_INTF_RET_TYPE bmp3_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) 37 | { 38 | uint8_t device_addr = *(uint8_t*)intf_ptr; 39 | 40 | (void)intf_ptr; 41 | 42 | return coines_write_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len); 43 | } 44 | 45 | /*! 46 | * SPI read function map to COINES platform 47 | */ 48 | BMP3_INTF_RET_TYPE bmp3_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) 49 | { 50 | uint8_t device_addr = *(uint8_t*)intf_ptr; 51 | 52 | (void)intf_ptr; 53 | 54 | return coines_read_spi(COINES_SPI_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len); 55 | } 56 | 57 | /*! 58 | * SPI write function map to COINES platform 59 | */ 60 | BMP3_INTF_RET_TYPE bmp3_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) 61 | { 62 | uint8_t device_addr = *(uint8_t*)intf_ptr; 63 | 64 | (void)intf_ptr; 65 | 66 | return coines_write_spi(COINES_SPI_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len); 67 | } 68 | 69 | /*! 70 | * Delay function map to COINES platform 71 | */ 72 | void bmp3_delay_us(uint32_t period, void *intf_ptr) 73 | { 74 | (void)intf_ptr; 75 | 76 | coines_delay_usec(period); 77 | } 78 | 79 | void bmp3_check_rslt(const char api_name[], int8_t rslt) 80 | { 81 | switch (rslt) 82 | { 83 | case BMP3_OK: 84 | 85 | /* Do nothing */ 86 | break; 87 | case BMP3_E_NULL_PTR: 88 | printf("API [%s] Error [%d] : Null pointer\r\n", api_name, rslt); 89 | break; 90 | case BMP3_E_COMM_FAIL: 91 | printf("API [%s] Error [%d] : Communication failure\r\n", api_name, rslt); 92 | break; 93 | case BMP3_E_INVALID_LEN: 94 | printf("API [%s] Error [%d] : Incorrect length parameter\r\n", api_name, rslt); 95 | break; 96 | case BMP3_E_DEV_NOT_FOUND: 97 | printf("API [%s] Error [%d] : Device not found\r\n", api_name, rslt); 98 | break; 99 | case BMP3_E_CONFIGURATION_ERR: 100 | printf("API [%s] Error [%d] : Configuration Error\r\n", api_name, rslt); 101 | break; 102 | case BMP3_W_SENSOR_NOT_ENABLED: 103 | printf("API [%s] Error [%d] : Warning when Sensor not enabled\r\n", api_name, rslt); 104 | break; 105 | case BMP3_W_INVALID_FIFO_REQ_FRAME_CNT: 106 | printf("API [%s] Error [%d] : Warning when Fifo watermark level is not in limit\r\n", api_name, rslt); 107 | break; 108 | default: 109 | printf("API [%s] Error [%d] : Unknown error code\r\n", api_name, rslt); 110 | break; 111 | } 112 | } 113 | 114 | BMP3_INTF_RET_TYPE bmp3_interface_init(struct bmp3_dev *bmp3, uint8_t intf) 115 | { 116 | int8_t rslt = BMP3_OK; 117 | struct coines_board_info board_info; 118 | 119 | if (bmp3 != NULL) 120 | { 121 | int16_t result = coines_open_comm_intf(COINES_COMM_INTF_USB, NULL); 122 | if (result < COINES_SUCCESS) 123 | { 124 | printf( 125 | "\n Unable to connect with Application Board ! \n" " 1. Check if the board is connected and powered on. \n" " 2. Check if Application Board USB driver is installed. \n" 126 | " 3. Check if board is in use by another application. (Insufficient permissions to access USB) \n"); 127 | exit(result); 128 | } 129 | 130 | result = coines_get_board_info(&board_info); 131 | 132 | #if defined(PC) 133 | setbuf(stdout, NULL); 134 | #endif 135 | 136 | if (result == COINES_SUCCESS) 137 | { 138 | if ((board_info.shuttle_id != BMP3_SHUTTLE_ID)) 139 | { 140 | printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n"); 141 | } 142 | } 143 | 144 | (void)coines_set_shuttleboard_vdd_vddio_config(0, 0); 145 | coines_delay_msec(1000); 146 | 147 | /* Bus configuration : I2C */ 148 | if (intf == BMP3_I2C_INTF) 149 | { 150 | printf("I2C Interface\n"); 151 | dev_addr = BMP3_ADDR_I2C_PRIM; 152 | bmp3->read = bmp3_i2c_read; 153 | bmp3->write = bmp3_i2c_write; 154 | bmp3->intf = BMP3_I2C_INTF; 155 | 156 | /* SDO pin is made low */ 157 | (void)coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW); 158 | (void)coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE); 159 | } 160 | /* Bus configuration : SPI */ 161 | else if (intf == BMP3_SPI_INTF) 162 | { 163 | printf("SPI Interface\n"); 164 | dev_addr = COINES_SHUTTLE_PIN_7; 165 | bmp3->read = bmp3_spi_read; 166 | bmp3->write = bmp3_spi_write; 167 | bmp3->intf = BMP3_SPI_INTF; 168 | (void)coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0); 169 | } 170 | 171 | coines_delay_msec(1000); 172 | 173 | (void)coines_set_shuttleboard_vdd_vddio_config(3300, 3300); 174 | 175 | coines_delay_msec(1000); 176 | 177 | bmp3->delay_us = bmp3_delay_us; 178 | bmp3->intf_ptr = &dev_addr; 179 | } 180 | else 181 | { 182 | rslt = BMP3_E_NULL_PTR; 183 | } 184 | 185 | return rslt; 186 | } 187 | 188 | void bmp3_coines_deinit(void) 189 | { 190 | (void)fflush(stdout); 191 | 192 | (void)coines_set_shuttleboard_vdd_vddio_config(0, 0); 193 | coines_delay_msec(1000); 194 | 195 | /* Coines interface reset */ 196 | coines_soft_reset(); 197 | coines_delay_msec(1000); 198 | (void)coines_close_comm_intf(COINES_COMM_INTF_USB, NULL); 199 | } 200 | -------------------------------------------------------------------------------- /examples/common/common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /*__cplusplus */ 10 | 11 | #include "bmp3.h" 12 | 13 | /*! 14 | * @brief Function to select the interface between SPI and I2C. 15 | * 16 | * @param[in] bmp3 : Structure instance of bmp3_dev 17 | * @param[in] intf : Interface selection parameter 18 | * 19 | * @return Status of execution 20 | * @retval 0 -> Success 21 | * @retval < 0 -> Failure Info 22 | */ 23 | BMP3_INTF_RET_TYPE bmp3_interface_init(struct bmp3_dev *bmp3, uint8_t intf); 24 | 25 | /*! 26 | * @brief Function for reading the sensor's registers through I2C bus. 27 | * 28 | * @param[in] reg_addr : Register address. 29 | * @param[out] reg_data : Pointer to the data buffer to store the read data. 30 | * @param[in] len : No of bytes to read. 31 | * @param[in] intf_ptr : Interface pointer 32 | * 33 | * @return Status of execution 34 | * @retval = BMP3_INTF_RET_SUCCESS -> Success 35 | * @retval != BMP3_INTF_RET_SUCCESS -> Failure Info 36 | * 37 | */ 38 | BMP3_INTF_RET_TYPE bmp3_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr); 39 | 40 | /*! 41 | * @brief Function for writing the sensor's registers through I2C bus. 42 | * 43 | * @param[in] reg_addr : Register address. 44 | * @param[in] reg_data : Pointer to the data buffer whose value is to be written. 45 | * @param[in] len : No of bytes to write. 46 | * @param[in] intf_ptr : Interface pointer 47 | * 48 | * @return Status of execution 49 | * @retval = BMP3_INTF_RET_SUCCESS -> Success 50 | * @retval != BMP3_INTF_RET_SUCCESS -> Failure Info 51 | * 52 | */ 53 | BMP3_INTF_RET_TYPE bmp3_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr); 54 | 55 | /*! 56 | * @brief Function for reading the sensor's registers through SPI bus. 57 | * 58 | * @param[in] reg_addr : Register address. 59 | * @param[out] reg_data : Pointer to the data buffer to store the read data. 60 | * @param[in] len : No of bytes to read. 61 | * @param[in] intf_ptr : Interface pointer 62 | * 63 | * @return Status of execution 64 | * @retval = BMP3_INTF_RET_SUCCESS -> Success 65 | * @retval != BMP3_INTF_RET_SUCCESS -> Failure Info 66 | * 67 | */ 68 | BMP3_INTF_RET_TYPE bmp3_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr); 69 | 70 | /*! 71 | * @brief Function for writing the sensor's registers through SPI bus. 72 | * 73 | * @param[in] reg_addr : Register address. 74 | * @param[in] reg_data : Pointer to the data buffer whose data has to be written. 75 | * @param[in] len : No of bytes to write. 76 | * @param[in] intf_ptr : Interface pointer 77 | * 78 | * @return Status of execution 79 | * @retval = BMP3_INTF_RET_SUCCESS -> Success 80 | * @retval != BMP3_INTF_RET_SUCCESS -> Failure Info 81 | * 82 | */ 83 | BMP3_INTF_RET_TYPE bmp3_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr); 84 | 85 | /*! 86 | * @brief This function provides the delay for required time (Microsecond) as per the input provided in some of the 87 | * APIs. 88 | * 89 | * @param[in] period : The required wait time in microsecond. 90 | * @param[in] intf_ptr : Interface pointer 91 | * 92 | * @return void. 93 | * 94 | */ 95 | void bmp3_delay_us(uint32_t period, void *intf_ptr); 96 | 97 | /*! 98 | * @brief Prints the execution status of the APIs. 99 | * 100 | * @param[in] api_name : Name of the API whose execution status has to be printed. 101 | * @param[in] rslt : Error code returned by the API whose execution status has to be printed. 102 | * 103 | * @return void. 104 | */ 105 | void bmp3_check_rslt(const char api_name[], int8_t rslt); 106 | 107 | /*! 108 | * @brief Deinitializes coines platform 109 | * 110 | * @return void. 111 | */ 112 | void bmp3_coines_deinit(void); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif /*__cplusplus */ 117 | -------------------------------------------------------------------------------- /examples/fifo_full_press/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_press.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_press/fifo_full_press.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, only Pressure is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint8_t try = 1; 38 | uint8_t index = 0; 39 | uint16_t settings_sel; 40 | uint16_t settings_fifo; 41 | uint16_t fifo_length = 0; 42 | uint8_t fifo_data[FIFO_MAX_SIZE]; 43 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 44 | struct bmp3_fifo_settings fifo_settings = { 0 }; 45 | struct bmp3_settings settings = { 0 }; 46 | struct bmp3_fifo_data fifo = { 0 }; 47 | struct bmp3_status status = { { 0 } }; 48 | 49 | /* Interface reference is given as a parameter 50 | * For I2C : BMP3_I2C_INTF 51 | * For SPI : BMP3_SPI_INTF 52 | */ 53 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 54 | bmp3_check_rslt("bmp3_interface_init", rslt); 55 | 56 | rslt = bmp3_init(&dev); 57 | bmp3_check_rslt("bmp3_init", rslt); 58 | 59 | /* 60 | * NOTE : Temperature will be enabled, to get pressure data. 61 | */ 62 | 63 | fifo_settings.mode = BMP3_ENABLE; 64 | fifo_settings.press_en = BMP3_ENABLE; 65 | fifo_settings.filter_en = BMP3_ENABLE; 66 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 67 | fifo_settings.ffull_en = BMP3_ENABLE; 68 | 69 | fifo.buffer = fifo_data; 70 | fifo.req_frames = FIFO_FRAME_COUNT; 71 | 72 | settings.press_en = BMP3_ENABLE; 73 | settings.odr_filter.press_os = BMP3_NO_OVERSAMPLING; 74 | settings.odr_filter.odr = BMP3_ODR_50_HZ; 75 | 76 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_ODR; 77 | 78 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_FULL_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | 79 | BMP3_SEL_FIFO_FILTER_EN; 80 | 81 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 82 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 83 | 84 | settings.op_mode = BMP3_MODE_NORMAL; 85 | rslt = bmp3_set_op_mode(&settings, &dev); 86 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 87 | 88 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 89 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 90 | 91 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 92 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 93 | 94 | printf("Read Fifo full interrupt data\n"); 95 | 96 | while (try <= ITERATION) 97 | { 98 | rslt = bmp3_get_status(&status, &dev); 99 | bmp3_check_rslt("bmp3_get_status", rslt); 100 | 101 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 102 | { 103 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 104 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 105 | 106 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 107 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 108 | 109 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 110 | rslt = bmp3_get_status(&status, &dev); 111 | bmp3_check_rslt("bmp3_get_status", rslt); 112 | 113 | if (rslt == BMP3_OK) 114 | { 115 | printf("\nIteration : %d\n", try); 116 | printf("Available fifo length : %d\n", fifo_length); 117 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 118 | 119 | printf("FIFO frames requested : %d\n", fifo.req_frames); 120 | 121 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 122 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 123 | 124 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 125 | 126 | for (index = 0; index < fifo.parsed_frames; index++) 127 | { 128 | #ifdef BMP3_FLOAT_COMPENSATION 129 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 130 | (fifo_p_t_data[index].pressure)); 131 | #else 132 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 133 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 134 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 135 | #endif 136 | } 137 | } 138 | 139 | try++; 140 | } 141 | } 142 | 143 | bmp3_coines_deinit(); 144 | 145 | return rslt; 146 | } 147 | -------------------------------------------------------------------------------- /examples/fifo_full_press_temp/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_press_temp.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_press_temp/fifo_full_press_temp.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, Pressure and Temperature are enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_AND_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint8_t try = 1; 38 | uint8_t index = 0; 39 | uint16_t settings_sel; 40 | uint16_t settings_fifo; 41 | uint16_t fifo_length = 0; 42 | uint8_t fifo_data[FIFO_MAX_SIZE]; 43 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 44 | struct bmp3_fifo_settings fifo_settings = { 0 }; 45 | struct bmp3_settings settings = { 0 }; 46 | struct bmp3_fifo_data fifo = { 0 }; 47 | struct bmp3_status status = { { 0 } }; 48 | 49 | /* Interface reference is given as a parameter 50 | * For I2C : BMP3_I2C_INTF 51 | * For SPI : BMP3_SPI_INTF 52 | */ 53 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 54 | bmp3_check_rslt("bmp3_interface_init", rslt); 55 | 56 | rslt = bmp3_init(&dev); 57 | bmp3_check_rslt("bmp3_init", rslt); 58 | 59 | fifo_settings.mode = BMP3_ENABLE; 60 | fifo_settings.press_en = BMP3_ENABLE; 61 | fifo_settings.temp_en = BMP3_ENABLE; 62 | fifo_settings.filter_en = BMP3_ENABLE; 63 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 64 | fifo_settings.ffull_en = BMP3_ENABLE; 65 | 66 | fifo.buffer = fifo_data; 67 | fifo.req_frames = FIFO_FRAME_COUNT; 68 | 69 | settings.press_en = BMP3_ENABLE; 70 | settings.temp_en = BMP3_ENABLE; 71 | settings.odr_filter.press_os = BMP3_NO_OVERSAMPLING; 72 | settings.odr_filter.temp_os = BMP3_NO_OVERSAMPLING; 73 | settings.odr_filter.odr = BMP3_ODR_50_HZ; 74 | 75 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 76 | 77 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FULL_EN | 78 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 79 | 80 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 81 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 82 | 83 | settings.op_mode = BMP3_MODE_NORMAL; 84 | rslt = bmp3_set_op_mode(&settings, &dev); 85 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 86 | 87 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 88 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 89 | 90 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 91 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 92 | 93 | printf("Read Fifo full interrupt data\n"); 94 | 95 | while (try <= ITERATION) 96 | { 97 | rslt = bmp3_get_status(&status, &dev); 98 | bmp3_check_rslt("bmp3_get_status", rslt); 99 | 100 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 101 | { 102 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 103 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 104 | 105 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 106 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 107 | 108 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 109 | rslt = bmp3_get_status(&status, &dev); 110 | bmp3_check_rslt("bmp3_get_status", rslt); 111 | 112 | if (rslt == BMP3_OK) 113 | { 114 | printf("\nIteration : %d\n", try); 115 | printf("Available fifo length : %d\n", fifo_length); 116 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 117 | 118 | printf("FIFO frames requested : %d\n", fifo.req_frames); 119 | 120 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 121 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 122 | 123 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 124 | 125 | for (index = 0; index < fifo.parsed_frames; index++) 126 | { 127 | #ifdef BMP3_FLOAT_COMPENSATION 128 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 129 | (fifo_p_t_data[index].pressure)); 130 | #else 131 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 132 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 133 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 134 | #endif 135 | } 136 | } 137 | 138 | try++; 139 | } 140 | } 141 | 142 | bmp3_coines_deinit(); 143 | 144 | return rslt; 145 | } 146 | -------------------------------------------------------------------------------- /examples/fifo_full_press_temp_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_press_temp_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_press_temp_with_sensortime/fifo_full_press_temp_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, Pressure and Temperature are enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_AND_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size 23 | * FIFO size is 512 bytes 24 | * Additional bytes given to read sensortime frame 25 | */ 26 | #define FIFO_MAX_SIZE UINT16_C(550) 27 | 28 | /* Iteration count to run example code */ 29 | #define ITERATION UINT8_C(10) 30 | 31 | /************************************************************************/ 32 | /********* Test code ******/ 33 | /************************************************************************/ 34 | 35 | int main(void) 36 | { 37 | struct bmp3_dev dev; 38 | int8_t rslt; 39 | 40 | uint8_t try = 1; 41 | uint8_t index = 0; 42 | uint16_t settings_sel; 43 | uint16_t settings_fifo; 44 | uint16_t fifo_length = 0; 45 | uint8_t fifo_data[FIFO_MAX_SIZE]; 46 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 47 | struct bmp3_fifo_settings fifo_settings = { 0 }; 48 | struct bmp3_settings settings = { 0 }; 49 | struct bmp3_fifo_data fifo = { 0 }; 50 | struct bmp3_status status = { { 0 } }; 51 | 52 | /* Interface reference is given as a parameter 53 | * For I2C : BMP3_I2C_INTF 54 | * For SPI : BMP3_SPI_INTF 55 | */ 56 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 57 | bmp3_check_rslt("bmp3_interface_init", rslt); 58 | 59 | rslt = bmp3_init(&dev); 60 | bmp3_check_rslt("bmp3_init", rslt); 61 | 62 | fifo_settings.mode = BMP3_ENABLE; 63 | fifo_settings.press_en = BMP3_ENABLE; 64 | fifo_settings.temp_en = BMP3_ENABLE; 65 | fifo_settings.filter_en = BMP3_ENABLE; 66 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 67 | fifo_settings.ffull_en = BMP3_ENABLE; 68 | fifo_settings.time_en = BMP3_ENABLE; 69 | 70 | fifo.buffer = fifo_data; 71 | fifo.req_frames = FIFO_FRAME_COUNT; 72 | 73 | settings.press_en = BMP3_ENABLE; 74 | settings.temp_en = BMP3_ENABLE; 75 | settings.odr_filter.press_os = BMP3_NO_OVERSAMPLING; 76 | settings.odr_filter.temp_os = BMP3_NO_OVERSAMPLING; 77 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 78 | 79 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 80 | 81 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FULL_EN | 82 | BMP3_SEL_FIFO_TIME_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 83 | 84 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 85 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 86 | 87 | settings.op_mode = BMP3_MODE_NORMAL; 88 | rslt = bmp3_set_op_mode(&settings, &dev); 89 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 90 | 91 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 92 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 93 | 94 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 95 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 96 | 97 | printf("Read Fifo full interrupt data with sensor time\n"); 98 | 99 | while (try <= ITERATION) 100 | { 101 | rslt = bmp3_get_status(&status, &dev); 102 | bmp3_check_rslt("bmp3_get_status", rslt); 103 | 104 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 105 | { 106 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 107 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 108 | 109 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 110 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 111 | 112 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 113 | rslt = bmp3_get_status(&status, &dev); 114 | bmp3_check_rslt("bmp3_get_status", rslt); 115 | 116 | if (rslt == BMP3_OK) 117 | { 118 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 119 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 120 | 121 | printf("\nIteration : %d\n", try); 122 | printf("Available fifo length : %d\n", fifo_length); 123 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 124 | 125 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 126 | 127 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 128 | 129 | for (index = 0; index < fifo.parsed_frames; index++) 130 | { 131 | #ifdef BMP3_FLOAT_COMPENSATION 132 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 133 | (fifo_p_t_data[index].pressure)); 134 | #else 135 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 136 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 137 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 138 | #endif 139 | } 140 | 141 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 142 | 143 | try++; 144 | } 145 | } 146 | } 147 | 148 | bmp3_coines_deinit(); 149 | 150 | return rslt; 151 | } 152 | -------------------------------------------------------------------------------- /examples/fifo_full_press_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_press_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_press_with_sensortime/fifo_full_press_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, only Pressure is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size 23 | * FIFO size is 512 bytes 24 | * Additional bytes given to read sensortime frame 25 | */ 26 | #define FIFO_MAX_SIZE UINT16_C(550) 27 | 28 | /* Iteration count to run example code */ 29 | #define ITERATION UINT8_C(10) 30 | 31 | /************************************************************************/ 32 | /********* Test code ******/ 33 | /************************************************************************/ 34 | 35 | int main(void) 36 | { 37 | struct bmp3_dev dev; 38 | int8_t rslt; 39 | 40 | uint8_t try = 1; 41 | uint8_t index = 0; 42 | uint16_t settings_sel; 43 | uint16_t settings_fifo; 44 | uint16_t fifo_length = 0; 45 | uint8_t fifo_data[FIFO_MAX_SIZE]; 46 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 47 | struct bmp3_fifo_settings fifo_settings = { 0 }; 48 | struct bmp3_settings settings = { 0 }; 49 | struct bmp3_fifo_data fifo = { 0 }; 50 | struct bmp3_status status = { { 0 } }; 51 | 52 | /* Interface reference is given as a parameter 53 | * For I2C : BMP3_I2C_INTF 54 | * For SPI : BMP3_SPI_INTF 55 | */ 56 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 57 | bmp3_check_rslt("bmp3_interface_init", rslt); 58 | 59 | rslt = bmp3_init(&dev); 60 | bmp3_check_rslt("bmp3_init", rslt); 61 | 62 | /* 63 | * NOTE : Temperature will be enabled, to get pressure data. 64 | */ 65 | 66 | fifo_settings.mode = BMP3_ENABLE; 67 | fifo_settings.press_en = BMP3_ENABLE; 68 | fifo_settings.filter_en = BMP3_ENABLE; 69 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 70 | fifo_settings.ffull_en = BMP3_ENABLE; 71 | fifo_settings.time_en = BMP3_ENABLE; 72 | 73 | fifo.buffer = fifo_data; 74 | fifo.req_frames = FIFO_FRAME_COUNT; 75 | 76 | settings.press_en = BMP3_ENABLE; 77 | settings.odr_filter.press_os = BMP3_NO_OVERSAMPLING; 78 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 79 | 80 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_ODR; 81 | 82 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_FULL_EN | BMP3_SEL_FIFO_TIME_EN | 83 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 84 | 85 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 86 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 87 | 88 | settings.op_mode = BMP3_MODE_NORMAL; 89 | rslt = bmp3_set_op_mode(&settings, &dev); 90 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 91 | 92 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 93 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 94 | 95 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 96 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 97 | 98 | printf("Read Fifo full interrupt data with sensor time\n"); 99 | 100 | while (try <= ITERATION) 101 | { 102 | rslt = bmp3_get_status(&status, &dev); 103 | bmp3_check_rslt("bmp3_get_status", rslt); 104 | 105 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 106 | { 107 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 108 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 109 | 110 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 111 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 112 | 113 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 114 | rslt = bmp3_get_status(&status, &dev); 115 | bmp3_check_rslt("bmp3_get_status", rslt); 116 | 117 | if (rslt == BMP3_OK) 118 | { 119 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 120 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 121 | 122 | printf("\nIteration : %d\n", try); 123 | printf("Available fifo length : %d\n", fifo_length); 124 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 125 | 126 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 127 | 128 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 129 | 130 | for (index = 0; index < fifo.parsed_frames; index++) 131 | { 132 | #ifdef BMP3_FLOAT_COMPENSATION 133 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 134 | (fifo_p_t_data[index].pressure)); 135 | #else 136 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 137 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 138 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 139 | #endif 140 | } 141 | 142 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 143 | 144 | try++; 145 | } 146 | } 147 | } 148 | 149 | bmp3_coines_deinit(); 150 | 151 | return rslt; 152 | } 153 | -------------------------------------------------------------------------------- /examples/fifo_full_temp/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_temp.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_temp/fifo_full_temp.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, only Temperature is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint8_t try = 1; 38 | uint8_t index = 0; 39 | uint16_t settings_sel; 40 | uint16_t settings_fifo; 41 | uint16_t fifo_length = 0; 42 | uint8_t fifo_data[FIFO_MAX_SIZE]; 43 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 44 | struct bmp3_fifo_settings fifo_settings = { 0 }; 45 | struct bmp3_settings settings = { 0 }; 46 | struct bmp3_fifo_data fifo = { 0 }; 47 | struct bmp3_status status = { { 0 } }; 48 | 49 | /* Interface reference is given as a parameter 50 | * For I2C : BMP3_I2C_INTF 51 | * For SPI : BMP3_SPI_INTF 52 | */ 53 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 54 | bmp3_check_rslt("bmp3_interface_init", rslt); 55 | 56 | rslt = bmp3_init(&dev); 57 | bmp3_check_rslt("bmp3_init", rslt); 58 | 59 | fifo_settings.mode = BMP3_ENABLE; 60 | fifo_settings.temp_en = BMP3_ENABLE; 61 | fifo_settings.filter_en = BMP3_ENABLE; 62 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 63 | fifo_settings.ffull_en = BMP3_ENABLE; 64 | 65 | fifo.buffer = fifo_data; 66 | fifo.req_frames = FIFO_FRAME_COUNT; 67 | 68 | settings.temp_en = BMP3_ENABLE; 69 | settings.odr_filter.temp_os = BMP3_NO_OVERSAMPLING; 70 | settings.odr_filter.odr = BMP3_ODR_50_HZ; 71 | 72 | settings_sel = BMP3_SEL_TEMP_EN | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 73 | 74 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FULL_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | 75 | BMP3_SEL_FIFO_FILTER_EN; 76 | 77 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 78 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 79 | 80 | settings.op_mode = BMP3_MODE_NORMAL; 81 | rslt = bmp3_set_op_mode(&settings, &dev); 82 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 83 | 84 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 85 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 86 | 87 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 88 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 89 | 90 | printf("Read Fifo full interrupt data\n"); 91 | 92 | while (try <= ITERATION) 93 | { 94 | rslt = bmp3_get_status(&status, &dev); 95 | bmp3_check_rslt("bmp3_get_status", rslt); 96 | 97 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 98 | { 99 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 100 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 101 | 102 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 103 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 104 | 105 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 106 | rslt = bmp3_get_status(&status, &dev); 107 | bmp3_check_rslt("bmp3_get_status", rslt); 108 | 109 | if (rslt == BMP3_OK) 110 | { 111 | printf("\nIteration : %d\n", try); 112 | printf("Available fifo length : %d\n", fifo_length); 113 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 114 | 115 | printf("FIFO frames requested : %d\n", fifo.req_frames); 116 | 117 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 118 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 119 | 120 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 121 | 122 | for (index = 0; index < fifo.parsed_frames; index++) 123 | { 124 | #ifdef BMP3_FLOAT_COMPENSATION 125 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 126 | (fifo_p_t_data[index].pressure)); 127 | #else 128 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 129 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 130 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 131 | #endif 132 | } 133 | } 134 | 135 | try++; 136 | } 137 | } 138 | 139 | bmp3_coines_deinit(); 140 | 141 | return rslt; 142 | } 143 | -------------------------------------------------------------------------------- /examples/fifo_full_temp_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_full_temp_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_full_temp_with_sensortime/fifo_full_temp_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines frame count requested 17 | * As, only Temperature is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size 23 | * FIFO size is 512 bytes 24 | * Additional bytes given to read sensortime frame 25 | */ 26 | #define FIFO_MAX_SIZE UINT16_C(550) 27 | 28 | /* Iteration count to run example code */ 29 | #define ITERATION UINT8_C(10) 30 | 31 | /************************************************************************/ 32 | /********* Test code ******/ 33 | /************************************************************************/ 34 | 35 | int main(void) 36 | { 37 | struct bmp3_dev dev; 38 | int8_t rslt; 39 | 40 | uint8_t try = 1; 41 | uint8_t index = 0; 42 | uint16_t settings_sel; 43 | uint16_t settings_fifo; 44 | uint16_t fifo_length = 0; 45 | uint8_t fifo_data[FIFO_MAX_SIZE]; 46 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 47 | struct bmp3_fifo_settings fifo_settings = { 0 }; 48 | struct bmp3_settings settings = { 0 }; 49 | struct bmp3_fifo_data fifo = { 0 }; 50 | struct bmp3_status status = { { 0 } }; 51 | 52 | /* Interface reference is given as a parameter 53 | * For I2C : BMP3_I2C_INTF 54 | * For SPI : BMP3_SPI_INTF 55 | */ 56 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 57 | bmp3_check_rslt("bmp3_interface_init", rslt); 58 | 59 | rslt = bmp3_init(&dev); 60 | bmp3_check_rslt("bmp3_init", rslt); 61 | 62 | fifo_settings.mode = BMP3_ENABLE; 63 | fifo_settings.temp_en = BMP3_ENABLE; 64 | fifo_settings.filter_en = BMP3_ENABLE; 65 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 66 | fifo_settings.ffull_en = BMP3_ENABLE; 67 | fifo_settings.time_en = BMP3_ENABLE; 68 | 69 | fifo.buffer = fifo_data; 70 | fifo.req_frames = FIFO_FRAME_COUNT; 71 | 72 | settings.temp_en = BMP3_ENABLE; 73 | settings.odr_filter.temp_os = BMP3_NO_OVERSAMPLING; 74 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 75 | 76 | settings_sel = BMP3_SEL_TEMP_EN | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 77 | 78 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FULL_EN | BMP3_SEL_FIFO_TIME_EN | 79 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 80 | 81 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 82 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 83 | 84 | settings.op_mode = BMP3_MODE_NORMAL; 85 | rslt = bmp3_set_op_mode(&settings, &dev); 86 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 87 | 88 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 89 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 90 | 91 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 92 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 93 | 94 | printf("Read Fifo full interrupt data with sensor time\n"); 95 | 96 | while (try <= ITERATION) 97 | { 98 | rslt = bmp3_get_status(&status, &dev); 99 | bmp3_check_rslt("bmp3_get_status", rslt); 100 | 101 | if ((rslt == BMP3_OK) && (status.intr.fifo_full == BMP3_ENABLE)) 102 | { 103 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 104 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 105 | 106 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 107 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 108 | 109 | /* NOTE : Read status register again to clear FIFO Full interrupt status */ 110 | rslt = bmp3_get_status(&status, &dev); 111 | bmp3_check_rslt("bmp3_get_status", rslt); 112 | 113 | if (rslt == BMP3_OK) 114 | { 115 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 116 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 117 | 118 | printf("\nIteration : %d\n", try); 119 | printf("Available fifo length : %d\n", fifo_length); 120 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 121 | 122 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 123 | 124 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 125 | 126 | for (index = 0; index < fifo.parsed_frames; index++) 127 | { 128 | #ifdef BMP3_FLOAT_COMPENSATION 129 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 130 | (fifo_p_t_data[index].pressure)); 131 | #else 132 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 133 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 134 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 135 | #endif 136 | } 137 | 138 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 139 | 140 | try++; 141 | } 142 | } 143 | } 144 | 145 | bmp3_coines_deinit(); 146 | 147 | return rslt; 148 | } 149 | -------------------------------------------------------------------------------- /examples/fifo_watermark_press/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_press.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_press/fifo_watermark_press.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, only Pressure is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | /* 61 | * NOTE : Temperature will be enabled, to get pressure data. 62 | */ 63 | 64 | fifo_settings.mode = BMP3_ENABLE; 65 | fifo_settings.press_en = BMP3_ENABLE; 66 | fifo_settings.filter_en = BMP3_ENABLE; 67 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 68 | fifo_settings.fwtm_en = BMP3_ENABLE; 69 | 70 | fifo.buffer = fifo_data; 71 | fifo.byte_count = FIFO_MAX_SIZE; 72 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 73 | 74 | settings.press_en = BMP3_ENABLE; 75 | settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; 76 | settings.odr_filter.odr = BMP3_ODR_100_HZ; 77 | 78 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_ODR; 79 | 80 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_FWTM_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | 81 | BMP3_SEL_FIFO_FILTER_EN; 82 | 83 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 84 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 85 | 86 | settings.op_mode = BMP3_MODE_NORMAL; 87 | rslt = bmp3_set_op_mode(&settings, &dev); 88 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 89 | 90 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 91 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 92 | 93 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 94 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 95 | 96 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 97 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 98 | 99 | printf("Read Fifo watermark interrupt data\n"); 100 | 101 | while (loop <= ITERATION) 102 | { 103 | rslt = bmp3_get_status(&status, &dev); 104 | bmp3_check_rslt("bmp3_get_status", rslt); 105 | 106 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 107 | { 108 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 109 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 110 | 111 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 112 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 113 | 114 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 115 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 116 | 117 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 118 | rslt = bmp3_get_status(&status, &dev); 119 | bmp3_check_rslt("bmp3_get_status", rslt); 120 | 121 | if (rslt == BMP3_OK) 122 | { 123 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 124 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 125 | 126 | printf("\nIteration : %d\n", loop); 127 | printf("Watermark level : %d\n", watermark); 128 | printf("Available fifo length : %d\n", fifo_length); 129 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 130 | 131 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 132 | 133 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 134 | 135 | for (index = 0; index < fifo.parsed_frames; index++) 136 | { 137 | #ifdef BMP3_FLOAT_COMPENSATION 138 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 139 | (fifo_p_t_data[index].pressure)); 140 | #else 141 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 142 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 143 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 144 | #endif 145 | } 146 | 147 | loop++; 148 | } 149 | } 150 | } 151 | 152 | bmp3_coines_deinit(); 153 | 154 | return rslt; 155 | } 156 | -------------------------------------------------------------------------------- /examples/fifo_watermark_press_temp/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_press_temp.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_press_temp/fifo_watermark_press_temp.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, Pressure and Temperature are enabled in this example, 18 | * Total byte count requested : FIFO_WATERMARK_FRAME_COUNT * BMP3_LEN_P_AND_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | fifo_settings.mode = BMP3_ENABLE; 61 | fifo_settings.press_en = BMP3_ENABLE; 62 | fifo_settings.temp_en = BMP3_ENABLE; 63 | fifo_settings.filter_en = BMP3_ENABLE; 64 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 65 | fifo_settings.fwtm_en = BMP3_ENABLE; 66 | 67 | fifo.buffer = fifo_data; 68 | fifo.byte_count = FIFO_MAX_SIZE; 69 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 70 | 71 | settings.press_en = BMP3_ENABLE; 72 | settings.temp_en = BMP3_ENABLE; 73 | settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; 74 | settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; 75 | settings.odr_filter.odr = BMP3_ODR_100_HZ; 76 | 77 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 78 | 79 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FWTM_EN | 80 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 81 | 82 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 83 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 84 | 85 | settings.op_mode = BMP3_MODE_NORMAL; 86 | rslt = bmp3_set_op_mode(&settings, &dev); 87 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 88 | 89 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 90 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 91 | 92 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 93 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 94 | 95 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 96 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 97 | 98 | printf("Read Fifo watermark interrupt data\n"); 99 | 100 | while (loop <= ITERATION) 101 | { 102 | rslt = bmp3_get_status(&status, &dev); 103 | bmp3_check_rslt("bmp3_get_status", rslt); 104 | 105 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 106 | { 107 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 108 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 109 | 110 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 111 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 112 | 113 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 114 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 115 | 116 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 117 | rslt = bmp3_get_status(&status, &dev); 118 | bmp3_check_rslt("bmp3_get_status", rslt); 119 | 120 | if (rslt == BMP3_OK) 121 | { 122 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 123 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 124 | 125 | printf("\nIteration : %d\n", loop); 126 | printf("Watermark level : %d\n", watermark); 127 | printf("Available fifo length : %d\n", fifo_length); 128 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 129 | 130 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 131 | 132 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 133 | 134 | for (index = 0; index < fifo.parsed_frames; index++) 135 | { 136 | #ifdef BMP3_FLOAT_COMPENSATION 137 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 138 | (fifo_p_t_data[index].pressure)); 139 | #else 140 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 141 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 142 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 143 | #endif 144 | } 145 | 146 | loop++; 147 | } 148 | } 149 | } 150 | 151 | bmp3_coines_deinit(); 152 | 153 | return rslt; 154 | } 155 | -------------------------------------------------------------------------------- /examples/fifo_watermark_press_temp_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_press_temp_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_press_temp_with_sensortime/fifo_watermark_press_temp_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, Pressure and Temperature are enabled in this example, 18 | * Total byte count requested : FIFO_WATERMARK_FRAME_COUNT * BMP3_LEN_P_AND_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | fifo_settings.mode = BMP3_ENABLE; 61 | fifo_settings.press_en = BMP3_ENABLE; 62 | fifo_settings.temp_en = BMP3_ENABLE; 63 | fifo_settings.filter_en = BMP3_ENABLE; 64 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 65 | fifo_settings.fwtm_en = BMP3_ENABLE; 66 | fifo_settings.time_en = BMP3_ENABLE; 67 | 68 | fifo.buffer = fifo_data; 69 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 70 | 71 | settings.press_en = BMP3_ENABLE; 72 | settings.temp_en = BMP3_ENABLE; 73 | settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; 74 | settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; 75 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 76 | settings.int_settings.latch = BMP3_ENABLE; 77 | 78 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 79 | 80 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_TIME_EN | 81 | BMP3_SEL_FIFO_FWTM_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 82 | 83 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 84 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 85 | 86 | settings.op_mode = BMP3_MODE_NORMAL; 87 | rslt = bmp3_set_op_mode(&settings, &dev); 88 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 89 | 90 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 91 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 92 | 93 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 94 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 95 | 96 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 97 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 98 | 99 | printf("Read Fifo watermark interrupt data with sensor time\n"); 100 | 101 | while (loop <= ITERATION) 102 | { 103 | rslt = bmp3_get_status(&status, &dev); 104 | bmp3_check_rslt("bmp3_get_status", rslt); 105 | 106 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 107 | { 108 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 109 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 110 | 111 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 112 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 113 | 114 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 115 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 116 | 117 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 118 | rslt = bmp3_get_status(&status, &dev); 119 | bmp3_check_rslt("bmp3_get_status", rslt); 120 | 121 | if (rslt == BMP3_OK) 122 | { 123 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 124 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 125 | 126 | printf("\nIteration : %d\n", loop); 127 | printf("Watermark level : %d\n", watermark); 128 | printf("Available fifo length : %d\n", fifo_length); 129 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 130 | 131 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 132 | 133 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 134 | 135 | for (index = 0; index < fifo.parsed_frames; index++) 136 | { 137 | #ifdef BMP3_FLOAT_COMPENSATION 138 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 139 | (fifo_p_t_data[index].pressure)); 140 | #else 141 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 142 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 143 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 144 | #endif 145 | } 146 | 147 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 148 | 149 | loop++; 150 | } 151 | } 152 | } 153 | 154 | bmp3_coines_deinit(); 155 | 156 | return rslt; 157 | } 158 | -------------------------------------------------------------------------------- /examples/fifo_watermark_press_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_press_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_press_with_sensortime/fifo_watermark_press_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, only Pressure is enabled in this example, 18 | * Total byte count requested : FIFO_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | /* 61 | * NOTE : Temperature will be enabled, to get pressure data. 62 | */ 63 | 64 | fifo_settings.mode = BMP3_ENABLE; 65 | fifo_settings.press_en = BMP3_ENABLE; 66 | fifo_settings.filter_en = BMP3_ENABLE; 67 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 68 | fifo_settings.fwtm_en = BMP3_ENABLE; 69 | fifo_settings.time_en = BMP3_ENABLE; 70 | 71 | fifo.buffer = fifo_data; 72 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 73 | 74 | settings.press_en = BMP3_ENABLE; 75 | settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; 76 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 77 | settings.int_settings.latch = BMP3_ENABLE; 78 | 79 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_ODR; 80 | 81 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_PRESS_EN | BMP3_SEL_FIFO_TIME_EN | BMP3_SEL_FIFO_FWTM_EN | 82 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 83 | 84 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 85 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 86 | 87 | settings.op_mode = BMP3_MODE_NORMAL; 88 | rslt = bmp3_set_op_mode(&settings, &dev); 89 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 90 | 91 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 92 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 93 | 94 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 95 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 96 | 97 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 98 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 99 | 100 | printf("Read Fifo watermark interrupt data with sensor time\n"); 101 | 102 | while (loop <= ITERATION) 103 | { 104 | rslt = bmp3_get_status(&status, &dev); 105 | bmp3_check_rslt("bmp3_get_status", rslt); 106 | 107 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 108 | { 109 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 110 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 111 | 112 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 113 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 114 | 115 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 116 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 117 | 118 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 119 | rslt = bmp3_get_status(&status, &dev); 120 | bmp3_check_rslt("bmp3_get_status", rslt); 121 | 122 | if (rslt == BMP3_OK) 123 | { 124 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 125 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 126 | 127 | printf("\nIteration : %d\n", loop); 128 | printf("Watermark level : %d\n", watermark); 129 | printf("Available fifo length : %d\n", fifo_length); 130 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 131 | 132 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 133 | 134 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 135 | 136 | for (index = 0; index < fifo.parsed_frames; index++) 137 | { 138 | #ifdef BMP3_FLOAT_COMPENSATION 139 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 140 | (fifo_p_t_data[index].pressure)); 141 | #else 142 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 143 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 144 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 145 | #endif 146 | } 147 | 148 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 149 | 150 | loop++; 151 | } 152 | } 153 | } 154 | 155 | bmp3_coines_deinit(); 156 | 157 | return rslt; 158 | } 159 | -------------------------------------------------------------------------------- /examples/fifo_watermark_temp/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_temp.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_temp/fifo_watermark_temp.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, only Temperature is enabled in this example, 18 | * Total byte count requested : FIFO_WATERMARK_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | fifo_settings.mode = BMP3_ENABLE; 61 | fifo_settings.temp_en = BMP3_ENABLE; 62 | fifo_settings.filter_en = BMP3_ENABLE; 63 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 64 | fifo_settings.fwtm_en = BMP3_ENABLE; 65 | 66 | fifo.buffer = fifo_data; 67 | fifo.byte_count = FIFO_MAX_SIZE; 68 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 69 | 70 | settings.temp_en = BMP3_ENABLE; 71 | settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; 72 | settings.odr_filter.odr = BMP3_ODR_100_HZ; 73 | 74 | settings_sel = BMP3_SEL_TEMP_EN | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 75 | 76 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_FWTM_EN | BMP3_SEL_FIFO_DOWN_SAMPLING | 77 | BMP3_SEL_FIFO_FILTER_EN; 78 | 79 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 80 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 81 | 82 | settings.op_mode = BMP3_MODE_NORMAL; 83 | rslt = bmp3_set_op_mode(&settings, &dev); 84 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 85 | 86 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 87 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 88 | 89 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 90 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 91 | 92 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 93 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 94 | 95 | printf("Read Fifo watermark interrupt data\n"); 96 | 97 | while (loop <= ITERATION) 98 | { 99 | rslt = bmp3_get_status(&status, &dev); 100 | bmp3_check_rslt("bmp3_get_status", rslt); 101 | 102 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 103 | { 104 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 105 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 106 | 107 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 108 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 109 | 110 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 111 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 112 | 113 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 114 | rslt = bmp3_get_status(&status, &dev); 115 | bmp3_check_rslt("bmp3_get_status", rslt); 116 | 117 | if (rslt == BMP3_OK) 118 | { 119 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 120 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 121 | 122 | printf("\nIteration : %d\n", loop); 123 | printf("Watermark level : %d\n", watermark); 124 | printf("Available fifo length : %d\n", fifo_length); 125 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 126 | 127 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 128 | 129 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 130 | 131 | for (index = 0; index < fifo.parsed_frames; index++) 132 | { 133 | #ifdef BMP3_FLOAT_COMPENSATION 134 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 135 | (fifo_p_t_data[index].pressure)); 136 | #else 137 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 138 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 139 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 140 | #endif 141 | } 142 | 143 | loop++; 144 | } 145 | } 146 | } 147 | 148 | bmp3_coines_deinit(); 149 | 150 | return rslt; 151 | } 152 | -------------------------------------------------------------------------------- /examples/fifo_watermark_temp_with_sensortime/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= fifo_watermark_temp_with_sensortime.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/fifo_watermark_temp_with_sensortime/fifo_watermark_temp_with_sensortime.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | 16 | /* Defines watermark level of frame count requested 17 | * As, only Temperature is enabled in this example, 18 | * Total byte count requested : FIFO_WATERMARK_FRAME_COUNT * BMP3_LEN_P_OR_T_HEADER_DATA 19 | */ 20 | #define FIFO_WATERMARK_FRAME_COUNT UINT8_C(50) 21 | 22 | /* Maximum FIFO size */ 23 | #define FIFO_MAX_SIZE UINT16_C(512) 24 | 25 | /* Iteration count to run example code */ 26 | #define ITERATION UINT8_C(10) 27 | 28 | /************************************************************************/ 29 | /********* Test code ******/ 30 | /************************************************************************/ 31 | 32 | int main(void) 33 | { 34 | struct bmp3_dev dev; 35 | int8_t rslt; 36 | 37 | uint16_t settings_sel; 38 | uint16_t settings_fifo; 39 | uint8_t loop = 1; 40 | uint8_t index = 0; 41 | uint16_t watermark = 0; 42 | uint16_t fifo_length = 0; 43 | uint8_t fifo_data[FIFO_MAX_SIZE]; 44 | struct bmp3_data fifo_p_t_data[FIFO_MAX_SIZE]; 45 | struct bmp3_fifo_settings fifo_settings = { 0 }; 46 | struct bmp3_settings settings = { 0 }; 47 | struct bmp3_fifo_data fifo = { 0 }; 48 | struct bmp3_status status = { { 0 } }; 49 | 50 | /* Interface reference is given as a parameter 51 | * For I2C : BMP3_I2C_INTF 52 | * For SPI : BMP3_SPI_INTF 53 | */ 54 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 55 | bmp3_check_rslt("bmp3_interface_init", rslt); 56 | 57 | rslt = bmp3_init(&dev); 58 | bmp3_check_rslt("bmp3_init", rslt); 59 | 60 | fifo_settings.mode = BMP3_ENABLE; 61 | fifo_settings.temp_en = BMP3_ENABLE; 62 | fifo_settings.filter_en = BMP3_ENABLE; 63 | fifo_settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING; 64 | fifo_settings.fwtm_en = BMP3_ENABLE; 65 | fifo_settings.time_en = BMP3_ENABLE; 66 | 67 | fifo.buffer = fifo_data; 68 | fifo.req_frames = FIFO_WATERMARK_FRAME_COUNT; 69 | 70 | settings.temp_en = BMP3_ENABLE; 71 | settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; 72 | settings.odr_filter.odr = BMP3_ODR_12_5_HZ; 73 | settings.int_settings.latch = BMP3_ENABLE; 74 | 75 | settings_sel = BMP3_SEL_TEMP_EN | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 76 | 77 | settings_fifo = BMP3_SEL_FIFO_MODE | BMP3_SEL_FIFO_TEMP_EN | BMP3_SEL_FIFO_TIME_EN | BMP3_SEL_FIFO_FWTM_EN | 78 | BMP3_SEL_FIFO_DOWN_SAMPLING | BMP3_SEL_FIFO_FILTER_EN; 79 | 80 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 81 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 82 | 83 | settings.op_mode = BMP3_MODE_NORMAL; 84 | rslt = bmp3_set_op_mode(&settings, &dev); 85 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 86 | 87 | rslt = bmp3_set_fifo_watermark(&fifo, &fifo_settings, &dev); 88 | bmp3_check_rslt("bmp3_set_fifo_watermark", rslt); 89 | 90 | rslt = bmp3_set_fifo_settings(settings_fifo, &fifo_settings, &dev); 91 | bmp3_check_rslt("bmp3_set_fifo_settings", rslt); 92 | 93 | rslt = bmp3_get_fifo_settings(&fifo_settings, &dev); 94 | bmp3_check_rslt("bmp3_get_fifo_settings", rslt); 95 | 96 | printf("Read Fifo watermark interrupt data with sensor time\n"); 97 | 98 | while (loop <= ITERATION) 99 | { 100 | rslt = bmp3_get_status(&status, &dev); 101 | bmp3_check_rslt("bmp3_get_status", rslt); 102 | 103 | if ((rslt == BMP3_OK) && (status.intr.fifo_wm == BMP3_ENABLE)) 104 | { 105 | rslt = bmp3_get_fifo_length(&fifo_length, &dev); 106 | bmp3_check_rslt("bmp3_get_fifo_length", rslt); 107 | 108 | rslt = bmp3_get_fifo_watermark(&watermark, &dev); 109 | bmp3_check_rslt("bmp3_get_fifo_watermark", rslt); 110 | 111 | rslt = bmp3_get_fifo_data(&fifo, &fifo_settings, &dev); 112 | bmp3_check_rslt("bmp3_get_fifo_data", rslt); 113 | 114 | /* NOTE : Read status register again to clear FIFO watermark interrupt status */ 115 | rslt = bmp3_get_status(&status, &dev); 116 | bmp3_check_rslt("bmp3_get_status", rslt); 117 | 118 | if (rslt == BMP3_OK) 119 | { 120 | rslt = bmp3_extract_fifo_data(fifo_p_t_data, &fifo, &dev); 121 | bmp3_check_rslt("bmp3_extract_fifo_data", rslt); 122 | 123 | printf("\nIteration : %d\n", loop); 124 | printf("Watermark level : %d\n", watermark); 125 | printf("Available fifo length : %d\n", fifo_length); 126 | printf("Fifo byte count from fifo structure : %d\n", fifo.byte_count); 127 | 128 | printf("FIFO compensation Pressure and Temperature frames requested : %d\n", fifo.req_frames); 129 | 130 | printf("FIFO frames extracted : %d\n", fifo.parsed_frames); 131 | 132 | for (index = 0; index < fifo.parsed_frames; index++) 133 | { 134 | #ifdef BMP3_FLOAT_COMPENSATION 135 | printf("Frame[%d] T: %.2f deg C, P: %.2f Pa\n", index, (fifo_p_t_data[index].temperature), 136 | (fifo_p_t_data[index].pressure)); 137 | #else 138 | printf("Frame[%d] T: %ld deg C, P: %lu Pa\n", index, 139 | (long int)(int32_t)(fifo_p_t_data[index].temperature / 100), 140 | (long unsigned int)(uint32_t)(fifo_p_t_data[index].pressure / 100)); 141 | #endif 142 | } 143 | 144 | printf("Sensor time : %lu\n", (long unsigned int)fifo.sensor_time); 145 | 146 | loop++; 147 | } 148 | } 149 | } 150 | 151 | bmp3_coines_deinit(); 152 | 153 | return rslt; 154 | } 155 | -------------------------------------------------------------------------------- /examples/read_sensor_data/Makefile: -------------------------------------------------------------------------------- 1 | COINES_INSTALL_PATH ?= ../../../.. 2 | 3 | EXAMPLE_FILE ?= read_sensor_data.c 4 | 5 | API_LOCATION ?= ../.. 6 | 7 | C_SRCS += \ 8 | $(API_LOCATION)/bmp3.c \ 9 | ../common/common.c 10 | 11 | INCLUDEPATHS += \ 12 | $(API_LOCATION) \ 13 | ../common 14 | 15 | include $(COINES_INSTALL_PATH)/coines.mk -------------------------------------------------------------------------------- /examples/read_sensor_data/read_sensor_data.c: -------------------------------------------------------------------------------- 1 | /**\ 2 | * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | **/ 6 | 7 | #include 8 | 9 | #include "bmp3.h" 10 | #include "common.h" 11 | 12 | /************************************************************************/ 13 | /********* Macros ******/ 14 | /************************************************************************/ 15 | /* Iteration count to run example code */ 16 | #define ITERATION UINT8_C(100) 17 | 18 | /************************************************************************/ 19 | /********* Test code ******/ 20 | /************************************************************************/ 21 | 22 | int main(void) 23 | { 24 | int8_t rslt; 25 | uint8_t loop = 0; 26 | uint16_t settings_sel; 27 | struct bmp3_dev dev; 28 | struct bmp3_data data = { 0 }; 29 | struct bmp3_settings settings = { 0 }; 30 | struct bmp3_status status = { { 0 } }; 31 | 32 | /* Interface reference is given as a parameter 33 | * For I2C : BMP3_I2C_INTF 34 | * For SPI : BMP3_SPI_INTF 35 | */ 36 | rslt = bmp3_interface_init(&dev, BMP3_I2C_INTF); 37 | bmp3_check_rslt("bmp3_interface_init", rslt); 38 | 39 | rslt = bmp3_init(&dev); 40 | bmp3_check_rslt("bmp3_init", rslt); 41 | 42 | settings.int_settings.drdy_en = BMP3_ENABLE; 43 | settings.press_en = BMP3_ENABLE; 44 | settings.temp_en = BMP3_ENABLE; 45 | 46 | settings.odr_filter.press_os = BMP3_OVERSAMPLING_2X; 47 | settings.odr_filter.temp_os = BMP3_OVERSAMPLING_2X; 48 | settings.odr_filter.odr = BMP3_ODR_100_HZ; 49 | 50 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR | 51 | BMP3_SEL_DRDY_EN; 52 | 53 | rslt = bmp3_set_sensor_settings(settings_sel, &settings, &dev); 54 | bmp3_check_rslt("bmp3_set_sensor_settings", rslt); 55 | 56 | settings.op_mode = BMP3_MODE_NORMAL; 57 | rslt = bmp3_set_op_mode(&settings, &dev); 58 | bmp3_check_rslt("bmp3_set_op_mode", rslt); 59 | 60 | while (loop < ITERATION) 61 | { 62 | rslt = bmp3_get_status(&status, &dev); 63 | bmp3_check_rslt("bmp3_get_status", rslt); 64 | 65 | /* Read temperature and pressure data iteratively based on data ready interrupt */ 66 | if ((rslt == BMP3_OK) && (status.intr.drdy == BMP3_ENABLE)) 67 | { 68 | /* 69 | * First parameter indicates the type of data to be read 70 | * BMP3_PRESS_TEMP : To read pressure and temperature data 71 | * BMP3_TEMP : To read only temperature data 72 | * BMP3_PRESS : To read only pressure data 73 | */ 74 | rslt = bmp3_get_sensor_data(BMP3_PRESS_TEMP, &data, &dev); 75 | bmp3_check_rslt("bmp3_get_sensor_data", rslt); 76 | 77 | /* NOTE : Read status register again to clear data ready interrupt status */ 78 | rslt = bmp3_get_status(&status, &dev); 79 | bmp3_check_rslt("bmp3_get_status", rslt); 80 | 81 | #ifdef BMP3_FLOAT_COMPENSATION 82 | printf("Data[%d] T: %.2f deg C, P: %.2f Pa\n", loop, (data.temperature), (data.pressure)); 83 | #else 84 | printf("Data[%d] T: %ld deg C, P: %lu Pa\n", loop, (long int)(int32_t)(data.temperature / 100), 85 | (long unsigned int)(uint32_t)(data.pressure / 100)); 86 | #endif 87 | 88 | loop = loop + 1; 89 | } 90 | } 91 | 92 | bmp3_coines_deinit(); 93 | 94 | return rslt; 95 | } 96 | -------------------------------------------------------------------------------- /self-test/bmp3_selftest.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * BSD-3-Clause 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * @file bmp3_selftest.c 34 | * @date 2020-07-20 35 | * @version v2.0.1 36 | * 37 | */ 38 | 39 | #include "bmp3_selftest.h" 40 | 41 | #ifndef BMP3_DOUBLE_PRECISION_COMPENSATION 42 | 43 | /* 0 degree celsius */ 44 | #define BMP3_MIN_TEMPERATURE INT16_C(0) 45 | 46 | /* 40 degree celsius */ 47 | #define BMP3_MAX_TEMPERATURE INT16_C(4000) 48 | 49 | /* 900 hecto Pascals */ 50 | #define BMP3_MIN_PRESSURE UINT32_C(90000) 51 | 52 | /* 1100 hecto Pascals */ 53 | #define BMP3_MAX_PRESSURE UINT32_C(110000) 54 | 55 | #else 56 | 57 | /* 0 degree celsius */ 58 | #define BMP3_MIN_TEMPERATURE (0.0f) 59 | 60 | /* 40 degree celsius */ 61 | #define BMP3_MAX_TEMPERATURE (40.0f) 62 | 63 | /* 900 hecto Pascals */ 64 | #define BMP3_MIN_PRESSURE (900.0f) 65 | 66 | /* 1100 hecto Pascals */ 67 | #define BMP3_MAX_PRESSURE (1100.0f) 68 | #endif 69 | 70 | /*! 71 | * @brief Function to analyze the sensor data 72 | * 73 | * @param[in] data Structure instance of bmp3_data(compensated temp & press values) 74 | * 75 | * @return Error code 76 | * @retval 0 Success 77 | */ 78 | static int8_t analyze_sensor_data(const struct bmp3_data *data); 79 | 80 | /*! 81 | * @brief Function to calculate the CRC of the trimming parameters. 82 | * 83 | * @param[in] seed CRC of each register 84 | * @param[in] data register data. 85 | * 86 | * @return calculated CRC 87 | */ 88 | static int8_t cal_crc(uint8_t seed, uint8_t data); 89 | 90 | /*! 91 | * @brief Function to validate the trimming parameters 92 | * 93 | * @param [in] dev Structure instance of bmp3_dev structure. 94 | * 95 | * @return Error code 96 | * @retval 0 Success 97 | * 98 | */ 99 | static int8_t validate_trimming_param(struct bmp3_dev *dev); 100 | 101 | /*! 102 | * @brief Self-test API for the BMP38X 103 | */ 104 | int8_t bmp3_selftest_check(struct bmp3_dev *dev) 105 | { 106 | int8_t rslt; 107 | 108 | /* Variable used to select the sensor component */ 109 | uint8_t sensor_comp; 110 | 111 | /* Variable used to store the compensated data */ 112 | struct bmp3_data data = { 0 }; 113 | 114 | /* Used to select the settings user needs to change */ 115 | uint16_t settings_sel; 116 | 117 | /* Reset the sensor */ 118 | rslt = bmp3_soft_reset(dev); 119 | if (rslt == BMP3_SENSOR_OK) 120 | { 121 | rslt = bmp3_init(dev); 122 | 123 | if (rslt == BMP3_E_COMM_FAIL || rslt == BMP3_E_DEV_NOT_FOUND) 124 | { 125 | rslt = BMP3_COMMUNICATION_ERROR_OR_WRONG_DEVICE; 126 | } 127 | 128 | if (rslt == BMP3_SENSOR_OK) 129 | { 130 | rslt = validate_trimming_param(dev); 131 | } 132 | 133 | if (rslt == BMP3_SENSOR_OK) 134 | { 135 | /* Select the pressure and temperature sensor to be enabled */ 136 | dev->settings.press_en = BMP3_ENABLE; 137 | dev->settings.temp_en = BMP3_ENABLE; 138 | 139 | /* Select the output data rate and over sampling settings for pressure and temperature */ 140 | dev->settings.odr_filter.press_os = BMP3_NO_OVERSAMPLING; 141 | dev->settings.odr_filter.temp_os = BMP3_NO_OVERSAMPLING; 142 | dev->settings.odr_filter.odr = BMP3_ODR_25_HZ; 143 | 144 | /* Assign the settings which needs to be set in the sensor */ 145 | settings_sel = BMP3_SEL_PRESS_EN | BMP3_SEL_TEMP_EN | BMP3_SEL_PRESS_OS | BMP3_SEL_TEMP_OS | BMP3_SEL_ODR; 146 | rslt = bmp3_set_sensor_settings(settings_sel, dev); 147 | if (rslt == BMP3_SENSOR_OK) 148 | { 149 | dev->settings.op_mode = BMP3_MODE_NORMAL; 150 | rslt = bmp3_set_op_mode(dev); 151 | if (rslt == BMP3_SENSOR_OK) 152 | { 153 | dev->delay_us(40000, dev->intf_ptr); 154 | 155 | /* Sensor component selection */ 156 | sensor_comp = BMP3_PRESS | BMP3_TEMP; 157 | 158 | /* Temperature and Pressure data are read and stored in the bmp3_data instance */ 159 | rslt = bmp3_get_sensor_data(sensor_comp, &data, dev); 160 | } 161 | } 162 | } 163 | 164 | if (rslt == BMP3_SENSOR_OK) 165 | { 166 | rslt = analyze_sensor_data(&data); 167 | 168 | /* Set the power mode to sleep mode */ 169 | if (rslt == BMP3_SENSOR_OK) 170 | { 171 | dev->settings.op_mode = BMP3_MODE_SLEEP; 172 | rslt = bmp3_set_op_mode(dev); 173 | } 174 | } 175 | } 176 | 177 | return rslt; 178 | } 179 | 180 | /*! 181 | * @brief Function to analyze the sensor data 182 | */ 183 | static int8_t analyze_sensor_data(const struct bmp3_data *sens_data) 184 | { 185 | int8_t rslt = BMP3_SENSOR_OK; 186 | 187 | if ((sens_data->temperature < BMP3_MIN_TEMPERATURE) || (sens_data->temperature > BMP3_MAX_TEMPERATURE)) 188 | { 189 | rslt = BMP3_IMPLAUSIBLE_TEMPERATURE; 190 | } 191 | 192 | if (rslt == BMP3_SENSOR_OK) 193 | { 194 | if ((sens_data->pressure / 100 < BMP3_MIN_PRESSURE) || (sens_data->pressure / 100 > BMP3_MAX_PRESSURE)) 195 | { 196 | rslt = BMP3_IMPLAUSIBLE_PRESSURE; 197 | } 198 | } 199 | 200 | return rslt; 201 | } 202 | 203 | /* 204 | * @brief Function to verify the trimming parameters 205 | * */ 206 | static int8_t validate_trimming_param(struct bmp3_dev *dev) 207 | { 208 | int8_t rslt; 209 | uint8_t crc = 0xFF; 210 | uint8_t stored_crc; 211 | uint8_t trim_param[21]; 212 | uint8_t i; 213 | 214 | rslt = bmp3_get_regs(BMP3_REG_CALIB_DATA, trim_param, 21, dev); 215 | if (rslt == BMP3_SENSOR_OK) 216 | { 217 | for (i = 0; i < 21; i++) 218 | { 219 | crc = (uint8_t)cal_crc(crc, trim_param[i]); 220 | } 221 | 222 | crc = (crc ^ 0xFF); 223 | rslt = bmp3_get_regs(0x30, &stored_crc, 1, dev); 224 | if (stored_crc != crc) 225 | { 226 | rslt = BMP3_TRIMMING_DATA_OUT_OF_BOUND; 227 | } 228 | } 229 | 230 | return rslt; 231 | 232 | } 233 | 234 | /* 235 | * @brief function to calculate CRC for the trimming parameters 236 | * */ 237 | static int8_t cal_crc(uint8_t seed, uint8_t data) 238 | { 239 | int8_t poly = 0x1D; 240 | int8_t var2; 241 | uint8_t i; 242 | 243 | for (i = 0; i < 8; i++) 244 | { 245 | if ((seed & 0x80) ^ (data & 0x80)) 246 | { 247 | var2 = 1; 248 | } 249 | else 250 | { 251 | var2 = 0; 252 | } 253 | 254 | seed = (seed & 0x7F) << 1; 255 | data = (data & 0x7F) << 1; 256 | seed = seed ^ (uint8_t)(poly * var2); 257 | } 258 | 259 | return (int8_t)seed; 260 | } 261 | 262 | /** @}*/ 263 | -------------------------------------------------------------------------------- /self-test/bmp3_selftest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. 3 | * 4 | * BSD-3-Clause 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | * POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * @file bmp3_selftest.h 34 | * @date 2020-07-20 35 | * @version v2.0.1 36 | * 37 | */ 38 | 39 | #ifndef BMP38X_SELFTEST_H_ 40 | #define BMP38X_SELFTEST_H_ 41 | 42 | /*! CPP guard */ 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #include "bmp3.h" 48 | 49 | /*Error codes for self test */ 50 | 51 | #define BMP3_SENSOR_OK UINT8_C(0) 52 | #define BMP3_COMMUNICATION_ERROR_OR_WRONG_DEVICE UINT8_C(10) 53 | #define BMP3_TRIMMING_DATA_OUT_OF_BOUND UINT8_C(20) 54 | #define BMP3_TEMPERATURE_BOUND_WIRE_FAILURE_OR_MEMS_DEFECT UINT8_C(30) 55 | #define BMP3_PRESSURE_BOUND_WIRE_FAILURE_OR_MEMS_DEFECT UINT8_C(31) 56 | #define BMP3_IMPLAUSIBLE_TEMPERATURE UINT8_C(40) 57 | #define BMP3_IMPLAUSIBLE_PRESSURE UINT8_C(41) 58 | 59 | /** 60 | * \ingroup bmp3 61 | * \defgroup bmp3ApiSelftest Self test 62 | * @brief Perform self test of sensor 63 | */ 64 | 65 | /*! 66 | * \ingroup bmp3ApiSelftest 67 | * \page bmp3_api_bmp3_selftest_check bmp3_selftest_check 68 | * \code 69 | * int8_t bmp3_selftest_check(const struct bmp3_dev *dev); 70 | * \endcode 71 | * @details Self-test API for the BMP38X 72 | * 73 | * @param[in] dev Device structure containing relevant information on how 74 | * to communicate with the sensor 75 | * 76 | * @return Error code 77 | * @retval 0 Success 78 | * @retval > 0 Error 79 | */ 80 | int8_t bmp3_selftest_check(struct bmp3_dev *dev); 81 | 82 | /*! CPP guard */ 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* BMP38X_SELFTEST_H_ */ 88 | /** @}*/ 89 | --------------------------------------------------------------------------------