bmi160.h 33 KB

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