lsm6dsl.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /*
  2. ChibiOS - Copyright (C) 2016..2018 Rocco Marco Guglielmi
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file lsm6dsl.h
  17. * @brief LSM6DSL MEMS interface module header.
  18. *
  19. * @addtogroup LSM6DSL
  20. * @ingroup EX_ST
  21. * @{
  22. */
  23. #ifndef _LSM6DSL_H_
  24. #define _LSM6DSL_H_
  25. #include "hal_accelerometer.h"
  26. #include "hal_gyroscope.h"
  27. /*===========================================================================*/
  28. /* Driver constants. */
  29. /*===========================================================================*/
  30. /**
  31. * @name Version identification
  32. * @{
  33. */
  34. /**
  35. * @brief LSM6DSL driver version string.
  36. */
  37. #define EX_LSM6DSL_VERSION "1.0.1"
  38. /**
  39. * @brief LSM6DSL driver version major number.
  40. */
  41. #define EX_LSM6DSL_MAJOR 1
  42. /**
  43. * @brief LSM6DSL driver version minor number.
  44. */
  45. #define EX_LSM6DSL_MINOR 0
  46. /**
  47. * @brief LSM6DSL driver version patch number.
  48. */
  49. #define EX_LSM6DSL_PATCH 1
  50. /** @} */
  51. /**
  52. * @brief LSM6DSL accelerometer subsystem characteristics.
  53. * @note Sensitivity is expressed as milli-G/LSB whereas
  54. * 1 milli-G = 0.00980665 m/s^2.
  55. * @note Bias is expressed as milli-G.
  56. *
  57. * @{
  58. */
  59. #define LSM6DSL_ACC_NUMBER_OF_AXES 3U
  60. #define LSM6DSL_ACC_2G 2.0f
  61. #define LSM6DSL_ACC_4G 4.0f
  62. #define LSM6DSL_ACC_8G 8.0f
  63. #define LSM6DSL_ACC_16G 16.0f
  64. #define LSM6DSL_ACC_SENS_2G 0.061f
  65. #define LSM6DSL_ACC_SENS_4G 0.122f
  66. #define LSM6DSL_ACC_SENS_8G 0.244f
  67. #define LSM6DSL_ACC_SENS_16G 0.488f
  68. #define LSM6DSL_ACC_BIAS 0.0f
  69. /** @} */
  70. /**
  71. * @brief L3GD20 gyroscope system characteristics.
  72. * @note Sensitivity is expressed as DPS/LSB whereas DPS stand for Degree
  73. * per second [°/s].
  74. * @note Bias is expressed as DPS.
  75. *
  76. * @{
  77. */
  78. #define LSM6DSL_GYRO_NUMBER_OF_AXES 3U
  79. #define LSM6DSL_GYRO_125DPS 125.0f
  80. #define LSM6DSL_GYRO_250DPS 250.0f
  81. #define LSM6DSL_GYRO_500DPS 500.0f
  82. #define LSM6DSL_GYRO_1000DPS 1000.0f
  83. #define LSM6DSL_GYRO_2000DPS 2000.0f
  84. #define LSM6DSL_GYRO_SENS_125DPS 0.004375f
  85. #define LSM6DSL_GYRO_SENS_250DPS 0.008750f
  86. #define LSM6DSL_GYRO_SENS_500DPS 0.017500f
  87. #define LSM6DSL_GYRO_SENS_1000DPS 0.035000f
  88. #define LSM6DSL_GYRO_SENS_2000DPS 0.070000f
  89. #define LSM6DSL_GYRO_BIAS 0.0f
  90. /** @} */
  91. /**
  92. * @name LSM6DSL communication interfaces related bit masks
  93. * @{
  94. */
  95. #define LSM6DSL_DI_MASK 0xFF
  96. #define LSM6DSL_DI(n) (1 << n)
  97. #define LSM6DSL_AD_MASK 0x7F
  98. #define LSM6DSL_AD(n) (1 << n)
  99. #define LSM6DSL_MS (1 << 7)
  100. /** @} */
  101. /**
  102. * @name LSM6DSL register addresses
  103. * @{
  104. */
  105. #define LSM6DSL_AD_FUNC_CFG_ACCESS 0x01
  106. #define LSM6DSL_AD_SENSOR_SYNC_TIME_FRAME 0x04
  107. #define LSM6DSL_AD_SENSOR_SYNC_RES_RATIO 0x05
  108. #define LSM6DSL_AD_FIFO_CTRL1 0x06
  109. #define LSM6DSL_AD_FIFO_CTRL2 0x07
  110. #define LSM6DSL_AD_FIFO_CTRL3 0x08
  111. #define LSM6DSL_AD_FIFO_CTRL4 0x09
  112. #define LSM6DSL_AD_FIFO_CTRL5 0x0A
  113. #define LSM6DSL_AD_DRDY_PULSE_CFG_G 0x0B
  114. #define LSM6DSL_AD_INT1_CTRL 0x0D
  115. #define LSM6DSL_AD_INT2_CTRL 0x0E
  116. #define LSM6DSL_AD_WHO_AM_I 0x0F
  117. #define LSM6DSL_AD_CTRL1_XL 0x10
  118. #define LSM6DSL_AD_CTRL2_G 0x11
  119. #define LSM6DSL_AD_CTRL3_C 0x12
  120. #define LSM6DSL_AD_CTRL4_C 0x13
  121. #define LSM6DSL_AD_CTRL5_C 0x14
  122. #define LSM6DSL_AD_CTRL6_C 0x15
  123. #define LSM6DSL_AD_CTRL7_G 0x16
  124. #define LSM6DSL_AD_CTRL8_XL 0x17
  125. #define LSM6DSL_AD_CTRL9_XL 0x18
  126. #define LSM6DSL_AD_CTRL10_C 0x19
  127. #define LSM6DSL_AD_MASTER_CONFIG 0x1A
  128. #define LSM6DSL_AD_WAKE_UP_SRC 0x1B
  129. #define LSM6DSL_AD_TAP_SRC 0x1C
  130. #define LSM6DSL_AD_D6D_SRC 0x1D
  131. #define LSM6DSL_AD_STATUS_REG 0x1E
  132. #define LSM6DSL_AD_OUT_TEMP_L 0x20
  133. #define LSM6DSL_AD_OUT_TEMP_H 0x21
  134. #define LSM6DSL_AD_OUTX_L_G 0x22
  135. #define LSM6DSL_AD_OUTX_H_G 0x23
  136. #define LSM6DSL_AD_OUTY_L_G 0x24
  137. #define LSM6DSL_AD_OUTY_H_G 0x25
  138. #define LSM6DSL_AD_OUTZ_L_G 0x26
  139. #define LSM6DSL_AD_OUTZ_H_G 0x27
  140. #define LSM6DSL_AD_OUTX_L_XL 0x28
  141. #define LSM6DSL_AD_OUTX_H_XL 0x29
  142. #define LSM6DSL_AD_OUTY_L_XL 0x2A
  143. #define LSM6DSL_AD_OUTY_H_XL 0x2B
  144. #define LSM6DSL_AD_OUTZ_L_XL 0x2C
  145. #define LSM6DSL_AD_OUTZ_H_XL 0x2D
  146. #define LSM6DSL_AD_SENSORHUB1_REG 0x2E
  147. #define LSM6DSL_AD_SENSORHUB2_REG 0x2F
  148. #define LSM6DSL_AD_SENSORHUB3_REG 0x30
  149. #define LSM6DSL_AD_SENSORHUB4_REG 0x31
  150. #define LSM6DSL_AD_SENSORHUB5_REG 0x32
  151. #define LSM6DSL_AD_SENSORHUB6_REG 0x33
  152. #define LSM6DSL_AD_SENSORHUB7_REG 0x34
  153. #define LSM6DSL_AD_SENSORHUB8_REG 0x35
  154. #define LSM6DSL_AD_SENSORHUB9_REG 0x36
  155. #define LSM6DSL_AD_SENSORHUB10_REG 0x37
  156. #define LSM6DSL_AD_SENSORHUB11_REG 0x38
  157. #define LSM6DSL_AD_SENSORHUB12_REG 0x39
  158. #define LSM6DSL_AD_FIFO_STATUS1 0x3A
  159. #define LSM6DSL_AD_FIFO_STATUS2 0x3B
  160. #define LSM6DSL_AD_FIFO_STATUS3 0x3C
  161. #define LSM6DSL_AD_FIFO_STATUS4 0x3D
  162. #define LSM6DSL_AD_FIFO_DATA_OUT_L 0x3E
  163. #define LSM6DSL_AD_FIFO_DATA_OUT_H 0x3F
  164. #define LSM6DSL_AD_TIMESTAMP0_REG 0x40
  165. #define LSM6DSL_AD_TIMESTAMP1_REG 0x41
  166. #define LSM6DSL_AD_TIMESTAMP2_REG 0x42
  167. #define LSM6DSL_AD_STEP_TIMESTAMP_L 0x49
  168. #define LSM6DSL_AD_STEP_TIMESTAMP_H 0x4A
  169. #define LSM6DSL_AD_STEP_COUNTER_L 0x4B
  170. #define LSM6DSL_AD_STEP_COUNTER_H 0x4C
  171. #define LSM6DSL_AD_SENSORHUB13_REG 0x4D
  172. #define LSM6DSL_AD_SENSORHUB14_REG 0x4E
  173. #define LSM6DSL_AD_SENSORHUB15_REG 0x4F
  174. #define LSM6DSL_AD_SENSORHUB16_REG 0x50
  175. #define LSM6DSL_AD_SENSORHUB17_REG 0x51
  176. #define LSM6DSL_AD_SENSORHUB18_REG 0x52
  177. #define LSM6DSL_AD_FUNC_SRC1 0x53
  178. #define LSM6DSL_AD_FUNC_SRC2 0x54
  179. #define LSM6DSL_AD_WRIST_TILT_IA 0x55
  180. #define LSM6DSL_AD_TAP_CFG 0x58
  181. #define LSM6DSL_AD_TAP_THS_6D 0x59
  182. #define LSM6DSL_AD_INT_DUR2 0x5A
  183. #define LSM6DSL_AD_WAKE_UP_THS 0x5B
  184. #define LSM6DSL_AD_WAKE_UP_DUR 0x5C
  185. #define LSM6DSL_AD_FREE_FALL 0x5D
  186. #define LSM6DSL_AD_MD1_CFG 0x5E
  187. #define LSM6DSL_AD_MD2_CFG 0x5F
  188. #define LSM6DSL_AD_MASTER_CMD_CODE 0x60
  189. #define LSM6DSL_AD_SENS_SYNC_SPI_ERROR_CODE 0x61
  190. #define LSM6DSL_AD_OUT_MAG_RAW_X_L 0x66
  191. #define LSM6DSL_AD_OUT_MAG_RAW_X_H 0x67
  192. #define LSM6DSL_AD_OUT_MAG_RAW_Y_L 0x68
  193. #define LSM6DSL_AD_OUT_MAG_RAW_Y_H 0x69
  194. #define LSM6DSL_AD_OUT_MAG_RAW_Z_L 0x6A
  195. #define LSM6DSL_AD_OUT_MAG_RAW_Z_H 0x6B
  196. #define LSM6DSL_AD_X_OFS_USR 0x73
  197. #define LSM6DSL_AD_Y_OFS_USR 0x74
  198. #define LSM6DSL_AD_Z_OFS_USR 0x75
  199. /** @} */
  200. /**
  201. * @name LSM6DSL_AD_CTRL1_XL register bits definitions
  202. * @{
  203. */
  204. #define LSMDSL_CTRL1_XL_BW0_XL (1 << 0)
  205. #define LSMDSL_CTRL1_XL_LPF1_BW_SEL (1 << 1)
  206. #define LSMDSL_CTRL1_XL_FS_MASK 0x0C
  207. #define LSMDSL_CTRL1_XL_FS_XL0 (1 << 2)
  208. #define LSMDSL_CTRL1_XL_FS_XL1 (1 << 3)
  209. #define LSMDSL_CTRL1_XL_ODR_XL0 (1 << 4)
  210. #define LSMDSL_CTRL1_XL_ODR_XL1 (1 << 5)
  211. #define LSMDSL_CTRL1_XL_ODR_XL2 (1 << 6)
  212. #define LSMDSL_CTRL1_XL_ODR_XL3 (1 << 7)
  213. /** @} */
  214. /**
  215. * @name LSM6DSL_AD_CTRL2_G register bits definitions
  216. * @{
  217. */
  218. #define LSMDSL_CTRL2_G_FS_MASK 0x0E
  219. #define LSMDSL_CTRL2_G_FS_125 (1 << 1)
  220. #define LSMDSL_CTRL2_G_FS_G0 (1 << 2)
  221. #define LSMDSL_CTRL2_G_FS_G1 (1 << 3)
  222. #define LSMDSL_CTRL2_G_ODR_G0 (1 << 4)
  223. #define LSMDSL_CTRL2_G_ODR_G1 (1 << 5)
  224. #define LSMDSL_CTRL2_G_ODR_G2 (1 << 6)
  225. #define LSMDSL_CTRL2_G_ODR_G3 (1 << 7)
  226. /** @} */
  227. /**
  228. * @name LSM6DSL_AD_CTRL3_C register bits definitions
  229. * @{
  230. */
  231. #define LSMDSL_CTRL3_C_SW_RESET (1 << 0)
  232. #define LSMDSL_CTRL3_C_BLE (1 << 1)
  233. #define LSMDSL_CTRL3_C_IF_INC (1 << 2)
  234. #define LSMDSL_CTRL3_C_SIM (1 << 3)
  235. #define LSMDSL_CTRL3_C_PP_OD (1 << 4)
  236. #define LSMDSL_CTRL3_C_H_LACTIVE (1 << 5)
  237. #define LSMDSL_CTRL3_C_BDU (1 << 6)
  238. #define LSMDSL_CTRL3_C_BOOT (1 << 7)
  239. /** @} */
  240. /**
  241. * @name LSM6DSL_AD_CTRL4_C register bits definitions
  242. * @{
  243. */
  244. #define LSMDSL_CTRL4_C_NOT_USED_01 (1 << 0)
  245. #define LSMDSL_CTRL4_C_LPF1_SEL_G (1 << 1)
  246. #define LSMDSL_CTRL4_C_I2C_DISABLE (1 << 2)
  247. #define LSMDSL_CTRL4_C_DRDY_MASK (1 << 3)
  248. #define LSMDSL_CTRL4_C_DEN_DRDY_IN (1 << 4)
  249. #define LSMDSL_CTRL4_C_INT2_ON_INT (1 << 5)
  250. #define LSMDSL_CTRL4_C_SLEEP (1 << 6)
  251. #define LSMDSL_CTRL4_C_DEN_XL_EN (1 << 7)
  252. /** @} */
  253. /**
  254. * @name LSM6DSL_AD_CTRL5_C register bits definitions
  255. * @{
  256. */
  257. #define LSMDSL_CTRL5_C_ST0_XL (1 << 0)
  258. #define LSMDSL_CTRL5_C_ST1_XL (1 << 1)
  259. #define LSMDSL_CTRL5_C_ST0_G (1 << 2)
  260. #define LSMDSL_CTRL5_C_ST1_G (1 << 3)
  261. #define LSMDSL_CTRL5_C_DEN_LH (1 << 4)
  262. #define LSMDSL_CTRL5_C_ROUNDING0 (1 << 5)
  263. #define LSMDSL_CTRL5_C_ROUNDING1 (1 << 6)
  264. #define LSMDSL_CTRL5_C_ROUNDING2 (1 << 7)
  265. /** @} */
  266. /**
  267. * @name LSM6DSL_AD_CTRL6_C register bits definitions
  268. * @{
  269. */
  270. #define LSMDSL_CTRL6_C_FTYPE_0 (1 << 0)
  271. #define LSMDSL_CTRL6_C_FTYPE_1 (1 << 1)
  272. #define LSMDSL_CTRL6_C_USR_OFF_W (1 << 3)
  273. #define LSMDSL_CTRL6_C_XL_HM_MODE (1 << 4)
  274. #define LSMDSL_CTRL6_C_LVL2_EN (1 << 5)
  275. #define LSMDSL_CTRL6_C_LVL_EN (1 << 6)
  276. #define LSMDSL_CTRL6_C_TRIG_EN (1 << 7)
  277. /** @} */
  278. /**
  279. * @name LSM6DSL_AD_CTRL7_G register bits definitions
  280. * @{
  281. */
  282. #define LSMDSL_CTRL7_G_ROUNDING_ST (1 << 2)
  283. #define LSMDSL_CTRL7_G_HPM0_G (1 << 4)
  284. #define LSMDSL_CTRL7_G_HPM1_G (1 << 5)
  285. #define LSMDSL_CTRL7_G_HP_EN_G (1 << 6)
  286. #define LSMDSL_CTRL7_G_G_HM_MODE (1 << 7)
  287. /** @} */
  288. /**
  289. * @name LSM6DSL_AD_CTRL8_XL register bits definitions
  290. * @{
  291. */
  292. #define LSMDSL_CTRL8_XL_LOW_PASS_ON (1 << 0)
  293. #define LSMDSL_CTRL8_XL_HP_SLOPE_XL (1 << 2)
  294. #define LSMDSL_CTRL8_XL_INPUT_COMPO (1 << 3)
  295. #define LSMDSL_CTRL8_XL_HP_REF_MODE (1 << 4)
  296. #define LSMDSL_CTRL8_XL_HPCF_XL0 (1 << 5)
  297. #define LSMDSL_CTRL8_XL_HPCF_XL1 (1 << 6)
  298. #define LSMDSL_CTRL8_XL_LPF2_XL_EN (1 << 7)
  299. /** @} */
  300. /**
  301. * @name LSM6DSL_AD_CTRL9_XL register bits definitions
  302. * @{
  303. */
  304. #define LSMDSL_CTRL9_XL_SOFT_EN (1 << 2)
  305. #define LSMDSL_CTRL9_XL_DEN_XL_G (1 << 4)
  306. #define LSMDSL_CTRL9_XL_DEN_Z (1 << 5)
  307. #define LSMDSL_CTRL9_XL_DEN_Y (1 << 6)
  308. #define LSMDSL_CTRL9_XL_DEN_X (1 << 7)
  309. /** @} */
  310. /**
  311. * @name LSM6DSL_AD_CTRL10_C register bits definitions
  312. * @{
  313. */
  314. #define LSMDSL_CTRL10_C_SIGN_MOTION (1 << 0)
  315. #define LSMDSL_CTRL10_C_PEDO_RST_ST (1 << 1)
  316. #define LSMDSL_CTRL10_C_FUNC_EN (1 << 2)
  317. #define LSMDSL_CTRL10_C_TILT_EN (1 << 3)
  318. #define LSMDSL_CTRL10_C_PEDO_EN (1 << 4)
  319. #define LSMDSL_CTRL10_C_TIMER_EN (1 << 5)
  320. #define LSMDSL_CTRL10_C_WRIST_TILT (1 << 7)
  321. /** @} */
  322. /*===========================================================================*/
  323. /* Driver pre-compile time settings. */
  324. /*===========================================================================*/
  325. /**
  326. * @name Configuration options
  327. * @{
  328. */
  329. /**
  330. * @brief LSM6DSL SPI interface switch.
  331. * @details If set to @p TRUE the support for SPI is included.
  332. * @note The default is @p FALSE.
  333. */
  334. #if !defined(LSM6DSL_USE_SPI) || defined(__DOXYGEN__)
  335. #define LSM6DSL_USE_SPI FALSE
  336. #endif
  337. /**
  338. * @brief LSM6DSL shared SPI switch.
  339. * @details If set to @p TRUE the device acquires SPI bus ownership
  340. * on each transaction.
  341. * @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION.
  342. */
  343. #if !defined(LSM6DSL_SHARED_SPI) || defined(__DOXYGEN__)
  344. #define LSM6DSL_SHARED_SPI FALSE
  345. #endif
  346. /**
  347. * @brief LSM6DSL I2C interface switch.
  348. * @details If set to @p TRUE the support for I2C is included.
  349. * @note The default is @p TRUE.
  350. */
  351. #if !defined(LSM6DSL_USE_I2C) || defined(__DOXYGEN__)
  352. #define LSM6DSL_USE_I2C TRUE
  353. #endif
  354. /**
  355. * @brief LSM6DSL shared I2C switch.
  356. * @details If set to @p TRUE the device acquires I2C bus ownership
  357. * on each transaction.
  358. * @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION.
  359. */
  360. #if !defined(LSM6DSL_SHARED_I2C) || defined(__DOXYGEN__)
  361. #define LSM6DSL_SHARED_I2C FALSE
  362. #endif
  363. /**
  364. * @brief LSM6DSL advanced configurations switch.
  365. * @details If set to @p TRUE more configurations are available.
  366. * @note The default is @p FALSE.
  367. */
  368. #if !defined(LSM6DSL_USE_ADVANCED) || defined(__DOXYGEN__)
  369. #define LSM6DSL_USE_ADVANCED FALSE
  370. #endif
  371. /**
  372. * @brief Number of acquisitions for gyroscope bias removal.
  373. * @details This is the number of acquisitions performed to compute the
  374. * bias. A repetition is required in order to remove noise.
  375. */
  376. #if !defined(LSM6DSL_GYRO_BIAS_ACQ_TIMES) || defined(__DOXYGEN__)
  377. #define LSM6DSL_GYRO_BIAS_ACQ_TIMES 50
  378. #endif
  379. /**
  380. * @brief Settling time for gyroscope bias removal.
  381. * @details This is the time between each bias acquisition.
  382. */
  383. #if !defined(LSM6DSL_GYRO_BIAS_SETTLING_US) || defined(__DOXYGEN__)
  384. #define LSM6DSL_GYRO_BIAS_SETTLING_US 5000
  385. #endif
  386. /** @} */
  387. /*===========================================================================*/
  388. /* Derived constants and error checks. */
  389. /*===========================================================================*/
  390. #if !(LSM6DSL_USE_SPI ^ LSM6DSL_USE_I2C)
  391. #error "LSM6DSL_USE_SPI and LSM6DSL_USE_I2C cannot be both true or both false"
  392. #endif
  393. #if LSM6DSL_USE_SPI && !HAL_USE_SPI
  394. #error "LSM6DSL_USE_SPI requires HAL_USE_SPI"
  395. #endif
  396. #if LSM6DSL_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
  397. #error "LSM6DSL_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
  398. #endif
  399. #if LSM6DSL_USE_I2C && !HAL_USE_I2C
  400. #error "LSM6DSL_USE_I2C requires HAL_USE_I2C"
  401. #endif
  402. #if LSM6DSL_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
  403. #error "LSM6DSL_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
  404. #endif
  405. /**
  406. * @todo Add support for LSM6DSL over SPI.
  407. */
  408. #if LSM6DSL_USE_SPI
  409. #error "LSM6DSL over SPI still not supported"
  410. #endif
  411. /*===========================================================================*/
  412. /* Driver data structures and types. */
  413. /*===========================================================================*/
  414. /**
  415. * @name LSM6DSL data structures and types.
  416. * @{
  417. */
  418. /**
  419. * @brief Structure representing a LSM6DSL driver.
  420. */
  421. typedef struct LSM6DSLDriver LSM6DSLDriver;
  422. /**
  423. * @brief Accelerometer and Gyroscope Slave Address.
  424. */
  425. typedef enum {
  426. LSM6DSL_SAD_GND = 0x6A, /**< SAD pin connected to GND. */
  427. LSM6DSL_SAD_VCC = 0x6B /**< SAD pin connected to VCC. */
  428. } lsm6dsl_sad_t;
  429. /**
  430. * @brief LSM6DSL accelerometer subsystem full scale.
  431. */
  432. typedef enum {
  433. LSM6DSL_ACC_FS_2G = 0x00, /**< Full scale ±2g. */
  434. LSM6DSL_ACC_FS_4G = 0x40, /**< Full scale ±4g. */
  435. LSM6DSL_ACC_FS_8G = 0x80, /**< Full scale ±8g. */
  436. LSM6DSL_ACC_FS_16G = 0xC0 /**< Full scale ±16g. */
  437. } lsm6dsl_acc_fs_t;
  438. /**
  439. * @brief LSM6DSL accelerometer subsystem output data rate.
  440. */
  441. typedef enum {
  442. LSM6DSL_ACC_ODR_PD = 0x00, /**< Power down */
  443. LSM6DSL_ACC_ODR_1P6Hz = 0xB0, /**< ODR 1.6 Hz (Low Power only) */
  444. LSM6DSL_ACC_ODR_12P5Hz = 0x10, /**< ODR 12.5 Hz */
  445. LSM6DSL_ACC_ODR_26Hz = 0x20, /**< ODR 26 Hz */
  446. LSM6DSL_ACC_ODR_52Hz = 0x30, /**< ODR 52 Hz */
  447. LSM6DSL_ACC_ODR_104Hz = 0x40, /**< ODR 104 Hz */
  448. LSM6DSL_ACC_ODR_208Hz = 0x50, /**< ODR 208 Hz */
  449. LSM6DSL_ACC_ODR_416Hz = 0x60, /**< ODR 416 Hz */
  450. LSM6DSL_ACC_ODR_833Hz = 0x70, /**< ODR 833 Hz */
  451. LSM6DSL_ACC_ODR_1P66Hz = 0x80, /**< ODR 1.66 kHz */
  452. LSM6DSL_ACC_ODR_3P33Hz = 0x90, /**< ODR 3.33 kHz */
  453. LSM6DSL_ACC_ODR_6P66Hz = 0xA0 /**< ODR 6.66 kHz */
  454. } lsm6dsl_acc_odr_t;
  455. /**
  456. * @brief LSM6DSL accelerometer subsystem output data rate.
  457. */
  458. typedef enum {
  459. LSM6DSL_ACC_LP_DISABLED = 0x00, /**< Low power disabled */
  460. LSM6DSL_ACC_LP_ENABLED = 0x10 /**< Low power enabled */
  461. } lsm6dsl_acc_lp_t;
  462. /**
  463. * @brief LSM6DSL gyroscope subsystem full scale.
  464. */
  465. typedef enum {
  466. LSM6DSL_GYRO_FS_125DPS = 0x02, /**< Full scale ±125 degree per second */
  467. LSM6DSL_GYRO_FS_250DPS = 0x00, /**< Full scale ±250 degree per second */
  468. LSM6DSL_GYRO_FS_500DPS = 0x04, /**< Full scale ±500 degree per second */
  469. LSM6DSL_GYRO_FS_1000DPS = 0x08, /**< Full scale ±1000 degree per second */
  470. LSM6DSL_GYRO_FS_2000DPS = 0x0C /**< Full scale ±2000 degree per second */
  471. } lsm6dsl_gyro_fs_t;
  472. /**
  473. * @brief LSM6DSL gyroscope subsystem output data rate.
  474. */
  475. typedef enum {
  476. LSM6DSL_GYRO_ODR_PD = 0x00, /**< Power down */
  477. LSM6DSL_GYRO_ODR_12P5Hz = 0x10, /**< ODR 12.5 Hz */
  478. LSM6DSL_GYRO_ODR_26Hz = 0x20, /**< ODR 26 Hz */
  479. LSM6DSL_GYRO_ODR_52Hz = 0x30, /**< ODR 52 Hz */
  480. LSM6DSL_GYRO_ODR_104Hz = 0x40, /**< ODR 104 Hz */
  481. LSM6DSL_GYRO_ODR_208Hz = 0x50, /**< ODR 208 Hz */
  482. LSM6DSL_GYRO_ODR_416Hz = 0x60, /**< ODR 416 Hz */
  483. LSM6DSL_GYRO_ODR_833Hz = 0x70, /**< ODR 833 Hz */
  484. LSM6DSL_GYRO_ODR_1P66Hz = 0x80, /**< ODR 1.66 kHz */
  485. LSM6DSL_GYRO_ODR_3P33Hz = 0x90, /**< ODR 3.33 kHz */
  486. LSM6DSL_GYRO_ODR_6P66Hz = 0xA0 /**< ODR 6.66 kHz */
  487. } lsm6dsl_gyro_odr_t;
  488. /**
  489. * @brief LSM6DSL gyroscope subsystem low mode configuration.
  490. */
  491. typedef enum {
  492. LSM6DSL_GYRO_LP_DISABLED = 0x00, /**< Low power mode disabled. */
  493. LSM6DSL_GYRO_LP_ENABLED = 0x80 /**< Low power mode enabled. */
  494. } lsm6dsl_gyro_lp_t;
  495. /**
  496. * @brief LSM6DSL gyroscope subsystem output selection.
  497. */
  498. typedef enum {
  499. LSM6DSL_GYRO_LPF_DISABLED = -1, /**< Low pass filter disabled. */
  500. LSM6DSL_GYRO_LPF_FTYPE0 = 0x00, /**< Refer to table 68 of Datasheet. */
  501. LSM6DSL_GYRO_LPF_FTYPE1 = 0x01, /**< Refer to table 68 of Datasheet. */
  502. LSM6DSL_GYRO_LPF_FTYPE2 = 0x10, /**< Refer to table 68 of Datasheet. */
  503. LSM6DSL_GYRO_LPF_FTYPE3 = 0x11 /**< Refer to table 68 of Datasheet. */
  504. } lsm6dsl_gyro_lpf_t;
  505. /**
  506. * @brief LSM6DSL block data update.
  507. */
  508. typedef enum {
  509. LSM6DSL_BDU_CONTINUOUS = 0x00, /**< Block data continuously updated. */
  510. LSM6DSL_BDU_BLOCKED = 0x40 /**< Block data updated after reading. */
  511. } lsm6dsl_bdu_t;
  512. /**
  513. * @brief LSM6DSL endianness.
  514. */
  515. typedef enum {
  516. LSM6DSL_END_LITTLE = 0x00, /**< Little endian. */
  517. LSM6DSL_END_BIG = 0x20 /**< Big endian. */
  518. } lsm6dsl_end_t;
  519. /**
  520. * @brief Driver state machine possible states.
  521. */
  522. typedef enum {
  523. LSM6DSL_UNINIT = 0, /**< Not initialized. */
  524. LSM6DSL_STOP = 1, /**< Stopped. */
  525. LSM6DSL_READY = 2, /**< Ready. */
  526. } lsm6dsl_state_t;
  527. /**
  528. * @brief LSM6DSL configuration structure.
  529. */
  530. typedef struct {
  531. #if (LSM6DSL_USE_SPI) || defined(__DOXYGEN__)
  532. /**
  533. * @brief SPI driver associated to this LSM6DSL.
  534. */
  535. SPIDriver *spip;
  536. /**
  537. * @brief SPI configuration associated to this LSM6DSL accelerometer
  538. * subsystem.
  539. */
  540. const SPIConfig *accspicfg;
  541. #endif /* LSM6DSL_USE_SPI */
  542. #if (LSM6DSL_USE_I2C) || defined(__DOXYGEN__)
  543. /**
  544. * @brief I2C driver associated to this LSM6DSL.
  545. */
  546. I2CDriver *i2cp;
  547. /**
  548. * @brief I2C configuration associated to this LSM6DSL accelerometer
  549. * subsystem.
  550. */
  551. const I2CConfig *i2ccfg;
  552. /**
  553. * @brief LSM6DSL Slave Address
  554. */
  555. lsm6dsl_sad_t slaveaddress;
  556. #endif /* LSM6DSL_USE_I2C */
  557. /**
  558. * @brief LSM6DSL accelerometer subsystem initial sensitivity.
  559. */
  560. float *accsensitivity;
  561. /**
  562. * @brief LSM6DSL accelerometer subsystem initial bias.
  563. */
  564. float *accbias;
  565. /**
  566. * @brief LSM6DSL accelerometer subsystem full scale.
  567. */
  568. lsm6dsl_acc_fs_t accfullscale;
  569. /**
  570. * @brief LSM6DSL accelerometer subsystem output data rate.
  571. */
  572. lsm6dsl_acc_odr_t accoutdatarate;
  573. #if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
  574. /**
  575. * @brief LSM6DSL accelerometer subsystem low power mode.
  576. */
  577. lsm6dsl_acc_lp_t acclpmode;
  578. #endif /* LSM6DSL_USE_ADVANCED */
  579. /**
  580. * @brief LSM6DSL gyroscope subsystem initial sensitivity.
  581. */
  582. float *gyrosensitivity;
  583. /**
  584. * @brief LSM6DSL gyroscope subsystem initial bias.
  585. */
  586. float *gyrobias;
  587. /**
  588. * @brief LSM6DSL gyroscope subsystem full scale.
  589. */
  590. lsm6dsl_gyro_fs_t gyrofullscale;
  591. /**
  592. * @brief LSM6DSL gyroscope subsystem output data rate.
  593. */
  594. lsm6dsl_gyro_odr_t gyrooutdatarate;
  595. #if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
  596. /**
  597. * @brief LSM6DSL gyroscope subsystem low mode configuration.
  598. */
  599. lsm6dsl_gyro_lp_t gyrolpmode;
  600. /**
  601. * @brief LSM6DSL gyroscope subsystem low pass filter configuration.
  602. */
  603. lsm6dsl_gyro_lpf_t gyrolowpassfilter;
  604. /**
  605. * @brief LSM6DSL block data update
  606. */
  607. lsm6dsl_bdu_t blockdataupdate;
  608. /**
  609. * @brief LSM6DSL endianness
  610. */
  611. lsm6dsl_end_t endianness;
  612. #endif /* LSM6DSL_USE_ADVANCED */
  613. } LSM6DSLConfig;
  614. /**
  615. * @brief @p LSM6DSL specific methods.
  616. */
  617. #define _lsm6dsl_methods_alone \
  618. /* Change full scale value of LSM6DSL accelerometer subsystem .*/ \
  619. msg_t (*acc_set_full_scale)(LSM6DSLDriver *devp, lsm6dsl_acc_fs_t fs); \
  620. /* Change full scale value of LSM6DSL gyroscope subsystem .*/ \
  621. msg_t (*gyro_set_full_scale)(LSM6DSLDriver *devp, lsm6dsl_gyro_fs_t fs);
  622. /**
  623. * @brief @p LSM6DSL specific methods with inherited ones.
  624. */
  625. #define _lsm6dsl_methods \
  626. _base_object_methods \
  627. _lsm6dsl_methods_alone
  628. /**
  629. * @extends BaseObjectVMT
  630. *
  631. * @brief @p LSM6DSL virtual methods table.
  632. */
  633. struct LSM6DSLVMT {
  634. _lsm6dsl_methods
  635. };
  636. /**
  637. * @brief @p LSM6DSLDriver specific data.
  638. */
  639. #define _lsm6dsl_data \
  640. _base_sensor_data \
  641. /* Driver state.*/ \
  642. lsm6dsl_state_t state; \
  643. /* Current configuration data.*/ \
  644. const LSM6DSLConfig *config; \
  645. /* Accelerometer subsystem axes number.*/ \
  646. size_t accaxes; \
  647. /* Accelerometer subsystem current sensitivity.*/ \
  648. float accsensitivity[LSM6DSL_ACC_NUMBER_OF_AXES]; \
  649. /* Accelerometer subsystem current bias .*/ \
  650. float accbias[LSM6DSL_ACC_NUMBER_OF_AXES]; \
  651. /* Accelerometer subsystem current full scale value.*/ \
  652. float accfullscale; \
  653. /* Gyroscope subsystem axes number.*/ \
  654. size_t gyroaxes; \
  655. /* Gyroscope subsystem current sensitivity.*/ \
  656. float gyrosensitivity[LSM6DSL_GYRO_NUMBER_OF_AXES]; \
  657. /* Gyroscope subsystem current Bias.*/ \
  658. float gyrobias[LSM6DSL_GYRO_NUMBER_OF_AXES]; \
  659. /* Gyroscope subsystem current full scale value.*/ \
  660. float gyrofullscale;
  661. /**
  662. * @brief LSM6DSL 6-axis accelerometer/gyroscope class.
  663. */
  664. struct LSM6DSLDriver {
  665. /** @brief Virtual Methods Table.*/
  666. const struct LSM6DSLVMT *vmt;
  667. /** @brief Base accelerometer interface.*/
  668. BaseAccelerometer acc_if;
  669. /** @brief Base gyroscope interface.*/
  670. BaseGyroscope gyro_if;
  671. _lsm6dsl_data
  672. };
  673. /** @} */
  674. /*===========================================================================*/
  675. /* Driver macros. */
  676. /*===========================================================================*/
  677. /**
  678. * @brief Return the number of axes of the BaseAccelerometer.
  679. *
  680. * @param[in] devp pointer to @p LSM6DSLDriver.
  681. *
  682. * @return the number of axes.
  683. *
  684. * @api
  685. */
  686. #define lsm6dslAccelerometerGetAxesNumber(devp) \
  687. accelerometerGetAxesNumber(&((devp)->acc_if))
  688. /**
  689. * @brief Retrieves raw data from the BaseAccelerometer.
  690. * @note This data is retrieved from MEMS register without any algebraical
  691. * manipulation.
  692. * @note The axes array must be at least the same size of the
  693. * BaseAccelerometer axes number.
  694. *
  695. * @param[in] devp pointer to @p LSM6DSLDriver.
  696. * @param[out] axes a buffer which would be filled with raw data.
  697. *
  698. * @return The operation status.
  699. * @retval MSG_OK if the function succeeded.
  700. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  701. * be retrieved using @p i2cGetErrors().
  702. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  703. *
  704. * @api
  705. */
  706. #define lsm6dslAccelerometerReadRaw(devp, axes) \
  707. accelerometerReadRaw(&((devp)->acc_if), axes)
  708. /**
  709. * @brief Retrieves cooked data from the BaseAccelerometer.
  710. * @note This data is manipulated according to the formula
  711. * cooked = (raw * sensitivity) - bias.
  712. * @note Final data is expressed as milli-G.
  713. * @note The axes array must be at least the same size of the
  714. * BaseAccelerometer axes number.
  715. *
  716. * @param[in] devp pointer to @p LSM6DSLDriver.
  717. * @param[out] axes a buffer which would be filled with cooked data.
  718. *
  719. * @return The operation status.
  720. * @retval MSG_OK if the function succeeded.
  721. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  722. * be retrieved using @p i2cGetErrors().
  723. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  724. *
  725. * @api
  726. */
  727. #define lsm6dslAccelerometerReadCooked(devp, axes) \
  728. accelerometerReadCooked(&((devp)->acc_if), axes)
  729. /**
  730. * @brief Set bias values for the BaseAccelerometer.
  731. * @note Bias must be expressed as milli-G.
  732. * @note The bias buffer must be at least the same size of the
  733. * BaseAccelerometer axes number.
  734. *
  735. * @param[in] devp pointer to @p LSM6DSLDriver.
  736. * @param[in] bp a buffer which contains biases.
  737. *
  738. * @return The operation status.
  739. * @retval MSG_OK if the function succeeded.
  740. *
  741. * @api
  742. */
  743. #define lsm6dslAccelerometerSetBias(devp, bp) \
  744. accelerometerSetBias(&((devp)->acc_if), bp)
  745. /**
  746. * @brief Reset bias values for the BaseAccelerometer.
  747. * @note Default biases value are obtained from device datasheet when
  748. * available otherwise they are considered zero.
  749. *
  750. * @param[in] devp pointer to @p LSM6DSLDriver.
  751. *
  752. * @return The operation status.
  753. * @retval MSG_OK if the function succeeded.
  754. *
  755. * @api
  756. */
  757. #define lsm6dslAccelerometerResetBias(devp) \
  758. accelerometerResetBias(&((devp)->acc_if))
  759. /**
  760. * @brief Set sensitivity values for the BaseAccelerometer.
  761. * @note Sensitivity must be expressed as milli-G/LSB.
  762. * @note The sensitivity buffer must be at least the same size of the
  763. * BaseAccelerometer axes number.
  764. *
  765. * @param[in] devp pointer to @p LSM6DSLDriver.
  766. * @param[in] sp a buffer which contains sensitivities.
  767. *
  768. * @return The operation status.
  769. * @retval MSG_OK if the function succeeded.
  770. *
  771. * @api
  772. */
  773. #define lsm6dslAccelerometerSetSensitivity(devp, sp) \
  774. accelerometerSetSensitivity(&((devp)->acc_if), sp)
  775. /**
  776. * @brief Reset sensitivity values for the BaseAccelerometer.
  777. * @note Default sensitivities value are obtained from device datasheet.
  778. *
  779. * @param[in] devp pointer to @p LSM6DSLDriver.
  780. *
  781. * @return The operation status.
  782. * @retval MSG_OK if the function succeeded.
  783. * @retval MSG_RESET otherwise.
  784. *
  785. * @api
  786. */
  787. #define lsm6dslAccelerometerResetSensitivity(devp) \
  788. accelerometerResetSensitivity(&((devp)->acc_if))
  789. /**
  790. * @brief Changes the LSM6DSLDriver accelerometer fullscale value.
  791. * @note This function also rescale sensitivities and biases based on
  792. * previous and next fullscale value.
  793. * @note A recalibration is highly suggested after calling this function.
  794. *
  795. * @param[in] devp pointer to @p LSM6DSLDriver.
  796. * @param[in] fs new fullscale value.
  797. *
  798. * @return The operation status.
  799. * @retval MSG_OK if the function succeeded.
  800. * @retval MSG_RESET otherwise.
  801. *
  802. * @api
  803. */
  804. #define lsm6dslAccelerometerSetFullScale(devp, fs) \
  805. (devp)->vmt->acc_set_full_scale(devp, fs)
  806. /**
  807. * @brief Return the number of axes of the BaseGyroscope.
  808. *
  809. * @param[in] devp pointer to @p LSM6DSLDriver.
  810. *
  811. * @return the number of axes.
  812. *
  813. * @api
  814. */
  815. #define lsm6dslGyroscopeGetAxesNumber(devp) \
  816. gyroscopeGetAxesNumber(&((devp)->gyro_if))
  817. /**
  818. * @brief Retrieves raw data from the BaseGyroscope.
  819. * @note This data is retrieved from MEMS register without any algebraical
  820. * manipulation.
  821. * @note The axes array must be at least the same size of the
  822. * BaseGyroscope axes number.
  823. *
  824. * @param[in] devp pointer to @p LSM6DSLDriver.
  825. * @param[out] axes a buffer which would be filled with raw data.
  826. *
  827. * @return The operation status.
  828. * @retval MSG_OK if the function succeeded.
  829. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  830. * be retrieved using @p i2cGetErrors().
  831. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  832. *
  833. * @api
  834. */
  835. #define lsm6dslGyroscopeReadRaw(devp, axes) \
  836. gyroscopeReadRaw(&((devp)->gyro_if), axes)
  837. /**
  838. * @brief Retrieves cooked data from the BaseGyroscope.
  839. * @note This data is manipulated according to the formula
  840. * cooked = (raw * sensitivity) - bias.
  841. * @note Final data is expressed as DPS.
  842. * @note The axes array must be at least the same size of the
  843. * BaseGyroscope axes number.
  844. *
  845. * @param[in] devp pointer to @p LSM6DSLDriver.
  846. * @param[out] axes a buffer which would be filled with cooked data.
  847. *
  848. * @return The operation status.
  849. * @retval MSG_OK if the function succeeded.
  850. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  851. * be retrieved using @p i2cGetErrors().
  852. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  853. *
  854. * @api
  855. */
  856. #define lsm6dslGyroscopeReadCooked(devp, axes) \
  857. gyroscopeReadCooked(&((devp)->gyro_if), axes)
  858. /**
  859. * @brief Samples bias values for the BaseGyroscope.
  860. * @note The LSM6DSL shall not be moved during the whole procedure.
  861. * @note After this function internal bias is automatically updated.
  862. * @note The behavior of this function depends on @p LSM6DSL_BIAS_ACQ_TIMES
  863. * and @p LSM6DSL_BIAS_SETTLING_US.
  864. *
  865. * @param[in] devp pointer to @p LSM6DSLDriver.
  866. *
  867. * @return The operation status.
  868. * @retval MSG_OK if the function succeeded.
  869. * @retval MSG_RESET if one or more I2C errors occurred, the errors can
  870. * be retrieved using @p i2cGetErrors().
  871. * @retval MSG_TIMEOUT if a timeout occurred before operation end.
  872. *
  873. * @api
  874. */
  875. #define lsm6dslGyroscopeSampleBias(devp) \
  876. gyroscopeSampleBias(&((devp)->gyro_if))
  877. /**
  878. * @brief Set bias values for the BaseGyroscope.
  879. * @note Bias must be expressed as DPS.
  880. * @note The bias buffer must be at least the same size of the BaseGyroscope
  881. * axes number.
  882. *
  883. * @param[in] devp pointer to @p LSM6DSLDriver.
  884. * @param[in] bp a buffer which contains biases.
  885. *
  886. * @return The operation status.
  887. * @retval MSG_OK if the function succeeded.
  888. *
  889. * @api
  890. */
  891. #define lsm6dslGyroscopeSetBias(devp, bp) \
  892. gyroscopeSetBias(&((devp)->gyro_if), bp)
  893. /**
  894. * @brief Reset bias values for the BaseGyroscope.
  895. * @note Default biases value are obtained from device datasheet when
  896. * available otherwise they are considered zero.
  897. *
  898. * @param[in] devp pointer to @p LSM6DSLDriver.
  899. *
  900. * @return The operation status.
  901. * @retval MSG_OK if the function succeeded.
  902. *
  903. * @api
  904. */
  905. #define lsm6dslGyroscopeResetBias(devp) \
  906. gyroscopeResetBias(&((devp)->gyro_if))
  907. /**
  908. * @brief Set sensitivity values for the BaseGyroscope.
  909. * @note Sensitivity must be expressed as DPS/LSB.
  910. * @note The sensitivity buffer must be at least the same size of the
  911. * BaseGyroscope axes number.
  912. *
  913. * @param[in] devp pointer to @p LSM6DSLDriver.
  914. * @param[in] sp a buffer which contains sensitivities.
  915. *
  916. * @return The operation status.
  917. * @retval MSG_OK if the function succeeded.
  918. *
  919. * @api
  920. */
  921. #define lsm6dslGyroscopeSetSensitivity(devp, sp) \
  922. gyroscopeSetSensitivity(&((devp)->gyro_if), sp)
  923. /**
  924. * @brief Reset sensitivity values for the BaseGyroscope.
  925. * @note Default sensitivities value are obtained from device datasheet.
  926. *
  927. * @param[in] devp pointer to @p LSM6DSLDriver.
  928. *
  929. * @return The operation status.
  930. * @retval MSG_OK if the function succeeded.
  931. * @retval MSG_RESET otherwise.
  932. *
  933. * @api
  934. */
  935. #define lsm6dslGyroscopeResetSensitivity(devp) \
  936. gyroscopeResetSensitivity(&((devp)->gyro_if))
  937. /**
  938. * @brief Changes the LSM6DSLDriver gyroscope fullscale value.
  939. * @note This function also rescale sensitivities and biases based on
  940. * previous and next fullscale value.
  941. * @note A recalibration is highly suggested after calling this function.
  942. *
  943. * @param[in] devp pointer to @p LSM6DSLDriver.
  944. * @param[in] fs new fullscale value.
  945. *
  946. * @return The operation status.
  947. * @retval MSG_OK if the function succeeded.
  948. * @retval MSG_RESET otherwise.
  949. *
  950. * @api
  951. */
  952. #define lsm6dslGyroscopeSetFullScale(devp, fs) \
  953. (devp)->vmt->acc_set_full_scale(devp, fs)
  954. /*===========================================================================*/
  955. /* External declarations. */
  956. /*===========================================================================*/
  957. #ifdef __cplusplus
  958. extern "C" {
  959. #endif
  960. void lsm6dslObjectInit(LSM6DSLDriver *devp);
  961. void lsm6dslStart(LSM6DSLDriver *devp, const LSM6DSLConfig *config);
  962. void lsm6dslStop(LSM6DSLDriver *devp);
  963. #ifdef __cplusplus
  964. }
  965. #endif
  966. #endif /* _LSM6DSL_H_ */
  967. /** @} */