l3gd20.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 l3gd20.h
  17. * @brief L3GD20 MEMS interface module header.
  18. *
  19. * @addtogroup L3GD20
  20. * @ingroup EX_ST
  21. * @{
  22. */
  23. #ifndef _L3GD20_H_
  24. #define _L3GD20_H_
  25. #include "hal_gyroscope.h"
  26. /*===========================================================================*/
  27. /* Driver constants. */
  28. /*===========================================================================*/
  29. /**
  30. * @name Version identification
  31. * @{
  32. */
  33. /**
  34. * @brief L3GD20 driver version string.
  35. */
  36. #define EX_L3GD20_VERSION "1.1.2"
  37. /**
  38. * @brief L3GD20 driver version major number.
  39. */
  40. #define EX_L3GD20_MAJOR 1
  41. /**
  42. * @brief L3GD20 driver version minor number.
  43. */
  44. #define EX_L3GD20_MINOR 1
  45. /**
  46. * @brief L3GD20 driver version patch number.
  47. */
  48. #define EX_L3GD20_PATCH 2
  49. /** @} */
  50. /**
  51. * @brief L3GD20 gyroscope system characteristics.
  52. * @note Sensitivity is expressed as DPS/LSB whereas DPS stand for Degree
  53. * per second [°/s].
  54. * @note Bias is expressed as DPS.
  55. *
  56. * @{
  57. */
  58. #define L3GD20_GYRO_NUMBER_OF_AXES 3U
  59. #define L3GD20_250DPS 250.0f
  60. #define L3GD20_500DPS 500.0f
  61. #define L3GD20_2000DPS 2000.0f
  62. #define L3GD20_GYRO_SENS_250DPS 0.00875f
  63. #define L3GD20_GYRO_SENS_500DPS 0.01750f
  64. #define L3GD20_GYRO_SENS_2000DPS 0.07000f
  65. #define L3GD20_GYRO_BIAS 0.0f
  66. /** @} */
  67. /**
  68. * @name L3GD20 communication interfaces related bit masks
  69. * @{
  70. */
  71. #define L3GD20_DI_MASK 0xFF
  72. #define L3GD20_DI(n) (1 << n)
  73. #define L3GD20_AD_MASK 0x3F
  74. #define L3GD20_AD(n) (1 << n)
  75. #define L3GD20_MS (1 << 6)
  76. #define L3GD20_RW (1 << 7)
  77. /** @} */
  78. /**
  79. * @name L3GD20 register addresses
  80. * @{
  81. */
  82. #define L3GD20_AD_WHO_AM_I 0x0F
  83. #define L3GD20_AD_CTRL_REG1 0x20
  84. #define L3GD20_AD_CTRL_REG2 0x21
  85. #define L3GD20_AD_CTRL_REG3 0x22
  86. #define L3GD20_AD_CTRL_REG4 0x23
  87. #define L3GD20_AD_CTRL_REG5 0x24
  88. #define L3GD20_AD_REFERENCE 0x25
  89. #define L3GD20_AD_OUT_TEMP 0x26
  90. #define L3GD20_AD_STATUS_REG 0x27
  91. #define L3GD20_AD_OUT_X_L 0x28
  92. #define L3GD20_AD_OUT_X_H 0x29
  93. #define L3GD20_AD_OUT_Y_L 0x2A
  94. #define L3GD20_AD_OUT_Y_H 0x2B
  95. #define L3GD20_AD_OUT_Z_L 0x2C
  96. #define L3GD20_AD_OUT_Z_H 0x2D
  97. #define L3GD20_AD_FIFO_CTRL_REG 0x2E
  98. #define L3GD20_AD_FIFO_SRC_REG 0x2F
  99. #define L3GD20_AD_INT1_CFG 0x30
  100. #define L3GD20_AD_INT1_SRC 0x31
  101. #define L3GD20_AD_INT1_THS_XH 0x32
  102. #define L3GD20_AD_INT1_THS_XL 0x33
  103. #define L3GD20_AD_INT1_THS_YH 0x34
  104. #define L3GD20_AD_INT1_THS_YL 0x35
  105. #define L3GD20_AD_INT1_THS_ZH 0x36
  106. #define L3GD20_AD_INT1_THS_ZL 0x37
  107. #define L3GD20_AD_INT1_DURATION 0x38
  108. /** @} */
  109. /**
  110. * @name L3GD20_CTRL_REG1 register bits definitions
  111. * @{
  112. */
  113. #define L3GD20_CTRL_REG1_MASK 0xFF
  114. #define L3GD20_CTRL_REG1_XEN (1 << 0)
  115. #define L3GD20_CTRL_REG1_YEN (1 << 1)
  116. #define L3GD20_CTRL_REG1_ZEN (1 << 2)
  117. #define L3GD20_CTRL_REG1_PD (1 << 3)
  118. #define L3GD20_CTRL_REG1_BW0 (1 << 4)
  119. #define L3GD20_CTRL_REG1_BW1 (1 << 5)
  120. #define L3GD20_CTRL_REG1_DR0 (1 << 6)
  121. #define L3GD20_CTRL_REG1_DR1 (1 << 7)
  122. /** @} */
  123. /**
  124. * @name L3GD20_CTRL_REG2 register bits definitions
  125. * @{
  126. */
  127. #define L3GD20_CTRL_REG2_MASK 0x3F
  128. #define L3GD20_CTRL_REG2_HPCF0 (1 << 0)
  129. #define L3GD20_CTRL_REG2_HPCF1 (1 << 1)
  130. #define L3GD20_CTRL_REG2_HPCF2 (1 << 2)
  131. #define L3GD20_CTRL_REG2_HPCF3 (1 << 3)
  132. #define L3GD20_CTRL_REG2_HPM0 (1 << 4)
  133. #define L3GD20_CTRL_REG2_HPM1 (1 << 5)
  134. /** @} */
  135. /**
  136. * @name L3GD20_CTRL_REG3 register bits definitions
  137. * @{
  138. */
  139. #define L3GD20_CTRL_REG3_MASK 0xFF
  140. #define L3GD20_CTRL_REG3_I2_EMPTY (1 << 0)
  141. #define L3GD20_CTRL_REG3_I2_ORUN (1 << 1)
  142. #define L3GD20_CTRL_REG3_I2_WTM (1 << 2)
  143. #define L3GD20_CTRL_REG3_I2_DRDY (1 << 3)
  144. #define L3GD20_CTRL_REG3_PP_OD (1 << 4)
  145. #define L3GD20_CTRL_REG3_H_LACTIVE (1 << 5)
  146. #define L3GD20_CTRL_REG3_I1_BOOT (1 << 6)
  147. #define L3GD20_CTRL_REG3_I1_INT1 (1 << 7)
  148. /** @} */
  149. /**
  150. * @name L3GD20_CTRL_REG4 register bits definitions
  151. * @{
  152. */
  153. #define L3GD20_CTRL_REG4_MASK 0xF1
  154. #define L3GD20_CTRL_REG4_SIM (1 << 0)
  155. #define L3GD20_CTRL_REG4_FS_MASK 0x30
  156. #define L3GD20_CTRL_REG4_FS0 (1 << 4)
  157. #define L3GD20_CTRL_REG4_FS1 (1 << 5)
  158. #define L3GD20_CTRL_REG4_BLE (1 << 6)
  159. #define L3GD20_CTRL_REG4_BDU (1 << 7)
  160. /** @} */
  161. /**
  162. * @name L3GD20_CTRL_REG5 register bits definitions
  163. * @{
  164. */
  165. #define L3GD20_CTRL_REG5_MASK 0xDF
  166. #define L3GD20_CTRL_REG5_OUT_SEL0 (1 << 0)
  167. #define L3GD20_CTRL_REG5_OUT_SEL1 (1 << 1)
  168. #define L3GD20_CTRL_REG5_INT1_SEL0 (1 << 2)
  169. #define L3GD20_CTRL_REG5_INT1_SEL1 (1 << 3)
  170. #define L3GD20_CTRL_REG5_HPEN (1 << 4)
  171. #define L3GD20_CTRL_REG5_FIFO_EN (1 << 6)
  172. #define L3GD20_CTRL_REG5_BOOT (1 << 7)
  173. /** @} */
  174. /**
  175. * @name L3GD20_INT1_CFG register bits definitions
  176. * @{
  177. */
  178. #define L3GD20_INT1_CFG_MASK 0xFF
  179. #define L3GD20_INT1_CFG_XLIE (1 << 0)
  180. #define L3GD20_INT1_CFG_XHIE (1 << 1)
  181. #define L3GD20_INT1_CFG_YLIE (1 << 2)
  182. #define L3GD20_INT1_CFG_YHIE (1 << 3)
  183. #define L3GD20_INT1_CFG_ZLIE (1 << 4)
  184. #define L3GD20_INT1_CFG_ZHIE (1 << 5)
  185. #define L3GD20_INT1_CFG_LIR (1 << 6)
  186. #define L3GD20_INT1_CFG_AND_OR (1 << 7)
  187. /** @} */
  188. /**
  189. * @name L3GD20_INT1_SRC register bits definitions
  190. * @{
  191. */
  192. #define L3GD20_INT1_SRC_MASK 0x7F
  193. #define L3GD20_INT1_SRC_XL (1 << 0)
  194. #define L3GD20_INT1_SRC_XH (1 << 1)
  195. #define L3GD20_INT1_SRC_YL (1 << 2)
  196. #define L3GD20_INT1_SRC_YH (1 << 3)
  197. #define L3GD20_INT1_SRC_ZL (1 << 4)
  198. #define L3GD20_INT1_SRC_ZH (1 << 5)
  199. #define L3GD20_INT1_SRC_IA (1 << 6)
  200. /** @} */
  201. /*===========================================================================*/
  202. /* Driver pre-compile time settings. */
  203. /*===========================================================================*/
  204. /**
  205. * @name Configuration options
  206. * @{
  207. */
  208. /**
  209. * @brief L3GD20 SPI interface switch.
  210. * @details If set to @p TRUE the support for SPI is included.
  211. * @note The default is @p TRUE.
  212. */
  213. #if !defined(L3GD20_USE_SPI) || defined(__DOXYGEN__)
  214. #define L3GD20_USE_SPI TRUE
  215. #endif
  216. /**
  217. * @brief L3GD20 shared SPI switch.
  218. * @details If set to @p TRUE the device acquires SPI bus ownership
  219. * on each transaction.
  220. * @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION.
  221. */
  222. #if !defined(L3GD20_SHARED_SPI) || defined(__DOXYGEN__)
  223. #define L3GD20_SHARED_SPI FALSE
  224. #endif
  225. /**
  226. * @brief L3GD20 I2C interface switch.
  227. * @details If set to @p TRUE the support for I2C is included.
  228. * @note The default is @p FALSE.
  229. */
  230. #if !defined(L3GD20_USE_I2C) || defined(__DOXYGEN__)
  231. #define L3GD20_USE_I2C FALSE
  232. #endif
  233. /**
  234. * @brief L3GD20 shared I2C switch.
  235. * @details If set to @p TRUE the device acquires I2C bus ownership
  236. * on each transaction.
  237. * @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION.
  238. */
  239. #if !defined(L3GD20_SHARED_I2C) || defined(__DOXYGEN__)
  240. #define L3GD20_SHARED_I2C FALSE
  241. #endif
  242. /**
  243. * @brief L3GD20 advanced configurations switch.
  244. * @details If set to @p TRUE more configurations are available.
  245. * @note The default is @p FALSE.
  246. */
  247. #if !defined(L3GD20_USE_ADVANCED) || defined(__DOXYGEN__)
  248. #define L3GD20_USE_ADVANCED FALSE
  249. #endif
  250. /**
  251. * @brief Number of acquisitions for bias removal
  252. * @details This is the number of acquisitions performed to compute the
  253. * bias. A repetition is required in order to remove noise.
  254. */
  255. #if !defined(L3GD20_BIAS_ACQ_TIMES) || defined(__DOXYGEN__)
  256. #define L3GD20_BIAS_ACQ_TIMES 50
  257. #endif
  258. /**
  259. * @brief Settling time for bias removal
  260. * @details This is the time between each bias acquisition.
  261. */
  262. #if !defined(L3GD20_BIAS_SETTLING_US) || defined(__DOXYGEN__)
  263. #define L3GD20_BIAS_SETTLING_US 5000
  264. #endif
  265. /** @} */
  266. /*===========================================================================*/
  267. /* Derived constants and error checks. */
  268. /*===========================================================================*/
  269. #if !(L3GD20_USE_SPI ^ L3GD20_USE_I2C)
  270. #error "L3GD20_USE_SPI and L3GD20_USE_I2C cannot be both true or both false"
  271. #endif
  272. #if L3GD20_USE_SPI && !HAL_USE_SPI
  273. #error "L3GD20_USE_SPI requires HAL_USE_SPI"
  274. #endif
  275. #if L3GD20_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
  276. #error "L3GD20_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
  277. #endif
  278. #if L3GD20_USE_I2C && !HAL_USE_I2C
  279. #error "L3GD20_USE_I2C requires HAL_USE_I2C"
  280. #endif
  281. #if L3GD20_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
  282. #error "L3GD20_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
  283. #endif
  284. /**
  285. * @todo Add support for L3GD20 over I2C.
  286. */
  287. #if L3GD20_USE_I2C
  288. #error "L3GD20 over I2C still not supported"
  289. #endif
  290. /*===========================================================================*/
  291. /* Driver data structures and types. */
  292. /*===========================================================================*/
  293. /**
  294. * @name L3GD20 data structures and types.
  295. * @{
  296. */
  297. /**
  298. * @brief Structure representing a L3GD20 driver.
  299. */
  300. typedef struct L3GD20Driver L3GD20Driver;
  301. /**
  302. * @brief L3GD20 full scale.
  303. */
  304. typedef enum {
  305. L3GD20_FS_250DPS = 0x00, /**< Full scale 250 degree per second. */
  306. L3GD20_FS_500DPS = 0x10, /**< Full scale 500 degree per second. */
  307. L3GD20_FS_2000DPS = 0x20 /**< Full scale 2000 degree per second. */
  308. } l3gd20_fs_t;
  309. /**
  310. * @brief L3GD20 output data rate and bandwidth.
  311. */
  312. typedef enum {
  313. L3GD20_ODR_95HZ = 0x00, /**< Output data rate 95 Hz. */
  314. L3GD20_ODR_190HZ = 0x40, /**< Output data rate 190 Hz. */
  315. L3GD20_ODR_380HZ = 0x80, /**< Output data rate 380 Hz. */
  316. L3GD20_ODR_760HZ = 0xC0 /**< Output data rate 760 Hz. */
  317. } l3gd20_odr_t;
  318. /**
  319. * @brief L3GD20 low pass filter 1 bandwidth.
  320. */
  321. typedef enum {
  322. L3GD20_BW0 = 0x00, /**< LPF1 bandwidth. Depends on ODR. */
  323. L3GD20_BW1 = 0x40, /**< LPF1 bandwidth. Depends on ODR. */
  324. L3GD20_BW2 = 0x80, /**< LPF1 bandwidth. Depends on ODR. */
  325. L3GD20_BW3 = 0xC0 /**< LPF1 bandwidth. Depends on ODR. */
  326. } l3gd20_bw_t;
  327. /**
  328. * @brief L3GD20 block data update.
  329. */
  330. typedef enum {
  331. L3GD20_BDU_CONTINUOUS = 0x00, /**< Block data continuously updated. */
  332. L3GD20_BDU_BLOCKED = 0x80 /**< Block data updated after reading. */
  333. } l3gd20_bdu_t;
  334. /**
  335. * @brief L3GD20 HP filter mode.
  336. */
  337. typedef enum {
  338. L3GD20_HPM_NORMAL = 0x00, /**< Normal mode. */
  339. L3GD20_HPM_REFERENCE = 0x10, /**< Reference signal for filtering. */
  340. L3GD20_HPM_AUTORESET = 0x30, /**< Autoreset on interrupt event. */
  341. L3GD20_HPM_BYPASSED = 0xFF /**< HP filter bypassed */
  342. } l3gd20_hpm_t;
  343. /**
  344. * @brief L3GD20 HP configuration.
  345. */
  346. typedef enum {
  347. L3GD20_HPCF_0 = 0x00, /**< Depends on ODR (Table 26 for more).*/
  348. L3GD20_HPCF_1 = 0x01, /**< Depends on ODR (Table 26 for more).*/
  349. L3GD20_HPCF_2 = 0x02, /**< Depends on ODR (Table 26 for more).*/
  350. L3GD20_HPCF_3 = 0x03, /**< Depends on ODR (Table 26 for more).*/
  351. L3GD20_HPCF_4 = 0x04, /**< Depends on ODR (Table 26 for more).*/
  352. L3GD20_HPCF_5 = 0x05, /**< Depends on ODR (Table 26 for more).*/
  353. L3GD20_HPCF_6 = 0x06, /**< Depends on ODR (Table 26 for more).*/
  354. L3GD20_HPCF_7 = 0x07, /**< Depends on ODR (Table 26 for more).*/
  355. L3GD20_HPCF_8 = 0x08, /**< Depends on ODR (Table 26 for more).*/
  356. L3GD20_HPCF_9 = 0x09 /**< Depends on ODR (Table 26 for more).*/
  357. } l3gd20_hpcf_t;
  358. /**
  359. * @brief L3GD20 LP2 filter mode.
  360. * @details To activate LP2 HP should be active
  361. */
  362. typedef enum {
  363. L3GD20_LP2M_ON = 0x00, /**< LP2 filter activated. */
  364. L3GD20_LP2M_BYPASSED = 0xFF, /**< LP2 filter bypassed. */
  365. } l3gd20_lp2m_t;
  366. /**
  367. * @brief L3GD20 endianness.
  368. */
  369. typedef enum {
  370. L3GD20_END_LITTLE = 0x00, /**< Little endian. */
  371. L3GD20_END_BIG = 0x40 /**< Big endian. */
  372. } l3gd20_end_t;
  373. /**
  374. * @brief Driver state machine possible states.
  375. */
  376. typedef enum {
  377. L3GD20_UNINIT = 0, /**< Not initialized. */
  378. L3GD20_STOP = 1, /**< Stopped. */
  379. L3GD20_READY = 2 /**< Ready. */
  380. } l3gd20_state_t;
  381. /**
  382. * @brief L3GD20 configuration structure.
  383. */
  384. typedef struct {
  385. #if L3GD20_USE_SPI || defined(__DOXYGEN__)
  386. /**
  387. * @brief SPI driver associated to this L3GD20.
  388. */
  389. SPIDriver *spip;
  390. /**
  391. * @brief SPI configuration associated to this L3GD20.
  392. */
  393. const SPIConfig *spicfg;
  394. #endif /* L3GD20_USE_SPI */
  395. #if L3GD20_USE_I2C || defined(__DOXYGEN__)
  396. /**
  397. * @brief I2C driver associated to this L3GD20.
  398. */
  399. I2CDriver *i2cp;
  400. /**
  401. * @brief I2C configuration associated to this L3GD20.
  402. */
  403. const I2CConfig *i2ccfg;
  404. #endif /* L3GD20_USE_I2C */
  405. /**
  406. * @brief L3GD20 gyroscope system initial sensitivity.
  407. */
  408. float *gyrosensitivity;
  409. /**
  410. * @brief L3GD20 gyroscope system initial bias.
  411. */
  412. float *gyrobias;
  413. /**
  414. * @brief L3GD20 gyroscope system initial full scale value.
  415. */
  416. l3gd20_fs_t gyrofullscale;
  417. /**
  418. * @brief L3GD20 gyroscope system output data rate selection.
  419. */
  420. l3gd20_odr_t gyrooutputdatarate;
  421. #if L3GD20_USE_ADVANCED || defined(__DOXYGEN__)
  422. /**
  423. * @brief L3GD20 gyroscope system block data update.
  424. */
  425. l3gd20_bdu_t gyroblockdataupdate;
  426. /**
  427. * @brief L3GD20 gyroscope system endianness.
  428. */
  429. l3gd20_end_t gyroendianness;
  430. /**
  431. * @brief L3GD20 gyroscope system LP1 filter bandwidth.
  432. */
  433. l3gd20_bw_t gyrobandwidth;
  434. /**
  435. * @brief L3GD20 gyroscope system HP filter mode.
  436. */
  437. l3gd20_hpm_t gyrohpmode;
  438. /**
  439. * @brief L3GD20 gyroscope system HP configuration.
  440. */
  441. l3gd20_hpcf_t gyrohpconfiguration;
  442. /**
  443. * @brief L3GD20 gyroscope system LP2 filter mode.
  444. * @details To activate LP2 HP should be active
  445. */
  446. l3gd20_lp2m_t gyrolp2mode;
  447. #endif
  448. } L3GD20Config;
  449. /**
  450. * @brief @p L3GD20 specific methods.
  451. */
  452. #define _l3gd20_methods_alone \
  453. /* Change full scale value of L3GD20.*/ \
  454. msg_t (*gyro_set_full_scale)(L3GD20Driver *devp, l3gd20_fs_t fs);
  455. /**
  456. * @brief @p L3GD20 specific methods with inherited ones.
  457. */
  458. #define _l3gd20_methods \
  459. _base_object_methods \
  460. _l3gd20_methods_alone
  461. /**
  462. * @extends BaseObjectVMT
  463. *
  464. * @brief @p L3GD20 virtual methods table.
  465. */
  466. struct L3GD20VMT {
  467. _l3gd20_methods
  468. };
  469. /**
  470. * @brief @p L3GD20Driver specific data.
  471. */
  472. #define _l3gd20_data \
  473. _base_sensor_data \
  474. /* Driver state.*/ \
  475. l3gd20_state_t state; \
  476. /* Current configuration data.*/ \
  477. const L3GD20Config *config; \
  478. /* Gyroscope subsystem axes number.*/ \
  479. size_t gyroaxes; \
  480. /* Gyroscope subsystem current sensitivity.*/ \
  481. float gyrosensitivity[L3GD20_GYRO_NUMBER_OF_AXES]; \
  482. /* Gyroscope subsystem current Bias.*/ \
  483. float gyrobias[L3GD20_GYRO_NUMBER_OF_AXES]; \
  484. /* Gyroscope subsystem current full scale value.*/ \
  485. float gyrofullscale;
  486. /**
  487. * @brief L3GD20 3-axis gyroscope class.
  488. */
  489. struct L3GD20Driver {
  490. /** @brief Virtual Methods Table. */
  491. const struct L3GD20VMT *vmt;
  492. /** @brief Base gyroscope interface.*/
  493. BaseGyroscope gyro_if;
  494. _l3gd20_data
  495. };
  496. /** @} */
  497. /*===========================================================================*/
  498. /* Driver macros. */
  499. /*===========================================================================*/
  500. /**
  501. * @brief Return the number of axes of the BaseGyroscope.
  502. *
  503. * @param[in] devp pointer to @p L3GD20Driver.
  504. *
  505. * @return the number of axes.
  506. *
  507. * @api
  508. */
  509. #define l3gd20GyroscopeGetAxesNumber(devp) \
  510. gyroscopeGetAxesNumber(&((devp)->gyro_if))
  511. /**
  512. * @brief Retrieves raw data from the BaseGyroscope.
  513. * @note This data is retrieved from MEMS register without any algebraical
  514. * manipulation.
  515. * @note The axes array must be at least the same size of the
  516. * BaseGyroscope axes number.
  517. *
  518. * @param[in] devp pointer to @p L3GD20Driver.
  519. * @param[out] axes a buffer which would be filled with raw data.
  520. *
  521. * @return The operation status.
  522. * @retval MSG_OK if the function succeeded.
  523. *
  524. * @api
  525. */
  526. #define l3gd20GyroscopeReadRaw(devp, axes) \
  527. gyroscopeReadRaw(&((devp)->gyro_if), axes)
  528. /**
  529. * @brief Retrieves cooked data from the BaseGyroscope.
  530. * @note This data is manipulated according to the formula
  531. * cooked = (raw * sensitivity) - bias.
  532. * @note Final data is expressed as DPS.
  533. * @note The axes array must be at least the same size of the
  534. * BaseGyroscope axes number.
  535. *
  536. * @param[in] devp pointer to @p L3GD20Driver.
  537. * @param[out] axes a buffer which would be filled with cooked data.
  538. *
  539. * @return The operation status.
  540. * @retval MSG_OK if the function succeeded.
  541. *
  542. * @api
  543. */
  544. #define l3gd20GyroscopeReadCooked(devp, axes) \
  545. gyroscopeReadCooked(&((devp)->gyro_if), axes)
  546. /**
  547. * @brief Samples bias values for the BaseGyroscope.
  548. * @note The L3GD20 shall not be moved during the whole procedure.
  549. * @note After this function internal bias is automatically updated.
  550. * @note The behavior of this function depends on @p L3GD20_BIAS_ACQ_TIMES
  551. * and @p L3GD20_BIAS_SETTLING_US.
  552. *
  553. * @param[in] devp pointer to @p L3GD20Driver.
  554. *
  555. * @return The operation status.
  556. * @retval MSG_OK if the function succeeded.
  557. *
  558. * @api
  559. */
  560. #define l3gd20GyroscopeSampleBias(devp) \
  561. gyroscopeSampleBias(&((devp)->gyro_if))
  562. /**
  563. * @brief Set bias values for the BaseGyroscope.
  564. * @note Bias must be expressed as DPS.
  565. * @note The bias buffer must be at least the same size of the BaseGyroscope
  566. * axes number.
  567. *
  568. * @param[in] devp pointer to @p L3GD20Driver.
  569. * @param[in] bp a buffer which contains biases.
  570. *
  571. * @return The operation status.
  572. * @retval MSG_OK if the function succeeded.
  573. *
  574. * @api
  575. */
  576. #define l3gd20GyroscopeSetBias(devp, bp) \
  577. gyroscopeSetBias(&((devp)->gyro_if), bp)
  578. /**
  579. * @brief Reset bias values for the BaseGyroscope.
  580. * @note Default biases value are obtained from device datasheet when
  581. * available otherwise they are considered zero.
  582. *
  583. * @param[in] devp pointer to @p L3GD20Driver.
  584. *
  585. * @return The operation status.
  586. * @retval MSG_OK if the function succeeded.
  587. *
  588. * @api
  589. */
  590. #define l3gd20GyroscopeResetBias(devp) \
  591. gyroscopeResetBias(&((devp)->gyro_if))
  592. /**
  593. * @brief Set sensitivity values for the BaseGyroscope.
  594. * @note Sensitivity must be expressed as DPS/LSB.
  595. * @note The sensitivity buffer must be at least the same size of the
  596. * BaseGyroscope axes number.
  597. *
  598. * @param[in] devp pointer to @p L3GD20Driver.
  599. * @param[in] sp a buffer which contains sensitivities.
  600. *
  601. * @return The operation status.
  602. * @retval MSG_OK if the function succeeded.
  603. *
  604. * @api
  605. */
  606. #define l3gd20GyroscopeSetSensitivity(devp, sp) \
  607. gyroscopeSetSensitivity(&((devp)->gyro_if), sp)
  608. /**
  609. * @brief Reset sensitivity values for the BaseGyroscope.
  610. * @note Default sensitivities value are obtained from device datasheet.
  611. *
  612. * @param[in] devp pointer to @p L3GD20Driver.
  613. *
  614. * @return The operation status.
  615. * @retval MSG_OK if the function succeeded.
  616. * @retval MSG_RESET otherwise.
  617. *
  618. * @api
  619. */
  620. #define l3gd20GyroscopeResetSensitivity(devp) \
  621. gyroscopeResetSensitivity(&((devp)->gyro_if))
  622. /**
  623. * @brief Changes the L3GD20Driver gyroscope fullscale value.
  624. * @note This function also rescale sensitivities and biases based on
  625. * previous and next fullscale value.
  626. * @note A recalibration is highly suggested after calling this function.
  627. *
  628. * @param[in] devp pointer to @p L3GD20Driver.
  629. * @param[in] fs new fullscale value.
  630. *
  631. * @return The operation status.
  632. * @retval MSG_OK if the function succeeded.
  633. * @retval MSG_RESET otherwise.
  634. *
  635. * @api
  636. */
  637. #define l3gd20GyroscopeSetFullScale(devp, fs) \
  638. (devp)->vmt->acc_set_full_scale(devp, fs)
  639. /*===========================================================================*/
  640. /* External declarations. */
  641. /*===========================================================================*/
  642. #ifdef __cplusplus
  643. extern "C" {
  644. #endif
  645. void l3gd20ObjectInit(L3GD20Driver *devp);
  646. void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config);
  647. void l3gd20Stop(L3GD20Driver *devp);
  648. #ifdef __cplusplus
  649. }
  650. #endif
  651. #endif /* _L3GD20_H_ */
  652. /** @} */