ChibiOS 21.11.4
lsm6dsl.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 lsm6dsl.c
23 * @brief LSM6DSL MEMS interface module code.
24 *
25 * @addtogroup LSM6DSL
26 * @ingroup EX_ST
27 * @{
28 */
29
30#include "hal.h"
31#include "lsm6dsl.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 (LSM6DSL_USE_I2C) || defined(__DOXYGEN__)
50/**
51 * @brief Reads registers value using I2C.
52 * @pre The I2C interface must be initialized and the driver started.
53 * @note IF_ADD_INC bit must be 1 in CTRL_REG8
54 *
55 * @param[in] i2cp pointer to the I2C interface
56 * @param[in] sad slave address without R bit
57 * @param[in] reg first sub-register address
58 * @param[out] rxbuf pointer to an output buffer
59 * @param[in] n number of consecutive register to read
60 * @return the operation status.
61 * @notapi
62 */
64 uint8_t* rxbuf, size_t n) {
65
66 return i2cMasterTransmitTimeout(i2cp, sad, &reg, 1, rxbuf, n,
68}
69
70/**
71 * @brief Writes a value into a register using I2C.
72 * @pre The I2C interface must be initialized and the driver started.
73 *
74 * @param[in] i2cp pointer to the I2C interface
75 * @param[in] sad slave address without R bit
76 * @param[in] txbuf buffer containing sub-address value in first position
77 * and values to write
78 * @param[in] n size of txbuf less one (not considering the first
79 * element)
80 * @return the operation status.
81 * @notapi
82 */
83#define lsm6dslI2CWriteRegister(i2cp, sad, txbuf, n) \
84 i2cMasterTransmitTimeout(i2cp, sad, txbuf, n + 1, NULL, 0, \
85 TIME_INFINITE)
86#endif /* LSM6DSL_USE_I2C */
87
88/**
89 * @brief Return the number of axes of the BaseAccelerometer.
90 *
91 * @param[in] ip pointer to @p BaseAccelerometer interface.
92 *
93 * @return the number of axes.
94 */
95static size_t acc_get_axes_number(void *ip) {
96 (void)ip;
97
99}
100
101/**
102 * @brief Retrieves raw data from the BaseAccelerometer.
103 * @note This data is retrieved from MEMS register without any algebraical
104 * manipulation.
105 * @note The axes array must be at least the same size of the
106 * BaseAccelerometer axes number.
107 *
108 * @param[in] ip pointer to @p BaseAccelerometer interface.
109 * @param[out] axes a buffer which would be filled with raw data.
110 *
111 * @return The operation status.
112 * @retval MSG_OK if the function succeeded.
113 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
114 * be retrieved using @p i2cGetErrors().
115 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
116 */
117static msg_t acc_read_raw(void *ip, int32_t axes[]) {
118 LSM6DSLDriver* devp;
119 uint8_t buff [LSM6DSL_ACC_NUMBER_OF_AXES * 2], i;
120 int16_t tmp;
121 msg_t msg;
122
123 osalDbgCheck((ip != NULL) && (axes != NULL));
124
125 /* Getting parent instance pointer.*/
127
128 osalDbgAssert((devp->state == LSM6DSL_READY),
129 "acc_read_raw(), invalid state");
130#if LSM6DSL_USE_I2C
131 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
132 "acc_read_raw(), channel not ready");
133
134#if LSM6DSL_SHARED_I2C
135 i2cAcquireBus(devp->config->i2cp);
136 i2cStart(devp->config->i2cp,
137 devp->config->i2ccfg);
138#endif /* LSM6DSL_SHARED_I2C */
139
140 msg = lsm6dslI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
143
144#if LSM6DSL_SHARED_I2C
145 i2cReleaseBus(devp->config->i2cp);
146#endif /* LSM6DSL_SHARED_I2C */
147#endif /* LSM6DSL_USE_I2C */
148 if(msg == MSG_OK)
149 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
150 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
151 axes[i] = (int32_t)tmp;
152 }
153 return msg;
154}
155
156/**
157 * @brief Retrieves cooked data from the BaseAccelerometer.
158 * @note This data is manipulated according to the formula
159 * cooked = (raw * sensitivity) - bias.
160 * @note Final data is expressed as milli-G.
161 * @note The axes array must be at least the same size of the
162 * BaseAccelerometer axes number.
163 *
164 * @param[in] ip pointer to @p BaseAccelerometer interface.
165 * @param[out] axes a buffer which would be filled with cooked data.
166 *
167 * @return The operation status.
168 * @retval MSG_OK if the function succeeded.
169 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
170 * be retrieved using @p i2cGetErrors().
171 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
172 */
173static msg_t acc_read_cooked(void *ip, float axes[]) {
174 LSM6DSLDriver* devp;
175 uint32_t i;
176 int32_t raw[LSM6DSL_ACC_NUMBER_OF_AXES];
177 msg_t msg;
178
179 osalDbgCheck((ip != NULL) && (axes != NULL));
180
181 /* Getting parent instance pointer.*/
183
184 osalDbgAssert((devp->state == LSM6DSL_READY),
185 "acc_read_cooked(), invalid state");
186
187 msg = acc_read_raw(ip, raw);
188 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
189 axes[i] = (raw[i] * devp->accsensitivity[i]) - devp->accbias[i];
190 }
191 return msg;
192}
193
194/**
195 * @brief Set bias values for the BaseAccelerometer.
196 * @note Bias must be expressed as milli-G.
197 * @note The bias buffer must be at least the same size of the
198 * BaseAccelerometer axes number.
199 *
200 * @param[in] ip pointer to @p BaseAccelerometer interface.
201 * @param[in] bp a buffer which contains biases.
202 *
203 * @return The operation status.
204 * @retval MSG_OK if the function succeeded.
205 */
206static msg_t acc_set_bias(void *ip, float *bp) {
207 LSM6DSLDriver* devp;
208 uint32_t i;
209 msg_t msg = MSG_OK;
210
211 osalDbgCheck((ip != NULL) && (bp != NULL));
212
213 /* Getting parent instance pointer.*/
215
216 osalDbgAssert((devp->state == LSM6DSL_READY),
217 "acc_set_bias(), invalid state");
218
219 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
220 devp->accbias[i] = bp[i];
221 }
222 return msg;
223}
224
225/**
226 * @brief Reset bias values for the BaseAccelerometer.
227 * @note Default biases value are obtained from device datasheet when
228 * available otherwise they are considered zero.
229 *
230 * @param[in] ip pointer to @p BaseAccelerometer interface.
231 *
232 * @return The operation status.
233 * @retval MSG_OK if the function succeeded.
234 */
235static msg_t acc_reset_bias(void *ip) {
236 LSM6DSLDriver* devp;
237 uint32_t i;
238 msg_t msg = MSG_OK;
239
240 osalDbgCheck(ip != NULL);
241
242 /* Getting parent instance pointer.*/
244
245 osalDbgAssert((devp->state == LSM6DSL_READY),
246 "acc_reset_bias(), invalid state");
247
248 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
249 devp->accbias[i] = LSM6DSL_ACC_BIAS;
250 return msg;
251}
252
253/**
254 * @brief Set sensitivity values for the BaseAccelerometer.
255 * @note Sensitivity must be expressed as milli-G/LSB.
256 * @note The sensitivity buffer must be at least the same size of the
257 * BaseAccelerometer axes number.
258 *
259 * @param[in] ip pointer to @p BaseAccelerometer interface.
260 * @param[in] sp a buffer which contains sensitivities.
261 *
262 * @return The operation status.
263 * @retval MSG_OK if the function succeeded.
264 */
265static msg_t acc_set_sensivity(void *ip, float *sp) {
266 LSM6DSLDriver* devp;
267 uint32_t i;
268 msg_t msg = MSG_OK;
269
270 /* Getting parent instance pointer.*/
272
273 osalDbgCheck((ip != NULL) && (sp != NULL));
274
275 osalDbgAssert((devp->state == LSM6DSL_READY),
276 "acc_set_sensivity(), invalid state");
277
278 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
279 devp->accsensitivity[i] = sp[i];
280 }
281 return msg;
282}
283
284/**
285 * @brief Reset sensitivity values for the BaseAccelerometer.
286 * @note Default sensitivities value are obtained from device datasheet.
287 *
288 * @param[in] ip pointer to @p BaseAccelerometer interface.
289 *
290 * @return The operation status.
291 * @retval MSG_OK if the function succeeded.
292 * @retval MSG_RESET otherwise.
293 */
294static msg_t acc_reset_sensivity(void *ip) {
295 LSM6DSLDriver* devp;
296 uint32_t i;
297 msg_t msg = MSG_OK;
298
299 osalDbgCheck(ip != NULL);
300
301 /* Getting parent instance pointer.*/
303
304 osalDbgAssert((devp->state == LSM6DSL_READY),
305 "acc_reset_sensivity(), invalid state");
306
307 if(devp->config->accfullscale == LSM6DSL_ACC_FS_2G)
308 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
309 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_2G;
310 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_4G)
311 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
312 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_4G;
313 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_8G)
314 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
315 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_8G;
316 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_16G)
317 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
318 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_16G;
319 else {
320 osalDbgAssert(FALSE, "reset_sensivity(), accelerometer full scale issue");
321 msg = MSG_RESET;
322 }
323 return msg;
324}
325
326/**
327 * @brief Changes the LSM6DSLDriver accelerometer fullscale value.
328 * @note This function also rescale sensitivities and biases based on
329 * previous and next fullscale value.
330 * @note A recalibration is highly suggested after calling this function.
331 *
332 * @param[in] devp pointer to @p LSM6DSLDriver interface.
333 * @param[in] fs new fullscale value.
334 *
335 * @return The operation status.
336 * @retval MSG_OK if the function succeeded.
337 * @retval MSG_RESET otherwise.
338 */
340 float newfs, scale;
341 uint8_t i, buff[2];
342 msg_t msg;
343
344 osalDbgCheck(devp != NULL);
345
346 osalDbgAssert((devp->state == LSM6DSL_READY),
347 "acc_set_full_scale(), invalid state");
348 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
349 "acc_set_full_scale(), channel not ready");
350
351 /* Computing new fullscale value.*/
352 if(fs == LSM6DSL_ACC_FS_2G) {
353 newfs = LSM6DSL_ACC_2G;
354 msg = MSG_OK;
355 }
356 else if(fs == LSM6DSL_ACC_FS_4G) {
357 newfs = LSM6DSL_ACC_4G;
358 msg = MSG_OK;
359 }
360 else if(fs == LSM6DSL_ACC_FS_8G) {
361 newfs = LSM6DSL_ACC_8G;
362 msg = MSG_OK;
363 }
364 else if(fs == LSM6DSL_ACC_FS_16G) {
365 newfs = LSM6DSL_ACC_16G;
366 msg = MSG_OK;
367 }
368 else {
369 msg = MSG_RESET;
370 }
371
372 if((msg == MSG_OK) &&
373 (newfs != devp->accfullscale)) {
374 /* Computing scale value.*/
375 scale = newfs / devp->accfullscale;
376 devp->accfullscale = newfs;
377
378#if LSM6DSL_SHARED_I2C
379 i2cAcquireBus(devp->config->i2cp);
380 i2cStart(devp->config->i2cp,
381 devp->config->i2ccfg);
382#endif /* LSM6DSL_SHARED_I2C */
383
384 /* Updating register.*/
385 msg = lsm6dslI2CReadRegister(devp->config->i2cp,
386 devp->config->slaveaddress,
387 LSM6DSL_AD_CTRL1_XL, &buff[1], 1);
388
389#if LSM6DSL_SHARED_I2C
390 i2cReleaseBus(devp->config->i2cp);
391#endif /* LSM6DSL_SHARED_I2C */
392
393 if(msg == MSG_OK) {
394
395 buff[1] &= ~(LSMDSL_CTRL1_XL_FS_MASK);
396 buff[1] |= fs;
397 buff[0] = LSM6DSL_AD_CTRL1_XL;
398
399#if LSM6DSL_SHARED_I2C
400 i2cAcquireBus(devp->config->i2cp);
401 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
402#endif /* LSM6DSL_SHARED_I2C */
403
404 msg = lsm6dslI2CWriteRegister(devp->config->i2cp,
405 devp->config->slaveaddress, buff, 1);
406
407#if LSM6DSL_SHARED_I2C
408 i2cReleaseBus(devp->config->i2cp);
409#endif /* LSM6DSL_SHARED_I2C */
410 }
411 if(msg == MSG_OK) {
412
413 /* Scaling sensitivity and bias. Re-calibration is suggested anyway.*/
414 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
415 devp->accsensitivity[i] *= scale;
416 devp->accbias[i] *= scale;
417 }
418 }
419 }
420 return msg;
421}
422
423/**
424 * @brief Return the number of axes of the BaseGyroscope.
425 *
426 * @param[in] ip pointer to @p BaseGyroscope interface.
427 *
428 * @return the number of axes.
429 */
430static size_t gyro_get_axes_number(void *ip) {
431 (void)ip;
432
434}
435
436/**
437 * @brief Retrieves raw data from the BaseGyroscope.
438 * @note This data is retrieved from MEMS register without any algebraical
439 * manipulation.
440 * @note The axes array must be at least the same size of the
441 * BaseGyroscope axes number.
442 *
443 * @param[in] ip pointer to @p BaseGyroscope interface.
444 * @param[out] axes a buffer which would be filled with raw data.
445 *
446 * @return The operation status.
447 * @retval MSG_OK if the function succeeded.
448 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
449 * be retrieved using @p i2cGetErrors().
450 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
451 */
452static msg_t gyro_read_raw(void *ip, int32_t axes[LSM6DSL_GYRO_NUMBER_OF_AXES]) {
453 LSM6DSLDriver* devp;
454 int16_t tmp;
455 uint8_t i, buff [2 * LSM6DSL_GYRO_NUMBER_OF_AXES];
456 msg_t msg = MSG_OK;
457
458 osalDbgCheck((ip != NULL) && (axes != NULL));
459
460 /* Getting parent instance pointer.*/
462
463 osalDbgAssert((devp->state == LSM6DSL_READY),
464 "gyro_read_raw(), invalid state");
465#if LSM6DSL_USE_I2C
466 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
467 "gyro_read_raw(), channel not ready");
468
469#if LSM6DSL_SHARED_I2C
470 i2cAcquireBus(devp->config->i2cp);
471 i2cStart(devp->config->i2cp,
472 devp->config->i2ccfg);
473#endif /* LSM6DSL_SHARED_I2C */
474
475 msg = lsm6dslI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
478
479#if LSM6DSL_SHARED_I2C
480 i2cReleaseBus(devp->config->i2cp);
481#endif /* LSM6DSL_SHARED_I2C */
482#endif /* LSM6DSL_USE_I2C */
483
484 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
485 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
486 axes[i] = (int32_t)tmp;
487 }
488 return msg;
489}
490
491/**
492 * @brief Retrieves cooked data from the BaseGyroscope.
493 * @note This data is manipulated according to the formula
494 * cooked = (raw * sensitivity) - bias.
495 * @note Final data is expressed as DPS.
496 * @note The axes array must be at least the same size of the
497 * BaseGyroscope axes number.
498 *
499 * @param[in] ip pointer to @p BaseGyroscope interface.
500 * @param[out] axes a buffer which would be filled with cooked data.
501 *
502 * @return The operation status.
503 * @retval MSG_OK if the function succeeded.
504 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
505 * be retrieved using @p i2cGetErrors().
506 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
507 */
508static msg_t gyro_read_cooked(void *ip, float axes[]) {
509 LSM6DSLDriver* devp;
510 uint32_t i;
511 int32_t raw[LSM6DSL_GYRO_NUMBER_OF_AXES];
512 msg_t msg;
513
514 osalDbgCheck((ip != NULL) && (axes != NULL));
515
516 /* Getting parent instance pointer.*/
518
519 osalDbgAssert((devp->state == LSM6DSL_READY),
520 "gyro_read_cooked(), invalid state");
521
522 msg = gyro_read_raw(ip, raw);
523 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++){
524 axes[i] = (raw[i] * devp->gyrosensitivity[i]) - devp->gyrobias[i];
525 }
526 return msg;
527}
528
529/**
530 * @brief Samples bias values for the BaseGyroscope.
531 * @note The LSM6DSL shall not be moved during the whole procedure.
532 * @note After this function internal bias is automatically updated.
533 * @note The behavior of this function depends on @p LSM6DSL_BIAS_ACQ_TIMES
534 * and @p LSM6DSL_BIAS_SETTLING_US.
535 *
536 * @param[in] ip pointer to @p BaseGyroscope interface.
537 *
538 * @return The operation status.
539 * @retval MSG_OK if the function succeeded.
540 */
541static msg_t gyro_sample_bias(void *ip) {
542 LSM6DSLDriver* devp;
543 uint32_t i, j;
544 int32_t raw[LSM6DSL_GYRO_NUMBER_OF_AXES];
545 int32_t buff[LSM6DSL_GYRO_NUMBER_OF_AXES] = {0, 0, 0};
546 msg_t msg;
547
548 osalDbgCheck(ip != NULL);
549
550 /* Getting parent instance pointer.*/
552
553 osalDbgAssert((devp->state == LSM6DSL_READY),
554 "gyro_sample_bias(), invalid state");
555#if LSM6DSL_USE_I2C
556 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
557 "gyro_sample_bias(), channel not ready");
558#endif
559
560 for(i = 0; i < LSM6DSL_GYRO_BIAS_ACQ_TIMES; i++){
561 msg = gyro_read_raw(ip, raw);
562 if(msg != MSG_OK)
563 return msg;
564 for(j = 0; j < LSM6DSL_GYRO_NUMBER_OF_AXES; j++){
565 buff[j] += raw[j];
566 }
568 }
569
570 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++){
571 devp->gyrobias[i] = (buff[i] / LSM6DSL_GYRO_BIAS_ACQ_TIMES);
572 devp->gyrobias[i] *= devp->gyrosensitivity[i];
573 }
574 return msg;
575}
576
577/**
578 * @brief Set bias values for the BaseGyroscope.
579 * @note Bias must be expressed as DPS.
580 * @note The bias buffer must be at least the same size of the BaseGyroscope
581 * axes number.
582 *
583 * @param[in] ip pointer to @p BaseGyroscope interface.
584 * @param[in] bp a buffer which contains biases.
585 *
586 * @return The operation status.
587 * @retval MSG_OK if the function succeeded.
588 */
589static msg_t gyro_set_bias(void *ip, float *bp) {
590 LSM6DSLDriver* devp;
591 uint32_t i;
592 msg_t msg = MSG_OK;
593
594 osalDbgCheck((ip != NULL) && (bp != NULL));
595
596 /* Getting parent instance pointer.*/
598
599 osalDbgAssert((devp->state == LSM6DSL_READY),
600 "gyro_set_bias(), invalid state");
601
602 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
603 devp->gyrobias[i] = bp[i];
604 }
605 return msg;
606}
607
608/**
609 * @brief Reset bias values for the BaseGyroscope.
610 * @note Default biases value are obtained from device datasheet when
611 * available otherwise they are considered zero.
612 *
613 * @param[in] ip pointer to @p BaseGyroscope interface.
614 *
615 * @return The operation status.
616 * @retval MSG_OK if the function succeeded.
617 */
618static msg_t gyro_reset_bias(void *ip) {
619 LSM6DSLDriver* devp;
620 uint32_t i;
621 msg_t msg = MSG_OK;
622
623 osalDbgCheck(ip != NULL);
624
625 /* Getting parent instance pointer.*/
627
628 osalDbgAssert((devp->state == LSM6DSL_READY),
629 "gyro_reset_bias(), invalid state");
630
631 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
632 devp->gyrobias[i] = LSM6DSL_GYRO_BIAS;
633 return msg;
634}
635
636/**
637 * @brief Set sensitivity values for the BaseGyroscope.
638 * @note Sensitivity must be expressed as DPS/LSB.
639 * @note The sensitivity buffer must be at least the same size of the
640 * BaseGyroscope axes number.
641 *
642 * @param[in] ip pointer to @p BaseGyroscope interface.
643 * @param[in] sp a buffer which contains sensitivities.
644 *
645 * @return The operation status.
646 * @retval MSG_OK if the function succeeded.
647 */
648static msg_t gyro_set_sensivity(void *ip, float *sp) {
649 LSM6DSLDriver* devp;
650 uint32_t i;
651 msg_t msg = MSG_OK;
652
653 osalDbgCheck((ip != NULL) && (sp !=NULL));
654
655 /* Getting parent instance pointer.*/
657
658 osalDbgAssert((devp->state == LSM6DSL_READY),
659 "gyro_set_sensivity(), invalid state");
660
661 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
662 devp->gyrosensitivity[i] = sp[i];
663 }
664 return msg;
665}
666
667/**
668 * @brief Reset sensitivity values for the BaseGyroscope.
669 * @note Default sensitivities value are obtained from device datasheet.
670 *
671 * @param[in] ip pointer to @p BaseGyroscope interface.
672 *
673 * @return The operation status.
674 * @retval MSG_OK if the function succeeded.
675 * @retval MSG_RESET otherwise.
676 */
677static msg_t gyro_reset_sensivity(void *ip) {
678 LSM6DSLDriver* devp;
679 uint32_t i;
680 msg_t msg = MSG_OK;
681
682 osalDbgCheck(ip != NULL);
683
684 /* Getting parent instance pointer.*/
686
687 osalDbgAssert((devp->state == LSM6DSL_READY),
688 "gyro_reset_sensivity(), invalid state");
689 if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_125DPS)
690 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
691 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_125DPS;
692 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_250DPS)
693 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
694 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_250DPS;
695 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_500DPS)
696 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
697 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_500DPS;
698 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_1000DPS)
699 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
700 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_1000DPS;
701 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_2000DPS)
702 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
703 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_2000DPS;
704 else {
705 osalDbgAssert(FALSE, "gyro_reset_sensivity(), full scale issue");
706 return MSG_RESET;
707 }
708 return msg;
709}
710
711/**
712 * @brief Changes the LSM6DSLDriver gyroscope fullscale value.
713 * @note This function also rescale sensitivities and biases based on
714 * previous and next fullscale value.
715 * @note A recalibration is highly suggested after calling this function.
716 *
717 * @param[in] devp pointer to @p BaseGyroscope interface.
718 * @param[in] fs new fullscale value.
719 *
720 * @return The operation status.
721 * @retval MSG_OK if the function succeeded.
722 * @retval MSG_RESET otherwise.
723 */
725 float newfs, scale;
726 uint8_t i, buff[2];
727 msg_t msg = MSG_OK;
728
729 osalDbgCheck(devp != NULL);
730
731 osalDbgAssert((devp->state == LSM6DSL_READY),
732 "gyro_set_full_scale(), invalid state");
733#if LSM6DSL_USE_I2C
734 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
735 "gyro_set_full_scale(), channel not ready");
736#endif
737
738 if(fs == LSM6DSL_GYRO_FS_125DPS) {
739 newfs = LSM6DSL_GYRO_125DPS;
740 }
741 else if(fs == LSM6DSL_GYRO_FS_250DPS) {
742 newfs = LSM6DSL_GYRO_250DPS;
743 }
744 else if(fs == LSM6DSL_GYRO_FS_500DPS) {
745 newfs = LSM6DSL_GYRO_500DPS;
746 }
747 else if(fs == LSM6DSL_GYRO_FS_1000DPS) {
748 newfs = LSM6DSL_GYRO_1000DPS;
749 }
750 else if(fs == LSM6DSL_GYRO_FS_2000DPS) {
751 newfs = LSM6DSL_GYRO_2000DPS;
752 }
753 else {
754 return MSG_RESET;
755 }
756
757 if(newfs != devp->gyrofullscale) {
758 scale = newfs / devp->gyrofullscale;
759 devp->gyrofullscale = newfs;
760
761#if LSM6DSL_USE_I2C
762#if LSM6DSL_SHARED_I2C
763 i2cAcquireBus(devp->config->i2cp);
764 i2cStart(devp->config->i2cp,
765 devp->config->i2ccfg);
766#endif /* LSM6DSL_SHARED_I2C */
767
768 /* Updating register.*/
769 msg = lsm6dslI2CReadRegister(devp->config->i2cp,
770 devp->config->slaveaddress,
771 LSM6DSL_AD_CTRL2_G, &buff[1], 1);
772
773#if LSM6DSL_SHARED_I2C
774 i2cReleaseBus(devp->config->i2cp);
775#endif /* LSM6DSL_SHARED_I2C */
776#endif /* LSM6DSL_USE_I2C */
777
778 buff[1] &= ~(LSMDSL_CTRL2_G_FS_MASK);
779 buff[1] |= fs;
780 buff[0] = LSM6DSL_AD_CTRL2_G;
781
782#if LSM6DSL_USE_I2C
783#if LSM6DSL_SHARED_I2C
784 i2cAcquireBus(devp->config->i2cp);
785 i2cStart(devp->config->i2cp,
786 devp->config->i2ccfg);
787#endif /* LSM6DSL_SHARED_I2C */
788
789 lsm6dslI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
790 buff, 1);
791
792#if LSM6DSL_SHARED_I2C
793 i2cReleaseBus(devp->config->i2cp);
794#endif /* LSM6DSL_SHARED_I2C */
795#endif /* LSM6DSL_USE_I2C */
796
797 /* Scaling sensitivity and bias. Re-calibration is suggested anyway. */
798 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
799 devp->gyrosensitivity[i] *= scale;
800 devp->gyrobias[i] *= scale;
801 }
802 }
803 return msg;
804}
805
806static const struct LSM6DSLVMT vmt_device = {
807 (size_t)0,
809};
810
816
823
824/*===========================================================================*/
825/* Driver exported functions. */
826/*===========================================================================*/
827
828/**
829 * @brief Initializes an instance.
830 *
831 * @param[out] devp pointer to the @p LSM6DSLDriver object
832 *
833 * @init
834 */
836 devp->vmt = &vmt_device;
838 devp->gyro_if.vmt = &vmt_gyroscope;
839
840 devp->config = NULL;
841
842 devp->accaxes = LSM6DSL_ACC_NUMBER_OF_AXES;
843 devp->gyroaxes = LSM6DSL_GYRO_NUMBER_OF_AXES;
844
845 devp->state = LSM6DSL_STOP;
846}
847
848/**
849 * @brief Configures and activates LSM6DSL Complex Driver peripheral.
850 *
851 * @param[in] devp pointer to the @p LSM6DSLDriver object
852 * @param[in] config pointer to the @p LSM6DSLConfig object
853 *
854 * @api
855 */
856void lsm6dslStart(LSM6DSLDriver *devp, const LSM6DSLConfig *config) {
857 uint32_t i;
858 uint8_t cr[11];
859 osalDbgCheck((devp != NULL) && (config != NULL));
860
861 osalDbgAssert((devp->state == LSM6DSL_STOP) ||
862 (devp->state == LSM6DSL_READY),
863 "lsm6dslStart(), invalid state");
864
865 devp->config = config;
866
867 /* Enforcing multiple write configuration.*/
868 {
869 cr[0] = LSM6DSL_AD_CTRL3_C;
870 cr[1] = LSMDSL_CTRL3_C_IF_INC;
871 }
872#if LSM6DSL_USE_I2C
873#if LSM6DSL_SHARED_I2C
874 i2cAcquireBus(devp->config->i2cp);
875#endif /* LSM6DSL_SHARED_I2C */
876
877 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
878 lsm6dslI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
879 cr, 1);
880
881#if LSM6DSL_SHARED_I2C
882 i2cReleaseBus(devp->config->i2cp);
883#endif /* LSM6DSL_SHARED_I2C */
884#endif /* LSM6DSL_USE_I2C */
885
886 /* Configuring all the control registers.*/
887 /* Multiple write starting address.*/
888 cr[0] = LSM6DSL_AD_CTRL1_XL;
889 /* Control register 1 configuration block.*/
890 {
891 cr[1] = devp->config->accodr |
892 devp->config->accfullscale;
893 }
894 /* Control register 2 configuration block.*/
895 {
896 cr[2] = devp->config->gyroodr |
897 devp->config->gyrofullscale;
898 }
899 /* Control register 3 configuration block.*/
900 {
901 cr[3] = LSMDSL_CTRL3_C_IF_INC;
902#if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
903 cr[3] |= devp->config->endianness | devp->config->bdu;
904#endif
905 }
906 /* Control register 4 configuration block.*/
907 {
908 cr[4] = 0;
909#if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
910 if(devp->config->gyrolpfilter != LSM6DSL_GYRO_LPF_DISABLED) {
912 }
913 else {
914 /* Nothing to do. */
915 }
916#endif
917 }
918 /* Control register 5 configuration block.*/
919 {
920 cr[5] = 0;
921 }
922 /* Control register 6 configuration block.*/
923 {
924 cr[6] = 0;
925#if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
926 cr[6] |= devp->config->acclpmode;
927
928#endif
929#if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
930 if(devp->config->gyrolpfilter != LSM6DSL_GYRO_LPF_DISABLED) {
931 cr[6] |= devp->config->gyrolpfilter;
932 }
933 else {
934 /* Nothing to do. */
935 }
936#endif
937 }
938 /* Control register 7 configuration block.*/
939 {
940 cr[7] = 0;
941#if LSM6DSL_USE_ADVANCED || defined(__DOXYGEN__)
942 cr[7] |= devp->config->gyrolpmode;
943
944#endif
945 }
946 /* Control register 8 configuration block.*/
947 {
948 cr[8] = 0;
949 }
950 /* Control register 9 configuration block.*/
951 {
952 cr[9] = 0;
953 }
954 /* Control register 10 configuration block.*/
955 {
956 cr[10] = 0;
957 }
958
959#if LSM6DSL_USE_I2C
960#if LSM6DSL_SHARED_I2C
961 i2cAcquireBus(devp->config->i2cp);
962 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
963#endif /* LSM6DSL_SHARED_I2C */
964
965 lsm6dslI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
966 cr, 10);
967
968#if LSM6DSL_SHARED_I2C
969 i2cReleaseBus(devp->config->i2cp);
970#endif /* LSM6DSL_SHARED_I2C */
971#endif /* LSM6DSL_USE_I2C */
972
973 /* Storing sensitivity according to user settings */
974 if(devp->config->accfullscale == LSM6DSL_ACC_FS_2G) {
975 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
976 if(devp->config->accsensitivity == NULL)
977 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_2G;
978 else
979 devp->accsensitivity[i] = devp->config->accsensitivity[i];
980 }
981 devp->accfullscale = LSM6DSL_ACC_2G;
982 }
983 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_4G) {
984 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
985 if(devp->config->accsensitivity == NULL)
986 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_4G;
987 else
988 devp->accsensitivity[i] = devp->config->accsensitivity[i];
989 }
990 devp->accfullscale = LSM6DSL_ACC_4G;
991 }
992 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_8G) {
993 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
994 if(devp->config->accsensitivity == NULL)
995 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_8G;
996 else
997 devp->accsensitivity[i] = devp->config->accsensitivity[i];
998 }
999 devp->accfullscale = LSM6DSL_ACC_8G;
1000 }
1001 else if(devp->config->accfullscale == LSM6DSL_ACC_FS_16G) {
1002 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++) {
1003 if(devp->config->accsensitivity == NULL)
1004 devp->accsensitivity[i] = LSM6DSL_ACC_SENS_16G;
1005 else
1006 devp->accsensitivity[i] = devp->config->accsensitivity[i];
1007 }
1008 devp->accfullscale = LSM6DSL_ACC_16G;
1009 }
1010 else
1011 osalDbgAssert(FALSE, "lsm6dslStart(), accelerometer full scale issue");
1012
1013 /* Storing bias information */
1014 if(devp->config->accbias != NULL)
1015 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
1016 devp->accbias[i] = devp->config->accbias[i];
1017 else
1018 for(i = 0; i < LSM6DSL_ACC_NUMBER_OF_AXES; i++)
1019 devp->accbias[i] = LSM6DSL_ACC_BIAS;
1020
1021 if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_125DPS) {
1022 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
1023 if(devp->config->gyrosensitivity == NULL)
1024 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_125DPS;
1025 else
1026 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1027 }
1028 devp->gyrofullscale = LSM6DSL_GYRO_125DPS;
1029 }
1030 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_250DPS) {
1031 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
1032 if(devp->config->gyrosensitivity == NULL)
1033 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_250DPS;
1034 else
1035 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1036 }
1037 devp->gyrofullscale = LSM6DSL_GYRO_250DPS;
1038 }
1039 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_500DPS) {
1040 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
1041 if(devp->config->gyrosensitivity == NULL)
1042 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_500DPS;
1043 else
1044 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1045 }
1046 devp->gyrofullscale = LSM6DSL_GYRO_500DPS;
1047 }
1048 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_1000DPS) {
1049 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
1050 if(devp->config->gyrosensitivity == NULL)
1051 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_1000DPS;
1052 else
1053 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1054 }
1055 devp->gyrofullscale = LSM6DSL_GYRO_1000DPS;
1056 }
1057 else if(devp->config->gyrofullscale == LSM6DSL_GYRO_FS_2000DPS) {
1058 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++) {
1059 if(devp->config->gyrosensitivity == NULL)
1060 devp->gyrosensitivity[i] = LSM6DSL_GYRO_SENS_2000DPS;
1061 else
1062 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1063 }
1064 devp->gyrofullscale = LSM6DSL_GYRO_2000DPS;
1065 }
1066 else
1067 osalDbgAssert(FALSE, "lsm6dslStart(), gyroscope full scale issue");
1068
1069 /* Storing bias information */
1070 if(devp->config->gyrobias != NULL)
1071 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
1072 devp->gyrobias[i] = devp->config->gyrobias[i];
1073 else
1074 for(i = 0; i < LSM6DSL_GYRO_NUMBER_OF_AXES; i++)
1075 devp->gyrobias[i] = LSM6DSL_GYRO_BIAS;
1076
1077 /* This is the MEMS transient recovery time */
1079
1080 devp->state = LSM6DSL_READY;
1081}
1082
1083/**
1084 * @brief Deactivates the LSM6DSL Complex Driver peripheral.
1085 *
1086 * @param[in] devp pointer to the @p LSM6DSLDriver object
1087 *
1088 * @api
1089 */
1091 uint8_t cr[2];
1092
1093 osalDbgCheck(devp != NULL);
1094
1095 osalDbgAssert((devp->state == LSM6DSL_STOP) || (devp->state == LSM6DSL_READY),
1096 "lsm6dslStop(), invalid state");
1097
1098 if (devp->state == LSM6DSL_READY) {
1099#if LSM6DSL_USE_I2C
1100#if LSM6DSL_SHARED_I2C
1101 i2cAcquireBus(devp->config->i2cp);
1102 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
1103#endif /* LSM6DSL_SHARED_I2C */
1104
1105
1106 cr[0] = LSM6DSL_AD_CTRL1_XL;
1107 /* Disabling accelerometer.*/
1108 cr[1] = LSM6DSL_ACC_ODR_PD;
1109 /* Disabling gyroscope.*/
1110 cr[2] = LSM6DSL_GYRO_ODR_PD;
1111 lsm6dslI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
1112 cr, 2);
1113
1114 i2cStop(devp->config->i2cp);
1115#if LSM6DSL_SHARED_I2C
1116 i2cReleaseBus(devp->config->i2cp);
1117#endif /* LSM6DSL_SHARED_I2C */
1118#endif /* LSM6DSL_USE_I2C */
1119 }
1120 devp->state = LSM6DSL_STOP;
1121}
1122/** @} */
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
msg_t i2cStart(I2CDriver *i2cp, const I2CConfig *config)
Configures and activates the I2C peripheral.
Definition hal_i2c.c:94
msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, sysinterval_t timeout)
Sends data via the I2C bus.
Definition hal_i2c.c:187
void i2cReleaseBus(I2CDriver *i2cp)
Releases exclusive access to the I2C bus.
Definition hal_i2c.c:293
void i2cStop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Definition hal_i2c.c:131
void i2cAcquireBus(I2CDriver *i2cp)
Gains exclusive access to the I2C bus.
Definition hal_i2c.c:277
struct hal_i2c_driver I2CDriver
Type of a structure representing an I2C driver.
Definition hal_i2c_lld.h:88
@ I2C_READY
Ready.
Definition hal_i2c.h:87
static const struct BaseGyroscopeVMT vmt_gyroscope
Definition l3gd20.c:455
static msg_t gyro_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseGyroscope.
Definition l3gd20.c:307
static size_t gyro_get_axes_number(void *ip)
Return the number of axes of the BaseGyroscope.
Definition l3gd20.c:96
static msg_t gyro_read_raw(void *ip, int32_t axes[L3GD20_GYRO_NUMBER_OF_AXES])
Retrieves raw data from the BaseGyroscope.
Definition l3gd20.c:115
static msg_t gyro_sample_bias(void *ip)
Samples bias values for the BaseGyroscope.
Definition l3gd20.c:200
static msg_t gyro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseGyroscope.
Definition l3gd20.c:167
static msg_t gyro_set_bias(void *ip, float *bp)
Set bias values for the BaseGyroscope.
Definition l3gd20.c:248
static msg_t gyro_set_full_scale(L3GD20Driver *devp, l3gd20_fs_t fs)
Changes the L3GD20Driver gyroscope fullscale value.
Definition l3gd20.c:378
static msg_t gyro_reset_sensivity(void *ip)
Reset sensitivity values for the BaseGyroscope.
Definition l3gd20.c:336
static msg_t gyro_reset_bias(void *ip)
Reset bias values for the BaseGyroscope.
Definition l3gd20.c:277
#define LSM6DSL_GYRO_SENS_250DPS
Definition lsm6dsl.h:104
void lsm6dslObjectInit(LSM6DSLDriver *devp)
Initializes an instance.
Definition lsm6dsl.c:835
#define LSM6DSL_ACC_SENS_2G
Definition lsm6dsl.h:79
#define lsm6dslI2CWriteRegister(i2cp, sad, txbuf, n)
Writes a value into a register using I2C.
Definition lsm6dsl.c:83
#define LSM6DSL_GYRO_125DPS
Definition lsm6dsl.h:97
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
Definition lsm6dsl.c:95
lsm6dsl_gyro_fs_t
LSM6DSL gyroscope subsystem full scale.
Definition lsm6dsl.h:519
void lsm6dslStart(LSM6DSLDriver *devp, const LSM6DSLConfig *config)
Configures and activates LSM6DSL Complex Driver peripheral.
Definition lsm6dsl.c:856
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
Definition lsm6dsl.c:294
lsm6dsl_acc_fs_t
LSM6DSL accelerometer subsystem full scale.
Definition lsm6dsl.h:483
lsm6dsl_sad_t
Accelerometer and Gyroscope Slave Address.
Definition lsm6dsl.h:475
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
Definition lsm6dsl.c:206
#define LSM6DSL_GYRO_SENS_125DPS
Definition lsm6dsl.h:103
#define LSM6DSL_GYRO_1000DPS
Definition lsm6dsl.h:100
static msg_t acc_set_full_scale(LSM6DSLDriver *devp, lsm6dsl_acc_fs_t fs)
Changes the LSM6DSLDriver accelerometer fullscale value.
Definition lsm6dsl.c:339
#define LSM6DSL_ACC_4G
Definition lsm6dsl.h:75
#define LSM6DSL_ACC_SENS_16G
Definition lsm6dsl.h:82
#define LSM6DSL_ACC_16G
Definition lsm6dsl.h:77
#define LSMDSL_CTRL4_C_LPF1_SEL_G
Definition lsm6dsl.h:271
static msg_t gyro_read_raw(void *ip, int32_t axes[LSM6DSL_GYRO_NUMBER_OF_AXES])
Retrieves raw data from the BaseGyroscope.
Definition lsm6dsl.c:452
#define LSM6DSL_ACC_8G
Definition lsm6dsl.h:76
#define LSM6DSL_ACC_SENS_8G
Definition lsm6dsl.h:81
#define LSM6DSL_GYRO_2000DPS
Definition lsm6dsl.h:101
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
Definition lsm6dsl.c:235
#define LSM6DSL_ACC_NUMBER_OF_AXES
LSM6DSL accelerometer subsystem characteristics.
Definition lsm6dsl.h:72
#define LSMDSL_CTRL1_XL_FS_MASK
Definition lsm6dsl.h:229
#define LSM6DSL_AD_CTRL3_C
Definition lsm6dsl.h:141
msg_t lsm6dslI2CReadRegister(I2CDriver *i2cp, lsm6dsl_sad_t sad, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
Definition lsm6dsl.c:63
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
Definition lsm6dsl.c:265
void lsm6dslStop(LSM6DSLDriver *devp)
Deactivates the LSM6DSL Complex Driver peripheral.
Definition lsm6dsl.c:1090
#define LSMDSL_CTRL3_C_IF_INC
Definition lsm6dsl.h:258
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
Definition lsm6dsl.c:173
static msg_t gyro_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseGyroscope.
Definition lsm6dsl.c:648
static size_t gyro_get_axes_number(void *ip)
Return the number of axes of the BaseGyroscope.
Definition lsm6dsl.c:430
#define LSM6DSL_GYRO_BIAS_SETTLING_US
Settling time for gyroscope bias removal.
Definition lsm6dsl.h:424
#define LSM6DSL_GYRO_SENS_1000DPS
Definition lsm6dsl.h:106
#define LSM6DSL_GYRO_SENS_2000DPS
Definition lsm6dsl.h:107
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
Definition lsm6dsl.c:117
static msg_t gyro_set_full_scale(LSM6DSLDriver *devp, lsm6dsl_gyro_fs_t fs)
Changes the LSM6DSLDriver gyroscope fullscale value.
Definition lsm6dsl.c:724
static msg_t gyro_sample_bias(void *ip)
Samples bias values for the BaseGyroscope.
Definition lsm6dsl.c:541
#define LSMDSL_CTRL2_G_FS_MASK
Definition lsm6dsl.h:242
static msg_t gyro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseGyroscope.
Definition lsm6dsl.c:508
#define LSM6DSL_GYRO_NUMBER_OF_AXES
L3GD20 gyroscope system characteristics.
Definition lsm6dsl.h:95
#define LSM6DSL_GYRO_BIAS_ACQ_TIMES
Number of acquisitions for gyroscope bias removal.
Definition lsm6dsl.h:416
#define LSM6DSL_AD_OUTX_L_XL
Definition lsm6dsl.h:162
static msg_t gyro_set_bias(void *ip, float *bp)
Set bias values for the BaseGyroscope.
Definition lsm6dsl.c:589
#define LSM6DSL_ACC_SENS_4G
Definition lsm6dsl.h:80
#define LSM6DSL_GYRO_250DPS
Definition lsm6dsl.h:98
#define LSM6DSL_GYRO_500DPS
Definition lsm6dsl.h:99
#define LSM6DSL_GYRO_BIAS
Definition lsm6dsl.h:109
#define LSM6DSL_ACC_BIAS
Definition lsm6dsl.h:84
#define LSM6DSL_GYRO_SENS_500DPS
Definition lsm6dsl.h:105
#define LSM6DSL_AD_OUTX_L_G
Definition lsm6dsl.h:156
static msg_t gyro_reset_sensivity(void *ip)
Reset sensitivity values for the BaseGyroscope.
Definition lsm6dsl.c:677
#define LSM6DSL_AD_CTRL2_G
Definition lsm6dsl.h:140
#define LSM6DSL_ACC_2G
Definition lsm6dsl.h:74
#define LSM6DSL_AD_CTRL1_XL
Definition lsm6dsl.h:139
static msg_t gyro_reset_bias(void *ip)
Reset bias values for the BaseGyroscope.
Definition lsm6dsl.c:618
@ LSM6DSL_GYRO_ODR_PD
Definition lsm6dsl.h:531
@ LSM6DSL_GYRO_FS_125DPS
Definition lsm6dsl.h:520
@ LSM6DSL_GYRO_FS_1000DPS
Definition lsm6dsl.h:523
@ LSM6DSL_GYRO_FS_2000DPS
Definition lsm6dsl.h:524
@ LSM6DSL_GYRO_FS_250DPS
Definition lsm6dsl.h:521
@ LSM6DSL_GYRO_FS_500DPS
Definition lsm6dsl.h:522
@ LSM6DSL_ACC_FS_4G
Definition lsm6dsl.h:485
@ LSM6DSL_ACC_FS_8G
Definition lsm6dsl.h:486
@ LSM6DSL_ACC_FS_16G
Definition lsm6dsl.h:487
@ LSM6DSL_ACC_FS_2G
Definition lsm6dsl.h:484
@ LSM6DSL_STOP
Definition lsm6dsl.h:584
@ LSM6DSL_READY
Definition lsm6dsl.h:585
@ LSM6DSL_GYRO_LPF_DISABLED
Definition lsm6dsl.h:556
@ LSM6DSL_ACC_ODR_PD
Definition lsm6dsl.h:494
#define osalThreadSleepMicroseconds(usecs)
Delays the invoking thread for the specified number of microseconds.
Definition osal.h:535
#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
#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
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
Definition chtime.h:55
HAL subsystem header.
LSM6DSL MEMS interface module header.
Base accelerometer class.
const struct BaseAccelerometerVMT * vmt
Virtual Methods Table.
BaseAccelerometer virtual methods table.
Base gyroscope class.
const struct BaseGyroscopeVMT * vmt
Virtual Methods Table.
BaseGyroscope virtual methods table.
LSM6DSL configuration structure.
Definition lsm6dsl.h:591
LSM6DSL 6-axis accelerometer/gyroscope class.
Definition lsm6dsl.h:730
BaseGyroscope gyro_if
Base gyroscope interface.
Definition lsm6dsl.h:736
BaseAccelerometer acc_if
Base accelerometer interface.
Definition lsm6dsl.h:734
const struct LSM6DSLVMT * vmt
Virtual Methods Table.
Definition lsm6dsl.h:732
LSM6DSL virtual methods table.
Definition lsm6dsl.h:697