bmi160.h 25 KB

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