ChibiOS  0.0.0
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.1"
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 1
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 accelerometer subsystem advanced configurations
337  * switch.
338  * @details If set to @p TRUE more configurations are available.
339  * @note The default is @p FALSE.
340  */
341 #if !defined(LIS3DSH_ACC_USE_ADVANCED) || defined(__DOXYGEN__)
342 #define LIS3DSH_ACC_USE_ADVANCED FALSE
343 #endif
344 /** @} */
345 
346 /*===========================================================================*/
347 /* Derived constants and error checks. */
348 /*===========================================================================*/
349 
350 #if !(LIS3DSH_USE_SPI ^ LIS3DSH_USE_I2C)
351 #error "LIS3DSH_USE_SPI and LIS3DSH_USE_I2C cannot be both true or both false"
352 #endif
353 
354 #if LIS3DSH_USE_SPI && !HAL_USE_SPI
355 #error "LIS3DSH_USE_SPI requires HAL_USE_SPI"
356 #endif
357 
358 #if LIS3DSH_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
359 #error "LIS3DSH_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
360 #endif
361 
362 #if LIS3DSH_USE_I2C && !HAL_USE_I2C
363 #error "LIS3DSH_USE_I2C requires HAL_USE_I2C"
364 #endif
365 
366 #if LIS3DSH_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
367 #error "LIS3DSH_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
368 #endif
369 
370 /**
371  * @todo Add support for LIS3DSH over I2C.
372  */
373 #if LIS3DSH_USE_I2C
374 #error "LIS3DSH over I2C still not supported"
375 #endif
376 
377 /*===========================================================================*/
378 /* Driver data structures and types. */
379 /*===========================================================================*/
380 
381 /**
382  * @name LIS3DSH data structures and types
383  * @{
384  */
385 /**
386  * @brief Structure representing a LIS3DSH driver.
387  */
389 
390 /**
391  * @brief LIS3DSH full scale.
392  */
393 typedef enum {
394  LIS3DSH_ACC_FS_2G = 0x00, /**< Full scale ±2g. */
395  LIS3DSH_ACC_FS_4G = 0x08, /**< Full scale ±4g. */
396  LIS3DSH_ACC_FS_6G = 0x10, /**< Full scale ±6g. */
397  LIS3DSH_ACC_FS_8G = 0x18, /**< Full scale ±8g. */
398  LIS3DSH_ACC_FS_16G = 0x20 /**< Full scale ±16g. */
400 
401 /**
402  * @brief LIS3DSH output data rate.
403  */
404 typedef enum {
405  LIS3DSH_ACC_ODR_PD = 0x00, /**< ODR 100 Hz. */
406  LIS3DSH_ACC_ODR_3_125HZ = 0x10, /**< ODR 3.125 Hz. */
407  LIS3DSH_ACC_ODR_6_25HZ = 0x20, /**< ODR 6.25 Hz. */
408  LIS3DSH_ACC_ODR_12_5HZ = 0x30, /**< ODR 12.5 Hz. */
409  LIS3DSH_ACC_ODR_25HZ = 0x40, /**< ODR 25 Hz. */
410  LIS3DSH_ACC_ODR_50HZ = 0x50, /**< ODR 50 Hz. */
411  LIS3DSH_ACC_ODR_100HZ = 0x60, /**< ODR 100 Hz. */
412  LIS3DSH_ACC_ODR_400HZ = 0x70, /**< ODR 400 Hz. */
413  LIS3DSH_ACC_ODR_800HZ = 0x80, /**< ODR 800 Hz. */
414  LIS3DSH_ACC_ODR_1600HZ = 0x90 /**< ODR 1600 Hz. */
416 
417 /**
418  * @brief LIS3DSH anti-aliasing bandwidth.
419  */
420 typedef enum {
421  LIS3DSH_ACC_BW_800HZ = 0x00, /**< AA filter BW 800Hz. */
422  LIS3DSH_ACC_BW_200HZ = 0x40, /**< AA filter BW 200Hz. */
423  LIS3DSH_ACC_BW_400HZ = 0x80, /**< AA filter BW 400Hz. */
424  LIS3DSH_ACC_BW_50HZ = 0xC0 /**< AA filter BW 50Hz. */
426 
427 /**
428  * @brief LIS3DSH block data update.
429  */
430 typedef enum {
431  LIS3DSH_ACC_BDU_CONTINUOUS = 0x00,/**< Block data continuously updated. */
432  LIS3DSH_ACC_BDU_BLOCKED = 0x80 /**< Block data updated after reading. */
434 
435 /**
436  * @brief Driver state machine possible states.
437  */
438 typedef enum {
439  LIS3DSH_UNINIT = 0, /**< Not initialized. */
440  LIS3DSH_STOP = 1, /**< Stopped. */
441  LIS3DSH_READY = 2, /**< Ready. */
443 
444 /**
445  * @brief LIS3DSH configuration structure.
446  */
447 typedef struct {
448 
449 #if (LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
450  /**
451  * @brief SPI driver associated to this LIS3DSH.
452  */
454  /**
455  * @brief SPI configuration associated to this LIS3DSH.
456  */
458 #endif /* LIS3DSH_USE_SPI */
459 #if (LIS3DSH_USE_I2C) || defined(__DOXYGEN__)
460  /**
461  * @brief I2C driver associated to this LIS3DSH.
462  */
464  /**
465  * @brief I2C configuration associated to this LIS3DSH.
466  */
468 #endif /* LIS3DSH_USE_I2C */
469  /**
470  * @brief LIS3DSH accelerometer subsystem initial sensitivity.
471  */
473  /**
474  * @brief LIS3DSH accelerometer subsystem initial bias.
475  */
476  float *accbias;
477  /**
478  * @brief LIS3DSH accelerometer subsystem initial full scale.
479  */
481  /**
482  * @brief LIS3DSH output data rate selection.
483  */
485 #if LIS3DSH_ACC_USE_ADVANCED || defined(__DOXYGEN__)
486  /**
487  * @brief LIS3DSH anti-aliasing bandwidth.
488  */
490  /**
491  * @brief LIS3DSH block data update.
492  */
494 #endif
495 } LIS3DSHConfig;
496 
497 /**
498  * @brief @p LIS3DSH specific methods.
499  */
500 #define _lis3dsh_methods_alone \
501  /* Change full scale value of LIS3DSH accelerometer subsystem.*/ \
502  msg_t (*acc_set_full_scale)(LIS3DSHDriver *devp, lis3dsh_acc_fs_t fs);
503 
504 
505 /**
506  * @brief @p LIS3DSH specific methods with inherited ones.
507  */
508 #define _lis3dsh_methods \
509  _base_object_methods \
510  _lis3dsh_methods_alone
511 
512 /**
513  * @extends BaseObjectVMT
514  *
515  * @brief @p LIS3DSH virtual methods table.
516  */
517 struct LIS3DSHVMT {
519 };
520 
521 /**
522  * @brief @p LIS3DSHDriver specific data.
523  */
524 #define _lis3dsh_data \
525  _base_sensor_data \
526  /* Driver state.*/ \
527  lis3dsh_state_t state; \
528  /* Current configuration data.*/ \
529  const LIS3DSHConfig *config; \
530  /* Accelerometer subsystem axes number.*/ \
531  size_t accaxes; \
532  /* Accelerometer subsystem current sensitivity.*/ \
533  float accsensitivity[LIS3DSH_ACC_NUMBER_OF_AXES]; \
534  /* Accelerometer subsystem current bias .*/ \
535  float accbias[LIS3DSH_ACC_NUMBER_OF_AXES]; \
536  /* Accelerometer subsystem current full scale value.*/ \
537  float accfullscale;
538 
539 /**
540  * @brief LIS3DSH 3-axis accelerometer class.
541  */
543  /** @brief Virtual Methods Table.*/
544  const struct LIS3DSHVMT *vmt;
545  /** @brief Base accelerometer interface.*/
548 };
549 /** @} */
550 
551 /*===========================================================================*/
552 /* Driver macros. */
553 /*===========================================================================*/
554 
555 /**
556  * @brief Return the number of axes of the BaseAccelerometer.
557  *
558  * @param[in] devp pointer to @p LIS3DSHDriver.
559  *
560  * @return the number of axes.
561  *
562  * @api
563  */
564 #define lis3dshAccelerometerGetAxesNumber(devp) \
565  accelerometerGetAxesNumber(&((devp)->acc_if))
566 
567 /**
568  * @brief Retrieves raw data from the BaseAccelerometer.
569  * @note This data is retrieved from MEMS register without any algebraical
570  * manipulation.
571  * @note The axes array must be at least the same size of the
572  * BaseAccelerometer axes number.
573  *
574  * @param[in] devp pointer to @p LIS3DSHDriver.
575  * @param[out] axes a buffer which would be filled with raw data.
576  *
577  * @return The operation status.
578  * @retval MSG_OK if the function succeeded.
579  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
580  * be retrieved using @p i2cGetErrors().
581  * @retval MSG_TIMEOUT if a timeout occurred before operation end.
582  *
583  * @api
584  */
585 #define lis3dshAccelerometerReadRaw(devp, axes) \
586  accelerometerReadRaw(&((devp)->acc_if), axes)
587 
588 /**
589  * @brief Retrieves cooked data from the BaseAccelerometer.
590  * @note This data is manipulated according to the formula
591  * cooked = (raw * sensitivity) - bias.
592  * @note Final data is expressed as milli-G.
593  * @note The axes array must be at least the same size of the
594  * BaseAccelerometer axes number.
595  *
596  * @param[in] devp pointer to @p LIS3DSHDriver.
597  * @param[out] axes a buffer which would be filled with cooked data.
598  *
599  * @return The operation status.
600  * @retval MSG_OK if the function succeeded.
601  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
602  * be retrieved using @p i2cGetErrors().
603  * @retval MSG_TIMEOUT if a timeout occurred before operation end.
604  *
605  * @api
606  */
607 #define lis3dshAccelerometerReadCooked(devp, axes) \
608  accelerometerReadCooked(&((devp)->acc_if), axes)
609 
610 /**
611  * @brief Set bias values for the BaseAccelerometer.
612  * @note Bias must be expressed as milli-G.
613  * @note The bias buffer must be at least the same size of the
614  * BaseAccelerometer axes number.
615  *
616  * @param[in] devp pointer to @p LIS3DSHDriver.
617  * @param[in] bp a buffer which contains biases.
618  *
619  * @return The operation status.
620  * @retval MSG_OK if the function succeeded.
621  *
622  * @api
623  */
624 #define lis3dshAccelerometerSetBias(devp, bp) \
625  accelerometerSetBias(&((devp)->acc_if), bp)
626 
627 /**
628  * @brief Reset bias values for the BaseAccelerometer.
629  * @note Default biases value are obtained from device datasheet when
630  * available otherwise they are considered zero.
631  *
632  * @param[in] devp pointer to @p LIS3DSHDriver.
633  *
634  * @return The operation status.
635  * @retval MSG_OK if the function succeeded.
636  *
637  * @api
638  */
639 #define lis3dshAccelerometerResetBias(devp) \
640  accelerometerResetBias(&((devp)->acc_if))
641 
642 /**
643  * @brief Set sensitivity values for the BaseAccelerometer.
644  * @note Sensitivity must be expressed as milli-G/LSB.
645  * @note The sensitivity buffer must be at least the same size of the
646  * BaseAccelerometer axes number.
647  *
648  * @param[in] devp pointer to @p LIS3DSHDriver.
649  * @param[in] sp a buffer which contains sensitivities.
650  *
651  * @return The operation status.
652  * @retval MSG_OK if the function succeeded.
653  *
654  * @api
655  */
656 #define lis3dshAccelerometerSetSensitivity(devp, sp) \
657  accelerometerSetSensitivity(&((devp)->acc_if), sp)
658 
659 /**
660  * @brief Reset sensitivity values for the BaseAccelerometer.
661  * @note Default sensitivities value are obtained from device datasheet.
662  *
663  * @param[in] devp pointer to @p LIS3DSHDriver.
664  *
665  * @return The operation status.
666  * @retval MSG_OK if the function succeeded.
667  * @retval MSG_RESET otherwise.
668  *
669  * @api
670  */
671 #define lis3dshAccelerometerResetSensitivity(devp) \
672  accelerometerResetSensitivity(&((devp)->acc_if))
673 
674 /**
675  * @brief Changes the LIS3DSHDriver accelerometer fullscale value.
676  * @note This function also rescale sensitivities and biases based on
677  * previous and next fullscale value.
678  * @note A recalibration is highly suggested after calling this function.
679  *
680  * @param[in] devp pointer to @p LIS3DSHDriver.
681  * @param[in] fs new fullscale value.
682  *
683  * @return The operation status.
684  * @retval MSG_OK if the function succeeded.
685  * @retval MSG_RESET otherwise.
686  *
687  * @api
688  */
689 #define lis3dshAccelerometerSetFullScale(devp, fs) \
690  (devp)->vmt->acc_set_full_scale(devp, fs)
691 
692 /*===========================================================================*/
693 /* External declarations. */
694 /*===========================================================================*/
695 
696 #ifdef __cplusplus
697 extern "C" {
698 #endif
699  void lis3dshObjectInit(LIS3DSHDriver *devp);
700  void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config);
701  void lis3dshStop(LIS3DSHDriver *devp);
702 #ifdef __cplusplus
703 }
704 #endif
705 
706 #endif /* _LIS3DSH_H_ */
707 
708 /** @} */
709 
const struct LIS3DSHVMT * vmt
Virtual Methods Table.
Definition: lis3dsh.h:544
lis3dsh_acc_bw_t accantialiasing
LIS3DSH anti-aliasing bandwidth.
Definition: lis3dsh.h:489
lis3dsh_acc_bdu_t
LIS3DSH block data update.
Definition: lis3dsh.h:430
I2CDriver * i2cp
I2C driver associated to this LIS3DSH.
Definition: lis3dsh.h:463
Type of I2C driver configuration structure.
Definition: hal_i2c_lld.h:75
const I2CConfig * i2ccfg
I2C configuration associated to this LIS3DSH.
Definition: lis3dsh.h:467
lis3dsh_acc_fs_t
LIS3DSH full scale.
Definition: lis3dsh.h:393
lis3dsh_state_t
Driver state machine possible states.
Definition: lis3dsh.h:438
lis3dsh_acc_fs_t accfullscale
LIS3DSH accelerometer subsystem initial full scale.
Definition: lis3dsh.h:480
BaseAccelerometer acc_if
Base accelerometer interface.
Definition: lis3dsh.h:546
const SPIConfig * spicfg
SPI configuration associated to this LIS3DSH.
Definition: lis3dsh.h:457
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:542
void lis3dshObjectInit(LIS3DSHDriver *devp)
Initializes an instance.
Definition: lis3dsh.c:448
lis3dsh_acc_odr_t
LIS3DSH output data rate.
Definition: lis3dsh.h:404
float * accbias
LIS3DSH accelerometer subsystem initial bias.
Definition: lis3dsh.h:476
lis3dsh_acc_odr_t accoutputdatarate
LIS3DSH output data rate selection.
Definition: lis3dsh.h:484
Structure representing an I2C driver.
Definition: hal_i2c_lld.h:88
float * accsensitivity
LIS3DSH accelerometer subsystem initial sensitivity.
Definition: lis3dsh.h:472
Driver configuration structure.
Definition: hal_spi_lld.h:83
lis3dsh_acc_bw_t
LIS3DSH anti-aliasing bandwidth.
Definition: lis3dsh.h:420
Generic accelerometer interface header.
#define _lis3dsh_data
LIS3DSHDriver specific data.
Definition: lis3dsh.h:524
lis3dsh_acc_bdu_t accblockdataupdate
LIS3DSH block data update.
Definition: lis3dsh.h:493
SPIDriver * spip
SPI driver associated to this LIS3DSH.
Definition: lis3dsh.h:453
void lis3dshStop(LIS3DSHDriver *devp)
Deactivates the LIS3DSH Complex Driver peripheral.
Definition: lis3dsh.c:613
LIS3DSH virtual methods table.
Definition: lis3dsh.h:517
#define _lis3dsh_methods
LIS3DSH specific methods with inherited ones.
Definition: lis3dsh.h:508
Base accelerometer class.
LIS3DSH configuration structure.
Definition: lis3dsh.h:447
Structure representing an SPI driver.
Definition: hal_spi_lld.h:128