bmi160.h 26 KB

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