bmi160_defs.h 48 KB

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