ChibiOS  19.1.4
lis3dsh.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 lis3dsh.h
23  * @brief LIS3DSH MEMS interface module header.
24  *
25  * @addtogroup LIS3DSH
26  * @ingroup EX_ST
27  * @{
28  */
29 
30 #ifndef _LIS3DSH_H_
31 #define _LIS3DSH_H_
32 
33 #include "hal_accelerometer.h"
34 
35 /*===========================================================================*/
36 /* Driver constants. */
37 /*===========================================================================*/
38 
39 /**
40  * @name Version identification
41  * @{
42  */
43 /**
44  * @brief LIS3DSH driver version string.
45  */
46 #define EX_LIS3DSH_VERSION "1.1.2"
47 
48 /**
49  * @brief LIS3DSH driver version major number.
50  */
51 #define EX_LIS3DSH_MAJOR 1
52 
53 /**
54  * @brief LIS3DSH driver version minor number.
55  */
56 #define EX_LIS3DSH_MINOR 1
57 
58 /**
59  * @brief LIS3DSH driver version patch number.
60  */
61 #define EX_LIS3DSH_PATCH 2
62 /** @} */
63 
64 /**
65  * @brief LIS3DSH 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 LIS3DSH_ACC_NUMBER_OF_AXES 3U
73 
74 #define LIS3DSH_ACC_2G 2.0f
75 #define LIS3DSH_ACC_4G 4.0f
76 #define LIS3DSH_ACC_6G 6.0f
77 #define LIS3DSH_ACC_8G 8.0f
78 #define LIS3DSH_ACC_16G 16.0f
79 
80 #define LIS3DSH_ACC_SENS_2G 0.06f
81 #define LIS3DSH_ACC_SENS_4G 0.12f
82 #define LIS3DSH_ACC_SENS_6G 0.18f
83 #define LIS3DSH_ACC_SENS_8G 0.24f
84 #define LIS3DSH_ACC_SENS_16G 0.73f
85 
86 #define LIS3DSH_ACC_BIAS 0.0f
87 /** @} */
88 
89 /**
90  * @name LIS3DSH communication interfaces related bit masks
91  * @{
92  */
93 #define LIS3DSH_DI_MASK 0xFF
94 #define LIS3DSH_DI(n) (1 << n)
95 #define LIS3DSH_AD_MASK 0x3F
96 #define LIS3DSH_AD(n) (1 << n)
97 #define LIS3DSH_MS (1 << 6)
98 #define LIS3DSH_RW (1 << 7)
99 /** @} */
100 
101 /**
102  * @name LIS3DSH register addresses
103  * @{
104  */
105 #define LIS3DSH_AD_OUT_T 0x0C
106 #define LIS3DSH_AD_INFO1 0x0D
107 #define LIS3DSH_AD_INFO2 0x0E
108 #define LIS3DSH_AD_WHO_AM_I 0x0F
109 #define LIS3DSH_AD_OFF_X 0x10
110 #define LIS3DSH_AD_OFF_Y 0x11
111 #define LIS3DSH_AD_OFF_Z 0x12
112 #define LIS3DSH_AD_CS_X 0x13
113 #define LIS3DSH_AD_CS_Y 0x14
114 #define LIS3DSH_AD_CS_Z 0x15
115 #define LIS3DSH_AD_LC_L 0x16
116 #define LIS3DSH_AD_LC_H 0x17
117 #define LIS3DSH_AD_STAT 0x18
118 #define LIS3DSH_AD_PEAK1 0x19
119 #define LIS3DSH_AD_PEAK2 0x1A
120 #define LIS3DSH_AD_VFC_1 0x1B
121 #define LIS3DSH_AD_VFC_2 0x1C
122 #define LIS3DSH_AD_VFC_3 0x1D
123 #define LIS3DSH_AD_VFC_4 0x1E
124 #define LIS3DSH_AD_THRS3 0x1F
125 #define LIS3DSH_AD_CTRL_REG4 0x20
126 #define LIS3DSH_AD_CTRL_REG1 0x21
127 #define LIS3DSH_AD_CTRL_REG2 0x22
128 #define LIS3DSH_AD_CTRL_REG3 0x23
129 #define LIS3DSH_AD_CTRL_REG5 0x24
130 #define LIS3DSH_AD_CTRL_REG6 0x25
131 #define LIS3DSH_AD_STATUS 0x27
132 #define LIS3DSH_AD_OUT_X_L 0x28
133 #define LIS3DSH_AD_OUT_X_H 0x29
134 #define LIS3DSH_AD_OUT_Y_L 0x2A
135 #define LIS3DSH_AD_OUT_Y_H 0x2B
136 #define LIS3DSH_AD_OUT_Z_L 0x2C
137 #define LIS3DSH_AD_OUT_Z_H 0x2D
138 #define LIS3DSH_AD_FIFO_CTRL 0x2E
139 #define LIS3DSH_AD_FIFO_SRC 0x2F
140 #define LIS3DSH_AD_ST1_0 0x40
141 #define LIS3DSH_AD_ST1_1 0x41
142 #define LIS3DSH_AD_ST1_2 0x42
143 #define LIS3DSH_AD_ST1_3 0x43
144 #define LIS3DSH_AD_ST1_4 0x44
145 #define LIS3DSH_AD_ST1_5 0x45
146 #define LIS3DSH_AD_ST1_6 0x46
147 #define LIS3DSH_AD_ST1_7 0x47
148 #define LIS3DSH_AD_ST1_8 0x48
149 #define LIS3DSH_AD_ST1_9 0x49
150 #define LIS3DSH_AD_ST1_A 0x4A
151 #define LIS3DSH_AD_ST1_B 0x4B
152 #define LIS3DSH_AD_ST1_C 0x4C
153 #define LIS3DSH_AD_ST1_D 0x4D
154 #define LIS3DSH_AD_ST1_E 0x4E
155 #define LIS3DSH_AD_ST1_F 0x4F
156 #define LIS3DSH_AD_TIM4_1 0x50
157 #define LIS3DSH_AD_TIM3_1 0x51
158 #define LIS3DSH_AD_TIM2_1_L 0x52
159 #define LIS3DSH_AD_TIM2_1_H 0x53
160 #define LIS3DSH_AD_TIM1_1_L 0x54
161 #define LIS3DSH_AD_TIM1_1_H 0x55
162 #define LIS3DSH_AD_THRS2_1 0x56
163 #define LIS3DSH_AD_THRS1_1 0x57
164 #define LIS3DSH_AD_MASK1_B 0x59
165 #define LIS3DSH_AD_MASK1_A 0x5A
166 #define LIS3DSH_AD_SETT1 0x5B
167 #define LIS3DSH_AD_PR1 0x5C
168 #define LIS3DSH_AD_TC1_L 0x5D
169 #define LIS3DSH_AD_TC1_H 0x5E
170 #define LIS3DSH_AD_OUTS1 0x5F
171 #define LIS3DSH_AD_ST2_0 0x60
172 #define LIS3DSH_AD_ST2_1 0x61
173 #define LIS3DSH_AD_ST2_2 0x62
174 #define LIS3DSH_AD_ST2_3 0x63
175 #define LIS3DSH_AD_ST2_4 0x64
176 #define LIS3DSH_AD_ST2_5 0x65
177 #define LIS3DSH_AD_ST2_6 0x66
178 #define LIS3DSH_AD_ST2_7 0x67
179 #define LIS3DSH_AD_ST2_8 0x68
180 #define LIS3DSH_AD_ST2_9 0x69
181 #define LIS3DSH_AD_ST2_A 0x6A
182 #define LIS3DSH_AD_ST2_B 0x6B
183 #define LIS3DSH_AD_ST2_C 0x6C
184 #define LIS3DSH_AD_ST2_D 0x6D
185 #define LIS3DSH_AD_ST2_E 0x6E
186 #define LIS3DSH_AD_ST2_F 0x6F
187 #define LIS3DSH_AD_TIM4_2 0x70
188 #define LIS3DSH_AD_TIM3_2 0x71
189 #define LIS3DSH_AD_TIM2_2_L 0x72
190 #define LIS3DSH_AD_TIM2_2_H 0x73
191 #define LIS3DSH_AD_TIM1_2_L 0x74
192 #define LIS3DSH_AD_TIM1_2_H 0x75
193 #define LIS3DSH_AD_THRS2_2 0x76
194 #define LIS3DSH_AD_THRS1_2 0x77
195 #define LIS3DSH_AD_DES2 0x78
196 #define LIS3DSH_AD_MASK2_B 0x79
197 #define LIS3DSH_AD_MASK2_A 0x7A
198 #define LIS3DSH_AD_SETT2 0x7B
199 #define LIS3DSH_AD_PR2 0x7C
200 #define LIS3DSH_AD_TC2_L 0x7D
201 #define LIS3DSH_AD_TC2_H 0x7E
202 #define LIS3DSH_AD_OUTS2 0x7F
203 /** @} */
204 
205 /**
206  * @name LIS3DSH_CTRL_REG1 register bits definitions
207  * @{
208  */
209 #define LIS3DSH_CTRL_REG1_MASK 0xE9
210 #define LIS3DSH_CTRL_REG1_SM1_EN (1 << 0)
211 #define LIS3DSH_CTRL_REG1_SM1_PIN (1 << 3)
212 #define LIS3DSH_CTRL_REG1_HYST0_1 (1 << 5)
213 #define LIS3DSH_CTRL_REG1_HYST1_1 (1 << 6)
214 #define LIS3DSH_CTRL_REG1_HYST2_1 (1 << 7)
215 /** @} */
216 
217 /**
218  * @name LIS3DSH_CTRL_REG2 register bits definitions
219  * @{
220  */
221 #define LIS3DSH_CTRL_REG2_MASK 0xE9
222 #define LIS3DSH_CTRL_REG2_SM2_EN (1 << 0)
223 #define LIS3DSH_CTRL_REG2_SM2_PIN (1 << 3)
224 #define LIS3DSH_CTRL_REG2_HYST0_2 (1 << 5)
225 #define LIS3DSH_CTRL_REG2_HYST1_2 (1 << 6)
226 #define LIS3DSH_CTRL_REG2_HYST2_2 (1 << 7)
227 /** @} */
228 
229 /**
230  * @name LIS3DSH_CTRL_REG3 register bits definitions
231  * @{
232  */
233 #define LIS3DSH_CTRL_REG3_MASK 0xFF
234 #define LIS3DSH_CTRL_REG3_STRT (1 << 0)
235 #define LIS3DSH_CTRL_REG3_VFILT (1 << 2)
236 #define LIS3DSH_CTRL_REG3_INT1_EN (1 << 3)
237 #define LIS3DSH_CTRL_REG3_INT2_EN (1 << 4)
238 #define LIS3DSH_CTRL_REG3_IEL (1 << 5)
239 #define LIS3DSH_CTRL_REG3_IEA (1 << 6)
240 #define LIS3DSH_CTRL_REG3_DR_EN (1 << 7)
241 /** @} */
242 
243 /**
244  * @name LIS3DSH_CTRL_REG4 register bits definitions
245  * @{
246  */
247 #define LIS3DSH_CTRL_REG4_MASK 0xFF
248 #define LIS3DSH_CTRL_REG4_XEN (1 << 0)
249 #define LIS3DSH_CTRL_REG4_YEN (1 << 1)
250 #define LIS3DSH_CTRL_REG4_ZEN (1 << 2)
251 #define LIS3DSH_CTRL_REG4_BDU (1 << 3)
252 #define LIS3DSH_CTRL_REG4_ODR_0 (1 << 4)
253 #define LIS3DSH_CTRL_REG4_ODR_1 (1 << 5)
254 #define LIS3DSH_CTRL_REG4_ODR_2 (1 << 6)
255 #define LIS3DSH_CTRL_REG4_ODR_3 (1 << 7)
256 /** @} */
257 
258 /**
259  * @name LIS3DSH_CTRL_REG5 register bits definitions
260  * @{
261  */
262 #define LIS3DSH_CTRL_REG5_MASK 0xFF
263 #define LIS3DSH_CTRL_REG5_SIM (1 << 0)
264 #define LIS3DSH_CTRL_REG5_ST1 (1 << 1)
265 #define LIS3DSH_CTRL_REG5_ST2 (1 << 2)
266 #define LIS3DSH_CTRL_REG5_FS_MASK 0x38
267 #define LIS3DSH_CTRL_REG5_FS0 (1 << 3)
268 #define LIS3DSH_CTRL_REG5_FS1 (1 << 4)
269 #define LIS3DSH_CTRL_REG5_FS2 (1 << 5)
270 #define LIS3DSH_CTRL_REG5_BW1 (1 << 6)
271 #define LIS3DSH_CTRL_REG5_BW2 (1 << 7)
272 /** @} */
273 
274 /**
275  * @name LIS3DSH_CTRL_REG6 register bits definitions
276  * @{
277  */
278 #define LIS3DSH_CTRL_REG6_MASK 0xFF
279 #define LIS3DSH_CTRL_REG6_P2_BOOT (1 << 0)
280 #define LIS3DSH_CTRL_REG6_P1_OVRUN (1 << 1)
281 #define LIS3DSH_CTRL_REG6_P1_WTM (1 << 2)
282 #define LIS3DSH_CTRL_REG6_P1_EMPTY (1 << 3)
283 #define LIS3DSH_CTRL_REG6_ADD_INC (1 << 4)
284 #define LIS3DSH_CTRL_REG6_WTM_EN (1 << 5)
285 #define LIS3DSH_CTRL_REG6_FIFO_EN (1 << 6)
286 #define LIS3DSH_CTRL_REG6_BOOT (1 << 7)
287 /** @} */
288 
289 /*===========================================================================*/
290 /* Driver pre-compile time settings. */
291 /*===========================================================================*/
292 
293 /**
294  * @name Configuration options
295  * @{
296  */
297 /**
298  * @brief LIS3DSH SPI interface switch.
299  * @details If set to @p TRUE the support for SPI is included.
300  * @note The default is @p TRUE.
301  */
302 #if !defined(LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
303 #define LIS3DSH_USE_SPI TRUE
304 #endif
305 
306 /**
307  * @brief LIS3DSH shared SPI switch.
308  * @details If set to @p TRUE the device acquires SPI bus ownership
309  * on each transaction.
310  * @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION.
311  */
312 #if !defined(LIS3DSH_SHARED_SPI) || defined(__DOXYGEN__)
313 #define LIS3DSH_SHARED_SPI FALSE
314 #endif
315 
316 /**
317  * @brief LIS3DSH I2C interface switch.
318  * @details If set to @p TRUE the support for I2C is included.
319  * @note The default is @p FALSE.
320  */
321 #if !defined(LIS3DSH_USE_I2C) || defined(__DOXYGEN__)
322 #define LIS3DSH_USE_I2C FALSE
323 #endif
324 
325 /**
326  * @brief LIS3DSH shared I2C switch.
327  * @details If set to @p TRUE the device acquires I2C bus ownership
328  * on each transaction.
329  * @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION.
330  */
331 #if !defined(LIS3DSH_SHARED_I2C) || defined(__DOXYGEN__)
332 #define LIS3DSH_SHARED_I2C FALSE
333 #endif
334 
335 /**
336  * @brief LIS3DSH advanced configurations switch.
337  * @details If set to @p TRUE more configurations are available.
338  * @note The default is @p FALSE.
339  */
340 #if !defined(LIS3DSH_USE_ADVANCED) || defined(__DOXYGEN__)
341 #define LIS3DSH_USE_ADVANCED FALSE
342 #endif
343 /** @} */
344 
345 /*===========================================================================*/
346 /* Derived constants and error checks. */
347 /*===========================================================================*/
348 
349 #if !(LIS3DSH_USE_SPI ^ LIS3DSH_USE_I2C)
350 #error "LIS3DSH_USE_SPI and LIS3DSH_USE_I2C cannot be both true or both false"
351 #endif
352 
353 #if LIS3DSH_USE_SPI && !HAL_USE_SPI
354 #error "LIS3DSH_USE_SPI requires HAL_USE_SPI"
355 #endif
356 
357 #if LIS3DSH_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
358 #error "LIS3DSH_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
359 #endif
360 
361 #if LIS3DSH_USE_I2C && !HAL_USE_I2C
362 #error "LIS3DSH_USE_I2C requires HAL_USE_I2C"
363 #endif
364 
365 #if LIS3DSH_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
366 #error "LIS3DSH_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
367 #endif
368 
369 /**
370  * @todo Add support for LIS3DSH over I2C.
371  */
372 #if LIS3DSH_USE_I2C
373 #error "LIS3DSH over I2C still not supported"
374 #endif
375 
376 /*===========================================================================*/
377 /* Driver data structures and types. */
378 /*===========================================================================*/
379 
380 /**
381  * @name LIS3DSH data structures and types
382  * @{
383  */
384 /**
385  * @brief Structure representing a LIS3DSH driver.
386  */
388 
389 /**
390  * @brief LIS3DSH full scale.
391  */
392 typedef enum {
393  LIS3DSH_ACC_FS_2G = 0x00, /**< Full scale ±2g. */
394  LIS3DSH_ACC_FS_4G = 0x08, /**< Full scale ±4g. */
395  LIS3DSH_ACC_FS_6G = 0x10, /**< Full scale ±6g. */
396  LIS3DSH_ACC_FS_8G = 0x18, /**< Full scale ±8g. */
397  LIS3DSH_ACC_FS_16G = 0x20 /**< Full scale ±16g. */
399 
400 /**
401  * @brief LIS3DSH output data rate.
402  */
403 typedef enum {
404  LIS3DSH_ACC_ODR_PD = 0x00, /**< ODR 100 Hz. */
405  LIS3DSH_ACC_ODR_3_125HZ = 0x10, /**< ODR 3.125 Hz. */
406  LIS3DSH_ACC_ODR_6_25HZ = 0x20, /**< ODR 6.25 Hz. */
407  LIS3DSH_ACC_ODR_12_5HZ = 0x30, /**< ODR 12.5 Hz. */
408  LIS3DSH_ACC_ODR_25HZ = 0x40, /**< ODR 25 Hz. */
409  LIS3DSH_ACC_ODR_50HZ = 0x50, /**< ODR 50 Hz. */
410  LIS3DSH_ACC_ODR_100HZ = 0x60, /**< ODR 100 Hz. */
411  LIS3DSH_ACC_ODR_400HZ = 0x70, /**< ODR 400 Hz. */
412  LIS3DSH_ACC_ODR_800HZ = 0x80, /**< ODR 800 Hz. */
413  LIS3DSH_ACC_ODR_1600HZ = 0x90 /**< ODR 1600 Hz. */
415 
416 /**
417  * @brief LIS3DSH anti-aliasing bandwidth.
418  */
419 typedef enum {
420  LIS3DSH_ACC_BW_800HZ = 0x00, /**< AA filter BW 800Hz. */
421  LIS3DSH_ACC_BW_200HZ = 0x40, /**< AA filter BW 200Hz. */
422  LIS3DSH_ACC_BW_400HZ = 0x80, /**< AA filter BW 400Hz. */
423  LIS3DSH_ACC_BW_50HZ = 0xC0 /**< AA filter BW 50Hz. */
425 
426 /**
427  * @brief LIS3DSH block data update.
428  */
429 typedef enum {
430  LIS3DSH_ACC_BDU_CONTINUOUS = 0x00,/**< Block data continuously updated. */
431  LIS3DSH_ACC_BDU_BLOCKED = 0x80 /**< Block data updated after reading. */
433 
434 /**
435  * @brief Driver state machine possible states.
436  */
437 typedef enum {
438  LIS3DSH_UNINIT = 0, /**< Not initialized. */
439  LIS3DSH_STOP = 1, /**< Stopped. */
440  LIS3DSH_READY = 2, /**< Ready. */
442 
443 /**
444  * @brief LIS3DSH configuration structure.
445  */
446 typedef struct {
447 
448 #if (LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
449  /**
450  * @brief SPI driver associated to this LIS3DSH.
451  */
453  /**
454  * @brief SPI configuration associated to this LIS3DSH.
455  */
457 #endif /* LIS3DSH_USE_SPI */
458 #if (LIS3DSH_USE_I2C) || defined(__DOXYGEN__)
459  /**
460  * @brief I2C driver associated to this LIS3DSH.
461  */
463  /**
464  * @brief I2C configuration associated to this LIS3DSH.
465  */
467 #endif /* LIS3DSH_USE_I2C */
468  /**
469  * @brief LIS3DSH accelerometer subsystem initial sensitivity.
470  */
472  /**
473  * @brief LIS3DSH accelerometer subsystem initial bias.
474  */
475  float *accbias;
476  /**
477  * @brief LIS3DSH accelerometer subsystem initial full scale.
478  */
480  /**
481  * @brief LIS3DSH output data rate selection.
482  */
484 #if LIS3DSH_USE_ADVANCED || defined(__DOXYGEN__)
485  /**
486  * @brief LIS3DSH anti-aliasing bandwidth.
487  */
489  /**
490  * @brief LIS3DSH block data update.
491  */
493 #endif
494 } LIS3DSHConfig;
495 
496 /**
497  * @brief @p LIS3DSH specific methods.
498  */
499 #define _lis3dsh_methods_alone \
500  /* Change full scale value of LIS3DSH accelerometer subsystem.*/ \
501  msg_t (*acc_set_full_scale)(LIS3DSHDriver *devp, lis3dsh_acc_fs_t fs);
502 
503 
504 /**
505  * @brief @p LIS3DSH specific methods with inherited ones.
506  */
507 #define _lis3dsh_methods \
508  _base_object_methods \
509  _lis3dsh_methods_alone
510 
511 /**
512  * @extends BaseObjectVMT
513  *
514  * @brief @p LIS3DSH virtual methods table.
515  */
516 struct LIS3DSHVMT {
518 };
519 
520 /**
521  * @brief @p LIS3DSHDriver specific data.
522  */
523 #define _lis3dsh_data \
524  _base_sensor_data \
525  /* Driver state.*/ \
526  lis3dsh_state_t state; \
527  /* Current configuration data.*/ \
528  const LIS3DSHConfig *config; \
529  /* Accelerometer subsystem axes number.*/ \
530  size_t accaxes; \
531  /* Accelerometer subsystem current sensitivity.*/ \
532  float accsensitivity[LIS3DSH_ACC_NUMBER_OF_AXES]; \
533  /* Accelerometer subsystem current bias .*/ \
534  float accbias[LIS3DSH_ACC_NUMBER_OF_AXES]; \
535  /* Accelerometer subsystem current full scale value.*/ \
536  float accfullscale;
537 
538 /**
539  * @brief LIS3DSH 3-axis accelerometer class.
540  */
542  /** @brief Virtual Methods Table.*/
543  const struct LIS3DSHVMT *vmt;
544  /** @brief Base accelerometer interface.*/
547 };
548 /** @} */
549 
550 /*===========================================================================*/
551 /* Driver macros. */
552 /*===========================================================================*/
553 
554 /**
555  * @brief Return the number of axes of the BaseAccelerometer.
556  *
557  * @param[in] devp pointer to @p LIS3DSHDriver.
558  *
559  * @return the number of axes.
560  *
561  * @api
562  */
563 #define lis3dshAccelerometerGetAxesNumber(devp) \
564  accelerometerGetAxesNumber(&((devp)->acc_if))
565 
566 /**
567  * @brief Retrieves raw data from the BaseAccelerometer.
568  * @note This data is retrieved from MEMS register without any algebraical
569  * manipulation.
570  * @note The axes array must be at least the same size of the
571  * BaseAccelerometer axes number.
572  *
573  * @param[in] devp pointer to @p LIS3DSHDriver.
574  * @param[out] axes a buffer which would be filled with raw data.
575  *
576  * @return The operation status.
577  * @retval MSG_OK if the function succeeded.
578  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
579  * be retrieved using @p i2cGetErrors().
580  * @retval MSG_TIMEOUT if a timeout occurred before operation end.
581  *
582  * @api
583  */
584 #define lis3dshAccelerometerReadRaw(devp, axes) \
585  accelerometerReadRaw(&((devp)->acc_if), axes)
586 
587 /**
588  * @brief Retrieves cooked data from the BaseAccelerometer.
589  * @note This data is manipulated according to the formula
590  * cooked = (raw * sensitivity) - bias.
591  * @note Final data is expressed as milli-G.
592  * @note The axes array must be at least the same size of the
593  * BaseAccelerometer axes number.
594  *
595  * @param[in] devp pointer to @p LIS3DSHDriver.
596  * @param[out] axes a buffer which would be filled with cooked data.
597  *
598  * @return The operation status.
599  * @retval MSG_OK if the function succeeded.
600  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
601  * be retrieved using @p i2cGetErrors().
602  * @retval MSG_TIMEOUT if a timeout occurred before operation end.
603  *
604  * @api
605  */
606 #define lis3dshAccelerometerReadCooked(devp, axes) \
607  accelerometerReadCooked(&((devp)->acc_if), axes)
608 
609 /**
610  * @brief Set bias values for the BaseAccelerometer.
611  * @note Bias must be expressed as milli-G.
612  * @note The bias buffer must be at least the same size of the
613  * BaseAccelerometer axes number.
614  *
615  * @param[in] devp pointer to @p LIS3DSHDriver.
616  * @param[in] bp a buffer which contains biases.
617  *
618  * @return The operation status.
619  * @retval MSG_OK if the function succeeded.
620  *
621  * @api
622  */
623 #define lis3dshAccelerometerSetBias(devp, bp) \
624  accelerometerSetBias(&((devp)->acc_if), bp)
625 
626 /**
627  * @brief Reset bias values for the BaseAccelerometer.
628  * @note Default biases value are obtained from device datasheet when
629  * available otherwise they are considered zero.
630  *
631  * @param[in] devp pointer to @p LIS3DSHDriver.
632  *
633  * @return The operation status.
634  * @retval MSG_OK if the function succeeded.
635  *
636  * @api
637  */
638 #define lis3dshAccelerometerResetBias(devp) \
639  accelerometerResetBias(&((devp)->acc_if))
640 
641 /**
642  * @brief Set sensitivity values for the BaseAccelerometer.
643  * @note Sensitivity must be expressed as milli-G/LSB.
644  * @note The sensitivity buffer must be at least the same size of the
645  * BaseAccelerometer axes number.
646  *
647  * @param[in] devp pointer to @p LIS3DSHDriver.
648  * @param[in] sp a buffer which contains sensitivities.
649  *
650  * @return The operation status.
651  * @retval MSG_OK if the function succeeded.
652  *
653  * @api
654  */
655 #define lis3dshAccelerometerSetSensitivity(devp, sp) \
656  accelerometerSetSensitivity(&((devp)->acc_if), sp)
657 
658 /**
659  * @brief Reset sensitivity values for the BaseAccelerometer.
660  * @note Default sensitivities value are obtained from device datasheet.
661  *
662  * @param[in] devp pointer to @p LIS3DSHDriver.
663  *
664  * @return The operation status.
665  * @retval MSG_OK if the function succeeded.
666  * @retval MSG_RESET otherwise.
667  *
668  * @api
669  */
670 #define lis3dshAccelerometerResetSensitivity(devp) \
671  accelerometerResetSensitivity(&((devp)->acc_if))
672 
673 /**
674  * @brief Changes the LIS3DSHDriver accelerometer fullscale value.
675  * @note This function also rescale sensitivities and biases based on
676  * previous and next fullscale value.
677  * @note A recalibration is highly suggested after calling this function.
678  *
679  * @param[in] devp pointer to @p LIS3DSHDriver.
680  * @param[in] fs new fullscale value.
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 lis3dshAccelerometerSetFullScale(devp, fs) \
689  (devp)->vmt->acc_set_full_scale(devp, fs)
690 
691 /*===========================================================================*/
692 /* External declarations. */
693 /*===========================================================================*/
694 
695 #ifdef __cplusplus
696 extern "C" {
697 #endif
698  void lis3dshObjectInit(LIS3DSHDriver *devp);
699  void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config);
700  void lis3dshStop(LIS3DSHDriver *devp);
701 #ifdef __cplusplus
702 }
703 #endif
704 
705 #endif /* _LIS3DSH_H_ */
706 
707 /** @} */
708 
const struct LIS3DSHVMT * vmt
Virtual Methods Table.
Definition: lis3dsh.h:543
lis3dsh_acc_bw_t accantialiasing
LIS3DSH anti-aliasing bandwidth.
Definition: lis3dsh.h:488
lis3dsh_acc_bdu_t
LIS3DSH block data update.
Definition: lis3dsh.h:429
I2CDriver * i2cp
I2C driver associated to this LIS3DSH.
Definition: lis3dsh.h:462
Type of I2C driver configuration structure.
Definition: hal_i2c_lld.h:75
const I2CConfig * i2ccfg
I2C configuration associated to this LIS3DSH.
Definition: lis3dsh.h:466
lis3dsh_acc_fs_t
LIS3DSH full scale.
Definition: lis3dsh.h:392
lis3dsh_state_t
Driver state machine possible states.
Definition: lis3dsh.h:437
lis3dsh_acc_fs_t accfullscale
LIS3DSH accelerometer subsystem initial full scale.
Definition: lis3dsh.h:479
BaseAccelerometer acc_if
Base accelerometer interface.
Definition: lis3dsh.h:545
const SPIConfig * spicfg
SPI configuration associated to this LIS3DSH.
Definition: lis3dsh.h:456
void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config)
Configures and activates LIS3DSH Complex Driver peripheral.
Definition: lis3dsh.c:467
LIS3DSH 3-axis accelerometer class.
Definition: lis3dsh.h:541
void lis3dshObjectInit(LIS3DSHDriver *devp)
Initializes an instance.
Definition: lis3dsh.c:448
lis3dsh_acc_odr_t
LIS3DSH output data rate.
Definition: lis3dsh.h:403
float * accbias
LIS3DSH accelerometer subsystem initial bias.
Definition: lis3dsh.h:475
lis3dsh_acc_odr_t accoutputdatarate
LIS3DSH output data rate selection.
Definition: lis3dsh.h:483
Structure representing an I2C driver.
Definition: hal_i2c_lld.h:88
Structure representing an SPI driver.
Definition: hal_spi.h:192
float * accsensitivity
LIS3DSH accelerometer subsystem initial sensitivity.
Definition: lis3dsh.h:471
lis3dsh_acc_bw_t
LIS3DSH anti-aliasing bandwidth.
Definition: lis3dsh.h:419
Generic accelerometer interface header.
#define _lis3dsh_data
LIS3DSHDriver specific data.
Definition: lis3dsh.h:523
lis3dsh_acc_bdu_t accblockdataupdate
LIS3DSH block data update.
Definition: lis3dsh.h:492
SPIDriver * spip
SPI driver associated to this LIS3DSH.
Definition: lis3dsh.h:452
Driver configuration structure.
Definition: hal_spi.h:148
void lis3dshStop(LIS3DSHDriver *devp)
Deactivates the LIS3DSH Complex Driver peripheral.
Definition: lis3dsh.c:613
LIS3DSH virtual methods table.
Definition: lis3dsh.h:516
#define _lis3dsh_methods
LIS3DSH specific methods with inherited ones.
Definition: lis3dsh.h:507
Base accelerometer class.
LIS3DSH configuration structure.
Definition: lis3dsh.h:446