ChibiOS 21.11.4
lsm6ds0.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 lsm6ds0.c
23 * @brief LSM6DS0 MEMS interface module code.
24 *
25 * @addtogroup LSM6DS0
26 * @ingroup EX_ST
27 * @{
28 */
29
30#include "hal.h"
31#include "lsm6ds0.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 (LSM6DS0_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 lsm6ds0I2CWriteRegister(i2cp, sad, txbuf, n) \
84 i2cMasterTransmitTimeout(i2cp, sad, txbuf, n + 1, NULL, 0, \
85 TIME_INFINITE)
86#endif /* LSM6DS0_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 LSM6DS0Driver* devp;
119 uint8_t buff [LSM6DS0_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 == LSM6DS0_READY),
129 "acc_read_raw(), invalid state");
130#if LSM6DS0_USE_I2C
131 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
132 "acc_read_raw(), channel not ready");
133
134#if LSM6DS0_SHARED_I2C
135 i2cAcquireBus(devp->config->i2cp);
136 i2cStart(devp->config->i2cp,
137 devp->config->i2ccfg);
138#endif /* LSM6DS0_SHARED_I2C */
139
140 msg = lsm6ds0I2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
143
144#if LSM6DS0_SHARED_I2C
145 i2cReleaseBus(devp->config->i2cp);
146#endif /* LSM6DS0_SHARED_I2C */
147#endif /* LSM6DS0_USE_I2C */
148 if(msg == MSG_OK)
149 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* devp;
175 uint32_t i;
176 int32_t raw[LSM6DS0_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 == LSM6DS0_READY),
185 "acc_read_cooked(), invalid state");
186
187 msg = acc_read_raw(ip, raw);
188 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
217 "acc_set_bias(), invalid state");
218
219 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
246 "acc_reset_bias(), invalid state");
247
248 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
249 devp->accbias[i] = LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
276 "acc_set_sensivity(), invalid state");
277
278 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
305 "acc_reset_sensivity(), invalid state");
306
307 if(devp->config->accfullscale == LSM6DS0_ACC_FS_2G)
308 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
309 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_2G;
310 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_4G)
311 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
312 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_4G;
313 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_8G)
314 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
315 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_8G;
316 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_16G)
317 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
318 devp->accsensitivity[i] = LSM6DS0_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 LSM6DS0Driver 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 LSM6DS0Driver 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 == LSM6DS0_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 == LSM6DS0_ACC_FS_2G) {
353 newfs = LSM6DS0_ACC_2G;
354 msg = MSG_OK;
355 }
356 else if(fs == LSM6DS0_ACC_FS_4G) {
357 newfs = LSM6DS0_ACC_4G;
358 msg = MSG_OK;
359 }
360 else if(fs == LSM6DS0_ACC_FS_8G) {
361 newfs = LSM6DS0_ACC_8G;
362 msg = MSG_OK;
363 }
364 else if(fs == LSM6DS0_ACC_FS_16G) {
365 newfs = LSM6DS0_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 LSM6DS0_SHARED_I2C
379 i2cAcquireBus(devp->config->i2cp);
380 i2cStart(devp->config->i2cp,
381 devp->config->i2ccfg);
382#endif /* LSM6DS0_SHARED_I2C */
383
384 /* Updating register.*/
385 msg = lsm6ds0I2CReadRegister(devp->config->i2cp,
386 devp->config->slaveaddress,
387 LSM6DS0_AD_CTRL_REG6_XL, &buff[1], 1);
388
389#if LSM6DS0_SHARED_I2C
390 i2cReleaseBus(devp->config->i2cp);
391#endif /* LSM6DS0_SHARED_I2C */
392
393 if(msg != MSG_OK) {
394
395 buff[1] &= ~(LSM6DS0_CTRL_REG6_XL_FS_MASK);
396 buff[1] |= fs;
397 buff[0] = LSM6DS0_AD_CTRL_REG6_XL;
398
399#if LSM6DS0_SHARED_I2C
400 i2cAcquireBus(devp->config->i2cp);
401 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
402#endif /* LSM6DS0_SHARED_I2C */
403
404 msg = lsm6ds0I2CWriteRegister(devp->config->i2cp,
405 devp->config->slaveaddress, buff, 1);
406
407#if LSM6DS0_SHARED_I2C
408 i2cReleaseBus(devp->config->i2cp);
409#endif /* LSM6DS0_SHARED_I2C */
410 }
411 if(msg != MSG_OK) {
412
413 /* Scaling sensitivity and bias. Re-calibration is suggested anyway.*/
414 for(i = 0; i < LSM6DS0_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[LSM6DS0_GYRO_NUMBER_OF_AXES]) {
453 LSM6DS0Driver* devp;
454 int16_t tmp;
455 uint8_t i, buff [2 * LSM6DS0_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 == LSM6DS0_READY),
464 "gyro_read_raw(), invalid state");
465#if LSM6DS0_USE_I2C
466 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
467 "gyro_read_raw(), channel not ready");
468
469#if LSM6DS0_SHARED_I2C
470 i2cAcquireBus(devp->config->i2cp);
471 i2cStart(devp->config->i2cp,
472 devp->config->i2ccfg);
473#endif /* LSM6DS0_SHARED_I2C */
474
475 msg = lsm6ds0I2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
478
479#if LSM6DS0_SHARED_I2C
480 i2cReleaseBus(devp->config->i2cp);
481#endif /* LSM6DS0_SHARED_I2C */
482#endif /* LSM6DS0_USE_I2C */
483
484 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* devp;
510 uint32_t i;
511 int32_t raw[LSM6DS0_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 == LSM6DS0_READY),
520 "gyro_read_cooked(), invalid state");
521
522 msg = gyro_read_raw(ip, raw);
523 for(i = 0; i < LSM6DS0_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 LSM6DS0 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 LSM6DS0_BIAS_ACQ_TIMES
534 * and @p LSM6DS0_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 LSM6DS0Driver* devp;
543 uint32_t i, j;
544 int32_t raw[LSM6DS0_GYRO_NUMBER_OF_AXES];
545 int32_t buff[LSM6DS0_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 == LSM6DS0_READY),
554 "gyro_sample_bias(), invalid state");
555#if LSM6DS0_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 < LSM6DS0_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 < LSM6DS0_GYRO_NUMBER_OF_AXES; j++){
565 buff[j] += raw[j];
566 }
568 }
569
570 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++){
571 devp->gyrobias[i] = (buff[i] / LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
600 "gyro_set_bias(), invalid state");
601
602 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
629 "gyro_reset_bias(), invalid state");
630
631 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
632 devp->gyrobias[i] = LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
659 "gyro_set_sensivity(), invalid state");
660
661 for(i = 0; i < LSM6DS0_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 LSM6DS0Driver* 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 == LSM6DS0_READY),
688 "gyro_reset_sensivity(), invalid state");
689
690 if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_245DPS)
691 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
692 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_245DPS;
693 else if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_500DPS)
694 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
695 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_500DPS;
696 else if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_2000DPS)
697 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
698 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_2000DPS;
699 else {
700 osalDbgAssert(FALSE, "gyro_reset_sensivity(), full scale issue");
701 return MSG_RESET;
702 }
703 return msg;
704}
705
706/**
707 * @brief Changes the LSM6DS0Driver gyroscope fullscale value.
708 * @note This function also rescale sensitivities and biases based on
709 * previous and next fullscale value.
710 * @note A recalibration is highly suggested after calling this function.
711 *
712 * @param[in] devp pointer to @p BaseGyroscope interface.
713 * @param[in] fs new fullscale value.
714 *
715 * @return The operation status.
716 * @retval MSG_OK if the function succeeded.
717 * @retval MSG_RESET otherwise.
718 */
720 float newfs, scale;
721 uint8_t i, buff[2];
722 msg_t msg = MSG_OK;
723
724 osalDbgCheck(devp != NULL);
725
726 osalDbgAssert((devp->state == LSM6DS0_READY),
727 "gyro_set_full_scale(), invalid state");
728#if LSM6DS0_USE_I2C
729 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
730 "gyro_set_full_scale(), channel not ready");
731#endif
732
733 if(fs == LSM6DS0_GYRO_FS_245DPS) {
734 newfs = LSM6DS0_GYRO_245DPS;
735 }
736 else if(fs == LSM6DS0_GYRO_FS_500DPS) {
737 newfs = LSM6DS0_GYRO_500DPS;
738 }
739 else if(fs == LSM6DS0_GYRO_FS_2000DPS) {
740 newfs = LSM6DS0_GYRO_2000DPS;
741 }
742 else {
743 return MSG_RESET;
744 }
745
746 if(newfs != devp->gyrofullscale) {
747 scale = newfs / devp->gyrofullscale;
748 devp->gyrofullscale = newfs;
749
750#if LSM6DS0_USE_I2C
751#if LSM6DS0_SHARED_I2C
752 i2cAcquireBus(devp->config->i2cp);
753 i2cStart(devp->config->i2cp,
754 devp->config->i2ccfg);
755#endif /* LSM6DS0_SHARED_I2C */
756
757 /* Updating register.*/
758 msg = lsm6ds0I2CReadRegister(devp->config->i2cp,
759 devp->config->slaveaddress,
760 LSM6DS0_AD_CTRL_REG1_G, &buff[1], 1);
761
762#if LSM6DS0_SHARED_I2C
763 i2cReleaseBus(devp->config->i2cp);
764#endif /* LSM6DS0_SHARED_I2C */
765#endif /* LSM6DS0_USE_I2C */
766
767 buff[1] &= ~(LSM6DS0_CTRL_REG1_G_FS_MASK);
768 buff[1] |= fs;
769 buff[0] = LSM6DS0_AD_CTRL_REG1_G;
770
771#if LSM6DS0_USE_I2C
772#if LSM6DS0_SHARED_I2C
773 i2cAcquireBus(devp->config->i2cp);
774 i2cStart(devp->config->i2cp,
775 devp->config->i2ccfg);
776#endif /* LSM6DS0_SHARED_I2C */
777
778 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
779 buff, 1);
780
781#if LSM6DS0_SHARED_I2C
782 i2cReleaseBus(devp->config->i2cp);
783#endif /* LSM6DS0_SHARED_I2C */
784#endif /* LSM6DS0_USE_I2C */
785
786 /* Scaling sensitivity and bias. Re-calibration is suggested anyway. */
787 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
788 devp->gyrosensitivity[i] *= scale;
789 devp->gyrobias[i] *= scale;
790 }
791 }
792 return msg;
793}
794
795static const struct LSM6DS0VMT vmt_device = {
796 (size_t)0,
798};
799
805
812
813/*===========================================================================*/
814/* Driver exported functions. */
815/*===========================================================================*/
816
817/**
818 * @brief Initializes an instance.
819 *
820 * @param[out] devp pointer to the @p LSM6DS0Driver object
821 *
822 * @init
823 */
825 devp->vmt = &vmt_device;
827 devp->gyro_if.vmt = &vmt_gyroscope;
828
829 devp->config = NULL;
830
831 devp->accaxes = LSM6DS0_ACC_NUMBER_OF_AXES;
832 devp->gyroaxes = LSM6DS0_GYRO_NUMBER_OF_AXES;
833
834 devp->state = LSM6DS0_STOP;
835}
836
837/**
838 * @brief Configures and activates LSM6DS0 Complex Driver peripheral.
839 *
840 * @param[in] devp pointer to the @p LSM6DS0Driver object
841 * @param[in] config pointer to the @p LSM6DS0Config object
842 *
843 * @api
844 */
845void lsm6ds0Start(LSM6DS0Driver *devp, const LSM6DS0Config *config) {
846 uint32_t i;
847 uint8_t cr[5];
848 osalDbgCheck((devp != NULL) && (config != NULL));
849
850 osalDbgAssert((devp->state == LSM6DS0_STOP) ||
851 (devp->state == LSM6DS0_READY),
852 "lsm6ds0Start(), invalid state");
853
854 devp->config = config;
855
856 /* Configuring common registers.*/
857
858 /* Control register 8 configuration block.*/
859 {
860 cr[0] = LSM6DS0_AD_CTRL_REG8;
862#if LSM6DS0_USE_ADVANCED || defined(__DOXYGEN__)
863 cr[1] |= devp->config->endianness | devp->config->bdu;
864#endif
865 }
866#if LSM6DS0_USE_I2C
867#if LSM6DS0_SHARED_I2C
868 i2cAcquireBus(devp->config->i2cp);
869#endif /* LSM6DS0_SHARED_I2C */
870
871 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
872 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
873 cr, 1);
874
875#if LSM6DS0_SHARED_I2C
876 i2cReleaseBus(devp->config->i2cp);
877#endif /* LSM6DS0_SHARED_I2C */
878#endif /* LSM6DS0_USE_I2C */
879
880 /* Configuring Accelerometer subsystem.*/
881 /* Multiple write starting address.*/
883 /* Control register 5 configuration block.*/
884 {
887#if LSM6DS0_USE_ADVANCED || defined(__DOXYGEN__)
888 cr[1] |= devp->config->accdecmode;
889#endif
890 }
891
892 /* Control register 6 configuration block.*/
893 {
894 cr[2] = devp->config->accodr |
895 devp->config->accfullscale;
896 }
897
898#if LSM6DS0_USE_I2C
899#if LSM6DS0_SHARED_I2C
900 i2cAcquireBus(devp->config->i2cp);
901 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
902#endif /* LSM6DS0_SHARED_I2C */
903
904 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
905 cr, 2);
906
907#if LSM6DS0_SHARED_I2C
908 i2cReleaseBus(devp->config->i2cp);
909#endif /* LSM6DS0_SHARED_I2C */
910#endif /* LSM6DS0_USE_I2C */
911
912 /* Storing sensitivity according to user settings */
913 if(devp->config->accfullscale == LSM6DS0_ACC_FS_2G) {
914 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
915 if(devp->config->accsensitivity == NULL)
916 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_2G;
917 else
918 devp->accsensitivity[i] = devp->config->accsensitivity[i];
919 }
920 devp->accfullscale = LSM6DS0_ACC_2G;
921 }
922 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_4G) {
923 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
924 if(devp->config->accsensitivity == NULL)
925 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_4G;
926 else
927 devp->accsensitivity[i] = devp->config->accsensitivity[i];
928 }
929 devp->accfullscale = LSM6DS0_ACC_4G;
930 }
931 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_8G) {
932 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
933 if(devp->config->accsensitivity == NULL)
934 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_8G;
935 else
936 devp->accsensitivity[i] = devp->config->accsensitivity[i];
937 }
938 devp->accfullscale = LSM6DS0_ACC_8G;
939 }
940 else if(devp->config->accfullscale == LSM6DS0_ACC_FS_16G) {
941 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
942 if(devp->config->accsensitivity == NULL)
943 devp->accsensitivity[i] = LSM6DS0_ACC_SENS_16G;
944 else
945 devp->accsensitivity[i] = devp->config->accsensitivity[i];
946 }
947 devp->accfullscale = LSM6DS0_ACC_16G;
948 }
949 else
950 osalDbgAssert(FALSE, "lsm6ds0Start(), accelerometer full scale issue");
951
952 /* Storing bias information */
953 if(devp->config->accbias != NULL)
954 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
955 devp->accbias[i] = devp->config->accbias[i];
956 else
957 for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
958 devp->accbias[i] = LSM6DS0_ACC_BIAS;
959
960 /* Configuring Gyroscope subsystem.*/
961 /* Multiple write starting address.*/
963
964 /* Control register 1 configuration block.*/
965 {
966 cr[1] = devp->config->gyrofullscale |
967 devp->config->gyroodr;
968 }
969
970 /* Control register 2 configuration block.*/
971 {
972 cr[2] = 0;
973#if LSM6DS0_USE_ADVANCED || defined(__DOXYGEN__)
974 cr[2] |= devp->config->gyrooutsel;
975#endif
976 }
977
978 /* Control register 3 configuration block.*/
979 {
980 cr[3] = 0;
981#if LSM6DS0_USE_ADVANCED || defined(__DOXYGEN__)
982 cr[3] |= devp->config->gyrohpfenable |
983 devp->config->gyrolowmodecfg |
984 devp->config->gyrohpcfg;
985#endif
986 }
987
988 /* Control register 4 configuration block.*/
989 {
992 }
993#if LSM6DS0_USE_I2C
994#if LSM6DS0_SHARED_I2C
995 i2cAcquireBus(devp->config->i2cp);
996 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
997#endif /* LSM6DS0_SHARED_I2C */
998
999 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
1000 cr, 4);
1001
1002#if LSM6DS0_SHARED_I2C
1003 i2cReleaseBus(devp->config->i2cp);
1004#endif /* LSM6DS0_SHARED_I2C */
1005#endif /* LSM6DS0_USE_I2C */
1006
1007 cr[0] = LSM6DS0_AD_CTRL_REG9;
1008 /* Control register 9 configuration block.*/
1009 {
1010 cr[1] = 0;
1011 }
1012#if LSM6DS0_USE_I2C
1013#if LSM6DS0_SHARED_I2C
1014 i2cAcquireBus(devp->config->i2cp);
1015 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
1016#endif /* LSM6DS0_SHARED_I2C */
1017
1018 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
1019 cr, 1);
1020
1021#if LSM6DS0_SHARED_I2C
1022 i2cReleaseBus(devp->config->i2cp);
1023#endif /* LSM6DS0_SHARED_I2C */
1024#endif /* LSM6DS0_USE_I2C */
1025
1026 if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_245DPS) {
1027 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
1028 if(devp->config->gyrosensitivity == NULL)
1029 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_245DPS;
1030 else
1031 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1032 }
1033 devp->gyrofullscale = LSM6DS0_GYRO_245DPS;
1034 }
1035 else if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_500DPS) {
1036 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
1037 if(devp->config->gyrosensitivity == NULL)
1038 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_500DPS;
1039 else
1040 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1041 }
1042 devp->gyrofullscale = LSM6DS0_GYRO_500DPS;
1043 }
1044 else if(devp->config->gyrofullscale == LSM6DS0_GYRO_FS_2000DPS) {
1045 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
1046 if(devp->config->gyrosensitivity == NULL)
1047 devp->gyrosensitivity[i] = LSM6DS0_GYRO_SENS_2000DPS;
1048 else
1049 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
1050 }
1051 devp->gyrofullscale = LSM6DS0_GYRO_2000DPS;
1052 }
1053 else
1054 osalDbgAssert(FALSE, "lsm6ds0Start(), gyroscope full scale issue");
1055
1056 /* Storing bias information */
1057 if(devp->config->gyrobias != NULL)
1058 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
1059 devp->gyrobias[i] = devp->config->gyrobias[i];
1060 else
1061 for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
1062 devp->gyrobias[i] = LSM6DS0_GYRO_BIAS;
1063
1064 /* This is the MEMS transient recovery time */
1066
1067 devp->state = LSM6DS0_READY;
1068}
1069
1070/**
1071 * @brief Deactivates the LSM6DS0 Complex Driver peripheral.
1072 *
1073 * @param[in] devp pointer to the @p LSM6DS0Driver object
1074 *
1075 * @api
1076 */
1078 uint8_t cr[2];
1079
1080 osalDbgCheck(devp != NULL);
1081
1082 osalDbgAssert((devp->state == LSM6DS0_STOP) || (devp->state == LSM6DS0_READY),
1083 "lsm6ds0Stop(), invalid state");
1084
1085 if (devp->state == LSM6DS0_READY) {
1086#if LSM6DS0_USE_I2C
1087#if LSM6DS0_SHARED_I2C
1088 i2cAcquireBus(devp->config->i2cp);
1089 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
1090#endif /* LSM6DS0_SHARED_I2C */
1091
1092 /* Disabling accelerometer.*/
1094 cr[1] = 0;
1095 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
1096 cr, 1);
1097
1098 /* Disabling gyroscope.*/
1099 cr[0] = LSM6DS0_AD_CTRL_REG9;
1101 lsm6ds0I2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
1102 cr, 1);
1103
1104 i2cStop(devp->config->i2cp);
1105#if LSM6DS0_SHARED_I2C
1106 i2cReleaseBus(devp->config->i2cp);
1107#endif /* LSM6DS0_SHARED_I2C */
1108#endif /* LSM6DS0_USE_I2C */
1109 }
1110 devp->state = LSM6DS0_STOP;
1111}
1112/** @} */
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 LSM6DS0_ACC_SENS_2G
Definition lsm6ds0.h:79
#define LSM6DS0_CTRL_REG6_XL_FS_MASK
Definition lsm6ds0.h:245
#define LSM6DS0_AD_OUT_X_L_XL
Definition lsm6ds0.h:156
#define LSM6DS0_ACC_16G
Definition lsm6ds0.h:77
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
Definition lsm6ds0.c:95
#define LSM6DS0_CTRL_REG1_G_FS_MASK
Definition lsm6ds0.h:181
#define LSM6DS0_CTRL_REG9_SLEEP_G
Definition lsm6ds0.h:290
void lsm6ds0Stop(LSM6DS0Driver *devp)
Deactivates the LSM6DS0 Complex Driver peripheral.
Definition lsm6ds0.c:1077
#define LSM6DS0_ACC_SENS_16G
Definition lsm6ds0.h:82
static msg_t acc_set_full_scale(LSM6DS0Driver *devp, lsm6ds0_acc_fs_t fs)
Changes the LSM6DS0Driver accelerometer fullscale value.
Definition lsm6ds0.c:339
void lsm6ds0Start(LSM6DS0Driver *devp, const LSM6DS0Config *config)
Configures and activates LSM6DS0 Complex Driver peripheral.
Definition lsm6ds0.c:845
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
Definition lsm6ds0.c:294
#define LSM6DS0_GYRO_BIAS
Definition lsm6ds0.h:105
#define LSM6DS0_CTRL_REG4_ZEN_G
Definition lsm6ds0.h:222
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
Definition lsm6ds0.c:206
#define LSM6DS0_AD_CTRL_REG9
Definition lsm6ds0.h:152
#define LSM6DS0_AD_OUT_X_L_G
Definition lsm6ds0.h:141
#define LSM6DS0_CTRL_REG5_XL_XEN_XL
Definition lsm6ds0.h:230
lsm6ds0_sad_t
Accelerometer and Gyroscope Slave Address.
Definition lsm6ds0.h:422
#define LSM6DS0_ACC_SENS_8G
Definition lsm6ds0.h:81
#define LSM6DS0_GYRO_2000DPS
Definition lsm6ds0.h:99
#define LSM6DS0_ACC_4G
Definition lsm6ds0.h:75
#define LSM6DS0_GYRO_NUMBER_OF_AXES
L3GD20 gyroscope system characteristics.
Definition lsm6ds0.h:95
#define LSM6DS0_GYRO_500DPS
Definition lsm6ds0.h:98
#define LSM6DS0_ACC_BIAS
Definition lsm6ds0.h:84
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
Definition lsm6ds0.c:235
#define LSM6DS0_ACC_2G
Definition lsm6ds0.h:74
#define LSM6DS0_CTRL_REG4_XEN_G
Definition lsm6ds0.h:220
void lsm6ds0ObjectInit(LSM6DS0Driver *devp)
Initializes an instance.
Definition lsm6ds0.c:824
#define LSM6DS0_GYRO_SENS_2000DPS
Definition lsm6ds0.h:103
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
Definition lsm6ds0.c:265
#define lsm6ds0I2CWriteRegister(i2cp, sad, txbuf, n)
Writes a value into a register using I2C.
Definition lsm6ds0.c:83
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
Definition lsm6ds0.c:173
#define LSM6DS0_ACC_8G
Definition lsm6ds0.h:76
#define LSM6DS0_AD_CTRL_REG8
Definition lsm6ds0.h:151
static msg_t gyro_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseGyroscope.
Definition lsm6ds0.c:648
#define LSM6DS0_CTRL_REG8_IF_ADD_INC
Definition lsm6ds0.h:272
static size_t gyro_get_axes_number(void *ip)
Return the number of axes of the BaseGyroscope.
Definition lsm6ds0.c:430
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
Definition lsm6ds0.c:117
#define LSM6DS0_AD_CTRL_REG1_G
Definition lsm6ds0.h:133
#define LSM6DS0_CTRL_REG5_XL_ZEN_XL
Definition lsm6ds0.h:232
lsm6ds0_acc_fs_t
LSM6DS0 accelerometer subsystem full scale.
Definition lsm6ds0.h:430
static msg_t gyro_sample_bias(void *ip)
Samples bias values for the BaseGyroscope.
Definition lsm6ds0.c:541
#define LSM6DS0_AD_CTRL_REG6_XL
Definition lsm6ds0.h:149
static msg_t gyro_set_full_scale(LSM6DS0Driver *devp, lsm6ds0_gyro_fs_t fs)
Changes the LSM6DS0Driver gyroscope fullscale value.
Definition lsm6ds0.c:719
static msg_t gyro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseGyroscope.
Definition lsm6ds0.c:508
#define LSM6DS0_GYRO_BIAS_ACQ_TIMES
Number of acquisitions for gyroscope bias removal.
Definition lsm6ds0.h:363
#define LSM6DS0_GYRO_SENS_245DPS
Definition lsm6ds0.h:101
#define LSM6DS0_CTRL_REG4_YEN_G
Definition lsm6ds0.h:221
#define LSM6DS0_CTRL_REG5_XL_YEN_XL
Definition lsm6ds0.h:231
#define LSM6DS0_ACC_SENS_4G
Definition lsm6ds0.h:80
static msg_t gyro_set_bias(void *ip, float *bp)
Set bias values for the BaseGyroscope.
Definition lsm6ds0.c:589
#define LSM6DS0_GYRO_BIAS_SETTLING_US
Settling time for gyroscope bias removal.
Definition lsm6ds0.h:371
#define LSM6DS0_ACC_NUMBER_OF_AXES
LSM6DS0 accelerometer subsystem characteristics.
Definition lsm6ds0.h:72
lsm6ds0_gyro_fs_t
LSM6DS0 gyroscope subsystem full scale.
Definition lsm6ds0.h:463
#define LSM6DS0_GYRO_SENS_500DPS
Definition lsm6ds0.h:102
#define LSM6DS0_GYRO_245DPS
Definition lsm6ds0.h:97
static msg_t gyro_reset_sensivity(void *ip)
Reset sensitivity values for the BaseGyroscope.
Definition lsm6ds0.c:677
#define LSM6DS0_AD_CTRL_REG5_XL
Definition lsm6ds0.h:148
static msg_t gyro_reset_bias(void *ip)
Reset bias values for the BaseGyroscope.
Definition lsm6ds0.c:618
static msg_t gyro_read_raw(void *ip, int32_t axes[LSM6DS0_GYRO_NUMBER_OF_AXES])
Retrieves raw data from the BaseGyroscope.
Definition lsm6ds0.c:452
msg_t lsm6ds0I2CReadRegister(I2CDriver *i2cp, lsm6ds0_sad_t sad, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
Definition lsm6ds0.c:63
@ LSM6DS0_READY
Definition lsm6ds0.h:556
@ LSM6DS0_STOP
Definition lsm6ds0.h:555
@ LSM6DS0_ACC_FS_8G
Definition lsm6ds0.h:433
@ LSM6DS0_ACC_FS_2G
Definition lsm6ds0.h:431
@ LSM6DS0_ACC_FS_4G
Definition lsm6ds0.h:432
@ LSM6DS0_ACC_FS_16G
Definition lsm6ds0.h:434
@ LSM6DS0_GYRO_FS_245DPS
Definition lsm6ds0.h:464
@ LSM6DS0_GYRO_FS_500DPS
Definition lsm6ds0.h:465
@ LSM6DS0_GYRO_FS_2000DPS
Definition lsm6ds0.h:466
#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.
LSM6DS0 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.
LSM6DS0 configuration structure.
Definition lsm6ds0.h:562
LSM6DS0 6-axis accelerometer/gyroscope class.
Definition lsm6ds0.h:709
BaseGyroscope gyro_if
Base gyroscope interface.
Definition lsm6ds0.h:715
const struct LSM6DS0VMT * vmt
Virtual Methods Table.
Definition lsm6ds0.h:711
BaseAccelerometer acc_if
Base accelerometer interface.
Definition lsm6ds0.h:713
LSM6DS0 virtual methods table.
Definition lsm6ds0.h:676