bmi160_defs.h 55 KB

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