lis2dh12_internal.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /**
  2. * Copyright (c) 2017 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef LIS2DH12_INTERNAL_H
  41. #define LIS2DH12_INTERNAL_H
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #define LIS2DH12_AUTO_INCR_MASK 0x80
  46. /**
  47. * @brief LIS2DH12 sensor registers.
  48. */
  49. #define LIS2DH12_REG_STATUS_AUX 0x07
  50. #define LIS2DH12_REG_OUT_TEMP_L 0x0C
  51. #define LIS2DH12_REG_OUT_TEMP_H 0x0D
  52. #define LIS2DH12_REG_WHO_AM_I 0x0F
  53. #define LIS2DH12_REG_CTRL_REG0 0x1E
  54. #define LIS2DH12_REG_TEMP_CFG_REG 0x1F
  55. #define LIS2DH12_REG_CTRL_REG1 0x20
  56. #define LIS2DH12_REG_CTRL_REG2 0x21
  57. #define LIS2DH12_REG_CTRL_REG3 0x22
  58. #define LIS2DH12_REG_CTRL_REG4 0x23
  59. #define LIS2DH12_REG_CTRL_REG5 0x24
  60. #define LIS2DH12_REG_CTRL_REG6 0x25
  61. #define LIS2DH12_REG_REFERENCE 0x26
  62. #define LIS2DH12_REG_STATUS 0x27
  63. #define LIS2DH12_REG_OUT_X_L 0x28
  64. #define LIS2DH12_REG_OUT_X_H 0x29
  65. #define LIS2DH12_REG_OUT_Y_L 0x2A
  66. #define LIS2DH12_REG_OUT_Y_H 0x2B
  67. #define LIS2DH12_REG_OUT_Z_L 0x2C
  68. #define LIS2DH12_REG_OUT_Z_H 0x2D
  69. #define LIS2DH12_REG_FIFO_CTRL 0x2E
  70. #define LIS2DH12_REG_FIFO_SRC 0x2F
  71. #define LIS2DH12_REG_INT1_CFG 0x30
  72. #define LIS2DH12_REG_INT1_SRC 0x31
  73. #define LIS2DH12_REG_INT1_THS 0x32
  74. #define LIS2DH12_REG_INT1_DURATION 0x33
  75. #define LIS2DH12_REG_INT2_CFG 0x34
  76. #define LIS2DH12_REG_INT2_SRC 0x35
  77. #define LIS2DH12_REG_INT2_THS 0x36
  78. #define LIS2DH12_REG_INT2_DURATION 0x37
  79. #define LIS2DH12_REG_CLICK_CFG 0x38
  80. #define LIS2DH12_REG_CLICK_SRC 0x39
  81. #define LIS2DH12_REG_CLICK_THS 0x3A
  82. #define LIS2DH12_REG_TIME_LIMIT 0x3B
  83. #define LIS2DH12_REG_TIME_LATENCY 0x3C
  84. #define LIS2DH12_REG_TIME_WINDOW 0x3D
  85. #define LIS2DH12_REG_ACT_THS 0x3E
  86. #define LIS2DH12_REG_ACT_DUR 0x3F
  87. /**
  88. * @brief Config register defaults.
  89. */
  90. #define LIS2DH12_DEF_CTRL_REG0 0x10
  91. #define LIS2DH12_DEF_CTRL_REG1 0x07
  92. #define LIS2DH12_BYTES_PER_SAMPLE 6
  93. #define LIS2DH12_BYTES_PER_TEMP 2
  94. /**
  95. * @brief Status reg aux bitmasks.
  96. */
  97. // Bitmasks for TOR.
  98. #define LIS2DH12_TOR_POS 6
  99. #define LIS2DH12_TOR_MASK (1 << LIS2DH12_TOR_POS)
  100. // Bitmasks for TDA.
  101. #define LIS2DH12_TDA_POS 2
  102. #define LIS2DH12_TDA_MASK (1 << LIS2DH12_TDA_POS)
  103. /**
  104. * @brief Control register 0 bitmasks
  105. */
  106. #define LIS2DH12_CTRL_REG0_VALID_MASK 0x7F
  107. #define LIS2DH12_CTRL_REG0_VALID_SET 0x10
  108. // Bitmasks for SDO_PU_DISC.
  109. #define LIS2DH12_SDO_PU_DISC_POS 7
  110. #define LIS2DH12_SDO_PU_DISC_MASK (1 << LIS2DH12_SDO_PU_DISC_POS)
  111. /**
  112. * @brief Temp config register bitmasks
  113. */
  114. #define LIS2DH12_TEMP_CONF_VALID_MASK 0x3F
  115. // Bitmasks for TEMP_EN
  116. #define LIS2DH12_TEMP_EN_POS 6
  117. #define LIS2DH12_TEMP_EN_MASK (3 << LIS2DH12_TEMP_EN_POS)
  118. /**
  119. * @brief Control register 1 bitmasks
  120. */
  121. // Bitmasks for ODR.
  122. #define LIS2DH12_ODR_POS 4
  123. #define LIS2DH12_ODR_MASK (0x0F << LIS2DH12_ODR_POS)
  124. // Bitmasks for LP_EN
  125. #define LIS2DH12_LP_EN_POS 3
  126. #define LIS2DH12_LP_EN_MASK (1 << LIS2DH12_LP_EN_POS)
  127. // Bitmasks for Z_EN
  128. #define LIS2DH12_Z_EN_POS 2
  129. #define LIS2DH12_Z_EN_MASK (1 << LIS2DH12_Z_EN_POS)
  130. // Bitmasks for Y_EN
  131. #define LIS2DH12_Y_EN_POS 1
  132. #define LIS2DH12_Y_EN_MASK (1 << LIS2DH12_Y_EN_POS)
  133. // Bitmasks for X_EN
  134. #define LIS2DH12_X_EN_POS 0
  135. #define LIS2DH12_X_EN_MASK (1 << LIS2DH12_X_EN_POS)
  136. /**
  137. * @brief Control register 2 bitmasks.
  138. */
  139. // Bitmasks for HPM.
  140. #define LIS2DH12_HPM_POS 6
  141. #define LIS2DH12_HPM_MASK (3 << LIS2DH12_HPM_POS)
  142. // Bitmasks for HPCF.
  143. #define LIS2DH12_HPCF_POS 4
  144. #define LIS2DH12_HPCF_MASK (3 << LIS2DH12_HPCF_POS)
  145. // Bitmasks for FDS.
  146. #define LIS2DH12_FDS_POS 3
  147. #define LIS2DH12_FDS_MASK (1 << LIS2DH12_FDS_POS)
  148. // Bitmasks for HPCLICK.
  149. #define LIS2DH12_HP_C_POS 2
  150. #define LIS2DH12_HP_C_MASK (1 << LIS2DH12_HP_C_POS)
  151. // Bitmasks for HP_IA2.
  152. #define LIS2DH12_HP_I2_POS 1
  153. #define LIS2DH12_HP_I2_MASK (1 << LIS2DH12_HP_I2_POS)
  154. // Bitmasks for HP_IA1.
  155. #define LIS2DH12_HP_I1_POS 0
  156. #define LIS2DH12_HP_I1_MASK (1 << LIS2DH12_HP_I1_POS)
  157. /**
  158. * @brief Control register 3 bitmasks.
  159. */
  160. // Bitmasks for I1_CLICK.
  161. #define LIS2DH12_I1_CLICK_POS 7
  162. #define LIS2DH12_I1_CLICK_MASK (1 << LIS2DH12_I1_CLICK_POS)
  163. // Bitmasks for I1_IA1.
  164. #define LIS2DH12_I1_IA1_POS 6
  165. #define LIS2DH12_I1_IA1_MASK (1 << LIS2DH12_I1_IA1_POS)
  166. // Bitmasks for I1_IA2.
  167. #define LIS2DH12_I1_IA2_POS 5
  168. #define LIS2DH12_I1_IA2_MASK (1 << LIS2DH12_I1_IA2_POS)
  169. // Bitmasks for I1_ZYXDA.
  170. #define LIS2DH12_I1_ZYXDA_POS 4
  171. #define LIS2DH12_I1_ZYXDA_MASK (1 << LIS2DH12_I1_ZYXDA_POS)
  172. // Bitmasks for I1_WTM.
  173. #define LIS2DH12_I1_WTM_POS 2
  174. #define LIS2DH12_I1_WTM_MASK (1 << LIS2DH12_I1_WTM_POS)
  175. // Bitmasks for I1_OVERRUN.
  176. #define LIS2DH12_I1_OVERRUN_POS 1
  177. #define LIS2DH12_I1_OVERRUN_MASK (1 << LIS2DH12_I1_OVERRUN_POS)
  178. /**
  179. * @brief Control register 4 bitmasks.
  180. */
  181. // Bitmasks for BDU.
  182. #define LIS2DH12_BDU_POS 7
  183. #define LIS2DH12_BDU_MASK (1 << LIS2DH12_BDU_POS)
  184. // Bitmasks for BLE.
  185. #define LIS2DH12_BLE_POS 6
  186. #define LIS2DH12_BLE_MASK (1 << LIS2DH12_BLE_POS)
  187. // Bitmasks for FS.
  188. #define LIS2DH12_FS_POS 4
  189. #define LIS2DH12_FS_MASK (3 << LIS2DH12_FS_POS)
  190. // Bitmasks for HR.
  191. #define LIS2DH12_HR_POS 3
  192. #define LIS2DH12_HR_MASK (1 << LIS2DH12_HR_POS)
  193. // Bitmasks for ST.
  194. #define LIS2DH12_ST_POS 1
  195. #define LIS2DH12_ST_MASK (3 << LIS2DH12_ST_POS)
  196. // Bitmasks for SIM.
  197. #define LIS2DH12_SIM_POS 0
  198. #define LIS2DH12_SIM_MASK (1 << LIS2DH12_SIM_POS)
  199. /**
  200. * @brief Control register 5 bitmasks.
  201. */
  202. // Bitmasks for BOOT.
  203. #define LIS2DH12_BOOT_POS 7
  204. #define LIS2DH12_BOOT_MASK (1 << LIS2DH12_BOOT_POS)
  205. // Bitmasks for FIFO_EN.
  206. #define LIS2DH12_FIFO_EN_POS 6
  207. #define LIS2DH12_FIFO_EN_MASK (1 << LIS2DH12_FIFO_EN_POS)
  208. // Bitmasks for LIR_INT1.
  209. #define LIS2DH12_LIR_INT1_POS 3
  210. #define LIS2DH12_LIR_INT1_MASK (1 << LIS2DH12_LIR_INT1_POS)
  211. // Bitmasks for D4D_INT1.
  212. #define LIS2DH12_D4D_INT1_POS 2
  213. #define LIS2DH12_D4D_INT1_MASK (1 << LIS2DH12_D4D_INT1_POS)
  214. // Bitmasks for LIR_INT2.
  215. #define LIS2DH12_LIR_INT2_POS 1
  216. #define LIS2DH12_LIR_INT2_MASK (1 << LIS2DH12_LIR_INT2_POS)
  217. // Bitmasks for D4D_INT2.
  218. #define LIS2DH12_D4D_INT2_POS 0
  219. #define LIS2DH12_D4D_INT2_MASK (1 << LIS2DH12_D4D_INT2_POS)
  220. /**
  221. * @brief Control register 6 bitmasks.
  222. */
  223. // Bitmasks for I2_CLICK.
  224. #define LIS2DH12_I2_CLICK_POS 7
  225. #define LIS2DH12_I2_CLICK_MASK (1 << LIS2DH12_I2_CLICK_POS)
  226. // Bitmasks for I2_IA1.
  227. #define LIS2DH12_I2_IA1_POS 6
  228. #define LIS2DH12_I2_IA1_MASK (1 << LIS2DH12_I2_IA1_POS)
  229. // Bitmasks for I2_IA2.
  230. #define LIS2DH12_I2_IA2_POS 5
  231. #define LIS2DH12_I2_IA2_MASK (1 << LIS2DH12_I2_IA2_POS)
  232. // Bitmasks for I2_BOOT.
  233. #define LIS2DH12_I2_BOOT_POS 4
  234. #define LIS2DH12_I2_BOOT_MASK (1 << LIS2DH12_I2_BOOT_POS)
  235. // Bitmasks for I2_ACT.
  236. #define LIS2DH12_I2_ACT_POS 3
  237. #define LIS2DH12_I2_ACT_MASK (1 << LIS2DH12_I2_ACT_POS)
  238. // Bitmasks for INT_POLARITY.
  239. #define LIS2DH12_INT_POLARITY_POS 1
  240. #define LIS2DH12_INT_POLARITY_MASK (1 << LIS2DH12_INT_POLARITY_POS)
  241. /**
  242. * @brief Status register bitmasks.
  243. */
  244. // Bitmasks for ZYXOR.
  245. #define LIS2DH12_ZYXOR_POS 7
  246. #define LIS2DH12_ZYXOR_MASK (1 << LIS2DH12_ZYXOR_POS)
  247. // Bitmasks for ZOR.
  248. #define LIS2DH12_ZOR_POS 6
  249. #define LIS2DH12_ZOR_MASK (1 << LIS2DH12_ZOR_POS)
  250. // Bitmasks for YOR.
  251. #define LIS2DH12_YOR_POS 5
  252. #define LIS2DH12_YOR_MASK (1 << LIS2DH12_YOR_POS)
  253. // Bitmasks for XOR.
  254. #define LIS2DH12_XOR_POS 4
  255. #define LIS2DH12_XOR_MASK (1 << LIS2DH12_XOR_POS)
  256. // Bitmasks for ZYXDA.
  257. #define LIS2DH12_ZYXDA_POS 3
  258. #define LIS2DH12_ZYXDA_MASK (1 << LIS2DH12_ZYXDA_POS)
  259. // Bitmasks for ZDA.
  260. #define LIS2DH12_ZDA_POS 2
  261. #define LIS2DH12_ZDA_MASK (1 << LIS2DH12_ZDA_POS)
  262. // Bitmasks for YDA.
  263. #define LIS2DH12_YDA_POS 1
  264. #define LIS2DH12_YDA_MASK (1 << LIS2DH12_YDA_POS)
  265. // Bitmasks for XDA.
  266. #define LIS2DH12_XDA_POS 0
  267. #define LIS2DH12_XDA_MASK (1 << LIS2DH12_XDA_POS)
  268. /**
  269. * @brief FIFO control register bitmasks.
  270. */
  271. // Bitmasks for FM.
  272. #define LIS2DH12_FM_POS 6
  273. #define LIS2DH12_FM_MASK (3 << LIS2DH12_FM_POS)
  274. // Bitmasks for TR.
  275. #define LIS2DH12_TR_POS 5
  276. #define LIS2DH12_TR_MASK (1 << LIS2DH12_TR_POS)
  277. // Bitmasks for FTH.
  278. #define LIS2DH12_FTH_POS 0
  279. #define LIS2DH12_FTH_MASK (0x1F << LIS2DH12_FTH_POS)
  280. /**
  281. * @brief FIFO source register bitmasks.
  282. */
  283. // Bitmasks for WTM.
  284. #define LIS2DH12_WTM_POS 7
  285. #define LIS2DH12_WTM_MASK (1 << LIS2DH12_WTM_POS)
  286. // Bitmasks for OVRN_FIFO.
  287. #define LIS2DH12_OVRN_FIFO_POS 6
  288. #define LIS2DH12_OVRN_FIFO_MASK (1 << LIS2DH12_OVRN_FIFO_POS)
  289. // Bitmasks for EMPTY.
  290. #define LIS2DH12_EMPTY_POS 5
  291. #define LIS2DH12_EMPTY_MASK (1 << LIS2DH12_EMPTY_POS)
  292. // Bitmasks for FSS.
  293. #define LIS2DH12_FSS_POS 0
  294. #define LIS2DH12_FSS_MASK (0x1F << LIS2DH12_FSS_POS)
  295. /**
  296. * @brief Interrupt config register bitmasks.
  297. */
  298. // Bitmasks for INT_AOI.
  299. #define LIS2DH12_INT_AOI_POS 7
  300. #define LIS2DH12_INT_AOI_MASK (1 << LIS2DH12_INT_AOI_POS)
  301. // Bitmasks for INT_6D.
  302. #define LIS2DH12_INT_6D_POS 6
  303. #define LIS2DH12_INT_6D_MASK (1 << LIS2DH12_INT_6D_POS)
  304. // Bitmasks for INT_ZHIE.
  305. #define LIS2DH12_INT_ZHIE_POS 5
  306. #define LIS2DH12_INT_ZHIE_MASK (1 << LIS2DH12_INT_ZHIE_POS)
  307. // Bitmasks for INT_ZLIE.
  308. #define LIS2DH12_INT_ZLIE_POS 4
  309. #define LIS2DH12_INT_ZLIE_MASK (1 << LIS2DH12_INT_ZLIE_POS)
  310. // Bitmasks for INT_YHIE.
  311. #define LIS2DH12_INT_YHIE_POS 3
  312. #define LIS2DH12_INT_YHIE_MASK (1 << LIS2DH12_INT_YHIE_POS)
  313. // Bitmasks for INT_YLIE.
  314. #define LIS2DH12_INT_YLIE_POS 2
  315. #define LIS2DH12_INT_YLIE_MASK (1 << LIS2DH12_INT_YLIE_POS)
  316. // Bitmasks for INT_XHIE.
  317. #define LIS2DH12_INT_XHIE_POS 1
  318. #define LIS2DH12_INT_XHIE_MASK (1 << LIS2DH12_INT_XHIE_POS)
  319. // Bitmasks for INT_XLIE.
  320. #define LIS2DH12_INT_XLIE_POS 0
  321. #define LIS2DH12_INT_XLIE_MASK (1 << LIS2DH12_INT_XLIE_POS)
  322. /**
  323. * @brief Interrupt source register bitmasks.
  324. */
  325. // Bitmasks for IA.
  326. #define LIS2DH12_INT_IA_POS 6
  327. #define LIS2DH12_INT_IA_MASK (1 << LIS2DH12_INT_IA_POS)
  328. // Bitmasks for ZH.
  329. #define LIS2DH12_INT_ZH_POS 5
  330. #define LIS2DH12_INT_ZH_MASK (1 << LIS2DH12_INT_ZH_POS)
  331. // Bitmasks for ZL.
  332. #define LIS2DH12_INT_ZL_POS 4
  333. #define LIS2DH12_INT_ZL_MASK (1 << LIS2DH12_INT_ZL_POS)
  334. // Bitmasks for YH.
  335. #define LIS2DH12_INT_YH_POS 3
  336. #define LIS2DH12_INT_YH_MASK (1 << LIS2DH12_INT_YH_POS)
  337. // Bitmasks for YL.
  338. #define LIS2DH12_INT_YL_POS 2
  339. #define LIS2DH12_INT_YL_MASK (1 << LIS2DH12_INT_YL_POS)
  340. // Bitmasks for XH.
  341. #define LIS2DH12_INT_XH_POS 1
  342. #define LIS2DH12_INT_XH_MASK (1 << LIS2DH12_INT_XH_POS)
  343. // Bitmasks for XL.
  344. #define LIS2DH12_INT_XL_POS 0
  345. #define LIS2DH12_INT_XL_MASK (1 << LIS2DH12_INT_XL_POS)
  346. /**
  347. * @brief Interrupt threshold register bitmasks.
  348. */
  349. // Bitmasks for THS.
  350. #define LIS2DH12_INT_THS_POS 0
  351. #define LIS2DH12_INT_THS_MASK (0x7F << LIS2DH12_INT_THS_POS)
  352. /**
  353. * @brief Interrupt duration register bitmasks.
  354. */
  355. // Bitmasks for DUR.
  356. #define LIS2DH12_INT_DUR_POS 0
  357. #define LIS2DH12_INT_DUR_MASK (0x7F << LIS2DH12_INT_DUR_POS)
  358. /**
  359. * @brief Click config register bitmasks.
  360. */
  361. // Bitmasks for ZD.
  362. #define LIS2DH12_CLICK_ZD_POS 5
  363. #define LIS2DH12_CLICK_ZD_MASK (1 << LIS2DH12_CLICK_ZD_POS)
  364. // Bitmasks for ZS.
  365. #define LIS2DH12_CLICK_ZS_POS 4
  366. #define LIS2DH12_CLICK_ZS_MASK (1 << LIS2DH12_CLICK_ZS_POS)
  367. // Bitmasks for YD.
  368. #define LIS2DH12_CLICK_YD_POS 3
  369. #define LIS2DH12_CLICK_YD_MASK (1 << LIS2DH12_CLICK_YD_POS)
  370. // Bitmasks for YS.
  371. #define LIS2DH12_CLICK_YS_POS 2
  372. #define LIS2DH12_CLICK_YS_MASK (1 << LIS2DH12_CLICK_YS_POS)
  373. // Bitmasks for XD.
  374. #define LIS2DH12_CLICK_XD_POS 1
  375. #define LIS2DH12_CLICK_XD_MASK (1 << LIS2DH12_CLICK_XD_POS)
  376. // Bitmasks for XS.
  377. #define LIS2DH12_CLICK_XS_POS 0
  378. #define LIS2DH12_CLICK_XS_MASK (1 << LIS2DH12_CLICK_XS_POS)
  379. /**
  380. * @brief Click source register bitmasks.
  381. */
  382. // Bitmasks for IA.
  383. #define LIS2DH12_CLICK_IA_POS 6
  384. #define LIS2DH12_CLICK_IA_MASK (1 << LIS2DH12_CLICK_IA_POS)
  385. // Bitmasks for DCLICK.
  386. #define LIS2DH12_CLICK_DCLICK_POS 5
  387. #define LIS2DH12_CLICK_DCLICK_MASK (1 << LIS2DH12_CLICK_DCLICK_POS)
  388. // Bitmasks for SCLICK.
  389. #define LIS2DH12_CLICK_SCLICK_POS 4
  390. #define LIS2DH12_CLICK_SCLICK_MASK (1 << LIS2DH12_CLICK_SCLICK_POS)
  391. // Bitmasks for SIGN.
  392. #define LIS2DH12_CLICK_SIGN_POS 3
  393. #define LIS2DH12_CLICK_SIGN_MASK (1 << LIS2DH12_CLICK_SIGN_POS)
  394. // Bitmasks for Z.
  395. #define LIS2DH12_CLICK_Z_POS 2
  396. #define LIS2DH12_CLICK_Z_MASK (1 << LIS2DH12_CLICK_Z_POS)
  397. // Bitmasks for Y.
  398. #define LIS2DH12_CLICK_Y_POS 1
  399. #define LIS2DH12_CLICK_Y_MASK (1 << LIS2DH12_CLICK_Y_POS)
  400. // Bitmasks for X.
  401. #define LIS2DH12_CLICK_X_POS 0
  402. #define LIS2DH12_CLICK_X_MASK (1 << LIS2DH12_CLICK_X_POS)
  403. /**
  404. * @brief Click threshold register bitmasks.
  405. */
  406. // Bitmasks for LIR.
  407. #define LIS2DH12_CLICK_LIR_POS 7
  408. #define LIS2DH12_CLICK_LIR_MASK (1 << LIS2DH12_CLICK_LIR_POS)
  409. // Bitmasks for THS.
  410. #define LIS2DH12_CLICK_THS_POS 0
  411. #define LIS2DH12_CLICK_THS_MASK (0x7F << LIS2DH12_CLICK_THS_POS)
  412. /**
  413. * @brief Click time limit register bitmasks.
  414. */
  415. // Bitmasks for TLI.
  416. #define LIS2DH12_CLICK_TLI_POS 0
  417. #define LIS2DH12_CLICK_TLI_MASK (0x7F << LIS2DH12_CLICK_TLI_POS)
  418. /**
  419. * @brief Activation threshold register bitmasks.
  420. */
  421. // Bitmasks for THS.
  422. #define LIS2DH12_ACT_THS_POS 0
  423. #define LIS2DH12_ACT_THS_MASK (0x7F << LIS2DH12_ACT_THS_POS)
  424. /**
  425. * @brief Structure holding sensor instance
  426. */
  427. typedef struct
  428. {
  429. nrf_twi_sensor_t * const p_sensor_data;
  430. uint8_t const sensor_addr;
  431. uint8_t ctrl0;
  432. uint8_t temp_cfg;
  433. uint8_t ctrl1;
  434. uint8_t ctrl2;
  435. uint8_t ctrl3;
  436. uint8_t ctrl4;
  437. uint8_t ctrl5;
  438. uint8_t ctrl6;
  439. uint8_t reference;
  440. uint8_t fifo_ctrl;
  441. uint8_t int1_cfg;
  442. uint8_t int1_ths;
  443. uint8_t int1_dur;
  444. uint8_t int2_cfg;
  445. uint8_t int2_ths;
  446. uint8_t int2_dur;
  447. uint8_t click_cfg;
  448. uint8_t click_ths;
  449. uint8_t time_lim;
  450. uint8_t latency;
  451. uint8_t time_win;
  452. uint8_t act_ths;
  453. uint8_t act_dur;
  454. } lis2dh12_instance_t;
  455. /**
  456. * @brief Macro for defining sensor instance.
  457. */
  458. #define LIS2DH12_INTERNAL_INSTANCE_DEF(_lis2dh12_inst_name, _p_twi_sensor, _sensor_address) \
  459. static lis2dh12_instance_t _lis2dh12_inst_name = \
  460. { \
  461. .p_sensor_data = _p_twi_sensor, \
  462. .sensor_addr = _sensor_address \
  463. }
  464. /**
  465. * @brief Macro for setting data acquisition configuration.
  466. */
  467. #define LIS2DH12_INTERNAL_DATA_CFG(_s, _odr, _lp, _z_en, _y_en, _x_en, _scale, _high_res) \
  468. NRF_TWI_SENSOR_REG_SET(_s.ctrl1, LIS2DH12_ODR_MASK, LIS2DH12_ODR_POS, _odr); \
  469. NRF_TWI_SENSOR_REG_SET(_s.ctrl1, LIS2DH12_LP_EN_MASK, LIS2DH12_LP_EN_POS, _lp); \
  470. NRF_TWI_SENSOR_REG_SET(_s.ctrl1, LIS2DH12_Z_EN_MASK, LIS2DH12_Z_EN_POS, _z_en); \
  471. NRF_TWI_SENSOR_REG_SET(_s.ctrl1, LIS2DH12_Y_EN_MASK, LIS2DH12_Y_EN_POS, _y_en); \
  472. NRF_TWI_SENSOR_REG_SET(_s.ctrl1, LIS2DH12_X_EN_MASK, LIS2DH12_X_EN_POS, _x_en); \
  473. NRF_TWI_SENSOR_REG_SET(_s.ctrl4, LIS2DH12_FS_MASK, LIS2DH12_FS_POS, _scale); \
  474. NRF_TWI_SENSOR_REG_SET(_s.ctrl4, LIS2DH12_HR_MASK, LIS2DH12_HR_POS, _high_res)
  475. /**
  476. * @brief Function for setting filter configuration.
  477. */
  478. #define LIS2DH12_INTERNAL_FILTER_CFG(_s, _mode, _freq, _d_en, _c_en, _i1_en, _i2_en) \
  479. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_HPM_MASK, LIS2DH12_HPM_POS, _mode); \
  480. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_HPCF_MASK, LIS2DH12_HPCF_POS, _freq); \
  481. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_FDS_MASK, LIS2DH12_FDS_POS, _d_en); \
  482. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_HP_C_MASK, LIS2DH12_HP_C_POS, _c_en); \
  483. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_HP_I1_MASK, LIS2DH12_HP_I1_POS, _i1_en); \
  484. NRF_TWI_SENSOR_REG_SET(_s.ctrl2, LIS2DH12_HP_I2_MASK, LIS2DH12_HP_I2_POS, _i2_en)
  485. /**
  486. * @brief Macro for configuring INT1 pin.
  487. */
  488. #define LIS2DH12_INTERNAL_INT1_PIN_CFG(_s, _cl, _ia1, _ia2, _zyxda, _wtm, _ovr, _pol, _d4d) \
  489. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_CLICK_MASK, LIS2DH12_I1_CLICK_POS, _cl); \
  490. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_IA1_MASK, LIS2DH12_I1_IA1_POS, _ia1); \
  491. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_IA2_MASK, LIS2DH12_I1_IA2_POS, _ia2); \
  492. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_ZYXDA_MASK, LIS2DH12_I1_ZYXDA_POS, _zyxda); \
  493. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_WTM_MASK, LIS2DH12_I1_WTM_POS, _wtm); \
  494. NRF_TWI_SENSOR_REG_SET(_s.ctrl3, LIS2DH12_I1_OVERRUN_MASK, LIS2DH12_I1_OVERRUN_POS, _ovr); \
  495. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_INT_POLARITY_MASK, LIS2DH12_INT_POLARITY_POS, _pol); \
  496. NRF_TWI_SENSOR_REG_SET(_s.ctrl5, LIS2DH12_D4D_INT1_MASK, LIS2DH12_D4D_INT1_POS, _d4d)
  497. /**
  498. * @brief Macro for configuring INT2 pin.
  499. */
  500. #define LIS2DH12_INTERNAL_INT2_PIN_CFG(_s, _cl, _ia1, _ia2, _boot, _act, _pol, _d4d) \
  501. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_I2_CLICK_MASK, LIS2DH12_I2_CLICK_POS, _cl); \
  502. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_I2_IA1_MASK, LIS2DH12_I2_IA1_POS, _ia1); \
  503. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_I2_IA2_MASK, LIS2DH12_I2_IA2_POS, _ia2); \
  504. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_I2_BOOT_MASK, LIS2DH12_I2_BOOT_POS, _boot);\
  505. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_I2_ACT_MASK, LIS2DH12_I2_ACT_POS, _act); \
  506. NRF_TWI_SENSOR_REG_SET(_s.ctrl6, LIS2DH12_INT_POLARITY_MASK, LIS2DH12_INT_POLARITY_POS, _pol); \
  507. NRF_TWI_SENSOR_REG_SET(_s.ctrl5, LIS2DH12_D4D_INT2_MASK, LIS2DH12_D4D_INT2_POS, _d4d)
  508. /**
  509. * @brief Macro for configuring interrupt 1.
  510. */
  511. #define LIS2DH12_INTERNAL_INT1_CFG(_s, _thr, _dur, _aoi, _6d, _zh, _zl, _yh, yl, _xh, _xl, _lir) \
  512. NRF_TWI_SENSOR_REG_SET(_s.int1_ths, LIS2DH12_INT_THS_MASK, LIS2DH12_INT_THS_POS, _thr); \
  513. NRF_TWI_SENSOR_REG_SET(_s.int1_dur, LIS2DH12_INT_DUR_MASK, LIS2DH12_INT_DUR_POS, _dur); \
  514. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_AOI_MASK, LIS2DH12_INT_AOI_POS, _aoi); \
  515. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_6D_MASK, LIS2DH12_INT_6D_POS, _6d); \
  516. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_ZHIE_MASK, LIS2DH12_INT_ZHIE_POS, _zh); \
  517. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_ZLIE_MASK, LIS2DH12_INT_ZLIE_POS, _zl); \
  518. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_YHIE_MASK, LIS2DH12_INT_YHIE_POS, _yh); \
  519. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_YLIE_MASK, LIS2DH12_INT_YLIE_POS, _yl); \
  520. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_XHIE_MASK, LIS2DH12_INT_XHIE_POS, _xh); \
  521. NRF_TWI_SENSOR_REG_SET(_s.int1_cfg, LIS2DH12_INT_XLIE_MASK, LIS2DH12_INT_XLIE_POS, _xl); \
  522. NRF_TWI_SENSOR_REG_SET(_s.ctrl5, LIS2DH12_LIR_INT1_MASK, LIS2DH12_LIR_INT1_POS, _lir)
  523. /**
  524. * @brief Macro for configuring interrupt 2.
  525. */
  526. #define LIS2DH12_INTERNAL_INT2_CFG(_s, _thr, _dur, _aoi, _6d, _zh, _zl, _yh, yl, _xh, _xl, _lir) \
  527. NRF_TWI_SENSOR_REG_SET(_s.int2_ths, LIS2DH12_INT_THS_MASK, LIS2DH12_INT_THS_POS, _thr); \
  528. NRF_TWI_SENSOR_REG_SET(_s.int2_dur, LIS2DH12_INT_DUR_MASK, LIS2DH12_INT_DUR_POS, _dur); \
  529. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_AOI_MASK, LIS2DH12_INT_AOI_POS, _aoi); \
  530. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_6D_MASK, LIS2DH12_INT_6D_POS, _6d); \
  531. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_ZHIE_MASK, LIS2DH12_INT_ZHIE_POS, _zh); \
  532. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_ZLIE_MASK, LIS2DH12_INT_ZLIE_POS, _zl); \
  533. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_YHIE_MASK, LIS2DH12_INT_YHIE_POS, _yh); \
  534. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_YLIE_MASK, LIS2DH12_INT_YLIE_POS, _yl); \
  535. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_XHIE_MASK, LIS2DH12_INT_XHIE_POS, _xh); \
  536. NRF_TWI_SENSOR_REG_SET(_s.int2_cfg, LIS2DH12_INT_XLIE_MASK, LIS2DH12_INT_XLIE_POS, _xl); \
  537. NRF_TWI_SENSOR_REG_SET(_s.ctrl5, LIS2DH12_LIR_INT2_MASK, LIS2DH12_LIR_INT2_POS, _lir)
  538. /**
  539. * @brief Function for setting click configuration.
  540. */
  541. #define LIS2DH12_INTERNAL_CLICK_CFG(_s, _zd, _zs, _yd, _ys, _xd, _xs, _lir, _ths, _lim, _ltc, _win) \
  542. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_ZD_MASK, LIS2DH12_CLICK_ZD_POS, _zd); \
  543. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_ZS_MASK, LIS2DH12_CLICK_ZD_POS, _zd); \
  544. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_YD_MASK, LIS2DH12_CLICK_YD_POS, _yd); \
  545. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_YS_MASK, LIS2DH12_CLICK_YS_POS, _ys); \
  546. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_XD_MASK, LIS2DH12_CLICK_XD_POS, _xd); \
  547. NRF_TWI_SENSOR_REG_SET(_s.click_cfg, LIS2DH12_CLICK_XS_MASK, LIS2DH12_CLICK_XS_POS, _xs); \
  548. NRF_TWI_SENSOR_REG_SET(_s.click_ths, LIS2DH12_CLICK_LIR_MASK, LIS2DH12_CLICK_LIR_POS, _lir); \
  549. NRF_TWI_SENSOR_REG_SET(_s.click_ths, LIS2DH12_CLICK_THS_MASK, LIS2DH12_CLICK_THS_POS, _ths); \
  550. NRF_TWI_SENSOR_REG_SET(_s.time_lim, LIS2DH12_CLICK_TLI_MASK, LIS2DH12_CLICK_TLI_POS, _lim); \
  551. _s.latency = _ltc; \
  552. _s.time_win = _win
  553. /**
  554. * @brief Macro for setting sleep configuration.
  555. */
  556. #define LIS2DH12_INTERNAL_SLEEP_CFG(_s, _ths, _dur) \
  557. NRF_TWI_SENSOR_REG_SET(_s.act_ths, LIS2DH12_ACT_THS_MASK, LIS2DH12_ACT_THS_POS, _ths); \
  558. _s.act_dur = _dur
  559. /**
  560. * @brief Macro for setting reference value for interrupt generation.
  561. */
  562. #define LIS2DH12_INTERNAL_REF_SET(_s, _ref) \
  563. _s.reference = _ref
  564. /**
  565. * @brief Macro for setting FIFO configuration.
  566. */
  567. #define LIS2DH12_INTERNAL_FIFO_CFG(_s, _en, _mode, _t_sel, _t_thr) \
  568. NRF_TWI_SENSOR_REG_SET(_s.fifo_ctrl, LIS2DH12_FM_MASK, LIS2DH12_FM_POS, _mode); \
  569. NRF_TWI_SENSOR_REG_SET(_s.fifo_ctrl, LIS2DH12_TR_MASK, LIS2DH12_TR_POS, _t_sel); \
  570. NRF_TWI_SENSOR_REG_SET(_s.fifo_ctrl, LIS2DH12_FTH_MASK, LIS2DH12_FTH_POS, _t_thr); \
  571. NRF_TWI_SENSOR_REG_SET(_s.ctrl5, LIS2DH12_FIFO_EN_MASK, LIS2DH12_FIFO_EN_POS, _en)
  572. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  573. __STATIC_INLINE ret_code_t lis2dh12_temp_status_read(lis2dh12_instance_t * p_inst,
  574. nrf_twi_sensor_reg_cb_t user_cb,
  575. uint8_t * p_data)
  576. {
  577. ASSERT(p_inst != NULL);
  578. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  579. p_inst->sensor_addr,
  580. LIS2DH12_REG_STATUS_AUX,
  581. user_cb,
  582. p_data,
  583. 1);
  584. }
  585. __STATIC_INLINE ret_code_t lis2dh12_who_am_i_read(lis2dh12_instance_t * p_inst,
  586. nrf_twi_sensor_reg_cb_t user_cb,
  587. uint8_t * p_data)
  588. {
  589. ASSERT(p_inst != NULL);
  590. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  591. p_inst->sensor_addr,
  592. LIS2DH12_REG_WHO_AM_I,
  593. user_cb,
  594. p_data,
  595. 1);
  596. }
  597. __STATIC_INLINE ret_code_t lis2dh12_status_read(lis2dh12_instance_t * p_inst,
  598. nrf_twi_sensor_reg_cb_t user_cb,
  599. uint8_t * p_data)
  600. {
  601. ASSERT(p_inst != NULL);
  602. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  603. p_inst->sensor_addr,
  604. LIS2DH12_REG_STATUS,
  605. user_cb,
  606. p_data,
  607. 1);
  608. }
  609. __STATIC_INLINE ret_code_t lis2dh12_fifo_src_read(lis2dh12_instance_t * p_inst,
  610. nrf_twi_sensor_reg_cb_t user_cb,
  611. uint8_t * p_data)
  612. {
  613. ASSERT(p_inst != NULL);
  614. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  615. p_inst->sensor_addr,
  616. LIS2DH12_REG_FIFO_SRC,
  617. user_cb,
  618. p_data,
  619. 1);
  620. }
  621. __STATIC_INLINE ret_code_t lis2dh12_int1_src_read(lis2dh12_instance_t * p_inst,
  622. nrf_twi_sensor_reg_cb_t user_cb,
  623. uint8_t * p_data)
  624. {
  625. ASSERT(p_inst != NULL);
  626. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  627. p_inst->sensor_addr,
  628. LIS2DH12_REG_INT1_SRC,
  629. user_cb,
  630. p_data,
  631. 1);
  632. }
  633. __STATIC_INLINE ret_code_t lis2dh12_int2_src_read(lis2dh12_instance_t * p_inst,
  634. nrf_twi_sensor_reg_cb_t user_cb,
  635. uint8_t * p_data)
  636. {
  637. ASSERT(p_inst != NULL);
  638. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  639. p_inst->sensor_addr,
  640. LIS2DH12_REG_INT2_SRC,
  641. user_cb,
  642. p_data,
  643. 1);
  644. }
  645. __STATIC_INLINE ret_code_t lis2dh12_click_src_read(lis2dh12_instance_t * p_inst,
  646. nrf_twi_sensor_reg_cb_t user_cb,
  647. uint8_t * p_data)
  648. {
  649. ASSERT(p_inst != NULL);
  650. return nrf_twi_sensor_reg_read(p_inst->p_sensor_data,
  651. p_inst->sensor_addr,
  652. LIS2DH12_REG_CLICK_SRC,
  653. user_cb,
  654. p_data,
  655. 1);
  656. }
  657. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  658. #ifdef __cplusplus
  659. }
  660. #endif
  661. #endif // LIS2DH12_INTERNAL_H