bmi160_support.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. /*
  2. ****************************************************************************
  3. * Copyright (C) 2016 Bosch Sensortec GmbH
  4. *
  5. * bmi160_support.c
  6. * Date: 2016/06/22
  7. * Revision: 1.1.4 $
  8. *
  9. * Usage: Sensor Driver support file for BMI160 sensor
  10. *
  11. ****************************************************************************
  12. * License:
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. *
  24. * Neither the name of the copyright holder nor the names of the
  25. * contributors may be used to endorse or promote products derived from
  26. * this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  29. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  30. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
  33. * OR CONTRIBUTORS BE LIABLE FOR ANY
  34. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  35. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  36. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  39. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  41. * ANY WAY OUT OF THE USE OF THIS
  42. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  43. *
  44. * The information provided is believed to be accurate and reliable.
  45. * The copyright holder assumes no responsibility
  46. * for the consequences of use
  47. * of such information nor for any infringement of patents or
  48. * other rights of third parties which may result from its use.
  49. * No license is granted by implication or otherwise under any patent or
  50. * patent rights of the copyright holder.
  51. **************************************************************************/
  52. #include "bmi160_support.h"
  53. #include "bmi160.h"
  54. /* Mapping the structure*/
  55. struct bmi160_t s_bmi160;
  56. /* Read the sensor data of accel, gyro and mag*/
  57. struct bmi160_gyro_t gyroxyz;
  58. struct bmi160_accel_t accelxyz;
  59. struct bmi160_mag_xyz_s32_t magxyz;
  60. /*!
  61. * @brief This function used for initialize the sensor
  62. *
  63. *
  64. * @return results of bus communication function
  65. * @retval 0 -> Success
  66. * @retval 1 -> Error
  67. *
  68. *
  69. */
  70. BMI160_RETURN_FUNCTION_TYPE bmi160_initialize_sensor(void)
  71. {
  72. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  73. /* Based on the user need configure I2C or SPI interface.
  74. * It is sample code to explain how to use the bmi160 API*/
  75. #ifdef INCLUDE_BMI160API
  76. com_rslt = i2c_routine();
  77. /*SPI_routine(); */
  78. #endif
  79. /*
  80. * This function used to assign the value/reference of
  81. * the following parameters
  82. * I2C address
  83. * Bus Write
  84. * Bus read
  85. * company_id
  86. */
  87. com_rslt += bmi160_init(&s_bmi160);
  88. /**** standard 9Dof with FIFO output****/
  89. com_rslt += bmi160_config_running_mode(STANDARD_UI_9DOF_FIFO);
  90. return com_rslt;
  91. }
  92. /*!
  93. * @brief This Function used to read the sensor data using
  94. * different running mode
  95. * @param v_running_mode_u8 : The value of running mode
  96. * Description | value
  97. * --------------------------------|----------
  98. * STANDARD_UI_9DOF_FIFO | 0
  99. * STANDARD_UI_IMU_FIFO | 1
  100. * STANDARD_UI_IMU | 2
  101. * STANDARD_UI_ADVANCEPOWERSAVE | 3
  102. * ACCEL_PEDOMETER | 4
  103. * APPLICATION_HEAD_TRACKING | 5
  104. * APPLICATION_NAVIGATION | 6
  105. * APPLICATION_REMOTE_CONTROL | 7
  106. * APPLICATION_INDOOR_NAVIGATION | 8
  107. *
  108. *
  109. * @return results of bus communication function
  110. * @retval 0 -> Success
  111. * @retval 1 -> Error
  112. *
  113. *
  114. */
  115. BMI160_RETURN_FUNCTION_TYPE bmi160_config_running_mode(
  116. u8 v_running_mode_u8)
  117. {
  118. struct gyro_sleep_setting gyr_setting;
  119. struct bmi160_fifo_data_header_t header_data;
  120. /* Variable used for get the status of mag interface*/
  121. u8 v_mag_interface_u8 = BMI160_INIT_VALUE;
  122. u8 v_bmm_chip_id_u8 = BMI160_INIT_VALUE;
  123. BMI160_RETURN_FUNCTION_TYPE com_rslt = ERROR;
  124. /* Configure the gyro sleep setting based on your need*/
  125. if (v_running_mode_u8 == STANDARD_UI_ADVANCEPOWERSAVE) {
  126. gyr_setting. sleep_trigger = BMI160_SLEEP_TRIGGER;
  127. gyr_setting. wakeup_trigger = BMI160_WAKEUP_TRIGGER;
  128. gyr_setting. sleep_state = BMI160_SLEEP_STATE;
  129. gyr_setting. wakeup_int = BMI160_WAKEUP_INTR;
  130. }
  131. /* The below code used for enable and
  132. disable the secondary mag interface*/
  133. com_rslt = bmi160_get_if_mode(&v_mag_interface_u8);
  134. if (((v_running_mode_u8 == STANDARD_UI_IMU_FIFO) ||
  135. (v_running_mode_u8 == STANDARD_UI_IMU) ||
  136. (v_running_mode_u8 == STANDARD_UI_ADVANCEPOWERSAVE) ||
  137. (v_running_mode_u8 == APPLICATION_NAVIGATION) ||
  138. (v_running_mode_u8 == ACCEL_PEDOMETER) ||
  139. (v_running_mode_u8 == APPLICATION_REMOTE_CONTROL) ||
  140. (v_running_mode_u8 == APPLICATION_INDOOR_NAVIGATION))
  141. && (v_mag_interface_u8 == BMI160_MAG_INTERFACE_ON_PRIMARY_ON)) {
  142. com_rslt +=
  143. bmi160_set_bmm150_mag_and_secondary_if_power_mode(
  144. MAG_SUSPEND_MODE);
  145. s_bmi160.delay_msec(
  146. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  147. com_rslt += bmi160_set_if_mode(
  148. BMI160_MAG_INTERFACE_OFF_PRIMARY_ON);
  149. s_bmi160.delay_msec(
  150. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  151. }
  152. if (((v_running_mode_u8 == STANDARD_UI_9DOF_FIFO)
  153. || (v_running_mode_u8 == APPLICATION_HEAD_TRACKING) ||
  154. (v_running_mode_u8 == APPLICATION_NAVIGATION)) &&
  155. (v_mag_interface_u8 == BMI160_MAG_INTERFACE_OFF_PRIMARY_ON)) {
  156. /* Init the magnetometer */
  157. com_rslt += bmi160_bmm150_mag_interface_init(
  158. &v_bmm_chip_id_u8);
  159. /* bmi160_delay_ms in ms*/
  160. s_bmi160.delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  161. }
  162. switch (v_running_mode_u8) {
  163. case STANDARD_UI_9DOF_FIFO:
  164. /*Set the accel mode as Normal write in the register 0x7E*/
  165. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  166. /* bmi160_delay_ms in ms*/
  167. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  168. /*Set the gyro mode as Normal write in the register 0x7E*/
  169. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  170. /* bmi160_delay_ms in ms*/
  171. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  172. /* Set the accel bandwidth as Normal */
  173. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
  174. s_bmi160.delay_msec(
  175. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  176. /* Set the gryo bandwidth as Normal */
  177. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  178. s_bmi160.delay_msec(
  179. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  180. /* set gyro data rate as 100Hz*/
  181. com_rslt += bmi160_set_gyro_output_data_rate(
  182. BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
  183. s_bmi160.delay_msec(
  184. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  185. /* set accel data rate as 100Hz*/
  186. com_rslt += bmi160_set_accel_output_data_rate(
  187. BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ, BMI160_ACCEL_OSR4_AVG1);
  188. s_bmi160.delay_msec(
  189. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  190. /***** read FIFO data based on interrupt*****/
  191. com_rslt += bmi160_interrupt_configuration();
  192. s_bmi160.delay_msec(
  193. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  194. /* Enable the FIFO header*/
  195. com_rslt += bmi160_set_fifo_header_enable(FIFO_HEADER_ENABLE);
  196. s_bmi160.delay_msec(
  197. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  198. /* Enable the FIFO mag*/
  199. com_rslt += bmi160_set_fifo_mag_enable(FIFO_MAG_ENABLE);
  200. s_bmi160.delay_msec(
  201. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  202. /* Enable the FIFO accel*/
  203. com_rslt += bmi160_set_fifo_accel_enable(FIFO_ACCEL_ENABLE);
  204. s_bmi160.delay_msec(
  205. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  206. /* Enable the FIFO gyro*/
  207. com_rslt += bmi160_set_fifo_gyro_enable(FIFO_GYRO_ENABLE);
  208. /* Enable the FIFO time*/
  209. com_rslt += bmi160_set_fifo_time_enable(FIFO_TIME_ENABLE);
  210. s_bmi160.delay_msec(
  211. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  212. /* Enable the FIFO water mark interrupt1*/
  213. /* Enable FIFO water mark interrupts in INT_EN[1] */
  214. com_rslt += bmi160_set_intr_enable_1(BMI160_FIFO_WM_ENABLE,
  215. BMI160_ENABLE);
  216. com_rslt += bmi160_set_intr_fifo_wm(BMI160_INIT_VALUE,
  217. FIFO_WM_INTERRUPT_ENABLE);
  218. s_bmi160.delay_msec(
  219. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  220. /* Enable the FIFO water mark interrupt2*/
  221. com_rslt += bmi160_set_intr_fifo_wm(BMI160_ENABLE,
  222. FIFO_WM_INTERRUPT_ENABLE);
  223. s_bmi160.delay_msec(
  224. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  225. /* set the fifo water mark*/
  226. com_rslt += bmi160_set_fifo_wm(BMI160_ENABLE_FIFO_WM);
  227. s_bmi160.delay_msec(
  228. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  229. /* read the FIFO data*/
  230. com_rslt += bmi160_read_fifo_header_data(BMI160_SEC_IF_BMM150,
  231. &header_data);
  232. break;
  233. case STANDARD_UI_IMU_FIFO:
  234. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  235. /* bmi160_delay_ms in ms*/
  236. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  237. /*Set the gyro mode as Normal write in the register 0x7E*/
  238. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  239. /* bmi160_delay_ms in ms*/
  240. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  241. /* Set the accel bandwidth as Normal */
  242. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
  243. s_bmi160.delay_msec(
  244. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  245. /* Set the gryo bandwidth as Normal */
  246. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  247. s_bmi160.delay_msec(
  248. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  249. /* set gyro data rate as 100Hz*/
  250. com_rslt += bmi160_set_gyro_output_data_rate(
  251. BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
  252. s_bmi160.delay_msec(
  253. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  254. /* set accel data rate as 100Hz*/
  255. com_rslt += bmi160_set_accel_output_data_rate(
  256. BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ,
  257. BMI160_ACCEL_OSR4_AVG1);
  258. s_bmi160.delay_msec(
  259. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  260. /***** read FIFO data based on interrupt*****/
  261. com_rslt += bmi160_interrupt_configuration();
  262. /* Enable the FIFO header*/
  263. com_rslt += bmi160_set_fifo_header_enable(FIFO_HEADER_ENABLE);
  264. s_bmi160.delay_msec(
  265. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  266. /* Enable the FIFO accel*/
  267. com_rslt += bmi160_set_fifo_accel_enable(FIFO_ACCEL_ENABLE);
  268. s_bmi160.delay_msec(
  269. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  270. /* Enable the FIFO gyro*/
  271. com_rslt += bmi160_set_fifo_gyro_enable(FIFO_GYRO_ENABLE);
  272. s_bmi160.delay_msec(
  273. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  274. /* Enable the FIFO time*/
  275. com_rslt += bmi160_set_fifo_time_enable(FIFO_TIME_ENABLE);
  276. s_bmi160.delay_msec(
  277. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  278. /* Enable FIFO water mark interrupts in INT_EN[1] */
  279. com_rslt += bmi160_set_intr_enable_1(BMI160_FIFO_WM_ENABLE,
  280. BMI160_ENABLE);
  281. /* Enable the FIFO water mark interrupt1*/
  282. com_rslt += bmi160_set_intr_fifo_wm(BMI160_INIT_VALUE,
  283. BMI160_ENABLE);
  284. s_bmi160.delay_msec(
  285. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  286. /* Enable the FIFO water mark interrupt2*/
  287. com_rslt += bmi160_set_intr_fifo_wm(BMI160_ENABLE,
  288. BMI160_ENABLE);
  289. s_bmi160.delay_msec(
  290. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  291. /* set the fifo water mark as 10*/
  292. com_rslt += bmi160_set_fifo_wm(BMI160_ENABLE_FIFO_WM);
  293. /* read the FIFO data*/
  294. com_rslt += bmi160_read_fifo_header_data(BMI160_SEC_IF_BMM150,
  295. &header_data);
  296. break;
  297. case STANDARD_UI_IMU:
  298. /*Set the accel mode as Normal write in the register 0x7E*/
  299. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  300. /* bmi160_delay_ms in ms*/
  301. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  302. /*Set the gyro mode as Normal write in the register 0x7E*/
  303. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  304. /* bmi160_delay_ms in ms*/
  305. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  306. /* Set the accel bandwidth as Normal */
  307. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
  308. s_bmi160.delay_msec(
  309. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  310. /* Set the gryo bandwidth as Normal */
  311. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  312. s_bmi160.delay_msec(
  313. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  314. /* set gyro data rate as 100Hz*/
  315. com_rslt += bmi160_set_gyro_output_data_rate(
  316. BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
  317. s_bmi160.delay_msec(
  318. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  319. /* set accel data rate as 100Hz*/
  320. com_rslt += bmi160_set_accel_output_data_rate(
  321. BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ,
  322. BMI160_ACCEL_OSR4_AVG1);
  323. s_bmi160.delay_msec(
  324. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  325. /* read gyro data*/
  326. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  327. /* read accel data*/
  328. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  329. break;
  330. case STANDARD_UI_ADVANCEPOWERSAVE:
  331. /*Set the accel mode as Normal write in the register 0x7E*/
  332. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  333. /* bmi160_delay_ms in ms*/
  334. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  335. /* Set the accel bandwidth as Normal */
  336. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
  337. s_bmi160.delay_msec(
  338. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  339. /* Set the gryo bandwidth as Normal */
  340. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  341. s_bmi160.delay_msec(
  342. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  343. /* set gyro data rate as 100Hz*/
  344. com_rslt += bmi160_set_gyro_output_data_rate(
  345. BMI160_GYRO_OUTPUT_DATA_RATE_100HZ);
  346. s_bmi160.delay_msec(
  347. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  348. /* set accel data rate as 100Hz*/
  349. com_rslt += bmi160_set_accel_output_data_rate(
  350. BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ,
  351. BMI160_ACCEL_OSR4_AVG1);
  352. s_bmi160.delay_msec(
  353. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  354. /* Enable any motion interrupt - x axis*/
  355. com_rslt += bmi160_set_intr_enable_0(BMI160_ANY_MOTION_X_ENABLE,
  356. BMI160_ENABLE);
  357. s_bmi160.delay_msec(
  358. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  359. /* Enable any motion interrupt - y axis*/
  360. com_rslt += bmi160_set_intr_enable_0(BMI160_ANY_MOTION_Y_ENABLE,
  361. BMI160_ENABLE);
  362. s_bmi160.delay_msec(
  363. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  364. /* Enable any motion interrupt - z axis*/
  365. com_rslt += bmi160_set_intr_enable_0(BMI160_ANY_MOTION_Z_ENABLE,
  366. BMI160_ENABLE);
  367. s_bmi160.delay_msec(
  368. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  369. /* Enable no motion interrupt - x axis*/
  370. com_rslt += bmi160_set_intr_enable_2(BMI160_NOMOTION_X_ENABLE,
  371. BMI160_ENABLE);
  372. s_bmi160.delay_msec(
  373. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  374. /* Enable no motion interrupt - y axis*/
  375. com_rslt += bmi160_set_intr_enable_2(BMI160_NOMOTION_Y_ENABLE,
  376. BMI160_ENABLE);
  377. s_bmi160.delay_msec(
  378. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  379. /* Enable no motion interrupt - z axis*/
  380. com_rslt += bmi160_set_intr_enable_2(BMI160_NOMOTION_Z_ENABLE,
  381. BMI160_ENABLE);
  382. s_bmi160.delay_msec(
  383. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  384. /* set the gyro sleep trigger*/
  385. com_rslt += bmi160_set_gyro_sleep_trigger(
  386. gyr_setting.sleep_trigger);
  387. s_bmi160.delay_msec(
  388. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  389. /* set the gyro wakeup trigger*/
  390. com_rslt += bmi160_set_gyro_wakeup_trigger(
  391. gyr_setting.wakeup_trigger);
  392. s_bmi160.delay_msec(
  393. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  394. /* set the gyro sleep state*/
  395. com_rslt += bmi160_set_gyro_sleep_state(
  396. gyr_setting.sleep_state);
  397. s_bmi160.delay_msec(
  398. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  399. /* set the gyro wakeup interrupt*/
  400. com_rslt += bmi160_set_gyro_wakeup_intr(gyr_setting.wakeup_int);
  401. s_bmi160.delay_msec(
  402. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  403. /* read gyro data*/
  404. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  405. /* read accel data*/
  406. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  407. break;
  408. case ACCEL_PEDOMETER:
  409. /*Set the accel mode as Normal write in the register 0x7E*/
  410. com_rslt = bmi160_set_command_register(ACCEL_LOWPOWER);
  411. /* bmi160_delay_ms in ms*/
  412. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  413. /*Set the gyro mode as SUSPEND write in the register 0x7E*/
  414. com_rslt += bmi160_set_command_register(GYRO_MODE_SUSPEND);
  415. /* bmi160_delay_ms in ms*/
  416. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  417. /* Set the accel bandwidth as OSR4 */
  418. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
  419. s_bmi160.delay_msec(
  420. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  421. /* set accel data rate as 25Hz*/
  422. com_rslt += bmi160_set_accel_output_data_rate(
  423. BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ,
  424. BMI160_ACCEL_OSR4_AVG1);
  425. /* 10 not available*/
  426. s_bmi160.delay_msec(
  427. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  428. /* read accel data*/
  429. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  430. break;
  431. case APPLICATION_HEAD_TRACKING:
  432. /*Set the accel mode as Normal write in the register 0x7E*/
  433. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  434. /* bmi160_delay_ms in ms*/
  435. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  436. /*Set the gyro mode as Normal write in the register 0x7E*/
  437. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  438. /* bmi160_delay_ms in ms*/
  439. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  440. /* Set the accel bandwidth as Normal */
  441. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_NORMAL_AVG4);
  442. s_bmi160.delay_msec(
  443. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  444. /* Set the gryo bandwidth as Normal */
  445. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  446. s_bmi160.delay_msec(
  447. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  448. /* set gyro data rate as 1600Hz*/
  449. com_rslt += bmi160_set_gyro_output_data_rate(
  450. BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ);
  451. s_bmi160.delay_msec(
  452. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  453. /* set accel data rate as 1600Hz*/
  454. com_rslt += bmi160_set_accel_output_data_rate(
  455. BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ, BMI160_ACCEL_OSR4_AVG1);
  456. s_bmi160.delay_msec(
  457. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  458. /* read gyro data*/
  459. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  460. /* read accel data */
  461. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  462. /* read mag data */
  463. com_rslt += bmi160_bmm150_mag_compensate_xyz(&magxyz);
  464. break;
  465. case APPLICATION_NAVIGATION:
  466. /*Set the accel mode as Normal write in the register 0x7E*/
  467. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  468. /* bmi160_delay_ms in ms*/
  469. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  470. /*Set the gyro mode as Normal write in the register 0x7E*/
  471. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  472. /* bmi160_delay_ms in ms*/
  473. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  474. /* Set the accel bandwidth as OSRS4 */
  475. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
  476. s_bmi160.delay_msec(
  477. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  478. /* Set the gryo bandwidth as Normal */
  479. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
  480. s_bmi160.delay_msec(
  481. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  482. /* set gyro data rate as 200Hz*/
  483. com_rslt += bmi160_set_gyro_output_data_rate(
  484. BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
  485. s_bmi160.delay_msec(
  486. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  487. /* set accel data rate as 200Hz*/
  488. com_rslt += bmi160_set_accel_output_data_rate(
  489. BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ,
  490. BMI160_ACCEL_OSR4_AVG1);
  491. s_bmi160.delay_msec(
  492. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  493. /* read gyro data*/
  494. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  495. /* read accel data */
  496. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  497. /* read mag data*/
  498. com_rslt += bmi160_bmm150_mag_compensate_xyz(&magxyz);
  499. break;
  500. case APPLICATION_REMOTE_CONTROL:
  501. /*Set the accel mode as Normal write in the register 0x7E*/
  502. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  503. /* bmi160_delay_ms in ms*/
  504. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  505. /*Set the gyro mode as Normal write in the register 0x7E*/
  506. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  507. /* bmi160_delay_ms in ms*/
  508. s_bmi160.delay_msec(BMI160_MODE_SWITCHING_DELAY);
  509. /* Set the accel bandwidth as OSRS4 */
  510. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
  511. s_bmi160.delay_msec(
  512. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  513. /* Set the gryo bandwidth as OSR4 */
  514. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_OSR4_MODE);
  515. s_bmi160.delay_msec(
  516. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  517. /* set gyro data rate as 200Hz*/
  518. com_rslt += bmi160_set_gyro_output_data_rate(
  519. BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
  520. s_bmi160.delay_msec(
  521. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  522. /* set accel data rate as 200Hz*/
  523. com_rslt += bmi160_set_accel_output_data_rate(
  524. BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ,
  525. BMI160_ACCEL_OSR4_AVG1);
  526. s_bmi160.delay_msec(
  527. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  528. /* read gyro data */
  529. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  530. /* read accel data*/
  531. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  532. break;
  533. case APPLICATION_INDOOR_NAVIGATION:
  534. /*Set the accel mode as Normal write in the register 0x7E*/
  535. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  536. s_bmi160.delay_msec(
  537. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  538. /*Set the gyro mode as Normal write in the register 0x7E*/
  539. com_rslt += bmi160_set_command_register(GYRO_MODE_NORMAL);
  540. s_bmi160.delay_msec(
  541. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  542. /* Set the accel bandwidth as OSRS4 */
  543. com_rslt += bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
  544. s_bmi160.delay_msec(
  545. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  546. /* Set the gryo bandwidth as OSR4 */
  547. com_rslt += bmi160_set_gyro_bw(BMI160_GYRO_OSR4_MODE);
  548. s_bmi160.delay_msec(
  549. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  550. /* set gyro data rate as 200Hz*/
  551. com_rslt += bmi160_set_gyro_output_data_rate(
  552. BMI160_GYRO_OUTPUT_DATA_RATE_400HZ);
  553. s_bmi160.delay_msec(
  554. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  555. /* set accel data rate as 200Hz*/
  556. com_rslt += bmi160_set_accel_output_data_rate(
  557. BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ,
  558. BMI160_ACCEL_OSR4_AVG1);
  559. s_bmi160.delay_msec(
  560. BMI160_GEN_READ_WRITE_DELAY);/* bmi160_delay_ms in ms*/
  561. /* read gyro data*/
  562. com_rslt += bmi160_read_gyro_xyz(&gyroxyz);
  563. /* read accel data */
  564. com_rslt += bmi160_read_accel_xyz(&accelxyz);
  565. break;
  566. }
  567. return com_rslt;
  568. }
  569. /*!
  570. * @brief This function used for interrupt configuration
  571. *
  572. *
  573. * @return results of bus communication function
  574. * @retval 0 -> Success
  575. * @retval 1 -> Error
  576. *
  577. *
  578. */
  579. BMI160_RETURN_FUNCTION_TYPE bmi160_interrupt_configuration(void)
  580. {
  581. /* This variable used for provide the communication
  582. results*/
  583. BMI160_RETURN_FUNCTION_TYPE com_rslt = ERROR;
  584. /* Configure the in/out control of interrupt1*/
  585. com_rslt = bmi160_set_output_enable(BMI160_INIT_VALUE,
  586. BMI160_ENABLE);
  587. s_bmi160.delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  588. /* Configure the in/out control of interrupt2*/
  589. com_rslt += bmi160_set_output_enable(BMI160_ENABLE,
  590. BMI160_ENABLE);
  591. s_bmi160.delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  592. /* Configure the interrupt1 active high
  593. 0x00 - Active low
  594. 0x01 - Active high*/
  595. com_rslt += bmi160_set_intr_level(BMI160_INIT_VALUE,
  596. BMI160_ENABLE);
  597. s_bmi160.delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  598. /* Configure the interrupt2 active high
  599. 0x00 - Active low
  600. 0x01 - Active high*/
  601. com_rslt += bmi160_set_intr_level(BMI160_ENABLE,
  602. BMI160_ENABLE);
  603. s_bmi160.delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  604. return com_rslt;
  605. }
  606. #ifdef INCLUDE_BMI160API
  607. #define MASK_DATA1 0xFF
  608. #define MASK_DATA2 0x80
  609. #define MASK_DATA3 0x7F
  610. /*!
  611. * @brief Used for I2C initialization
  612. * @note
  613. * The following function is used to map the
  614. * I2C bus read, write, bmi160_delay_ms and
  615. * device address with global structure bmi160_t
  616. */
  617. s8 i2c_routine(void)
  618. {
  619. /*--------------------------------------------------------------------------*
  620. * By using bmi160 the following structure parameter can be accessed
  621. * Bus write function pointer: BMI160_WR_FUNC_PTR
  622. * Bus read function pointer: BMI160_RD_FUNC_PTR
  623. * bmi160_delay_ms function pointer: bmi160_delay_ms_msec
  624. * I2C address: dev_addr
  625. *--------------------------------------------------------------------------*/
  626. struct_bmi160.bus_write = bmi160_i2c_bus_write;
  627. struct_bmi160.bus_read = bmi160_i2c_bus_read;
  628. struct_bmi160.delay_msec = bmi160_delay_ms;
  629. struct_bmi160.dev_addr = BMI160_I2C_ADDR2;
  630. return BMI160_INIT_VALUE;
  631. }
  632. /*!
  633. * @brief Used for SPI initialization
  634. * @note
  635. * The following function is used to map the
  636. * SPI bus read, write and bmi160_delay_ms
  637. * with global structure bmi160
  638. */
  639. s8 spi_routine(void)
  640. {
  641. /*--------------------------------------------------------------------------*
  642. * By using bmi160 the following structure parameter can be accessed
  643. * Bus write function pointer: BMI160_WR_FUNC_PTR
  644. * Bus read function pointer: BMI160_RD_FUNC_PTR
  645. * bmi160_delay_ms function pointer: bmi160_delay_ms_msec
  646. *--------------------------------------------------------------------------*/
  647. struct_bmi160.bus_write = bmi160_spi_bus_write;
  648. struct_bmi160.bus_read = bmi160_spi_bus_read;
  649. struct_bmi160.delay_msec = bmi160_delay_ms;
  650. return BMI160_INIT_VALUE;
  651. }
  652. /**************************************************************/
  653. /**\name I2C/SPI read write function */
  654. /**************************************************************/
  655. /*-------------------------------------------------------------------*
  656. *
  657. * This is a sample code for read and write the data by using I2C/SPI
  658. * Use either I2C or SPI based on your need
  659. * Configure the below code to your SPI or I2C driver
  660. *
  661. *-----------------------------------------------------------------------*/
  662. /*!
  663. * @brief : The function is used as I2C bus read
  664. * @return : Status of the I2C read
  665. * @param dev_addr : The device address of the sensor
  666. * @param reg_addr : Address of the first register, will data is going to be read
  667. * @param reg_data : This data read from the sensor, which is hold in an array
  668. * @param cnt : The no of byte of data to be read
  669. */
  670. s8 bmi160_i2c_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  671. {
  672. s32 ierror = BMI160_INIT_VALUE;
  673. #ifdef INCLUDE_BMI160API
  674. u8 array[I2C_BUFFER_LEN] = {BMI160_INIT_VALUE};
  675. u8 stringpos = BMI160_INIT_VALUE;
  676. array[BMI160_INIT_VALUE] = reg_addr;
  677. /* Please take the below function as your reference
  678. * for read the data using I2C communication
  679. * add your I2C rad function here.
  680. * "IERROR = I2C_WRITE_READ_STRING(DEV_ADDR, ARRAY, ARRAY, 1, CNT)"
  681. * iError is an return value of SPI write function
  682. * Please select your valid return value
  683. * In the driver SUCCESS defined as 0
  684. * and FAILURE defined as -1
  685. */
  686. for (stringpos = BMI160_INIT_VALUE; stringpos < cnt; stringpos++)
  687. *(reg_data + stringpos) = array[stringpos];
  688. #endif
  689. return (s8)ierror;
  690. }
  691. /*!
  692. * @brief : The function is used as I2C bus write
  693. * @return : Status of the I2C write
  694. * @param dev_addr : The device address of the sensor
  695. * @param reg_addr : Address of the first register,
  696. * will data is going to be written
  697. * @param reg_data : It is a value hold in the array,
  698. * will be used for write the value into the register
  699. * @param cnt : The no of byte of data to be write
  700. */
  701. s8 bmi160_i2c_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  702. {
  703. s32 ierror = BMI160_INIT_VALUE;
  704. #ifdef INCLUDE_BMI160API
  705. u8 array[I2C_BUFFER_LEN];
  706. u8 stringpos = BMI160_INIT_VALUE;
  707. array[0] = reg_addr;
  708. for (stringpos = BMI160_INIT_VALUE; stringpos
  709. < cnt; stringpos++)
  710. array[stringpos + BMI160_GEN_READ_WRITE_DATA_LENGTH]
  711. = *(reg_data + stringpos);
  712. /*
  713. * Please take the below function as your reference for
  714. * write the data using I2C communication
  715. * "IERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)"
  716. * add your I2C write function here
  717. * iError is an return value of I2C read function
  718. * Please select your valid return value
  719. * In the driver SUCCESS defined as 0
  720. * and FAILURE defined as -1
  721. * Note :
  722. * This is a full duplex operation,
  723. * The first read data is discarded, for that extra write operation
  724. * have to be initiated. For that cnt+1 operation done
  725. * in the I2C write string function
  726. * For more information please refer data sheet SPI communication:
  727. */
  728. #endif
  729. return (s8)ierror;
  730. }
  731. /*!
  732. * @brief : The function is used as SPI bus read
  733. * @return : Status of the SPI read
  734. * @param dev_addr : The device address of the sensor
  735. * @param reg_addr : Address of the first register,
  736. * will data is going to be read
  737. * @param reg_data : This data read from the sensor,
  738. * which is hold in an array
  739. * @param cnt : The no of byte of data to be read
  740. */
  741. s8 bmi160_spi_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  742. {
  743. s32 ierror = BMI160_INIT_VALUE;
  744. #ifdef INCLUDE_BMI160API
  745. u8 array[SPI_BUFFER_LEN] = {MASK_DATA1};
  746. u8 stringpos;
  747. /* For the SPI mode only 7 bits of register addresses are used.
  748. The MSB of register address is declared the bit what functionality it is
  749. read/write (read as 1/write as 0)*/
  750. array[BMI160_INIT_VALUE] = reg_addr|MASK_DATA2;
  751. /*
  752. * Please take the below function as your reference for
  753. * read the data using SPI communication
  754. * " IERROR = SPI_READ_WRITE_STRING(ARRAY, ARRAY, CNT+1)"
  755. * add your SPI read function here
  756. * ierror is an return value of SPI read function
  757. * Please select your valid return value
  758. * In the driver SUCCESS defined as 0
  759. * and FAILURE defined as -1
  760. * Note :
  761. * This is a full duplex operation,
  762. * The first read data is discarded, for that extra write operation
  763. * have to be initiated. For that cnt+1 operation done in the SPI read
  764. * and write string function
  765. * For more information please refer data sheet SPI communication:
  766. */
  767. for (stringpos = BMI160_INIT_VALUE; stringpos
  768. < cnt; stringpos++)
  769. *(reg_data + stringpos) = array[stringpos
  770. + BMI160_GEN_READ_WRITE_DATA_LENGTH];
  771. #endif
  772. return (s8)ierror;
  773. }
  774. /*!
  775. * @brief : The function is used as SPI bus write
  776. * @return : Status of the SPI write
  777. * @param dev_addr : The device address of the sensor
  778. * @param reg_addr : Address of the first register,
  779. * will data is going to be written
  780. * @param reg_data : It is a value hold in the array,
  781. * will be used for write the value into the register
  782. * @param cnt : The no of byte of data to be write
  783. */
  784. s8 bmi160_spi_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  785. {
  786. s32 ierror = BMI160_INIT_VALUE;
  787. #ifdef INCLUDE_BMI160API
  788. u8 array[SPI_BUFFER_LEN * C_BMI160_BYTE_COUNT];
  789. u8 stringpos = BMI160_INIT_VALUE;
  790. for (stringpos = BMI160_INIT_VALUE;
  791. stringpos < cnt; stringpos++) {
  792. /* the operation of (reg_addr++)&0x7F done:
  793. because it ensure the
  794. 0 and 1 of the given value
  795. It is done only for 8bit operation*/
  796. array[stringpos * C_BMI160_BYTE_COUNT] =
  797. (reg_addr++) & MASK_DATA3;
  798. array[stringpos * C_BMI160_BYTE_COUNT +
  799. BMI160_GEN_READ_WRITE_DATA_LENGTH] =
  800. *(reg_data + stringpos);
  801. }
  802. /* Please take the below function as your reference
  803. * for write the data using SPI communication
  804. * add your SPI write function here.
  805. * "IERROR = SPI_WRITE_STRING(ARRAY, CNT*2)"
  806. * ierror is an return value of SPI write function
  807. * Please select your valid return value
  808. * In the driver SUCCESS defined as 0
  809. * and FAILURE defined as -1
  810. */
  811. #endif
  812. return (s8)ierror;
  813. }
  814. #endif
  815. /*!
  816. * @brief This function is an example for delay
  817. * @param msec: delay in milli seconds
  818. * @return : communication result
  819. */
  820. void bmi160_delay_ms(u32 msec)
  821. {
  822. /* user delay*/
  823. }