bmi160_defs.h 56 KB

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