ChibiOS 21.11.4
lsm303dlhc.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 lsm303dlhc.c
23 * @brief LSM303DLHC MEMS interface module code.
24 *
25 * @addtogroup LSM303DLHC
26 * @ingroup EX_ST
27 * @{
28 */
29
30#include "hal.h"
31#include "lsm303dlhc.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 * @brief Accelerometer and Compass Slave Address.
47 */
48typedef enum {
49 LSM303DLHC_SAD_ACC = 0x19, /**< SAD for accelerometer. */
50 LSM303DLHC_SAD_COMP = 0x1E /**< SAD for compass. */
52
53/*===========================================================================*/
54/* Driver local functions. */
55/*===========================================================================*/
56
57/**
58 * @brief Reads registers value using I2C.
59 * @pre The I2C interface must be initialized and the driver started.
60 * @note IF_ADD_INC bit must be 1 in CTRL_REG8.
61 *
62 * @param[in] i2cp pointer to the I2C interface.
63 * @param[in] sad slave address without R bit.
64 * @param[in] reg first sub-register address.
65 * @param[in] rxbuf receiving buffer.
66 * @param[in] n size of rxbuf.
67 * @return the operation status.
68 */
70 uint8_t reg, uint8_t *rxbuf, size_t n) {
71
72 uint8_t txbuf = reg | LSM303DLHC_MS;
73 return i2cMasterTransmitTimeout(i2cp, sad, &txbuf, 1, rxbuf, n,
75}
76
77/**
78 * @brief Writes a value into a register using I2C.
79 * @pre The I2C interface must be initialized and the driver started.
80 *
81 * @param[in] i2cp pointer to the I2C interface.
82 * @param[in] sad slave address without R bit.
83 * @param[in] txbuf buffer containing sub-address value in first position
84 * and values to write.
85 * @param[in] n size of txbuf less one (not considering the first
86 * element).
87 * @return the operation status.
88 */
90 uint8_t *txbuf, size_t n) {
91 if (n != 1)
92 *txbuf |= LSM303DLHC_MS;
93 return i2cMasterTransmitTimeout(i2cp, sad, txbuf, n + 1, NULL, 0,
95}
96
97/**
98 * @brief Return the number of axes of the BaseAccelerometer.
99 *
100 * @param[in] ip pointer to @p BaseAccelerometer interface.
101 *
102 * @return the number of axes.
103 */
104static size_t acc_get_axes_number(void *ip) {
105 (void)ip;
106
108}
109
110/**
111 * @brief Retrieves raw data from the BaseAccelerometer.
112 * @note This data is retrieved from MEMS register without any algebraical
113 * manipulation.
114 * @note The axes array must be at least the same size of the
115 * BaseAccelerometer axes number.
116 *
117 * @param[in] ip pointer to @p BaseAccelerometer interface.
118 * @param[out] axes a buffer which would be filled with raw data.
119 *
120 * @return The operation status.
121 * @retval MSG_OK if the function succeeded.
122 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
123 * be retrieved using @p i2cGetErrors().
124 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
125 */
126static msg_t acc_read_raw(void *ip, int32_t axes[]) {
127 LSM303DLHCDriver* devp;
128 uint8_t buff [LSM303DLHC_ACC_NUMBER_OF_AXES * 2], i;
129 int16_t tmp;
130 msg_t msg;
131
132 osalDbgCheck((ip != NULL) && (axes != NULL));
133
134 /* Getting parent instance pointer.*/
136
137 osalDbgAssert((devp->state == LSM303DLHC_READY),
138 "acc_read_raw(), invalid state");
139 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
140 "acc_read_raw(), channel not ready");
141
142#if LSM303DLHC_SHARED_I2C
143 i2cAcquireBus(devp->config->i2cp);
144 i2cStart(devp->config->i2cp,
145 devp->config->i2ccfg);
146#endif /* LSM303DLHC_SHARED_I2C */
147
148 msg = lsm303dlhcI2CReadRegister(devp->config->i2cp, LSM303DLHC_SAD_ACC,
151
152#if LSM303DLHC_SHARED_I2C
153 i2cReleaseBus(devp->config->i2cp);
154#endif /* LSM303DLHC_SHARED_I2C */
155
156 if(msg == MSG_OK)
157 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
158 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
159 axes[i] = (int32_t)tmp;
160 }
161 return msg;
162}
163
164/**
165 * @brief Retrieves cooked data from the BaseAccelerometer.
166 * @note This data is manipulated according to the formula
167 * cooked = (raw * sensitivity) - bias.
168 * @note Final data is expressed as milli-G.
169 * @note The axes array must be at least the same size of the
170 * BaseAccelerometer axes number.
171 *
172 * @param[in] ip pointer to @p BaseAccelerometer interface.
173 * @param[out] axes a buffer which would be filled with cooked data.
174 *
175 * @return The operation status.
176 * @retval MSG_OK if the function succeeded.
177 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
178 * be retrieved using @p i2cGetErrors().
179 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
180 */
181static msg_t acc_read_cooked(void *ip, float axes[]) {
182 LSM303DLHCDriver* devp;
183 uint32_t i;
185 msg_t msg;
186
187 osalDbgCheck((ip != NULL) && (axes != NULL));
188
189 /* Getting parent instance pointer.*/
191
192 osalDbgAssert((devp->state == LSM303DLHC_READY),
193 "acc_read_cooked(), invalid state");
194
195 msg = acc_read_raw(ip, raw);
196 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
197 axes[i] = (raw[i] * devp->accsensitivity[i]) - devp->accbias[i];
198 }
199 return msg;
200}
201
202/**
203 * @brief Set bias values for the BaseAccelerometer.
204 * @note Bias must be expressed as milli-G.
205 * @note The bias buffer must be at least the same size of the
206 * BaseAccelerometer axes number.
207 *
208 * @param[in] ip pointer to @p BaseAccelerometer interface.
209 * @param[in] bp a buffer which contains biases.
210 *
211 * @return The operation status.
212 * @retval MSG_OK if the function succeeded.
213 */
214static msg_t acc_set_bias(void *ip, float *bp) {
215 LSM303DLHCDriver* devp;
216 uint32_t i;
217 msg_t msg = MSG_OK;
218
219 osalDbgCheck((ip != NULL) && (bp != NULL));
220
221 /* Getting parent instance pointer.*/
223
224 osalDbgAssert((devp->state == LSM303DLHC_READY),
225 "acc_set_bias(), invalid state");
226
227 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
228 devp->accbias[i] = bp[i];
229 }
230 return msg;
231}
232
233/**
234 * @brief Reset bias values for the BaseAccelerometer.
235 * @note Default biases value are obtained from device datasheet when
236 * available otherwise they are considered zero.
237 *
238 * @param[in] ip pointer to @p BaseAccelerometer interface.
239 *
240 * @return The operation status.
241 * @retval MSG_OK if the function succeeded.
242 */
243static msg_t acc_reset_bias(void *ip) {
244 LSM303DLHCDriver* devp;
245 uint32_t i;
246 msg_t msg = MSG_OK;
247
248 osalDbgCheck(ip != NULL);
249
250 /* Getting parent instance pointer.*/
252
253 osalDbgAssert((devp->state == LSM303DLHC_READY),
254 "acc_reset_bias(), invalid state");
255
256 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
257 devp->accbias[i] = LSM303DLHC_ACC_BIAS;
258 return msg;
259}
260
261/**
262 * @brief Set sensitivity values for the BaseAccelerometer.
263 * @note Sensitivity must be expressed as milli-G/LSB.
264 * @note The sensitivity buffer must be at least the same size of the
265 * BaseAccelerometer axes number.
266 *
267 * @param[in] ip pointer to @p BaseAccelerometer interface.
268 * @param[in] sp a buffer which contains sensitivities.
269 *
270 * @return The operation status.
271 * @retval MSG_OK if the function succeeded.
272 */
273static msg_t acc_set_sensivity(void *ip, float *sp) {
274 LSM303DLHCDriver* devp;
275 uint32_t i;
276 msg_t msg = MSG_OK;
277
278 /* Getting parent instance pointer.*/
280
281 osalDbgCheck((ip != NULL) && (sp != NULL));
282
283 osalDbgAssert((devp->state == LSM303DLHC_READY),
284 "acc_set_sensivity(), invalid state");
285
286 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
287 devp->accsensitivity[i] = sp[i];
288 }
289 return msg;
290}
291
292/**
293 * @brief Reset sensitivity values for the BaseAccelerometer.
294 * @note Default sensitivities value are obtained from device datasheet.
295 *
296 * @param[in] ip pointer to @p BaseAccelerometer interface.
297 *
298 * @return The operation status.
299 * @retval MSG_OK if the function succeeded.
300 * @retval MSG_RESET otherwise.
301 */
302static msg_t acc_reset_sensivity(void *ip) {
303 LSM303DLHCDriver* devp;
304 uint32_t i;
305 msg_t msg = MSG_OK;
306
307 osalDbgCheck(ip != NULL);
308
309 /* Getting parent instance pointer.*/
311
312 osalDbgAssert((devp->state == LSM303DLHC_READY),
313 "acc_reset_sensivity(), invalid state");
314
315 if(devp->config->accfullscale == LSM303DLHC_ACC_FS_2G)
316 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
317 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_2G;
318 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_4G)
319 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
320 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_4G;
321 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_8G)
322 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
323 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_8G;
324 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_16G)
325 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
326 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_16G;
327 else {
328 osalDbgAssert(FALSE, "acc_reset_sensivity(), accelerometer full scale issue");
329 msg = MSG_RESET;
330 }
331 return msg;
332}
333
334/**
335 * @brief Changes the LSM303DLHCDriver accelerometer fullscale value.
336 * @note This function also rescale sensitivities and biases based on
337 * previous and next fullscale value.
338 * @note A recalibration is highly suggested after calling this function.
339 *
340 * @param[in] devp pointer to @p LSM303DLHCDriver interface.
341 * @param[in] fs new fullscale value.
342 *
343 * @return The operation status.
344 * @retval MSG_OK if the function succeeded.
345 * @retval MSG_RESET otherwise.
346 */
349 float newfs, scale;
350 uint8_t i, buff[2];
351 msg_t msg;
352
353 osalDbgCheck(devp != NULL);
354
355 osalDbgAssert((devp->state == LSM303DLHC_READY),
356 "acc_set_full_scale(), invalid state");
357 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
358 "acc_set_full_scale(), channel not ready");
359
360 /* Computing new fullscale value.*/
361 if(fs == LSM303DLHC_ACC_FS_2G) {
362 newfs = LSM303DLHC_ACC_2G;
363 msg = MSG_OK;
364 }
365 else if(fs == LSM303DLHC_ACC_FS_4G) {
366 newfs = LSM303DLHC_ACC_4G;
367 msg = MSG_OK;
368 }
369 else if(fs == LSM303DLHC_ACC_FS_8G) {
370 newfs = LSM303DLHC_ACC_8G;
371 msg = MSG_OK;
372 }
373 else if(fs == LSM303DLHC_ACC_FS_16G) {
374 newfs = LSM303DLHC_ACC_16G;
375 msg = MSG_OK;
376 }
377 else {
378 msg = MSG_RESET;
379 }
380
381 if((msg == MSG_OK) &&
382 (newfs != devp->accfullscale)) {
383 /* Computing scale value.*/
384 scale = newfs / devp->accfullscale;
385 devp->accfullscale = newfs;
386
387#if LSM303DLHC_SHARED_I2C
388 i2cAcquireBus(devp->config->i2cp);
389 i2cStart(devp->config->i2cp,
390 devp->config->i2ccfg);
391#endif /* LSM303DLHC_SHARED_I2C */
392
393 /* Updating register.*/
394 msg = lsm303dlhcI2CReadRegister(devp->config->i2cp,
397 &buff[1], 1);
398
399#if LSM303DLHC_SHARED_I2C
400 i2cReleaseBus(devp->config->i2cp);
401#endif /* LSM303DLHC_SHARED_I2C */
402
403 if(msg == MSG_OK) {
404
405 buff[1] &= ~(LSM303DLHC_CTRL_REG4_A_FS_MASK);
406 buff[1] |= fs;
408
409#if LSM303DLHC_SHARED_I2C
410 i2cAcquireBus(devp->config->i2cp);
411 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
412#endif /* LSM303DLHC_SHARED_I2C */
413
414 msg = lsm303dlhcI2CWriteRegister(devp->config->i2cp,
415 LSM303DLHC_SAD_ACC, buff, 1);
416
417#if LSM303DLHC_SHARED_I2C
418 i2cReleaseBus(devp->config->i2cp);
419#endif /* LSM303DLHC_SHARED_I2C */
420 }
421 if(msg == MSG_OK) {
422
423 /* Scaling sensitivity and bias. Re-calibration is suggested anyway.*/
424 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
425 devp->accsensitivity[i] *= scale;
426 devp->accbias[i] *= scale;
427 }
428 }
429 }
430 return msg;
431}
432
433/**
434 * @brief Return the number of axes of the BaseCompass.
435 *
436 * @param[in] ip pointer to @p BaseCompass interface
437 *
438 * @return the number of axes.
439 */
440static size_t comp_get_axes_number(void *ip) {
441
442 osalDbgCheck(ip != NULL);
444}
445
446/**
447 * @brief Retrieves raw data from the BaseCompass.
448 * @note This data is retrieved from MEMS register without any algebraical
449 * manipulation.
450 * @note The axes array must be at least the same size of the
451 * BaseCompass axes number.
452 *
453 * @param[in] ip pointer to @p BaseCompass interface.
454 * @param[out] axes a buffer which would be filled with raw data.
455 *
456 * @return The operation status.
457 * @retval MSG_OK if the function succeeded.
458 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
459 * be retrieved using @p i2cGetErrors().
460 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
461 */
462static msg_t comp_read_raw(void *ip, int32_t axes[]) {
463 LSM303DLHCDriver* devp;
464 uint8_t buff [LSM303DLHC_COMP_NUMBER_OF_AXES * 2], i;
465 int16_t tmp;
466 msg_t msg;
467
468 osalDbgCheck((ip != NULL) && (axes != NULL));
469
470 /* Getting parent instance pointer.*/
472
473 osalDbgAssert((devp->state == LSM303DLHC_READY),
474 "comp_read_raw(), invalid state");
475 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
476 "comp_read_raw(), channel not ready");
477
478#if LSM303DLHC_SHARED_I2C
479 i2cAcquireBus(devp->config->i2cp);
480 i2cStart(devp->config->i2cp,
481 devp->config->i2ccfg);
482#endif /* LSM303DLHC_SHARED_I2C */
483 msg = lsm303dlhcI2CReadRegister(devp->config->i2cp, LSM303DLHC_SAD_COMP,
486
487#if LSM303DLHC_SHARED_I2C
488 i2cReleaseBus(devp->config->i2cp);
489#endif /* LSM303DLHC_SHARED_I2C */
490
491 if(msg == MSG_OK)
492 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
493 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
494 axes[i] = (int32_t)tmp;
495 }
496 return msg;
497}
498
499/**
500 * @brief Retrieves cooked data from the BaseCompass.
501 * @note This data is manipulated according to the formula
502 * cooked = (raw * sensitivity) - bias.
503 * @note Final data is expressed as G.
504 * @note The axes array must be at least the same size of the
505 * BaseCompass axes number.
506 *
507 * @param[in] ip pointer to @p BaseCompass interface.
508 * @param[out] axes a buffer which would be filled with cooked data.
509 *
510 * @return The operation status.
511 * @retval MSG_OK if the function succeeded.
512 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
513 * be retrieved using @p i2cGetErrors().
514 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
515 */
516static msg_t comp_read_cooked(void *ip, float axes[]) {
517 LSM303DLHCDriver* devp;
518 uint32_t i;
520 msg_t msg;
521
522 osalDbgCheck((ip != NULL) && (axes != NULL));
523
524
525 /* Getting parent instance pointer.*/
527
528 osalDbgAssert((devp->state == LSM303DLHC_READY),
529 "comp_read_cooked(), invalid state");
530
531 msg = comp_read_raw(ip, raw);
532 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES ; i++) {
533 axes[i] = (raw[i] * devp->compsensitivity[i]) - devp->compbias[i];
534 }
535 return msg;
536}
537
538/**
539 * @brief Set bias values for the BaseCompass.
540 * @note Bias must be expressed as G.
541 * @note The bias buffer must be at least the same size of the
542 * BaseCompass axes number.
543 *
544 * @param[in] ip pointer to @p BaseCompass interface.
545 * @param[in] bp a buffer which contains biases.
546 *
547 * @return The operation status.
548 * @retval MSG_OK if the function succeeded.
549 */
550static msg_t comp_set_bias(void *ip, float *bp) {
551 LSM303DLHCDriver* devp;
552 uint32_t i;
553 msg_t msg = MSG_OK;
554
555 osalDbgCheck((ip != NULL) && (bp != NULL));
556
557 /* Getting parent instance pointer.*/
559
560 osalDbgAssert((devp->state == LSM303DLHC_READY),
561 "comp_set_bias(), invalid state");
562
563 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
564 devp->compbias[i] = bp[i];
565 }
566 return msg;
567}
568
569/**
570 * @brief Reset bias values for the BaseCompass.
571 * @note Default biases value are obtained from device datasheet when
572 * available otherwise they are considered zero.
573 *
574 * @param[in] ip pointer to @p BaseCompass interface.
575 *
576 * @return The operation status.
577 * @retval MSG_OK if the function succeeded.
578 */
579static msg_t comp_reset_bias(void *ip) {
580 LSM303DLHCDriver* devp;
581 uint32_t i;
582 msg_t msg = MSG_OK;
583
584 osalDbgCheck(ip != NULL);
585
586 /* Getting parent instance pointer.*/
588
589 osalDbgAssert((devp->state == LSM303DLHC_READY),
590 "comp_reset_bias(), invalid state");
591
592 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
593 devp->compbias[i] = LSM303DLHC_COMP_BIAS;
594 return msg;
595}
596
597/**
598 * @brief Set sensitivity values for the BaseCompass.
599 * @note Sensitivity must be expressed as G/LSB.
600 * @note The sensitivity buffer must be at least the same size of the
601 * BaseCompass axes number.
602 *
603 * @param[in] ip pointer to @p BaseCompass interface.
604 * @param[in] sp a buffer which contains sensitivities.
605 *
606 * @return The operation status.
607 * @retval MSG_OK if the function succeeded.
608 */
609static msg_t comp_set_sensivity(void *ip, float *sp) {
610 LSM303DLHCDriver* devp;
611 uint32_t i;
612 msg_t msg = MSG_OK;
613
614 /* Getting parent instance pointer.*/
616
617 osalDbgCheck((ip != NULL) && (sp != NULL));
618
619 osalDbgAssert((devp->state == LSM303DLHC_READY),
620 "comp_set_sensivity(), invalid state");
621
622 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
623 devp->compsensitivity[i] = sp[i];
624 }
625 return msg;
626}
627
628/**
629 * @brief Reset sensitivity values for the BaseCompass.
630 * @note Default sensitivities value are obtained from device datasheet.
631 *
632 * @param[in] ip pointer to @p BaseCompass interface.
633 *
634 * @return The operation status.
635 * @retval MSG_OK if the function succeeded.
636 * @retval MSG_RESET otherwise.
637 */
638static msg_t comp_reset_sensivity(void *ip) {
639 LSM303DLHCDriver* devp;
640 uint32_t i;
641 msg_t msg = MSG_OK;
642
643 osalDbgCheck(ip != NULL);
644
645 /* Getting parent instance pointer.*/
647
648 osalDbgAssert((devp->state == LSM303DLHC_READY),
649 "comp_reset_sensivity(), invalid state");
650
651 if(devp->config->compfullscale == LSM303DLHC_COMP_FS_1P3GA)
652 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
653 if(i != 2) {
654 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_1P3GA;
655 }
656 else {
657 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_1P3GA;
658 }
659 }
660 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_1P9GA)
661 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
662 if(i != 2) {
663 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_1P9GA;
664 }
665 else {
666 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_1P9GA;
667 }
668 }
669 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_2P5GA)
670 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
671 if(i != 2) {
672 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_2P5GA;
673 }
674 else {
675 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_2P5GA;
676 }
677 }
678 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_4P0GA)
679 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
680 if(i != 2) {
681 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_4P0GA;
682 }
683 else {
684 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_4P0GA;
685 }
686 }
687 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_4P7GA)
688 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
689 if(i != 2) {
690 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_4P7GA;
691 }
692 else {
693 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_4P7GA;
694 }
695 }
696 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_5P6GA)
697 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
698 if(i != 2) {
699 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_5P6GA;
700 }
701 else {
702 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_5P6GA;
703 }
704 }
705 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_8P1GA)
706 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
707 if(i != 2) {
708 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_8P1GA;
709 }
710 else {
711 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_8P1GA;
712 }
713 }
714 else {
715 osalDbgAssert(FALSE, "comp_reset_sensivity(), compass full scale issue");
716 msg = MSG_RESET;
717 }
718 return msg;
719}
720
721/**
722 * @brief Changes the LSM303DLHCDriver compass fullscale value.
723 * @note This function also rescale sensitivities and biases based on
724 * previous and next fullscale value.
725 * @note A recalibration is highly suggested after calling this function.
726 *
727 * @param[in] devp pointer to @p LSM303DLHCDriver interface.
728 * @param[in] fs new fullscale value.
729 *
730 * @return The operation status.
731 * @retval MSG_OK if the function succeeded.
732 * @retval MSG_RESET otherwise.
733 */
736 float newfs, scale;
737 uint8_t i, buff[2];
738 msg_t msg;
739
740 osalDbgCheck(devp != NULL);
741
742 osalDbgAssert((devp->state == LSM303DLHC_READY),
743 "comp_set_full_scale(), invalid state");
744 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
745 "comp_set_full_scale(), channel not ready");
746
747 /* Computing new fullscale value.*/
748 if(fs == LSM303DLHC_COMP_FS_1P3GA) {
749 newfs = LSM303DLHC_COMP_1P3GA;
750 }
751 else if(fs == LSM303DLHC_COMP_FS_1P9GA) {
752 newfs = LSM303DLHC_COMP_1P9GA;
753 }
754 else if(fs == LSM303DLHC_COMP_FS_2P5GA) {
755 newfs = LSM303DLHC_COMP_2P5GA;
756 }
757 else if(fs == LSM303DLHC_COMP_FS_4P0GA) {
758 newfs = LSM303DLHC_COMP_4P0GA;
759 }
760 else if(fs == LSM303DLHC_COMP_FS_4P7GA) {
761 newfs = LSM303DLHC_COMP_4P7GA;
762 }
763 else if(fs == LSM303DLHC_COMP_FS_5P6GA) {
764 newfs = LSM303DLHC_COMP_5P6GA;
765 }
766 else if(fs == LSM303DLHC_COMP_FS_8P1GA) {
767 newfs = LSM303DLHC_COMP_8P1GA;
768 }
769 else {
770 msg = MSG_RESET;
771 return msg;
772 }
773
774 if(newfs != devp->compfullscale) {
775 /* Computing scale value.*/
776 scale = newfs / devp->compfullscale;
777 devp->compfullscale = newfs;
778
779#if LSM303DLHC_SHARED_I2C
780 i2cAcquireBus(devp->config->i2cp);
781 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
782#endif /* LSM303DLHC_SHARED_I2C */
783
784 /* Updating register.*/
785 msg = lsm303dlhcI2CReadRegister(devp->config->i2cp, LSM303DLHC_SAD_COMP,
786 LSM303DLHC_AD_COMP_CRB_REG, &buff[1], 1);
787
788#if LSM303DLHC_SHARED_I2C
789 i2cReleaseBus(devp->config->i2cp);
790#endif /* LSM303DLHC_SHARED_I2C */
791
792 if(msg != MSG_OK)
793 return msg;
794 buff[1] &= ~(LSM303DLHC_CRB_REG_M_GN_MASK);
795 buff[1] |= fs;
797
798#if LSM303DLHC_SHARED_I2C
799 i2cAcquireBus(devp->config->i2cp);
800 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
801#endif /* LSM303DLHC_SHARED_I2C */
802
803 msg = lsm303dlhcI2CWriteRegister(devp->config->i2cp, LSM303DLHC_SAD_COMP,
804 buff, 1);
805
806#if LSM303DLHC_SHARED_I2C
807 i2cReleaseBus(devp->config->i2cp);
808#endif /* LSM303DLHC_SHARED_I2C */
809
810 if(msg != MSG_OK)
811 return msg;
812
813 /* Scaling sensitivity and bias. Re-calibration is suggested anyway.*/
814 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
815 devp->compsensitivity[i] *= scale;
816 devp->compbias[i] *= scale;
817 }
818 }
819 return msg;
820}
821
822static const struct LSM303DLHCVMT vmt_device = {
823 (size_t)0,
825};
826
832
838
839/*===========================================================================*/
840/* Driver exported functions. */
841/*===========================================================================*/
842
843/**
844 * @brief Initializes an instance.
845 *
846 * @param[out] devp pointer to the @p LSM303DLHCDriver object
847 *
848 * @init
849 */
851 devp->vmt = &vmt_device;
853 devp->comp_if.vmt = &vmt_compass;
854
855 devp->config = NULL;
856
857 devp->accaxes = LSM303DLHC_ACC_NUMBER_OF_AXES;
858 devp->compaxes = LSM303DLHC_COMP_NUMBER_OF_AXES;
859
860 devp->state = LSM303DLHC_STOP;
861}
862
863/**
864 * @brief Configures and activates LSM303DLHC Complex Driver peripheral.
865 *
866 * @param[in] devp pointer to the @p LSM303DLHCDriver object
867 * @param[in] config pointer to the @p LSM303DLHCConfig object
868 *
869 * @api
870 */
872 uint32_t i;
873 uint8_t cr[6];
874 osalDbgCheck((devp != NULL) && (config != NULL));
875
876 osalDbgAssert((devp->state == LSM303DLHC_STOP) ||
877 (devp->state == LSM303DLHC_READY),
878 "lsm303dlhcStart(), invalid state");
879
880 devp->config = config;
881
882 /* Configuring Accelerometer subsystem.*/
883
884 /* Multiple write starting address.*/
886
887 /* Control register 1 configuration block.*/
888 {
890 LSM303DLHC_CTRL_REG1_A_ZEN | devp->config->accodr;
891#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
892 cr[1] |= devp->config->acclowpower;
893#endif
894 }
895
896 /* Control register 2 configuration block.*/
897 {
898 cr[2] = 0;
899 }
900
901 /* Control register 3 configuration block.*/
902 {
903 cr[3] = 0;
904 }
905
906 /* Control register 4 configuration block.*/
907 {
908 cr[4] = devp->config->accfullscale;
909#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
910 cr[4] |= devp->config->accendianess |
911 devp->config->accbdu |
912 devp->config->acchighresmode;
913#endif
914 }
915
916#if LSM303DLHC_SHARED_I2C
917 i2cAcquireBus((devp)->config->i2cp);
918#endif /* LSM303DLHC_SHARED_I2C */
919 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
920
921 lsm303dlhcI2CWriteRegister(devp->config->i2cp, LSM303DLHC_SAD_ACC, cr, 4);
922
923#if LSM303DLHC_SHARED_I2C
924 i2cReleaseBus((devp)->config->i2cp);
925#endif /* LSM303DLHC_SHARED_I2C */
926
927 /* Storing sensitivity according to user settings */
928 if(devp->config->accfullscale == LSM303DLHC_ACC_FS_2G) {
929 devp->accfullscale = LSM303DLHC_ACC_2G;
930 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
931 if(devp->config->accsensitivity == NULL)
932 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_2G;
933 else
934 devp->accsensitivity[i] = devp->config->accsensitivity[i];
935 }
936 }
937 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_4G) {
938 devp->accfullscale = LSM303DLHC_ACC_4G;
939 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
940 if(devp->config->accsensitivity == NULL)
941 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_4G;
942 else
943 devp->accsensitivity[i] = devp->config->accsensitivity[i];
944 }
945 }
946 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_8G) {
947 devp->accfullscale = LSM303DLHC_ACC_8G;
948 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
949 if(devp->config->accsensitivity == NULL)
950 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_8G;
951 else
952 devp->accsensitivity[i] = devp->config->accsensitivity[i];
953 }
954 }
955 else if(devp->config->accfullscale == LSM303DLHC_ACC_FS_16G) {
956 devp->accfullscale = LSM303DLHC_ACC_16G;
957 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) {
958 if(devp->config->accsensitivity == NULL)
959 devp->accsensitivity[i] = LSM303DLHC_ACC_SENS_16G;
960 else
961 devp->accsensitivity[i] = devp->config->accsensitivity[i];
962 }
963 }
964 else
965 osalDbgAssert(FALSE, "lsm303dlhcStart(), accelerometer full scale issue");
966
967 /* Storing bias information */
968 if(devp->config->accbias != NULL)
969 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
970 devp->accbias[i] = devp->config->accbias[i];
971 else
972 for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
973 devp->accbias[i] = LSM303DLHC_ACC_BIAS;
974
975 /* Configuring Compass subsystem */
976 /* Multiple write starting address.*/
978
979 /* Control register A configuration block.*/
980 {
981 cr[1] = devp->config->compodr;
982 }
983
984 /* Control register B configuration block.*/
985 {
986 cr[2] = devp->config->compfullscale;
987 }
988
989 /* Mode register configuration block.*/
990 {
991 cr[3] = 0;
992#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
993 cr[3] |= devp->config->compmode;
994#endif
995 }
996
997#if LSM303DLHC_SHARED_I2C
998 i2cAcquireBus((devp)->config->i2cp);
999 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
1000#endif /* LSM303DLHC_SHARED_I2C */
1001
1003 cr, 3);
1004
1005#if LSM303DLHC_SHARED_I2C
1006 i2cReleaseBus((devp)->config->i2cp);
1007#endif /* LSM303DLHC_SHARED_I2C */
1008
1009 if(devp->config->compfullscale == LSM303DLHC_COMP_FS_1P3GA) {
1010 devp->compfullscale = LSM303DLHC_COMP_1P3GA;
1011 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1012 if(devp->config->compsensitivity == NULL) {
1013 if(i != 2) {
1014 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_1P3GA;
1015 }
1016 else {
1017 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_1P3GA;
1018 }
1019 }
1020 else {
1021 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1022 }
1023 }
1024 }
1025 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_1P9GA) {
1026 devp->compfullscale = LSM303DLHC_COMP_1P9GA;
1027 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1028 if(devp->config->compsensitivity == NULL) {
1029 if(i != 2) {
1030 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_1P9GA;
1031 }
1032 else {
1033 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_1P9GA;
1034 }
1035 }
1036 else {
1037 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1038 }
1039 }
1040 }
1041 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_2P5GA) {
1042 devp->compfullscale = LSM303DLHC_COMP_2P5GA;
1043 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1044 if(devp->config->compsensitivity == NULL) {
1045 if(i != 2) {
1046 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_2P5GA;
1047 }
1048 else {
1049 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_2P5GA;
1050 }
1051 }
1052 else {
1053 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1054 }
1055 }
1056 }
1057 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_4P0GA) {
1058 devp->compfullscale = LSM303DLHC_COMP_4P0GA;
1059 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1060 if(devp->config->compsensitivity == NULL) {
1061 if(i != 2) {
1062 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_4P0GA;
1063 }
1064 else {
1065 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_4P0GA;
1066 }
1067 }
1068 else {
1069 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1070 }
1071 }
1072 }
1073 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_4P7GA) {
1074 devp->compfullscale = LSM303DLHC_COMP_4P7GA;
1075 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1076 if(devp->config->compsensitivity == NULL) {
1077 if(i != 2) {
1078 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_4P7GA;
1079 }
1080 else {
1081 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_4P7GA;
1082 }
1083 }
1084 else {
1085 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1086 }
1087 }
1088 }
1089 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_5P6GA) {
1090 devp->compfullscale = LSM303DLHC_COMP_5P6GA;
1091 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1092 if(devp->config->compsensitivity == NULL) {
1093 if(i != 2) {
1094 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_5P6GA;
1095 }
1096 else {
1097 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_5P6GA;
1098 }
1099 }
1100 else {
1101 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1102 }
1103 }
1104 }
1105 else if(devp->config->compfullscale == LSM303DLHC_COMP_FS_8P1GA) {
1106 devp->compfullscale = LSM303DLHC_COMP_8P1GA;
1107 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) {
1108 if(devp->config->compsensitivity == NULL) {
1109 if(i != 2) {
1110 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_XY_8P1GA;
1111 }
1112 else {
1113 devp->compsensitivity[i] = LSM303DLHC_COMP_SENS_Z_8P1GA;
1114 }
1115 }
1116 else {
1117 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1118 }
1119 }
1120 }
1121 else
1122 osalDbgAssert(FALSE, "lsm303dlhcStart(), compass full scale issue");
1123
1124 /* Storing bias information */
1125 if(devp->config->compbias != NULL)
1126 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
1127 devp->compbias[i] = devp->config->compbias[i];
1128 else
1129 for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
1130 devp->compbias[i] = LSM303DLHC_COMP_BIAS;
1131
1132 /* This is the MEMS transient recovery time */
1134
1135 devp->state = LSM303DLHC_READY;
1136}
1137
1138/**
1139 * @brief Deactivates the LSM303DLHC Complex Driver peripheral.
1140 *
1141 * @param[in] devp pointer to the @p LSM303DLHCDriver object
1142 *
1143 * @api
1144 */
1146 uint8_t cr[2];
1147 osalDbgCheck(devp != NULL);
1148
1149 osalDbgAssert((devp->state == LSM303DLHC_STOP) ||
1150 (devp->state == LSM303DLHC_READY),
1151 "lsm303dlhcStop(), invalid state");
1152
1153 if (devp->state == LSM303DLHC_READY) {
1154#if LSM303DLHC_SHARED_I2C
1155 i2cAcquireBus((devp)->config->i2cp);
1156 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
1157#endif /* LSM303DLHC_SHARED_I2C */
1158
1159 /* Disabling accelerometer. */
1163 cr, 1);
1164
1165 /* Disabling compass. */
1169 cr, 1);
1170
1171 i2cStop((devp)->config->i2cp);
1172#if LSM303DLHC_SHARED_I2C
1173 i2cReleaseBus((devp)->config->i2cp);
1174#endif /* LSM303DLHC_SHARED_I2C */
1175 }
1176 devp->state = LSM303DLHC_STOP;
1177}
1178/** @} */
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 size_t comp_get_axes_number(void *ip)
Return the number of axes of the BaseCompass.
Definition lis3mdl.c:102
static msg_t comp_set_full_scale(LIS3MDLDriver *devp, lis3mdl_comp_fs_t fs)
Changes the LIS3MDLDriver compass fullscale value.
Definition lis3mdl.c:345
static msg_t comp_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseCompass.
Definition lis3mdl.c:271
static msg_t comp_reset_bias(void *ip)
Reset bias values for the BaseCompass.
Definition lis3mdl.c:241
static msg_t comp_set_bias(void *ip, float *bp)
Set bias values for the BaseCompass.
Definition lis3mdl.c:212
static msg_t comp_reset_sensivity(void *ip)
Reset sensitivity values for the BaseCompass.
Definition lis3mdl.c:300
static msg_t comp_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseCompass.
Definition lis3mdl.c:178
static const struct BaseCompassVMT vmt_compass
Definition lis3mdl.c:433
static msg_t comp_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseCompass.
Definition lis3mdl.c:124
#define LSM303DLHC_COMP_SENS_Z_4P0GA
Definition lsm303dlhc.h:115
#define LSM303DLHC_AD_ACC_CTRL_REG1
Definition lsm303dlhc.h:138
static size_t comp_get_axes_number(void *ip)
Return the number of axes of the BaseCompass.
Definition lsm303dlhc.c:440
#define LSM303DLHC_COMP_1P9GA
Definition lsm303dlhc.h:97
void lsm303dlhcStop(LSM303DLHCDriver *devp)
Deactivates the LSM303DLHC Complex Driver peripheral.
#define LSM303DLHC_ACC_8G
Definition lsm303dlhc.h:76
static msg_t comp_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseCompass.
Definition lsm303dlhc.c:609
#define LSM303DLHC_ACC_4G
Definition lsm303dlhc.h:75
#define LSM303DLHC_COMP_2P5GA
Definition lsm303dlhc.h:98
#define LSM303DLHC_COMP_SENS_Z_1P3GA
Definition lsm303dlhc.h:112
static msg_t comp_reset_bias(void *ip)
Reset bias values for the BaseCompass.
Definition lsm303dlhc.c:579
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
Definition lsm303dlhc.c:104
#define LSM303DLHC_COMP_SENS_XY_5P6GA
Definition lsm303dlhc.h:109
lsm303dlhc_comp_fs_t
LSM303DLHC compass subsystem full scale.
Definition lsm303dlhc.h:480
#define LSM303DLHC_AD_ACC_CTRL_REG4
Definition lsm303dlhc.h:141
static msg_t comp_set_full_scale(LSM303DLHCDriver *devp, lsm303dlhc_comp_fs_t fs)
Changes the LSM303DLHCDriver compass fullscale value.
Definition lsm303dlhc.c:734
static msg_t acc_set_full_scale(LSM303DLHCDriver *devp, lsm303dlhc_acc_fs_t fs)
Changes the LSM303DLHCDriver accelerometer fullscale value.
Definition lsm303dlhc.c:347
#define LSM303DLHC_COMP_SENS_Z_8P1GA
Definition lsm303dlhc.h:118
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
Definition lsm303dlhc.c:302
#define LSM303DLHC_CTRL_REG1_A_XEN
Definition lsm303dlhc.h:190
static msg_t comp_set_bias(void *ip, float *bp)
Set bias values for the BaseCompass.
Definition lsm303dlhc.c:550
#define LSM303DLHC_COMP_8P1GA
Definition lsm303dlhc.h:102
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
Definition lsm303dlhc.c:214
#define LSM303DLHC_ACC_SENS_8G
Definition lsm303dlhc.h:81
#define LSM303DLHC_CTRL_REG4_A_FS_MASK
Definition lsm303dlhc.h:236
#define LSM303DLHC_MS
Definition lsm303dlhc.h:131
static msg_t comp_reset_sensivity(void *ip)
Reset sensitivity values for the BaseCompass.
Definition lsm303dlhc.c:638
static msg_t lsm303dlhcI2CWriteRegister(I2CDriver *i2cp, lsm303dlhc_sad_t sad, uint8_t *txbuf, size_t n)
Writes a value into a register using I2C.
Definition lsm303dlhc.c:89
#define LSM303DLHC_AD_COMP_OUT_X_L
Definition lsm303dlhc.h:172
#define LSM303DLHC_AD_COMP_MR_REG
Definition lsm303dlhc.h:170
#define LSM303DLHC_COMP_4P0GA
Definition lsm303dlhc.h:99
#define LSM303DLHC_ACC_BIAS
Definition lsm303dlhc.h:84
void lsm303dlhcStart(LSM303DLHCDriver *devp, const LSM303DLHCConfig *config)
Configures and activates LSM303DLHC Complex Driver peripheral.
Definition lsm303dlhc.c:871
#define LSM303DLHC_COMP_4P7GA
Definition lsm303dlhc.h:100
static msg_t comp_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseCompass.
Definition lsm303dlhc.c:516
#define LSM303DLHC_ACC_NUMBER_OF_AXES
LSM303DLHC accelerometer subsystem characteristics.
Definition lsm303dlhc.h:72
#define LSM303DLHC_ACC_SENS_16G
Definition lsm303dlhc.h:82
static msg_t lsm303dlhcI2CReadRegister(I2CDriver *i2cp, lsm303dlhc_sad_t sad, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
Definition lsm303dlhc.c:69
#define LSM303DLHC_CRB_REG_M_GN_MASK
Definition lsm303dlhc.h:285
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
Definition lsm303dlhc.c:243
lsm303dlhc_acc_fs_t
LSM303DLHC accelerometer subsystem full scale.
Definition lsm303dlhc.h:403
#define LSM303DLHC_ACC_SENS_2G
Definition lsm303dlhc.h:79
#define LSM303DLHC_COMP_SENS_XY_1P9GA
Definition lsm303dlhc.h:105
#define LSM303DLHC_ACC_2G
Definition lsm303dlhc.h:74
#define LSM303DLHC_ACC_16G
Definition lsm303dlhc.h:77
#define LSM303DLHC_COMP_SENS_XY_2P5GA
Definition lsm303dlhc.h:106
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
Definition lsm303dlhc.c:273
#define LSM303DLHC_AD_ACC_OUT_X_L
Definition lsm303dlhc.h:146
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
Definition lsm303dlhc.c:181
#define LSM303DLHC_COMP_SENS_XY_1P3GA
Definition lsm303dlhc.h:104
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
Definition lsm303dlhc.c:126
lsm303dlhc_sad_t
Accelerometer and Compass Slave Address.
Definition lsm303dlhc.c:48
#define LSM303DLHC_COMP_1P3GA
Definition lsm303dlhc.h:96
#define LSM303DLHC_AD_COMP_CRB_REG
Definition lsm303dlhc.h:169
#define LSM303DLHC_COMP_SENS_XY_4P7GA
Definition lsm303dlhc.h:108
void lsm303dlhcObjectInit(LSM303DLHCDriver *devp)
Initializes an instance.
Definition lsm303dlhc.c:850
#define LSM303DLHC_COMP_SENS_Z_1P9GA
Definition lsm303dlhc.h:113
#define LSM303DLHC_COMP_SENS_Z_2P5GA
Definition lsm303dlhc.h:114
#define LSM303DLHC_CTRL_REG1_A_ZEN
Definition lsm303dlhc.h:192
#define LSM303DLHC_COMP_SENS_Z_5P6GA
Definition lsm303dlhc.h:117
#define LSM303DLHC_COMP_5P6GA
Definition lsm303dlhc.h:101
#define LSM303DLHC_CTRL_REG1_A_YEN
Definition lsm303dlhc.h:191
static msg_t comp_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseCompass.
Definition lsm303dlhc.c:462
#define LSM303DLHC_COMP_BIAS
Definition lsm303dlhc.h:120
#define LSM303DLHC_COMP_SENS_XY_4P0GA
Definition lsm303dlhc.h:107
#define LSM303DLHC_COMP_SENS_XY_8P1GA
Definition lsm303dlhc.h:110
#define LSM303DLHC_COMP_NUMBER_OF_AXES
LSM303DLHC compass subsystem characteristics.
Definition lsm303dlhc.h:94
#define LSM303DLHC_AD_COMP_CRA_REG
Definition lsm303dlhc.h:168
#define LSM303DLHC_ACC_SENS_4G
Definition lsm303dlhc.h:80
#define LSM303DLHC_COMP_SENS_Z_4P7GA
Definition lsm303dlhc.h:116
@ LSM303DLHC_COMP_FS_8P1GA
Definition lsm303dlhc.h:487
@ LSM303DLHC_COMP_FS_4P7GA
Definition lsm303dlhc.h:485
@ LSM303DLHC_COMP_FS_1P3GA
Definition lsm303dlhc.h:481
@ LSM303DLHC_COMP_FS_2P5GA
Definition lsm303dlhc.h:483
@ LSM303DLHC_COMP_FS_1P9GA
Definition lsm303dlhc.h:482
@ LSM303DLHC_COMP_FS_4P0GA
Definition lsm303dlhc.h:484
@ LSM303DLHC_COMP_FS_5P6GA
Definition lsm303dlhc.h:486
@ LSM303DLHC_ACC_AE_DISABLED
Definition lsm303dlhc.h:430
@ LSM303DLHC_ACC_FS_16G
Definition lsm303dlhc.h:407
@ LSM303DLHC_ACC_FS_4G
Definition lsm303dlhc.h:405
@ LSM303DLHC_ACC_FS_2G
Definition lsm303dlhc.h:404
@ LSM303DLHC_ACC_FS_8G
Definition lsm303dlhc.h:406
@ LSM303DLHC_SAD_COMP
Definition lsm303dlhc.c:50
@ LSM303DLHC_SAD_ACC
Definition lsm303dlhc.c:49
@ LSM303DLHC_STOP
Definition lsm303dlhc.h:523
@ LSM303DLHC_READY
Definition lsm303dlhc.h:524
@ LSM303DLHC_COMP_MD_SLEEP
Definition lsm303dlhc.h:510
@ LSM303DLHC_ACC_ODR_PD
Definition lsm303dlhc.h:414
#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.
LSM303DLHC MEMS interface module header.
Base accelerometer class.
const struct BaseAccelerometerVMT * vmt
Virtual Methods Table.
BaseAccelerometer virtual methods table.
Base compass class.
Definition ex_compass.h:86
const struct BaseCompassVMT * vmt
Virtual Methods Table.
Definition ex_compass.h:88
BaseCompass virtual methods table.
Definition ex_compass.h:70
LSM303DLHC configuration structure.
Definition lsm303dlhc.h:530
I2CDriver * i2cp
I2C driver associated to this LSM303DLHC.
Definition lsm303dlhc.h:534
LSM303DLHC 6-axis accelerometer/compass class.
Definition lsm303dlhc.h:653
BaseCompass comp_if
Base compass interface.
Definition lsm303dlhc.h:659
const struct LSM303DLHCVMT * vmt
Virtual Methods Table.
Definition lsm303dlhc.h:655
BaseAccelerometer acc_if
Base accelerometer interface.
Definition lsm303dlhc.h:657
LSM303DLHC virtual methods table.
Definition lsm303dlhc.h:620
const I2CConfig * config
Current configuration data.