bmi160.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. /**
  2. * Copyright (c) 2021 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 2021-10-05
  35. * @version v3.9.2
  36. *
  37. */
  38. /*!
  39. * @defgroup bmi160 BMI160
  40. */
  41. #ifndef BMI160_H_
  42. #define BMI160_H_
  43. /*************************** C++ guard macro *****************************/
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #include "bmi160_defs.h"
  48. #ifdef __KERNEL__
  49. #include <bmi160_math.h>
  50. #else
  51. #include <math.h>
  52. #include <string.h>
  53. #include <stdlib.h>
  54. #endif
  55. /*********************** User function prototypes ************************/
  56. /**
  57. * \ingroup bmi160
  58. * \defgroup bmi160ApiInit Initialization
  59. * @brief Initialize the sensor and device structure
  60. */
  61. /*!
  62. * \ingroup bmi160ApiInit
  63. * \page bmi160_api_bmi160_init bmi160_init
  64. * \code
  65. * int8_t bmi160_init(struct bmi160_dev *dev);
  66. * \endcode
  67. * @details This API is the entry point for sensor.It performs
  68. * the selection of I2C/SPI read mechanism according to the
  69. * selected interface and reads the chip-id of bmi160 sensor.
  70. *
  71. * @param[in,out] dev : Structure instance of bmi160_dev
  72. * @note : Refer user guide for detailed info.
  73. *
  74. * @return Result of API execution status
  75. * @retval Zero Success
  76. * @retval Negative Error
  77. */
  78. int8_t bmi160_init(struct bmi160_dev *dev);
  79. /**
  80. * \ingroup bmi160
  81. * \defgroup bmi160ApiRegs Registers
  82. * @brief Read data from the given register address of sensor
  83. */
  84. /*!
  85. * \ingroup bmi160ApiRegs
  86. * \page bmi160_api_bmi160_get_regs bmi160_get_regs
  87. * \code
  88. * int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  89. * \endcode
  90. * @details This API reads the data from the given register address of sensor.
  91. *
  92. * @param[in] reg_addr : Register address from where the data to be read
  93. * @param[out] data : Pointer to data buffer to store the read data.
  94. * @param[in] len : No of bytes of data to be read.
  95. * @param[in] dev : Structure instance of bmi160_dev.
  96. *
  97. * @note For most of the registers auto address increment applies, with the
  98. * exception of a few special registers, which trap the address. For e.g.,
  99. * Register address - 0x24(BMI160_FIFO_DATA_ADDR)
  100. *
  101. * @return Result of API execution status
  102. * @retval Zero Success
  103. * @retval Negative Error
  104. */
  105. int8_t bmi160_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  106. /*!
  107. * \ingroup bmi160ApiRegs
  108. * \page bmi160_api_bmi160_set_regs bmi160_set_regs
  109. * \code
  110. * int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  111. * \endcode
  112. * @details This API writes the given data to the register address
  113. * of sensor.
  114. *
  115. * @param[in] reg_addr : Register address from where the data to be written.
  116. * @param[in] data : Pointer to data buffer which is to be written
  117. * in the sensor.
  118. * @param[in] len : No of bytes of data to write..
  119. * @param[in] dev : Structure instance of bmi160_dev.
  120. *
  121. * @return Result of API execution status
  122. * @retval Zero Success
  123. * @retval Negative Error
  124. */
  125. int8_t bmi160_set_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi160_dev *dev);
  126. /**
  127. * \ingroup bmi160
  128. * \defgroup bmi160ApiSoftreset Soft reset
  129. * @brief Perform soft reset of the sensor
  130. */
  131. /*!
  132. * \ingroup bmi160ApiSoftreset
  133. * \page bmi160_api_bmi160_soft_reset bmi160_soft_reset
  134. * \code
  135. * int8_t bmi160_soft_reset(struct bmi160_dev *dev);
  136. * \endcode
  137. * @details This API resets and restarts the device.
  138. * All register values are overwritten with default parameters.
  139. *
  140. * @param[in] dev : Structure instance of bmi160_dev.
  141. *
  142. * @return Result of API execution status
  143. * @retval Zero Success
  144. * @retval Negative Error
  145. */
  146. int8_t bmi160_soft_reset(struct bmi160_dev *dev);
  147. /**
  148. * \ingroup bmi160
  149. * \defgroup bmi160ApiConfig Configuration
  150. * @brief Configuration of the sensor
  151. */
  152. /*!
  153. * \ingroup bmi160ApiConfig
  154. * \page bmi160_api_bmi160_set_sens_conf bmi160_set_sens_conf
  155. * \code
  156. * int8_t bmi160_set_sens_conf(struct bmi160_dev *dev);
  157. * \endcode
  158. * @details This API configures the power mode, range and bandwidth
  159. * of sensor.
  160. *
  161. * @param[in] dev : Structure instance of bmi160_dev.
  162. * @note : Refer user guide for detailed info.
  163. *
  164. * @return Result of API execution status
  165. * @retval Zero Success
  166. * @retval Negative Error
  167. */
  168. int8_t bmi160_set_sens_conf(struct bmi160_dev *dev);
  169. /*!
  170. * \ingroup bmi160ApiConfig
  171. * \page bmi160_api_bmi160_get_sens_conf bmi160_get_sens_conf
  172. * \code
  173. * int8_t bmi160_get_sens_conf(struct bmi160_dev *dev);
  174. * \endcode
  175. * @details This API gets accel and gyro configurations.
  176. *
  177. * @param[out] dev : Structure instance of bmi160_dev.
  178. * @note : Refer user guide for detailed info.
  179. *
  180. * @return Result of API execution status
  181. * @retval Zero Success
  182. * @retval Negative Error
  183. */
  184. int8_t bmi160_get_sens_conf(struct bmi160_dev *dev);
  185. /**
  186. * \ingroup bmi160
  187. * \defgroup bmi160ApiPowermode Power mode
  188. * @brief Set / Get power mode of the sensor
  189. */
  190. /*!
  191. * \ingroup bmi160ApiPowermode
  192. * \page bmi160_api_bmi160_set_power_mode bmi160_set_power_mode
  193. * \code
  194. * int8_t bmi160_set_power_mode(struct bmi160_dev *dev);
  195. * \endcode
  196. * @details This API sets the power mode of the sensor.
  197. *
  198. * @param[in] dev : Structure instance of bmi160_dev.
  199. *
  200. * @return Result of API execution status
  201. * @retval Zero Success
  202. * @retval Negative Error
  203. */
  204. int8_t bmi160_set_power_mode(struct bmi160_dev *dev);
  205. /*!
  206. * \ingroup bmi160ApiPowermode
  207. * \page bmi160_api_bmi160_get_power_mode bmi160_get_power_mode
  208. * \code
  209. * int8_t bmi160_get_power_mode(struct bmi160_dev *dev);
  210. * \endcode
  211. * @details This API gets the power mode of the sensor.
  212. *
  213. * @param[in] dev : Structure instance of bmi160_dev
  214. *
  215. * @return Result of API execution status
  216. * @retval Zero Success
  217. * @retval Negative Error
  218. */
  219. int8_t bmi160_get_power_mode(struct bmi160_dev *dev);
  220. /**
  221. * \ingroup bmi160
  222. * \defgroup bmi160ApiData Sensor Data
  223. * @brief Read sensor data
  224. */
  225. /*!
  226. * \ingroup bmi160ApiData
  227. * \page bmi160_api_bmi160_get_sensor_data bmi160_get_sensor_data
  228. * \code
  229. * int8_t bmi160_get_sensor_data(uint8_t select_sensor,
  230. * struct bmi160_sensor_data *accel,
  231. * struct bmi160_sensor_data *gyro,
  232. * const struct bmi160_dev *dev);
  233. *
  234. * \endcode
  235. * @details This API reads sensor data, stores it in
  236. * the bmi160_sensor_data structure pointer passed by the user.
  237. * The user can ask for accel data ,gyro data or both sensor
  238. * data using bmi160_select_sensor enum
  239. *
  240. * @param[in] select_sensor : enum to choose accel,gyro or both sensor data
  241. * @param[out] accel : Structure pointer to store accel data
  242. * @param[out] gyro : Structure pointer to store gyro data
  243. * @param[in] dev : Structure instance of bmi160_dev.
  244. * @note : Refer user guide for detailed info.
  245. *
  246. * @return Result of API execution status
  247. * @retval Zero Success
  248. * @retval Negative Error
  249. */
  250. int8_t bmi160_get_sensor_data(uint8_t select_sensor,
  251. struct bmi160_sensor_data *accel,
  252. struct bmi160_sensor_data *gyro,
  253. const struct bmi160_dev *dev);
  254. /**
  255. * \ingroup bmi160
  256. * \defgroup bmi160ApiInt Interrupt configuration
  257. * @brief Set interrupt configuration of the sensor
  258. */
  259. /*!
  260. * \ingroup bmi160ApiInt
  261. * \page bmi160_api_bmi160_set_int_config bmi160_set_int_config
  262. * \code
  263. * int8_t bmi160_set_int_config(struct bmi160_int_settg *int_config, struct bmi160_dev *dev);
  264. * \endcode
  265. * @details This API configures the necessary interrupt based on
  266. * the user settings in the bmi160_int_settg structure instance.
  267. *
  268. * @param[in] int_config : Structure instance of bmi160_int_settg.
  269. * @param[in] dev : Structure instance of bmi160_dev.
  270. * @note : Refer user guide for detailed info.
  271. *
  272. * @return Result of API execution status
  273. * @retval Zero Success
  274. * @retval Negative Error
  275. */
  276. int8_t bmi160_set_int_config(struct bmi160_int_settg *int_config, struct bmi160_dev *dev);
  277. /**
  278. * \ingroup bmi160
  279. * \defgroup bmi160ApiStepC Step counter
  280. * @brief Step counter operations
  281. */
  282. /*!
  283. * \ingroup bmi160ApiStepC
  284. * \page bmi160_api_bmi160_set_step_counter bmi160_set_step_counter
  285. * \code
  286. * int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev *dev);
  287. * \endcode
  288. * @details This API enables the step counter feature.
  289. *
  290. * @param[in] step_cnt_enable : value to enable or disable
  291. * @param[in] dev : Structure instance of bmi160_dev.
  292. * @note : Refer user guide for detailed info.
  293. *
  294. * @return Result of API execution status
  295. * @retval Zero Success
  296. * @retval Negative Error
  297. */
  298. int8_t bmi160_set_step_counter(uint8_t step_cnt_enable, const struct bmi160_dev *dev);
  299. /*!
  300. * \ingroup bmi160ApiStepC
  301. * \page bmi160_api_bmi160_read_step_counter bmi160_read_step_counter
  302. * \code
  303. * int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev);
  304. * \endcode
  305. * @details This API reads the step counter value.
  306. *
  307. * @param[in] step_val : Pointer to store the step counter value.
  308. * @param[in] dev : Structure instance of bmi160_dev.
  309. * @note : Refer user guide for detailed info.
  310. *
  311. * @return Result of API execution status
  312. * @retval Zero Success
  313. * @retval Negative Error
  314. */
  315. int8_t bmi160_read_step_counter(uint16_t *step_val, const struct bmi160_dev *dev);
  316. /**
  317. * \ingroup bmi160
  318. * \defgroup bmi160ApiAux Auxiliary sensor
  319. * @brief Auxiliary sensor operations
  320. */
  321. /*!
  322. * \ingroup bmi160ApiAux
  323. * \page bmi160_api_bmi160_aux_read bmi160_aux_read
  324. * \code
  325. * int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  326. * \endcode
  327. * @details This API reads the mention no of byte of data from the given
  328. * register address of auxiliary sensor.
  329. *
  330. * @param[in] reg_addr : Address of register to read.
  331. * @param[in] aux_data : Pointer to store the read data.
  332. * @param[in] len : No of bytes to read.
  333. * @param[in] dev : Structure instance of bmi160_dev.
  334. * @note : Refer user guide for detailed info.
  335. *
  336. * @return Result of API execution status
  337. * @retval Zero Success
  338. * @retval Negative Error
  339. */
  340. int8_t bmi160_aux_read(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  341. /*!
  342. * \ingroup bmi160ApiAux
  343. * \page bmi160_api_bmi160_aux_write bmi160_aux_write
  344. * \code
  345. * int8_t bmi160_aux_write(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  346. * \endcode
  347. * @details This API writes the mention no of byte of data to the given
  348. * register address of auxiliary sensor.
  349. *
  350. * @param[in] reg_addr : Address of register to write.
  351. * @param[in] aux_data : Pointer to write data.
  352. * @param[in] len : No of bytes to write.
  353. * @param[in] dev : Structure instance of bmi160_dev.
  354. * @note : Refer user guide for detailed info.
  355. *
  356. * @return Result of API execution status
  357. * @retval Zero Success
  358. * @retval Negative Error
  359. */
  360. int8_t bmi160_aux_write(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, const struct bmi160_dev *dev);
  361. /*!
  362. * \ingroup bmi160ApiAux
  363. * \page bmi160_api_bmi160_aux_init bmi160_aux_init
  364. * \code
  365. * int8_t bmi160_aux_init(const struct bmi160_dev *dev);
  366. * \endcode
  367. * @details This API initialize the auxiliary sensor
  368. * in order to access it.
  369. *
  370. * @param[in] dev : Structure instance of bmi160_dev.
  371. * @note : Refer user guide for detailed info.
  372. *
  373. * @return Result of API execution status
  374. * @retval Zero Success
  375. * @retval Negative Error
  376. */
  377. int8_t bmi160_aux_init(const struct bmi160_dev *dev);
  378. /*!
  379. * \ingroup bmi160ApiAux
  380. * \page bmi160_api_bmi160_set_aux_auto_mode bmi160_set_aux_auto_mode
  381. * \code
  382. * int8_t bmi160_set_aux_auto_mode(uint8_t *data_addr, struct bmi160_dev *dev);
  383. * \endcode
  384. * @details This API is used to setup the auxiliary sensor of bmi160 in auto mode
  385. * Thus enabling the auto update of 8 bytes of data from auxiliary sensor
  386. * to BMI160 register address 0x04 to 0x0B
  387. *
  388. * @param[in] data_addr : Starting address of aux. sensor's data register
  389. * (BMI160 registers 0x04 to 0x0B will be updated
  390. * with 8 bytes of data from auxiliary sensor
  391. * starting from this register address.)
  392. * @param[in] dev : Structure instance of bmi160_dev.
  393. *
  394. * @note : Set the value of auxiliary polling rate by setting
  395. * dev->aux_cfg.aux_odr to the required value from the table
  396. * before calling this API
  397. *
  398. *@verbatim
  399. * dev->aux_cfg.aux_odr | Auxiliary ODR (Hz)
  400. * -----------------------|-----------------------
  401. * BMI160_AUX_ODR_0_78HZ | 25/32
  402. * BMI160_AUX_ODR_1_56HZ | 25/16
  403. * BMI160_AUX_ODR_3_12HZ | 25/8
  404. * BMI160_AUX_ODR_6_25HZ | 25/4
  405. * BMI160_AUX_ODR_12_5HZ | 25/2
  406. * BMI160_AUX_ODR_25HZ | 25
  407. * BMI160_AUX_ODR_50HZ | 50
  408. * BMI160_AUX_ODR_100HZ | 100
  409. * BMI160_AUX_ODR_200HZ | 200
  410. * BMI160_AUX_ODR_400HZ | 400
  411. * BMI160_AUX_ODR_800HZ | 800
  412. *@endverbatim
  413. *
  414. * @note : Other values of dev->aux_cfg.aux_odr are reserved and not for use
  415. *
  416. * @return Result of API execution status
  417. * @retval Zero Success
  418. * @retval Negative Error
  419. */
  420. int8_t bmi160_set_aux_auto_mode(uint8_t *data_addr, struct bmi160_dev *dev);
  421. /*!
  422. * \ingroup bmi160ApiAux
  423. * \page bmi160_api_bmi160_config_aux_mode bmi160_config_aux_mode
  424. * \code
  425. * int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev);
  426. * \endcode
  427. * @details This API configures the 0x4C register and settings like
  428. * Auxiliary sensor manual enable/ disable and aux burst read length.
  429. *
  430. * @param[in] dev : Structure instance of bmi160_dev.
  431. *
  432. * @return Result of API execution status
  433. * @retval Zero Success
  434. * @retval Negative Error
  435. */
  436. int8_t bmi160_config_aux_mode(const struct bmi160_dev *dev);
  437. /*!
  438. * \ingroup bmi160ApiAux
  439. * \page bmi160_api_bmi160_read_aux_data_auto_mode bmi160_read_aux_data_auto_mode
  440. * \code
  441. * int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev *dev);
  442. * \endcode
  443. * @details This API is used to read the raw uncompensated auxiliary sensor
  444. * data of 8 bytes from BMI160 register address 0x04 to 0x0B
  445. *
  446. * @param[in] aux_data : Pointer to user array of length 8 bytes
  447. * Ensure that the aux_data array is of
  448. * length 8 bytes
  449. * @param[in] dev : Structure instance of bmi160_dev
  450. *
  451. * @retval zero -> Success / -ve value -> Error
  452. * @retval Zero Success
  453. * @retval Negative Error
  454. */
  455. int8_t bmi160_read_aux_data_auto_mode(uint8_t *aux_data, const struct bmi160_dev *dev);
  456. /**
  457. * \ingroup bmi160
  458. * \defgroup bmi160ApiSelfTest Self test
  459. * @brief Perform self test of the sensor
  460. */
  461. /*!
  462. * \ingroup bmi160ApiSelfTest
  463. * \page bmi160_api_bmi160_perform_self_test bmi160_perform_self_test
  464. * \code
  465. * int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev);
  466. * \endcode
  467. * @details This is used to perform self test of accel/gyro of the BMI160 sensor
  468. *
  469. * @param[in] select_sensor : enum to choose accel or gyro for self test
  470. * @param[in] dev : Structure instance of bmi160_dev
  471. *
  472. * @note self test can be performed either for accel/gyro at any instant.
  473. *
  474. *@verbatim
  475. * value of select_sensor | Inference
  476. *----------------------------------|--------------------------------
  477. * BMI160_ACCEL_ONLY | Accel self test enabled
  478. * BMI160_GYRO_ONLY | Gyro self test enabled
  479. * BMI160_BOTH_ACCEL_AND_GYRO | NOT TO BE USED
  480. *@endverbatim
  481. *
  482. * @note The return value of this API gives us the result of self test.
  483. *
  484. * @note Performing self test does soft reset of the sensor, User can
  485. * set the desired settings after performing the self test.
  486. *
  487. * @return Result of API execution status
  488. * @retval BMI160_OK Self test success
  489. * @retval BMI160_W_GYRO_SELF_TEST_FAIL Gyro self test fail
  490. * @retval BMI160_W_ACCEl_SELF_TEST_FAIL Accel self test fail
  491. */
  492. int8_t bmi160_perform_self_test(uint8_t select_sensor, struct bmi160_dev *dev);
  493. /**
  494. * \ingroup bmi160
  495. * \defgroup bmi160ApiFIFO FIFO
  496. * @brief FIFO operations of the sensor
  497. */
  498. /*!
  499. * \ingroup bmi160ApiFIFO
  500. * \page bmi160_api_bmi160_get_fifo_data bmi160_get_fifo_data
  501. * \code
  502. * int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev);
  503. * \endcode
  504. * @details This API reads data from the fifo buffer.
  505. *
  506. * @note User has to allocate the FIFO buffer along with
  507. * corresponding fifo length from his side before calling this API
  508. * as mentioned in the readme.md
  509. *
  510. * @note User must specify the number of bytes to read from the FIFO in
  511. * dev->fifo->length , It will be updated by the number of bytes actually
  512. * read from FIFO after calling this API
  513. *
  514. * @param[in] dev : Structure instance of bmi160_dev.
  515. *
  516. * @return Result of API execution status
  517. * @retval Zero Success
  518. * @retval Negative Error
  519. */
  520. int8_t bmi160_get_fifo_data(struct bmi160_dev const *dev);
  521. /*!
  522. * \ingroup bmi160ApiFIFO
  523. * \page bmi160_api_bmi160_set_fifo_flush bmi160_set_fifo_flush
  524. * \code
  525. * int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev);
  526. * \endcode
  527. * @details This API writes fifo_flush command to command register.This
  528. * action clears all data in the Fifo without changing fifo configuration
  529. * settings.
  530. *
  531. * @param[in] dev : Structure instance of bmi160_dev
  532. *
  533. * @return Result of API execution status
  534. * @retval 0 -> Success
  535. * @retval Any non zero value -> Fail
  536. *
  537. */
  538. int8_t bmi160_set_fifo_flush(const struct bmi160_dev *dev);
  539. /*!
  540. * \ingroup bmi160ApiFIFO
  541. * \page bmi160_api_bmi160_set_fifo_config bmi160_set_fifo_config
  542. * \code
  543. * int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev const *dev);
  544. * \endcode
  545. * @details This API sets the FIFO configuration in the sensor.
  546. *
  547. * @param[in] config : variable used to specify the FIFO
  548. * configurations which are to be enabled or disabled in the sensor.
  549. *
  550. * @note : User can set either set one or more or all FIFO configurations
  551. * by ORing the below mentioned macros.
  552. *
  553. *@verbatim
  554. * config | Value
  555. * ------------------------|---------------------------
  556. * BMI160_FIFO_TIME | 0x02
  557. * BMI160_FIFO_TAG_INT2 | 0x04
  558. * BMI160_FIFO_TAG_INT1 | 0x08
  559. * BMI160_FIFO_HEADER | 0x10
  560. * BMI160_FIFO_AUX | 0x20
  561. * BMI160_FIFO_ACCEL | 0x40
  562. * BMI160_FIFO_GYRO | 0x80
  563. *@endverbatim
  564. *
  565. * @param[in] enable : Parameter used to enable or disable the above
  566. * FIFO configuration
  567. * @param[in] dev : Structure instance of bmi160_dev.
  568. *
  569. * @return status of bus communication result
  570. * @retval 0 -> Success
  571. * @retval Any non zero value -> Fail
  572. *
  573. */
  574. int8_t bmi160_set_fifo_config(uint8_t config, uint8_t enable, struct bmi160_dev const *dev);
  575. /*!
  576. * \ingroup bmi160ApiFIFO
  577. * \page bmi160_api_bmi160_set_fifo_down bmi160_set_fifo_down
  578. * \code
  579. * int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev);
  580. * \endcode
  581. * @details This API is used to configure the down sampling ratios of
  582. * the accel and gyro data for FIFO.Also, it configures filtered or
  583. * pre-filtered data for the fifo for accel and gyro.
  584. *
  585. * @param[in] fifo_down : variable used to specify the FIFO down
  586. * configurations which are to be enabled or disabled in the sensor.
  587. *
  588. * @note The user must select one among the following macros to
  589. * select down-sampling ratio for accel
  590. *
  591. *@verbatim
  592. * config | Value
  593. * -------------------------------------|---------------------------
  594. * BMI160_ACCEL_FIFO_DOWN_ZERO | 0x00
  595. * BMI160_ACCEL_FIFO_DOWN_ONE | 0x10
  596. * BMI160_ACCEL_FIFO_DOWN_TWO | 0x20
  597. * BMI160_ACCEL_FIFO_DOWN_THREE | 0x30
  598. * BMI160_ACCEL_FIFO_DOWN_FOUR | 0x40
  599. * BMI160_ACCEL_FIFO_DOWN_FIVE | 0x50
  600. * BMI160_ACCEL_FIFO_DOWN_SIX | 0x60
  601. * BMI160_ACCEL_FIFO_DOWN_SEVEN | 0x70
  602. *@endverbatim
  603. *
  604. * @note The user must select one among the following macros to
  605. * select down-sampling ratio for gyro
  606. *
  607. *@verbatim
  608. * config | Value
  609. * -------------------------------------|---------------------------
  610. * BMI160_GYRO_FIFO_DOWN_ZERO | 0x00
  611. * BMI160_GYRO_FIFO_DOWN_ONE | 0x01
  612. * BMI160_GYRO_FIFO_DOWN_TWO | 0x02
  613. * BMI160_GYRO_FIFO_DOWN_THREE | 0x03
  614. * BMI160_GYRO_FIFO_DOWN_FOUR | 0x04
  615. * BMI160_GYRO_FIFO_DOWN_FIVE | 0x05
  616. * BMI160_GYRO_FIFO_DOWN_SIX | 0x06
  617. * BMI160_GYRO_FIFO_DOWN_SEVEN | 0x07
  618. *@endverbatim
  619. *
  620. * @note The user can enable filtered accel data by the following macro
  621. *
  622. *@verbatim
  623. * config | Value
  624. * -------------------------------------|---------------------------
  625. * BMI160_ACCEL_FIFO_FILT_EN | 0x80
  626. *@endverbatim
  627. *
  628. * @note The user can enable filtered gyro data by the following macro
  629. *
  630. *@verbatim
  631. * config | Value
  632. * -------------------------------------|---------------------------
  633. * BMI160_GYRO_FIFO_FILT_EN | 0x08
  634. *@endverbatim
  635. *
  636. * @note : By ORing the above mentioned macros, the user can select
  637. * the required FIFO down config settings
  638. *
  639. * @param[in] dev : Structure instance of bmi160_dev.
  640. *
  641. * @return status of bus communication result
  642. * @retval 0 -> Success
  643. * @retval Any non zero value -> Fail
  644. *
  645. */
  646. int8_t bmi160_set_fifo_down(uint8_t fifo_down, const struct bmi160_dev *dev);
  647. /*!
  648. * \ingroup bmi160ApiFIFO
  649. * \page bmi160_api_bmi160_set_fifo_wm bmi160_set_fifo_wm
  650. * \code
  651. * int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev);
  652. * \endcode
  653. * @details This API sets the FIFO watermark level in the sensor.
  654. *
  655. * @note The FIFO watermark is issued when the FIFO fill level is
  656. * equal or above the watermark level and units of watermark is 4 bytes.
  657. *
  658. * @param[in] fifo_wm : Variable used to set the FIFO water mark level
  659. * @param[in] dev : Structure instance of bmi160_dev
  660. *
  661. * @return Result of API execution status
  662. * @retval 0 -> Success
  663. * @retval Any non zero value -> Fail
  664. *
  665. */
  666. int8_t bmi160_set_fifo_wm(uint8_t fifo_wm, const struct bmi160_dev *dev);
  667. /*!
  668. * \ingroup bmi160ApiFIFO
  669. * \page bmi160_api_bmi160_extract_accel bmi160_extract_accel
  670. * \code
  671. * int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, struct bmi160_dev const
  672. **dev);
  673. * \endcode
  674. * @details This API parses and extracts the accelerometer frames from
  675. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  676. * the "accel_data" structure instance.
  677. *
  678. * @note The bmi160_extract_accel API should be called only after
  679. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  680. *
  681. * @param[out] accel_data : Structure instance of bmi160_sensor_data
  682. * where the accelerometer data in FIFO is stored.
  683. * @param[in,out] accel_length : Number of valid accelerometer frames
  684. * (x,y,z axes data) read out from fifo.
  685. * @param[in] dev : Structure instance of bmi160_dev.
  686. *
  687. * @note accel_length is updated with the number of valid accelerometer
  688. * frames extracted from fifo (1 accel frame = 6 bytes) at the end of
  689. * execution of this API.
  690. *
  691. * @return Result of API execution status
  692. * @retval 0 -> Success
  693. * @retval Any non zero value -> Fail
  694. *
  695. */
  696. int8_t bmi160_extract_accel(struct bmi160_sensor_data *accel_data, uint8_t *accel_length, struct bmi160_dev const *dev);
  697. /*!
  698. * \ingroup bmi160ApiFIFO
  699. * \page bmi160_api_bmi160_extract_gyro bmi160_extract_gyro
  700. * \code
  701. * int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev);
  702. * \endcode
  703. * @details This API parses and extracts the gyro frames from
  704. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  705. * the "gyro_data" structure instance.
  706. *
  707. * @note The bmi160_extract_gyro API should be called only after
  708. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  709. *
  710. * @param[out] gyro_data : Structure instance of bmi160_sensor_data
  711. * where the gyro data in FIFO is stored.
  712. * @param[in,out] gyro_length : Number of valid gyro frames
  713. * (x,y,z axes data) read out from fifo.
  714. * @param[in] dev : Structure instance of bmi160_dev.
  715. *
  716. * @note gyro_length is updated with the number of valid gyro
  717. * frames extracted from fifo (1 gyro frame = 6 bytes) at the end of
  718. * execution of this API.
  719. *
  720. * @return Result of API execution status
  721. * @retval 0 -> Success
  722. * @retval Any non zero value -> Fail
  723. *
  724. */
  725. int8_t bmi160_extract_gyro(struct bmi160_sensor_data *gyro_data, uint8_t *gyro_length, struct bmi160_dev const *dev);
  726. /*!
  727. * \ingroup bmi160ApiFIFO
  728. * \page bmi160_api_bmi160_extract_aux bmi160_extract_aux
  729. * \code
  730. * int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev);
  731. * \endcode
  732. * @details This API parses and extracts the aux frames from
  733. * FIFO data read by the "bmi160_get_fifo_data" API and stores it in
  734. * the bmi160_aux_data structure instance.
  735. *
  736. * @note The bmi160_extract_aux API should be called only after
  737. * reading the FIFO data by calling the bmi160_get_fifo_data() API.
  738. *
  739. * @param[out] aux_data : Structure instance of bmi160_aux_data
  740. * where the aux data in FIFO is stored.
  741. * @param[in,out] aux_len : Number of valid aux frames (8bytes)
  742. * read out from FIFO.
  743. * @param[in] dev : Structure instance of bmi160_dev.
  744. *
  745. * @note aux_len is updated with the number of valid aux
  746. * frames extracted from fifo (1 aux frame = 8 bytes) at the end of
  747. * execution of this API.
  748. *
  749. * @return Result of API execution status
  750. * @retval 0 -> Success
  751. * @retval Any non zero value -> Fail
  752. *
  753. */
  754. int8_t bmi160_extract_aux(struct bmi160_aux_data *aux_data, uint8_t *aux_len, struct bmi160_dev const *dev);
  755. /**
  756. * \ingroup bmi160
  757. * \defgroup bmi160ApiFOC FOC
  758. * @brief Start FOC of accel and gyro sensors
  759. */
  760. /*!
  761. * \ingroup bmi160ApiFOC
  762. * \page bmi160_api_bmi160_start_foc bmi160_start_foc
  763. * \code
  764. * int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf,
  765. * \endcode
  766. * @details This API starts the FOC of accel and gyro
  767. *
  768. * @note FOC should not be used in low-power mode of sensor
  769. *
  770. * @note Accel FOC targets values of +1g , 0g , -1g
  771. * Gyro FOC always targets value of 0 dps
  772. *
  773. * @param[in] foc_conf : Structure instance of bmi160_foc_conf which
  774. * has the FOC configuration
  775. * @param[in,out] offset : Structure instance to store Offset
  776. * values read from sensor
  777. * @param[in] dev : Structure instance of bmi160_dev.
  778. *
  779. * @note Pre-requisites for triggering FOC in accel , Set the following,
  780. * Enable the acc_off_en
  781. * Ex : foc_conf.acc_off_en = BMI160_ENABLE;
  782. *
  783. * Set the desired target values of FOC to each axes (x,y,z) by using the
  784. * following macros
  785. * - BMI160_FOC_ACCEL_DISABLED
  786. * - BMI160_FOC_ACCEL_POSITIVE_G
  787. * - BMI160_FOC_ACCEL_NEGATIVE_G
  788. * - BMI160_FOC_ACCEL_0G
  789. *
  790. * Ex : foc_conf.foc_acc_x = BMI160_FOC_ACCEL_0G;
  791. * foc_conf.foc_acc_y = BMI160_FOC_ACCEL_0G;
  792. * foc_conf.foc_acc_z = BMI160_FOC_ACCEL_POSITIVE_G;
  793. *
  794. * @note Pre-requisites for triggering FOC in gyro ,
  795. * Set the following parameters,
  796. *
  797. * Ex : foc_conf.foc_gyr_en = BMI160_ENABLE;
  798. * foc_conf.gyro_off_en = BMI160_ENABLE;
  799. *
  800. * @return Result of API execution status
  801. * @retval 0 -> Success
  802. * @retval Any non zero value -> Fail
  803. */
  804. int8_t bmi160_start_foc(const struct bmi160_foc_conf *foc_conf,
  805. struct bmi160_offsets *offset,
  806. struct bmi160_dev const *dev);
  807. /**
  808. * \ingroup bmi160
  809. * \defgroup bmi160ApiOffsets Offsets
  810. * @brief Set / Get offset values of accel and gyro sensors
  811. */
  812. /*!
  813. * \ingroup bmi160ApiOffsets
  814. * \page bmi160_api_bmi160_get_offsets bmi160_get_offsets
  815. * \code
  816. * int8_t bmi160_get_offsets(struct bmi160_offsets *offset, const struct bmi160_dev *dev);
  817. * \endcode
  818. * @details This API reads and stores the offset values of accel and gyro
  819. *
  820. * @param[in,out] offset : Structure instance of bmi160_offsets in which
  821. * the offset values are read and stored
  822. * @param[in] dev : Structure instance of bmi160_dev.
  823. *
  824. * @return Result of API execution status
  825. * @retval 0 -> Success
  826. * @retval Any non zero value -> Fail
  827. */
  828. int8_t bmi160_get_offsets(struct bmi160_offsets *offset, const struct bmi160_dev *dev);
  829. /*!
  830. * \ingroup bmi160ApiOffsets
  831. * \page bmi160_api_bmi160_set_offsets bmi160_set_offsets
  832. * \code
  833. * int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf,
  834. * const struct bmi160_offsets *offset,
  835. * struct bmi160_dev const *dev);
  836. * \endcode
  837. * @details This API writes the offset values of accel and gyro to
  838. * the sensor but these values will be reset on POR or soft reset.
  839. *
  840. * @param[in] foc_conf : Structure instance of bmi160_foc_conf which
  841. * has the FOC configuration
  842. * @param[in] offset : Structure instance in which user updates offset
  843. * values which are to be written in the sensor
  844. * @param[in] dev : Structure instance of bmi160_dev.
  845. *
  846. * @note Offsets can be set by user like offset->off_acc_x = 10;
  847. * where 1LSB = 3.9mg and for gyro 1LSB = 0.061degrees/second
  848. *
  849. * @note BMI160 offset values for xyz axes of accel should be within range of
  850. * BMI160_ACCEL_MIN_OFFSET (-128) to BMI160_ACCEL_MAX_OFFSET (127)
  851. *
  852. * @note BMI160 offset values for xyz axes of gyro should be within range of
  853. * BMI160_GYRO_MIN_OFFSET (-512) to BMI160_GYRO_MAX_OFFSET (511)
  854. *
  855. * @return Result of API execution status
  856. * @retval 0 -> Success
  857. * @retval Any non zero value -> Fail
  858. */
  859. int8_t bmi160_set_offsets(const struct bmi160_foc_conf *foc_conf,
  860. const struct bmi160_offsets *offset,
  861. struct bmi160_dev const *dev);
  862. /**
  863. * \ingroup bmi160
  864. * \defgroup bmi160ApiNVM NVM
  865. * @brief Write image registers values to NVM
  866. */
  867. /*!
  868. * \ingroup bmi160ApiNVM
  869. * \page bmi160_api_bmi160_update_nvm bmi160_update_nvm
  870. * \code
  871. * int8_t bmi160_update_nvm(struct bmi160_dev const *dev);
  872. * \endcode
  873. * @details This API writes the image registers values to NVM which is
  874. * stored even after POR or soft reset
  875. *
  876. * @param[in] dev : Structure instance of bmi160_dev.
  877. *
  878. * @return Result of API execution status
  879. * @retval 0 -> Success
  880. * @retval Any non zero value -> Fail
  881. */
  882. int8_t bmi160_update_nvm(struct bmi160_dev const *dev);
  883. /**
  884. * \ingroup bmi160
  885. * \defgroup bmi160ApiInts Interrupt status
  886. * @brief Read interrupt status from the sensor
  887. */
  888. /*!
  889. * \ingroup bmi160ApiInts
  890. * \page bmi160_api_bmi160_get_int_status bmi160_get_int_status
  891. * \code
  892. * int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel,
  893. * union bmi160_int_status *int_status,
  894. * struct bmi160_dev const *dev);
  895. * \endcode
  896. * @details This API gets the interrupt status from the sensor.
  897. *
  898. * @param[in] int_status_sel : Enum variable to select either individual or all the
  899. * interrupt status bits.
  900. * @param[in] int_status : pointer variable to get the interrupt status
  901. * from the sensor.
  902. * param[in] dev : Structure instance of bmi160_dev.
  903. *
  904. * @return Result of API execution status
  905. * @retval 0 -> Success
  906. * @retval Any non zero value -> Fail
  907. */
  908. int8_t bmi160_get_int_status(enum bmi160_int_status_sel int_status_sel,
  909. union bmi160_int_status *int_status,
  910. struct bmi160_dev const *dev);
  911. /*************************** C++ guard macro *****************************/
  912. #ifdef __cplusplus
  913. }
  914. #endif
  915. #endif /* BMI160_H_ */