bmi160.h 24 KB

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