ChibiOS 21.11.4
lis3dsh.c
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2016..2023 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.c
23 * @brief LIS3DSH MEMS interface module code.
24 *
25 * @addtogroup LIS3DSH
26 * @ingroup EX_ST
27 * @{
28 */
29
30#include "hal.h"
31#include "lis3dsh.h"
32
33/*===========================================================================*/
34/* Driver local definitions. */
35/*===========================================================================*/
36
37/*===========================================================================*/
38/* Driver exported variables. */
39/*===========================================================================*/
40
41/*===========================================================================*/
42/* Driver local variables and types. */
43/*===========================================================================*/
44
45/*===========================================================================*/
46/* Driver local functions. */
47/*===========================================================================*/
48
49#if (LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
50/**
51 * @brief Reads a generic register value using SPI.
52 * @pre The SPI interface must be initialized and the driver started.
53 * @note Multiple write/read requires proper settings in CTRL_REG6.
54 *
55 * @param[in] spip pointer to the SPI interface
56 * @param[in] reg starting register address
57 * @param[in] n number of adjacent registers to write
58 * @param[in] b pointer to a buffer.
59 */
60static void lis3dshSPIReadRegister(SPIDriver *spip, uint8_t reg, size_t n,
61 uint8_t* b) {
62 uint8_t cmd;
63 cmd = reg | LIS3DSH_RW;
64 spiSelect(spip);
65 spiSend(spip, 1, &cmd);
66 spiReceive(spip, n, b);
67 spiUnselect(spip);
68}
69
70/**
71 * @brief Writes a value into a generic register using SPI.
72 * @pre The SPI interface must be initialized and the driver started.
73 * @note Multiple write/read requires proper settings in CTRL_REG6.
74 *
75 * @param[in] spip pointer to the SPI interface
76 * @param[in] reg starting register address
77 * @param[in] n number of adjacent registers to write
78 * @param[in] b pointer to a buffer of values.
79 */
80static void lis3dshSPIWriteRegister(SPIDriver *spip, uint8_t reg, size_t n,
81 uint8_t* b) {
82 uint8_t cmd;
83 cmd = reg;
84 spiSelect(spip);
85 spiSend(spip, 1, &cmd);
86 spiSend(spip, n, b);
87 spiUnselect(spip);
88}
89#endif /* LIS3DSH_USE_SPI */
90
91/**
92 * @brief Return the number of axes of the BaseAccelerometer.
93 *
94 * @param[in] ip pointer to @p BaseAccelerometer interface.
95 *
96 * @return the number of axes.
97 */
98static size_t acc_get_axes_number(void *ip) {
99 (void)ip;
100
102}
103
104/**
105 * @brief Retrieves raw data from the BaseAccelerometer.
106 * @note This data is retrieved from MEMS register without any algebraical
107 * manipulation.
108 * @note The axes array must be at least the same size of the
109 * BaseAccelerometer axes number.
110 *
111 * @param[in] ip pointer to @p BaseAccelerometer interface.
112 * @param[out] axes a buffer which would be filled with raw data.
113 *
114 * @return The operation status.
115 * @retval MSG_OK if the function succeeded.
116 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
117 * be retrieved using @p i2cGetErrors().
118 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
119 */
120static msg_t acc_read_raw(void *ip, int32_t axes[]) {
121 LIS3DSHDriver* devp;
122 uint8_t buff [LIS3DSH_ACC_NUMBER_OF_AXES * 2], i;
123 int16_t tmp;
124 msg_t msg = MSG_OK;
125
126 osalDbgCheck((ip != NULL) && (axes != NULL));
127
128 /* Getting parent instance pointer.*/
130
131 osalDbgAssert((devp->state == LIS3DSH_READY),
132 "acc_read_raw(), invalid state");
133
134#if LIS3DSH_USE_SPI
135#if LIS3DSH_SHARED_SPI
136 osalDbgAssert((devp->config->spip->state == SPI_READY),
137 "acc_read_raw(), channel not ready");
138
139 spiAcquireBus(devp->config->spip);
140 spiStart(devp->config->spip,
141 devp->config->spicfg);
142#endif /* LIS3DSH_SHARED_SPI */
143
144 lis3dshSPIReadRegister(devp->config->spip, LIS3DSH_AD_OUT_X_L,
146
147#if LIS3DSH_SHARED_SPI
148 spiReleaseBus(devp->config->spip);
149#endif /* LIS3DSH_SHARED_SPI */
150#endif /* LIS3DSH_USE_SPI */
151
152 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++) {
153 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
154 axes[i] = (int32_t)tmp;
155 }
156 return msg;
157}
158
159/**
160 * @brief Retrieves cooked data from the BaseAccelerometer.
161 * @note This data is manipulated according to the formula
162 * cooked = (raw * sensitivity) - bias.
163 * @note Final data is expressed as milli-G.
164 * @note The axes array must be at least the same size of the
165 * BaseAccelerometer axes number.
166 *
167 * @param[in] ip pointer to @p BaseAccelerometer interface.
168 * @param[out] axes a buffer which would be filled with cooked data.
169 *
170 * @return The operation status.
171 * @retval MSG_OK if the function succeeded.
172 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
173 * be retrieved using @p i2cGetErrors().
174 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
175 */
176static msg_t acc_read_cooked(void *ip, float axes[]) {
177 LIS3DSHDriver* devp;
178 uint32_t i;
179 int32_t raw[LIS3DSH_ACC_NUMBER_OF_AXES];
180 msg_t msg;
181
182 osalDbgCheck((ip != NULL) && (axes != NULL));
183
184 /* Getting parent instance pointer.*/
186
187 osalDbgAssert((devp->state == LIS3DSH_READY),
188 "acc_read_cooked(), invalid state");
189
190 msg = acc_read_raw(ip, raw);
191 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++) {
192 axes[i] = (raw[i] * devp->accsensitivity[i]) - devp->accbias[i];
193 }
194 return msg;
195}
196
197/**
198 * @brief Set bias values for the BaseAccelerometer.
199 * @note Bias must be expressed as milli-G.
200 * @note The bias buffer must be at least the same size of the
201 * BaseAccelerometer axes number.
202 *
203 * @param[in] ip pointer to @p BaseAccelerometer interface.
204 * @param[in] bp a buffer which contains biases.
205 *
206 * @return The operation status.
207 * @retval MSG_OK if the function succeeded.
208 */
209static msg_t acc_set_bias(void *ip, float *bp) {
210 LIS3DSHDriver* devp;
211 uint32_t i;
212 msg_t msg = MSG_OK;
213
214 osalDbgCheck((ip != NULL) && (bp != NULL));
215
216 /* Getting parent instance pointer.*/
218
219 osalDbgAssert((devp->state == LIS3DSH_READY),
220 "acc_set_bias(), invalid state");
221
222 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++) {
223 devp->accbias[i] = bp[i];
224 }
225 return msg;
226}
227
228/**
229 * @brief Reset bias values for the BaseAccelerometer.
230 * @note Default biases value are obtained from device datasheet when
231 * available otherwise they are considered zero.
232 *
233 * @param[in] ip pointer to @p BaseAccelerometer interface.
234 *
235 * @return The operation status.
236 * @retval MSG_OK if the function succeeded.
237 */
238static msg_t acc_reset_bias(void *ip) {
239 LIS3DSHDriver* devp;
240 uint32_t i;
241 msg_t msg = MSG_OK;
242
243 osalDbgCheck(ip != NULL);
244
245 /* Getting parent instance pointer.*/
247
248 osalDbgAssert((devp->state == LIS3DSH_READY),
249 "acc_reset_bias(), invalid state");
250
251 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
252 devp->accbias[i] = LIS3DSH_ACC_BIAS;
253 return msg;
254}
255
256/**
257 * @brief Set sensitivity values for the BaseAccelerometer.
258 * @note Sensitivity must be expressed as milli-G/LSB.
259 * @note The sensitivity buffer must be at least the same size of the
260 * BaseAccelerometer axes number.
261 *
262 * @param[in] ip pointer to @p BaseAccelerometer interface.
263 * @param[in] sp a buffer which contains sensitivities.
264 *
265 * @return The operation status.
266 * @retval MSG_OK if the function succeeded.
267 */
268static msg_t acc_set_sensivity(void *ip, float *sp) {
269 LIS3DSHDriver* devp;
270 uint32_t i;
271 msg_t msg = MSG_OK;
272
273 /* Getting parent instance pointer.*/
275
276 osalDbgCheck((ip != NULL) && (sp != NULL));
277
278 osalDbgAssert((devp->state == LIS3DSH_READY),
279 "acc_set_sensivity(), invalid state");
280
281 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++) {
282 devp->accsensitivity[i] = sp[i];
283 }
284 return msg;
285}
286
287/**
288 * @brief Reset sensitivity values for the BaseAccelerometer.
289 * @note Default sensitivities value are obtained from device datasheet.
290 *
291 * @param[in] ip pointer to @p BaseAccelerometer interface.
292 *
293 * @return The operation status.
294 * @retval MSG_OK if the function succeeded.
295 * @retval MSG_RESET otherwise.
296 */
297static msg_t acc_reset_sensivity(void *ip) {
298 LIS3DSHDriver* devp;
299 uint32_t i;
300 msg_t msg = MSG_OK;
301
302 osalDbgCheck(ip != NULL);
303
304 /* Getting parent instance pointer.*/
306
307 osalDbgAssert((devp->state == LIS3DSH_READY),
308 "acc_reset_sensivity(), invalid state");
309
310 if(devp->config->accfullscale == LIS3DSH_ACC_FS_2G)
311 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
312 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_2G;
313 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_4G)
314 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
315 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_4G;
316 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_6G)
317 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
318 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_6G;
319 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_8G)
320 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
321 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_8G;
322 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_16G)
323 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
324 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_16G;
325 else {
327 "acc_reset_sensivity(), accelerometer full scale issue");
328 return MSG_RESET;
329 }
330 return msg;
331}
332
333/**
334 * @brief Changes the LIS3DSHDriver accelerometer fullscale value.
335 * @note This function also rescale sensitivities and biases based on
336 * previous and next fullscale value.
337 * @note A recalibration is highly suggested after calling this function.
338 *
339 * @param[in] devp pointer to @p LIS3DSHDriver interface.
340 * @param[in] fs new fullscale value.
341 *
342 * @return The operation status.
343 * @retval MSG_OK if the function succeeded.
344 * @retval MSG_RESET otherwise.
345 */
347 float newfs, scale;
348 uint8_t i, cr;
349 msg_t msg;
350
351 osalDbgCheck(devp != NULL);
352
353 osalDbgAssert((devp->state == LIS3DSH_READY),
354 "acc_set_full_scale(), invalid state");
355 osalDbgAssert((devp->config->spip->state == SPI_READY),
356 "acc_set_full_scale(), channel not ready");
357
358 /* Computing new fullscale value.*/
359 if(fs == LIS3DSH_ACC_FS_2G) {
360 newfs = LIS3DSH_ACC_2G;
361 msg = MSG_OK;
362 }
363 else if(fs == LIS3DSH_ACC_FS_4G) {
364 newfs = LIS3DSH_ACC_4G;
365 msg = MSG_OK;
366 }
367 else if(fs == LIS3DSH_ACC_FS_6G) {
368 newfs = LIS3DSH_ACC_6G;
369 msg = MSG_OK;
370 }
371 else if(fs == LIS3DSH_ACC_FS_8G) {
372 newfs = LIS3DSH_ACC_8G;
373 msg = MSG_OK;
374 }
375 else if(fs == LIS3DSH_ACC_FS_16G) {
376 newfs = LIS3DSH_ACC_16G;
377 msg = MSG_OK;
378 }
379 else {
380 msg = MSG_RESET;
381 }
382
383 if((msg == MSG_OK) &&
384 (newfs != devp->accfullscale)) {
385 /* Computing scale value.*/
386 scale = newfs / devp->accfullscale;
387 devp->accfullscale = newfs;
388
389#if LIS3DSH_USE_SPI
390#if LIS3DSH_SHARED_SPI
391 spiAcquireBus(devp->config->spip);
392 spiStart(devp->config->spip,
393 devp->config->spicfg);
394#endif /* LIS3DSH_SHARED_SPI */
395
396 /* Getting data from register.*/
397 lis3dshSPIReadRegister(devp->config->spip, LIS3DSH_AD_CTRL_REG5, 1, &cr);
398
399#if LIS3DSH_SHARED_SPI
400 spiReleaseBus(devp->config->spip);
401#endif /* LIS3DSH_SHARED_SPI */
402#endif /* LIS3DSH_USE_SPI */
403
405 cr |= fs;
406
407#if LIS3DSH_USE_SPI
408#if LIS3DSH_SHARED_SPI
409 spiAcquireBus(devp->config->spip);
410 spiStart(devp->config->spip,
411 devp->config->spicfg);
412#endif /* LIS3DSH_SHARED_SPI */
413
414 /* Getting data from register.*/
415 lis3dshSPIWriteRegister(devp->config->spip, LIS3DSH_AD_CTRL_REG5, 1, &cr);
416
417#if LIS3DSH_SHARED_SPI
418 spiReleaseBus(devp->config->spip);
419#endif /* LIS3DSH_SHARED_SPI */
420#endif /* LIS3DSH_USE_SPI */
421
422 /* Scaling sensitivity and bias. Re-calibration is suggested anyway. */
423 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++) {
424 devp->accsensitivity[i] *= scale;
425 devp->accbias[i] *= scale;
426 }
427 }
428 return msg;
429}
430
431static const struct LIS3DSHVMT vmt_device = {
432 (size_t)0,
434};
435
441
442/*===========================================================================*/
443/* Driver exported functions. */
444/*===========================================================================*/
445
446/**
447 * @brief Initializes an instance.
448 *
449 * @param[out] devp pointer to the @p LIS3DSHDriver object
450 *
451 * @init
452 */
454 devp->vmt = &vmt_device;
456
457 devp->config = NULL;
458
459 devp->accaxes = LIS3DSH_ACC_NUMBER_OF_AXES;
460
461 devp->state = LIS3DSH_STOP;
462}
463
464/**
465 * @brief Configures and activates LIS3DSH Complex Driver peripheral.
466 *
467 * @param[in] devp pointer to the @p LIS3DSHDriver object
468 * @param[in] config pointer to the @p LIS3DSHConfig object
469 *
470 * @api
471 */
472void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config) {
473 uint32_t i;
474 uint8_t cr;
475 osalDbgCheck((devp != NULL) && (config != NULL));
476
477 osalDbgAssert((devp->state == LIS3DSH_STOP) ||
478 (devp->state == LIS3DSH_READY),
479 "lis3dshStart(), invalid state");
480
481 devp->config = config;
482
483 /* Control register 4 configuration block.*/
484 {
486 devp->config->accodr;
487#if LIS3DSH_USE_ADVANCED || defined(__DOXYGEN__)
488 cr |= devp->config->accbdu;
489#endif
490 }
491
492#if LIS3DSH_USE_SPI
493#if LIS3DSH_SHARED_SPI
494 spiAcquireBus(devp->config->spip);
495#endif /* LIS3DSH_SHARED_SPI */
496 spiStart(devp->config->spip, devp->config->spicfg);
497
498 lis3dshSPIWriteRegister(devp->config->spip, LIS3DSH_AD_CTRL_REG4, 1, &cr);
499
500#if LIS3DSH_SHARED_SPI
501 spiReleaseBus(devp->config->spip);
502#endif /* LIS3DSH_SHARED_SPI */
503#endif /* LIS3DSH_USE_SPI */
504
505 /* Control register 5 configuration block.*/
506 {
507 cr = devp->config->accfullscale;
508#if LIS3DSH_USE_ADVANCED || defined(__DOXYGEN__)
509 cr |= devp->config->accantialiasing;
510#endif
511 }
512
513#if LIS3DSH_USE_SPI
514#if LIS3DSH_SHARED_SPI
515 spiAcquireBus(devp->config->spip);
516 spiStart(devp->config->spip, devp->config->spicfg);
517#endif /* LIS3DSH_SHARED_SPI */
518
519 lis3dshSPIWriteRegister(devp->config->spip, LIS3DSH_AD_CTRL_REG5, 1, &cr);
520
521#if LIS3DSH_SHARED_SPI
522 spiReleaseBus(devp->config->spip);
523#endif /* LIS3DSH_SHARED_SPI */
524#endif /* LIS3DSH_USE_SPI */
525
526 /* Control register 6 configuration block.*/
527 {
529#if LIS3DSH_USE_ADVANCED || defined(__DOXYGEN__)
530 cr |= devp->config->accbdu;
531#endif
532 }
533
534#if LIS3DSH_USE_SPI
535#if LIS3DSH_SHARED_SPI
536 spiAcquireBus(devp->config->spip);
537 spiStart(devp->config->spip, devp->config->spicfg);
538#endif /* LIS3DSH_SHARED_SPI */
539
540 lis3dshSPIWriteRegister(devp->config->spip, LIS3DSH_AD_CTRL_REG6, 1, &cr);
541
542#if LIS3DSH_SHARED_SPI
543 spiReleaseBus(devp->config->spip);
544#endif /* LIS3DSH_SHARED_SPI */
545#endif /* LIS3DSH_USE_SPI */
546
547 /* Storing sensitivity information according to user setting */
548 if(devp->config->accfullscale == LIS3DSH_ACC_FS_2G) {
549 devp->accfullscale = LIS3DSH_ACC_2G;
550 if(devp->config->accsensitivity == NULL)
551 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
552 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_2G;
553 else
554 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
555 devp->accsensitivity[i] = devp->config->accsensitivity[i];
556 }
557 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_4G) {
558 devp->accfullscale = LIS3DSH_ACC_4G;
559 if(devp->config->accsensitivity == NULL)
560 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
561 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_4G;
562 else
563 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
564 devp->accsensitivity[i] = devp->config->accsensitivity[i];
565 }
566 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_6G) {
567 devp->accfullscale = LIS3DSH_ACC_6G;
568 if(devp->config->accsensitivity == NULL)
569 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
570 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_6G;
571 else
572 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
573 devp->accsensitivity[i] = devp->config->accsensitivity[i];
574 }
575 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_8G) {
576 devp->accfullscale = LIS3DSH_ACC_8G;
577 if(devp->config->accsensitivity == NULL)
578 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
579 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_8G;
580 else
581 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
582 devp->accsensitivity[i] = devp->config->accsensitivity[i];
583 }
584 else if(devp->config->accfullscale == LIS3DSH_ACC_FS_16G) {
585 devp->accfullscale = LIS3DSH_ACC_16G;
586 if(devp->config->accsensitivity == NULL)
587 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
588 devp->accsensitivity[i] = LIS3DSH_ACC_SENS_16G;
589 else
590 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
591 devp->accsensitivity[i] = devp->config->accsensitivity[i];
592 }
593 else {
594 osalDbgAssert(FALSE, "lis3dshStart(), accelerometer full scale issue");
595 }
596
597 /* Storing bias information according to user setting */
598 if(devp->config->accbias != NULL)
599 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
600 devp->accbias[i] = devp->config->accbias[i];
601 else
602 for(i = 0; i < LIS3DSH_ACC_NUMBER_OF_AXES; i++)
603 devp->accbias[i] = LIS3DSH_ACC_BIAS;
604
605 /* This is the Accelerometer transient recovery time */
607
608 devp->state = LIS3DSH_READY;
609}
610
611/**
612 * @brief Deactivates the LIS3DSH Complex Driver peripheral.
613 *
614 * @param[in] devp pointer to the @p LIS3DSHDriver object
615 *
616 * @api
617 */
619 uint8_t cr4;
620 osalDbgCheck(devp != NULL);
621
622 osalDbgAssert((devp->state == LIS3DSH_STOP) ||
623 (devp->state == LIS3DSH_READY),
624 "lis3dshStop(), invalid state");
625
626 if (devp->state == LIS3DSH_READY) {
627#if (LIS3DSH_USE_SPI)
628#if LIS3DSH_SHARED_SPI
629 spiAcquireBus(devp->config->spip);
630 spiStart(devp->config->spip,
631 devp->config->spicfg);
632#endif /* LIS3DSH_SHARED_SPI */
633 /* Disabling all axes and enabling power down mode.*/
634 cr4 = 0;
636 1, &cr4);
637
638 spiStop(devp->config->spip);
639#if LIS3DSH_SHARED_SPI
640 spiReleaseBus(devp->config->spip);
641#endif /* LIS3DSH_SHARED_SPI */
642#endif /* LIS3DSH_USE_SPI */
643 }
644 devp->state = LIS3DSH_STOP;
645}
646/** @} */
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
Definition adxl317.c:115
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
Definition adxl317.c:310
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
Definition adxl317.c:222
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
Definition adxl317.c:251
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
Definition adxl317.c:281
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
Definition adxl317.c:185
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
Definition adxl317.c:137
static const struct BaseAccelerometerVMT vmt_accelerometer
Definition adxl317.c:332
static const struct ADXL317VMT vmt_device
Definition adxl317.c:328
static msg_t acc_set_full_scale(ADXL355Driver *devp, adxl355_acc_fs_t fs)
Changes the ADXL355Driver accelerometer fullscale value.
Definition adxl355.c:301
#define objGetInstance(type, ip)
Returns the instance pointer starting from an interface pointer.
Definition hal_objects.h:78
#define LIS3DSH_ACC_NUMBER_OF_AXES
LIS3DSH accelerometer subsystem characteristics.
Definition lis3dsh.h:72
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
Definition lis3dsh.c:98
#define LIS3DSH_AD_CTRL_REG5
Definition lis3dsh.h:129
#define LIS3DSH_ACC_SENS_8G
Definition lis3dsh.h:83
#define LIS3DSH_CTRL_REG4_ZEN
Definition lis3dsh.h:250
#define LIS3DSH_ACC_SENS_16G
Definition lis3dsh.h:84
static void lis3dshSPIWriteRegister(SPIDriver *spip, uint8_t reg, size_t n, uint8_t *b)
Writes a value into a generic register using SPI.
Definition lis3dsh.c:80
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
Definition lis3dsh.c:297
void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config)
Configures and activates LIS3DSH Complex Driver peripheral.
Definition lis3dsh.c:472
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
Definition lis3dsh.c:209
#define LIS3DSH_AD_CTRL_REG6
Definition lis3dsh.h:130
#define LIS3DSH_RW
Definition lis3dsh.h:98
#define LIS3DSH_ACC_SENS_4G
Definition lis3dsh.h:81
#define LIS3DSH_CTRL_REG6_ADD_INC
Definition lis3dsh.h:283
#define LIS3DSH_CTRL_REG4_XEN
Definition lis3dsh.h:248
static void lis3dshSPIReadRegister(SPIDriver *spip, uint8_t reg, size_t n, uint8_t *b)
Reads a generic register value using SPI.
Definition lis3dsh.c:60
#define LIS3DSH_ACC_BIAS
Definition lis3dsh.h:86
#define LIS3DSH_ACC_SENS_2G
Definition lis3dsh.h:80
lis3dsh_acc_fs_t
LIS3DSH full scale.
Definition lis3dsh.h:392
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
Definition lis3dsh.c:238
#define LIS3DSH_ACC_6G
Definition lis3dsh.h:76
#define LIS3DSH_CTRL_REG5_FS_MASK
Definition lis3dsh.h:266
#define LIS3DSH_ACC_2G
Definition lis3dsh.h:74
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
Definition lis3dsh.c:268
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
Definition lis3dsh.c:176
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
Definition lis3dsh.c:120
static msg_t acc_set_full_scale(LIS3DSHDriver *devp, lis3dsh_acc_fs_t fs)
Changes the LIS3DSHDriver accelerometer fullscale value.
Definition lis3dsh.c:346
#define LIS3DSH_AD_CTRL_REG4
Definition lis3dsh.h:125
void lis3dshStop(LIS3DSHDriver *devp)
Deactivates the LIS3DSH Complex Driver peripheral.
Definition lis3dsh.c:618
#define LIS3DSH_ACC_4G
Definition lis3dsh.h:75
#define LIS3DSH_AD_OUT_X_L
Definition lis3dsh.h:132
#define LIS3DSH_ACC_16G
Definition lis3dsh.h:78
#define LIS3DSH_ACC_8G
Definition lis3dsh.h:77
#define LIS3DSH_CTRL_REG4_YEN
Definition lis3dsh.h:249
void lis3dshObjectInit(LIS3DSHDriver *devp)
Initializes an instance.
Definition lis3dsh.c:453
#define LIS3DSH_ACC_SENS_6G
Definition lis3dsh.h:82
@ LIS3DSH_ACC_FS_16G
Definition lis3dsh.h:397
@ LIS3DSH_ACC_FS_8G
Definition lis3dsh.h:396
@ LIS3DSH_ACC_FS_4G
Definition lis3dsh.h:394
@ LIS3DSH_ACC_FS_2G
Definition lis3dsh.h:393
@ LIS3DSH_ACC_FS_6G
Definition lis3dsh.h:395
@ LIS3DSH_STOP
Definition lis3dsh.h:439
@ LIS3DSH_READY
Definition lis3dsh.h:440
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
Definition osal.h:522
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
msg_t spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
struct hal_spi_driver SPIDriver
Type of a structure representing an SPI driver.
Definition hal_spi_v1.h:117
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
@ SPI_READY
Definition hal_spi_v1.h:109
#define FALSE
Generic 'false' preprocessor boolean constant.
int32_t msg_t
Definition chearly.h:88
#define MSG_OK
Normal wakeup message.
Definition chschd.h:39
#define MSG_RESET
Wakeup caused by a reset condition.
Definition chschd.h:42
HAL subsystem header.
LIS3DSH MEMS interface module header.
Base accelerometer class.
const struct BaseAccelerometerVMT * vmt
Virtual Methods Table.
BaseAccelerometer virtual methods table.
LIS3DSH configuration structure.
Definition lis3dsh.h:446
LIS3DSH 3-axis accelerometer class.
Definition lis3dsh.h:541
const struct LIS3DSHVMT * vmt
Virtual Methods Table.
Definition lis3dsh.h:543
BaseAccelerometer acc_if
Base accelerometer interface.
Definition lis3dsh.h:545
LIS3DSH virtual methods table.
Definition lis3dsh.h:516