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