bmi160_defs.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. /**
  2. * Copyright (C) 2015 - 2016 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 bmi160_defs.h
  43. * @date 11 Jan 2018
  44. * @version 3.7.5
  45. * @brief
  46. *
  47. */
  48. /*!
  49. * @defgroup bmi160_defs
  50. * @brief
  51. * @{*/
  52. #ifndef BMI160_DEFS_H_
  53. #define BMI160_DEFS_H_
  54. /*************************** C types headers *****************************/
  55. #ifdef __KERNEL__
  56. #include <linux/types.h>
  57. #include <linux/kernel.h>
  58. #else
  59. #include <stdint.h>
  60. #include <stddef.h>
  61. #endif
  62. /*************************** Common macros *****************************/
  63. #if !defined(UINT8_C) && !defined(INT8_C)
  64. #define INT8_C(x) S8_C(x)
  65. #define UINT8_C(x) U8_C(x)
  66. #endif
  67. #if !defined(UINT16_C) && !defined(INT16_C)
  68. #define INT16_C(x) S16_C(x)
  69. #define UINT16_C(x) U16_C(x)
  70. #endif
  71. #if !defined(INT32_C) && !defined(UINT32_C)
  72. #define INT32_C(x) S32_C(x)
  73. #define UINT32_C(x) U32_C(x)
  74. #endif
  75. #if !defined(INT64_C) && !defined(UINT64_C)
  76. #define INT64_C(x) S64_C(x)
  77. #define UINT64_C(x) U64_C(x)
  78. #endif
  79. /**@}*/
  80. /**\name C standard macros */
  81. #ifndef NULL
  82. #ifdef __cplusplus
  83. #define NULL 0
  84. #else
  85. #define NULL ((void *) 0)
  86. #endif
  87. #endif
  88. /*************************** Sensor macros *****************************/
  89. /* Test for an endian machine */
  90. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  91. #define LITTLE_ENDIAN 1
  92. #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  93. #define BIG_ENDIAN 1
  94. #else
  95. #error "Code does not support Endian format of the processor"
  96. #endif
  97. /** Mask definitions */
  98. #define BMI160_ACCEL_BW_MASK UINT8_C(0x70)
  99. #define BMI160_ACCEL_ODR_MASK UINT8_C(0x0F)
  100. #define BMI160_ACCEL_UNDERSAMPLING_MASK UINT8_C(0x80)
  101. #define BMI160_ACCEL_RANGE_MASK UINT8_C(0x0F)
  102. #define BMI160_GYRO_BW_MASK UINT8_C(0x30)
  103. #define BMI160_GYRO_ODR_MASK UINT8_C(0x0F)
  104. #define BMI160_GYRO_RANGE_MSK UINT8_C(0x07)
  105. /** Mask definitions for INT_EN registers */
  106. #define BMI160_ANY_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  107. #define BMI160_HIGH_G_X_INT_EN_MASK UINT8_C(0x01)
  108. #define BMI160_NO_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  109. #define BMI160_ANY_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  110. #define BMI160_HIGH_G_Y_INT_EN_MASK UINT8_C(0x02)
  111. #define BMI160_NO_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  112. #define BMI160_ANY_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  113. #define BMI160_HIGH_G_Z_INT_EN_MASK UINT8_C(0x04)
  114. #define BMI160_NO_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  115. #define BMI160_SIG_MOTION_INT_EN_MASK UINT8_C(0x07)
  116. #define BMI160_ANY_MOTION_ALL_INT_EN_MASK UINT8_C(0x07)
  117. #define BMI160_STEP_DETECT_INT_EN_MASK UINT8_C(0x08)
  118. #define BMI160_DOUBLE_TAP_INT_EN_MASK UINT8_C(0x10)
  119. #define BMI160_SINGLE_TAP_INT_EN_MASK UINT8_C(0x20)
  120. #define BMI160_FIFO_FULL_INT_EN_MASK UINT8_C(0x20)
  121. #define BMI160_ORIENT_INT_EN_MASK UINT8_C(0x40)
  122. #define BMI160_FIFO_WATERMARK_INT_EN_MASK UINT8_C(0x40)
  123. #define BMI160_LOW_G_INT_EN_MASK UINT8_C(0x08)
  124. #define BMI160_STEP_DETECT_EN_MASK UINT8_C(0x08)
  125. #define BMI160_FLAT_INT_EN_MASK UINT8_C(0x80)
  126. #define BMI160_DATA_RDY_INT_EN_MASK UINT8_C(0x10)
  127. /** PMU status Macros */
  128. #define BMI160_AUX_PMU_SUSPEND UINT8_C(0x00)
  129. #define BMI160_AUX_PMU_NORMAL UINT8_C(0x01)
  130. #define BMI160_AUX_PMU_LOW_POWER UINT8_C(0x02)
  131. #define BMI160_GYRO_PMU_SUSPEND UINT8_C(0x00)
  132. #define BMI160_GYRO_PMU_NORMAL UINT8_C(0x01)
  133. #define BMI160_GYRO_PMU_FSU UINT8_C(0x03)
  134. #define BMI160_ACCEL_PMU_SUSPEND UINT8_C(0x00)
  135. #define BMI160_ACCEL_PMU_NORMAL UINT8_C(0x01)
  136. #define BMI160_ACCEL_PMU_LOW_POWER UINT8_C(0x02)
  137. /** Mask definitions for INT_OUT_CTRL register */
  138. #define BMI160_INT1_EDGE_CTRL_MASK UINT8_C(0x01)
  139. #define BMI160_INT1_OUTPUT_MODE_MASK UINT8_C(0x04)
  140. #define BMI160_INT1_OUTPUT_TYPE_MASK UINT8_C(0x02)
  141. #define BMI160_INT1_OUTPUT_EN_MASK UINT8_C(0x08)
  142. #define BMI160_INT2_EDGE_CTRL_MASK UINT8_C(0x10)
  143. #define BMI160_INT2_OUTPUT_MODE_MASK UINT8_C(0x40)
  144. #define BMI160_INT2_OUTPUT_TYPE_MASK UINT8_C(0x20)
  145. #define BMI160_INT2_OUTPUT_EN_MASK UINT8_C(0x80)
  146. /** Mask definitions for INT_LATCH register */
  147. #define BMI160_INT1_INPUT_EN_MASK UINT8_C(0x10)
  148. #define BMI160_INT2_INPUT_EN_MASK UINT8_C(0x20)
  149. #define BMI160_INT_LATCH_MASK UINT8_C(0x0F)
  150. /** Mask definitions for INT_MAP register */
  151. #define BMI160_INT1_LOW_G_MASK UINT8_C(0x01)
  152. #define BMI160_INT1_HIGH_G_MASK UINT8_C(0x02)
  153. #define BMI160_INT1_SLOPE_MASK UINT8_C(0x04)
  154. #define BMI160_INT1_NO_MOTION_MASK UINT8_C(0x08)
  155. #define BMI160_INT1_DOUBLE_TAP_MASK UINT8_C(0x10)
  156. #define BMI160_INT1_SINGLE_TAP_MASK UINT8_C(0x20)
  157. #define BMI160_INT1_FIFO_FULL_MASK UINT8_C(0x20)
  158. #define BMI160_INT1_FIFO_WM_MASK UINT8_C(0x40)
  159. #define BMI160_INT1_ORIENT_MASK UINT8_C(0x40)
  160. #define BMI160_INT1_FLAT_MASK UINT8_C(0x80)
  161. #define BMI160_INT1_DATA_READY_MASK UINT8_C(0x80)
  162. #define BMI160_INT2_LOW_G_MASK UINT8_C(0x01)
  163. #define BMI160_INT1_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  164. #define BMI160_INT2_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  165. #define BMI160_INT2_HIGH_G_MASK UINT8_C(0x02)
  166. #define BMI160_INT2_FIFO_FULL_MASK UINT8_C(0x02)
  167. #define BMI160_INT2_FIFO_WM_MASK UINT8_C(0x04)
  168. #define BMI160_INT2_SLOPE_MASK UINT8_C(0x04)
  169. #define BMI160_INT2_DATA_READY_MASK UINT8_C(0x08)
  170. #define BMI160_INT2_NO_MOTION_MASK UINT8_C(0x08)
  171. #define BMI160_INT2_DOUBLE_TAP_MASK UINT8_C(0x10)
  172. #define BMI160_INT2_SINGLE_TAP_MASK UINT8_C(0x20)
  173. #define BMI160_INT2_ORIENT_MASK UINT8_C(0x40)
  174. #define BMI160_INT2_FLAT_MASK UINT8_C(0x80)
  175. /** Mask definitions for INT_DATA register */
  176. #define BMI160_TAP_SRC_INT_MASK UINT8_C(0x08)
  177. #define BMI160_LOW_HIGH_SRC_INT_MASK UINT8_C(0x80)
  178. #define BMI160_MOTION_SRC_INT_MASK UINT8_C(0x80)
  179. /** Mask definitions for INT_MOTION register */
  180. #define BMI160_SLOPE_INT_DUR_MASK UINT8_C(0x03)
  181. #define BMI160_NO_MOTION_INT_DUR_MASK UINT8_C(0xFC)
  182. #define BMI160_NO_MOTION_SEL_BIT_MASK UINT8_C(0x01)
  183. /** Mask definitions for INT_TAP register */
  184. #define BMI160_TAP_DUR_MASK UINT8_C(0x07)
  185. #define BMI160_TAP_SHOCK_DUR_MASK UINT8_C(0x40)
  186. #define BMI160_TAP_QUIET_DUR_MASK UINT8_C(0x80)
  187. #define BMI160_TAP_THRES_MASK UINT8_C(0x1F)
  188. /** Mask definitions for INT_FLAT register */
  189. #define BMI160_FLAT_THRES_MASK UINT8_C(0x3F)
  190. #define BMI160_FLAT_HOLD_TIME_MASK UINT8_C(0x30)
  191. #define BMI160_FLAT_HYST_MASK UINT8_C(0x07)
  192. /** Mask definitions for INT_LOWHIGH register */
  193. #define BMI160_LOW_G_HYST_MASK UINT8_C(0x03)
  194. #define BMI160_LOW_G_LOW_MODE_MASK UINT8_C(0x04)
  195. #define BMI160_HIGH_G_HYST_MASK UINT8_C(0xC0)
  196. /** Mask definitions for INT_SIG_MOTION register */
  197. #define BMI160_SIG_MOTION_SEL_MASK UINT8_C(0x02)
  198. #define BMI160_SIG_MOTION_SKIP_MASK UINT8_C(0x0C)
  199. #define BMI160_SIG_MOTION_PROOF_MASK UINT8_C(0x30)
  200. /** Mask definitions for INT_ORIENT register */
  201. #define BMI160_ORIENT_MODE_MASK UINT8_C(0x03)
  202. #define BMI160_ORIENT_BLOCK_MASK UINT8_C(0x0C)
  203. #define BMI160_ORIENT_HYST_MASK UINT8_C(0xF0)
  204. #define BMI160_ORIENT_THETA_MASK UINT8_C(0x3F)
  205. #define BMI160_ORIENT_UD_ENABLE UINT8_C(0x40)
  206. #define BMI160_AXES_EN_MASK UINT8_C(0x80)
  207. /** Mask definitions for FIFO_CONFIG register */
  208. #define BMI160_FIFO_GYRO UINT8_C(0x80)
  209. #define BMI160_FIFO_ACCEL UINT8_C(0x40)
  210. #define BMI160_FIFO_AUX UINT8_C(0x20)
  211. #define BMI160_FIFO_TAG_INT1 UINT8_C(0x08)
  212. #define BMI160_FIFO_TAG_INT2 UINT8_C(0x04)
  213. #define BMI160_FIFO_TIME UINT8_C(0x02)
  214. #define BMI160_FIFO_HEADER UINT8_C(0x10)
  215. #define BMI160_FIFO_CONFIG_1_MASK UINT8_C(0xFE)
  216. /** Mask definitions for STEP_CONF register */
  217. #define BMI160_STEP_COUNT_EN_BIT_MASK UINT8_C(0x08)
  218. #define BMI160_STEP_DETECT_MIN_THRES_MASK UINT8_C(0x18)
  219. #define BMI160_STEP_DETECT_STEPTIME_MIN_MASK UINT8_C(0x07)
  220. #define BMI160_STEP_MIN_BUF_MASK UINT8_C(0x07)
  221. /** Mask definition for FIFO Header Data Tag */
  222. #define BMI160_FIFO_TAG_INTR_MASK UINT8_C(0xFC)
  223. /** Fifo byte counter mask definitions */
  224. #define BMI160_FIFO_BYTE_COUNTER_MASK UINT8_C(0x07)
  225. /** Enable/disable bit value */
  226. #define BMI160_ENABLE UINT8_C(0x01)
  227. #define BMI160_DISABLE UINT8_C(0x00)
  228. /** Latch Duration */
  229. #define BMI160_LATCH_DUR_NONE UINT8_C(0x00)
  230. #define BMI160_LATCH_DUR_312_5_MICRO_SEC UINT8_C(0x01)
  231. #define BMI160_LATCH_DUR_625_MICRO_SEC UINT8_C(0x02)
  232. #define BMI160_LATCH_DUR_1_25_MILLI_SEC UINT8_C(0x03)
  233. #define BMI160_LATCH_DUR_2_5_MILLI_SEC UINT8_C(0x04)
  234. #define BMI160_LATCH_DUR_5_MILLI_SEC UINT8_C(0x05)
  235. #define BMI160_LATCH_DUR_10_MILLI_SEC UINT8_C(0x06)
  236. #define BMI160_LATCH_DUR_20_MILLI_SEC UINT8_C(0x07)
  237. #define BMI160_LATCH_DUR_40_MILLI_SEC UINT8_C(0x08)
  238. #define BMI160_LATCH_DUR_80_MILLI_SEC UINT8_C(0x09)
  239. #define BMI160_LATCH_DUR_160_MILLI_SEC UINT8_C(0x0A)
  240. #define BMI160_LATCH_DUR_320_MILLI_SEC UINT8_C(0x0B)
  241. #define BMI160_LATCH_DUR_640_MILLI_SEC UINT8_C(0x0C)
  242. #define BMI160_LATCH_DUR_1_28_SEC UINT8_C(0x0D)
  243. #define BMI160_LATCH_DUR_2_56_SEC UINT8_C(0x0E)
  244. #define BMI160_LATCHED UINT8_C(0x0F)
  245. /** BMI160 Register map */
  246. #define BMI160_CHIP_ID_ADDR UINT8_C(0x00)
  247. #define BMI160_ERROR_REG_ADDR UINT8_C(0x02)
  248. #define BMI160_PMU_STATUS_ADDR UINT8_C(0x03)
  249. #define BMI160_AUX_DATA_ADDR UINT8_C(0x04)
  250. #define BMI160_GYRO_DATA_ADDR UINT8_C(0x0C)
  251. #define BMI160_ACCEL_DATA_ADDR UINT8_C(0x12)
  252. #define BMI160_STATUS_ADDR UINT8_C(0x1B)
  253. #define BMI160_INT_STATUS_ADDR UINT8_C(0x1C)
  254. #define BMI160_FIFO_LENGTH_ADDR UINT8_C(0x22)
  255. #define BMI160_FIFO_DATA_ADDR UINT8_C(0x24)
  256. #define BMI160_ACCEL_CONFIG_ADDR UINT8_C(0x40)
  257. #define BMI160_ACCEL_RANGE_ADDR UINT8_C(0x41)
  258. #define BMI160_GYRO_CONFIG_ADDR UINT8_C(0x42)
  259. #define BMI160_GYRO_RANGE_ADDR UINT8_C(0x43)
  260. #define BMI160_AUX_ODR_ADDR UINT8_C(0x44)
  261. #define BMI160_FIFO_DOWN_ADDR UINT8_C(0x45)
  262. #define BMI160_FIFO_CONFIG_0_ADDR UINT8_C(0x46)
  263. #define BMI160_FIFO_CONFIG_1_ADDR UINT8_C(0x47)
  264. #define BMI160_AUX_IF_0_ADDR UINT8_C(0x4B)
  265. #define BMI160_AUX_IF_1_ADDR UINT8_C(0x4C)
  266. #define BMI160_AUX_IF_2_ADDR UINT8_C(0x4D)
  267. #define BMI160_AUX_IF_3_ADDR UINT8_C(0x4E)
  268. #define BMI160_AUX_IF_4_ADDR UINT8_C(0x4F)
  269. #define BMI160_INT_ENABLE_0_ADDR UINT8_C(0x50)
  270. #define BMI160_INT_ENABLE_1_ADDR UINT8_C(0x51)
  271. #define BMI160_INT_ENABLE_2_ADDR UINT8_C(0x52)
  272. #define BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53)
  273. #define BMI160_INT_LATCH_ADDR UINT8_C(0x54)
  274. #define BMI160_INT_MAP_0_ADDR UINT8_C(0x55)
  275. #define BMI160_INT_MAP_1_ADDR UINT8_C(0x56)
  276. #define BMI160_INT_MAP_2_ADDR UINT8_C(0x57)
  277. #define BMI160_INT_DATA_0_ADDR UINT8_C(0x58)
  278. #define BMI160_INT_DATA_1_ADDR UINT8_C(0x59)
  279. #define BMI160_INT_LOWHIGH_0_ADDR UINT8_C(0x5A)
  280. #define BMI160_INT_LOWHIGH_1_ADDR UINT8_C(0x5B)
  281. #define BMI160_INT_LOWHIGH_2_ADDR UINT8_C(0x5C)
  282. #define BMI160_INT_LOWHIGH_3_ADDR UINT8_C(0x5D)
  283. #define BMI160_INT_LOWHIGH_4_ADDR UINT8_C(0x5E)
  284. #define BMI160_INT_MOTION_0_ADDR UINT8_C(0x5F)
  285. #define BMI160_INT_MOTION_1_ADDR UINT8_C(0x60)
  286. #define BMI160_INT_MOTION_2_ADDR UINT8_C(0x61)
  287. #define BMI160_INT_MOTION_3_ADDR UINT8_C(0x62)
  288. #define BMI160_INT_TAP_0_ADDR UINT8_C(0x63)
  289. #define BMI160_INT_TAP_1_ADDR UINT8_C(0x64)
  290. #define BMI160_INT_ORIENT_0_ADDR UINT8_C(0x65)
  291. #define BMI160_INT_ORIENT_1_ADDR UINT8_C(0x66)
  292. #define BMI160_INT_FLAT_0_ADDR UINT8_C(0x67)
  293. #define BMI160_INT_FLAT_1_ADDR UINT8_C(0x68)
  294. #define BMI160_FOC_CONF_ADDR UINT8_C(0x69)
  295. #define BMI160_CONF_ADDR UINT8_C(0x6A)
  296. #define BMI160_IF_CONF_ADDR UINT8_C(0x6B)
  297. #define BMI160_SELF_TEST_ADDR UINT8_C(0x6D)
  298. #define BMI160_OFFSET_ADDR UINT8_C(0x71)
  299. #define BMI160_OFFSET_CONF_ADDR UINT8_C(0x77)
  300. #define BMI160_INT_STEP_CNT_0_ADDR UINT8_C(0x78)
  301. #define BMI160_INT_STEP_CONFIG_0_ADDR UINT8_C(0x7A)
  302. #define BMI160_INT_STEP_CONFIG_1_ADDR UINT8_C(0x7B)
  303. #define BMI160_COMMAND_REG_ADDR UINT8_C(0x7E)
  304. #define BMI160_SPI_COMM_TEST_ADDR UINT8_C(0x7F)
  305. #define BMI160_INTL_PULLUP_CONF_ADDR UINT8_C(0x85)
  306. /** Error code definitions */
  307. #define BMI160_OK INT8_C(0)
  308. #define BMI160_E_NULL_PTR INT8_C(-1)
  309. #define BMI160_E_COM_FAIL INT8_C(-2)
  310. #define BMI160_E_DEV_NOT_FOUND INT8_C(-3)
  311. #define BMI160_E_OUT_OF_RANGE INT8_C(-4)
  312. #define BMI160_E_INVALID_INPUT INT8_C(-5)
  313. #define BMI160_E_ACCEL_ODR_BW_INVALID INT8_C(-6)
  314. #define BMI160_E_GYRO_ODR_BW_INVALID INT8_C(-7)
  315. #define BMI160_E_LWP_PRE_FLTR_INT_INVALID INT8_C(-8)
  316. #define BMI160_E_LWP_PRE_FLTR_INVALID INT8_C(-9)
  317. #define BMI160_E_AUX_NOT_FOUND INT8_C(-10)
  318. #define BMI160_FOC_FAILURE INT8_C(-11)
  319. /**\name API warning codes */
  320. #define BMI160_W_GYRO_SELF_TEST_FAIL INT8_C(1)
  321. #define BMI160_W_ACCEl_SELF_TEST_FAIL INT8_C(2)
  322. /** BMI160 unique chip identifier */
  323. #define BMI160_CHIP_ID UINT8_C(0xD1)
  324. /** Soft reset command */
  325. #define BMI160_SOFT_RESET_CMD UINT8_C(0xb6)
  326. #define BMI160_SOFT_RESET_DELAY_MS UINT8_C(15)
  327. /** Start FOC command */
  328. #define BMI160_START_FOC_CMD UINT8_C(0x03)
  329. /** NVM backup enabling command */
  330. #define BMI160_NVM_BACKUP_EN UINT8_C(0xA0)
  331. /* Delay in ms settings */
  332. #define BMI160_ACCEL_DELAY_MS UINT8_C(5)
  333. #define BMI160_GYRO_DELAY_MS UINT8_C(81)
  334. #define BMI160_ONE_MS_DELAY UINT8_C(1)
  335. #define BMI160_AUX_COM_DELAY UINT8_C(10)
  336. #define BMI160_GYRO_SELF_TEST_DELAY UINT8_C(20)
  337. #define BMI160_ACCEL_SELF_TEST_DELAY UINT8_C(50)
  338. /** Self test configurations */
  339. #define BMI160_ACCEL_SELF_TEST_CONFIG UINT8_C(0x2C)
  340. #define BMI160_ACCEL_SELF_TEST_POSITIVE_EN UINT8_C(0x0D)
  341. #define BMI160_ACCEL_SELF_TEST_NEGATIVE_EN UINT8_C(0x09)
  342. #define BMI160_ACCEL_SELF_TEST_LIMIT UINT16_C(8192)
  343. /** Power mode settings */
  344. /* Accel power mode */
  345. #define BMI160_ACCEL_NORMAL_MODE UINT8_C(0x11)
  346. #define BMI160_ACCEL_LOWPOWER_MODE UINT8_C(0x12)
  347. #define BMI160_ACCEL_SUSPEND_MODE UINT8_C(0x10)
  348. /* Gyro power mode */
  349. #define BMI160_GYRO_SUSPEND_MODE UINT8_C(0x14)
  350. #define BMI160_GYRO_NORMAL_MODE UINT8_C(0x15)
  351. #define BMI160_GYRO_FASTSTARTUP_MODE UINT8_C(0x17)
  352. /* Aux power mode */
  353. #define BMI160_AUX_SUSPEND_MODE UINT8_C(0x18)
  354. #define BMI160_AUX_NORMAL_MODE UINT8_C(0x19)
  355. #define BMI160_AUX_LOWPOWER_MODE UINT8_C(0x1A)
  356. /** Range settings */
  357. /* Accel Range */
  358. #define BMI160_ACCEL_RANGE_2G UINT8_C(0x03)
  359. #define BMI160_ACCEL_RANGE_4G UINT8_C(0x05)
  360. #define BMI160_ACCEL_RANGE_8G UINT8_C(0x08)
  361. #define BMI160_ACCEL_RANGE_16G UINT8_C(0x0C)
  362. /* Gyro Range */
  363. #define BMI160_GYRO_RANGE_2000_DPS UINT8_C(0x00)
  364. #define BMI160_GYRO_RANGE_1000_DPS UINT8_C(0x01)
  365. #define BMI160_GYRO_RANGE_500_DPS UINT8_C(0x02)
  366. #define BMI160_GYRO_RANGE_250_DPS UINT8_C(0x03)
  367. #define BMI160_GYRO_RANGE_125_DPS UINT8_C(0x04)
  368. /** Bandwidth settings */
  369. /* Accel Bandwidth */
  370. #define BMI160_ACCEL_BW_OSR4_AVG1 UINT8_C(0x00)
  371. #define BMI160_ACCEL_BW_OSR2_AVG2 UINT8_C(0x01)
  372. #define BMI160_ACCEL_BW_NORMAL_AVG4 UINT8_C(0x02)
  373. #define BMI160_ACCEL_BW_RES_AVG8 UINT8_C(0x03)
  374. #define BMI160_ACCEL_BW_RES_AVG16 UINT8_C(0x04)
  375. #define BMI160_ACCEL_BW_RES_AVG32 UINT8_C(0x05)
  376. #define BMI160_ACCEL_BW_RES_AVG64 UINT8_C(0x06)
  377. #define BMI160_ACCEL_BW_RES_AVG128 UINT8_C(0x07)
  378. #define BMI160_GYRO_BW_OSR4_MODE UINT8_C(0x00)
  379. #define BMI160_GYRO_BW_OSR2_MODE UINT8_C(0x01)
  380. #define BMI160_GYRO_BW_NORMAL_MODE UINT8_C(0x02)
  381. /* Output Data Rate settings */
  382. /* Accel Output data rate */
  383. #define BMI160_ACCEL_ODR_RESERVED UINT8_C(0x00)
  384. #define BMI160_ACCEL_ODR_0_78HZ UINT8_C(0x01)
  385. #define BMI160_ACCEL_ODR_1_56HZ UINT8_C(0x02)
  386. #define BMI160_ACCEL_ODR_3_12HZ UINT8_C(0x03)
  387. #define BMI160_ACCEL_ODR_6_25HZ UINT8_C(0x04)
  388. #define BMI160_ACCEL_ODR_12_5HZ UINT8_C(0x05)
  389. #define BMI160_ACCEL_ODR_25HZ UINT8_C(0x06)
  390. #define BMI160_ACCEL_ODR_50HZ UINT8_C(0x07)
  391. #define BMI160_ACCEL_ODR_100HZ UINT8_C(0x08)
  392. #define BMI160_ACCEL_ODR_200HZ UINT8_C(0x09)
  393. #define BMI160_ACCEL_ODR_400HZ UINT8_C(0x0A)
  394. #define BMI160_ACCEL_ODR_800HZ UINT8_C(0x0B)
  395. #define BMI160_ACCEL_ODR_1600HZ UINT8_C(0x0C)
  396. #define BMI160_ACCEL_ODR_RESERVED0 UINT8_C(0x0D)
  397. #define BMI160_ACCEL_ODR_RESERVED1 UINT8_C(0x0E)
  398. #define BMI160_ACCEL_ODR_RESERVED2 UINT8_C(0x0F)
  399. /* Gyro Output data rate */
  400. #define BMI160_GYRO_ODR_RESERVED UINT8_C(0x00)
  401. #define BMI160_GYRO_ODR_25HZ UINT8_C(0x06)
  402. #define BMI160_GYRO_ODR_50HZ UINT8_C(0x07)
  403. #define BMI160_GYRO_ODR_100HZ UINT8_C(0x08)
  404. #define BMI160_GYRO_ODR_200HZ UINT8_C(0x09)
  405. #define BMI160_GYRO_ODR_400HZ UINT8_C(0x0A)
  406. #define BMI160_GYRO_ODR_800HZ UINT8_C(0x0B)
  407. #define BMI160_GYRO_ODR_1600HZ UINT8_C(0x0C)
  408. #define BMI160_GYRO_ODR_3200HZ UINT8_C(0x0D)
  409. /* Auxiliary sensor Output data rate */
  410. #define BMI160_AUX_ODR_RESERVED UINT8_C(0x00)
  411. #define BMI160_AUX_ODR_0_78HZ UINT8_C(0x01)
  412. #define BMI160_AUX_ODR_1_56HZ UINT8_C(0x02)
  413. #define BMI160_AUX_ODR_3_12HZ UINT8_C(0x03)
  414. #define BMI160_AUX_ODR_6_25HZ UINT8_C(0x04)
  415. #define BMI160_AUX_ODR_12_5HZ UINT8_C(0x05)
  416. #define BMI160_AUX_ODR_25HZ UINT8_C(0x06)
  417. #define BMI160_AUX_ODR_50HZ UINT8_C(0x07)
  418. #define BMI160_AUX_ODR_100HZ UINT8_C(0x08)
  419. #define BMI160_AUX_ODR_200HZ UINT8_C(0x09)
  420. #define BMI160_AUX_ODR_400HZ UINT8_C(0x0A)
  421. #define BMI160_AUX_ODR_800HZ UINT8_C(0x0B)
  422. /* Maximum limits definition */
  423. #define BMI160_ACCEL_ODR_MAX UINT8_C(15)
  424. #define BMI160_ACCEL_BW_MAX UINT8_C(2)
  425. #define BMI160_ACCEL_RANGE_MAX UINT8_C(12)
  426. #define BMI160_GYRO_ODR_MAX UINT8_C(13)
  427. #define BMI160_GYRO_BW_MAX UINT8_C(2)
  428. #define BMI160_GYRO_RANGE_MAX UINT8_C(4)
  429. /** FIFO_CONFIG Definitions */
  430. #define BMI160_FIFO_TIME_ENABLE UINT8_C(0x02)
  431. #define BMI160_FIFO_TAG_INT2_ENABLE UINT8_C(0x04)
  432. #define BMI160_FIFO_TAG_INT1_ENABLE UINT8_C(0x08)
  433. #define BMI160_FIFO_HEAD_ENABLE UINT8_C(0x10)
  434. #define BMI160_FIFO_M_ENABLE UINT8_C(0x20)
  435. #define BMI160_FIFO_A_ENABLE UINT8_C(0x40)
  436. #define BMI160_FIFO_M_A_ENABLE UINT8_C(0x60)
  437. #define BMI160_FIFO_G_ENABLE UINT8_C(0x80)
  438. #define BMI160_FIFO_M_G_ENABLE UINT8_C(0xA0)
  439. #define BMI160_FIFO_G_A_ENABLE UINT8_C(0xC0)
  440. #define BMI160_FIFO_M_G_A_ENABLE UINT8_C(0xE0)
  441. /* Macro to specify the number of bytes over-read from the
  442. * FIFO in order to get the sensor time at the end of FIFO */
  443. #ifndef BMI160_FIFO_BYTES_OVERREAD
  444. #define BMI160_FIFO_BYTES_OVERREAD UINT8_C(25)
  445. #endif
  446. /* Accel, gyro and aux. sensor length and also their combined
  447. * length definitions in FIFO */
  448. #define BMI160_FIFO_G_LENGTH UINT8_C(6)
  449. #define BMI160_FIFO_A_LENGTH UINT8_C(6)
  450. #define BMI160_FIFO_M_LENGTH UINT8_C(8)
  451. #define BMI160_FIFO_GA_LENGTH UINT8_C(12)
  452. #define BMI160_FIFO_MA_LENGTH UINT8_C(14)
  453. #define BMI160_FIFO_MG_LENGTH UINT8_C(14)
  454. #define BMI160_FIFO_MGA_LENGTH UINT8_C(20)
  455. /** FIFO Header Data definitions */
  456. #define BMI160_FIFO_HEAD_SKIP_FRAME UINT8_C(0x40)
  457. #define BMI160_FIFO_HEAD_SENSOR_TIME UINT8_C(0x44)
  458. #define BMI160_FIFO_HEAD_INPUT_CONFIG UINT8_C(0x48)
  459. #define BMI160_FIFO_HEAD_OVER_READ UINT8_C(0x80)
  460. #define BMI160_FIFO_HEAD_A UINT8_C(0x84)
  461. #define BMI160_FIFO_HEAD_G UINT8_C(0x88)
  462. #define BMI160_FIFO_HEAD_G_A UINT8_C(0x8C)
  463. #define BMI160_FIFO_HEAD_M UINT8_C(0x90)
  464. #define BMI160_FIFO_HEAD_M_A UINT8_C(0x94)
  465. #define BMI160_FIFO_HEAD_M_G UINT8_C(0x98)
  466. #define BMI160_FIFO_HEAD_M_G_A UINT8_C(0x9C)
  467. /** FIFO sensor time length definitions */
  468. #define BMI160_SENSOR_TIME_LENGTH UINT8_C(3)
  469. /** FIFO DOWN selection */
  470. /* Accel fifo down-sampling values*/
  471. #define BMI160_ACCEL_FIFO_DOWN_ZERO UINT8_C(0x00)
  472. #define BMI160_ACCEL_FIFO_DOWN_ONE UINT8_C(0x10)
  473. #define BMI160_ACCEL_FIFO_DOWN_TWO UINT8_C(0x20)
  474. #define BMI160_ACCEL_FIFO_DOWN_THREE UINT8_C(0x30)
  475. #define BMI160_ACCEL_FIFO_DOWN_FOUR UINT8_C(0x40)
  476. #define BMI160_ACCEL_FIFO_DOWN_FIVE UINT8_C(0x50)
  477. #define BMI160_ACCEL_FIFO_DOWN_SIX UINT8_C(0x60)
  478. #define BMI160_ACCEL_FIFO_DOWN_SEVEN UINT8_C(0x70)
  479. /* Gyro fifo down-smapling values*/
  480. #define BMI160_GYRO_FIFO_DOWN_ZERO UINT8_C(0x00)
  481. #define BMI160_GYRO_FIFO_DOWN_ONE UINT8_C(0x01)
  482. #define BMI160_GYRO_FIFO_DOWN_TWO UINT8_C(0x02)
  483. #define BMI160_GYRO_FIFO_DOWN_THREE UINT8_C(0x03)
  484. #define BMI160_GYRO_FIFO_DOWN_FOUR UINT8_C(0x04)
  485. #define BMI160_GYRO_FIFO_DOWN_FIVE UINT8_C(0x05)
  486. #define BMI160_GYRO_FIFO_DOWN_SIX UINT8_C(0x06)
  487. #define BMI160_GYRO_FIFO_DOWN_SEVEN UINT8_C(0x07)
  488. /* Accel Fifo filter enable*/
  489. #define BMI160_ACCEL_FIFO_FILT_EN UINT8_C(0x80)
  490. /* Gyro Fifo filter enable*/
  491. #define BMI160_GYRO_FIFO_FILT_EN UINT8_C(0x08)
  492. /** Definitions to check validity of FIFO frames */
  493. #define FIFO_CONFIG_MSB_CHECK UINT8_C(0x80)
  494. #define FIFO_CONFIG_LSB_CHECK UINT8_C(0x00)
  495. /*! BMI160 accel FOC configurations */
  496. #define BMI160_FOC_ACCEL_DISABLED UINT8_C(0x00)
  497. #define BMI160_FOC_ACCEL_POSITIVE_G UINT8_C(0x01)
  498. #define BMI160_FOC_ACCEL_NEGATIVE_G UINT8_C(0x02)
  499. #define BMI160_FOC_ACCEL_0G UINT8_C(0x03)
  500. /** Array Parameter DefinItions */
  501. #define BMI160_SENSOR_TIME_LSB_BYTE UINT8_C(0)
  502. #define BMI160_SENSOR_TIME_XLSB_BYTE UINT8_C(1)
  503. #define BMI160_SENSOR_TIME_MSB_BYTE UINT8_C(2)
  504. /** Interface settings */
  505. #define BMI160_SPI_INTF UINT8_C(1)
  506. #define BMI160_I2C_INTF UINT8_C(0)
  507. #define BMI160_SPI_RD_MASK UINT8_C(0x80)
  508. #define BMI160_SPI_WR_MASK UINT8_C(0x7F)
  509. /* Sensor & time select definition*/
  510. #define BMI160_ACCEL_SEL UINT8_C(0x01)
  511. #define BMI160_GYRO_SEL UINT8_C(0x02)
  512. #define BMI160_TIME_SEL UINT8_C(0x04)
  513. /* Sensor select mask*/
  514. #define BMI160_SEN_SEL_MASK UINT8_C(0x07)
  515. /* Error code mask */
  516. #define BMI160_ERR_REG_MASK UINT8_C(0x0F)
  517. /* BMI160 I2C address */
  518. #define BMI160_I2C_ADDR UINT8_C(0x68)
  519. /* BMI160 secondary IF address */
  520. #define BMI160_AUX_BMM150_I2C_ADDR UINT8_C(0x10)
  521. /** BMI160 Length definitions */
  522. #define BMI160_ONE UINT8_C(1)
  523. #define BMI160_TWO UINT8_C(2)
  524. #define BMI160_THREE UINT8_C(3)
  525. #define BMI160_FOUR UINT8_C(4)
  526. #define BMI160_FIVE UINT8_C(5)
  527. /** BMI160 fifo level Margin */
  528. #define BMI160_FIFO_LEVEL_MARGIN UINT8_C(16)
  529. /** BMI160 fifo flush Command */
  530. #define BMI160_FIFO_FLUSH_VALUE UINT8_C(0xB0)
  531. /** BMI160 offset values for xyz axes of accel */
  532. #define BMI160_ACCEL_MIN_OFFSET INT8_C(-128)
  533. #define BMI160_ACCEL_MAX_OFFSET INT8_C(127)
  534. /** BMI160 offset values for xyz axes of gyro */
  535. #define BMI160_GYRO_MIN_OFFSET INT16_C(-512)
  536. #define BMI160_GYRO_MAX_OFFSET INT16_C(511)
  537. /** BMI160 fifo full interrupt position and mask */
  538. #define BMI160_FIFO_FULL_INT_POS UINT8_C(5)
  539. #define BMI160_FIFO_FULL_INT_MSK UINT8_C(0x20)
  540. #define BMI160_FIFO_WTM_INT_POS UINT8_C(6)
  541. #define BMI160_FIFO_WTM_INT_MSK UINT8_C(0x40)
  542. #define BMI160_FIFO_FULL_INT_PIN1_POS UINT8_C(5)
  543. #define BMI160_FIFO_FULL_INT_PIN1_MSK UINT8_C(0x20)
  544. #define BMI160_FIFO_FULL_INT_PIN2_POS UINT8_C(1)
  545. #define BMI160_FIFO_FULL_INT_PIN2_MSK UINT8_C(0x02)
  546. #define BMI160_FIFO_WTM_INT_PIN1_POS UINT8_C(6)
  547. #define BMI160_FIFO_WTM_INT_PIN1_MSK UINT8_C(0x40)
  548. #define BMI160_FIFO_WTM_INT_PIN2_POS UINT8_C(2)
  549. #define BMI160_FIFO_WTM_INT_PIN2_MSK UINT8_C(0x04)
  550. #define BMI160_MANUAL_MODE_EN_POS UINT8_C(7)
  551. #define BMI160_MANUAL_MODE_EN_MSK UINT8_C(0x80)
  552. #define BMI160_AUX_READ_BURST_POS UINT8_C(0)
  553. #define BMI160_AUX_READ_BURST_MSK UINT8_C(0x03)
  554. #define BMI160_GYRO_SELF_TEST_POS UINT8_C(4)
  555. #define BMI160_GYRO_SELF_TEST_MSK UINT8_C(0x10)
  556. #define BMI160_GYRO_SELF_TEST_STATUS_POS UINT8_C(1)
  557. #define BMI160_GYRO_SELF_TEST_STATUS_MSK UINT8_C(0x02)
  558. #define BMI160_GYRO_FOC_EN_POS UINT8_C(6)
  559. #define BMI160_GYRO_FOC_EN_MSK UINT8_C(0x40)
  560. #define BMI160_ACCEL_FOC_X_CONF_POS UINT8_C(4)
  561. #define BMI160_ACCEL_FOC_X_CONF_MSK UINT8_C(0x30)
  562. #define BMI160_ACCEL_FOC_Y_CONF_POS UINT8_C(2)
  563. #define BMI160_ACCEL_FOC_Y_CONF_MSK UINT8_C(0x0C)
  564. #define BMI160_ACCEL_FOC_Z_CONF_MSK UINT8_C(0x03)
  565. #define BMI160_FOC_STATUS_POS UINT8_C(3)
  566. #define BMI160_FOC_STATUS_MSK UINT8_C(0x08)
  567. #define BMI160_GYRO_OFFSET_X_MSK UINT8_C(0x03)
  568. #define BMI160_GYRO_OFFSET_Y_POS UINT8_C(2)
  569. #define BMI160_GYRO_OFFSET_Y_MSK UINT8_C(0x0C)
  570. #define BMI160_GYRO_OFFSET_Z_POS UINT8_C(4)
  571. #define BMI160_GYRO_OFFSET_Z_MSK UINT8_C(0x30)
  572. #define BMI160_GYRO_OFFSET_EN_POS UINT8_C(7)
  573. #define BMI160_GYRO_OFFSET_EN_MSK UINT8_C(0x80)
  574. #define BMI160_ACCEL_OFFSET_EN_POS UINT8_C(6)
  575. #define BMI160_ACCEL_OFFSET_EN_MSK UINT8_C(0x40)
  576. #define BMI160_GYRO_OFFSET_POS UINT16_C(8)
  577. #define BMI160_GYRO_OFFSET_MSK UINT16_C(0x0300)
  578. #define BMI160_NVM_UPDATE_POS UINT8_C(1)
  579. #define BMI160_NVM_UPDATE_MSK UINT8_C(0x02)
  580. #define BMI160_NVM_STATUS_POS UINT8_C(4)
  581. #define BMI160_NVM_STATUS_MSK UINT8_C(0x10)
  582. #define BMI160_MAG_POWER_MODE_MSK UINT8_C(0x03)
  583. #define BMI160_ACCEL_POWER_MODE_MSK UINT8_C(0x30)
  584. #define BMI160_ACCEL_POWER_MODE_POS UINT8_C(4)
  585. #define BMI160_GYRO_POWER_MODE_MSK UINT8_C(0x0C)
  586. #define BMI160_GYRO_POWER_MODE_POS UINT8_C(2)
  587. /* BIT SLICE GET AND SET FUNCTIONS */
  588. #define BMI160_GET_BITS(regvar, bitname)\
  589. ((regvar & bitname##_MSK) >> bitname##_POS)
  590. #define BMI160_SET_BITS(regvar, bitname, val)\
  591. ((regvar & ~bitname##_MSK) | \
  592. ((val<<bitname##_POS)&bitname##_MSK))
  593. #define BMI160_SET_BITS_POS_0(reg_data, bitname, data) \
  594. ((reg_data & ~(bitname##_MSK)) | \
  595. (data & bitname##_MSK))
  596. #define BMI160_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
  597. /**\name UTILITY MACROS */
  598. #define BMI160_SET_LOW_BYTE UINT16_C(0x00FF)
  599. #define BMI160_SET_HIGH_BYTE UINT16_C(0xFF00)
  600. #define BMI160_GET_LSB(var) (uint8_t)(var & BMI160_SET_LOW_BYTE)
  601. #define BMI160_GET_MSB(var) (uint8_t)((var & BMI160_SET_HIGH_BYTE) >> 8)
  602. /*****************************************************************************/
  603. /* type definitions */
  604. typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
  605. uint8_t *data, uint16_t len);
  606. typedef void (*bmi160_delay_fptr_t)(uint32_t period);
  607. /*************************** Data structures *********************************/
  608. struct bmi160_pmu_status {
  609. /*! Power mode status of Accel
  610. * Possible values :
  611. * - BMI160_ACCEL_PMU_SUSPEND
  612. * - BMI160_ACCEL_PMU_NORMAL
  613. * - BMI160_ACCEL_PMU_LOW_POWER
  614. */
  615. uint8_t accel_pmu_status;
  616. /*! Power mode status of Gyro
  617. * Possible values :
  618. * - BMI160_GYRO_PMU_SUSPEND
  619. * - BMI160_GYRO_PMU_NORMAL
  620. * - BMI160_GYRO_PMU_FSU
  621. */
  622. uint8_t gyro_pmu_status;
  623. /*! Power mode status of 'Auxiliary sensor interface' whereas the actual
  624. * power mode of the aux. sensor should be configured
  625. * according to the connected sensor specifications
  626. * Possible values :
  627. * - BMI160_AUX_PMU_SUSPEND
  628. * - BMI160_AUX_PMU_NORMAL
  629. * - BMI160_AUX_PMU_LOW_POWER
  630. */
  631. uint8_t aux_pmu_status;
  632. };
  633. /*!
  634. * @brief bmi160 interrupt status selection enum.
  635. */
  636. enum bmi160_int_status_sel {
  637. BMI160_INT_STATUS_0 = 1,
  638. BMI160_INT_STATUS_1 = 2,
  639. BMI160_INT_STATUS_2 = 4,
  640. BMI160_INT_STATUS_3 = 8,
  641. BMI160_INT_STATUS_ALL = 15
  642. };
  643. /*!
  644. * @brief bmi160 interrupt status bits structure
  645. */
  646. struct bmi160_int_status_bits {
  647. #if LITTLE_ENDIAN == 1
  648. uint32_t step :1;
  649. uint32_t sigmot :1;
  650. uint32_t anym :1;
  651. /* pmu trigger will be handled later */
  652. uint32_t pmu_trigger_reserved :1;
  653. uint32_t d_tap :1;
  654. uint32_t s_tap :1;
  655. uint32_t orient :1;
  656. uint32_t flat_int :1;
  657. uint32_t reserved :2;
  658. uint32_t high_g :1;
  659. uint32_t low_g :1;
  660. uint32_t drdy :1;
  661. uint32_t ffull :1;
  662. uint32_t fwm :1;
  663. uint32_t nomo :1;
  664. uint32_t anym_first_x :1;
  665. uint32_t anym_first_y :1;
  666. uint32_t anym_first_z :1;
  667. uint32_t anym_sign :1;
  668. uint32_t tap_first_x :1;
  669. uint32_t tap_first_y :1;
  670. uint32_t tap_first_z :1;
  671. uint32_t tap_sign :1;
  672. uint32_t high_first_x :1;
  673. uint32_t high_first_y :1;
  674. uint32_t high_first_z :1;
  675. uint32_t high_sign :1;
  676. uint32_t orient_1_0 :2;
  677. uint32_t orient_2 :1;
  678. uint32_t flat :1;
  679. #elif BIG_ENDIAN == 1
  680. uint32_t high_first_x :1;
  681. uint32_t high_first_y :1;
  682. uint32_t high_first_z :1;
  683. uint32_t high_sign :1;
  684. uint32_t orient_1_0 :2;
  685. uint32_t orient_2 :1;
  686. uint32_t flat :1;
  687. uint32_t anym_first_x :1;
  688. uint32_t anym_first_y :1;
  689. uint32_t anym_first_z :1;
  690. uint32_t anym_sign :1;
  691. uint32_t tap_first_x :1;
  692. uint32_t tap_first_y :1;
  693. uint32_t tap_first_z :1;
  694. uint32_t tap_sign :1;
  695. uint32_t reserved :2;
  696. uint32_t high_g :1;
  697. uint32_t low_g :1;
  698. uint32_t drdy :1;
  699. uint32_t ffull :1;
  700. uint32_t fwm :1;
  701. uint32_t nomo :1;
  702. uint32_t step :1;
  703. uint32_t sigmot :1;
  704. uint32_t anym :1;
  705. /* pmu trigger will be handled later */
  706. uint32_t pmu_trigger_reserved :1;
  707. uint32_t d_tap :1;
  708. uint32_t s_tap :1;
  709. uint32_t orient :1;
  710. uint32_t flat_int :1;
  711. #endif
  712. };
  713. /*!
  714. * @brief bmi160 interrupt status structure
  715. */
  716. union bmi160_int_status {
  717. uint8_t data[4];
  718. struct bmi160_int_status_bits bit;
  719. };
  720. /*!
  721. * @brief bmi160 sensor data structure which comprises of accel data
  722. */
  723. struct bmi160_sensor_data {
  724. /*! X-axis sensor data */
  725. int16_t x;
  726. /*! Y-axis sensor data */
  727. int16_t y;
  728. /*! Z-axis sensor data */
  729. int16_t z;
  730. /*! sensor time */
  731. uint32_t sensortime;
  732. };
  733. /*!
  734. * @brief bmi160 aux data structure which comprises of 8 bytes of accel data
  735. */
  736. struct bmi160_aux_data {
  737. /*! Auxiliary data */
  738. uint8_t data[8];
  739. };
  740. /*!
  741. * @brief bmi160 FOC configuration structure
  742. */
  743. struct bmi160_foc_conf {
  744. /*! Enabling FOC in gyro
  745. * Assignable macros :
  746. * - BMI160_ENABLE
  747. * - BMI160_DISABLE
  748. */
  749. uint8_t foc_gyr_en;
  750. /*! Accel FOC configurations
  751. * Assignable macros :
  752. * - BMI160_FOC_ACCEL_DISABLED
  753. * - BMI160_FOC_ACCEL_POSITIVE_G
  754. * - BMI160_FOC_ACCEL_NEGATIVE_G
  755. * - BMI160_FOC_ACCEL_0G
  756. */
  757. uint8_t foc_acc_x;
  758. uint8_t foc_acc_y;
  759. uint8_t foc_acc_z;
  760. /*! Enabling offset compensation for accel in data registers
  761. * Assignable macros :
  762. * - BMI160_ENABLE
  763. * - BMI160_DISABLE
  764. */
  765. uint8_t acc_off_en;
  766. /*! Enabling offset compensation for gyro in data registers
  767. * Assignable macros :
  768. * - BMI160_ENABLE
  769. * - BMI160_DISABLE
  770. */
  771. uint8_t gyro_off_en;
  772. };
  773. /*!
  774. * @brief bmi160 accel gyro offsets
  775. */
  776. struct bmi160_offsets {
  777. /*! Accel offset for x axis */
  778. int8_t off_acc_x;
  779. /*! Accel offset for y axis */
  780. int8_t off_acc_y;
  781. /*! Accel offset for z axis */
  782. int8_t off_acc_z;
  783. /*! Gyro offset for x axis */
  784. int16_t off_gyro_x;
  785. /*! Gyro offset for y axis */
  786. int16_t off_gyro_y;
  787. /*! Gyro offset for z axis */
  788. int16_t off_gyro_z;
  789. };
  790. /*!
  791. * @brief FIFO aux. sensor data structure
  792. */
  793. struct bmi160_aux_fifo_data {
  794. /*! The value of aux. sensor x LSB data */
  795. uint8_t aux_x_lsb;
  796. /*! The value of aux. sensor x MSB data */
  797. uint8_t aux_x_msb;
  798. /*! The value of aux. sensor y LSB data */
  799. uint8_t aux_y_lsb;
  800. /*! The value of aux. sensor y MSB data */
  801. uint8_t aux_y_msb;
  802. /*! The value of aux. sensor z LSB data */
  803. uint8_t aux_z_lsb;
  804. /*! The value of aux. sensor z MSB data */
  805. uint8_t aux_z_msb;
  806. /*! The value of aux. sensor r for BMM150 LSB data */
  807. uint8_t aux_r_y2_lsb;
  808. /*! The value of aux. sensor r for BMM150 MSB data */
  809. uint8_t aux_r_y2_msb;
  810. };
  811. /*!
  812. * @brief bmi160 sensor select structure
  813. */
  814. enum bmi160_select_sensor {
  815. BMI160_ACCEL_ONLY = 1,
  816. BMI160_GYRO_ONLY,
  817. BMI160_BOTH_ACCEL_AND_GYRO
  818. };
  819. /*!
  820. * @brief bmi160 sensor step detector mode structure
  821. */
  822. enum bmi160_step_detect_mode {
  823. BMI160_STEP_DETECT_NORMAL,
  824. BMI160_STEP_DETECT_SENSITIVE,
  825. BMI160_STEP_DETECT_ROBUST,
  826. /*! Non recommended User defined setting */
  827. BMI160_STEP_DETECT_USER_DEFINE
  828. };
  829. /*!
  830. * @brief enum for auxiliary burst read selection
  831. */
  832. enum bm160_aux_read_len {
  833. BMI160_AUX_READ_LEN_0,
  834. BMI160_AUX_READ_LEN_1,
  835. BMI160_AUX_READ_LEN_2,
  836. BMI160_AUX_READ_LEN_3
  837. };
  838. /*!
  839. * @brief bmi160 sensor configuration structure
  840. */
  841. struct bmi160_cfg {
  842. /*! power mode */
  843. uint8_t power;
  844. /*! output data rate */
  845. uint8_t odr;
  846. /*! range */
  847. uint8_t range;
  848. /*! bandwidth */
  849. uint8_t bw;
  850. };
  851. /*!
  852. * @brief Aux sensor configuration structure
  853. */
  854. struct bmi160_aux_cfg {
  855. /*! Aux sensor, 1 - enable 0 - disable */
  856. uint8_t aux_sensor_enable : 1;
  857. /*! Aux manual/auto mode status */
  858. uint8_t manual_enable : 1;
  859. /*! Aux read burst length */
  860. uint8_t aux_rd_burst_len : 2;
  861. /*! output data rate */
  862. uint8_t aux_odr :4;
  863. /*! i2c addr of auxiliary sensor */
  864. uint8_t aux_i2c_addr;
  865. };
  866. /*!
  867. * @brief bmi160 interrupt channel selection structure
  868. */
  869. enum bmi160_int_channel {
  870. /*! Un-map both channels */
  871. BMI160_INT_CHANNEL_NONE,
  872. /*! interrupt Channel 1 */
  873. BMI160_INT_CHANNEL_1,
  874. /*! interrupt Channel 2 */
  875. BMI160_INT_CHANNEL_2,
  876. /*! Map both channels */
  877. BMI160_INT_CHANNEL_BOTH
  878. };
  879. enum bmi160_int_types {
  880. /*! Slope/Any-motion interrupt */
  881. BMI160_ACC_ANY_MOTION_INT,
  882. /*! Significant motion interrupt */
  883. BMI160_ACC_SIG_MOTION_INT,
  884. /*! Step detector interrupt */
  885. BMI160_STEP_DETECT_INT,
  886. /*! double tap interrupt */
  887. BMI160_ACC_DOUBLE_TAP_INT,
  888. /*! single tap interrupt */
  889. BMI160_ACC_SINGLE_TAP_INT,
  890. /*! orientation interrupt */
  891. BMI160_ACC_ORIENT_INT,
  892. /*! flat interrupt */
  893. BMI160_ACC_FLAT_INT,
  894. /*! high-g interrupt */
  895. BMI160_ACC_HIGH_G_INT,
  896. /*! low-g interrupt */
  897. BMI160_ACC_LOW_G_INT,
  898. /*! slow/no-motion interrupt */
  899. BMI160_ACC_SLOW_NO_MOTION_INT,
  900. /*! data ready interrupt */
  901. BMI160_ACC_GYRO_DATA_RDY_INT,
  902. /*! fifo full interrupt */
  903. BMI160_ACC_GYRO_FIFO_FULL_INT,
  904. /*! fifo watermark interrupt */
  905. BMI160_ACC_GYRO_FIFO_WATERMARK_INT,
  906. /*! fifo tagging feature support */
  907. BMI160_FIFO_TAG_INT_PIN
  908. };
  909. /*!
  910. * @brief bmi160 active state of any & sig motion interrupt.
  911. */
  912. enum bmi160_any_sig_motion_active_interrupt_state {
  913. /*! Both any & sig motion are disabled */
  914. BMI160_BOTH_ANY_SIG_MOTION_DISABLED = -1,
  915. /*! Any-motion selected */
  916. BMI160_ANY_MOTION_ENABLED,
  917. /*! Sig-motion selected */
  918. BMI160_SIG_MOTION_ENABLED
  919. };
  920. struct bmi160_acc_tap_int_cfg {
  921. #if LITTLE_ENDIAN == 1
  922. /*! tap threshold */
  923. uint16_t tap_thr :5;
  924. /*! tap shock */
  925. uint16_t tap_shock :1;
  926. /*! tap quiet */
  927. uint16_t tap_quiet :1;
  928. /*! tap duration */
  929. uint16_t tap_dur :3;
  930. /*! data source 0- filter & 1 pre-filter*/
  931. uint16_t tap_data_src :1;
  932. /*! tap enable, 1 - enable, 0 - disable */
  933. uint16_t tap_en :1;
  934. #elif BIG_ENDIAN == 1
  935. /*! tap enable, 1 - enable, 0 - disable */
  936. uint16_t tap_en :1;
  937. /*! data source 0- filter & 1 pre-filter*/
  938. uint16_t tap_data_src :1;
  939. /*! tap duration */
  940. uint16_t tap_dur : 3;
  941. /*! tap quiet */
  942. uint16_t tap_quiet : 1;
  943. /*! tap shock */
  944. uint16_t tap_shock : 1;
  945. /*! tap threshold */
  946. uint16_t tap_thr : 5;
  947. #endif
  948. };
  949. struct bmi160_acc_any_mot_int_cfg {
  950. #if LITTLE_ENDIAN == 1
  951. /*! 1 any-motion enable, 0 - any-motion disable */
  952. uint8_t anymotion_en :1;
  953. /*! slope interrupt x, 1 - enable, 0 - disable */
  954. uint8_t anymotion_x :1;
  955. /*! slope interrupt y, 1 - enable, 0 - disable */
  956. uint8_t anymotion_y :1;
  957. /*! slope interrupt z, 1 - enable, 0 - disable */
  958. uint8_t anymotion_z :1;
  959. /*! slope duration */
  960. uint8_t anymotion_dur :2;
  961. /*! data source 0- filter & 1 pre-filter*/
  962. uint8_t anymotion_data_src :1;
  963. /*! slope threshold */
  964. uint8_t anymotion_thr;
  965. #elif BIG_ENDIAN == 1
  966. /*! slope threshold */
  967. uint8_t anymotion_thr;
  968. /*! data source 0- filter & 1 pre-filter*/
  969. uint8_t anymotion_data_src :1;
  970. /*! slope duration */
  971. uint8_t anymotion_dur : 2;
  972. /*! slope interrupt z, 1 - enable, 0 - disable */
  973. uint8_t anymotion_z : 1;
  974. /*! slope interrupt y, 1 - enable, 0 - disable */
  975. uint8_t anymotion_y : 1;
  976. /*! slope interrupt x, 1 - enable, 0 - disable */
  977. uint8_t anymotion_x : 1;
  978. /*! 1 any-motion enable, 0 - any-motion disable */
  979. uint8_t anymotion_en :1;
  980. #endif
  981. };
  982. struct bmi160_acc_sig_mot_int_cfg {
  983. #if LITTLE_ENDIAN == 1
  984. /*! skip time of sig-motion interrupt */
  985. uint8_t sig_mot_skip :2;
  986. /*! proof time of sig-motion interrupt */
  987. uint8_t sig_mot_proof :2;
  988. /*! data source 0- filter & 1 pre-filter*/
  989. uint8_t sig_data_src :1;
  990. /*! 1 - enable sig, 0 - disable sig & enable anymotion */
  991. uint8_t sig_en :1;
  992. /*! sig-motion threshold */
  993. uint8_t sig_mot_thres;
  994. #elif BIG_ENDIAN == 1
  995. /*! sig-motion threshold */
  996. uint8_t sig_mot_thres;
  997. /*! 1 - enable sig, 0 - disable sig & enable anymotion */
  998. uint8_t sig_en :1;
  999. /*! data source 0- filter & 1 pre-filter*/
  1000. uint8_t sig_data_src :1;
  1001. /*! proof time of sig-motion interrupt */
  1002. uint8_t sig_mot_proof : 2;
  1003. /*! skip time of sig-motion interrupt */
  1004. uint8_t sig_mot_skip : 2;
  1005. #endif
  1006. };
  1007. struct bmi160_acc_step_detect_int_cfg {
  1008. #if LITTLE_ENDIAN == 1
  1009. /*! 1- step detector enable, 0- step detector disable */
  1010. uint16_t step_detector_en :1;
  1011. /*! minimum threshold */
  1012. uint16_t min_threshold :2;
  1013. /*! minimal detectable step time */
  1014. uint16_t steptime_min :3;
  1015. /*! enable step counter mode setting */
  1016. uint16_t step_detector_mode :2;
  1017. /*! minimum step buffer size*/
  1018. uint16_t step_min_buf :3;
  1019. #elif BIG_ENDIAN == 1
  1020. /*! minimum step buffer size*/
  1021. uint16_t step_min_buf :3;
  1022. /*! enable step counter mode setting */
  1023. uint16_t step_detector_mode : 2;
  1024. /*! minimal detectable step time */
  1025. uint16_t steptime_min : 3;
  1026. /*! minimum threshold */
  1027. uint16_t min_threshold : 2;
  1028. /*! 1- step detector enable, 0- step detector disable */
  1029. uint16_t step_detector_en :1;
  1030. #endif
  1031. };
  1032. struct bmi160_acc_no_motion_int_cfg {
  1033. #if LITTLE_ENDIAN == 1
  1034. /*! no motion interrupt x */
  1035. uint16_t no_motion_x :1;
  1036. /*! no motion interrupt y */
  1037. uint16_t no_motion_y :1;
  1038. /*! no motion interrupt z */
  1039. uint16_t no_motion_z :1;
  1040. /*! no motion duration */
  1041. uint16_t no_motion_dur :6;
  1042. /*! no motion sel , 1 - enable no-motion ,0- enable slow-motion */
  1043. uint16_t no_motion_sel :1;
  1044. /*! data source 0- filter & 1 pre-filter*/
  1045. uint16_t no_motion_src :1;
  1046. /*! no motion threshold */
  1047. uint8_t no_motion_thres;
  1048. #elif BIG_ENDIAN == 1
  1049. /*! no motion threshold */
  1050. uint8_t no_motion_thres;
  1051. /*! data source 0- filter & 1 pre-filter*/
  1052. uint16_t no_motion_src :1;
  1053. /*! no motion sel , 1 - enable no-motion ,0- enable slow-motion */
  1054. uint16_t no_motion_sel : 1;
  1055. /*! no motion duration */
  1056. uint16_t no_motion_dur : 6;
  1057. /* no motion interrupt z */
  1058. uint16_t no_motion_z :1;
  1059. /*! no motion interrupt y */
  1060. uint16_t no_motion_y :1;
  1061. /*! no motion interrupt x */
  1062. uint16_t no_motion_x :1;
  1063. #endif
  1064. };
  1065. struct bmi160_acc_orient_int_cfg {
  1066. #if LITTLE_ENDIAN == 1
  1067. /*! thresholds for switching between the different orientations */
  1068. uint16_t orient_mode :2;
  1069. /*! blocking_mode */
  1070. uint16_t orient_blocking :2;
  1071. /*! Orientation interrupt hysteresis */
  1072. uint16_t orient_hyst :4;
  1073. /*! Orientation interrupt theta */
  1074. uint16_t orient_theta :6;
  1075. /*! Enable/disable Orientation interrupt */
  1076. uint16_t orient_ud_en :1;
  1077. /*! exchange x- and z-axis in algorithm ,0 - z, 1 - x */
  1078. uint16_t axes_ex :1;
  1079. /*! 1 - orient enable, 0 - orient disable */
  1080. uint8_t orient_en :1;
  1081. #elif BIG_ENDIAN == 1
  1082. /*! 1 - orient enable, 0 - orient disable */
  1083. uint8_t orient_en :1;
  1084. /*! exchange x- and z-axis in algorithm ,0 - z, 1 - x */
  1085. uint16_t axes_ex : 1;
  1086. /*! Enable/disable Orientation interrupt */
  1087. uint16_t orient_ud_en : 1;
  1088. /*! Orientation interrupt theta */
  1089. uint16_t orient_theta : 6;
  1090. /*! Orientation interrupt hysteresis */
  1091. uint16_t orient_hyst : 4;
  1092. /*! blocking_mode */
  1093. uint16_t orient_blocking : 2;
  1094. /*! thresholds for switching between the different orientations */
  1095. uint16_t orient_mode : 2;
  1096. #endif
  1097. };
  1098. struct bmi160_acc_flat_detect_int_cfg {
  1099. #if LITTLE_ENDIAN == 1
  1100. /*! flat threshold */
  1101. uint16_t flat_theta :6;
  1102. /*! flat interrupt hysteresis */
  1103. uint16_t flat_hy :3;
  1104. /*! delay time for which the flat value must remain stable for the
  1105. * flat interrupt to be generated */
  1106. uint16_t flat_hold_time :2;
  1107. /*! 1 - flat enable, 0 - flat disable */
  1108. uint16_t flat_en :1;
  1109. #elif BIG_ENDIAN == 1
  1110. /*! 1 - flat enable, 0 - flat disable */
  1111. uint16_t flat_en :1;
  1112. /*! delay time for which the flat value must remain stable for the
  1113. * flat interrupt to be generated */
  1114. uint16_t flat_hold_time : 2;
  1115. /*! flat interrupt hysteresis */
  1116. uint16_t flat_hy : 3;
  1117. /*! flat threshold */
  1118. uint16_t flat_theta : 6;
  1119. #endif
  1120. };
  1121. struct bmi160_acc_low_g_int_cfg {
  1122. #if LITTLE_ENDIAN == 1
  1123. /*! low-g interrupt trigger delay */
  1124. uint8_t low_dur;
  1125. /*! low-g interrupt trigger threshold */
  1126. uint8_t low_thres;
  1127. /*! hysteresis of low-g interrupt */
  1128. uint8_t low_hyst :2;
  1129. /*! 0 - single-axis mode ,1 - axis-summing mode */
  1130. uint8_t low_mode :1;
  1131. /*! data source 0- filter & 1 pre-filter */
  1132. uint8_t low_data_src :1;
  1133. /*! 1 - enable low-g, 0 - disable low-g */
  1134. uint8_t low_en :1;
  1135. #elif BIG_ENDIAN == 1
  1136. /*! 1 - enable low-g, 0 - disable low-g */
  1137. uint8_t low_en :1;
  1138. /*! data source 0- filter & 1 pre-filter */
  1139. uint8_t low_data_src :1;
  1140. /*! 0 - single-axis mode ,1 - axis-summing mode */
  1141. uint8_t low_mode : 1;
  1142. /*! hysteresis of low-g interrupt */
  1143. uint8_t low_hyst : 2;
  1144. /*! low-g interrupt trigger threshold */
  1145. uint8_t low_thres;
  1146. /*! low-g interrupt trigger delay */
  1147. uint8_t low_dur;
  1148. #endif
  1149. };
  1150. struct bmi160_acc_high_g_int_cfg {
  1151. #if LITTLE_ENDIAN == 1
  1152. /*! High-g interrupt x, 1 - enable, 0 - disable */
  1153. uint8_t high_g_x :1;
  1154. /*! High-g interrupt y, 1 - enable, 0 - disable */
  1155. uint8_t high_g_y :1;
  1156. /*! High-g interrupt z, 1 - enable, 0 - disable */
  1157. uint8_t high_g_z :1;
  1158. /*! High-g hysteresis */
  1159. uint8_t high_hy :2;
  1160. /*! data source 0- filter & 1 pre-filter */
  1161. uint8_t high_data_src :1;
  1162. /*! High-g threshold */
  1163. uint8_t high_thres;
  1164. /*! High-g duration */
  1165. uint8_t high_dur;
  1166. #elif BIG_ENDIAN == 1
  1167. /*! High-g duration */
  1168. uint8_t high_dur;
  1169. /*! High-g threshold */
  1170. uint8_t high_thres;
  1171. /*! data source 0- filter & 1 pre-filter */
  1172. uint8_t high_data_src :1;
  1173. /*! High-g hysteresis */
  1174. uint8_t high_hy : 2;
  1175. /*! High-g interrupt z, 1 - enable, 0 - disable */
  1176. uint8_t high_g_z : 1;
  1177. /*! High-g interrupt y, 1 - enable, 0 - disable */
  1178. uint8_t high_g_y : 1;
  1179. /*! High-g interrupt x, 1 - enable, 0 - disable */
  1180. uint8_t high_g_x : 1;
  1181. #endif
  1182. };
  1183. struct bmi160_int_pin_settg {
  1184. #if LITTLE_ENDIAN == 1
  1185. /*! To enable either INT1 or INT2 pin as output.
  1186. * 0- output disabled ,1- output enabled */
  1187. uint16_t output_en :1;
  1188. /*! 0 - push-pull 1- open drain,only valid if output_en is set 1 */
  1189. uint16_t output_mode :1;
  1190. /*! 0 - active low , 1 - active high level.
  1191. * if output_en is 1,this applies to interrupts,else PMU_trigger */
  1192. uint16_t output_type :1;
  1193. /*! 0 - level trigger , 1 - edge trigger */
  1194. uint16_t edge_ctrl :1;
  1195. /*! To enable either INT1 or INT2 pin as input.
  1196. * 0 - input disabled ,1 - input enabled */
  1197. uint16_t input_en :1;
  1198. /*! latch duration*/
  1199. uint16_t latch_dur :4;
  1200. #elif BIG_ENDIAN == 1
  1201. /*! latch duration*/
  1202. uint16_t latch_dur : 4;
  1203. /*! Latched,non-latched or temporary interrupt modes */
  1204. uint16_t input_en : 1;
  1205. /*! 1 - edge trigger, 0 - level trigger */
  1206. uint16_t edge_ctrl : 1;
  1207. /*! 0 - active low , 1 - active high level.
  1208. * if output_en is 1,this applies to interrupts,else PMU_trigger */
  1209. uint16_t output_type : 1;
  1210. /*! 0 - push-pull , 1 - open drain,only valid if output_en is set 1 */
  1211. uint16_t output_mode : 1;
  1212. /*! To enable either INT1 or INT2 pin as output.
  1213. * 0 - output disabled , 1 - output enabled */
  1214. uint16_t output_en : 1;
  1215. #endif
  1216. };
  1217. union bmi160_int_type_cfg {
  1218. /*! Tap interrupt structure */
  1219. struct bmi160_acc_tap_int_cfg acc_tap_int;
  1220. /*! Slope interrupt structure */
  1221. struct bmi160_acc_any_mot_int_cfg acc_any_motion_int;
  1222. /*! Significant motion interrupt structure */
  1223. struct bmi160_acc_sig_mot_int_cfg acc_sig_motion_int;
  1224. /*! Step detector interrupt structure */
  1225. struct bmi160_acc_step_detect_int_cfg acc_step_detect_int;
  1226. /*! No motion interrupt structure */
  1227. struct bmi160_acc_no_motion_int_cfg acc_no_motion_int;
  1228. /*! Orientation interrupt structure */
  1229. struct bmi160_acc_orient_int_cfg acc_orient_int;
  1230. /*! Flat interrupt structure */
  1231. struct bmi160_acc_flat_detect_int_cfg acc_flat_int;
  1232. /*! Low-g interrupt structure */
  1233. struct bmi160_acc_low_g_int_cfg acc_low_g_int;
  1234. /*! High-g interrupt structure */
  1235. struct bmi160_acc_high_g_int_cfg acc_high_g_int;
  1236. };
  1237. struct bmi160_int_settg {
  1238. /*! Interrupt channel */
  1239. enum bmi160_int_channel int_channel;
  1240. /*! Select Interrupt */
  1241. enum bmi160_int_types int_type;
  1242. /*! Structure configuring Interrupt pins */
  1243. struct bmi160_int_pin_settg int_pin_settg;
  1244. /*! Union configures required interrupt */
  1245. union bmi160_int_type_cfg int_type_cfg;
  1246. /*! FIFO FULL INT 1-enable, 0-disable */
  1247. uint8_t fifo_full_int_en :1;
  1248. /*! FIFO WTM INT 1-enable, 0-disable */
  1249. uint8_t fifo_WTM_int_en :1;
  1250. };
  1251. /*!
  1252. * @brief This structure holds the information for usage of
  1253. * FIFO by the user.
  1254. */
  1255. struct bmi160_fifo_frame {
  1256. /*! Data buffer of user defined length is to be mapped here */
  1257. uint8_t *data;
  1258. /*! While calling the API "bmi160_get_fifo_data" , length stores
  1259. * number of bytes in FIFO to be read (specified by user as input)
  1260. * and after execution of the API ,number of FIFO data bytes
  1261. * available is provided as an output to user
  1262. */
  1263. uint16_t length;
  1264. /*! FIFO time enable */
  1265. uint8_t fifo_time_enable;
  1266. /*! Enabling of the FIFO header to stream in header mode */
  1267. uint8_t fifo_header_enable;
  1268. /*! Streaming of the Accelerometer, Gyroscope
  1269. sensor data or both in FIFO */
  1270. uint8_t fifo_data_enable;
  1271. /*! Will be equal to length when no more frames are there to parse */
  1272. uint16_t accel_byte_start_idx;
  1273. /*! Will be equal to length when no more frames are there to parse */
  1274. uint16_t gyro_byte_start_idx;
  1275. /*! Will be equal to length when no more frames are there to parse */
  1276. uint16_t aux_byte_start_idx;
  1277. /*! Value of FIFO sensor time time */
  1278. uint32_t sensor_time;
  1279. /*! Value of Skipped frame counts */
  1280. uint8_t skipped_frame_count;
  1281. };
  1282. struct bmi160_dev {
  1283. /*! Chip Id */
  1284. uint8_t chip_id;
  1285. /*! Device Id */
  1286. uint8_t id;
  1287. /*! 0 - I2C , 1 - SPI Interface */
  1288. uint8_t interface;
  1289. /*! Hold active interrupts status for any and sig motion
  1290. * 0 - Any-motion enable, 1 - Sig-motion enable,
  1291. * -1 neither any-motion nor sig-motion selected */
  1292. enum bmi160_any_sig_motion_active_interrupt_state any_sig_sel;
  1293. /*! Structure to configure Accel sensor */
  1294. struct bmi160_cfg accel_cfg;
  1295. /*! Structure to hold previous/old accel config parameters.
  1296. * This is used at driver level to prevent overwriting of same
  1297. * data, hence user does not change it in the code */
  1298. struct bmi160_cfg prev_accel_cfg;
  1299. /*! Structure to configure Gyro sensor */
  1300. struct bmi160_cfg gyro_cfg;
  1301. /*! Structure to hold previous/old gyro config parameters.
  1302. * This is used at driver level to prevent overwriting of same
  1303. * data, hence user does not change it in the code */
  1304. struct bmi160_cfg prev_gyro_cfg;
  1305. /*! Structure to configure the auxiliary sensor */
  1306. struct bmi160_aux_cfg aux_cfg;
  1307. /*! Structure to hold previous/old aux config parameters.
  1308. * This is used at driver level to prevent overwriting of same
  1309. * data, hence user does not change it in the code */
  1310. struct bmi160_aux_cfg prev_aux_cfg;
  1311. /*! FIFO related configurations */
  1312. struct bmi160_fifo_frame *fifo;
  1313. /*! Read function pointer */
  1314. bmi160_com_fptr_t read;
  1315. /*! Write function pointer */
  1316. bmi160_com_fptr_t write;
  1317. /*! Delay function pointer */
  1318. bmi160_delay_fptr_t delay_ms;
  1319. };
  1320. #endif /* BMI160_DEFS_H_ */