bmi160_defs.h 48 KB

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