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