ChibiOS 21.11.4
lis3mdl.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 lis3mdl.c
23 * @brief LIS3MDL MEMS interface module code.
24 *
25 * @addtogroup LIS3MDL
26 * @ingroup EX_ST
27 * @{
28 */
29
30#include "hal.h"
31#include "lis3mdl.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 (LIS3MDL_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 *
54 * @param[in] i2cp pointer to the I2C interface
55 * @param[in] sad slave address without R bit
56 * @param[in] reg first sub-register address
57 * @param[out] rxbuf pointer to an output buffer
58 * @param[in] n number of consecutive register to read
59 * @return the operation status.
60 * @notapi
61 */
63 uint8_t* rxbuf, size_t n) {
64 uint8_t txbuf = reg;
65 if(n > 1)
66 txbuf |= LIS3MDL_SUB_MS;
67
68 return i2cMasterTransmitTimeout(i2cp, sad, &txbuf, 1, rxbuf, n,
70}
71
72/**
73 * @brief Writes a value into a register using I2C.
74 * @pre The I2C interface must be initialized and the driver started.
75 *
76 * @param[in] i2cp pointer to the I2C interface
77 * @param[in] sad slave address without R bit
78 * @param[in] txbuf buffer containing sub-address value in first position
79 * and values to write
80 * @param[in] n size of txbuf less one (not considering the first
81 * element)
82 * @return the operation status.
83 * @notapi
84 */
86 uint8_t n) {
87 if (n > 1)
88 (*txbuf) |= LIS3MDL_SUB_MS;
89
90 return i2cMasterTransmitTimeout(i2cp, sad, txbuf, n + 1, NULL, 0,
92}
93#endif /* LIS3MDL_USE_I2C */
94
95/**
96 * @brief Return the number of axes of the BaseCompass.
97 *
98 * @param[in] ip pointer to @p BaseCompass interface
99 *
100 * @return the number of axes.
101 */
102static size_t comp_get_axes_number(void *ip) {
103
104 osalDbgCheck(ip != NULL);
106}
107
108/**
109 * @brief Retrieves raw data from the BaseCompass.
110 * @note This data is retrieved from MEMS register without any algebraical
111 * manipulation.
112 * @note The axes array must be at least the same size of the
113 * BaseCompass axes number.
114 *
115 * @param[in] ip pointer to @p BaseCompass interface.
116 * @param[out] axes a buffer which would be filled with raw data.
117 *
118 * @return The operation status.
119 * @retval MSG_OK if the function succeeded.
120 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
121 * be retrieved using @p i2cGetErrors().
122 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
123 */
124static msg_t comp_read_raw(void *ip, int32_t axes[]) {
125 LIS3MDLDriver* devp;
126 uint8_t buff [LIS3MDL_COMP_NUMBER_OF_AXES * 2], i;
127 int16_t tmp;
128 msg_t msg;
129
130 osalDbgCheck((ip != NULL) && (axes != NULL));
131
132 /* Getting parent instance pointer.*/
134
135 osalDbgAssert((devp->state == LIS3MDL_READY),
136 "comp_read_raw(), invalid state");
137 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
138 "comp_read_raw(), channel not ready");
139
140#if LIS3MDL_SHARED_I2C
141 i2cAcquireBus(devp->config->i2cp);
142 i2cStart(devp->config->i2cp,
143 devp->config->i2ccfg);
144#endif /* LIS3MDL_SHARED_I2C */
145 msg = lis3mdlI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
146 LIS3MDL_AD_OUT_X_L, buff,
148
149#if LIS3MDL_SHARED_I2C
150 i2cReleaseBus(devp->config->i2cp);
151#endif /* LIS3MDL_SHARED_I2C */
152
153 if(msg == MSG_OK)
154 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
155 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
156 axes[i] = (int32_t)tmp;
157 }
158 return msg;
159}
160
161/**
162 * @brief Retrieves cooked data from the BaseCompass.
163 * @note This data is manipulated according to the formula
164 * cooked = (raw * sensitivity) - bias.
165 * @note Final data is expressed as G.
166 * @note The axes array must be at least the same size of the
167 * BaseCompass axes number.
168 *
169 * @param[in] ip pointer to @p BaseCompass interface.
170 * @param[out] axes a buffer which would be filled with cooked data.
171 *
172 * @return The operation status.
173 * @retval MSG_OK if the function succeeded.
174 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
175 * be retrieved using @p i2cGetErrors().
176 * @retval MSG_TIMEOUT if a timeout occurred before operation end.
177 */
178static msg_t comp_read_cooked(void *ip, float axes[]) {
179 LIS3MDLDriver* devp;
180 uint32_t i;
181 int32_t raw[LIS3MDL_COMP_NUMBER_OF_AXES];
182 msg_t msg;
183
184 osalDbgCheck((ip != NULL) && (axes != NULL));
185
186
187 /* Getting parent instance pointer.*/
189
190 osalDbgAssert((devp->state == LIS3MDL_READY),
191 "comp_read_cooked(), invalid state");
192
193 msg = comp_read_raw(ip, raw);
194 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES ; i++) {
195 axes[i] = (raw[i] * devp->compsensitivity[i]) - devp->compbias[i];
196 }
197 return msg;
198}
199
200/**
201 * @brief Set bias values for the BaseCompass.
202 * @note Bias must be expressed as G.
203 * @note The bias buffer must be at least the same size of the
204 * BaseCompass axes number.
205 *
206 * @param[in] ip pointer to @p BaseCompass interface.
207 * @param[in] bp a buffer which contains biases.
208 *
209 * @return The operation status.
210 * @retval MSG_OK if the function succeeded.
211 */
212static msg_t comp_set_bias(void *ip, float *bp) {
213 LIS3MDLDriver* devp;
214 uint32_t i;
215 msg_t msg = MSG_OK;
216
217 osalDbgCheck((ip != NULL) && (bp != NULL));
218
219 /* Getting parent instance pointer.*/
221
222 osalDbgAssert((devp->state == LIS3MDL_READY),
223 "comp_set_bias(), invalid state");
224
225 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
226 devp->compbias[i] = bp[i];
227 }
228 return msg;
229}
230
231/**
232 * @brief Reset bias values for the BaseCompass.
233 * @note Default biases value are obtained from device datasheet when
234 * available otherwise they are considered zero.
235 *
236 * @param[in] ip pointer to @p BaseCompass interface.
237 *
238 * @return The operation status.
239 * @retval MSG_OK if the function succeeded.
240 */
241static msg_t comp_reset_bias(void *ip) {
242 LIS3MDLDriver* devp;
243 uint32_t i;
244 msg_t msg = MSG_OK;
245
246 osalDbgCheck(ip != NULL);
247
248 /* Getting parent instance pointer.*/
250
251 osalDbgAssert((devp->state == LIS3MDL_READY),
252 "comp_reset_bias(), invalid state");
253
254 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
255 devp->compbias[i] = LIS3MDL_COMP_BIAS;
256 return msg;
257}
258
259/**
260 * @brief Set sensitivity values for the BaseCompass.
261 * @note Sensitivity must be expressed as G/LSB.
262 * @note The sensitivity buffer must be at least the same size of the
263 * BaseCompass axes number.
264 *
265 * @param[in] ip pointer to @p BaseCompass interface.
266 * @param[in] sp a buffer which contains sensitivities.
267 *
268 * @return The operation status.
269 * @retval MSG_OK if the function succeeded.
270 */
271static msg_t comp_set_sensivity(void *ip, float *sp) {
272 LIS3MDLDriver* devp;
273 uint32_t i;
274 msg_t msg = MSG_OK;
275
276 /* Getting parent instance pointer.*/
278
279 osalDbgCheck((ip != NULL) && (sp != NULL));
280
281 osalDbgAssert((devp->state == LIS3MDL_READY),
282 "comp_set_sensivity(), invalid state");
283
284 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
285 devp->compsensitivity[i] = sp[i];
286 }
287 return msg;
288}
289
290/**
291 * @brief Reset sensitivity values for the BaseCompass.
292 * @note Default sensitivities value are obtained from device datasheet.
293 *
294 * @param[in] ip pointer to @p BaseCompass interface.
295 *
296 * @return The operation status.
297 * @retval MSG_OK if the function succeeded.
298 * @retval MSG_RESET otherwise.
299 */
300static msg_t comp_reset_sensivity(void *ip) {
301 LIS3MDLDriver* devp;
302 uint32_t i;
303 msg_t msg = MSG_OK;
304
305 osalDbgCheck(ip != NULL);
306
307 /* Getting parent instance pointer.*/
309
310 osalDbgAssert((devp->state == LIS3MDL_READY),
311 "comp_reset_sensivity(), invalid state");
312
313 if(devp->config->compfullscale == LIS3MDL_COMP_FS_4GA)
314 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
315 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_4GA;
316 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_8GA)
317 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
318 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_8GA;
319 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_12GA)
320 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
321 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_12GA;
322 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_16GA)
323 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
324 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_16GA;
325 else {
326 osalDbgAssert(FALSE, "comp_reset_sensivity(), compass full scale issue");
327 msg = MSG_RESET;
328 }
329 return msg;
330}
331
332/**
333 * @brief Changes the LIS3MDLDriver compass fullscale value.
334 * @note This function also rescale sensitivities and biases based on
335 * previous and next fullscale value.
336 * @note A recalibration is highly suggested after calling this function.
337 *
338 * @param[in] devp pointer to @p LIS3MDLDriver interface.
339 * @param[in] fs new fullscale value.
340 *
341 * @return The operation status.
342 * @retval MSG_OK if the function succeeded.
343 * @retval MSG_RESET otherwise.
344 */
346 float newfs, scale;
347 uint8_t i, buff[2];
348 msg_t msg;
349
350 osalDbgCheck(devp != NULL);
351
352 osalDbgAssert((devp->state == LIS3MDL_READY),
353 "comp_set_full_scale(), invalid state");
354 osalDbgAssert((devp->config->i2cp->state == I2C_READY),
355 "comp_set_full_scale(), channel not ready");
356
357 /* Computing new fullscale value.*/
358 if(fs == LIS3MDL_COMP_FS_4GA) {
359 newfs = LIS3MDL_COMP_4GA;
360 msg = MSG_OK;
361 }
362 else if(fs == LIS3MDL_COMP_FS_8GA) {
363 newfs = LIS3MDL_COMP_8GA;
364 msg = MSG_OK;
365 }
366 else if(fs == LIS3MDL_COMP_FS_12GA) {
367 newfs = LIS3MDL_COMP_12GA;
368 msg = MSG_OK;
369 }
370 else if(fs == LIS3MDL_COMP_FS_16GA) {
371 newfs = LIS3MDL_COMP_16GA;
372 msg = MSG_OK;
373 }
374 else {
375 msg = MSG_RESET;
376 }
377
378 if((msg == MSG_OK) &&
379 (newfs != devp->compfullscale)) {
380 /* Computing scale value.*/
381 scale = newfs / devp->compfullscale;
382 devp->compfullscale = newfs;
383
384#if LIS3MDL_SHARED_I2C
385 i2cAcquireBus(devp->config->i2cp);
386 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
387#endif /* LIS3MDL_SHARED_I2C */
388
389 /* Updating register.*/
390 msg = lis3mdlI2CReadRegister(devp->config->i2cp, devp->config->slaveaddress,
391 LIS3MDL_AD_CTRL_REG2, &buff[1], 1);
392
393#if LIS3MDL_SHARED_I2C
394 i2cReleaseBus(devp->config->i2cp);
395#endif /* LIS3MDL_SHARED_I2C */
396
397 if(msg == MSG_OK) {
398
399 buff[1] &= ~(LIS3MDL_CTRL_REG2_FS_MASK);
400 buff[1] |= fs;
401 buff[0] = LIS3MDL_AD_CTRL_REG2;
402
403#if LIS3MDL_SHARED_I2C
404 i2cAcquireBus(devp->config->i2cp);
405 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
406#endif /* LIS3MDL_SHARED_I2C */
407
408 msg = lis3mdlI2CWriteRegister(devp->config->i2cp,
409 devp->config->slaveaddress,
410 buff, 1);
411
412#if LIS3MDL_SHARED_I2C
413 i2cReleaseBus(devp->config->i2cp);
414#endif /* LIS3MDL_SHARED_I2C */
415 }
416 if(msg == MSG_OK) {
417
418 /* Scaling sensitivity and bias. Re-calibration is suggested anyway.*/
419 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
420 devp->compsensitivity[i] *= scale;
421 devp->compbias[i] *= scale;
422 }
423 }
424 }
425 return msg;
426}
427
428static const struct LIS3MDLVMT vmt_device = {
429 (size_t)0,
431};
432
438
439/*===========================================================================*/
440/* Driver exported functions. */
441/*===========================================================================*/
442
443/**
444 * @brief Initializes an instance.
445 *
446 * @param[out] devp pointer to the @p LIS3MDLDriver object
447 *
448 * @init
449 */
451 devp->vmt = &vmt_device;
452 devp->comp_if.vmt = &vmt_compass;
453
454 devp->config = NULL;
455
456 devp->compaxes = LIS3MDL_COMP_NUMBER_OF_AXES;
457
458 devp->state = LIS3MDL_STOP;
459}
460
461/**
462 * @brief Configures and activates LIS3MDL Complex Driver peripheral.
463 *
464 * @param[in] devp pointer to the @p LIS3MDLDriver object
465 * @param[in] config pointer to the @p LIS3MDLConfig object
466 *
467 * @api
468 */
469void lis3mdlStart(LIS3MDLDriver *devp, const LIS3MDLConfig *config) {
470 uint32_t i;
471 uint8_t cr[6];
472 osalDbgCheck((devp != NULL) && (config != NULL));
473
474 osalDbgAssert((devp->state == LIS3MDL_STOP) || (devp->state == LIS3MDL_READY),
475 "lis3mdlStart(), invalid state");
476
477 devp->config = config;
478
479 /* Control register 1 configuration block.*/
480 {
481 cr[0] = LIS3MDL_AD_CTRL_REG1;
482 cr[1] = devp->config->compodr;
483#if LIS3MDL_USE_ADVANCED || defined(__DOXYGEN__)
484 cr[1] |= devp->config->compopmodexy;
485#else
487#endif
488 }
489
490 /* Control register 2 configuration block.*/
491 {
492 cr[2] = devp->config->compfullscale;
493 }
494
495 /* Control register 3 configuration block.*/
496 {
497 cr[3] = 0;
498#if LIS3MDL_USE_ADVANCED || defined(__DOXYGEN__)
499 cr[3] = devp->config->compconvmode;
500#endif
501 }
502
503 /* Control register 4 configuration block.*/
504 {
505 cr[4] = 0;
506#if LIS3MDL_USE_ADVANCED || defined(__DOXYGEN__)
507 cr[4] = devp->config->compopmodez | devp->config->endianness;
508#endif
509 }
510
511 /* Control register 5 configuration block.*/
512 {
513 cr[5] = 0;
514#if LIS3MDL_USE_ADVANCED || defined(__DOXYGEN__)
515 cr[5] = devp->config->bdu;
516#endif
517 }
518
519#if LIS3MDL_USE_I2C
520#if LIS3MDL_SHARED_I2C
521 i2cAcquireBus((devp)->config->i2cp);
522#endif /* LIS3MDL_SHARED_I2C */
523 i2cStart((devp)->config->i2cp,
524 (devp)->config->i2ccfg);
525
526 lis3mdlI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
527 cr, 5);
528
529#if LIS3MDL_SHARED_I2C
530 i2cReleaseBus((devp)->config->i2cp);
531#endif /* LIS3MDL_SHARED_I2C */
532#endif /* LIS3MDL_USE_I2C */
533
534 if(devp->config->compfullscale == LIS3MDL_COMP_FS_4GA) {
535 devp->compfullscale = LIS3MDL_COMP_4GA;
536 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
537 if(devp->config->compsensitivity == NULL) {
538 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_4GA;
539 }
540 else {
541 devp->compsensitivity[i] = devp->config->compsensitivity[i];
542 }
543 }
544 }
545 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_8GA) {
546 devp->compfullscale = LIS3MDL_COMP_8GA;
547 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
548 if(devp->config->compsensitivity == NULL) {
549 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_8GA;
550 }
551 else {
552 devp->compsensitivity[i] = devp->config->compsensitivity[i];
553 }
554 }
555 }
556 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_12GA) {
557 devp->compfullscale = LIS3MDL_COMP_12GA;
558 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
559 if(devp->config->compsensitivity == NULL) {
560 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_12GA;
561 }
562 else {
563 devp->compsensitivity[i] = devp->config->compsensitivity[i];
564 }
565 }
566 }
567 else if(devp->config->compfullscale == LIS3MDL_COMP_FS_16GA) {
568 devp->compfullscale = LIS3MDL_COMP_16GA;
569 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++) {
570 if(devp->config->compsensitivity == NULL) {
571 devp->compsensitivity[i] = LIS3MDL_COMP_SENS_16GA;
572 }
573 else {
574 devp->compsensitivity[i] = devp->config->compsensitivity[i];
575 }
576 }
577 }
578 else
579 osalDbgAssert(FALSE, "lis3mdlStart(), compass full scale issue");
580
581 /* Storing bias information */
582 if(devp->config->compbias != NULL)
583 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
584 devp->compbias[i] = devp->config->compbias[i];
585 else
586 for(i = 0; i < LIS3MDL_COMP_NUMBER_OF_AXES; i++)
587 devp->compbias[i] = LIS3MDL_COMP_BIAS;
588
589 /* This is the MEMS transient recovery time */
591
592 devp->state = LIS3MDL_READY;
593}
594
595/**
596 * @brief Deactivates the LIS3MDL Complex Driver peripheral.
597 *
598 * @param[in] devp pointer to the @p LIS3MDLDriver object
599 *
600 * @api
601 */
603 uint8_t cr[2];
604 osalDbgCheck(devp != NULL);
605
606 osalDbgAssert((devp->state == LIS3MDL_STOP) || (devp->state == LIS3MDL_READY),
607 "lis3mdlStop(), invalid state");
608
609 if (devp->state == LIS3MDL_READY) {
610#if (LIS3MDL_USE_I2C)
611#if LIS3MDL_SHARED_I2C
612 i2cAcquireBus((devp)->config->i2cp);
613 i2cStart((devp)->config->i2cp,
614 (devp)->config->i2ccfg);
615#endif /* LIS3MDL_SHARED_I2C */
616
617 /* Disabling compass. */
618 cr[0] = LIS3MDL_AD_CTRL_REG3;
620 lis3mdlI2CWriteRegister(devp->config->i2cp, devp->config->slaveaddress,
621 cr, 1);
622
623 i2cStop((devp)->config->i2cp);
624#if LIS3MDL_SHARED_I2C
625 i2cReleaseBus((devp)->config->i2cp);
626#endif /* LIS3MDL_SHARED_I2C */
627#endif /* LIS3MDL_USE_I2C */
628 }
629 devp->state = LIS3MDL_STOP;
630}
631/** @} */
static const struct ADXL317VMT vmt_device
Definition adxl317.c:328
#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
void lis3mdlStart(LIS3MDLDriver *devp, const LIS3MDLConfig *config)
Configures and activates LIS3MDL Complex Driver peripheral.
Definition lis3mdl.c:469
msg_t lis3mdlI2CWriteRegister(I2CDriver *i2cp, lis3mdl_sad_t sad, uint8_t *txbuf, uint8_t n)
Writes a value into a register using I2C.
Definition lis3mdl.c:85
#define LIS3MDL_COMP_SENS_4GA
Definition lis3mdl.h:77
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
#define LIS3MDL_CTRL_REG3_MD1
Definition lis3mdl.h:157
static msg_t comp_reset_bias(void *ip)
Reset bias values for the BaseCompass.
Definition lis3mdl.c:241
#define LIS3MDL_COMP_SENS_12GA
Definition lis3mdl.h:79
#define LIS3MDL_CTRL_REG1_OM1
Definition lis3mdl.h:135
static msg_t comp_set_bias(void *ip, float *bp)
Set bias values for the BaseCompass.
Definition lis3mdl.c:212
#define LIS3MDL_COMP_16GA
Definition lis3mdl.h:75
static msg_t comp_reset_sensivity(void *ip)
Reset sensitivity values for the BaseCompass.
Definition lis3mdl.c:300
#define LIS3MDL_AD_OUT_X_L
Definition lis3mdl.h:110
static msg_t comp_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseCompass.
Definition lis3mdl.c:178
#define LIS3MDL_COMP_SENS_16GA
Definition lis3mdl.h:80
void lis3mdlObjectInit(LIS3MDLDriver *devp)
Initializes an instance.
Definition lis3mdl.c:450
#define LIS3MDL_CTRL_REG2_FS_MASK
Definition lis3mdl.h:146
void lis3mdlStop(LIS3MDLDriver *devp)
Deactivates the LIS3MDL Complex Driver peripheral.
Definition lis3mdl.c:602
#define LIS3MDL_AD_CTRL_REG2
Definition lis3mdl.h:105
#define LIS3MDL_COMP_4GA
Definition lis3mdl.h:72
#define LIS3MDL_AD_CTRL_REG3
Definition lis3mdl.h:106
lis3mdl_comp_fs_t
LIS3MDL full scale.
Definition lis3mdl.h:296
msg_t lis3mdlI2CReadRegister(I2CDriver *i2cp, lis3mdl_sad_t sad, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
Definition lis3mdl.c:62
#define LIS3MDL_CTRL_REG1_OM0
Definition lis3mdl.h:134
#define LIS3MDL_AD_CTRL_REG1
Definition lis3mdl.h:104
#define LIS3MDL_COMP_12GA
Definition lis3mdl.h:74
lis3mdl_sad_t
LIS3MDL slave address.
Definition lis3mdl.h:288
#define LIS3MDL_COMP_8GA
Definition lis3mdl.h:73
#define LIS3MDL_CTRL_REG3_MD0
Definition lis3mdl.h:156
static const struct BaseCompassVMT vmt_compass
Definition lis3mdl.c:433
#define LIS3MDL_COMP_BIAS
Definition lis3mdl.h:82
#define LIS3MDL_SUB_MS
Definition lis3mdl.h:96
#define LIS3MDL_COMP_NUMBER_OF_AXES
LIS3MDL compass subsystem characteristics.
Definition lis3mdl.h:70
static msg_t comp_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseCompass.
Definition lis3mdl.c:124
#define LIS3MDL_COMP_SENS_8GA
Definition lis3mdl.h:78
@ LIS3MDL_COMP_FS_4GA
Definition lis3mdl.h:297
@ LIS3MDL_COMP_FS_8GA
Definition lis3mdl.h:298
@ LIS3MDL_COMP_FS_16GA
Definition lis3mdl.h:300
@ LIS3MDL_COMP_FS_12GA
Definition lis3mdl.h:299
@ LIS3MDL_STOP
Definition lis3mdl.h:383
@ LIS3MDL_READY
Definition lis3mdl.h:384
#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.
LIS3MDL MEMS interface module header.
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
LIS3MDL configuration structure.
Definition lis3mdl.h:390
I2CDriver * i2cp
I2C driver associated to this LIS3MDL.
Definition lis3mdl.h:405
LIS3MDL 3-axis compass class.
Definition lis3mdl.h:503
const struct LIS3MDLVMT * vmt
Virtual Methods Table.
Definition lis3mdl.h:505
BaseCompass comp_if
Base compass interface.
Definition lis3mdl.h:507
LIS3MDL virtual methods table.
Definition lis3mdl.h:478
const I2CConfig * config
Current configuration data.