bma400_defs.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /**
  2. * Copyright (C) 2017 - 2018 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 bma400_defs.h
  43. * @date 25 Sep 2018
  44. * @version 1.5.0
  45. * @brief
  46. *
  47. */
  48. /*! \file bma400_defs.h */
  49. /*!
  50. * @defgroup BMA400 SENSOR API
  51. * @brief
  52. * @{
  53. */
  54. #ifndef BMA400_DEFS_H_
  55. #define BMA400_DEFS_H_
  56. /*********************************************************************/
  57. /**\ header files */
  58. #ifdef __KERNEL__
  59. #include <linux/types.h>
  60. #include <linux/kernel.h>
  61. #else
  62. #include <stdint.h>
  63. #include <stddef.h>
  64. #endif
  65. /*********************************************************************/
  66. /** \name Common macros */
  67. /*********************************************************************/
  68. #if !defined(UINT8_C) && !defined(INT8_C)
  69. #define INT8_C(x) S8_C(x)
  70. #define UINT8_C(x) U8_C(x)
  71. #endif
  72. #if !defined(UINT16_C) && !defined(INT16_C)
  73. #define INT16_C(x) S16_C(x)
  74. #define UINT16_C(x) U16_C(x)
  75. #endif
  76. #if !defined(INT32_C) && !defined(UINT32_C)
  77. #define INT32_C(x) S32_C(x)
  78. #define UINT32_C(x) U32_C(x)
  79. #endif
  80. #if !defined(INT64_C) && !defined(UINT64_C)
  81. #define INT64_C(x) S64_C(x)
  82. #define UINT64_C(x) U64_C(x)
  83. #endif
  84. /**\name C standard macros */
  85. #ifndef NULL
  86. #ifdef __cplusplus
  87. #define NULL 0
  88. #else
  89. #define NULL ((void *) 0)
  90. #endif
  91. #endif
  92. #ifndef TRUE
  93. #define TRUE UINT8_C(1)
  94. #endif
  95. #ifndef FALSE
  96. #define FALSE UINT8_C(0)
  97. #endif
  98. /********************************************************/
  99. /**\name Macro definitions */
  100. /**\name API success code */
  101. #define BMA400_OK INT8_C(0)
  102. /**\name API error codes */
  103. #define BMA400_E_NULL_PTR INT8_C(-1)
  104. #define BMA400_E_COM_FAIL INT8_C(-2)
  105. #define BMA400_E_DEV_NOT_FOUND INT8_C(-3)
  106. #define BMA400_E_INVALID_CONFIG INT8_C(-4)
  107. /**\name API warning codes */
  108. #define BMA400_W_SELF_TEST_FAIL INT8_C(1)
  109. /**\name CHIP ID VALUE */
  110. #define BMA400_CHIP_ID UINT8_C(0x90)
  111. /********************************************************/
  112. /**\name USER CONFIGURATION MACROS */
  113. /**\name BMA400 I2C address macros */
  114. #define BMA400_I2C_ADDRESS_SDO_LOW UINT8_C(0x14)
  115. #define BMA400_I2C_ADDRESS_SDO_HIGH UINT8_C(0x15)
  116. /**\name Power mode configurations */
  117. #define BMA400_NORMAL_MODE UINT8_C(0x02)
  118. #define BMA400_SLEEP_MODE UINT8_C(0x00)
  119. #define BMA400_LOW_POWER_MODE UINT8_C(0x01)
  120. /**\name Enable / Disable macros */
  121. #define BMA400_DISABLE UINT8_C(0)
  122. #define BMA400_ENABLE UINT8_C(1)
  123. /**\name Data/sensortime selection macros */
  124. #define BMA400_DATA_ONLY UINT8_C(0x00)
  125. #define BMA400_DATA_SENSOR_TIME UINT8_C(0x01)
  126. /**\name ODR configurations */
  127. #define BMA400_ODR_12_5HZ UINT8_C(0x05)
  128. #define BMA400_ODR_25HZ UINT8_C(0x06)
  129. #define BMA400_ODR_50HZ UINT8_C(0x07)
  130. #define BMA400_ODR_100HZ UINT8_C(0x08)
  131. #define BMA400_ODR_200HZ UINT8_C(0x09)
  132. #define BMA400_ODR_400HZ UINT8_C(0x0A)
  133. #define BMA400_ODR_800HZ UINT8_C(0x0B)
  134. /**\name Accel Range configuration */
  135. #define BMA400_2G_RANGE UINT8_C(0x00)
  136. #define BMA400_4G_RANGE UINT8_C(0x01)
  137. #define BMA400_8G_RANGE UINT8_C(0x02)
  138. #define BMA400_16G_RANGE UINT8_C(0x03)
  139. /**\name Accel Axes selection settings for
  140. * DATA SAMPLING, WAKEUP, ORIENTATION CHANGE,
  141. * GEN1, GEN2 , ACTIVITY CHANGE
  142. */
  143. #define BMA400_X_AXIS_EN UINT8_C(0x01)
  144. #define BMA400_Y_AXIS_EN UINT8_C(0x02)
  145. #define BMA400_Z_AXIS_EN UINT8_C(0x04)
  146. #define BMA400_XYZ_AXIS_EN UINT8_C(0x07)
  147. /**\name Accel filter(data_src_reg) selection settings */
  148. #define BMA400_DATA_SRC_ACCEL_FILT_1 UINT8_C(0x00)
  149. #define BMA400_DATA_SRC_ACCEL_FILT_2 UINT8_C(0x01)
  150. #define BMA400_DATA_SRC_ACCEL_FILT_LP UINT8_C(0x02)
  151. /**\name Accel OSR (OSR,OSR_LP) settings */
  152. #define BMA400_ACCEL_OSR_SETTING_0 UINT8_C(0x00)
  153. #define BMA400_ACCEL_OSR_SETTING_1 UINT8_C(0x01)
  154. #define BMA400_ACCEL_OSR_SETTING_2 UINT8_C(0x02)
  155. #define BMA400_ACCEL_OSR_SETTING_3 UINT8_C(0x03)
  156. /**\name Accel filt1_bw settings */
  157. /* Accel filt1_bw = 0.48 * ODR */
  158. #define BMA400_ACCEL_FILT1_BW_0 UINT8_C(0x00)
  159. /* Accel filt1_bw = 0.24 * ODR */
  160. #define BMA400_ACCEL_FILT1_BW_1 UINT8_C(0x01)
  161. /**\name Auto wake-up timeout value of 10.24s */
  162. #define BMA400_AUTO_WAKEUP_TIMEOUT_MAX UINT16_C(0x0FFF)
  163. /**\name Auto low power timeout value of 10.24s */
  164. #define BMA400_AUTO_LP_TIMEOUT_MAX UINT16_C(0x0FFF)
  165. /**\name Reference Update macros */
  166. #define BMA400_MANUAL_UPDATE UINT8_C(0x00)
  167. #define BMA400_ONE_TIME_UPDATE UINT8_C(0x01)
  168. #define BMA400_EVERY_TIME_UPDATE UINT8_C(0x02)
  169. #define BMA400_LP_EVERY_TIME_UPDATE UINT8_C(0x03)
  170. /**\name Reference Update macros for orient interrupts */
  171. #define BMA400_ORIENT_REFU_ACC_FILT_2 UINT8_C(0x01)
  172. #define BMA400_ORIENT_REFU_ACC_FILT_LP UINT8_C(0x02)
  173. /**\name Stability evaluation macros for orient interrupts */
  174. #define BMA400_STABILITY_DISABLED UINT8_C(0x00)
  175. #define BMA400_STABILITY_ACC_FILT_2 UINT8_C(0x01)
  176. #define BMA400_STABILITY_ACC_FILT_LP UINT8_C(0x02)
  177. /**\name Number of samples needed for Auto-wakeup interrupt evaluation */
  178. #define BMA400_SAMPLE_COUNT_1 UINT8_C(0x00)
  179. #define BMA400_SAMPLE_COUNT_2 UINT8_C(0x01)
  180. #define BMA400_SAMPLE_COUNT_3 UINT8_C(0x02)
  181. #define BMA400_SAMPLE_COUNT_4 UINT8_C(0x03)
  182. #define BMA400_SAMPLE_COUNT_5 UINT8_C(0x04)
  183. #define BMA400_SAMPLE_COUNT_6 UINT8_C(0x05)
  184. #define BMA400_SAMPLE_COUNT_7 UINT8_C(0x06)
  185. #define BMA400_SAMPLE_COUNT_8 UINT8_C(0x07)
  186. /**\name Auto low power configurations */
  187. /* Auto low power timeout disabled */
  188. #define BMA400_AUTO_LP_TIMEOUT_DISABLE UINT8_C(0x00)
  189. /* Auto low power entered on drdy interrupt */
  190. #define BMA400_AUTO_LP_DRDY_TRIGGER UINT8_C(0x01)
  191. /* Auto low power entered on GEN1 interrupt */
  192. #define BMA400_AUTO_LP_GEN1_TRIGGER UINT8_C(0x02)
  193. /* Auto low power entered on timeout of threshold value */
  194. #define BMA400_AUTO_LP_TIMEOUT_EN UINT8_C(0x04)
  195. /* Auto low power entered on timeout of threshold value
  196. * but reset on activity detection
  197. */
  198. #define BMA400_AUTO_LP_TIME_RESET_EN UINT8_C(0x08)
  199. /**\name TAP INTERRUPT CONFIG MACROS */
  200. /* Axes select for TAP interrupt */
  201. #define BMA400_X_AXIS_EN_TAP UINT8_C(0x02)
  202. #define BMA400_Y_AXIS_EN_TAP UINT8_C(0x01)
  203. #define BMA400_Z_AXIS_EN_TAP UINT8_C(0x00)
  204. /*! TAP tics_th setting */
  205. /* Maximum time between upper and lower peak of a tap, in data samples
  206. * this time depends on the mechanics of the device tapped onto
  207. * default = 12 samples
  208. */
  209. /* Configures 6 data samples for high-low tap signal change time */
  210. #define BMA400_TICS_TH_6_DATA_SAMPLES UINT8_C(0x00)
  211. /* Configures 9 data samples for high-low tap signal change time */
  212. #define BMA400_TICS_TH_9_DATA_SAMPLES UINT8_C(0x01)
  213. /* Configures 12 data samples for high-low tap signal change time */
  214. #define BMA400_TICS_TH_12_DATA_SAMPLES UINT8_C(0x02)
  215. /* Configures 18 data samples for high-low tap signal change time */
  216. #define BMA400_TICS_TH_18_DATA_SAMPLES UINT8_C(0x03)
  217. /*! TAP Sensitivity setting */
  218. /* It modifies the threshold for minimum TAP amplitude */
  219. /* BMA400_TAP_SENSITIVITY_0 correspond to highest sensitivity */
  220. #define BMA400_TAP_SENSITIVITY_0 UINT8_C(0x00)
  221. #define BMA400_TAP_SENSITIVITY_1 UINT8_C(0x01)
  222. #define BMA400_TAP_SENSITIVITY_2 UINT8_C(0x02)
  223. #define BMA400_TAP_SENSITIVITY_3 UINT8_C(0x03)
  224. #define BMA400_TAP_SENSITIVITY_4 UINT8_C(0x04)
  225. #define BMA400_TAP_SENSITIVITY_5 UINT8_C(0x05)
  226. #define BMA400_TAP_SENSITIVITY_6 UINT8_C(0x06)
  227. /* BMA400_TAP_SENSITIVITY_7 correspond to lowest sensitivity */
  228. #define BMA400_TAP_SENSITIVITY_7 UINT8_C(0x07)
  229. /*! BMA400 TAP - quiet settings */
  230. /* Quiet refers to minimum quiet time before and after double tap,
  231. * in the data samples This time also defines the longest time interval
  232. * between two taps so that they are considered as double tap
  233. */
  234. /* Configures 60 data samples quiet time between single or double taps */
  235. #define BMA400_QUIET_60_DATA_SAMPLES UINT8_C(0x00)
  236. /* Configures 80 data samples quiet time between single or double taps */
  237. #define BMA400_QUIET_80_DATA_SAMPLES UINT8_C(0x01)
  238. /* Configures 100 data samples quiet time between single or double taps */
  239. #define BMA400_QUIET_100_DATA_SAMPLES UINT8_C(0x02)
  240. /* Configures 120 data samples quiet time between single or double taps */
  241. #define BMA400_QUIET_120_DATA_SAMPLES UINT8_C(0x03)
  242. /*! BMA400 TAP - quiet_dt settings */
  243. /* quiet_dt refers to Minimum time between the two taps of a
  244. * double tap, in data samples
  245. */
  246. /* Configures 4 data samples minimum time between double taps */
  247. #define BMA400_QUIET_DT_4_DATA_SAMPLES UINT8_C(0x00)
  248. /* Configures 8 data samples minimum time between double taps */
  249. #define BMA400_QUIET_DT_8_DATA_SAMPLES UINT8_C(0x01)
  250. /* Configures 12 data samples minimum time between double taps */
  251. #define BMA400_QUIET_DT_12_DATA_SAMPLES UINT8_C(0x02)
  252. /* Configures 16 data samples minimum time between double taps */
  253. #define BMA400_QUIET_DT_16_DATA_SAMPLES UINT8_C(0x03)
  254. /**\name ACTIVITY CHANGE CONFIG MACROS */
  255. /* Data source for activity change detection */
  256. #define BMA400_DATA_SRC_ACC_FILT1 UINT8_C(0x00)
  257. #define BMA400_DATA_SRC_ACC_FILT2 UINT8_C(0x01)
  258. /* Number of samples to evaluate for activity change detection */
  259. #define BMA400_ACT_CH_SAMPLE_CNT_32 UINT8_C(0x00)
  260. #define BMA400_ACT_CH_SAMPLE_CNT_64 UINT8_C(0x01)
  261. #define BMA400_ACT_CH_SAMPLE_CNT_128 UINT8_C(0x02)
  262. #define BMA400_ACT_CH_SAMPLE_CNT_256 UINT8_C(0x03)
  263. #define BMA400_ACT_CH_SAMPLE_CNT_512 UINT8_C(0x04)
  264. /**\name Interrupt pin configuration macros */
  265. #define BMA400_INT_PUSH_PULL_ACTIVE_0 UINT8_C(0x00)
  266. #define BMA400_INT_PUSH_PULL_ACTIVE_1 UINT8_C(0x01)
  267. #define BMA400_INT_OPEN_DRIVE_ACTIVE_0 UINT8_C(0x02)
  268. #define BMA400_INT_OPEN_DRIVE_ACTIVE_1 UINT8_C(0x03)
  269. /**\name Interrupt Assertion status macros */
  270. #define BMA400_WAKEUP_INT_ASSERTED UINT16_C(0x0001)
  271. #define BMA400_ORIENT_CH_INT_ASSERTED UINT16_C(0x0002)
  272. #define BMA400_GEN1_INT_ASSERTED UINT16_C(0x0004)
  273. #define BMA400_GEN2_INT_ASSERTED UINT16_C(0x0008)
  274. #define BMA400_INT_OVERRUN_ASSERTED UINT16_C(0x0010)
  275. #define BMA400_FIFO_FULL_INT_ASSERTED UINT16_C(0x0020)
  276. #define BMA400_FIFO_WM_INT_ASSERTED UINT16_C(0x0040)
  277. #define BMA400_DRDY_INT_ASSERTED UINT16_C(0x0080)
  278. #define BMA400_STEP_INT_ASSERTED UINT16_C(0x0300)
  279. #define BMA400_S_TAP_INT_ASSERTED UINT16_C(0x0400)
  280. #define BMA400_D_TAP_INT_ASSERTED UINT16_C(0x0800)
  281. #define BMA400_ACT_CH_X_ASSERTED UINT16_C(0x2000)
  282. #define BMA400_ACT_CH_Y_ASSERTED UINT16_C(0x4000)
  283. #define BMA400_ACT_CH_Z_ASSERTED UINT16_C(0x8000)
  284. /**\name Generic interrupt criterion_sel configuration macros */
  285. #define BMA400_ACTIVITY_INT UINT8_C(0x01)
  286. #define BMA400_INACTIVITY_INT UINT8_C(0x00)
  287. /**\name Generic interrupt axes evaluation logic configuration macros */
  288. #define BMA400_ALL_AXES_INT UINT8_C(0x01)
  289. #define BMA400_ANY_AXES_INT UINT8_C(0x00)
  290. /**\name Generic interrupt hysteresis configuration macros */
  291. #define BMA400_HYST_0_MG UINT8_C(0x00)
  292. #define BMA400_HYST_24_MG UINT8_C(0x01)
  293. #define BMA400_HYST_48_MG UINT8_C(0x02)
  294. #define BMA400_HYST_96_MG UINT8_C(0x03)
  295. /**********************************************************************/
  296. /**\name BMA400 Register Address */
  297. #define BMA400_CHIP_ID_ADDR UINT8_C(0x00)
  298. #define BMA400_STATUS_ADDR UINT8_C(0x03)
  299. #define BMA400_ACCEL_DATA_ADDR UINT8_C(0x04)
  300. #define BMA400_INT_STAT0_ADDR UINT8_C(0x0E)
  301. #define BMA400_TEMP_DATA_ADDR UINT8_C(0x11)
  302. #define BMA400_FIFO_LENGTH_ADDR UINT8_C(0x12)
  303. #define BMA400_FIFO_DATA_ADDR UINT8_C(0x14)
  304. #define BMA400_STEP_CNT_0_ADDR UINT8_C(0x15)
  305. #define BMA400_ACCEL_CONFIG_0_ADDR UINT8_C(0x19)
  306. #define BMA400_ACCEL_CONFIG_1_ADDR UINT8_C(0x1A)
  307. #define BMA400_ACCEL_CONFIG_2_ADDR UINT8_C(0x1B)
  308. #define BMA400_INT_CONF_0_ADDR UINT8_C(0x1F)
  309. #define BMA400_INT_12_IO_CTRL_ADDR UINT8_C(0x24)
  310. #define BMA400_INT_MAP_ADDR UINT8_C(0x21)
  311. #define BMA400_FIFO_CONFIG_0_ADDR UINT8_C(0x26)
  312. #define BMA400_FIFO_READ_EN_ADDR UINT8_C(0x29)
  313. #define BMA400_AUTO_LOW_POW_0_ADDR UINT8_C(0x2A)
  314. #define BMA400_AUTO_LOW_POW_1_ADDR UINT8_C(0x2B)
  315. #define BMA400_AUTOWAKEUP_0_ADDR UINT8_C(0x2C)
  316. #define BMA400_AUTOWAKEUP_1_ADDR UINT8_C(0x2D)
  317. #define BMA400_WAKEUP_INT_CONF_0_ADDR UINT8_C(0x2F)
  318. #define BMA400_ORIENTCH_INT_CONFIG_ADDR UINT8_C(0x35)
  319. #define BMA400_GEN1_INT_CONFIG_ADDR UINT8_C(0x3F)
  320. #define BMA400_GEN2_INT_CONFIG_ADDR UINT8_C(0x4A)
  321. #define BMA400_ACT_CH_CONFIG_0_ADDR UINT8_C(0x55)
  322. #define BMA400_TAP_CONFIG_ADDR UINT8_C(0x57)
  323. #define BMA400_SELF_TEST_ADDR UINT8_C(0x7D)
  324. #define BMA400_COMMAND_REG_ADDR UINT8_C(0x7E)
  325. /**\name BMA400 Command register */
  326. #define BMA400_SOFT_RESET_CMD UINT8_C(0xB6)
  327. #define BMA400_FIFO_FLUSH_CMD UINT8_C(0xB0)
  328. /**\name BMA400 Delay definitions */
  329. #define BMA400_SOFT_RESET_DELAY_MS UINT8_C(5)
  330. #define BMA400_SELF_TEST_DELAY_MS UINT8_C(7)
  331. #define BMA400_SELF_TEST_DATA_READ_MS UINT8_C(50)
  332. /**\name Interface selection macro */
  333. #define BMA400_SPI_WR_MASK UINT8_C(0x7F)
  334. #define BMA400_SPI_RD_MASK UINT8_C(0x80)
  335. /**\name UTILITY MACROS */
  336. #define BMA400_SET_LOW_BYTE UINT16_C(0x00FF)
  337. #define BMA400_SET_HIGH_BYTE UINT16_C(0xFF00)
  338. /**\name Interrupt mapping selection */
  339. #define BMA400_DATA_READY_INT_MAP UINT8_C(0x01)
  340. #define BMA400_FIFO_WM_INT_MAP UINT8_C(0x02)
  341. #define BMA400_FIFO_FULL_INT_MAP UINT8_C(0x03)
  342. #define BMA400_GEN2_INT_MAP UINT8_C(0x04)
  343. #define BMA400_GEN1_INT_MAP UINT8_C(0x05)
  344. #define BMA400_ORIENT_CH_INT_MAP UINT8_C(0x06)
  345. #define BMA400_WAKEUP_INT_MAP UINT8_C(0x07)
  346. #define BMA400_ACT_CH_INT_MAP UINT8_C(0x08)
  347. #define BMA400_TAP_INT_MAP UINT8_C(0x09)
  348. #define BMA400_STEP_INT_MAP UINT8_C(0x0A)
  349. #define BMA400_INT_OVERRUN_MAP UINT8_C(0x0B)
  350. /**\name BMA400 FIFO configurations */
  351. #define BMA400_FIFO_AUTO_FLUSH UINT8_C(0x01)
  352. #define BMA400_FIFO_STOP_ON_FULL UINT8_C(0x02)
  353. #define BMA400_FIFO_TIME_EN UINT8_C(0x04)
  354. #define BMA400_FIFO_DATA_SRC UINT8_C(0x08)
  355. #define BMA400_FIFO_8_BIT_EN UINT8_C(0x10)
  356. #define BMA400_FIFO_X_EN UINT8_C(0x20)
  357. #define BMA400_FIFO_Y_EN UINT8_C(0x40)
  358. #define BMA400_FIFO_Z_EN UINT8_C(0x80)
  359. /**\name BMA400 FIFO data configurations */
  360. #define BMA400_FIFO_EN_X UINT8_C(0x01)
  361. #define BMA400_FIFO_EN_Y UINT8_C(0x02)
  362. #define BMA400_FIFO_EN_Z UINT8_C(0x04)
  363. #define BMA400_FIFO_EN_XY UINT8_C(0x03)
  364. #define BMA400_FIFO_EN_YZ UINT8_C(0x06)
  365. #define BMA400_FIFO_EN_XZ UINT8_C(0x05)
  366. #define BMA400_FIFO_EN_XYZ UINT8_C(0x07)
  367. /**\name BMA400 Self test configurations */
  368. #define BMA400_DISABLE_SELF_TEST UINT8_C(0x00)
  369. #define BMA400_ENABLE_POSITIVE_SELF_TEST UINT8_C(0x07)
  370. #define BMA400_ENABLE_NEGATIVE_SELF_TEST UINT8_C(0x0F)
  371. /**\name BMA400 FIFO data masks */
  372. #define BMA400_FIFO_HEADER_MASK UINT8_C(0x3E)
  373. #define BMA400_FIFO_BYTES_OVERREAD UINT8_C(25)
  374. #define BMA400_AWIDTH_MASK UINT8_C(0xEF)
  375. #define BMA400_FIFO_DATA_EN_MASK UINT8_C(0x0E)
  376. /**\name BMA400 Step status field - Activity status */
  377. #define BMA400_STILL_ACT UINT8_C(0x00)
  378. #define BMA400_WALK_ACT UINT8_C(0x01)
  379. #define BMA400_RUN_ACT UINT8_C(0x02)
  380. /*! It is inserted when FIFO_CONFIG0.fifo_data_src
  381. * is changed during the FIFO read
  382. */
  383. #define BMA400_FIFO_CONF0_CHANGE UINT8_C(0x01)
  384. /*! It is inserted when ACC_CONFIG0.filt1_bw
  385. * is changed during the FIFO read
  386. */
  387. #define BMA400_ACCEL_CONF0_CHANGE UINT8_C(0x02)
  388. /*! It is inserted when ACC_CONFIG1.acc_range
  389. * acc_odr or osr is changed during the FIFO read
  390. */
  391. #define BMA400_ACCEL_CONF1_CHANGE UINT8_C(0x04)
  392. /*! Accel width setting either 12/8 bit mode */
  393. #define BMA400_12_BIT_FIFO_DATA UINT8_C(0x01)
  394. #define BMA400_8_BIT_FIFO_DATA UINT8_C(0x00)
  395. /**\name BMA400 FIFO header configurations */
  396. #define BMA400_FIFO_SENSOR_TIME UINT8_C(0xA0)
  397. #define BMA400_FIFO_EMPTY_FRAME UINT8_C(0x80)
  398. #define BMA400_FIFO_CONTROL_FRAME UINT8_C(0x48)
  399. #define BMA400_FIFO_XYZ_ENABLE UINT8_C(0x8E)
  400. #define BMA400_FIFO_X_ENABLE UINT8_C(0x82)
  401. #define BMA400_FIFO_Y_ENABLE UINT8_C(0x84)
  402. #define BMA400_FIFO_Z_ENABLE UINT8_C(0x88)
  403. #define BMA400_FIFO_XY_ENABLE UINT8_C(0x86)
  404. #define BMA400_FIFO_YZ_ENABLE UINT8_C(0x8C)
  405. #define BMA400_FIFO_XZ_ENABLE UINT8_C(0x8A)
  406. /**\name BMA400 bit mask definitions */
  407. #define BMA400_POWER_MODE_STATUS_MSK UINT8_C(0x06)
  408. #define BMA400_POWER_MODE_STATUS_POS UINT8_C(1)
  409. #define BMA400_POWER_MODE_MSK UINT8_C(0x03)
  410. #define BMA400_ACCEL_ODR_MSK UINT8_C(0x0F)
  411. #define BMA400_ACCEL_RANGE_MSK UINT8_C(0xC0)
  412. #define BMA400_ACCEL_RANGE_POS UINT8_C(6)
  413. #define BMA400_DATA_FILTER_MSK UINT8_C(0x0C)
  414. #define BMA400_DATA_FILTER_POS UINT8_C(2)
  415. #define BMA400_OSR_MSK UINT8_C(0x30)
  416. #define BMA400_OSR_POS UINT8_C(4)
  417. #define BMA400_OSR_LP_MSK UINT8_C(0x60)
  418. #define BMA400_OSR_LP_POS UINT8_C(5)
  419. #define BMA400_FILT_1_BW_MSK UINT8_C(0x80)
  420. #define BMA400_FILT_1_BW_POS UINT8_C(7)
  421. #define BMA400_WAKEUP_TIMEOUT_MSK UINT8_C(0x04)
  422. #define BMA400_WAKEUP_TIMEOUT_POS UINT8_C(2)
  423. #define BMA400_WAKEUP_THRES_LSB_MSK UINT16_C(0x000F)
  424. #define BMA400_WAKEUP_THRES_MSB_MSK UINT16_C(0x0FF0)
  425. #define BMA400_WAKEUP_THRES_MSB_POS UINT8_C(4)
  426. #define BMA400_WAKEUP_TIMEOUT_THRES_MSK UINT8_C(0xF0)
  427. #define BMA400_WAKEUP_TIMEOUT_THRES_POS UINT8_C(4)
  428. #define BMA400_WAKEUP_INTERRUPT_MSK UINT8_C(0x02)
  429. #define BMA400_WAKEUP_INTERRUPT_POS UINT8_C(1)
  430. #define BMA400_AUTO_LOW_POW_MSK UINT8_C(0x0F)
  431. #define BMA400_AUTO_LP_THRES_MSK UINT16_C(0x0FF0)
  432. #define BMA400_AUTO_LP_THRES_POS UINT8_C(4)
  433. #define BMA400_AUTO_LP_THRES_LSB_MSK UINT16_C(0x000F)
  434. #define BMA400_WKUP_REF_UPDATE_MSK UINT8_C(0x03)
  435. #define BMA400_AUTO_LP_TIMEOUT_LSB_MSK UINT8_C(0xF0)
  436. #define BMA400_AUTO_LP_TIMEOUT_LSB_POS UINT8_C(4)
  437. #define BMA400_SAMPLE_COUNT_MSK UINT8_C(0x1C)
  438. #define BMA400_SAMPLE_COUNT_POS UINT8_C(2)
  439. #define BMA400_WAKEUP_EN_AXES_MSK UINT8_C(0xE0)
  440. #define BMA400_WAKEUP_EN_AXES_POS UINT8_C(5)
  441. #define BMA400_TAP_AXES_EN_MSK UINT8_C(0x18)
  442. #define BMA400_TAP_AXES_EN_POS UINT8_C(3)
  443. #define BMA400_TAP_QUIET_DT_MSK UINT8_C(0x30)
  444. #define BMA400_TAP_QUIET_DT_POS UINT8_C(4)
  445. #define BMA400_TAP_QUIET_MSK UINT8_C(0x0C)
  446. #define BMA400_TAP_QUIET_POS UINT8_C(2)
  447. #define BMA400_TAP_TICS_TH_MSK UINT8_C(0x03)
  448. #define BMA400_TAP_SENSITIVITY_MSK UINT8_C(0X07)
  449. #define BMA400_ACT_CH_AXES_EN_MSK UINT8_C(0xE0)
  450. #define BMA400_ACT_CH_AXES_EN_POS UINT8_C(5)
  451. #define BMA400_ACT_CH_DATA_SRC_MSK UINT8_C(0x10)
  452. #define BMA400_ACT_CH_DATA_SRC_POS UINT8_C(4)
  453. #define BMA400_ACT_CH_NPTS_MSK UINT8_C(0x0F)
  454. #define BMA400_INT_AXES_EN_MSK UINT8_C(0xE0)
  455. #define BMA400_INT_AXES_EN_POS UINT8_C(5)
  456. #define BMA400_INT_DATA_SRC_MSK UINT8_C(0x10)
  457. #define BMA400_INT_DATA_SRC_POS UINT8_C(4)
  458. #define BMA400_INT_REFU_MSK UINT8_C(0x0C)
  459. #define BMA400_INT_REFU_POS UINT8_C(2)
  460. #define BMA400_INT_HYST_MSK UINT8_C(0x03)
  461. #define BMA400_STABILITY_MODE_MSK UINT8_C(0x03)
  462. #define BMA400_GEN_INT_COMB_MSK UINT8_C(0x01)
  463. #define BMA400_GEN_INT_CRITERION_MSK UINT8_C(0x02)
  464. #define BMA400_GEN_INT_CRITERION_POS UINT8_C(0x01)
  465. #define BMA400_INT_PIN1_CONF_MSK UINT8_C(0x06)
  466. #define BMA400_INT_PIN1_CONF_POS UINT8_C(1)
  467. #define BMA400_INT_PIN2_CONF_MSK UINT8_C(0x60)
  468. #define BMA400_INT_PIN2_CONF_POS UINT8_C(5)
  469. #define BMA400_INT_STATUS_MSK UINT8_C(0xE0)
  470. #define BMA400_INT_STATUS_POS UINT8_C(5)
  471. #define BMA400_EN_DRDY_MSK UINT8_C(0x80)
  472. #define BMA400_EN_DRDY_POS UINT8_C(7)
  473. #define BMA400_EN_FIFO_WM_MSK UINT8_C(0x40)
  474. #define BMA400_EN_FIFO_WM_POS UINT8_C(6)
  475. #define BMA400_EN_FIFO_FULL_MSK UINT8_C(0x20)
  476. #define BMA400_EN_FIFO_FULL_POS UINT8_C(5)
  477. #define BMA400_EN_INT_OVERRUN_MSK UINT8_C(0x10)
  478. #define BMA400_EN_INT_OVERRUN_POS UINT8_C(4)
  479. #define BMA400_EN_GEN2_MSK UINT8_C(0x08)
  480. #define BMA400_EN_GEN2_POS UINT8_C(3)
  481. #define BMA400_EN_GEN1_MSK UINT8_C(0x04)
  482. #define BMA400_EN_GEN1_POS UINT8_C(2)
  483. #define BMA400_EN_ORIENT_CH_MSK UINT8_C(0x02)
  484. #define BMA400_EN_ORIENT_CH_POS UINT8_C(1)
  485. #define BMA400_EN_LATCH_MSK UINT8_C(0x80)
  486. #define BMA400_EN_LATCH_POS UINT8_C(7)
  487. #define BMA400_EN_ACTCH_MSK UINT8_C(0x10)
  488. #define BMA400_EN_ACTCH_POS UINT8_C(4)
  489. #define BMA400_EN_D_TAP_MSK UINT8_C(0x08)
  490. #define BMA400_EN_D_TAP_POS UINT8_C(3)
  491. #define BMA400_EN_S_TAP_MSK UINT8_C(0x04)
  492. #define BMA400_EN_S_TAP_POS UINT8_C(2)
  493. #define BMA400_EN_STEP_INT_MSK UINT8_C(0x01)
  494. #define BMA400_STEP_MAP_INT2_MSK UINT8_C(0x10)
  495. #define BMA400_STEP_MAP_INT2_POS UINT8_C(4)
  496. #define BMA400_EN_WAKEUP_INT_MSK UINT8_C(0x01)
  497. #define BMA400_TAP_MAP_INT1_MSK UINT8_C(0x04)
  498. #define BMA400_TAP_MAP_INT1_POS UINT8_C(2)
  499. #define BMA400_TAP_MAP_INT2_MSK UINT8_C(0x40)
  500. #define BMA400_TAP_MAP_INT2_POS UINT8_C(6)
  501. #define BMA400_ACTCH_MAP_INT1_MSK UINT8_C(0x08)
  502. #define BMA400_ACTCH_MAP_INT1_POS UINT8_C(3)
  503. #define BMA400_ACTCH_MAP_INT2_MSK UINT8_C(0x80)
  504. #define BMA400_ACTCH_MAP_INT2_POS UINT8_C(7)
  505. #define BMA400_FIFO_BYTES_CNT_MSK UINT8_C(0x07)
  506. #define BMA400_FIFO_TIME_EN_MSK UINT8_C(0x04)
  507. #define BMA400_FIFO_TIME_EN_POS UINT8_C(2)
  508. #define BMA400_FIFO_AXES_EN_MSK UINT8_C(0xE0)
  509. #define BMA400_FIFO_AXES_EN_POS UINT8_C(5)
  510. #define BMA400_FIFO_8_BIT_EN_MSK UINT8_C(0x10)
  511. #define BMA400_FIFO_8_BIT_EN_POS UINT8_C(4)
  512. /**\name Macro to SET and GET BITS of a register */
  513. #define BMA400_SET_BITS(reg_data, bitname, data) \
  514. ((reg_data & ~(bitname ## _MSK)) | \
  515. ((data << bitname ## _POS) & bitname ## _MSK))
  516. #define BMA400_GET_BITS(reg_data, bitname) ((reg_data & (bitname ## _MSK)) >> \
  517. (bitname ## _POS))
  518. #define BMA400_SET_BITS_POS_0(reg_data, bitname, data) \
  519. ((reg_data & ~(bitname ## _MSK)) | \
  520. (data & bitname ## _MSK))
  521. #define BMA400_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname ## _MSK))
  522. #define BMA400_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname ## _MSK))
  523. #define BMA400_GET_LSB(var) (uint8_t)(var & BMA400_SET_LOW_BYTE)
  524. #define BMA400_GET_MSB(var) (uint8_t)((var & BMA400_SET_HIGH_BYTE) >> 8)
  525. /********************************************************/
  526. /*!
  527. * @brief Interface selection enums
  528. */
  529. enum bma400_intf {
  530. /*! SPI interface */
  531. BMA400_SPI_INTF,
  532. /*! I2C interface */
  533. BMA400_I2C_INTF
  534. };
  535. /********************************************************/
  536. /**\name TYPE DEFINITIONS */
  537. /*!
  538. * @brief Bus communication function pointer which should be mapped to
  539. * the platform specific read and write functions of the user
  540. */
  541. typedef int8_t (*bma400_com_fptr_t)(void *intf_ptr, uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
  542. uint16_t length);
  543. /*! Delay function pointer */
  544. typedef void (*bma400_delay_fptr_t)(uint32_t period);
  545. /********************************************************/
  546. /**\name STRUCTURE DEFINITIONS*/
  547. /*!
  548. * @brief Sensor selection enums
  549. */
  550. enum bma400_sensor {
  551. BMA400_ACCEL,
  552. BMA400_TAP_INT,
  553. BMA400_ACTIVITY_CHANGE_INT,
  554. BMA400_GEN1_INT,
  555. BMA400_GEN2_INT,
  556. BMA400_ORIENT_CHANGE_INT,
  557. BMA400_STEP_COUNTER_INT
  558. };
  559. /*!
  560. * @brief Interrupt channel selection enums
  561. */
  562. enum bma400_int_chan {
  563. BMA400_UNMAP_INT_PIN,
  564. BMA400_INT_CHANNEL_1,
  565. BMA400_INT_CHANNEL_2,
  566. BMA400_MAP_BOTH_INT_PINS
  567. };
  568. /*!
  569. * @brief Interrupt pin hardware configurations
  570. */
  571. struct bma400_int_pin_conf {
  572. /*! Interrupt channel selection enums */
  573. enum bma400_int_chan int_chan;
  574. /*! Interrupt pin configuration
  575. * Assignable Macros :
  576. * - BMA400_INT_PUSH_PULL_ACTIVE_0
  577. * - BMA400_INT_PUSH_PULL_ACTIVE_1
  578. * - BMA400_INT_OPEN_DRIVE_ACTIVE_0
  579. * - BMA400_INT_OPEN_DRIVE_ACTIVE_1
  580. */
  581. uint8_t pin_conf;
  582. };
  583. /*!
  584. * @brief Accel basic configuration
  585. */
  586. struct bma400_acc_conf {
  587. /*! Output data rate
  588. * Assignable macros :
  589. * - BMA400_ODR_12_5HZ - BMA400_ODR_25HZ - BMA400_ODR_50HZ
  590. * - BMA400_ODR_100HZ - BMA400_ODR_200HZ - BMA400_ODR_400HZ
  591. * - BMA400_ODR_800HZ
  592. */
  593. uint8_t odr;
  594. /*! Range of sensor
  595. * Assignable macros :
  596. * - BMA400_2G_RANGE - BMA400_8G_RANGE
  597. * - BMA400_4G_RANGE - BMA400_16G_RANGE
  598. */
  599. uint8_t range;
  600. /*! Filter setting for data source
  601. * Assignable Macros :
  602. * - BMA400_DATA_SRC_ACCEL_FILT_1
  603. * - BMA400_DATA_SRC_ACCEL_FILT_2
  604. * - BMA400_DATA_SRC_ACCEL_FILT_LP
  605. */
  606. uint8_t data_src;
  607. /*! Assignable Macros for osr and osr_lp:
  608. * - BMA400_ACCEL_OSR_SETTING_0 - BMA400_ACCEL_OSR_SETTING_2
  609. * - BMA400_ACCEL_OSR_SETTING_1 - BMA400_ACCEL_OSR_SETTING_3
  610. */
  611. /*! OSR setting for data source */
  612. uint8_t osr;
  613. /*! OSR setting for low power mode */
  614. uint8_t osr_lp;
  615. /*! Filter 1 Bandwidth
  616. * Assignable macros :
  617. * - BMA400_ACCEL_FILT1_BW_0
  618. * - BMA400_ACCEL_FILT1_BW_1
  619. */
  620. uint8_t filt1_bw;
  621. /*! Interrupt channel to be mapped */
  622. enum bma400_int_chan int_chan;
  623. };
  624. /*!
  625. * @brief Tap interrupt configurations
  626. */
  627. struct bma400_tap_conf {
  628. /*! Axes enabled to sense tap setting
  629. * Assignable macros :
  630. * - BMA400_X_AXIS_EN_TAP
  631. * - BMA400_Y_AXIS_EN_TAP
  632. * - BMA400_Z_AXIS_EN_TAP
  633. */
  634. uint8_t axes_sel;
  635. /*! TAP sensitivity settings modifies the threshold
  636. * for minimum TAP amplitude
  637. * Assignable macros :
  638. * - BMA400_TAP_SENSITIVITY_0 - BMA400_TAP_SENSITIVITY_4
  639. * - BMA400_TAP_SENSITIVITY_1 - BMA400_TAP_SENSITIVITY_5
  640. * - BMA400_TAP_SENSITIVITY_2 - BMA400_TAP_SENSITIVITY_6
  641. * - BMA400_TAP_SENSITIVITY_3 - BMA400_TAP_SENSITIVITY_7
  642. *
  643. * @note :
  644. * - BMA400_TAP_SENSITIVITY_0 correspond to highest sensitivity
  645. * - BMA400_TAP_SENSITIVITY_7 correspond to lowest sensitivity
  646. */
  647. uint8_t sensitivity;
  648. /*! TAP tics_th setting is the maximum time between upper and lower
  649. * peak of a tap, in data samples, This time depends on the
  650. * mechanics of the device tapped onto default = 12 samples
  651. * Assignable macros :
  652. * - BMA400_TICS_TH_6_DATA_SAMPLES
  653. * - BMA400_TICS_TH_9_DATA_SAMPLES
  654. * - BMA400_TICS_TH_12_DATA_SAMPLES
  655. * - BMA400_TICS_TH_18_DATA_SAMPLES
  656. */
  657. uint8_t tics_th;
  658. /*! BMA400 TAP - quiet settings to configure minimum quiet time
  659. * before and after double tap, in the data samples.
  660. * This time also defines the longest time interval between two
  661. * taps so that they are considered as double tap
  662. * Assignable macros :
  663. * - BMA400_QUIET_60_DATA_SAMPLES
  664. * - BMA400_QUIET_80_DATA_SAMPLES
  665. * - BMA400_QUIET_100_DATA_SAMPLES
  666. * - BMA400_QUIET_120_DATA_SAMPLES
  667. */
  668. uint8_t quiet;
  669. /*! BMA400 TAP - quiet_dt settings
  670. * quiet_dt refers to Minimum time between the two taps of a
  671. * double tap, in data samples
  672. * Assignable macros :
  673. * - BMA400_QUIET_DT_4_DATA_SAMPLES
  674. * - BMA400_QUIET_DT_8_DATA_SAMPLES
  675. * - BMA400_QUIET_DT_12_DATA_SAMPLES
  676. * - BMA400_QUIET_DT_16_DATA_SAMPLES
  677. */
  678. uint8_t quiet_dt;
  679. /*! Interrupt channel to be mapped */
  680. enum bma400_int_chan int_chan;
  681. };
  682. /*!
  683. * @brief Activity change interrupt configurations
  684. */
  685. struct bma400_act_ch_conf {
  686. /*! Threshold for activity change (8 mg/LSB) */
  687. uint8_t act_ch_thres;
  688. /*! Axes enabled to sense activity change
  689. * Assignable macros :
  690. * - BMA400_X_AXIS_EN
  691. * - BMA400_Y_AXIS_EN
  692. * - BMA400_Z_AXIS_EN
  693. * - BMA400_XYZ_AXIS_EN
  694. */
  695. uint8_t axes_sel;
  696. /*! Data Source for activity change
  697. * Assignable macros :
  698. * - BMA400_DATA_SRC_ACC_FILT1
  699. * - BMA400_DATA_SRC_ACC_FILT2
  700. */
  701. uint8_t data_source;
  702. /*! Sample count for sensing act_ch
  703. * Assignable macros :
  704. * - BMA400_ACT_CH_SAMPLE_CNT_32
  705. * - BMA400_ACT_CH_SAMPLE_CNT_64
  706. * - BMA400_ACT_CH_SAMPLE_CNT_128
  707. * - BMA400_ACT_CH_SAMPLE_CNT_256
  708. * - BMA400_ACT_CH_SAMPLE_CNT_512
  709. */
  710. uint8_t act_ch_ntps;
  711. /*! Interrupt channel to be mapped */
  712. enum bma400_int_chan int_chan;
  713. };
  714. /*!
  715. * @brief Generic interrupt configurations
  716. */
  717. struct bma400_gen_int_conf {
  718. /*! Threshold for the gen1 interrupt (1 LSB = 8mg)
  719. * if gen_int_thres = 10, then threshold = 10 * 8 = 80mg
  720. */
  721. uint8_t gen_int_thres;
  722. /*! Duration for which the condition has to persist until
  723. * interrupt can be triggered
  724. * duration is measured in data samples of selected data source
  725. */
  726. uint16_t gen_int_dur;
  727. /*! Enable axes to sense for the gen1 interrupt
  728. * Assignable macros :
  729. * - BMA400_X_AXIS_EN
  730. * - BMA400_Y_AXIS_EN
  731. * - BMA400_Z_AXIS_EN
  732. * - BMA400_XYZ_AXIS_EN
  733. */
  734. uint8_t axes_sel;
  735. /*! Data source to sense for the gen1 interrupt
  736. * Assignable macros :
  737. * - BMA400_DATA_SRC_ACC_FILT1
  738. * - BMA400_DATA_SRC_ACC_FILT2
  739. */
  740. uint8_t data_src;
  741. /*! Activity/Inactivity selection macros
  742. * Assignable macros :
  743. * - BMA400_ACTIVITY_INT
  744. * - BMA400_INACTIVITY_INT
  745. */
  746. uint8_t criterion_sel;
  747. /*! Axes selection logic macros
  748. * Assignable macros :
  749. * - BMA400_ALL_AXES_INT
  750. * - BMA400_ANY_AXES_INT
  751. */
  752. uint8_t evaluate_axes;
  753. /*! Reference x,y,z values updates
  754. * Assignable macros :
  755. * - BMA400_MANUAL_UPDATE
  756. * - BMA400_ONE_TIME_UPDATE
  757. * - BMA400_EVERY_TIME_UPDATE
  758. * - BMA400_LP_EVERY_TIME_UPDATE
  759. */
  760. uint8_t ref_update;
  761. /*! Hysteresis value
  762. * Higher the hysteresis value, Lower the value of noise
  763. * Assignable macros :
  764. * - BMA400_HYST_0_MG
  765. * - BMA400_HYST_24_MG
  766. * - BMA400_HYST_48_MG
  767. * - BMA400_HYST_96_MG
  768. */
  769. uint8_t hysteresis;
  770. /*! Threshold value for x axes */
  771. uint16_t int_thres_ref_x;
  772. /*! Threshold value for y axes */
  773. uint16_t int_thres_ref_y;
  774. /*! Threshold value for z axes */
  775. uint16_t int_thres_ref_z;
  776. /*! Interrupt channel to be mapped */
  777. enum bma400_int_chan int_chan;
  778. };
  779. /*!
  780. * @brief Orient interrupt configurations
  781. */
  782. struct bma400_orient_int_conf {
  783. /*! Enable axes to sense for the gen1 interrupt
  784. * Assignable macros :
  785. * - BMA400_X_AXIS_EN
  786. * - BMA400_Y_AXIS_EN
  787. * - BMA400_Z_AXIS_EN
  788. * - BMA400_XYZ_AXIS_EN
  789. */
  790. uint8_t axes_sel;
  791. /*! Data source to sense for the gen1 interrupt
  792. * Assignable macros :
  793. * - BMA400_DATA_SRC_ACC_FILT1
  794. * - BMA400_DATA_SRC_ACC_FILT2
  795. */
  796. uint8_t data_src;
  797. /*! Reference x,y,z values updates
  798. * Assignable macros :
  799. * - BMA400_MANUAL_UPDATE
  800. * - BMA400_ORIENT_REFU_ACC_FILT_2
  801. * - BMA400_ORIENT_REFU_ACC_FILT_LP
  802. */
  803. uint8_t ref_update;
  804. /*! Threshold for the orient interrupt (1 LSB = 8mg)
  805. * if orient_thres = 10, then threshold = 10 * 8 = 80mg
  806. */
  807. uint8_t orient_thres;
  808. /*! Threshold to check for stability (1 LSB = 8mg)
  809. * if stability_thres = 10, then threshold = 10 * 8 = 80mg
  810. */
  811. uint8_t stability_thres;
  812. /*! orient_int_dur duration in which orient interrupt
  813. * should occur, It is 8bit value configurable at 10ms/LSB.
  814. */
  815. uint8_t orient_int_dur;
  816. /*! Stability check conditions
  817. * Assignable macros :
  818. * - BMA400_STABILITY_DISABLED
  819. * - BMA400_STABILITY_ACC_FILT_2
  820. * - BMA400_STABILITY_ACC_FILT_LP
  821. */
  822. uint8_t stability_mode;
  823. /*! Reference value for x axes */
  824. uint16_t orient_ref_x;
  825. /*! Reference value for y axes */
  826. uint16_t orient_ref_y;
  827. /*! Reference value for z axes */
  828. uint16_t orient_ref_z;
  829. /*! Interrupt channel to be mapped */
  830. enum bma400_int_chan int_chan;
  831. };
  832. /* Step counter configurations */
  833. struct bma400_step_int_conf {
  834. /*! Interrupt channel to be mapped */
  835. enum bma400_int_chan int_chan;
  836. };
  837. /*!
  838. * @brief Union of sensor Configurations
  839. */
  840. union bma400_set_param {
  841. /* Accel configurations */
  842. struct bma400_acc_conf accel;
  843. /* TAP configurations */
  844. struct bma400_tap_conf tap;
  845. /* Activity change configurations */
  846. struct bma400_act_ch_conf act_ch;
  847. /* Generic interrupt configurations */
  848. struct bma400_gen_int_conf gen_int;
  849. /* Orient configurations */
  850. struct bma400_orient_int_conf orient;
  851. /* Step counter configurations */
  852. struct bma400_step_int_conf step_cnt;
  853. };
  854. /*!
  855. * @brief Sensor selection and their configurations
  856. */
  857. struct bma400_sensor_conf {
  858. /* Sensor selection */
  859. enum bma400_sensor type;
  860. /* Sensor configuration */
  861. union bma400_set_param param;
  862. };
  863. /*!
  864. * @brief enum to select device settings
  865. */
  866. enum bma400_device {
  867. BMA400_AUTOWAKEUP_TIMEOUT,
  868. BMA400_AUTOWAKEUP_INT,
  869. BMA400_AUTO_LOW_POWER,
  870. BMA400_INT_PIN_CONF,
  871. BMA400_INT_OVERRUN_CONF,
  872. BMA400_FIFO_CONF
  873. };
  874. /*!
  875. * @brief BMA400 auto-wakeup configurations
  876. */
  877. struct bma400_auto_wakeup_conf {
  878. /*! Enable auto wake-up by using timeout threshold
  879. * Assignable Macros :
  880. * - BMA400_ENABLE - BMA400_DISABLE
  881. */
  882. uint8_t wakeup_timeout;
  883. /*! Timeout threshold after which auto wake-up occurs
  884. * It is 12bit value configurable at 2.5ms/LSB
  885. * Maximum timeout is 10.24s (4096 * 2.5) for
  886. * which the assignable macro is :
  887. * - BMA400_AUTO_WAKEUP_TIMEOUT_MAX
  888. */
  889. uint16_t timeout_thres;
  890. };
  891. /*!
  892. * @brief BMA400 wakeup configurations
  893. */
  894. struct bma400_wakeup_conf {
  895. /*! Wakeup reference update
  896. * Assignable macros:
  897. * - BMA400_MANUAL_UPDATE
  898. * - BMA400_ONE_TIME_UPDATE
  899. * - BMA400_EVERY_TIME_UPDATE
  900. */
  901. uint8_t wakeup_ref_update;
  902. /*! Number of samples for interrupt condition evaluation
  903. * Assignable Macros :
  904. * - BMA400_SAMPLE_COUNT_1 - BMA400_SAMPLE_COUNT_5
  905. * - BMA400_SAMPLE_COUNT_2 - BMA400_SAMPLE_COUNT_6
  906. * - BMA400_SAMPLE_COUNT_3 - BMA400_SAMPLE_COUNT_7
  907. * - BMA400_SAMPLE_COUNT_4 - BMA400_SAMPLE_COUNT_8
  908. */
  909. uint8_t sample_count;
  910. /*! Enable low power wake-up interrupt for X(BIT 0), Y(BIT 1), Z(BIT 2)
  911. * axes 0 - not active; 1 - active
  912. * Assignable macros :
  913. * - BMA400_X_AXIS_EN
  914. * - BMA400_Y_AXIS_EN
  915. * - BMA400_Z_AXIS_EN
  916. * - BMA400_XYZ_AXIS_EN
  917. */
  918. uint8_t wakeup_axes_en;
  919. /*! Interrupt threshold configuration */
  920. uint8_t int_wkup_threshold;
  921. /*! Reference acceleration x-axis for the wake-up interrupt */
  922. uint8_t int_wkup_ref_x;
  923. /*! Reference acceleration y-axis for the wake-up interrupt */
  924. uint8_t int_wkup_ref_y;
  925. /*! Reference acceleration z-axis for the wake-up interrupt */
  926. uint8_t int_wkup_ref_z;
  927. /*! Interrupt channel to be mapped */
  928. enum bma400_int_chan int_chan;
  929. };
  930. /*!
  931. * @brief BMA400 auto-low power configurations
  932. */
  933. struct bma400_auto_lp_conf {
  934. /*! Enable auto low power mode using data ready interrupt /
  935. * Genric interrupt1 / timeout counter value
  936. * Assignable macros :
  937. * - BMA400_AUTO_LP_DRDY_TRIGGER
  938. * - BMA400_AUTO_LP_GEN1_TRIGGER
  939. * - BMA400_AUTO_LP_TIMEOUT_EN
  940. * - BMA400_AUTO_LP_TIME_RESET_EN
  941. * - BMA400_AUTO_LP_TIMEOUT_DISABLE
  942. */
  943. uint8_t auto_low_power_trigger;
  944. /*! Timeout threshold after which auto wake-up occurs
  945. * It is 12bit value configurable at 2.5ms/LSB
  946. * Maximum timeout is 10.24s (4096 * 2.5) for
  947. * which the assignable macro is :
  948. * - BMA400_AUTO_LP_TIMEOUT_MAX
  949. */
  950. uint16_t auto_lp_timeout_threshold;
  951. };
  952. /*!
  953. * @brief FIFO configurations
  954. */
  955. struct bma400_fifo_conf {
  956. /*! Select FIFO configurations to enable/disable
  957. * Assignable Macros :
  958. * - BMA400_FIFO_AUTO_FLUSH
  959. * - BMA400_FIFO_STOP_ON_FULL
  960. * - BMA400_FIFO_TIME_EN
  961. * - BMA400_FIFO_DATA_SRC
  962. * - BMA400_FIFO_8_BIT_EN
  963. * - BMA400_FIFO_X_EN
  964. * - BMA400_FIFO_Y_EN
  965. * - BMA400_FIFO_Z_EN
  966. */
  967. uint8_t conf_regs;
  968. /*! Enable/ disable selected FIFO configurations
  969. * Assignable Macros :
  970. * - BMA400_ENABLE
  971. * - BMA400_DISABLE
  972. */
  973. uint8_t conf_status;
  974. /*! Value to set the water-mark */
  975. uint16_t fifo_watermark;
  976. /*! Interrupt pin mapping for FIFO full interrupt */
  977. enum bma400_int_chan fifo_full_channel;
  978. /*! Interrupt pin mapping for FIFO water-mark interrupt */
  979. enum bma400_int_chan fifo_wm_channel;
  980. };
  981. /*!
  982. * @brief Interrupt overrun configurations
  983. */
  984. struct bma400_int_overrun {
  985. /*! Interrupt pin mapping for interrupt overrun */
  986. enum bma400_int_chan int_chan;
  987. };
  988. /*!
  989. * @brief Union of device configuration parameters
  990. */
  991. union bma400_device_params {
  992. /* Auto wakeup configurations */
  993. struct bma400_auto_wakeup_conf auto_wakeup;
  994. /* Wakeup interrupt configurations */
  995. struct bma400_wakeup_conf wakeup;
  996. /* Auto Low power configurations */
  997. struct bma400_auto_lp_conf auto_lp;
  998. /* Interrupt pin configurations */
  999. struct bma400_int_pin_conf int_conf;
  1000. /* FIFO configuration */
  1001. struct bma400_fifo_conf fifo_conf;
  1002. /* Interrupt overrun configuration */
  1003. struct bma400_int_overrun overrun_int;
  1004. };
  1005. /*!
  1006. * @brief BMA400 device configuration
  1007. */
  1008. struct bma400_device_conf {
  1009. /* Device feature selection */
  1010. enum bma400_device type;
  1011. /* Device feature configuration */
  1012. union bma400_device_params param;
  1013. };
  1014. /*!
  1015. * @brief BMA400 sensor data
  1016. */
  1017. struct bma400_sensor_data {
  1018. /*! X-axis sensor data */
  1019. int16_t x;
  1020. /*! Y-axis sensor data */
  1021. int16_t y;
  1022. /*! Z-axis sensor data */
  1023. int16_t z;
  1024. /*! sensor time */
  1025. uint32_t sensortime;
  1026. };
  1027. /*!
  1028. * @brief BMA400 interrupt selection
  1029. */
  1030. enum bma400_int_type {
  1031. /* DRDY interrupt */
  1032. BMA400_DRDY_INT_EN,
  1033. /* FIFO watermark interrupt */
  1034. BMA400_FIFO_WM_INT_EN,
  1035. /* FIFO full interrupt */
  1036. BMA400_FIFO_FULL_INT_EN,
  1037. /* Generic interrupt 2 */
  1038. BMA400_GEN2_INT_EN,
  1039. /* Generic interrupt 1 */
  1040. BMA400_GEN1_INT_EN,
  1041. /* Orient change interrupt */
  1042. BMA400_ORIENT_CHANGE_INT_EN,
  1043. /* Latch interrupt */
  1044. BMA400_LATCH_INT_EN,
  1045. /* Activity change interrupt */
  1046. BMA400_ACTIVITY_CHANGE_INT_EN,
  1047. /* Double tap interrupt */
  1048. BMA400_DOUBLE_TAP_INT_EN,
  1049. /* Single tap interrupt */
  1050. BMA400_SINGLE_TAP_INT_EN,
  1051. /* Step interrupt */
  1052. BMA400_STEP_COUNTER_INT_EN,
  1053. /* Auto wakeup interrupt */
  1054. BMA400_AUTO_WAKEUP_EN
  1055. };
  1056. /*!
  1057. * @brief Interrupt enable/disable configurations
  1058. */
  1059. struct bma400_int_enable {
  1060. /*! Enum to choose the interrupt to be enabled */
  1061. enum bma400_int_type type;
  1062. /*! Enable/ disable selected interrupts
  1063. * Assignable Macros :
  1064. * - BMA400_ENABLE
  1065. * - BMA400_DISABLE
  1066. */
  1067. uint8_t conf;
  1068. };
  1069. struct bma400_fifo_data {
  1070. /*! Data buffer of user defined length is to be mapped here */
  1071. uint8_t *data;
  1072. /*! While calling the API "bma400_get_fifo_data" , length stores
  1073. * number of bytes in FIFO to be read (specified by user as input)
  1074. * and after execution of the API ,number of FIFO data bytes
  1075. * available is provided as an output to user
  1076. */
  1077. uint16_t length;
  1078. /*! FIFO time enable */
  1079. uint8_t fifo_time_enable;
  1080. /*! FIFO 8bit mode enable */
  1081. uint8_t fifo_8_bit_en;
  1082. /*! Streaming of the Accelerometer data for selected x,y,z axes
  1083. * - BMA400_FIFO_X_EN
  1084. * - BMA400_FIFO_Y_EN
  1085. * - BMA400_FIFO_Z_EN
  1086. */
  1087. uint8_t fifo_data_enable;
  1088. /*! Will be equal to length when no more frames are there to parse */
  1089. uint16_t accel_byte_start_idx;
  1090. /*! It stores the value of configuration changes
  1091. * in sensor during FIFO read */
  1092. uint8_t conf_change;
  1093. /*! Value of FIFO sensor time time */
  1094. uint32_t fifo_sensor_time;
  1095. };
  1096. /*!
  1097. * @brief bma400 device structure
  1098. */
  1099. struct bma400_dev {
  1100. /*! Chip Id */
  1101. uint8_t chip_id;
  1102. /*! Device Id */
  1103. uint8_t dev_id;
  1104. /*! SPI/I2C Interface selection */
  1105. enum bma400_intf intf;
  1106. /*! Interface handle pointer */
  1107. void *intf_ptr;
  1108. /*! Decide SPI or I2C read mechanism */
  1109. uint8_t dummy_byte;
  1110. /*! Bus read function pointer */
  1111. bma400_com_fptr_t read;
  1112. /*! Bus write function pointer */
  1113. bma400_com_fptr_t write;
  1114. /*! delay(in ms) function pointer */
  1115. bma400_delay_fptr_t delay_ms;
  1116. };
  1117. #endif /* BMA400_DEFS_H_ */
  1118. /** @}*/
  1119. /** @}*/