bma400.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /**
  2. * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of the copyright holder nor the names of the
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  33. *
  34. * The information provided is believed to be accurate and reliable.
  35. * The copyright holder assumes no responsibility
  36. * for the consequences of use
  37. * of such information nor for any infringement of patents or
  38. * other rights of third parties which may result from its use.
  39. * No license is granted by implication or otherwise under any patent or
  40. * patent rights of the copyright holder.
  41. *
  42. * @file bma400.h
  43. * @date 25 Sep 2018
  44. * @version 1.5.0
  45. * @brief
  46. *
  47. */
  48. /*! @file bma400.h */
  49. /*!
  50. * @defgroup BMA400 SENSOR API
  51. * @{
  52. */
  53. #ifndef BMA400_H__
  54. #define BMA400_H__
  55. /*! CPP guard */
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. /*********************************************************************/
  60. /* header files */
  61. #include "bma400_defs.h"
  62. /*********************************************************************/
  63. /* (extern) variable declarations */
  64. /*********************************************************************/
  65. /* function prototype declarations */
  66. /*!
  67. * @brief This API is the entry point, Call this API before using other APIs.
  68. * This API reads the chip-id of the sensor which is the first step to
  69. * verify the sensor and also it configures the read mechanism of SPI and
  70. * I2C interface.
  71. *
  72. * @param[in,out] dev : Structure instance of bma400_dev
  73. *
  74. * @return Result of API execution status
  75. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  76. */
  77. int8_t bma400_init(struct bma400_dev *dev);
  78. /*!
  79. * @brief This API writes the given data to the register address
  80. * of the sensor.
  81. *
  82. * @param[in] reg_addr : Register address from where the data to be written.
  83. * @param[in] reg_data : Pointer to data buffer which is to be written
  84. * in the reg_addr of sensor.
  85. * @param[in] len : No of bytes of data to write..
  86. * @param[in] dev : Structure instance of bma400_dev.
  87. *
  88. * @return Result of API execution status
  89. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  90. */
  91. int8_t bma400_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev);
  92. /*!
  93. * @brief This API reads the data from the given register address of sensor.
  94. *
  95. * @param[in] reg_addr : Register address from where the data to be read
  96. * @param[out] reg_data : Pointer to data buffer to store the read data.
  97. * @param[in] len : No of bytes of data to be read.
  98. * @param[in] dev : Structure instance of bma400_dev.
  99. *
  100. * @note For most of the registers auto address increment applies, with the
  101. * exception of a few special registers, which trap the address. For e.g.,
  102. * Register address - 0x14(BMA400_FIFO_DATA_ADDR)
  103. *
  104. * @return Result of API execution status
  105. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  106. */
  107. int8_t bma400_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bma400_dev *dev);
  108. /*!
  109. * @brief This API is used to perform soft-reset of the sensor
  110. * where all the registers are reset to their default values except 0x4B.
  111. *
  112. * @param[in] dev : Structure instance of bma400_dev.
  113. *
  114. * @return Result of API execution status
  115. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  116. */
  117. int8_t bma400_soft_reset(const struct bma400_dev *dev);
  118. /*!
  119. * @brief This API is used to set the power mode of the sensor.
  120. *
  121. * @param[in] power_mode : Macro to select power mode of the sensor.
  122. * @param[in] dev : Structure instance of bma400_dev.
  123. *
  124. * Possible value for power_mode :
  125. * - BMA400_NORMAL_MODE
  126. * - BMA400_SLEEP_MODE
  127. * - BMA400_LOW_POWER_MODE
  128. *
  129. * @return Result of API execution status
  130. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  131. */
  132. int8_t bma400_set_power_mode(uint8_t power_mode, const struct bma400_dev *dev);
  133. /*!
  134. * @brief This API is used to get the power mode of the sensor
  135. *
  136. * @param[out] power_mode : power mode of the sensor.
  137. * @param[in] dev : Structure instance of bma400_dev.
  138. *
  139. * * Possible value for power_mode :
  140. * - BMA400_NORMAL_MODE
  141. * - BMA400_SLEEP_MODE
  142. * - BMA400_LOW_POWER_MODE
  143. *
  144. * @return Result of API execution status
  145. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  146. */
  147. int8_t bma400_get_power_mode(uint8_t *power_mode, const struct bma400_dev *dev);
  148. /*!
  149. * @brief This API is used to get the accel data along with the sensor-time
  150. *
  151. * @param[in] data_sel : Variable to select sensor data only
  152. * or data along with sensortime
  153. * @param[in,out] accel : Structure instance to store data
  154. * @param[in] dev : Structure instance of bma400_dev
  155. *
  156. * Assignable macros for "data_sel" :
  157. * - BMA400_DATA_ONLY
  158. * - BMA400_DATA_SENSOR_TIME
  159. *
  160. * @note : The Accel data value are in LSB based on the range selected
  161. *
  162. * @return Result of API execution status
  163. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  164. */
  165. int8_t bma400_get_accel_data(uint8_t data_sel, struct bma400_sensor_data *accel, const struct bma400_dev *dev);
  166. /*!
  167. * @brief This API is used to set the sensor settings like sensor
  168. * configurations and interrupt configurations like
  169. * - Accelerometer configurations (Like ODR,OSR,range...)
  170. * - Tap configurations
  171. * - Activity change configurations
  172. * - Gen1/Gen2 configurations
  173. * - Orient change configurations
  174. * - Step counter configurations
  175. *
  176. * @param[in] conf : Structure instance of the configuration structure
  177. * @param[in] n_sett : Number of settings to be set
  178. * @param[in] dev : Structure instance of bma400_dev
  179. *
  180. * @note : Fill in the value of the required configurations in the conf structure
  181. * (Examples are mentioned in the readme.md) before calling this API
  182. *
  183. * @return Result of API execution status
  184. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  185. */
  186. int8_t bma400_set_sensor_conf(const struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev);
  187. /*!
  188. * @brief This API is used to get the sensor settings like sensor
  189. * configurations and interrupt configurations and store
  190. * them in the corresponding structure instance
  191. *
  192. * @param[in] conf : Structure instance of the configuration structure
  193. * @param[in] n_sett : Number of settings to be obtained
  194. * @param[in] dev : Structure instance of bma400_dev.
  195. *
  196. * @note : Call the API and the settings structure will be updated with the
  197. * sensor settings
  198. *
  199. * @return Result of API execution status
  200. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  201. */
  202. int8_t bma400_get_sensor_conf(struct bma400_sensor_conf *conf, uint16_t n_sett, const struct bma400_dev *dev);
  203. /*!
  204. * @brief This API is used to set the device specific settings like
  205. * - BMA400_AUTOWAKEUP_TIMEOUT
  206. * - BMA400_AUTOWAKEUP_INT
  207. * - BMA400_AUTO_LOW_POWER
  208. * - BMA400_INT_PIN_CONF
  209. * - BMA400_INT_OVERRUN_CONF
  210. * - BMA400_FIFO_CONF
  211. *
  212. * @param[in] conf : Structure instance of the configuration structure.
  213. * @param[in] n_sett : Number of settings to be set
  214. * @param[in] dev : Structure instance of bma400_dev.
  215. *
  216. * @note : Fill in the value of the required configurations in the conf structure
  217. * (Examples are mentioned in the readme.md) before calling this API
  218. *
  219. * @return Result of API execution status
  220. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  221. */
  222. int8_t bma400_set_device_conf(const struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev);
  223. /*!
  224. * @brief This API is used to get the device specific settings and store
  225. * them in the corresponding structure instance
  226. *
  227. * @param[in] conf : Structure instance of the configuration structure
  228. * @param[in] n_sett : Number of settings to be obtained
  229. * @param[in] dev : Structure instance of bma400_dev.
  230. *
  231. * @note : Call the API and the settings structure will be updated with the
  232. * sensor settings
  233. *
  234. * @return Result of API execution status
  235. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  236. */
  237. int8_t bma400_get_device_conf(struct bma400_device_conf *conf, uint8_t n_sett, const struct bma400_dev *dev);
  238. /*!
  239. * @brief This API is used to get the status of all the interrupts
  240. * whether they are asserted or not
  241. *
  242. * @param[in] int_status : Interrupt status of sensor
  243. * @param[in] dev : Structure instance of bma400_dev.
  244. *
  245. * @note : Interrupt status of the sensor determines which all
  246. * interrupts are asserted at any instant of time
  247. *
  248. * Interrupt status macros :
  249. * - BMA400_WAKEUP_INT_ASSERTED
  250. * - BMA400_ORIENT_CH_INT_ASSERTED
  251. * - BMA400_GEN1_INT_ASSERTED
  252. * - BMA400_GEN2_INT_ASSERTED
  253. * - BMA400_FIFO_FULL_INT_ASSERTED
  254. * - BMA400_FIFO_WM_INT_ASSERTED
  255. * - BMA400_DRDY_INT_ASSERTED
  256. * - BMA400_INT_OVERRUN_ASSERTED
  257. * - BMA400_STEP_INT_ASSERTED
  258. * - BMA400_S_TAP_INT_ASSERTED
  259. * - BMA400_D_TAP_INT_ASSERTED
  260. * - BMA400_ACT_CH_X_ASSERTED
  261. * - BMA400_ACT_CH_Y_ASSERTED
  262. * - BMA400_ACT_CH_Z_ASSERTED
  263. *
  264. * @note : Call the API and then use the above macros to
  265. * check whether the interrupt is asserted or not
  266. *
  267. * if (int_status & BMA400_FIFO_FULL_INT_ASSERTED) {
  268. * printf("\n FIFO FULL INT ASSERTED");
  269. * }
  270. *
  271. * @return Result of API execution status
  272. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  273. */
  274. int8_t bma400_get_interrupt_status(uint16_t *int_status, const struct bma400_dev *dev);
  275. /*!
  276. * @brief This API is used to get the enable/disable
  277. * status of the various interrupts
  278. *
  279. * @param[in] int_select : Structure to select specific interrupts
  280. * @param[in] n_sett : Number of interrupt settings enabled / disabled
  281. * @param[in] dev : Structure instance of bma400_dev.
  282. *
  283. * @note : Select the needed interrupt type for which the status of it whether
  284. * it is enabled/disabled is to be known in the int_select->int_sel, and the
  285. * output is stored in int_select->conf either as BMA400_ENABLE/BMA400_DISABLE
  286. *
  287. * @return Result of API execution status
  288. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  289. */
  290. int8_t bma400_get_interrupts_enabled(struct bma400_int_enable *int_select, uint8_t n_sett, const struct bma400_dev *dev);
  291. /*!
  292. * @brief This API is used to enable the various interrupts
  293. *
  294. * @param[in] int_select : Structure to enable specific interrupts
  295. * @param[in] n_sett : Number of interrupt settings enabled / disabled
  296. * @param[in] dev : Structure instance of bma400_dev.
  297. *
  298. * @note : Multiple interrupt can be enabled/disabled by
  299. * struct interrupt_enable int_select[2];
  300. *
  301. * int_select[0].int_sel = BMA400_FIFO_FULL_INT_EN;
  302. * int_select[0].conf = BMA400_ENABLE;
  303. *
  304. * int_select[1].int_sel = BMA400_FIFO_WM_INT_EN;
  305. * int_select[1].conf = BMA400_ENABLE;
  306. *
  307. * rslt = bma400_enable_interrupt(&int_select, 2, dev);
  308. *
  309. * @return Result of API execution status
  310. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  311. */
  312. int8_t bma400_enable_interrupt(const struct bma400_int_enable *int_select, uint8_t n_sett, const struct bma400_dev *dev);
  313. /*!
  314. * @brief This API is used to get the step counter output in form
  315. * of number of steps in the step_count value
  316. *
  317. * @param[out] step_count : Number of step counts
  318. * @param[out] activity_data : Activity data WALK/STILL/RUN
  319. * @param[in] dev : Structure instance of bma400_dev.
  320. *
  321. * activity_data | Status
  322. * -----------------|------------------
  323. * 0x00 | BMA400_STILL_ACT
  324. * 0x01 | BMA400_WALK_ACT
  325. * 0x02 | BMA400_RUN_ACT
  326. *
  327. * @return Result of API execution status
  328. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  329. */
  330. int8_t bma400_get_steps_counted(uint32_t *step_count, uint8_t *activity_data, const struct bma400_dev *dev);
  331. /*!
  332. * @brief This API is used to get the temperature data output
  333. *
  334. * @note Temperature data output must be divided by a factor of 10
  335. * Consider temperature_data = 195 ,
  336. * Then the actual temperature is 19.5 degree Celsius
  337. *
  338. * @param[in,out] temperature_data : Temperature data
  339. * @param[in] dev : Structure instance of bma400_dev.
  340. *
  341. * @return Result of API execution status
  342. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  343. */
  344. int8_t bma400_get_temperature_data(int16_t *temperature_data, const struct bma400_dev *dev);
  345. /*!
  346. * @brief This API writes fifo_flush command to command register.
  347. * This action clears all data in the FIFO
  348. *
  349. * @param[in] dev : Structure instance of bma400_dev.
  350. *
  351. * @return Result of API execution status
  352. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  353. */
  354. int8_t bma400_set_fifo_flush(const struct bma400_dev *dev);
  355. /*!
  356. * @brief This API reads the FIFO data from the sensor
  357. *
  358. * @note User has to allocate the FIFO buffer along with
  359. * corresponding fifo read length from his side before calling this API
  360. * as mentioned in the readme.md
  361. *
  362. * @note User must specify the number of bytes to read from the FIFO in
  363. * fifo->length , It will be updated by the number of bytes actually
  364. * read from FIFO after calling this API
  365. *
  366. * @param[in,out] fifo : Pointer to the fifo structure.
  367. *
  368. * @param[in,out] dev : Structure instance of bma400_dev.
  369. *
  370. * @return Result of API execution status
  371. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  372. */
  373. int8_t bma400_get_fifo_data(struct bma400_fifo_data *fifo, const struct bma400_dev *dev);
  374. /*!
  375. * @brief This API parses and extracts the accelerometer frames, FIFO time
  376. * and control frames from FIFO data read by the "bma400_get_fifo_data" API
  377. * and stores it in the "accel_data" structure instance.
  378. *
  379. * @note The bma400_extract_accel API should be called only after
  380. * reading the FIFO data by calling the bma400_get_fifo_data() API
  381. * Please refer the readme.md for usage.
  382. *
  383. * @param[in,out] fifo : Pointer to the fifo structure.
  384. *
  385. * @param[out] accel_data : Structure instance of bma400_sensor_data where
  386. * the accelerometer data from FIFO is extracted
  387. * and stored after calling this API
  388. *
  389. * @param[in,out] frame_count : Number of valid accelerometer frames requested
  390. * by user is given as input and it is updated by
  391. * the actual frames parsed from the FIFO
  392. *
  393. * @param[in] dev : Structure instance of bma400_dev.
  394. *
  395. * @return Result of API execution status
  396. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  397. */
  398. int8_t bma400_extract_accel(struct bma400_fifo_data *fifo,
  399. struct bma400_sensor_data *accel_data,
  400. uint16_t *frame_count,
  401. const struct bma400_dev *dev);
  402. /*!
  403. * @brief This is used to perform self test of accelerometer in BMA400
  404. *
  405. * @param[in] dev : Structure instance of bma400_dev.
  406. *
  407. * @note The return value of this API gives us the result of self test.
  408. *
  409. * @note Performing self test does soft reset of the sensor, User can
  410. * set the desired settings after performing the self test.
  411. *
  412. * @return Result of API execution status
  413. * @retval zero -> Success / -ve value -> Error / +ve value -> Self-test fail
  414. *
  415. * Return value | Result of self test
  416. * --------------------------------|---------------------------------
  417. * BMA400_OK | Self test success
  418. * BMA400_W_SELF_TEST_FAIL | self test fail
  419. */
  420. int8_t bma400_perform_self_test(const struct bma400_dev *dev);
  421. /*!
  422. * @brief This API is used to set the step counter's configuration
  423. * parameters from the registers 0x59 to 0x71
  424. */
  425. int8_t bma400_set_step_counter_param(uint8_t *sccr_conf, const struct bma400_dev *dev);
  426. #ifdef __cplusplus
  427. }
  428. #endif /* End of CPP guard */
  429. #endif /* BMA400_H__ */
  430. /** @}*/