bmi160_defs.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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 2021-03-12
  35. * @version v3.9.1
  36. *
  37. */
  38. #ifndef BMI160_DEFS_H_
  39. #define BMI160_DEFS_H_
  40. /*************************** C types headers *****************************/
  41. #ifdef __KERNEL__
  42. #include <linux/types.h>
  43. #include <linux/kernel.h>
  44. #else
  45. #include <stdint.h>
  46. #include <stddef.h>
  47. #endif
  48. /*************************** Common macros *****************************/
  49. #if !defined(UINT8_C) && !defined(INT8_C)
  50. #define INT8_C(x) S8_C(x)
  51. #define UINT8_C(x) U8_C(x)
  52. #endif
  53. #if !defined(UINT16_C) && !defined(INT16_C)
  54. #define INT16_C(x) S16_C(x)
  55. #define UINT16_C(x) U16_C(x)
  56. #endif
  57. #if !defined(INT32_C) && !defined(UINT32_C)
  58. #define INT32_C(x) S32_C(x)
  59. #define UINT32_C(x) U32_C(x)
  60. #endif
  61. #if !defined(INT64_C) && !defined(UINT64_C)
  62. #define INT64_C(x) S64_C(x)
  63. #define UINT64_C(x) U64_C(x)
  64. #endif
  65. /**@}*/
  66. /**\name C standard macros */
  67. #ifndef NULL
  68. #ifdef __cplusplus
  69. #define NULL 0
  70. #else
  71. #define NULL ((void *) 0)
  72. #endif
  73. #endif
  74. /*************************** Sensor macros *****************************/
  75. /* Test for an endian machine */
  76. #ifndef __ORDER_LITTLE_ENDIAN__
  77. #define __ORDER_LITTLE_ENDIAN__ 0
  78. #endif
  79. #ifndef __BYTE_ORDER__
  80. #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
  81. #endif
  82. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  83. #ifndef LITTLE_ENDIAN
  84. #define LITTLE_ENDIAN 1
  85. #endif
  86. #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  87. #ifndef BIG_ENDIAN
  88. #define BIG_ENDIAN 1
  89. #endif
  90. #else
  91. #error "Code does not support Endian format of the processor"
  92. #endif
  93. /** Mask definitions */
  94. #define BMI160_ACCEL_BW_MASK UINT8_C(0x70)
  95. #define BMI160_ACCEL_ODR_MASK UINT8_C(0x0F)
  96. #define BMI160_ACCEL_UNDERSAMPLING_MASK UINT8_C(0x80)
  97. #define BMI160_ACCEL_RANGE_MASK UINT8_C(0x0F)
  98. #define BMI160_GYRO_BW_MASK UINT8_C(0x30)
  99. #define BMI160_GYRO_ODR_MASK UINT8_C(0x0F)
  100. #define BMI160_GYRO_RANGE_MASK UINT8_C(0x07)
  101. #define BMI160_ACCEL_BW_POS UINT8_C(4)
  102. #define BMI160_GYRO_BW_POS UINT8_C(4)
  103. /** Mask definitions for INT_EN registers */
  104. #define BMI160_ANY_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  105. #define BMI160_HIGH_G_X_INT_EN_MASK UINT8_C(0x01)
  106. #define BMI160_NO_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  107. #define BMI160_ANY_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  108. #define BMI160_HIGH_G_Y_INT_EN_MASK UINT8_C(0x02)
  109. #define BMI160_NO_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  110. #define BMI160_ANY_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  111. #define BMI160_HIGH_G_Z_INT_EN_MASK UINT8_C(0x04)
  112. #define BMI160_NO_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  113. #define BMI160_SIG_MOTION_INT_EN_MASK UINT8_C(0x07)
  114. #define BMI160_ANY_MOTION_ALL_INT_EN_MASK UINT8_C(0x07)
  115. #define BMI160_STEP_DETECT_INT_EN_MASK UINT8_C(0x08)
  116. #define BMI160_DOUBLE_TAP_INT_EN_MASK UINT8_C(0x10)
  117. #define BMI160_SINGLE_TAP_INT_EN_MASK UINT8_C(0x20)
  118. #define BMI160_FIFO_FULL_INT_EN_MASK UINT8_C(0x20)
  119. #define BMI160_ORIENT_INT_EN_MASK UINT8_C(0x40)
  120. #define BMI160_FIFO_WATERMARK_INT_EN_MASK UINT8_C(0x40)
  121. #define BMI160_LOW_G_INT_EN_MASK UINT8_C(0x08)
  122. #define BMI160_STEP_DETECT_EN_MASK UINT8_C(0x08)
  123. #define BMI160_FLAT_INT_EN_MASK UINT8_C(0x80)
  124. #define BMI160_DATA_RDY_INT_EN_MASK UINT8_C(0x10)
  125. /** PMU status Macros */
  126. #define BMI160_AUX_PMU_SUSPEND UINT8_C(0x00)
  127. #define BMI160_AUX_PMU_NORMAL UINT8_C(0x01)
  128. #define BMI160_AUX_PMU_LOW_POWER UINT8_C(0x02)
  129. #define BMI160_GYRO_PMU_SUSPEND UINT8_C(0x00)
  130. #define BMI160_GYRO_PMU_NORMAL UINT8_C(0x01)
  131. #define BMI160_GYRO_PMU_FSU UINT8_C(0x03)
  132. #define BMI160_ACCEL_PMU_SUSPEND UINT8_C(0x00)
  133. #define BMI160_ACCEL_PMU_NORMAL UINT8_C(0x01)
  134. #define BMI160_ACCEL_PMU_LOW_POWER UINT8_C(0x02)
  135. /** Mask definitions for INT_OUT_CTRL register */
  136. #define BMI160_INT1_EDGE_CTRL_MASK UINT8_C(0x01)
  137. #define BMI160_INT1_OUTPUT_MODE_MASK UINT8_C(0x04)
  138. #define BMI160_INT1_OUTPUT_TYPE_MASK UINT8_C(0x02)
  139. #define BMI160_INT1_OUTPUT_EN_MASK UINT8_C(0x08)
  140. #define BMI160_INT2_EDGE_CTRL_MASK UINT8_C(0x10)
  141. #define BMI160_INT2_OUTPUT_MODE_MASK UINT8_C(0x40)
  142. #define BMI160_INT2_OUTPUT_TYPE_MASK UINT8_C(0x20)
  143. #define BMI160_INT2_OUTPUT_EN_MASK UINT8_C(0x80)
  144. /** Mask definitions for INT_LATCH register */
  145. #define BMI160_INT1_INPUT_EN_MASK UINT8_C(0x10)
  146. #define BMI160_INT2_INPUT_EN_MASK UINT8_C(0x20)
  147. #define BMI160_INT_LATCH_MASK UINT8_C(0x0F)
  148. /** Mask definitions for INT_MAP register */
  149. #define BMI160_INT1_LOW_G_MASK UINT8_C(0x01)
  150. #define BMI160_INT1_HIGH_G_MASK UINT8_C(0x02)
  151. #define BMI160_INT1_SLOPE_MASK UINT8_C(0x04)
  152. #define BMI160_INT1_NO_MOTION_MASK UINT8_C(0x08)
  153. #define BMI160_INT1_DOUBLE_TAP_MASK UINT8_C(0x10)
  154. #define BMI160_INT1_SINGLE_TAP_MASK UINT8_C(0x20)
  155. #define BMI160_INT1_FIFO_FULL_MASK UINT8_C(0x20)
  156. #define BMI160_INT1_FIFO_WM_MASK UINT8_C(0x40)
  157. #define BMI160_INT1_ORIENT_MASK UINT8_C(0x40)
  158. #define BMI160_INT1_FLAT_MASK UINT8_C(0x80)
  159. #define BMI160_INT1_DATA_READY_MASK UINT8_C(0x80)
  160. #define BMI160_INT2_LOW_G_MASK UINT8_C(0x01)
  161. #define BMI160_INT1_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  162. #define BMI160_INT2_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  163. #define BMI160_INT2_HIGH_G_MASK UINT8_C(0x02)
  164. #define BMI160_INT2_FIFO_FULL_MASK UINT8_C(0x02)
  165. #define BMI160_INT2_FIFO_WM_MASK UINT8_C(0x04)
  166. #define BMI160_INT2_SLOPE_MASK UINT8_C(0x04)
  167. #define BMI160_INT2_DATA_READY_MASK UINT8_C(0x08)
  168. #define BMI160_INT2_NO_MOTION_MASK UINT8_C(0x08)
  169. #define BMI160_INT2_DOUBLE_TAP_MASK UINT8_C(0x10)
  170. #define BMI160_INT2_SINGLE_TAP_MASK UINT8_C(0x20)
  171. #define BMI160_INT2_ORIENT_MASK UINT8_C(0x40)
  172. #define BMI160_INT2_FLAT_MASK UINT8_C(0x80)
  173. /** Mask definitions for INT_DATA register */
  174. #define BMI160_TAP_SRC_INT_MASK UINT8_C(0x08)
  175. #define BMI160_LOW_HIGH_SRC_INT_MASK UINT8_C(0x80)
  176. #define BMI160_MOTION_SRC_INT_MASK UINT8_C(0x80)
  177. /** Mask definitions for INT_MOTION register */
  178. #define BMI160_SLOPE_INT_DUR_MASK UINT8_C(0x03)
  179. #define BMI160_NO_MOTION_INT_DUR_MASK UINT8_C(0xFC)
  180. #define BMI160_NO_MOTION_SEL_BIT_MASK UINT8_C(0x01)
  181. /** Mask definitions for INT_TAP register */
  182. #define BMI160_TAP_DUR_MASK UINT8_C(0x07)
  183. #define BMI160_TAP_SHOCK_DUR_MASK UINT8_C(0x40)
  184. #define BMI160_TAP_QUIET_DUR_MASK UINT8_C(0x80)
  185. #define BMI160_TAP_THRES_MASK UINT8_C(0x1F)
  186. /** Mask definitions for INT_FLAT register */
  187. #define BMI160_FLAT_THRES_MASK UINT8_C(0x3F)
  188. #define BMI160_FLAT_HOLD_TIME_MASK UINT8_C(0x30)
  189. #define BMI160_FLAT_HYST_MASK UINT8_C(0x07)
  190. /** Mask definitions for INT_LOWHIGH register */
  191. #define BMI160_LOW_G_HYST_MASK UINT8_C(0x03)
  192. #define BMI160_LOW_G_LOW_MODE_MASK UINT8_C(0x04)
  193. #define BMI160_HIGH_G_HYST_MASK UINT8_C(0xC0)
  194. /** Mask definitions for INT_SIG_MOTION register */
  195. #define BMI160_SIG_MOTION_SEL_MASK UINT8_C(0x02)
  196. #define BMI160_SIG_MOTION_SKIP_MASK UINT8_C(0x0C)
  197. #define BMI160_SIG_MOTION_PROOF_MASK UINT8_C(0x30)
  198. /** Mask definitions for INT_ORIENT register */
  199. #define BMI160_ORIENT_MODE_MASK UINT8_C(0x03)
  200. #define BMI160_ORIENT_BLOCK_MASK UINT8_C(0x0C)
  201. #define BMI160_ORIENT_HYST_MASK UINT8_C(0xF0)
  202. #define BMI160_ORIENT_THETA_MASK UINT8_C(0x3F)
  203. #define BMI160_ORIENT_UD_ENABLE UINT8_C(0x40)
  204. #define BMI160_AXES_EN_MASK UINT8_C(0x80)
  205. /** Mask definitions for FIFO_CONFIG register */
  206. #define BMI160_FIFO_GYRO UINT8_C(0x80)
  207. #define BMI160_FIFO_ACCEL UINT8_C(0x40)
  208. #define BMI160_FIFO_AUX UINT8_C(0x20)
  209. #define BMI160_FIFO_TAG_INT1 UINT8_C(0x08)
  210. #define BMI160_FIFO_TAG_INT2 UINT8_C(0x04)
  211. #define BMI160_FIFO_TIME UINT8_C(0x02)
  212. #define BMI160_FIFO_HEADER UINT8_C(0x10)
  213. #define BMI160_FIFO_CONFIG_1_MASK UINT8_C(0xFE)
  214. /** Mask definitions for STEP_CONF register */
  215. #define BMI160_STEP_COUNT_EN_BIT_MASK UINT8_C(0x08)
  216. #define BMI160_STEP_DETECT_MIN_THRES_MASK UINT8_C(0x18)
  217. #define BMI160_STEP_DETECT_STEPTIME_MIN_MASK UINT8_C(0x07)
  218. #define BMI160_STEP_MIN_BUF_MASK UINT8_C(0x07)
  219. /** Mask definition for FIFO Header Data Tag */
  220. #define BMI160_FIFO_TAG_INTR_MASK UINT8_C(0xFC)
  221. /** Fifo byte counter mask definitions */
  222. #define BMI160_FIFO_BYTE_COUNTER_MASK UINT8_C(0x07)
  223. /** Enable/disable bit value */
  224. #define BMI160_ENABLE UINT8_C(0x01)
  225. #define BMI160_DISABLE UINT8_C(0x00)
  226. /** Latch Duration */
  227. #define BMI160_LATCH_DUR_NONE UINT8_C(0x00)
  228. #define BMI160_LATCH_DUR_312_5_MICRO_SEC UINT8_C(0x01)
  229. #define BMI160_LATCH_DUR_625_MICRO_SEC UINT8_C(0x02)
  230. #define BMI160_LATCH_DUR_1_25_MILLI_SEC UINT8_C(0x03)
  231. #define BMI160_LATCH_DUR_2_5_MILLI_SEC UINT8_C(0x04)
  232. #define BMI160_LATCH_DUR_5_MILLI_SEC UINT8_C(0x05)
  233. #define BMI160_LATCH_DUR_10_MILLI_SEC UINT8_C(0x06)
  234. #define BMI160_LATCH_DUR_20_MILLI_SEC UINT8_C(0x07)
  235. #define BMI160_LATCH_DUR_40_MILLI_SEC UINT8_C(0x08)
  236. #define BMI160_LATCH_DUR_80_MILLI_SEC UINT8_C(0x09)
  237. #define BMI160_LATCH_DUR_160_MILLI_SEC UINT8_C(0x0A)
  238. #define BMI160_LATCH_DUR_320_MILLI_SEC UINT8_C(0x0B)
  239. #define BMI160_LATCH_DUR_640_MILLI_SEC UINT8_C(0x0C)
  240. #define BMI160_LATCH_DUR_1_28_SEC UINT8_C(0x0D)
  241. #define BMI160_LATCH_DUR_2_56_SEC UINT8_C(0x0E)
  242. #define BMI160_LATCHED UINT8_C(0x0F)
  243. /** BMI160 Register map */
  244. #define BMI160_CHIP_ID_ADDR UINT8_C(0x00)
  245. #define BMI160_ERROR_REG_ADDR UINT8_C(0x02)
  246. #define BMI160_PMU_STATUS_ADDR UINT8_C(0x03)
  247. #define BMI160_AUX_DATA_ADDR UINT8_C(0x04)
  248. #define BMI160_GYRO_DATA_ADDR UINT8_C(0x0C)
  249. #define BMI160_ACCEL_DATA_ADDR UINT8_C(0x12)
  250. #define BMI160_STATUS_ADDR UINT8_C(0x1B)
  251. #define BMI160_INT_STATUS_ADDR UINT8_C(0x1C)
  252. #define BMI160_FIFO_LENGTH_ADDR UINT8_C(0x22)
  253. #define BMI160_FIFO_DATA_ADDR UINT8_C(0x24)
  254. #define BMI160_ACCEL_CONFIG_ADDR UINT8_C(0x40)
  255. #define BMI160_ACCEL_RANGE_ADDR UINT8_C(0x41)
  256. #define BMI160_GYRO_CONFIG_ADDR UINT8_C(0x42)
  257. #define BMI160_GYRO_RANGE_ADDR UINT8_C(0x43)
  258. #define BMI160_AUX_ODR_ADDR UINT8_C(0x44)
  259. #define BMI160_FIFO_DOWN_ADDR UINT8_C(0x45)
  260. #define BMI160_FIFO_CONFIG_0_ADDR UINT8_C(0x46)
  261. #define BMI160_FIFO_CONFIG_1_ADDR UINT8_C(0x47)
  262. #define BMI160_AUX_IF_0_ADDR UINT8_C(0x4B)
  263. #define BMI160_AUX_IF_1_ADDR UINT8_C(0x4C)
  264. #define BMI160_AUX_IF_2_ADDR UINT8_C(0x4D)
  265. #define BMI160_AUX_IF_3_ADDR UINT8_C(0x4E)
  266. #define BMI160_AUX_IF_4_ADDR UINT8_C(0x4F)
  267. #define BMI160_INT_ENABLE_0_ADDR UINT8_C(0x50)
  268. #define BMI160_INT_ENABLE_1_ADDR UINT8_C(0x51)
  269. #define BMI160_INT_ENABLE_2_ADDR UINT8_C(0x52)
  270. #define BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53)
  271. #define BMI160_INT_LATCH_ADDR UINT8_C(0x54)
  272. #define BMI160_INT_MAP_0_ADDR UINT8_C(0x55)
  273. #define BMI160_INT_MAP_1_ADDR UINT8_C(0x56)
  274. #define BMI160_INT_MAP_2_ADDR UINT8_C(0x57)
  275. #define BMI160_INT_DATA_0_ADDR UINT8_C(0x58)
  276. #define BMI160_INT_DATA_1_ADDR UINT8_C(0x59)
  277. #define BMI160_INT_LOWHIGH_0_ADDR UINT8_C(0x5A)
  278. #define BMI160_INT_LOWHIGH_1_ADDR UINT8_C(0x5B)
  279. #define BMI160_INT_LOWHIGH_2_ADDR UINT8_C(0x5C)
  280. #define BMI160_INT_LOWHIGH_3_ADDR UINT8_C(0x5D)
  281. #define BMI160_INT_LOWHIGH_4_ADDR UINT8_C(0x5E)
  282. #define BMI160_INT_MOTION_0_ADDR UINT8_C(0x5F)
  283. #define BMI160_INT_MOTION_1_ADDR UINT8_C(0x60)
  284. #define BMI160_INT_MOTION_2_ADDR UINT8_C(0x61)
  285. #define BMI160_INT_MOTION_3_ADDR UINT8_C(0x62)
  286. #define BMI160_INT_TAP_0_ADDR UINT8_C(0x63)
  287. #define BMI160_INT_TAP_1_ADDR UINT8_C(0x64)
  288. #define BMI160_INT_ORIENT_0_ADDR UINT8_C(0x65)
  289. #define BMI160_INT_ORIENT_1_ADDR UINT8_C(0x66)
  290. #define BMI160_INT_FLAT_0_ADDR UINT8_C(0x67)
  291. #define BMI160_INT_FLAT_1_ADDR UINT8_C(0x68)
  292. #define BMI160_FOC_CONF_ADDR UINT8_C(0x69)
  293. #define BMI160_CONF_ADDR UINT8_C(0x6A)
  294. #define BMI160_IF_CONF_ADDR UINT8_C(0x6B)
  295. #define BMI160_SELF_TEST_ADDR UINT8_C(0x6D)
  296. #define BMI160_OFFSET_ADDR UINT8_C(0x71)
  297. #define BMI160_OFFSET_CONF_ADDR UINT8_C(0x77)
  298. #define BMI160_INT_STEP_CNT_0_ADDR UINT8_C(0x78)
  299. #define BMI160_INT_STEP_CONFIG_0_ADDR UINT8_C(0x7A)
  300. #define BMI160_INT_STEP_CONFIG_1_ADDR UINT8_C(0x7B)
  301. #define BMI160_COMMAND_REG_ADDR UINT8_C(0x7E)
  302. #define BMI160_SPI_COMM_TEST_ADDR UINT8_C(0x7F)
  303. #define BMI160_INTL_PULLUP_CONF_ADDR UINT8_C(0x85)
  304. /** Error code definitions */
  305. #define BMI160_OK INT8_C(0)
  306. #define BMI160_E_NULL_PTR INT8_C(-1)
  307. #define BMI160_E_COM_FAIL INT8_C(-2)
  308. #define BMI160_E_DEV_NOT_FOUND INT8_C(-3)
  309. #define BMI160_E_OUT_OF_RANGE INT8_C(-4)
  310. #define BMI160_E_INVALID_INPUT INT8_C(-5)
  311. #define BMI160_E_ACCEL_ODR_BW_INVALID INT8_C(-6)
  312. #define BMI160_E_GYRO_ODR_BW_INVALID INT8_C(-7)
  313. #define BMI160_E_LWP_PRE_FLTR_INT_INVALID INT8_C(-8)
  314. #define BMI160_E_LWP_PRE_FLTR_INVALID INT8_C(-9)
  315. #define BMI160_E_AUX_NOT_FOUND INT8_C(-10)
  316. #define BMI160_FOC_FAILURE INT8_C(-11)
  317. #define BMI160_READ_WRITE_LENGHT_INVALID INT8_C(-12)
  318. /**\name API warning codes */
  319. #define BMI160_W_GYRO_SELF_TEST_FAIL INT8_C(1)
  320. #define BMI160_W_ACCEl_SELF_TEST_FAIL INT8_C(2)
  321. /** BMI160 unique chip identifier */
  322. #define BMI160_CHIP_ID UINT8_C(0xD1)
  323. /** Soft reset command */
  324. #define BMI160_SOFT_RESET_CMD UINT8_C(0xb6)
  325. #define BMI160_SOFT_RESET_DELAY_MS UINT8_C(1)
  326. /** Start FOC command */
  327. #define BMI160_START_FOC_CMD UINT8_C(0x03)
  328. /** NVM backup enabling command */
  329. #define BMI160_NVM_BACKUP_EN UINT8_C(0xA0)
  330. /* Delay in ms settings */
  331. #define BMI160_ACCEL_DELAY_MS UINT8_C(5)
  332. #define BMI160_GYRO_DELAY_MS UINT8_C(81)
  333. #define BMI160_ONE_MS_DELAY UINT8_C(1)
  334. #define BMI160_AUX_COM_DELAY UINT8_C(10)
  335. #define BMI160_GYRO_SELF_TEST_DELAY UINT8_C(20)
  336. #define BMI160_ACCEL_SELF_TEST_DELAY UINT8_C(50)
  337. /** Self test configurations */
  338. #define BMI160_ACCEL_SELF_TEST_CONFIG UINT8_C(0x2C)
  339. #define BMI160_ACCEL_SELF_TEST_POSITIVE_EN UINT8_C(0x0D)
  340. #define BMI160_ACCEL_SELF_TEST_NEGATIVE_EN UINT8_C(0x09)
  341. #define BMI160_ACCEL_SELF_TEST_LIMIT UINT16_C(8192)
  342. /** Power mode settings */
  343. /* Accel power mode */
  344. #define BMI160_ACCEL_NORMAL_MODE UINT8_C(0x11)
  345. #define BMI160_ACCEL_LOWPOWER_MODE UINT8_C(0x12)
  346. #define BMI160_ACCEL_SUSPEND_MODE UINT8_C(0x10)
  347. /* Gyro power mode */
  348. #define BMI160_GYRO_SUSPEND_MODE UINT8_C(0x14)
  349. #define BMI160_GYRO_NORMAL_MODE UINT8_C(0x15)
  350. #define BMI160_GYRO_FASTSTARTUP_MODE UINT8_C(0x17)
  351. /* Aux power mode */
  352. #define BMI160_AUX_SUSPEND_MODE UINT8_C(0x18)
  353. #define BMI160_AUX_NORMAL_MODE UINT8_C(0x19)
  354. #define BMI160_AUX_LOWPOWER_MODE UINT8_C(0x1A)
  355. /** Range settings */
  356. /* Accel Range */
  357. #define BMI160_ACCEL_RANGE_2G UINT8_C(0x03)
  358. #define BMI160_ACCEL_RANGE_4G UINT8_C(0x05)
  359. #define BMI160_ACCEL_RANGE_8G UINT8_C(0x08)
  360. #define BMI160_ACCEL_RANGE_16G UINT8_C(0x0C)
  361. /* Gyro Range */
  362. #define BMI160_GYRO_RANGE_2000_DPS UINT8_C(0x00)
  363. #define BMI160_GYRO_RANGE_1000_DPS UINT8_C(0x01)
  364. #define BMI160_GYRO_RANGE_500_DPS UINT8_C(0x02)
  365. #define BMI160_GYRO_RANGE_250_DPS UINT8_C(0x03)
  366. #define BMI160_GYRO_RANGE_125_DPS UINT8_C(0x04)
  367. /** Bandwidth settings */
  368. /* Accel Bandwidth */
  369. #define BMI160_ACCEL_BW_OSR4_AVG1 UINT8_C(0x00)
  370. #define BMI160_ACCEL_BW_OSR2_AVG2 UINT8_C(0x01)
  371. #define BMI160_ACCEL_BW_NORMAL_AVG4 UINT8_C(0x02)
  372. #define BMI160_ACCEL_BW_RES_AVG8 UINT8_C(0x03)
  373. #define BMI160_ACCEL_BW_RES_AVG16 UINT8_C(0x04)
  374. #define BMI160_ACCEL_BW_RES_AVG32 UINT8_C(0x05)
  375. #define BMI160_ACCEL_BW_RES_AVG64 UINT8_C(0x06)
  376. #define BMI160_ACCEL_BW_RES_AVG128 UINT8_C(0x07)
  377. #define BMI160_GYRO_BW_OSR4_MODE UINT8_C(0x00)
  378. #define BMI160_GYRO_BW_OSR2_MODE UINT8_C(0x01)
  379. #define BMI160_GYRO_BW_NORMAL_MODE UINT8_C(0x02)
  380. /* Output Data Rate settings */
  381. /* Accel Output data rate */
  382. #define BMI160_ACCEL_ODR_RESERVED UINT8_C(0x00)
  383. #define BMI160_ACCEL_ODR_0_78HZ UINT8_C(0x01)
  384. #define BMI160_ACCEL_ODR_1_56HZ UINT8_C(0x02)
  385. #define BMI160_ACCEL_ODR_3_12HZ UINT8_C(0x03)
  386. #define BMI160_ACCEL_ODR_6_25HZ UINT8_C(0x04)
  387. #define BMI160_ACCEL_ODR_12_5HZ UINT8_C(0x05)
  388. #define BMI160_ACCEL_ODR_25HZ UINT8_C(0x06)
  389. #define BMI160_ACCEL_ODR_50HZ UINT8_C(0x07)
  390. #define BMI160_ACCEL_ODR_100HZ UINT8_C(0x08)
  391. #define BMI160_ACCEL_ODR_200HZ UINT8_C(0x09)
  392. #define BMI160_ACCEL_ODR_400HZ UINT8_C(0x0A)
  393. #define BMI160_ACCEL_ODR_800HZ UINT8_C(0x0B)
  394. #define BMI160_ACCEL_ODR_1600HZ UINT8_C(0x0C)
  395. #define BMI160_ACCEL_ODR_RESERVED0 UINT8_C(0x0D)
  396. #define BMI160_ACCEL_ODR_RESERVED1 UINT8_C(0x0E)
  397. #define BMI160_ACCEL_ODR_RESERVED2 UINT8_C(0x0F)
  398. /* Gyro Output data rate */
  399. #define BMI160_GYRO_ODR_RESERVED UINT8_C(0x00)
  400. #define BMI160_GYRO_ODR_25HZ UINT8_C(0x06)
  401. #define BMI160_GYRO_ODR_50HZ UINT8_C(0x07)
  402. #define BMI160_GYRO_ODR_100HZ UINT8_C(0x08)
  403. #define BMI160_GYRO_ODR_200HZ UINT8_C(0x09)
  404. #define BMI160_GYRO_ODR_400HZ UINT8_C(0x0A)
  405. #define BMI160_GYRO_ODR_800HZ UINT8_C(0x0B)
  406. #define BMI160_GYRO_ODR_1600HZ UINT8_C(0x0C)
  407. #define BMI160_GYRO_ODR_3200HZ UINT8_C(0x0D)
  408. /* Auxiliary sensor Output data rate */
  409. #define BMI160_AUX_ODR_RESERVED UINT8_C(0x00)
  410. #define BMI160_AUX_ODR_0_78HZ UINT8_C(0x01)
  411. #define BMI160_AUX_ODR_1_56HZ UINT8_C(0x02)
  412. #define BMI160_AUX_ODR_3_12HZ UINT8_C(0x03)
  413. #define BMI160_AUX_ODR_6_25HZ UINT8_C(0x04)
  414. #define BMI160_AUX_ODR_12_5HZ UINT8_C(0x05)
  415. #define BMI160_AUX_ODR_25HZ UINT8_C(0x06)
  416. #define BMI160_AUX_ODR_50HZ UINT8_C(0x07)
  417. #define BMI160_AUX_ODR_100HZ UINT8_C(0x08)
  418. #define BMI160_AUX_ODR_200HZ UINT8_C(0x09)
  419. #define BMI160_AUX_ODR_400HZ UINT8_C(0x0A)
  420. #define BMI160_AUX_ODR_800HZ UINT8_C(0x0B)
  421. /** FIFO_CONFIG Definitions */
  422. #define BMI160_FIFO_TIME_ENABLE UINT8_C(0x02)
  423. #define BMI160_FIFO_TAG_INT2_ENABLE UINT8_C(0x04)
  424. #define BMI160_FIFO_TAG_INT1_ENABLE UINT8_C(0x08)
  425. #define BMI160_FIFO_HEAD_ENABLE UINT8_C(0x10)
  426. #define BMI160_FIFO_M_ENABLE UINT8_C(0x20)
  427. #define BMI160_FIFO_A_ENABLE UINT8_C(0x40)
  428. #define BMI160_FIFO_M_A_ENABLE UINT8_C(0x60)
  429. #define BMI160_FIFO_G_ENABLE UINT8_C(0x80)
  430. #define BMI160_FIFO_M_G_ENABLE UINT8_C(0xA0)
  431. #define BMI160_FIFO_G_A_ENABLE UINT8_C(0xC0)
  432. #define BMI160_FIFO_M_G_A_ENABLE UINT8_C(0xE0)
  433. /* Macro to specify the number of bytes over-read from the
  434. * FIFO in order to get the sensor time at the end of FIFO */
  435. #ifndef BMI160_FIFO_BYTES_OVERREAD
  436. #define BMI160_FIFO_BYTES_OVERREAD UINT8_C(25)
  437. #endif
  438. /* Accel, gyro and aux. sensor length and also their combined
  439. * length definitions in FIFO */
  440. #define BMI160_FIFO_G_LENGTH UINT8_C(6)
  441. #define BMI160_FIFO_A_LENGTH UINT8_C(6)
  442. #define BMI160_FIFO_M_LENGTH UINT8_C(8)
  443. #define BMI160_FIFO_GA_LENGTH UINT8_C(12)
  444. #define BMI160_FIFO_MA_LENGTH UINT8_C(14)
  445. #define BMI160_FIFO_MG_LENGTH UINT8_C(14)
  446. #define BMI160_FIFO_MGA_LENGTH UINT8_C(20)
  447. /** FIFO Header Data definitions */
  448. #define BMI160_FIFO_HEAD_SKIP_FRAME UINT8_C(0x40)
  449. #define BMI160_FIFO_HEAD_SENSOR_TIME UINT8_C(0x44)
  450. #define BMI160_FIFO_HEAD_INPUT_CONFIG UINT8_C(0x48)
  451. #define BMI160_FIFO_HEAD_OVER_READ UINT8_C(0x80)
  452. #define BMI160_FIFO_HEAD_A UINT8_C(0x84)
  453. #define BMI160_FIFO_HEAD_G UINT8_C(0x88)
  454. #define BMI160_FIFO_HEAD_G_A UINT8_C(0x8C)
  455. #define BMI160_FIFO_HEAD_M UINT8_C(0x90)
  456. #define BMI160_FIFO_HEAD_M_A UINT8_C(0x94)
  457. #define BMI160_FIFO_HEAD_M_G UINT8_C(0x98)
  458. #define BMI160_FIFO_HEAD_M_G_A UINT8_C(0x9C)
  459. /** FIFO sensor time length definitions */
  460. #define BMI160_SENSOR_TIME_LENGTH UINT8_C(3)
  461. /** FIFO DOWN selection */
  462. /* Accel fifo down-sampling values*/
  463. #define BMI160_ACCEL_FIFO_DOWN_ZERO UINT8_C(0x00)
  464. #define BMI160_ACCEL_FIFO_DOWN_ONE UINT8_C(0x10)
  465. #define BMI160_ACCEL_FIFO_DOWN_TWO UINT8_C(0x20)
  466. #define BMI160_ACCEL_FIFO_DOWN_THREE UINT8_C(0x30)
  467. #define BMI160_ACCEL_FIFO_DOWN_FOUR UINT8_C(0x40)
  468. #define BMI160_ACCEL_FIFO_DOWN_FIVE UINT8_C(0x50)
  469. #define BMI160_ACCEL_FIFO_DOWN_SIX UINT8_C(0x60)
  470. #define BMI160_ACCEL_FIFO_DOWN_SEVEN UINT8_C(0x70)
  471. /* Gyro fifo down-smapling values*/
  472. #define BMI160_GYRO_FIFO_DOWN_ZERO UINT8_C(0x00)
  473. #define BMI160_GYRO_FIFO_DOWN_ONE UINT8_C(0x01)
  474. #define BMI160_GYRO_FIFO_DOWN_TWO UINT8_C(0x02)
  475. #define BMI160_GYRO_FIFO_DOWN_THREE UINT8_C(0x03)
  476. #define BMI160_GYRO_FIFO_DOWN_FOUR UINT8_C(0x04)
  477. #define BMI160_GYRO_FIFO_DOWN_FIVE UINT8_C(0x05)
  478. #define BMI160_GYRO_FIFO_DOWN_SIX UINT8_C(0x06)
  479. #define BMI160_GYRO_FIFO_DOWN_SEVEN UINT8_C(0x07)
  480. /* Accel Fifo filter enable*/
  481. #define BMI160_ACCEL_FIFO_FILT_EN UINT8_C(0x80)
  482. /* Gyro Fifo filter enable*/
  483. #define BMI160_GYRO_FIFO_FILT_EN UINT8_C(0x08)
  484. /** Definitions to check validity of FIFO frames */
  485. #define FIFO_CONFIG_MSB_CHECK UINT8_C(0x80)
  486. #define FIFO_CONFIG_LSB_CHECK UINT8_C(0x00)
  487. /*! BMI160 accel FOC configurations */
  488. #define BMI160_FOC_ACCEL_DISABLED UINT8_C(0x00)
  489. #define BMI160_FOC_ACCEL_POSITIVE_G UINT8_C(0x01)
  490. #define BMI160_FOC_ACCEL_NEGATIVE_G UINT8_C(0x02)
  491. #define BMI160_FOC_ACCEL_0G UINT8_C(0x03)
  492. /** Array Parameter DefinItions */
  493. #define BMI160_SENSOR_TIME_LSB_BYTE UINT8_C(0)
  494. #define BMI160_SENSOR_TIME_XLSB_BYTE UINT8_C(1)
  495. #define BMI160_SENSOR_TIME_MSB_BYTE UINT8_C(2)
  496. /** Interface settings */
  497. #define BMI160_SPI_INTF UINT8_C(1)
  498. #define BMI160_I2C_INTF UINT8_C(0)
  499. #define BMI160_SPI_RD_MASK UINT8_C(0x80)
  500. #define BMI160_SPI_WR_MASK UINT8_C(0x7F)
  501. /* Sensor & time select definition*/
  502. #define BMI160_ACCEL_SEL UINT8_C(0x01)
  503. #define BMI160_GYRO_SEL UINT8_C(0x02)
  504. #define BMI160_TIME_SEL UINT8_C(0x04)
  505. /* Sensor select mask*/
  506. #define BMI160_SEN_SEL_MASK UINT8_C(0x07)
  507. /* Error code mask */
  508. #define BMI160_ERR_REG_MASK UINT8_C(0x0F)
  509. /* BMI160 I2C address */
  510. #define BMI160_I2C_ADDR UINT8_C(0x68)
  511. /* BMI160 secondary IF address */
  512. #define BMI160_AUX_BMM150_I2C_ADDR UINT8_C(0x10)
  513. /** BMI160 Length definitions */
  514. #define BMI160_ONE UINT8_C(1)
  515. #define BMI160_TWO UINT8_C(2)
  516. #define BMI160_THREE UINT8_C(3)
  517. #define BMI160_FOUR UINT8_C(4)
  518. #define BMI160_FIVE UINT8_C(5)
  519. /** BMI160 fifo level Margin */
  520. #define BMI160_FIFO_LEVEL_MARGIN UINT8_C(16)
  521. /** BMI160 fifo flush Command */
  522. #define BMI160_FIFO_FLUSH_VALUE UINT8_C(0xB0)
  523. /** BMI160 offset values for xyz axes of accel */
  524. #define BMI160_ACCEL_MIN_OFFSET INT8_C(-128)
  525. #define BMI160_ACCEL_MAX_OFFSET INT8_C(127)
  526. /** BMI160 offset values for xyz axes of gyro */
  527. #define BMI160_GYRO_MIN_OFFSET INT16_C(-512)
  528. #define BMI160_GYRO_MAX_OFFSET INT16_C(511)
  529. /** BMI160 fifo full interrupt position and mask */
  530. #define BMI160_FIFO_FULL_INT_POS UINT8_C(5)
  531. #define BMI160_FIFO_FULL_INT_MSK UINT8_C(0x20)
  532. #define BMI160_FIFO_WTM_INT_POS UINT8_C(6)
  533. #define BMI160_FIFO_WTM_INT_MSK UINT8_C(0x40)
  534. #define BMI160_FIFO_FULL_INT_PIN1_POS UINT8_C(5)
  535. #define BMI160_FIFO_FULL_INT_PIN1_MSK UINT8_C(0x20)
  536. #define BMI160_FIFO_FULL_INT_PIN2_POS UINT8_C(1)
  537. #define BMI160_FIFO_FULL_INT_PIN2_MSK UINT8_C(0x02)
  538. #define BMI160_FIFO_WTM_INT_PIN1_POS UINT8_C(6)
  539. #define BMI160_FIFO_WTM_INT_PIN1_MSK UINT8_C(0x40)
  540. #define BMI160_FIFO_WTM_INT_PIN2_POS UINT8_C(2)
  541. #define BMI160_FIFO_WTM_INT_PIN2_MSK UINT8_C(0x04)
  542. #define BMI160_MANUAL_MODE_EN_POS UINT8_C(7)
  543. #define BMI160_MANUAL_MODE_EN_MSK UINT8_C(0x80)
  544. #define BMI160_AUX_READ_BURST_POS UINT8_C(0)
  545. #define BMI160_AUX_READ_BURST_MSK UINT8_C(0x03)
  546. #define BMI160_GYRO_SELF_TEST_POS UINT8_C(4)
  547. #define BMI160_GYRO_SELF_TEST_MSK UINT8_C(0x10)
  548. #define BMI160_GYRO_SELF_TEST_STATUS_POS UINT8_C(1)
  549. #define BMI160_GYRO_SELF_TEST_STATUS_MSK UINT8_C(0x02)
  550. #define BMI160_GYRO_FOC_EN_POS UINT8_C(6)
  551. #define BMI160_GYRO_FOC_EN_MSK UINT8_C(0x40)
  552. #define BMI160_ACCEL_FOC_X_CONF_POS UINT8_C(4)
  553. #define BMI160_ACCEL_FOC_X_CONF_MSK UINT8_C(0x30)
  554. #define BMI160_ACCEL_FOC_Y_CONF_POS UINT8_C(2)
  555. #define BMI160_ACCEL_FOC_Y_CONF_MSK UINT8_C(0x0C)
  556. #define BMI160_ACCEL_FOC_Z_CONF_MSK UINT8_C(0x03)
  557. #define BMI160_FOC_STATUS_POS UINT8_C(3)
  558. #define BMI160_FOC_STATUS_MSK UINT8_C(0x08)
  559. #define BMI160_GYRO_OFFSET_X_MSK UINT8_C(0x03)
  560. #define BMI160_GYRO_OFFSET_Y_POS UINT8_C(2)
  561. #define BMI160_GYRO_OFFSET_Y_MSK UINT8_C(0x0C)
  562. #define BMI160_GYRO_OFFSET_Z_POS UINT8_C(4)
  563. #define BMI160_GYRO_OFFSET_Z_MSK UINT8_C(0x30)
  564. #define BMI160_GYRO_OFFSET_EN_POS UINT8_C(7)
  565. #define BMI160_GYRO_OFFSET_EN_MSK UINT8_C(0x80)
  566. #define BMI160_ACCEL_OFFSET_EN_POS UINT8_C(6)
  567. #define BMI160_ACCEL_OFFSET_EN_MSK UINT8_C(0x40)
  568. #define BMI160_GYRO_OFFSET_POS UINT16_C(8)
  569. #define BMI160_GYRO_OFFSET_MSK UINT16_C(0x0300)
  570. #define BMI160_NVM_UPDATE_POS UINT8_C(1)
  571. #define BMI160_NVM_UPDATE_MSK UINT8_C(0x02)
  572. #define BMI160_NVM_STATUS_POS UINT8_C(4)
  573. #define BMI160_NVM_STATUS_MSK UINT8_C(0x10)
  574. #define BMI160_MAG_POWER_MODE_MSK UINT8_C(0x03)
  575. #define BMI160_ACCEL_POWER_MODE_MSK UINT8_C(0x30)
  576. #define BMI160_ACCEL_POWER_MODE_POS UINT8_C(4)
  577. #define BMI160_GYRO_POWER_MODE_MSK UINT8_C(0x0C)
  578. #define BMI160_GYRO_POWER_MODE_POS UINT8_C(2)
  579. /* BIT SLICE GET AND SET FUNCTIONS */
  580. #define BMI160_GET_BITS(regvar, bitname) \
  581. ((regvar & bitname##_MSK) >> bitname##_POS)
  582. #define BMI160_SET_BITS(regvar, bitname, val) \
  583. ((regvar & ~bitname##_MSK) | \
  584. ((val << bitname##_POS) & bitname##_MSK))
  585. #define BMI160_SET_BITS_POS_0(reg_data, bitname, data) \
  586. ((reg_data & ~(bitname##_MSK)) | \
  587. (data & bitname##_MSK))
  588. #define BMI160_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
  589. /**\name UTILITY MACROS */
  590. #define BMI160_SET_LOW_BYTE UINT16_C(0x00FF)
  591. #define BMI160_SET_HIGH_BYTE UINT16_C(0xFF00)
  592. #define BMI160_GET_LSB(var) (uint8_t)(var & BMI160_SET_LOW_BYTE)
  593. #define BMI160_GET_MSB(var) (uint8_t)((var & BMI160_SET_HIGH_BYTE) >> 8)
  594. /*****************************************************************************/
  595. /* type definitions */
  596. /*!
  597. * @brief Bus communication function pointer which should be mapped to
  598. * the platform specific read functions of the user
  599. */
  600. typedef int8_t (*bmi160_read_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);
  601. /*!
  602. * @brief Bus communication function pointer which should be mapped to
  603. * the platform specific write functions of the user
  604. */
  605. typedef int8_t (*bmi160_write_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_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 bmi160_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 intf;
  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_read_fptr_t read;
  1339. /*! Write function pointer */
  1340. bmi160_write_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. };
  1346. #endif /* BMI160_DEFS_H_ */