diff options
Diffstat (limited to 'lib/chibios/os/ex/devices/ST/l3gd20.h')
-rw-r--r-- | lib/chibios/os/ex/devices/ST/l3gd20.h | 725 |
1 files changed, 725 insertions, 0 deletions
diff --git a/lib/chibios/os/ex/devices/ST/l3gd20.h b/lib/chibios/os/ex/devices/ST/l3gd20.h new file mode 100644 index 000000000..5528ecc05 --- /dev/null +++ b/lib/chibios/os/ex/devices/ST/l3gd20.h | |||
@@ -0,0 +1,725 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2016..2019 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 "ex_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.2" | ||
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 2 | ||
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 advanced configurations switch. | ||
275 | * @details If set to @p TRUE more configurations are available. | ||
276 | * @note The default is @p FALSE. | ||
277 | */ | ||
278 | #if !defined(L3GD20_USE_ADVANCED) || defined(__DOXYGEN__) | ||
279 | #define L3GD20_USE_ADVANCED FALSE | ||
280 | #endif | ||
281 | |||
282 | /** | ||
283 | * @brief Number of acquisitions for bias removal | ||
284 | * @details This is the number of acquisitions performed to compute the | ||
285 | * bias. A repetition is required in order to remove noise. | ||
286 | */ | ||
287 | #if !defined(L3GD20_BIAS_ACQ_TIMES) || defined(__DOXYGEN__) | ||
288 | #define L3GD20_BIAS_ACQ_TIMES 50 | ||
289 | #endif | ||
290 | |||
291 | /** | ||
292 | * @brief Settling time for bias removal | ||
293 | * @details This is the time between each bias acquisition. | ||
294 | */ | ||
295 | #if !defined(L3GD20_BIAS_SETTLING_US) || defined(__DOXYGEN__) | ||
296 | #define L3GD20_BIAS_SETTLING_US 5000 | ||
297 | #endif | ||
298 | /** @} */ | ||
299 | |||
300 | /*===========================================================================*/ | ||
301 | /* Derived constants and error checks. */ | ||
302 | /*===========================================================================*/ | ||
303 | |||
304 | #if !(L3GD20_USE_SPI ^ L3GD20_USE_I2C) | ||
305 | #error "L3GD20_USE_SPI and L3GD20_USE_I2C cannot be both true or both false" | ||
306 | #endif | ||
307 | |||
308 | #if L3GD20_USE_SPI && !HAL_USE_SPI | ||
309 | #error "L3GD20_USE_SPI requires HAL_USE_SPI" | ||
310 | #endif | ||
311 | |||
312 | #if L3GD20_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION | ||
313 | #error "L3GD20_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION" | ||
314 | #endif | ||
315 | |||
316 | #if L3GD20_USE_I2C && !HAL_USE_I2C | ||
317 | #error "L3GD20_USE_I2C requires HAL_USE_I2C" | ||
318 | #endif | ||
319 | |||
320 | #if L3GD20_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION | ||
321 | #error "L3GD20_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION" | ||
322 | #endif | ||
323 | |||
324 | /* | ||
325 | * CHTODO: Add support for L3GD20 over I2C. | ||
326 | */ | ||
327 | #if L3GD20_USE_I2C | ||
328 | #error "L3GD20 over I2C still not supported" | ||
329 | #endif | ||
330 | |||
331 | /*===========================================================================*/ | ||
332 | /* Driver data structures and types. */ | ||
333 | /*===========================================================================*/ | ||
334 | |||
335 | /** | ||
336 | * @name L3GD20 data structures and types. | ||
337 | * @{ | ||
338 | */ | ||
339 | /** | ||
340 | * @brief Structure representing a L3GD20 driver. | ||
341 | */ | ||
342 | typedef struct L3GD20Driver L3GD20Driver; | ||
343 | |||
344 | /** | ||
345 | * @brief L3GD20 full scale. | ||
346 | */ | ||
347 | typedef enum { | ||
348 | L3GD20_FS_250DPS = 0x00, /**< Full scale 250 degree per second. */ | ||
349 | L3GD20_FS_500DPS = 0x10, /**< Full scale 500 degree per second. */ | ||
350 | L3GD20_FS_2000DPS = 0x20 /**< Full scale 2000 degree per second. */ | ||
351 | } l3gd20_fs_t; | ||
352 | |||
353 | /** | ||
354 | * @brief L3GD20 output data rate and bandwidth. | ||
355 | */ | ||
356 | typedef enum { | ||
357 | L3GD20_ODR_95HZ = 0x00, /**< Output data rate 95 Hz. */ | ||
358 | L3GD20_ODR_190HZ = 0x40, /**< Output data rate 190 Hz. */ | ||
359 | L3GD20_ODR_380HZ = 0x80, /**< Output data rate 380 Hz. */ | ||
360 | L3GD20_ODR_760HZ = 0xC0 /**< Output data rate 760 Hz. */ | ||
361 | } l3gd20_odr_t; | ||
362 | |||
363 | /** | ||
364 | * @brief L3GD20 low pass filter 1 bandwidth. | ||
365 | */ | ||
366 | typedef enum { | ||
367 | L3GD20_BW0 = 0x00, /**< LPF1 bandwidth. Depends on ODR. */ | ||
368 | L3GD20_BW1 = 0x40, /**< LPF1 bandwidth. Depends on ODR. */ | ||
369 | L3GD20_BW2 = 0x80, /**< LPF1 bandwidth. Depends on ODR. */ | ||
370 | L3GD20_BW3 = 0xC0 /**< LPF1 bandwidth. Depends on ODR. */ | ||
371 | } l3gd20_bw_t; | ||
372 | |||
373 | /** | ||
374 | * @brief L3GD20 block data update. | ||
375 | */ | ||
376 | typedef enum { | ||
377 | L3GD20_BDU_CONTINUOUS = 0x00, /**< Block data continuously updated. */ | ||
378 | L3GD20_BDU_BLOCKED = 0x80 /**< Block data updated after reading. */ | ||
379 | } l3gd20_bdu_t; | ||
380 | |||
381 | /** | ||
382 | * @brief L3GD20 HP filter mode. | ||
383 | */ | ||
384 | typedef enum { | ||
385 | L3GD20_HPM_NORMAL = 0x00, /**< Normal mode. */ | ||
386 | L3GD20_HPM_REFERENCE = 0x10, /**< Reference signal for filtering. */ | ||
387 | L3GD20_HPM_AUTORESET = 0x30, /**< Autoreset on interrupt event. */ | ||
388 | L3GD20_HPM_BYPASSED = 0xFF /**< HP filter bypassed */ | ||
389 | } l3gd20_hpm_t; | ||
390 | |||
391 | /** | ||
392 | * @brief L3GD20 HP configuration. | ||
393 | */ | ||
394 | typedef enum { | ||
395 | L3GD20_HPCF_0 = 0x00, /**< Depends on ODR (Table 26 for more).*/ | ||
396 | L3GD20_HPCF_1 = 0x01, /**< Depends on ODR (Table 26 for more).*/ | ||
397 | L3GD20_HPCF_2 = 0x02, /**< Depends on ODR (Table 26 for more).*/ | ||
398 | L3GD20_HPCF_3 = 0x03, /**< Depends on ODR (Table 26 for more).*/ | ||
399 | L3GD20_HPCF_4 = 0x04, /**< Depends on ODR (Table 26 for more).*/ | ||
400 | L3GD20_HPCF_5 = 0x05, /**< Depends on ODR (Table 26 for more).*/ | ||
401 | L3GD20_HPCF_6 = 0x06, /**< Depends on ODR (Table 26 for more).*/ | ||
402 | L3GD20_HPCF_7 = 0x07, /**< Depends on ODR (Table 26 for more).*/ | ||
403 | L3GD20_HPCF_8 = 0x08, /**< Depends on ODR (Table 26 for more).*/ | ||
404 | L3GD20_HPCF_9 = 0x09 /**< Depends on ODR (Table 26 for more).*/ | ||
405 | } l3gd20_hpcf_t; | ||
406 | |||
407 | /** | ||
408 | * @brief L3GD20 LP2 filter mode. | ||
409 | * @details To activate LP2 HP should be active | ||
410 | */ | ||
411 | typedef enum { | ||
412 | L3GD20_LP2M_ON = 0x00, /**< LP2 filter activated. */ | ||
413 | L3GD20_LP2M_BYPASSED = 0xFF, /**< LP2 filter bypassed. */ | ||
414 | } l3gd20_lp2m_t; | ||
415 | |||
416 | /** | ||
417 | * @brief L3GD20 endianness. | ||
418 | */ | ||
419 | typedef enum { | ||
420 | L3GD20_END_LITTLE = 0x00, /**< Little endian. */ | ||
421 | L3GD20_END_BIG = 0x40 /**< Big endian. */ | ||
422 | } l3gd20_end_t; | ||
423 | |||
424 | /** | ||
425 | * @brief Driver state machine possible states. | ||
426 | */ | ||
427 | typedef enum { | ||
428 | L3GD20_UNINIT = 0, /**< Not initialized. */ | ||
429 | L3GD20_STOP = 1, /**< Stopped. */ | ||
430 | L3GD20_READY = 2 /**< Ready. */ | ||
431 | } l3gd20_state_t; | ||
432 | |||
433 | /** | ||
434 | * @brief L3GD20 configuration structure. | ||
435 | */ | ||
436 | typedef struct { | ||
437 | |||
438 | #if L3GD20_USE_SPI || defined(__DOXYGEN__) | ||
439 | /** | ||
440 | * @brief SPI driver associated to this L3GD20. | ||
441 | */ | ||
442 | SPIDriver *spip; | ||
443 | /** | ||
444 | * @brief SPI configuration associated to this L3GD20. | ||
445 | */ | ||
446 | const SPIConfig *spicfg; | ||
447 | #endif /* L3GD20_USE_SPI */ | ||
448 | #if L3GD20_USE_I2C || defined(__DOXYGEN__) | ||
449 | /** | ||
450 | * @brief I2C driver associated to this L3GD20. | ||
451 | */ | ||
452 | I2CDriver *i2cp; | ||
453 | /** | ||
454 | * @brief I2C configuration associated to this L3GD20. | ||
455 | */ | ||
456 | const I2CConfig *i2ccfg; | ||
457 | #endif /* L3GD20_USE_I2C */ | ||
458 | /** | ||
459 | * @brief L3GD20 gyroscope system initial sensitivity. | ||
460 | */ | ||
461 | float *gyrosensitivity; | ||
462 | /** | ||
463 | * @brief L3GD20 gyroscope system initial bias. | ||
464 | */ | ||
465 | float *gyrobias; | ||
466 | /** | ||
467 | * @brief L3GD20 gyroscope system initial full scale value. | ||
468 | */ | ||
469 | l3gd20_fs_t gyrofullscale; | ||
470 | /** | ||
471 | * @brief L3GD20 gyroscope system output data rate selection. | ||
472 | */ | ||
473 | l3gd20_odr_t gyrooutputdatarate; | ||
474 | #if L3GD20_USE_ADVANCED || defined(__DOXYGEN__) | ||
475 | /** | ||
476 | * @brief L3GD20 gyroscope system block data update. | ||
477 | */ | ||
478 | l3gd20_bdu_t gyroblockdataupdate; | ||
479 | /** | ||
480 | * @brief L3GD20 gyroscope system endianness. | ||
481 | */ | ||
482 | l3gd20_end_t gyroendianness; | ||
483 | /** | ||
484 | * @brief L3GD20 gyroscope system LP1 filter bandwidth. | ||
485 | */ | ||
486 | l3gd20_bw_t gyrobandwidth; | ||
487 | /** | ||
488 | * @brief L3GD20 gyroscope system HP filter mode. | ||
489 | */ | ||
490 | l3gd20_hpm_t gyrohpmode; | ||
491 | /** | ||
492 | * @brief L3GD20 gyroscope system HP configuration. | ||
493 | */ | ||
494 | l3gd20_hpcf_t gyrohpconfiguration; | ||
495 | /** | ||
496 | * @brief L3GD20 gyroscope system LP2 filter mode. | ||
497 | * @details To activate LP2 HP should be active | ||
498 | */ | ||
499 | l3gd20_lp2m_t gyrolp2mode; | ||
500 | #endif | ||
501 | } L3GD20Config; | ||
502 | |||
503 | /** | ||
504 | * @brief @p L3GD20 specific methods. | ||
505 | */ | ||
506 | #define _l3gd20_methods_alone \ | ||
507 | /* Change full scale value of L3GD20.*/ \ | ||
508 | msg_t (*gyro_set_full_scale)(L3GD20Driver *devp, l3gd20_fs_t fs); | ||
509 | |||
510 | /** | ||
511 | * @brief @p L3GD20 specific methods with inherited ones. | ||
512 | */ | ||
513 | #define _l3gd20_methods \ | ||
514 | _base_object_methods \ | ||
515 | _l3gd20_methods_alone | ||
516 | |||
517 | /** | ||
518 | * @extends BaseObjectVMT | ||
519 | * | ||
520 | * @brief @p L3GD20 virtual methods table. | ||
521 | */ | ||
522 | struct L3GD20VMT { | ||
523 | _l3gd20_methods | ||
524 | }; | ||
525 | |||
526 | /** | ||
527 | * @brief @p L3GD20Driver specific data. | ||
528 | */ | ||
529 | #define _l3gd20_data \ | ||
530 | _base_sensor_data \ | ||
531 | /* Driver state.*/ \ | ||
532 | l3gd20_state_t state; \ | ||
533 | /* Current configuration data.*/ \ | ||
534 | const L3GD20Config *config; \ | ||
535 | /* Gyroscope subsystem axes number.*/ \ | ||
536 | size_t gyroaxes; \ | ||
537 | /* Gyroscope subsystem current sensitivity.*/ \ | ||
538 | float gyrosensitivity[L3GD20_GYRO_NUMBER_OF_AXES]; \ | ||
539 | /* Gyroscope subsystem current Bias.*/ \ | ||
540 | float gyrobias[L3GD20_GYRO_NUMBER_OF_AXES]; \ | ||
541 | /* Gyroscope subsystem current full scale value.*/ \ | ||
542 | float gyrofullscale; | ||
543 | |||
544 | /** | ||
545 | * @brief L3GD20 3-axis gyroscope class. | ||
546 | */ | ||
547 | struct L3GD20Driver { | ||
548 | /** @brief Virtual Methods Table. */ | ||
549 | const struct L3GD20VMT *vmt; | ||
550 | /** @brief Base gyroscope interface.*/ | ||
551 | BaseGyroscope gyro_if; | ||
552 | _l3gd20_data | ||
553 | }; | ||
554 | /** @} */ | ||
555 | |||
556 | /*===========================================================================*/ | ||
557 | /* Driver macros. */ | ||
558 | /*===========================================================================*/ | ||
559 | |||
560 | /** | ||
561 | * @brief Return the number of axes of the BaseGyroscope. | ||
562 | * | ||
563 | * @param[in] devp pointer to @p L3GD20Driver. | ||
564 | * | ||
565 | * @return the number of axes. | ||
566 | * | ||
567 | * @api | ||
568 | */ | ||
569 | #define l3gd20GyroscopeGetAxesNumber(devp) \ | ||
570 | gyroscopeGetAxesNumber(&((devp)->gyro_if)) | ||
571 | |||
572 | /** | ||
573 | * @brief Retrieves raw data from the BaseGyroscope. | ||
574 | * @note This data is retrieved from MEMS register without any algebraical | ||
575 | * manipulation. | ||
576 | * @note The axes array must be at least the same size of the | ||
577 | * BaseGyroscope axes number. | ||
578 | * | ||
579 | * @param[in] devp pointer to @p L3GD20Driver. | ||
580 | * @param[out] axes a buffer which would be filled with raw data. | ||
581 | * | ||
582 | * @return The operation status. | ||
583 | * @retval MSG_OK if the function succeeded. | ||
584 | * | ||
585 | * @api | ||
586 | */ | ||
587 | #define l3gd20GyroscopeReadRaw(devp, axes) \ | ||
588 | gyroscopeReadRaw(&((devp)->gyro_if), axes) | ||
589 | |||
590 | /** | ||
591 | * @brief Retrieves cooked data from the BaseGyroscope. | ||
592 | * @note This data is manipulated according to the formula | ||
593 | * cooked = (raw * sensitivity) - bias. | ||
594 | * @note Final data is expressed as DPS. | ||
595 | * @note The axes array must be at least the same size of the | ||
596 | * BaseGyroscope axes number. | ||
597 | * | ||
598 | * @param[in] devp pointer to @p L3GD20Driver. | ||
599 | * @param[out] axes a buffer which would be filled with cooked data. | ||
600 | * | ||
601 | * @return The operation status. | ||
602 | * @retval MSG_OK if the function succeeded. | ||
603 | * | ||
604 | * @api | ||
605 | */ | ||
606 | #define l3gd20GyroscopeReadCooked(devp, axes) \ | ||
607 | gyroscopeReadCooked(&((devp)->gyro_if), axes) | ||
608 | |||
609 | /** | ||
610 | * @brief Samples bias values for the BaseGyroscope. | ||
611 | * @note The L3GD20 shall not be moved during the whole procedure. | ||
612 | * @note After this function internal bias is automatically updated. | ||
613 | * @note The behavior of this function depends on @p L3GD20_BIAS_ACQ_TIMES | ||
614 | * and @p L3GD20_BIAS_SETTLING_US. | ||
615 | * | ||
616 | * @param[in] devp pointer to @p L3GD20Driver. | ||
617 | * | ||
618 | * @return The operation status. | ||
619 | * @retval MSG_OK if the function succeeded. | ||
620 | * | ||
621 | * @api | ||
622 | */ | ||
623 | #define l3gd20GyroscopeSampleBias(devp) \ | ||
624 | gyroscopeSampleBias(&((devp)->gyro_if)) | ||
625 | |||
626 | /** | ||
627 | * @brief Set bias values for the BaseGyroscope. | ||
628 | * @note Bias must be expressed as DPS. | ||
629 | * @note The bias buffer must be at least the same size of the BaseGyroscope | ||
630 | * axes number. | ||
631 | * | ||
632 | * @param[in] devp pointer to @p L3GD20Driver. | ||
633 | * @param[in] bp a buffer which contains biases. | ||
634 | * | ||
635 | * @return The operation status. | ||
636 | * @retval MSG_OK if the function succeeded. | ||
637 | * | ||
638 | * @api | ||
639 | */ | ||
640 | #define l3gd20GyroscopeSetBias(devp, bp) \ | ||
641 | gyroscopeSetBias(&((devp)->gyro_if), bp) | ||
642 | |||
643 | /** | ||
644 | * @brief Reset bias values for the BaseGyroscope. | ||
645 | * @note Default biases value are obtained from device datasheet when | ||
646 | * available otherwise they are considered zero. | ||
647 | * | ||
648 | * @param[in] devp pointer to @p L3GD20Driver. | ||
649 | * | ||
650 | * @return The operation status. | ||
651 | * @retval MSG_OK if the function succeeded. | ||
652 | * | ||
653 | * @api | ||
654 | */ | ||
655 | #define l3gd20GyroscopeResetBias(devp) \ | ||
656 | gyroscopeResetBias(&((devp)->gyro_if)) | ||
657 | |||
658 | /** | ||
659 | * @brief Set sensitivity values for the BaseGyroscope. | ||
660 | * @note Sensitivity must be expressed as DPS/LSB. | ||
661 | * @note The sensitivity buffer must be at least the same size of the | ||
662 | * BaseGyroscope axes number. | ||
663 | * | ||
664 | * @param[in] devp pointer to @p L3GD20Driver. | ||
665 | * @param[in] sp a buffer which contains sensitivities. | ||
666 | * | ||
667 | * @return The operation status. | ||
668 | * @retval MSG_OK if the function succeeded. | ||
669 | * | ||
670 | * @api | ||
671 | */ | ||
672 | #define l3gd20GyroscopeSetSensitivity(devp, sp) \ | ||
673 | gyroscopeSetSensitivity(&((devp)->gyro_if), sp) | ||
674 | |||
675 | /** | ||
676 | * @brief Reset sensitivity values for the BaseGyroscope. | ||
677 | * @note Default sensitivities value are obtained from device datasheet. | ||
678 | * | ||
679 | * @param[in] devp pointer to @p L3GD20Driver. | ||
680 | * | ||
681 | * @return The operation status. | ||
682 | * @retval MSG_OK if the function succeeded. | ||
683 | * @retval MSG_RESET otherwise. | ||
684 | * | ||
685 | * @api | ||
686 | */ | ||
687 | #define l3gd20GyroscopeResetSensitivity(devp) \ | ||
688 | gyroscopeResetSensitivity(&((devp)->gyro_if)) | ||
689 | |||
690 | /** | ||
691 | * @brief Changes the L3GD20Driver gyroscope fullscale value. | ||
692 | * @note This function also rescale sensitivities and biases based on | ||
693 | * previous and next fullscale value. | ||
694 | * @note A recalibration is highly suggested after calling this function. | ||
695 | * | ||
696 | * @param[in] devp pointer to @p L3GD20Driver. | ||
697 | * @param[in] fs new fullscale value. | ||
698 | * | ||
699 | * @return The operation status. | ||
700 | * @retval MSG_OK if the function succeeded. | ||
701 | * @retval MSG_RESET otherwise. | ||
702 | * | ||
703 | * @api | ||
704 | */ | ||
705 | #define l3gd20GyroscopeSetFullScale(devp, fs) \ | ||
706 | (devp)->vmt->acc_set_full_scale(devp, fs) | ||
707 | |||
708 | /*===========================================================================*/ | ||
709 | /* External declarations. */ | ||
710 | /*===========================================================================*/ | ||
711 | |||
712 | #ifdef __cplusplus | ||
713 | extern "C" { | ||
714 | #endif | ||
715 | void l3gd20ObjectInit(L3GD20Driver *devp); | ||
716 | void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config); | ||
717 | void l3gd20Stop(L3GD20Driver *devp); | ||
718 | #ifdef __cplusplus | ||
719 | } | ||
720 | #endif | ||
721 | |||
722 | #endif /* _L3GD20_H_ */ | ||
723 | |||
724 | /** @} */ | ||
725 | |||