bmi160_defs.h 47 KB

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