-
Notifications
You must be signed in to change notification settings - Fork 23
/
bmp3.h
552 lines (520 loc) · 19.4 KB
/
bmp3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
/**
* Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bmp3.h
* @date 2022-04-01
* @version v2.0.6
*
*/
/*!
* @defgroup bmp3 BMP3
*/
#ifndef _BMP3_H
#define _BMP3_H
/* Header includes */
#include "bmp3_defs.h"
/*! CPP guard */
#ifdef __cplusplus
extern "C" {
#endif
/**
* \ingroup bmp3
* \defgroup bmp3ApiInit Initialization
* @brief Initialize the sensor and device structure
*/
/*!
* \ingroup bmp3ApiInit
* \page bmp3_api_bmp3_init bmp3_init
* \code
* int8_t bmp3_init(struct bmp3_dev *dev);
* \endcode
* @details This API is the entry point.
* Performs the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id and calibration data of the sensor.
*
* @param[in,out] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_init(struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiSoftReset Soft reset
* @brief Perform soft reset of the sensor
*/
/*!
* \ingroup bmp3ApiSoftReset
* \page bmp3_api_bmp3_soft_reset bmp3_soft_reset
* \code
* int8_t bmp3_soft_reset(const struct bmp3_dev *dev);
* \endcode
* @details This API performs the soft reset of the sensor.
*
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_soft_reset(struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiSensorS Sensor settings
* @brief Get / Set sensor settings
*/
/*!
* \ingroup bmp3ApiSensorS
* \page bmp3_api_bmp3_set_sensor_settings bmp3_set_sensor_settings
* \code
* int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev);
* \endcode
* @details This API sets the power control(pressure enable and
* temperature enable), over sampling, odr and filter
* settings in the sensor.
*
* @param[in] desired_settings : Variable used to select the settings which
* are to be set in the sensor.
* @param[in] settings : Structure instance of bmp3_settings
* @param[in] dev : Structure instance of bmp3_dev.
*
* @note : Below are the macros to be used by the user for selecting the
* desired settings. User can do OR operation of these macros for configuring
* multiple settings.
*
*@verbatim
* ---------------------|----------------------------------------------
* desired_settings | Functionality
* ---------------------|----------------------------------------------
* BMP3_SEL_PRESS_EN | Enable/Disable pressure.
* BMP3_SEL_TEMP_EN | Enable/Disable temperature.
* BMP3_SEL_PRESS_OS | Set pressure oversampling.
* BMP3_SEL_TEMP_OS | Set temperature oversampling.
* BMP3_SEL_IIR_FILTER | Set IIR filter.
* BMP3_SEL_ODR | Set ODR.
* BMP3_SEL_OUTPUT_MODE | Set either open drain or push pull
* BMP3_SEL_LEVEL | Set interrupt pad to be active high or low
* BMP3_SEL_LATCH | Set interrupt pad to be latched or nonlatched.
* BMP3_SEL_DRDY_EN | Map/Unmap the drdy interrupt to interrupt pad.
* BMP3_SEL_I2C_WDT_EN | Enable/Disable I2C internal watch dog.
* BMP3_SEL_I2C_WDT | Set I2C watch dog timeout delay.
* ---------------------|----------------------------------------------
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_set_sensor_settings(uint32_t desired_settings, struct bmp3_settings *settings, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiSensorS
* \page bmp3_api_bmp3_get_sensor_settings bmp3_get_sensor_settings
* \code
* int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev);
* \endcode
* @details This API gets the power control(power mode, pressure enable and
* temperature enable), over sampling, odr, filter, interrupt control and
* advance settings from the sensor.
*
* @param[out] settings : Structure instance of bmp3_settings
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_sensor_settings(struct bmp3_settings *settings, struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiPowermode Power mode
* @brief Set / Get power mode of the sensor
*/
/*!
* \ingroup bmp3ApiPowermode
* \page bmp3_api_bmp3_set_op_mode bmp3_set_op_mode
* \code
* int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev);
* \endcode
* @details This API sets the power mode of the sensor.
*
* @param[in] settings : Structure instance of bmp3_settings
* @param[in] dev : Structure instance of bmp3_dev.
*
*@verbatim
* ----------------------|-------------------
* dev->settings.op_mode | Macros
* ----------------------|-------------------
* 0 | BMP3_MODE_SLEEP
* 1 | BMP3_MODE_FORCED
* 3 | BMP3_MODE_NORMAL
* ----------------------|-------------------
*@endverbatim
*
* @note : Before setting normal mode, valid odr and osr settings should be set
* in the sensor by using 'bmp3_set_sensor_settings' function.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_set_op_mode(struct bmp3_settings *settings, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiPowermode
* \page bmp3_api_bmp3_get_op_mode bmp3_get_op_mode
* \code
* int8_t bmp3_get_op_mode(uint8_t *op_mode, const struct bmp3_dev *dev);
* \endcode
* @details This API gets the power mode of the sensor.
*
* @param[in] dev : Structure instance of bmp3_dev.
* @param[out] op_mode : Pointer variable to store the op-mode.
*
*@verbatim
* ------------------------------------------
* op_mode | Macros
* ----------------------|-------------------
* 0 | BMP3_MODE_SLEEP
* 1 | BMP3_MODE_FORCED
* 3 | BMP3_MODE_NORMAL
* ------------------------------------------
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_op_mode(uint8_t *op_mode, struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiData Sensor Data
* @brief Get Sensor data
*/
/*!
* \ingroup bmp3ApiData
* \page bmp3_api_bmp3_get_sensor_data bmp3_get_sensor_data
* \code
* int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *data, struct bmp3_dev *dev);
* \endcode
* @details This API reads the pressure, temperature or both data from the
* sensor, compensates the data and store it in the bmp3_data structure
* instance passed by the user.
*
* @param[in] sensor_comp : Variable which selects which data to be read from
* the sensor.
*
*@verbatim
* sensor_comp | Macros
* ------------|-------------------
* 1 | BMP3_PRESS
* 2 | BMP3_TEMP
* 3 | BMP3_ALL
*@endverbatim
*
* @param[out] data : Structure instance of bmp3_data.
* @param[in] dev : Structure instance of bmp3_dev.
*
* @note : For fixed point the compensated temperature and pressure has a multiplication factor of 100.
* Units are degree celsius and Pascal respectively.
* ie. If temperature is 2426 then temperature is 24.26 deg C
* If press is 9528709, then pressure is 95287.09 Pascal.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *data, struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiRegs Registers
* @brief Read / Write data to the given register address
*/
/*!
* \ingroup bmp3ApiRegs
* \page bmp3_api_bmp3_set_regs bmp3_set_regs
* \code
* int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bmp3_dev *dev);
* \endcode
* @details This API writes the given data to the register address
* of the sensor.
*
* @param[in] reg_addr : Register address to where the data to be written.
* @param[in] reg_data : Pointer to data buffer which is to be written
* in the sensor.
* @param[in] len : No. of bytes of data to write.
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiRegs
* \page bmp3_api_bmp3_get_regs bmp3_get_regs
* \code
* int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t length, const struct bmp3_dev *dev);
* \endcode
* @details This API reads the data from the given register address of the sensor.
*
* @param[in] reg_addr : Register address from where the data to be read
* @param[out] reg_data : Pointer to data buffer to store the read data.
* @param[in] len : No. of bytes of data to be read.
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiFIFO FIFO
* @brief FIFO operations of the sensor
*/
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_set_fifo_settings bmp3_set_fifo_settings
* \code
* int8_t bmp3_set_fifo_settings(uint16_t desired_settings, struct bmp3_fifo_settings *fifo_settings,
* struct bmp3_dev *dev);
* \endcode
* @details This API sets the fifo_config_1(fifo_mode,
* fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en),
* fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en)
* settings in the sensor.
*
* @param[in] desired_settings : Variable used to select the FIFO settings which
* are to be set in the sensor.
*
* @note : Below are the macros to be used by the user for selecting the
* desired settings. User can do OR operation of these macros for configuring
* multiple settings.
*
*@verbatim
* --------------------------------|---------------------------------------------
* desired_settings | Functionality
* --------------------------------|---------------------------------------------
* BMP3_SEL_FIFO_MODE | Enable/Disable FIFO
* BMP3_SEL_FIFO_STOP_ON_FULL_EN | Set FIFO stop on full interrupt
* BMP3_SEL_FIFO_TIME_EN | Enable/Disable FIFO time
* BMP3_SEL_FIFO_PRESS_EN | Enable/Disable pressure
* BMP3_SEL_FIFO_TEMP_EN | Enable/Disable temperature
* BMP3_SEL_FIFO_DOWN_SAMPLING | Set FIFO downsampling
* BMP3_SEL_FIFO_FILTER_EN | Enable/Disable FIFO filter
* BMP3_SEL_FIFO_FWTM_EN | Enable/Disable FIFO watermark interrupt
* BMP3_SEL_FIFO_FFULL_EN | Enable/Disable FIFO full interrupt
* --------------------------------|---------------------------------------------
*@endverbatim
*
* @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_set_fifo_settings(uint16_t desired_settings,
const struct bmp3_fifo_settings *fifo_settings,
struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_get_fifo_settings bmp3_get_fifo_settings
* \code
* int8_t bmp3_get_fifo_settings(struct bmp3_fifo_settings *fifo_settings, struct bmp3_dev *dev);
* \endcode
* @details This API gets the fifo_config_1(fifo_mode,
* fifo_stop_on_full, fifo_time_en, fifo_press_en, fifo_temp_en),
* fifo_config_2(fifo_subsampling, data_select) and int_ctrl(fwtm_en, ffull_en)
* settings from the sensor.
*
* @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_fifo_settings(struct bmp3_fifo_settings *fifo_settings, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_get_fifo_data bmp3_get_fifo_data
* \code
* int8_t bmp3_get_fifo_data(struct bmp3_fifo_data *fifo,
* const struct bmp3_fifo_settings *fifo_settings,
* struct bmp3_dev *dev);
* \endcode
* @details This API gets the fifo data from the sensor.
*
* @param[in,out] fifo : Structure instance of bmp3_fifo_data
* @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
* @param[in] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_fifo_data(struct bmp3_fifo_data *fifo,
const struct bmp3_fifo_settings *fifo_settings,
struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_get_fifo_length bmp3_get_fifo_length
* \code
* int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev);
* \endcode
* @details This API gets the fifo length from the sensor.
*
* @param[out] fifo_length : Variable used to store the fifo length.
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_get_fifo_length(uint16_t *fifo_length, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_extract_fifo_data bmp3_extract_fifo_data
* \code
* int8_t bmp3_extract_fifo_data(struct bmp3_data *data, struct bmp3_fifo_data *fifo, struct bmp3_dev *dev);
* \endcode
* @details This API extracts the temperature and/or pressure data from the FIFO
* data which is already read from the fifo.
*
* @param[out] data : Array of bmp3_data structures where the temperature
* and pressure frames will be stored.
* @param[in] fifo : Structure instance of bmp3_fifo_data
* @param[in] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval <0 -> Error
*/
int8_t bmp3_extract_fifo_data(struct bmp3_data *data, struct bmp3_fifo_data *fifo, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_set_fifo_watermark bmp3_set_fifo_watermark
* \code
* int8_t bmp3_set_fifo_watermark(const struct bmp3_fifo_data *fifo,
* const struct bmp3_fifo_settings *fifo_settings,
* struct bmp3_dev *dev);
* \endcode
* @details This API sets the fifo watermark length according to the frames count
* set by the user in the device structure. Refer below for usage.
*
* @note: fifo.req_frames = 50;
*
* @param[in] fifo : Structure instance of bmp3_fifo_data
* @param[in] fifo_settings : Structure instance of bmp3_fifo_settings
* @param[in] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval <0 -> Error
*/
int8_t bmp3_set_fifo_watermark(const struct bmp3_fifo_data *fifo,
const struct bmp3_fifo_settings *fifo_settings,
struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_get_fifo_watermark bmp3_get_fifo_watermark
* \code
* int8_t bmp3_get_fifo_watermark(uint16_t *watermark_len, struct bmp3_dev *dev);
* \endcode
* @details This API gets the fifo watermark length according to the frames count
* set by the user in the device structure
*
* @param[in] watermark_len : Watermark level value
* @param[in] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval <0 -> Error
*/
int8_t bmp3_get_fifo_watermark(uint16_t *watermark_len, struct bmp3_dev *dev);
/*!
* \ingroup bmp3ApiFIFO
* \page bmp3_api_bmp3_fifo_flush bmp3_fifo_flush
* \code
* int8_t bmp3_fifo_flush(const struct bmp3_dev *dev);
* \endcode
* @details This API performs fifo flush
*
* @param[in] dev : Structure instance of bmp3_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval >0 -> Warning
* @retval <0 -> Error
*/
int8_t bmp3_fifo_flush(struct bmp3_dev *dev);
/**
* \ingroup bmp3
* \defgroup bmp3ApiStatus Sensor Status
* @brief Read status of the sensor
*/
/*!
* \ingroup bmp3ApiStatus
* \page bmp3_api_bmp3_get_status bmp3_get_status
* \code
* int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev);
* \endcode
* @details This API gets the command ready, data ready for pressure and
* temperature and interrupt (fifo watermark, fifo full, data ready) and
* error status from the sensor.
*
* @param[out] status : Structure instance of bmp3_status
* @param[in] dev : Structure instance of bmp3_dev
*
* @return Result of API execution status.
* @retval 0 -> Success
* @retval <0 -> Error
*/
int8_t bmp3_get_status(struct bmp3_status *status, struct bmp3_dev *dev);
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* _BMP3_H */