bmi160_defs.h 53 KB

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