forked from boschsensortec/BMI08x_SensorAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi08x.h
477 lines (445 loc) · 17.6 KB
/
bmi08x.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
/**
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 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.
*
* Neither the name of the copyright holder nor the names of the
* 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 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
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
*
* @file bmi08x.h
* @date 24 Aug 2018
* @version 1.2.0
*
*/
/*! \file bmi08x.h
\brief Sensor Driver for BMI08x family of sensors */
#ifndef BMI08X_H_
#define BMI08X_H_
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************************/
/* header files */
#include "bmi08x_defs.h"
/*********************************************************************/
/* (extern) variable declarations */
/*********************************************************************/
/* function prototype declarations */
/*********************** BMI08x Accelerometer function prototypes ************************/
/*!
* @brief This API is the entry point for accel sensor.
* It performs the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id of accel sensor.
*
* @param[in,out] dev : Structure instance of bmi08x_dev.
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success /-ve value -> Error
*/
int8_t bmi08a_init(struct bmi08x_dev *dev);
/*!
* @brief This API is used to write the binary configuration in the sensor
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_write_config_file(const struct bmi08x_dev *dev);
/*!
* @brief This API writes the feature configuration to the accel sensor.
*
* @param[in] reg_addr : Address offset of the feature setting inside the feature conf region.
* @param[in] reg_data : Feature settings.
* @param[in] len : Number of 16 bit words to be written.
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_write_feature_config(uint8_t reg_addr, const uint16_t *reg_data, uint8_t len,
const struct bmi08x_dev *dev);
/*!
* @brief This API reads the data from the given register address of accel 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 bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bmi08x_dev *dev);
/*!
* @brief This API writes the given data to the register address
* of accel 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 bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bmi08x_dev *dev);
/*!
* @brief This API reads the error status from the accel sensor.
*
* Below table mention the types of error which can occur in the sensor
*@verbatim
*************************************************************************
* Error | Description
*************************|***********************************************
* | Fatal Error, chip is not in operational
* fatal | state (Boot-, power-system).
* | This flag will be reset only by
* | power-on-reset or soft reset.
*************************|***********************************************
* | Value Name Description
* error_code | 000 no_error no error
* | 001 accel_err error in
* | ACCEL_CONF
*************************************************************************
*@endverbatim
* @param[out] err_reg : Pointer to structure variable which stores the
* error status read from the sensor.
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_get_error_status(struct bmi08x_err_reg *err_reg, const struct bmi08x_dev *dev);
/*!
* @brief This API reads the status of the accel sensor.
*
* Below table lists the sensor status flags
*@verbatim
*************************************************************************
* Status | Description
***********************************|*************************************
* drdy_accel | Data ready for Accel.
*************************************************************************
*@endverbatim
*
* @param[out] status : Variable used to store the sensor status flags
* which is read from the sensor.
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
*/
int8_t bmi08a_get_status(uint8_t *status, const struct bmi08x_dev *dev);
/*!
* @brief This API resets the accel sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_soft_reset(const struct bmi08x_dev *dev);
/*!
* @brief This API reads the accel config values ie odr, band width and range from the sensor,
* store it in the bmi08x_dev structure instance
* passed by the user.
* @param[in,out] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
*/
int8_t bmi08a_get_meas_conf(struct bmi08x_dev *dev);
/*!
* @brief This API sets the Output data rate, range and bandwidth
* of accel sensor.
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @note : The user must select one among the following macros to
* select range value for BMI085 accel
* config | value
* -------------------------------|---------------------------
* BMI085_ACCEL_RANGE_2G | 0x00
* BMI085_ACCEL_RANGE_4G | 0x01
* BMI085_ACCEL_RANGE_8G | 0x02
* BMI085_ACCEL_RANGE_16G | 0x03
*
* @note : The user must select one among the following macros to
* select range value for BMI088 accel
* config | value
* -------------------------------|---------------------------
* BMI088_ACCEL_RANGE_3G | 0x00
* BMI088_ACCEL_RANGE_6G | 0x01
* BMI088_ACCEL_RANGE_12G | 0x02
* BMI088_ACCEL_RANGE_24G | 0x03
*
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_set_meas_conf(const struct bmi08x_dev *dev);
/*!
* @brief This API reads the accel power mode from the sensor,
* store it in the bmi08x_dev structure instance
* passed by the user.
* @param[in,out] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
*/
int8_t bmi08a_get_power_mode(struct bmi08x_dev *dev);
/*!
* @brief This API sets the power mode of the accel sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_set_power_mode(const struct bmi08x_dev *dev);
/*!
* @brief This API reads the accel data from the sensor,
* store it in the bmi08x_sensor_data structure instance
* passed by the user.
*
* @param[out] accel : Structure pointer to store accel data
* @param[in] dev : Structure instance of bmi08x_dev.
*
*
* @return Result of API execution status
* @retval zero -> Success /-ve value -> Error
*/
int8_t bmi08a_get_data(struct bmi08x_sensor_data *accel, const struct bmi08x_dev *dev);
/*!
* @brief This API configures the necessary accel interrupt
* based on the user settings in the bmi08x_int_cfg
* structure instance.
*
* @param[in] int_config : Structure instance of bmi08x_int_cfg.
* @param[in] dev : Structure instance of bmi08x_dev.
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_set_int_config(const struct bmi08x_accel_int_channel_cfg *int_config, const struct bmi08x_dev *dev);
/*!
* @brief This API reads the temperature of the sensor in degree Celcius.
*
* @param[in] dev : Structure instance of bmi08x_dev.
* @param[out] sensor_temp : Pointer to store sensor temperature in degree Celcius
*
* @note Temperature data output must be divided by a factor of 1000
*
* Consider sensor_temp = 19520 , Then the actual temperature is 19.520 degree Celsius
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_get_sensor_temperature(const struct bmi08x_dev *dev, int32_t *sensor_temp);
/*!
* @brief This API reads the sensor time of the accel sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
* @param[out] sensor_time : Pointer to store sensor time
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08a_get_sensor_time(const struct bmi08x_dev *dev, uint32_t *sensor_time);
/*!
* @brief This API checks whether the self test functionality of the sensor
* is working or not
*
* @param[in] dev : Structure instance of bmi08x_dev
*
* @return results of self test
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*
* Return value | Result of self test
* --------------------------------|---------------------------------
* BMI08X_OK | Self test success
* BMI08X_W_SELF_TEST_FAIL | self test fail
*/
int8_t bmi08a_perform_selftest(struct bmi08x_dev *dev);
/*********************** BMI088 Gyroscope function prototypes ****************************/
/*!
* @brief This API is the entry point for gyro sensor.
* It performs the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id of gyro sensor.
*
* @param[in,out] dev : Structure instance of bmi08x_dev.
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_init(struct bmi08x_dev *dev);
/*!
* @brief This API reads the data from the given register address of gyro 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 bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bmi08x_dev *dev);
/*!
* @brief This API writes the given data to the register address
* of gyro 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 bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bmi08x_dev *dev);
/*!
* @brief This API resets the gyro sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
*/
int8_t bmi08g_soft_reset(const struct bmi08x_dev *dev);
/*!
* @brief This API reads the gyro odr and range from the sensor,
* store it in the bmi08x_dev structure instance
* passed by the user.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
* @note : band width also updated, which is same as odr
* Refer user guide for detailed info.
*/
int8_t bmi08g_get_meas_conf(struct bmi08x_dev *dev);
/*!
* @brief This API sets the output data rate, range and bandwidth
* of gyro sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*
* @note : No need to give the band width parameter,
* odr will update the band width.
* Refer user guide for detailed info.
*/
int8_t bmi08g_set_meas_conf(const struct bmi08x_dev *dev);
/*!
* @brief This API gets the power mode of the gyro sensor and store it
* inside the instance of bmi08x_dev passed by the user.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_get_power_mode(struct bmi08x_dev *dev);
/*!
* @brief This API sets the power mode of the gyro sensor.
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_set_power_mode(const struct bmi08x_dev *dev);
/*!
* @brief This API reads the gyro data from the sensor,
* store it in the bmi08x_sensor_data structure instance
* passed by the user.
*
* @param[out] gyro : Structure pointer to store gyro data
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_get_data(struct bmi08x_sensor_data *gyro, const struct bmi08x_dev *dev);
/*!
* @brief This API configures the necessary gyro interrupt
* based on the user settings in the bmi08x_int_cfg
* structure instance.
*
* @param[in] int_config : Structure instance of bmi08x_int_cfg.
* @param[in] dev : Structure instance of bmi08x_dev.
* @note : Refer user guide for detailed info.
*
* @return Result of API execution status
* @retval zero -> Success / -ve value -> Error
*/
int8_t bmi08g_set_int_config(const struct bmi08x_gyro_int_channel_cfg *int_config, const struct bmi08x_dev *dev);
/*!
* @brief This API checks whether the self test functionality of the
* gyro sensor is working or not
*
* @param[in] dev : Structure instance of bmi08x_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*
* Return value | Result of self test
* --------------------------------|---------------------------------
* BMI08X_OK | Self test success
* BMI08X_W_SELF_TEST_FAIL | self test fail
*/
int8_t bmi08g_perform_selftest(const struct bmi08x_dev *dev);
#ifdef __cplusplus
}
#endif
#endif /* BMI08X_H_ */
/** @}*/