bmi160_defs.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. /**
  2. * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of the copyright holder nor the names of the
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  33. *
  34. * The information provided is believed to be accurate and reliable.
  35. * The copyright holder assumes no responsibility
  36. * for the consequences of use
  37. * of such information nor for any infringement of patents or
  38. * other rights of third parties which may result from its use.
  39. * No license is granted by implication or otherwise under any patent or
  40. * patent rights of the copyright holder.
  41. *
  42. * @file bmi160_defs.h
  43. * @date 13 Apr 2017
  44. * @version 3.5.0
  45. * @brief
  46. *
  47. */
  48. /*!
  49. * @defgroup bmi160_defs
  50. * @brief
  51. * @{*/
  52. #ifndef BMI160_DEFS_H_
  53. #define BMI160_DEFS_H_
  54. /*************************** C types headers *****************************/
  55. #ifdef __KERNEL__
  56. #include <linux/types.h>
  57. #else
  58. #include <stdint.h>
  59. #include <stddef.h>
  60. #endif
  61. /*************************** C++ guard macro *****************************/
  62. #ifdef __cplusplus
  63. extern "C"
  64. {
  65. #endif
  66. /*************************** Common macros *****************************/
  67. #if (LONG_MAX) > 0x7fffffff
  68. #define __have_long64 1
  69. #elif (LONG_MAX) == 0x7fffffff
  70. #define __have_long32 1
  71. #endif
  72. #if !defined(UINT8_C)
  73. #define INT8_C(x) x
  74. #if (INT_MAX) > 0x7f
  75. #define UINT8_C(x) x
  76. #else
  77. #define UINT8_C(x) x##U
  78. #endif
  79. #endif
  80. #if !defined(UINT16_C)
  81. #define INT16_C(x) x
  82. #if (INT_MAX) > 0x7fff
  83. #define UINT16_C(x) x
  84. #else
  85. #define UINT16_C(x) x##U
  86. #endif
  87. #endif
  88. #if !defined(INT32_C) && !defined(UINT32_C)
  89. #if __have_long32
  90. #define INT32_C(x) x##L
  91. #define UINT32_C(x) x##UL
  92. #else
  93. #define INT32_C(x) x
  94. #define UINT32_C(x) x##U
  95. #endif
  96. #endif
  97. #if !defined(INT64_C) && !defined(UINT64_C)
  98. #if __have_long64
  99. #define INT64_C(x) x##L
  100. #define UINT64_C(x) x##UL
  101. #else
  102. #define INT64_C(x) x##LL
  103. #define UINT64_C(x) x##ULL
  104. #endif
  105. #endif
  106. /*************************** Sensor macros *****************************/
  107. /* Test for an endian machine */
  108. #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  109. #define LITTLE_ENDIAN 1
  110. #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  111. #define BIG_ENDIAN 1
  112. #else
  113. #error "Code does not support Endian format of the processor"
  114. #endif
  115. /** Mask definitions */
  116. #define BMI160_ACCEL_BW_MASK UINT8_C(0x70)
  117. #define BMI160_ACCEL_ODR_MASK UINT8_C(0x0F)
  118. #define BMI160_ACCEL_UNDERSAMPLING_MASK UINT8_C(0x80)
  119. #define BMI160_ACCEL_RANGE_MASK UINT8_C(0x0F)
  120. #define BMI160_GYRO_BW_MASK UINT8_C(0x30)
  121. #define BMI160_GYRO_ODR_MASK UINT8_C(0x0F)
  122. #define BMI160_GYRO_RANGE_MSK UINT8_C(0x07)
  123. /** Mask definitions for INT_EN registers */
  124. #define BMI160_ANY_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  125. #define BMI160_HIGH_G_X_INT_EN_MASK UINT8_C(0x01)
  126. #define BMI160_NO_MOTION_X_INT_EN_MASK UINT8_C(0x01)
  127. #define BMI160_ANY_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  128. #define BMI160_HIGH_G_Y_INT_EN_MASK UINT8_C(0x02)
  129. #define BMI160_NO_MOTION_Y_INT_EN_MASK UINT8_C(0x02)
  130. #define BMI160_ANY_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  131. #define BMI160_HIGH_G_Z_INT_EN_MASK UINT8_C(0x04)
  132. #define BMI160_NO_MOTION_Z_INT_EN_MASK UINT8_C(0x04)
  133. #define BMI160_SIG_MOTION_INT_EN_MASK UINT8_C(0x07)
  134. #define BMI160_ANY_MOTION_ALL_INT_EN_MASK UINT8_C(0x07)
  135. #define BMI160_STEP_DETECT_INT_EN_MASK UINT8_C(0x08)
  136. #define BMI160_DOUBLE_TAP_INT_EN_MASK UINT8_C(0x10)
  137. #define BMI160_SINGLE_TAP_INT_EN_MASK UINT8_C(0x20)
  138. #define BMI160_FIFO_FULL_INT_EN_MASK UINT8_C(0x20)
  139. #define BMI160_ORIENT_INT_EN_MASK UINT8_C(0x40)
  140. #define BMI160_FIFO_WATERMARK_INT_EN_MASK UINT8_C(0x40)
  141. #define BMI160_LOW_G_INT_EN_MASK UINT8_C(0x08)
  142. #define BMI160_STEP_DETECT_EN_MASK UINT8_C(0x08)
  143. #define BMI160_FLAT_INT_EN_MASK UINT8_C(0x80)
  144. #define BMI160_DATA_RDY_INT_EN_MASK UINT8_C(0x10)
  145. /** Mask definitions for INT_OUT_CTRL register */
  146. #define BMI160_INT1_EDGE_CTRL_MASK UINT8_C(0x01)
  147. #define BMI160_INT1_OUTPUT_MODE_MASK UINT8_C(0x04)
  148. #define BMI160_INT1_OUTPUT_TYPE_MASK UINT8_C(0x02)
  149. #define BMI160_INT1_OUTPUT_EN_MASK UINT8_C(0x08)
  150. #define BMI160_INT2_EDGE_CTRL_MASK UINT8_C(0x10)
  151. #define BMI160_INT2_OUTPUT_MODE_MASK UINT8_C(0x40)
  152. #define BMI160_INT2_OUTPUT_TYPE_MASK UINT8_C(0x20)
  153. #define BMI160_INT2_OUTPUT_EN_MASK UINT8_C(0x80)
  154. /** Mask definitions for INT_LATCH register */
  155. #define BMI160_INT1_INPUT_EN_MASK UINT8_C(0x10)
  156. #define BMI160_INT2_INPUT_EN_MASK UINT8_C(0x20)
  157. #define BMI160_INT_LATCH_MASK UINT8_C(0x0F)
  158. /** Mask definitions for INT_MAP register */
  159. #define BMI160_INT1_LOW_G_MASK UINT8_C(0x01)
  160. #define BMI160_INT1_HIGH_G_MASK UINT8_C(0x02)
  161. #define BMI160_INT1_SLOPE_MASK UINT8_C(0x04)
  162. #define BMI160_INT1_NO_MOTION_MASK UINT8_C(0x08)
  163. #define BMI160_INT1_DOUBLE_TAP_MASK UINT8_C(0x10)
  164. #define BMI160_INT1_SINGLE_TAP_MASK UINT8_C(0x20)
  165. #define BMI160_INT1_FIFO_FULL_MASK UINT8_C(0x20)
  166. #define BMI160_INT1_FIFO_WM_MASK UINT8_C(0x40)
  167. #define BMI160_INT1_ORIENT_MASK UINT8_C(0x40)
  168. #define BMI160_INT1_FLAT_MASK UINT8_C(0x80)
  169. #define BMI160_INT1_DATA_READY_MASK UINT8_C(0x80)
  170. #define BMI160_INT2_LOW_G_MASK UINT8_C(0x01)
  171. #define BMI160_INT1_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  172. #define BMI160_INT2_LOW_STEP_DETECT_MASK UINT8_C(0x01)
  173. #define BMI160_INT2_HIGH_G_MASK UINT8_C(0x02)
  174. #define BMI160_INT2_FIFO_FULL_MASK UINT8_C(0x02)
  175. #define BMI160_INT2_FIFO_WM_MASK UINT8_C(0x04)
  176. #define BMI160_INT2_SLOPE_MASK UINT8_C(0x04)
  177. #define BMI160_INT2_DATA_READY_MASK UINT8_C(0x08)
  178. #define BMI160_INT2_NO_MOTION_MASK UINT8_C(0x08)
  179. #define BMI160_INT2_DOUBLE_TAP_MASK UINT8_C(0x10)
  180. #define BMI160_INT2_SINGLE_TAP_MASK UINT8_C(0x20)
  181. #define BMI160_INT2_ORIENT_MASK UINT8_C(0x40)
  182. #define BMI160_INT2_FLAT_MASK UINT8_C(0x80)
  183. /** Mask definitions for INT_DATA register */
  184. #define BMI160_TAP_SRC_INT_MASK UINT8_C(0x08)
  185. #define BMI160_LOW_HIGH_SRC_INT_MASK UINT8_C(0x80)
  186. #define BMI160_MOTION_SRC_INT_MASK UINT8_C(0x80)
  187. /** Mask definitions for INT_MOTION register */
  188. #define BMI160_SLOPE_INT_DUR_MASK UINT8_C(0x03)
  189. #define BMI160_NO_MOTION_INT_DUR_MASK UINT8_C(0xFC)
  190. #define BMI160_NO_MOTION_SEL_BIT_MASK UINT8_C(0x01)
  191. /** Mask definitions for INT_TAP register */
  192. #define BMI160_TAP_DUR_MASK UINT8_C(0x07)
  193. #define BMI160_TAP_SHOCK_DUR_MASK UINT8_C(0x40)
  194. #define BMI160_TAP_QUIET_DUR_MASK UINT8_C(0x80)
  195. #define BMI160_TAP_THRES_MASK UINT8_C(0x1F)
  196. /** Mask definitions for INT_FLAT register */
  197. #define BMI160_FLAT_THRES_MASK UINT8_C(0x3F)
  198. #define BMI160_FLAT_HOLD_TIME_MASK UINT8_C(0x30)
  199. #define BMI160_FLAT_HYST_MASK UINT8_C(0x07)
  200. /** Mask definitions for INT_LOWHIGH register */
  201. #define BMI160_LOW_G_HYST_MASK UINT8_C(0x03)
  202. #define BMI160_LOW_G_LOW_MODE_MASK UINT8_C(0x04)
  203. #define BMI160_HIGH_G_HYST_MASK UINT8_C(0xC0)
  204. /** Mask definitions for INT_SIG_MOTION register */
  205. #define BMI160_SIG_MOTION_SEL_MASK UINT8_C(0x02)
  206. #define BMI160_SIG_MOTION_SKIP_MASK UINT8_C(0x0C)
  207. #define BMI160_SIG_MOTION_PROOF_MASK UINT8_C(0x30)
  208. /** Mask definitions for INT_ORIENT register */
  209. #define BMI160_ORIENT_MODE_MASK UINT8_C(0x03)
  210. #define BMI160_ORIENT_BLOCK_MASK UINT8_C(0x0C)
  211. #define BMI160_ORIENT_HYST_MASK UINT8_C(0xF0)
  212. #define BMI160_ORIENT_THETA_MASK UINT8_C(0x3F)
  213. #define BMI160_ORIENT_UD_ENABLE UINT8_C(0x40)
  214. #define BMI160_AXES_EN_MASK UINT8_C(0x80)
  215. /** Mask definitions for FIFO_CONFIG register */
  216. #define BMI160_FIFO_GYRO UINT8_C(0x80)
  217. #define BMI160_FIFO_ACCEL UINT8_C(0x40)
  218. #define BMI160_FIFO_AUX UINT8_C(0x20)
  219. #define BMI160_FIFO_TAG_INT1 UINT8_C(0x08)
  220. #define BMI160_FIFO_TAG_INT2 UINT8_C(0x04)
  221. #define BMI160_FIFO_TIME UINT8_C(0x02)
  222. #define BMI160_FIFO_HEADER UINT8_C(0x10)
  223. #define BMI160_FIFO_CONFIG_1_MASK UINT8_C(0xFE)
  224. /** Mask definitions for STEP_CONF register */
  225. #define BMI160_STEP_COUNT_EN_BIT_MASK UINT8_C(0x08)
  226. #define BMI160_STEP_DETECT_MIN_THRES_MASK UINT8_C(0x18)
  227. #define BMI160_STEP_DETECT_STEPTIME_MIN_MASK UINT8_C(0x07)
  228. #define BMI160_STEP_MIN_BUF_MASK UINT8_C(0x07)
  229. /** Mask definition for FIFO Header Data Tag */
  230. #define BMI160_FIFO_TAG_INTR_MASK UINT8_C(0xFC)
  231. /** Fifo byte counter mask definitions */
  232. #define BMI160_FIFO_BYTE_COUNTER_MASK UINT8_C(0x07)
  233. /** Enable/disable bit value */
  234. #define BMI160_ENABLE UINT8_C(0x01)
  235. #define BMI160_DISABLE UINT8_C(0x00)
  236. /** Latch Duration */
  237. #define BMI160_LATCH_DUR_NONE UINT8_C(0x00)
  238. #define BMI160_LATCH_DUR_312_5_MICRO_SEC UINT8_C(0x01)
  239. #define BMI160_LATCH_DUR_625_MICRO_SEC UINT8_C(0x02)
  240. #define BMI160_LATCH_DUR_1_25_MILLI_SEC UINT8_C(0x03)
  241. #define BMI160_LATCH_DUR_2_5_MILLI_SEC UINT8_C(0x04)
  242. #define BMI160_LATCH_DUR_5_MILLI_SEC UINT8_C(0x05)
  243. #define BMI160_LATCH_DUR_10_MILLI_SEC UINT8_C(0x06)
  244. #define BMI160_LATCH_DUR_20_MILLI_SEC UINT8_C(0x07)
  245. #define BMI160_LATCH_DUR_40_MILLI_SEC UINT8_C(0x08)
  246. #define BMI160_LATCH_DUR_80_MILLI_SEC UINT8_C(0x09)
  247. #define BMI160_LATCH_DUR_160_MILLI_SEC UINT8_C(0x0A)
  248. #define BMI160_LATCH_DUR_320_MILLI_SEC UINT8_C(0x0B)
  249. #define BMI160_LATCH_DUR_640_MILLI_SEC UINT8_C(0x0C)
  250. #define BMI160_LATCH_DUR_1_28_SEC UINT8_C(0x0D)
  251. #define BMI160_LATCH_DUR_2_56_SEC UINT8_C(0x0E)
  252. #define BMI160_LATCHED UINT8_C(0x0F)
  253. /** BMI160 Register map */
  254. #define BMI160_CHIP_ID_ADDR UINT8_C(0x00)
  255. #define BMI160_ERROR_REG_ADDR UINT8_C(0x02)
  256. #define BMI160_AUX_DATA_ADDR UINT8_C(0x04)
  257. #define BMI160_GYRO_DATA_ADDR UINT8_C(0x0C)
  258. #define BMI160_ACCEL_DATA_ADDR UINT8_C(0x12)
  259. #define BMI160_STATUS_ADDR UINT8_C(0x1B)
  260. #define BMI160_FIFO_LENGTH_ADDR UINT8_C(0x22)
  261. #define BMI160_FIFO_DATA_ADDR UINT8_C(0x24)
  262. #define BMI160_ACCEL_CONFIG_ADDR UINT8_C(0x40)
  263. #define BMI160_ACCEL_RANGE_ADDR UINT8_C(0x41)
  264. #define BMI160_GYRO_CONFIG_ADDR UINT8_C(0x42)
  265. #define BMI160_GYRO_RANGE_ADDR UINT8_C(0x43)
  266. #define BMI160_AUX_ODR_ADDR UINT8_C(0x44)
  267. #define BMI160_FIFO_DOWN_ADDR UINT8_C(0x45)
  268. #define BMI160_FIFO_CONFIG_0_ADDR UINT8_C(0x46)
  269. #define BMI160_FIFO_CONFIG_1_ADDR UINT8_C(0x47)
  270. #define BMI160_AUX_IF_0_ADDR UINT8_C(0x4B)
  271. #define BMI160_AUX_IF_1_ADDR UINT8_C(0x4C)
  272. #define BMI160_AUX_IF_2_ADDR UINT8_C(0x4D)
  273. #define BMI160_AUX_IF_3_ADDR UINT8_C(0x4E)
  274. #define BMI160_AUX_IF_4_ADDR UINT8_C(0x4F)
  275. #define BMI160_INT_ENABLE_0_ADDR UINT8_C(0x50)
  276. #define BMI160_INT_ENABLE_1_ADDR UINT8_C(0x51)
  277. #define BMI160_INT_ENABLE_2_ADDR UINT8_C(0x52)
  278. #define BMI160_INT_OUT_CTRL_ADDR UINT8_C(0x53)
  279. #define BMI160_INT_LATCH_ADDR UINT8_C(0x54)
  280. #define BMI160_INT_MAP_0_ADDR UINT8_C(0x55)
  281. #define BMI160_INT_MAP_1_ADDR UINT8_C(0x56)
  282. #define BMI160_INT_MAP_2_ADDR UINT8_C(0x57)
  283. #define BMI160_INT_DATA_0_ADDR UINT8_C(0x58)
  284. #define BMI160_INT_DATA_1_ADDR UINT8_C(0x59)
  285. #define BMI160_INT_LOWHIGH_0_ADDR UINT8_C(0x5A)
  286. #define BMI160_INT_LOWHIGH_1_ADDR UINT8_C(0x5B)
  287. #define BMI160_INT_LOWHIGH_2_ADDR UINT8_C(0x5C)
  288. #define BMI160_INT_LOWHIGH_3_ADDR UINT8_C(0x5D)
  289. #define BMI160_INT_LOWHIGH_4_ADDR UINT8_C(0x5E)
  290. #define BMI160_INT_MOTION_0_ADDR UINT8_C(0x5F)
  291. #define BMI160_INT_MOTION_1_ADDR UINT8_C(0x60)
  292. #define BMI160_INT_MOTION_2_ADDR UINT8_C(0x61)
  293. #define BMI160_INT_MOTION_3_ADDR UINT8_C(0x62)
  294. #define BMI160_INT_TAP_0_ADDR UINT8_C(0x63)
  295. #define BMI160_INT_TAP_1_ADDR UINT8_C(0x64)
  296. #define BMI160_INT_ORIENT_0_ADDR UINT8_C(0x65)
  297. #define BMI160_INT_ORIENT_1_ADDR UINT8_C(0x66)
  298. #define BMI160_INT_FLAT_0_ADDR UINT8_C(0x67)
  299. #define BMI160_INT_FLAT_1_ADDR UINT8_C(0x68)
  300. #define BMI160_IF_CONF_ADDR UINT8_C(0x6B)
  301. #define BMI160_SELF_TEST_ADDR UINT8_C(0x6D)
  302. #define BMI160_INT_STEP_CNT_0_ADDR UINT8_C(0x78)
  303. #define BMI160_INT_STEP_CONFIG_0_ADDR UINT8_C(0x7A)
  304. #define BMI160_INT_STEP_CONFIG_1_ADDR UINT8_C(0x7B)
  305. #define BMI160_COMMAND_REG_ADDR UINT8_C(0x7E)
  306. #define BMI160_SPI_COMM_TEST_ADDR UINT8_C(0x7F)
  307. #define BMI160_INTL_PULLUP_CONF_ADDR UINT8_C(0x85)
  308. /** Error code definitions */
  309. #define BMI160_OK INT8_C(0)
  310. #define BMI160_E_NULL_PTR INT8_C(-1)
  311. #define BMI160_E_COM_FAIL INT8_C(-2)
  312. #define BMI160_E_DEV_NOT_FOUND INT8_C(-3)
  313. #define BMI160_E_OUT_OF_RANGE INT8_C(-4)
  314. #define BMI160_E_INVALID_INPUT INT8_C(-5)
  315. #define BMI160_E_ACCEL_ODR_BW_INVALID INT8_C(-6)
  316. #define BMI160_E_GYRO_ODR_BW_INVALID INT8_C(-7)
  317. #define BMI160_E_LWP_PRE_FLTR_INT_INVALID INT8_C(-8)
  318. #define BMI160_E_LWP_PRE_FLTR_INVALID INT8_C(-9)
  319. #define BMI160_E_AUX_NOT_FOUND INT8_C(-10)
  320. /**\name API warning codes */
  321. #define BMI160_W_GYRO_SELF_TEST_FAIL INT8_C(1)
  322. #define BMI160_W_ACCEl_SELF_TEST_FAIL INT8_C(2)
  323. /** BMI160 unique chip identifier */
  324. #define BMI160_CHIP_ID UINT8_C(0xD1)
  325. /** Soft reset command */
  326. #define BMI160_SOFT_RESET_CMD UINT8_C(0xb6)
  327. #define BMI160_SOFT_RESET_DELAY_MS UINT8_C(15)
  328. /* Delay in ms settings */
  329. #define BMI160_ACCEL_DELAY_MS UINT8_C(5)
  330. #define BMI160_GYRO_DELAY_MS UINT8_C(81)
  331. #define BMI160_ONE_MS_DELAY UINT8_C(1)
  332. #define BMI160_AUX_COM_DELAY UINT8_C(10)
  333. #define BMI160_GYRO_SELF_TEST_DELAY UINT8_C(20)
  334. #define BMI160_ACCEL_SELF_TEST_DELAY UINT8_C(50)
  335. /** Self test configurations */
  336. #define BMI160_ACCEL_SELF_TEST_CONFIG UINT8_C(0x2C)
  337. #define BMI160_ACCEL_SELF_TEST_POSITIVE_EN UINT8_C(0x0D)
  338. #define BMI160_ACCEL_SELF_TEST_NEGATIVE_EN UINT8_C(0x09)
  339. #define BMI160_ACCEL_SELF_TEST_LIMIT UINT16_C(8192)
  340. /** Power mode settings */
  341. /* Accel power mode */
  342. #define BMI160_ACCEL_NORMAL_MODE UINT8_C(0x11)
  343. #define BMI160_ACCEL_LOWPOWER_MODE UINT8_C(0x12)
  344. #define BMI160_ACCEL_SUSPEND_MODE UINT8_C(0x10)
  345. /* Gyro power mode */
  346. #define BMI160_GYRO_SUSPEND_MODE UINT8_C(0x14)
  347. #define BMI160_GYRO_NORMAL_MODE UINT8_C(0x15)
  348. #define BMI160_GYRO_FASTSTARTUP_MODE UINT8_C(0x17)
  349. /* Aux power mode */
  350. #define BMI160_AUX_SUSPEND_MODE UINT8_C(0x18)
  351. #define BMI160_AUX_NORMAL_MODE UINT8_C(0x19)
  352. #define BMI160_AUX_LOWPOWER_MODE UINT8_C(0x1A)
  353. /** Range settings */
  354. /* Accel Range */
  355. #define BMI160_ACCEL_RANGE_2G UINT8_C(0x03)
  356. #define BMI160_ACCEL_RANGE_4G UINT8_C(0x05)
  357. #define BMI160_ACCEL_RANGE_8G UINT8_C(0x08)
  358. #define BMI160_ACCEL_RANGE_16G UINT8_C(0x0C)
  359. /* Gyro Range */
  360. #define BMI160_GYRO_RANGE_2000_DPS UINT8_C(0x00)
  361. #define BMI160_GYRO_RANGE_1000_DPS UINT8_C(0x01)
  362. #define BMI160_GYRO_RANGE_500_DPS UINT8_C(0x02)
  363. #define BMI160_GYRO_RANGE_250_DPS UINT8_C(0x03)
  364. #define BMI160_GYRO_RANGE_125_DPS UINT8_C(0x04)
  365. /** Bandwidth settings */
  366. /* Accel Bandwidth */
  367. #define BMI160_ACCEL_BW_OSR4_AVG1 UINT8_C(0x00)
  368. #define BMI160_ACCEL_BW_OSR2_AVG2 UINT8_C(0x01)
  369. #define BMI160_ACCEL_BW_NORMAL_AVG4 UINT8_C(0x02)
  370. #define BMI160_ACCEL_BW_CIC_AVG8 UINT8_C(0x03)
  371. #define BMI160_ACCEL_BW_RES_AVG16 UINT8_C(0x04)
  372. #define BMI160_ACCEL_BW_RES_AVG32 UINT8_C(0x05)
  373. #define BMI160_ACCEL_BW_RES_AVG64 UINT8_C(0x06)
  374. #define BMI160_ACCEL_BW_RES_AVG128 UINT8_C(0x07)
  375. #define BMI160_GYRO_BW_OSR4_MODE UINT8_C(0x00)
  376. #define BMI160_GYRO_BW_OSR2_MODE UINT8_C(0x01)
  377. #define BMI160_GYRO_BW_NORMAL_MODE UINT8_C(0x02)
  378. #define BMI160_GYRO_BW_CIC_MODE UINT8_C(0x03)
  379. /* Output Data Rate settings */
  380. /* Accel Output data rate */
  381. #define BMI160_ACCEL_ODR_RESERVED UINT8_C(0x00)
  382. #define BMI160_ACCEL_ODR_0_78HZ UINT8_C(0x01)
  383. #define BMI160_ACCEL_ODR_1_56HZ UINT8_C(0x02)
  384. #define BMI160_ACCEL_ODR_3_12HZ UINT8_C(0x03)
  385. #define BMI160_ACCEL_ODR_6_25HZ UINT8_C(0x04)
  386. #define BMI160_ACCEL_ODR_12_5HZ UINT8_C(0x05)
  387. #define BMI160_ACCEL_ODR_25HZ UINT8_C(0x06)
  388. #define BMI160_ACCEL_ODR_50HZ UINT8_C(0x07)
  389. #define BMI160_ACCEL_ODR_100HZ UINT8_C(0x08)
  390. #define BMI160_ACCEL_ODR_200HZ UINT8_C(0x09)
  391. #define BMI160_ACCEL_ODR_400HZ UINT8_C(0x0A)
  392. #define BMI160_ACCEL_ODR_800HZ UINT8_C(0x0B)
  393. #define BMI160_ACCEL_ODR_1600HZ UINT8_C(0x0C)
  394. #define BMI160_ACCEL_ODR_RESERVED0 UINT8_C(0x0D)
  395. #define BMI160_ACCEL_ODR_RESERVED1 UINT8_C(0x0E)
  396. #define BMI160_ACCEL_ODR_RESERVED2 UINT8_C(0x0F)
  397. /* Gyro Output data rate */
  398. #define BMI160_GYRO_ODR_RESERVED UINT8_C(0x00)
  399. #define BMI160_GYRO_ODR_25HZ UINT8_C(0x06)
  400. #define BMI160_GYRO_ODR_50HZ UINT8_C(0x07)
  401. #define BMI160_GYRO_ODR_100HZ UINT8_C(0x08)
  402. #define BMI160_GYRO_ODR_200HZ UINT8_C(0x09)
  403. #define BMI160_GYRO_ODR_400HZ UINT8_C(0x0A)
  404. #define BMI160_GYRO_ODR_800HZ UINT8_C(0x0B)
  405. #define BMI160_GYRO_ODR_1600HZ UINT8_C(0x0C)
  406. #define BMI160_GYRO_ODR_3200HZ UINT8_C(0x0D)
  407. /* Auxiliary sensor Output data rate */
  408. #define BMI160_AUX_ODR_RESERVED UINT8_C(0x00)
  409. #define BMI160_AUX_ODR_0_78HZ UINT8_C(0x01)
  410. #define BMI160_AUX_ODR_1_56HZ UINT8_C(0x02)
  411. #define BMI160_AUX_ODR_3_12HZ UINT8_C(0x03)
  412. #define BMI160_AUX_ODR_6_25HZ UINT8_C(0x04)
  413. #define BMI160_AUX_ODR_12_5HZ UINT8_C(0x05)
  414. #define BMI160_AUX_ODR_25HZ UINT8_C(0x06)
  415. #define BMI160_AUX_ODR_50HZ UINT8_C(0x07)
  416. #define BMI160_AUX_ODR_100HZ UINT8_C(0x08)
  417. #define BMI160_AUX_ODR_200HZ UINT8_C(0x09)
  418. #define BMI160_AUX_ODR_400HZ UINT8_C(0x0A)
  419. #define BMI160_AUX_ODR_800HZ UINT8_C(0x0B)
  420. /* Maximum limits definition */
  421. #define BMI160_ACCEL_ODR_MAX UINT8_C(15)
  422. #define BMI160_ACCEL_BW_MAX UINT8_C(2)
  423. #define BMI160_ACCEL_RANGE_MAX UINT8_C(12)
  424. #define BMI160_GYRO_ODR_MAX UINT8_C(13)
  425. #define BMI160_GYRO_BW_MAX UINT8_C(2)
  426. #define BMI160_GYRO_RANGE_MAX UINT8_C(4)
  427. /** FIFO_CONFIG Definitions */
  428. #define BMI160_FIFO_TIME_ENABLE UINT8_C(0x02)
  429. #define BMI160_FIFO_TAG_INT2_ENABLE UINT8_C(0x04)
  430. #define BMI160_FIFO_TAG_INT1_ENABLE UINT8_C(0x08)
  431. #define BMI160_FIFO_HEAD_ENABLE UINT8_C(0x10)
  432. #define BMI160_FIFO_M_ENABLE UINT8_C(0x20)
  433. #define BMI160_FIFO_A_ENABLE UINT8_C(0x40)
  434. #define BMI160_FIFO_M_A_ENABLE UINT8_C(0x60)
  435. #define BMI160_FIFO_G_ENABLE UINT8_C(0x80)
  436. #define BMI160_FIFO_M_G_ENABLE UINT8_C(0xA0)
  437. #define BMI160_FIFO_G_A_ENABLE UINT8_C(0xC0)
  438. #define BMI160_FIFO_M_G_A_ENABLE UINT8_C(0xE0)
  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. /** Array Parameter DefinItions */
  489. #define BMI160_SENSOR_TIME_LSB_BYTE UINT8_C(0)
  490. #define BMI160_SENSOR_TIME_XLSB_BYTE UINT8_C(1)
  491. #define BMI160_SENSOR_TIME_MSB_BYTE UINT8_C(2)
  492. /** Interface settings */
  493. #define BMI160_SPI_INTF UINT8_C(1)
  494. #define BMI160_I2C_INTF UINT8_C(0)
  495. #define BMI160_SPI_RD_MASK UINT8_C(0x80)
  496. #define BMI160_SPI_WR_MASK UINT8_C(0x7F)
  497. /* Sensor & time select definition*/
  498. #define BMI160_ACCEL_SEL UINT8_C(0x01)
  499. #define BMI160_GYRO_SEL UINT8_C(0x02)
  500. #define BMI160_TIME_SEL UINT8_C(0x04)
  501. /* Sensor select mask*/
  502. #define BMI160_SEN_SEL_MASK UINT8_C(0x07)
  503. /* Error code mask */
  504. #define BMI160_ERR_REG_MASK UINT8_C(0x0F)
  505. /* BMI160 I2C address */
  506. #define BMI160_I2C_ADDR UINT8_C(0x68)
  507. /* BMI160 secondary IF address */
  508. #define BMI160_AUX_BMM150_I2C_ADDR UINT8_C(0x10)
  509. /** BMI160 Length definitions */
  510. #define BMI160_ONE UINT8_C(1)
  511. #define BMI160_TWO UINT8_C(2)
  512. #define BMI160_THREE UINT8_C(3)
  513. #define BMI160_FOUR UINT8_C(4)
  514. #define BMI160_FIVE UINT8_C(5)
  515. /** BMI160 fifo level Margin */
  516. #define BMI160_FIFO_LEVEL_MARGIN UINT8_C(16)
  517. /** BMI160 fifo flush Command */
  518. #define BMI160_FIFO_FLUSH_VALUE UINT8_C(0xB0)
  519. /** BMI160 fifo full interrupt position and mask */
  520. #define BMI160_FIFO_FULL_INT_POS UINT8_C(5)
  521. #define BMI160_FIFO_FULL_INT_MSK UINT8_C(0x20)
  522. #define BMI160_FIFO_WTM_INT_POS UINT8_C(6)
  523. #define BMI160_FIFO_WTM_INT_MSK UINT8_C(0x40)
  524. #define BMI160_FIFO_FULL_INT_PIN1_POS UINT8_C(5)
  525. #define BMI160_FIFO_FULL_INT_PIN1_MSK UINT8_C(0x20)
  526. #define BMI160_FIFO_FULL_INT_PIN2_POS UINT8_C(1)
  527. #define BMI160_FIFO_FULL_INT_PIN2_MSK UINT8_C(0x02)
  528. #define BMI160_FIFO_WTM_INT_PIN1_POS UINT8_C(6)
  529. #define BMI160_FIFO_WTM_INT_PIN1_MSK UINT8_C(0x40)
  530. #define BMI160_FIFO_WTM_INT_PIN2_POS UINT8_C(2)
  531. #define BMI160_FIFO_WTM_INT_PIN2_MSK UINT8_C(0x04)
  532. #define BMI160_MANUAL_MODE_EN_POS UINT8_C(7)
  533. #define BMI160_MANUAL_MODE_EN_MSK UINT8_C(0x80)
  534. #define BMI160_AUX_READ_BURST_POS UINT8_C(0)
  535. #define BMI160_AUX_READ_BURST_MSK UINT8_C(0x03)
  536. #define BMI160_GYRO_SELF_TEST_POS UINT8_C(4)
  537. #define BMI160_GYRO_SELF_TEST_MSK UINT8_C(0x10)
  538. #define BMI160_GYRO_SELF_TEST_STATUS_POS UINT8_C(1)
  539. #define BMI160_GYRO_SELF_TEST_STATUS_MSK UINT8_C(0x02)
  540. /* BIT SLICE GET AND SET FUNCTIONS */
  541. #define BMI160_GET_BITS(regvar, bitname)\
  542. ((regvar & bitname##_MSK) >> bitname##_POS)
  543. #define BMI160_SET_BITS(regvar, bitname, val)\
  544. ((regvar & ~bitname##_MSK) | \
  545. ((val<<bitname##_POS)&bitname##_MSK))
  546. #define BMI160_SET_BITS_POS_0(reg_data, bitname, data) \
  547. ((reg_data & ~(bitname##_MSK)) | \
  548. (data & bitname##_MSK))
  549. #define BMI160_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
  550. /*****************************************************************************/
  551. /* type definitions */
  552. typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
  553. uint8_t *data, uint16_t len);
  554. typedef void (*bmi160_delay_fptr_t)(uint32_t period);
  555. /*************************** Data structures *********************************/
  556. /*!
  557. * @brief bmi160 sensor data structure which comprises of accel data
  558. */
  559. struct bmi160_sensor_data {
  560. /*! X-axis sensor data */
  561. int16_t x;
  562. /*! Y-axis sensor data */
  563. int16_t y;
  564. /*! Z-axis sensor data */
  565. int16_t z;
  566. /*! sensor time */
  567. uint32_t sensortime;
  568. };
  569. /*!
  570. * @brief FIFO aux. sensor data structure
  571. */
  572. struct bmi160_aux_fifo_data {
  573. /*! The value of aux. sensor x LSB data */
  574. uint8_t aux_x_lsb;
  575. /*! The value of aux. sensor x MSB data */
  576. uint8_t aux_x_msb;
  577. /*! The value of aux. sensor y LSB data */
  578. uint8_t aux_y_lsb;
  579. /*! The value of aux. sensor y MSB data */
  580. uint8_t aux_y_msb;
  581. /*! The value of aux. sensor z LSB data */
  582. uint8_t aux_z_lsb;
  583. /*! The value of aux. sensor z MSB data */
  584. uint8_t aux_z_msb;
  585. /*! The value of aux. sensor r for BMM150 LSB data */
  586. uint8_t aux_r_y2_lsb;
  587. /*! The value of aux. sensor r for BMM150 MSB data */
  588. uint8_t aux_r_y2_msb;
  589. };
  590. /*!
  591. * @brief bmi160 sensor select structure
  592. */
  593. enum bmi160_select_sensor {
  594. BMI160_ACCEL_ONLY = 1,
  595. BMI160_GYRO_ONLY,
  596. BMI160_BOTH_ACCEL_AND_GYRO
  597. };
  598. /*!
  599. * @brief bmi160 sensor step detector mode structure
  600. */
  601. enum bmi160_step_detect_mode {
  602. BMI160_STEP_DETECT_NORMAL,
  603. BMI160_STEP_DETECT_SENSITIVE,
  604. BMI160_STEP_DETECT_ROBUST,
  605. /*! Non recommended User defined setting */
  606. BMI160_STEP_DETECT_USER_DEFINE
  607. };
  608. /*!
  609. * @brief enum for auxiliary burst read selection
  610. */
  611. enum bm160_aux_read_len {
  612. BMI160_AUX_READ_LEN_0,
  613. BMI160_AUX_READ_LEN_1,
  614. BMI160_AUX_READ_LEN_2,
  615. BMI160_AUX_READ_LEN_3
  616. };
  617. /*!
  618. * @brief bmi160 sensor configuration structure
  619. */
  620. struct bmi160_cfg {
  621. /*! power mode */
  622. uint8_t power;
  623. /*! output data rate */
  624. uint8_t odr;
  625. /*! range */
  626. uint8_t range;
  627. /*! bandwidth */
  628. uint8_t bw;
  629. };
  630. /*!
  631. * @brief Aux sensor configuration structure
  632. */
  633. struct bmi160_aux_cfg {
  634. /*! Aux sensor, 1 - enable 0 - disable */
  635. uint8_t aux_sensor_enable : 1;
  636. /*! Aux manual/auto mode status */
  637. uint8_t manual_enable : 1;
  638. /*! Aux read burst length */
  639. uint8_t aux_rd_burst_len : 2;
  640. /*! output data rate */
  641. uint8_t aux_odr :4;
  642. /*! i2c addr of auxiliary sensor */
  643. uint8_t aux_i2c_addr;
  644. };
  645. /*!
  646. * @brief bmi160 interrupt channel selection structure
  647. */
  648. enum bmi160_int_channel {
  649. /*! interrupt Channel 1 */
  650. BMI160_INT_CHANNEL_1,
  651. /*! interrupt Channel 2 */
  652. BMI160_INT_CHANNEL_2
  653. };
  654. enum bmi160_int_types {
  655. /*! Slope/Any-motion interrupt */
  656. BMI160_ACC_ANY_MOTION_INT,
  657. /*! Significant motion interrupt */
  658. BMI160_ACC_SIG_MOTION_INT,
  659. /*! Step detector interrupt */
  660. BMI160_STEP_DETECT_INT,
  661. /*! double tap interrupt */
  662. BMI160_ACC_DOUBLE_TAP_INT,
  663. /*! single tap interrupt */
  664. BMI160_ACC_SINGLE_TAP_INT,
  665. /*! orientation interrupt */
  666. BMI160_ACC_ORIENT_INT,
  667. /*! flat interrupt */
  668. BMI160_ACC_FLAT_INT,
  669. /*! high-g interrupt */
  670. BMI160_ACC_HIGH_G_INT,
  671. /*! low-g interrupt */
  672. BMI160_ACC_LOW_G_INT,
  673. /*! slow/no-motion interrupt */
  674. BMI160_ACC_SLOW_NO_MOTION_INT,
  675. /*! data ready interrupt */
  676. BMI160_ACC_GYRO_DATA_RDY_INT,
  677. /*! fifo full interrupt */
  678. BMI160_ACC_GYRO_FIFO_FULL_INT,
  679. /*! fifo watermark interrupt */
  680. BMI160_ACC_GYRO_FIFO_WATERMARK_INT
  681. };
  682. /*!
  683. * @brief bmi160 active state of any & sig motion interrupt.
  684. */
  685. enum bmi160_any_sig_motion_active_interrupt_state {
  686. /*! Both any & sig motion are disabled */
  687. BMI160_BOTH_ANY_SIG_MOTION_DISABLED = -1,
  688. /*! Any-motion selected */
  689. BMI160_ANY_MOTION_ENABLED,
  690. /*! Sig-motion selected */
  691. BMI160_SIG_MOTION_ENABLED
  692. };
  693. struct bmi160_acc_tap_int_cfg {
  694. #if LITTLE_ENDIAN == 1
  695. /*! tap threshold */
  696. uint16_t tap_thr :5;
  697. /*! tap shock */
  698. uint16_t tap_shock :1;
  699. /*! tap quiet */
  700. uint16_t tap_quiet :1;
  701. /*! tap duration */
  702. uint16_t tap_dur :3;
  703. /*! data source 0- filter & 1 pre-filter*/
  704. uint16_t tap_data_src :1;
  705. /*! tap enable, 1 - enable, 0 - disable */
  706. uint16_t tap_en :1;
  707. #elif BIG_ENDIAN == 1
  708. /*! tap enable, 1 - enable, 0 - disable */
  709. uint16_t tap_en :1;
  710. /*! data source 0- filter & 1 pre-filter*/
  711. uint16_t tap_data_src :1;
  712. /*! tap duration */
  713. uint16_t tap_dur : 3;
  714. /*! tap quiet */
  715. uint16_t tap_quiet : 1;
  716. /*! tap shock */
  717. uint16_t tap_shock : 1;
  718. /*! tap threshold */
  719. uint16_t tap_thr : 5;
  720. #endif
  721. };
  722. struct bmi160_acc_any_mot_int_cfg {
  723. #if LITTLE_ENDIAN == 1
  724. /*! 1 any-motion enable, 0 - any-motion disable */
  725. uint8_t anymotion_en :1;
  726. /*! slope interrupt x, 1 - enable, 0 - disable */
  727. uint8_t anymotion_x :1;
  728. /*! slope interrupt y, 1 - enable, 0 - disable */
  729. uint8_t anymotion_y :1;
  730. /*! slope interrupt z, 1 - enable, 0 - disable */
  731. uint8_t anymotion_z :1;
  732. /*! slope duration */
  733. uint8_t anymotion_dur :2;
  734. /*! data source 0- filter & 1 pre-filter*/
  735. uint8_t anymotion_data_src :1;
  736. /*! slope threshold */
  737. uint8_t anymotion_thr;
  738. #elif BIG_ENDIAN == 1
  739. /*! slope threshold */
  740. uint8_t anymotion_thr;
  741. /*! data source 0- filter & 1 pre-filter*/
  742. uint8_t anymotion_data_src :1;
  743. /*! slope duration */
  744. uint8_t anymotion_dur : 2;
  745. /*! slope interrupt z, 1 - enable, 0 - disable */
  746. uint8_t anymotion_z : 1;
  747. /*! slope interrupt y, 1 - enable, 0 - disable */
  748. uint8_t anymotion_y : 1;
  749. /*! slope interrupt x, 1 - enable, 0 - disable */
  750. uint8_t anymotion_x : 1;
  751. /*! 1 any-motion enable, 0 - any-motion disable */
  752. uint8_t anymotion_en :1;
  753. #endif
  754. };
  755. struct bmi160_acc_sig_mot_int_cfg {
  756. #if LITTLE_ENDIAN == 1
  757. /*! skip time of sig-motion interrupt */
  758. uint8_t sig_mot_skip :2;
  759. /*! proof time of sig-motion interrupt */
  760. uint8_t sig_mot_proof :2;
  761. /*! data source 0- filter & 1 pre-filter*/
  762. uint8_t sig_data_src :1;
  763. /*! 1 - enable sig, 0 - disable sig & enable anymotion */
  764. uint8_t sig_en :1;
  765. /*! sig-motion threshold */
  766. uint8_t sig_mot_thres;
  767. #elif BIG_ENDIAN == 1
  768. /*! sig-motion threshold */
  769. uint8_t sig_mot_thres;
  770. /*! 1 - enable sig, 0 - disable sig & enable anymotion */
  771. uint8_t sig_en :1;
  772. /*! data source 0- filter & 1 pre-filter*/
  773. uint8_t sig_data_src :1;
  774. /*! proof time of sig-motion interrupt */
  775. uint8_t sig_mot_proof : 2;
  776. /*! skip time of sig-motion interrupt */
  777. uint8_t sig_mot_skip : 2;
  778. #endif
  779. };
  780. struct bmi160_acc_step_detect_int_cfg {
  781. #if LITTLE_ENDIAN == 1
  782. /*! 1- step detector enable, 0- step detector disable */
  783. uint16_t step_detector_en :1;
  784. /*! minimum threshold */
  785. uint16_t min_threshold :2;
  786. /*! minimal detectable step time */
  787. uint16_t steptime_min :3;
  788. /*! enable step counter mode setting */
  789. uint16_t step_detector_mode :2;
  790. /*! minimum step buffer size*/
  791. uint16_t step_min_buf :3;
  792. #elif BIG_ENDIAN == 1
  793. /*! minimum step buffer size*/
  794. uint16_t step_min_buf :3;
  795. /*! enable step counter mode setting */
  796. uint16_t step_detector_mode : 2;
  797. /*! minimal detectable step time */
  798. uint16_t steptime_min : 3;
  799. /*! minimum threshold */
  800. uint16_t min_threshold : 2;
  801. /*! 1- step detector enable, 0- step detector disable */
  802. uint16_t step_detector_en :1;
  803. #endif
  804. };
  805. struct bmi160_acc_no_motion_int_cfg {
  806. #if LITTLE_ENDIAN == 1
  807. /*! no motion interrupt x */
  808. uint16_t no_motion_x :1;
  809. /*! no motion interrupt y */
  810. uint16_t no_motion_y :1;
  811. /*! no motion interrupt z */
  812. uint16_t no_motion_z :1;
  813. /*! no motion duration */
  814. uint16_t no_motion_dur :6;
  815. /*! no motion sel , 1 - enable no-motion ,0- enable slow-motion */
  816. uint16_t no_motion_sel :1;
  817. /*! data source 0- filter & 1 pre-filter*/
  818. uint16_t no_motion_src :1;
  819. /*! no motion threshold */
  820. uint8_t no_motion_thres;
  821. #elif BIG_ENDIAN == 1
  822. /*! no motion threshold */
  823. uint8_t no_motion_thres;
  824. /*! data source 0- filter & 1 pre-filter*/
  825. uint16_t no_motion_src :1;
  826. /*! no motion sel , 1 - enable no-motion ,0- enable slow-motion */
  827. uint16_t no_motion_sel : 1;
  828. /*! no motion duration */
  829. uint16_t no_motion_dur : 6;
  830. /* no motion interrupt z */
  831. uint16_t no_motion_z :1;
  832. /*! no motion interrupt y */
  833. uint16_t no_motion_y :1;
  834. /*! no motion interrupt x */
  835. uint16_t no_motion_x :1;
  836. #endif
  837. };
  838. struct bmi160_acc_orient_int_cfg {
  839. #if LITTLE_ENDIAN == 1
  840. /*! thresholds for switching between the different orientations */
  841. uint16_t orient_mode :2;
  842. /*! blocking_mode */
  843. uint16_t orient_blocking :2;
  844. /*! Orientation interrupt hysteresis */
  845. uint16_t orient_hyst :4;
  846. /*! Orientation interrupt theta */
  847. uint16_t orient_theta :6;
  848. /*! Enable/disable Orientation interrupt */
  849. uint16_t orient_ud_en :1;
  850. /*! exchange x- and z-axis in algorithm ,0 - z, 1 - x */
  851. uint16_t axes_ex :1;
  852. /*! 1 - orient enable, 0 - orient disable */
  853. uint8_t orient_en :1;
  854. #elif BIG_ENDIAN == 1
  855. /*! 1 - orient enable, 0 - orient disable */
  856. uint8_t orient_en :1;
  857. /*! exchange x- and z-axis in algorithm ,0 - z, 1 - x */
  858. uint16_t axes_ex : 1;
  859. /*! Enable/disable Orientation interrupt */
  860. uint16_t orient_ud_en : 1;
  861. /*! Orientation interrupt theta */
  862. uint16_t orient_theta : 6;
  863. /*! Orientation interrupt hysteresis */
  864. uint16_t orient_hyst : 4;
  865. /*! blocking_mode */
  866. uint16_t orient_blocking : 2;
  867. /*! thresholds for switching between the different orientations */
  868. uint16_t orient_mode : 2;
  869. #endif
  870. };
  871. struct bmi160_acc_flat_detect_int_cfg {
  872. #if LITTLE_ENDIAN == 1
  873. /*! flat threshold */
  874. uint16_t flat_theta :6;
  875. /*! flat interrupt hysteresis */
  876. uint16_t flat_hy :3;
  877. /*! delay time for which the flat value must remain stable for the
  878. * flat interrupt to be generated */
  879. uint16_t flat_hold_time :2;
  880. /*! 1 - flat enable, 0 - flat disable */
  881. uint16_t flat_en :1;
  882. #elif BIG_ENDIAN == 1
  883. /*! 1 - flat enable, 0 - flat disable */
  884. uint16_t flat_en :1;
  885. /*! delay time for which the flat value must remain stable for the
  886. * flat interrupt to be generated */
  887. uint16_t flat_hold_time : 2;
  888. /*! flat interrupt hysteresis */
  889. uint16_t flat_hy : 3;
  890. /*! flat threshold */
  891. uint16_t flat_theta : 6;
  892. #endif
  893. };
  894. struct bmi160_acc_low_g_int_cfg {
  895. #if LITTLE_ENDIAN == 1
  896. /*! low-g interrupt trigger delay */
  897. uint8_t low_dur;
  898. /*! low-g interrupt trigger threshold */
  899. uint8_t low_thres;
  900. /*! hysteresis of low-g interrupt */
  901. uint8_t low_hyst :2;
  902. /*! 0 - single-axis mode ,1 - axis-summing mode */
  903. uint8_t low_mode :1;
  904. /*! data source 0- filter & 1 pre-filter */
  905. uint8_t low_data_src :1;
  906. /*! 1 - enable low-g, 0 - disable low-g */
  907. uint8_t low_en :1;
  908. #elif BIG_ENDIAN == 1
  909. /*! 1 - enable low-g, 0 - disable low-g */
  910. uint8_t low_en :1;
  911. /*! data source 0- filter & 1 pre-filter */
  912. uint8_t low_data_src :1;
  913. /*! 0 - single-axis mode ,1 - axis-summing mode */
  914. uint8_t low_mode : 1;
  915. /*! hysteresis of low-g interrupt */
  916. uint8_t low_hyst : 2;
  917. /*! low-g interrupt trigger threshold */
  918. uint8_t low_thres;
  919. /*! low-g interrupt trigger delay */
  920. uint8_t low_dur;
  921. #endif
  922. };
  923. struct bmi160_acc_high_g_int_cfg {
  924. #if LITTLE_ENDIAN == 1
  925. /*! High-g interrupt x, 1 - enable, 0 - disable */
  926. uint8_t high_g_x :1;
  927. /*! High-g interrupt y, 1 - enable, 0 - disable */
  928. uint8_t high_g_y :1;
  929. /*! High-g interrupt z, 1 - enable, 0 - disable */
  930. uint8_t high_g_z :1;
  931. /*! High-g hysteresis */
  932. uint8_t high_hy :2;
  933. /*! data source 0- filter & 1 pre-filter */
  934. uint8_t high_data_src :1;
  935. /*! High-g threshold */
  936. uint8_t high_thres;
  937. /*! High-g duration */
  938. uint8_t high_dur;
  939. #elif BIG_ENDIAN == 1
  940. /*! High-g duration */
  941. uint8_t high_dur;
  942. /*! High-g threshold */
  943. uint8_t high_thres;
  944. /*! data source 0- filter & 1 pre-filter */
  945. uint8_t high_data_src :1;
  946. /*! High-g hysteresis */
  947. uint8_t high_hy : 2;
  948. /*! High-g interrupt z, 1 - enable, 0 - disable */
  949. uint8_t high_g_z : 1;
  950. /*! High-g interrupt y, 1 - enable, 0 - disable */
  951. uint8_t high_g_y : 1;
  952. /*! High-g interrupt x, 1 - enable, 0 - disable */
  953. uint8_t high_g_x : 1;
  954. #endif
  955. };
  956. struct bmi160_int_pin_settg {
  957. #if LITTLE_ENDIAN == 1
  958. /*! To enable either INT1 or INT2 pin as output.
  959. * 0- output disabled ,1- output enabled */
  960. uint16_t output_en :1;
  961. /*! 0 - push-pull 1- open drain,only valid if output_en is set 1 */
  962. uint16_t output_mode :1;
  963. /*! 0 - active low , 1 - active high level.
  964. * if output_en is 1,this applies to interrupts,else PMU_trigger */
  965. uint16_t output_type :1;
  966. /*! 0 - level trigger , 1 - edge trigger */
  967. uint16_t edge_ctrl :1;
  968. /*! To enable either INT1 or INT2 pin as input.
  969. * 0 - input disabled ,1 - input enabled */
  970. uint16_t input_en :1;
  971. /*! latch duration*/
  972. uint16_t latch_dur :4;
  973. #elif BIG_ENDIAN == 1
  974. /*! latch duration*/
  975. uint16_t latch_dur : 4;
  976. /*! Latched,non-latched or temporary interrupt modes */
  977. uint16_t input_en : 1;
  978. /*! 1 - edge trigger, 0 - level trigger */
  979. uint16_t edge_ctrl : 1;
  980. /*! 0 - active low , 1 - active high level.
  981. * if output_en is 1,this applies to interrupts,else PMU_trigger */
  982. uint16_t output_type : 1;
  983. /*! 0 - push-pull , 1 - open drain,only valid if output_en is set 1 */
  984. uint16_t output_mode : 1;
  985. /*! To enable either INT1 or INT2 pin as output.
  986. * 0 - output disabled , 1 - output enabled */
  987. uint16_t output_en : 1;
  988. #endif
  989. };
  990. union bmi160_int_type_cfg {
  991. /*! Tap interrupt structure */
  992. struct bmi160_acc_tap_int_cfg acc_tap_int;
  993. /*! Slope interrupt structure */
  994. struct bmi160_acc_any_mot_int_cfg acc_any_motion_int;
  995. /*! Significant motion interrupt structure */
  996. struct bmi160_acc_sig_mot_int_cfg acc_sig_motion_int;
  997. /*! Step detector interrupt structure */
  998. struct bmi160_acc_step_detect_int_cfg acc_step_detect_int;
  999. /*! No motion interrupt structure */
  1000. struct bmi160_acc_no_motion_int_cfg acc_no_motion_int;
  1001. /*! Orientation interrupt structure */
  1002. struct bmi160_acc_orient_int_cfg acc_orient_int;
  1003. /*! Flat interrupt structure */
  1004. struct bmi160_acc_flat_detect_int_cfg acc_flat_int;
  1005. /*! Low-g interrupt structure */
  1006. struct bmi160_acc_low_g_int_cfg acc_low_g_int;
  1007. /*! High-g interrupt structure */
  1008. struct bmi160_acc_high_g_int_cfg acc_high_g_int;
  1009. };
  1010. struct bmi160_int_settg {
  1011. /*! Interrupt channel */
  1012. enum bmi160_int_channel int_channel;
  1013. /*! Select Interrupt */
  1014. enum bmi160_int_types int_type;
  1015. /*! Structure configuring Interrupt pins */
  1016. struct bmi160_int_pin_settg int_pin_settg;
  1017. /*! Union configures required interrupt */
  1018. union bmi160_int_type_cfg int_type_cfg;
  1019. /*! FIFO FULL INT 1-enable, 0-disable */
  1020. uint8_t fifo_full_int_en :1;
  1021. /*! FIFO WTM INT 1-enable, 0-disable */
  1022. uint8_t fifo_WTM_int_en :1;
  1023. };
  1024. /*!
  1025. * @brief This structure holds the information for usage of
  1026. * FIFO by the user.
  1027. */
  1028. struct bmi160_fifo_frame {
  1029. /*! Data buffer of user defined length is to be mapped here */
  1030. uint8_t *data;
  1031. /*! While calling the API "bmi160_get_fifo_data" , length stores
  1032. * number of bytes in FIFO to be read (specified by user as input)
  1033. * and after execution of the API ,number of FIFO data bytes
  1034. * available is provided as an output to user
  1035. */
  1036. uint16_t length;
  1037. /*! FIFO time enable */
  1038. uint8_t fifo_time_enable;
  1039. /*! Enabling of the FIFO header to stream in header mode */
  1040. uint8_t fifo_header_enable;
  1041. /*! Streaming of the Accelerometer, Gyroscope
  1042. sensor data or both in FIFO */
  1043. uint8_t fifo_data_enable;
  1044. /*! Will be equal to length when no more frames are there to parse */
  1045. uint16_t accel_byte_start_idx;
  1046. /*! Will be equal to length when no more frames are there to parse */
  1047. uint16_t gyro_byte_start_idx;
  1048. /*! Will be equal to length when no more frames are there to parse */
  1049. uint16_t aux_byte_start_idx;
  1050. /*! Value of FIFO sensor time time */
  1051. uint32_t sensor_time;
  1052. /*! Value of Skipped frame counts */
  1053. uint8_t skipped_frame_count;
  1054. };
  1055. struct bmi160_dev {
  1056. /*! Chip Id */
  1057. uint8_t chip_id;
  1058. /*! Device Id */
  1059. uint8_t id;
  1060. /*! 0 - I2C , 1 - SPI Interface */
  1061. uint8_t interface;
  1062. /*! Hold active interrupts status for any and sig motion
  1063. * 0 - Any-motion enable, 1 - Sig-motion enable,
  1064. * -1 neither any-motion nor sig-motion selected */
  1065. enum bmi160_any_sig_motion_active_interrupt_state any_sig_sel;
  1066. /*! Structure to configure Accel sensor */
  1067. struct bmi160_cfg accel_cfg;
  1068. /*! Structure to hold previous/old accel config parameters.
  1069. * This is used at driver level to prevent overwriting of same
  1070. * data, hence user does not change it in the code */
  1071. struct bmi160_cfg prev_accel_cfg;
  1072. /*! Structure to configure Gyro sensor */
  1073. struct bmi160_cfg gyro_cfg;
  1074. /*! Structure to hold previous/old gyro config parameters.
  1075. * This is used at driver level to prevent overwriting of same
  1076. * data, hence user does not change it in the code */
  1077. struct bmi160_cfg prev_gyro_cfg;
  1078. /*! Structure to configure the auxiliary sensor */
  1079. struct bmi160_aux_cfg aux_cfg;
  1080. /*! Structure to hold previous/old aux config parameters.
  1081. * This is used at driver level to prevent overwriting of same
  1082. * data, hence user does not change it in the code */
  1083. struct bmi160_aux_cfg prev_aux_cfg;
  1084. /*! FIFO related configurations */
  1085. struct bmi160_fifo_frame *fifo;
  1086. /*! Read function pointer */
  1087. bmi160_com_fptr_t read;
  1088. /*! Write function pointer */
  1089. bmi160_com_fptr_t write;
  1090. /*! Delay function pointer */
  1091. bmi160_delay_fptr_t delay_ms;
  1092. };
  1093. /*************************** C++ guard macro *****************************/
  1094. #ifdef __cplusplus
  1095. }
  1096. #endif
  1097. #endif /* BMI160_DEFS_H_ */