bmi160.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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 bmi160.h
  34. * @date 10/01/2020
  35. * @version 3.8.1
  36. *
  37. */
  38. /*!
  39. * @defgroup bmi160
  40. * @brief
  41. * @{*/
  42. #ifndef BMI160_H_
  43. #define BMI160_H_
  44. /*************************** C++ guard macro *****************************/
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. #include "bmi160_defs.h"
  49. #ifdef __KERNEL__
  50. #include <bmi160_math.h>
  51. #else
  52. #include <math.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55. #endif
  56. /*********************** User function prototypes ************************/
  57. /*!
  58. * @brief This API is the entry point for sensor.It performs
  59. * the selection of I2C/SPI read mechanism according to the
  60. * selected interface and reads the chip-id of bmi160 sensor.
  61. *
  62. * @param[in,out] dev : Structure instance of bmi160_dev
  63. * @note : Refer user guide for detailed info.
  64. *
  65. * @return Result of API execution status
  66. * @retval zero -> Success / -ve value -> Error
  67. */
  68. int8_t bmi160_init(struct bmi160_dev *dev);
  69. /*!
  70. * @brief This API reads the data from the given register address of sensor.
  71. *
  72. * @param[in] reg_addr : Register address from where the data to be read
  73. * @param[out] data : Pointer to data buffer to store the read data.
  74. * @param[in] len : No of bytes of data to be read.
  75. * @param[in] dev : Structure instance of bmi160_dev.
  76. *
  77. * @note For most of the registers auto address increment applies, with the
  78. * exception of a few special registers, which trap the address. For e.g.,
  79. * Register address - 0x24(BMI160_FIFO_DATA_ADDR)
  80. *
  81. * @return Result of API execution status
  82. * @retval zero -> Success / -ve value -> Error
  83. */
  84. int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  85. /*!
  86. * @brief This API writes the given data to the register address
  87. * of sensor.
  88. *
  89. * @param[in] reg_addr : Register address from where the data to be written.
  90. * @param[in] data : Pointer to data buffer which is to be written
  91. * in the sensor.
  92. * @param[in] len : No of bytes of data to write..
  93. * @param[in] dev : Structure instance of bmi160_dev.
  94. *
  95. * @return Result of API execution status
  96. * @retval zero -> Success / -ve value -> Error
  97. */
  98. int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  99. /*!
  100. * @brief This API resets and restarts the device.
  101. * All register values are overwritten with default parameters.
  102. *
  103. * @param[in] dev : Structure instance of bmi160_dev.
  104. *
  105. * @return Result of API execution status
  106. * @retval zero -> Success / -ve value -> Error.
  107. */
  108. int8_t bmi160_soft_reset(struct bmi160_dev *dev);
  109. /*!
  110. * @brief This API configures the power mode, range and bandwidth
  111. * of sensor.
  112. *
  113. * @param[in] dev : Structure instance of bmi160_dev.
  114. * @note : Refer user guide for detailed info.
  115. *
  116. * @return Result of API execution status
  117. * @retval zero -> Success / -ve value -> Error.
  118. */
  119. int8_t bmi160_set_sens_conf(struct bmi160_dev *dev);
  120. /*!
  121. * @brief This API sets the power mode of the sensor.
  122. *
  123. * @param[in] dev : Structure instance of bmi160_dev.
  124. *
  125. * @return Result of API execution status
  126. * @retval zero -> Success / -ve value -> Error.
  127. */
  128. int8_t bmi160_set_power_mode(struct bmi160_dev *dev);
  129. /*!
  130. * @brief This API gets the power mode of the sensor.
  131. *
  132. * @param[in] power_mode : Power mode of the sensor
  133. * @param[in] dev : Structure instance of bmi160_dev
  134. *
  135. * power_mode Macros possible values for pmu_status->aux_pmu_status :
  136. * - BMI160_AUX_PMU_SUSPEND
  137. * - BMI160_AUX_PMU_NORMAL
  138. * - BMI160_AUX_PMU_LOW_POWER
  139. *
  140. * power_mode Macros possible values for pmu_status->gyro_pmu_status :
  141. * - BMI160_GYRO_PMU_SUSPEND
  142. * - BMI160_GYRO_PMU_NORMAL
  143. * - BMI160_GYRO_PMU_FSU
  144. *
  145. * power_mode Macros possible values for pmu_status->accel_pmu_status :
  146. * - BMI160_ACCEL_PMU_SUSPEND
  147. * - BMI160_ACCEL_PMU_NORMAL
  148. * - BMI160_ACCEL_PMU_LOW_POWER
  149. *
  150. * @return Result of API execution status
  151. * @retval zero -> Success / -ve value -> Error.
  152. */
  153. int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct bmi160_dev *dev);
  154. /*!
  155. * @brief This API reads sensor data, stores it in
  156. * the bmi160_sensor_data structure pointer passed by the user.
  157. * The user can ask for accel data ,gyro data or both sensor
  158. * data using bmi160_select_sensor enum
  159. *
  160. * @param[in] select_sensor : enum to choose accel,gyro or both sensor data
  161. * @param[out] accel : Structure pointer to store accel data
  162. * @param[out] gyro : Structure pointer to store gyro data
  163. * @param[in] dev : Structure instance of bmi160_dev.
  164. * @note : Refer user guide for detailed info.
  165. *
  166. * @return Result of API execution status
  167. * @retval zero -> Success / -ve value -> Error
  168. */
  169. int8_t bmi160_get_sensor_data(uint8_t select_sensor,
  170. struct bmi160_sensor_data *accel,
  171. struct bmi160_sensor_data *gyro,
  172. const struct bmi160_dev *dev);
  173. /*!
  174. * @brief This API configures the necessary interrupt based on
  175. * the user settings in the bmi160_int_settg structure instance.
  176. *
  177. * @param[in] int_config : Structure instance of bmi160_int_settg.
  178. * @param[in] dev : Structure instance of bmi160_dev.
  179. * @note : Refer user guide for detailed info.
  180. *
  181. * @return Result of API execution status
  182. * @retval zero -> Success / -ve value -> Error
  183. */
  184. int8_t bmi160_set_int_config(struct bmi160_int_settg *int_config, struct bmi160_dev *dev);
  185. /*!
  186. * @brief This API enables the step counter feature.
  187. *
  188. * @param[in] step_cnt_enable : value to enable or disable
  189. * @param[in] dev : Structure instance of bmi160_dev.
  190. * @note : Refer user guide for detailed info.
  191. *
  192. * @return Result of API execution status
  193. * @retval zero -> Success / -ve value -> Error
  194. */
  195. int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev *dev);
  196. /*!
  197. * @brief This API reads the step counter value.
  198. *
  199. * @param[in] step_val : Pointer to store the step counter value.
  200. * @param[in] dev : Structure instance of bmi160_dev.
  201. * @note : Refer user guide for detailed info.
  202. *
  203. * @return Result of API execution status
  204. * @retval zero -> Success / -ve value -> Error
  205. */
  206. int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev);
  207. /*!
  208. * @brief This API reads the mention no of byte of data from the given
  209. * register address of auxiliary sensor.
  210. *
  211. * @param[in] reg_addr : Address of register to read.
  212. * @param[in] aux_data : Pointer to store the read data.
  213. * @param[in] len : No of bytes to read.
  214. * @param[in] dev : Structure instance of bmi160_dev.
  215. * @note : Refer user guide for detailed info.
  216. *
  217. * @return Result of API execution status
  218. * @retval zero -> Success / -ve value -> Error
  219. */
  220. int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  221. /*!
  222. * @brief This API writes the mention no of byte of data to the given
  223. * register address of auxiliary sensor.
  224. *
  225. * @param[in] reg_addr : Address of register to write.
  226. * @param[in] aux_data : Pointer to write data.
  227. * @param[in] len : No of bytes to write.
  228. * @param[in] dev : Structure instance of bmi160_dev.
  229. * @note : Refer user guide for detailed info.
  230. *
  231. * @return Result of API execution status
  232. * @retval zero -> Success / -ve value -> Error
  233. */
  234. int8_t bmi160_aux_write(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  235. /*!
  236. * @brief This API initialize the auxiliary sensor
  237. * in order to access it.
  238. *
  239. * @param[in] dev : Structure instance of bmi160_dev.
  240. * @note : Refer user guide for detailed info.
  241. *
  242. * @return Result of API execution status
  243. * @retval zero -> Success / -ve value -> Error
  244. */
  245. int8_t bmi160_aux_init(const struct bmi160_dev *dev);
  246. /*!
  247. * @brief This API is used to setup the auxiliary sensor of bmi160 in auto mode
  248. * Thus enabling the auto update of 8 bytes of data from auxiliary sensor
  249. * to BMI160 register address 0x04 to 0x0B
  250. *
  251. * @param[in] data_addr : Starting address of aux. sensor's data register
  252. * (BMI160 registers 0x04 to 0x0B will be updated
  253. * with 8 bytes of data from auxiliary sensor
  254. * starting from this register address.)
  255. * @param[in] dev : Structure instance of bmi160_dev.
  256. *
  257. * @note : Set the value of auxiliary polling rate by setting
  258. * dev->aux_cfg.aux_odr to the required value from the table
  259. * before calling this API
  260. *
  261. * dev->aux_cfg.aux_odr | Auxiliary ODR (Hz)
  262. * -----------------------|-----------------------
  263. * BMI160_AUX_ODR_0_78HZ | 25/32
  264. * BMI160_AUX_ODR_1_56HZ | 25/16
  265. * BMI160_AUX_ODR_3_12HZ | 25/8
  266. * BMI160_AUX_ODR_6_25HZ | 25/4
  267. * BMI160_AUX_ODR_12_5HZ | 25/2
  268. * BMI160_AUX_ODR_25HZ | 25
  269. * BMI160_AUX_ODR_50HZ | 50
  270. * BMI160_AUX_ODR_100HZ | 100
  271. * BMI160_AUX_ODR_200HZ | 200
  272. * BMI160_AUX_ODR_400HZ | 400
  273. * BMI160_AUX_ODR_800HZ | 800
  274. *
  275. * @note : Other values of dev->aux_cfg.aux_odr are reserved and not for use
  276. *
  277. * @return Result of API execution status
  278. * @retval zero -> Success / -ve value -> Error
  279. */
  280. int8_t bmi160_set_aux_auto_mode(uint8_t *data_addr, struct bmi160_dev *dev);
  281. /*!
  282. * @brief This API configures the 0x4C register and settings like
  283. * Auxiliary sensor manual enable/ disable and aux burst read length.
  284. *
  285. * @param[in] dev : Structure instance of bmi160_dev.
  286. *
  287. * @return Result of API execution status
  288. * @retval zero -> Success / -ve value -> Error
  289. */
  290. int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev);
  291. /*!
  292. * @brief This API is used to read the raw uncompensated auxiliary sensor
  293. * data of 8 bytes from BMI160 register address 0x04 to 0x0B
  294. *
  295. * @param[in] aux_data : Pointer to user array of length 8 bytes
  296. * Ensure that the aux_data array is of
  297. * length 8 bytes
  298. * @param[in] dev : Structure instance of bmi160_dev
  299. *
  300. * @return Result of API execution status
  301. * @retval zero -> Success / -ve value -> Error
  302. */
  303. int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev *dev);
  304. /*!
  305. * @brief This is used to perform self test of accel/gyro of the BMI160 sensor
  306. *
  307. * @param[in] select_sensor : enum to choose accel or gyro for self test
  308. * @param[in] dev : Structure instance of bmi160_dev
  309. *
  310. * @note self test can be performed either for accel/gyro at any instant.
  311. *
  312. * value of select_sensor | Inference
  313. *----------------------------------|--------------------------------
  314. * BMI160_ACCEL_ONLY | Accel self test enabled
  315. * BMI160_GYRO_ONLY | Gyro self test enabled
  316. * BMI160_BOTH_ACCEL_AND_GYRO | NOT TO BE USED
  317. *
  318. * @note The return value of this API gives us the result of self test.
  319. *
  320. * @note Performing self test does soft reset of the sensor, User can
  321. * set the desired settings after performing the self test.
  322. *
  323. * @return Result of API execution status
  324. * @retval zero -> Success / -ve value -> Error / +ve value -> Self-test fail
  325. *
  326. * Return value | Result of self test
  327. * --------------------------------|---------------------------------
  328. * BMI160_OK | Self test success
  329. * BMI160_W_GYRO_SELF_TEST_FAIL | Gyro self test fail
  330. * BMI160_W_ACCEl_SELF_TEST_FAIL | Accel self test fail
  331. */
  332. int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev);
  333. /*!
  334. * @brief This API reads data from the fifo buffer.
  335. *
  336. * @note User has to allocate the FIFO buffer along with
  337. * corresponding fifo length from his side before calling this API
  338. * as mentioned in the readme.md
  339. *
  340. * @note User must specify the number of bytes to read from the FIFO in
  341. * dev->fifo->length , It will be updated by the number of bytes actually
  342. * read from FIFO after calling this API
  343. *
  344. * @param[in] dev : Structure instance of bmi160_dev.
  345. *
  346. * @return Result of API execution status
  347. * @retval zero -> Success / -ve value -> Error
  348. *
  349. */
  350. int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev);
  351. /*!
  352. * @brief This API writes fifo_flush command to command register.This
  353. * action clears all data in the Fifo without changing fifo configuration
  354. * settings.
  355. *
  356. * @param[in] dev : Structure instance of bmi160_dev
  357. *
  358. * @return Result of API execution status
  359. * @retval 0 -> Success
  360. * @retval Any non zero value -> Fail
  361. *
  362. */
  363. int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev);
  364. /*! @brief This API sets the FIFO configuration in the sensor.
  365. *
  366. * @param[in] config : variable used to specify the FIFO
  367. * configurations which are to be enabled or disabled in the sensor.
  368. *
  369. * @note : User can set either set one or more or all FIFO configurations
  370. * by ORing the below mentioned macros.
  371. * config | Value
  372. * ------------------------|---------------------------
  373. * BMI160_FIFO_TIME | 0x02
  374. * BMI160_FIFO_TAG_INT2 | 0x04
  375. * BMI160_FIFO_TAG_INT1 | 0x08
  376. * BMI160_FIFO_HEADER | 0x10
  377. * BMI160_FIFO_AUX | 0x20
  378. * BMI160_FIFO_ACCEL | 0x40
  379. * BMI160_FIFO_GYRO | 0x80
  380. *
  381. * @param[in] enable : Parameter used to enable or disable the above
  382. * FIFO configuration
  383. * @param[in] dev : Structure instance of bmi160_dev.
  384. *
  385. * @return status of bus communication result
  386. * @retval 0 -> Success
  387. * @retval Any non zero value -> Fail
  388. *
  389. */
  390. int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev const *dev);
  391. /*! @brief This API is used to configure the down sampling ratios of
  392. * the accel and gyro data for FIFO.Also, it configures filtered or
  393. * pre-filtered data for the fifo for accel and gyro.
  394. *
  395. * @param[in] fifo_down : variable used to specify the FIFO down
  396. * configurations which are to be enabled or disabled in the sensor.
  397. *
  398. * @note The user must select one among the following macros to
  399. * select down-sampling ratio for accel
  400. * config | Value
  401. * -------------------------------------|---------------------------
  402. * BMI160_ACCEL_FIFO_DOWN_ZERO | 0x00
  403. * BMI160_ACCEL_FIFO_DOWN_ONE | 0x10
  404. * BMI160_ACCEL_FIFO_DOWN_TWO | 0x20
  405. * BMI160_ACCEL_FIFO_DOWN_THREE | 0x30
  406. * BMI160_ACCEL_FIFO_DOWN_FOUR | 0x40
  407. * BMI160_ACCEL_FIFO_DOWN_FIVE | 0x50
  408. * BMI160_ACCEL_FIFO_DOWN_SIX | 0x60
  409. * BMI160_ACCEL_FIFO_DOWN_SEVEN | 0x70
  410. *
  411. * @note The user must select one among the following macros to
  412. * select down-sampling ratio for gyro
  413. *
  414. * config | Value
  415. * -------------------------------------|---------------------------
  416. * BMI160_GYRO_FIFO_DOWN_ZERO | 0x00
  417. * BMI160_GYRO_FIFO_DOWN_ONE | 0x01
  418. * BMI160_GYRO_FIFO_DOWN_TWO | 0x02
  419. * BMI160_GYRO_FIFO_DOWN_THREE | 0x03
  420. * BMI160_GYRO_FIFO_DOWN_FOUR | 0x04
  421. * BMI160_GYRO_FIFO_DOWN_FIVE | 0x05
  422. * BMI160_GYRO_FIFO_DOWN_SIX | 0x06
  423. * BMI160_GYRO_FIFO_DOWN_SEVEN | 0x07
  424. *
  425. * @note The user can enable filtered accel data by the following macro
  426. * config | Value
  427. * -------------------------------------|---------------------------
  428. * BMI160_ACCEL_FIFO_FILT_EN | 0x80
  429. *
  430. * @note The user can enable filtered gyro data by the following macro
  431. * config | Value
  432. * -------------------------------------|---------------------------
  433. * BMI160_GYRO_FIFO_FILT_EN | 0x08
  434. *
  435. * @note : By ORing the above mentioned macros, the user can select
  436. * the required FIFO down config settings
  437. *
  438. * @param[in] dev : Structure instance of bmi160_dev.
  439. *
  440. * @return status of bus communication result
  441. * @retval 0 -> Success
  442. * @retval Any non zero value -> Fail
  443. *
  444. */
  445. int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev);
  446. /*!
  447. * @brief This API sets the FIFO watermark level in the sensor.
  448. *
  449. * @note The FIFO watermark is issued when the FIFO fill level is
  450. * equal or above the watermark level and units of watermark is 4 bytes.
  451. *
  452. * @param[in] fifo_wm : Variable used to set the FIFO water mark level
  453. * @param[in] dev : Structure instance of bmi160_dev
  454. *
  455. * @return Result of API execution status
  456. * @retval 0 -> Success
  457. * @retval Any non zero value -> Fail
  458. *
  459. */
  460. int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev);
  461. /*!
  462. * @brief This API parses and extracts the accelerometer frames from
  463. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  464. * the "accel_data" structure instance.
  465. *
  466. * @note The bmi160_extract_accel API should be called only after
  467. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  468. *
  469. * @param[out] accel_data : Structure instance of bmi160_sensor_data
  470. * where the accelerometer data in FIFO is stored.
  471. * @param[in,out] accel_length : Number of valid accelerometer frames
  472. * (x,y,z axes data) read out from fifo.
  473. * @param[in] dev : Structure instance of bmi160_dev.
  474. *
  475. * @note accel_length is updated with the number of valid accelerometer
  476. * frames extracted from fifo (1 accel frame = 6 bytes) at the end of
  477. * execution of this API.
  478. *
  479. * @return Result of API execution status
  480. * @retval 0 -> Success
  481. * @retval Any non zero value -> Fail
  482. *
  483. */
  484. int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, struct bmi160_dev const *dev);
  485. /*!
  486. * @brief This API parses and extracts the gyro frames from
  487. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  488. * the "gyro_data" structure instance.
  489. *
  490. * @note The bmi160_extract_gyro API should be called only after
  491. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  492. *
  493. * @param[out] gyro_data : Structure instance of bmi160_sensor_data
  494. * where the gyro data in FIFO is stored.
  495. * @param[in,out] gyro_length : Number of valid gyro frames
  496. * (x,y,z axes data) read out from fifo.
  497. * @param[in] dev : Structure instance of bmi160_dev.
  498. *
  499. * @note gyro_length is updated with the number of valid gyro
  500. * frames extracted from fifo (1 gyro frame = 6 bytes) at the end of
  501. * execution of this API.
  502. *
  503. * @return Result of API execution status
  504. * @retval 0 -> Success
  505. * @retval Any non zero value -> Fail
  506. *
  507. */
  508. int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev);
  509. /*!
  510. * @brief This API parses and extracts the aux frames from
  511. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  512. * the bmi160_aux_data structure instance.
  513. *
  514. * @note The bmi160_extract_aux API should be called only after
  515. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  516. *
  517. * @param[out] aux_data : Structure instance of bmi160_aux_data
  518. * where the aux data in FIFO is stored.
  519. * @param[in,out] aux_len : Number of valid aux frames (8bytes)
  520. * read out from FIFO.
  521. * @param[in] dev : Structure instance of bmi160_dev.
  522. *
  523. * @note aux_len is updated with the number of valid aux
  524. * frames extracted from fifo (1 aux frame = 8 bytes) at the end of
  525. * execution of this API.
  526. *
  527. * @return Result of API execution status
  528. * @retval 0 -> Success
  529. * @retval Any non zero value -> Fail
  530. *
  531. */
  532. int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev);
  533. /*!
  534. * @brief This API starts the FOC of accel and gyro
  535. *
  536. * @note FOC should not be used in low-power mode of sensor
  537. *
  538. * @note Accel FOC targets values of +1g , 0g , -1g
  539. * Gyro FOC always targets value of 0 dps
  540. *
  541. * @param[in] foc_conf : Structure instance of bmi160_foc_conf which
  542. * has the FOC configuration
  543. * @param[in,out] offset : Structure instance to store Offset
  544. * values read from sensor
  545. * @param[in] dev : Structure instance of bmi160_dev.
  546. *
  547. * @note Pre-requisites for triggering FOC in accel , Set the following,
  548. * Enable the acc_off_en
  549. * Ex : foc_conf.acc_off_en = BMI160_ENABLE;
  550. *
  551. * Set the desired target values of FOC to each axes (x,y,z) by using the
  552. * following macros
  553. * - BMI160_FOC_ACCEL_DISABLED
  554. * - BMI160_FOC_ACCEL_POSITIVE_G
  555. * - BMI160_FOC_ACCEL_NEGATIVE_G
  556. * - BMI160_FOC_ACCEL_0G
  557. *
  558. * Ex : foc_conf.foc_acc_x = BMI160_FOC_ACCEL_0G;
  559. * foc_conf.foc_acc_y = BMI160_FOC_ACCEL_0G;
  560. * foc_conf.foc_acc_z = BMI160_FOC_ACCEL_POSITIVE_G;
  561. *
  562. * @note Pre-requisites for triggering FOC in gyro ,
  563. * Set the following parameters,
  564. *
  565. * Ex : foc_conf.foc_gyr_en = BMI160_ENABLE;
  566. * foc_conf.gyro_off_en = BMI160_ENABLE;
  567. *
  568. * @return Result of API execution status
  569. * @retval 0 -> Success
  570. * @retval Any non zero value -> Fail
  571. */
  572. int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf,
  573. struct bmi160_offsets *offset,
  574. struct bmi160_dev const *dev);
  575. /*!
  576. * @brief This API reads and stores the offset values of accel and gyro
  577. *
  578. * @param[in,out] offset : Structure instance of bmi160_offsets in which
  579. * the offset values are read and stored
  580. * @param[in] dev : Structure instance of bmi160_dev.
  581. *
  582. * @return Result of API execution status
  583. * @retval 0 -> Success
  584. * @retval Any non zero value -> Fail
  585. */
  586. int8_t bmi160_get_offsets(struct bmi160_offsets *offset, const struct bmi160_dev *dev);
  587. /*!
  588. * @brief This API writes the offset values of accel and gyro to
  589. * the sensor but these values will be reset on POR or soft reset.
  590. *
  591. * @param[in] foc_conf : Structure instance of bmi160_foc_conf which
  592. * has the FOC configuration
  593. * @param[in] offset : Structure instance in which user updates offset
  594. * values which are to be written in the sensor
  595. * @param[in] dev : Structure instance of bmi160_dev.
  596. *
  597. * @note Offsets can be set by user like offset->off_acc_x = 10;
  598. * where 1LSB = 3.9mg and for gyro 1LSB = 0.061degrees/second
  599. *
  600. * @note BMI160 offset values for xyz axes of accel should be within range of
  601. * BMI160_ACCEL_MIN_OFFSET (-128) to BMI160_ACCEL_MAX_OFFSET (127)
  602. *
  603. * @note BMI160 offset values for xyz axes of gyro should be within range of
  604. * BMI160_GYRO_MIN_OFFSET (-512) to BMI160_GYRO_MAX_OFFSET (511)
  605. *
  606. * @return Result of API execution status
  607. * @retval 0 -> Success
  608. * @retval Any non zero value -> Fail
  609. */
  610. int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf,
  611. const struct bmi160_offsets *offset,
  612. struct bmi160_dev const *dev);
  613. /*!
  614. * @brief This API writes the image registers values to NVM which is
  615. * stored even after POR or soft reset
  616. *
  617. * @param[in] dev : Structure instance of bmi160_dev.
  618. *
  619. * @return Result of API execution status
  620. * @retval 0 -> Success
  621. * @retval Any non zero value -> Fail
  622. */
  623. int8_t bmi160_update_nvm(struct bmi160_dev const *dev);
  624. /*!
  625. * @brief This API gets the interrupt status from the sensor.
  626. *
  627. * @param[in] int_status_sel : Enum variable to select either individual or all the
  628. * interrupt status bits.
  629. * @param[in] int_status : pointer variable to get the interrupt status
  630. * from the sensor.
  631. * param[in] dev : Structure instance of bmi160_dev.
  632. *
  633. * @return Result of API execution status
  634. * @retval 0 -> Success
  635. * @retval Any non zero value -> Fail
  636. */
  637. int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel,
  638. union bmi160_int_status *int_status,
  639. struct bmi160_dev const *dev);
  640. /*************************** C++ guard macro *****************************/
  641. #ifdef __cplusplus
  642. }
  643. #endif
  644. #endif /* BMI160_H_ */
  645. /** @}*/