bmi160.h 35 KB

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