ChibiOS/EX 1.3.0
bmp085.c
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2016..2017 Theodore Ateba
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 bmp085.c
23 * @brief BMP085 Digital pressure sensor interface module code.
24 *
25 * @addtogroup BMP085
26 * @ingroup EX_BOSCH
27 * @{
28 */
29
30#include "hal.h"
31#include "bmp085.h"
32
33/*==========================================================================*/
34/* Driver local definitions. */
35/*==========================================================================*/
36
37#define BMP085_SAD 0x77
38
39#define BMP085_CR_P_VAL0 0x34
40#define BMP085_CR_P_VAL1 0x74
41#define BMP085_CR_P_VAL2 0xB4
42#define BMP085_CR_P_VAL3 0xF4
43
44#define BMP085_CR_T_VAL 0x2E
45
46/*==========================================================================*/
47/* Driver exported variables. */
48/*==========================================================================*/
49
50/*==========================================================================*/
51/* Driver local variables and types. */
52/*==========================================================================*/
53
54/*==========================================================================*/
55/* Driver local functions. */
56/*==========================================================================*/
57
58#if (BMP085_USE_I2C) || defined(__DOXYGEN__)
59/**
60 * @brief Reads registers value using I2C.
61 * @pre The I2C interface must be initialized and the driver started.
62 *
63 * @param[in] i2cp pointer to the I2C interface
64 * @param[in] reg first sub-register address
65 * @param[out] rxbufp pointer to an output buffer
66 * @param[in] n number of consecutive register to read
67 *
68 * @return the operation status
69 * @notapi
70 */
71msg_t bmp085I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t *rxbufp,
72 size_t n) {
73 uint8_t txbuf = reg;
74
75 return i2cMasterTransmitTimeout(i2cp, BMP085_SAD, &txbuf, 1, rxbufp, n,
76 TIME_INFINITE);
77}
78
79/**
80 * @brief Writes a value into a register using I2C.
81 * @pre The I2C interface must be initialized and the driver started.
82 *
83 * @param[in] i2cp pointer to the I2C interface
84 * @param[in] txbufp buffer containing sub-address value in first position
85 * and values to write
86 * @param[in] n size of txbuf less one (not considering the first
87 * element)
88 *
89 * @return the operation status
90 * @notapi
91 */
92msg_t bmp085I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbufp, size_t n) {
93
94 return i2cMasterTransmitTimeout(i2cp, BMP085_SAD, txbufp, n + 1, NULL, 0,
95 TIME_INFINITE);
96}
97#endif /* BMP085_USE_I2C */
98
99/**
100 * @brief Read all the calibration data from the BMP085 EEPROM.
101 * @pre The I2C interface must be initialized and the driver started.
102 *
103 * @param[in] devp pointer to the BMP085 device driver sensor
104 * @param[in] reg first calibration coefficient register to read
105 *
106 * @return msg the operation status
107 */
108static msg_t bmp085ReadCoefficient(BMP085Driver *devp, uint8_t reg) {
109
110 uint8_t rxbuf[22];
111
112#if BMP085_SHARED_I2C
113 i2cAcquireBus(devp->config->i2cp);
114#endif /* BMP085_SHARED_I2C */
115
116 msg_t msg = bmp085I2CReadRegister(devp->config->i2cp, reg, rxbuf, 22);
117
118#if BMP085_SHARED_I2C
119 i2cReleaseBus(devp->config->i2cp);
120#endif /* BMP085_SHARED_I2C */
121
122 if (msg == MSG_OK) {
123 devp->calibrationdata.ac1 = ((rxbuf[ 0] << 8) | rxbuf[ 1]);
124 devp->calibrationdata.ac2 = ((rxbuf[ 2] << 8) | rxbuf[ 3]);
125 devp->calibrationdata.ac3 = ((rxbuf[ 4] << 8) | rxbuf[ 5]);
126 devp->calibrationdata.ac4 = ((rxbuf[ 6] << 8) | rxbuf[ 7]);
127 devp->calibrationdata.ac5 = ((rxbuf[ 8] << 8) | rxbuf[ 9]);
128 devp->calibrationdata.ac6 = ((rxbuf[10] << 8) | rxbuf[11]);
129 devp->calibrationdata.b1 = ((rxbuf[12] << 8) | rxbuf[13]);
130 devp->calibrationdata.b2 = ((rxbuf[14] << 8) | rxbuf[15]);
131 devp->calibrationdata.mb = ((rxbuf[16] << 8) | rxbuf[17]);
132 devp->calibrationdata.mc = ((rxbuf[18] << 8) | rxbuf[19]);
133 devp->calibrationdata.md = ((rxbuf[20] << 8) | rxbuf[21]);
134 }
135
136 return msg;
137}
138
139/**
140 * @brief Calcul the true temperature.
141 *
142 * @param[in] devp pointer to the BMP085 device driver sensor
143 * @param[in] ut uncompensated temperature
144 * @param[out] ctp pointer of the compensated temperature
145 */
146static void calcul_t(BMP085Driver *devp, int32_t ut, float *ctp) {
147
148 int32_t x1, x2;
149
150 /* Converting the temperature value. */
151 x1 = ((ut - devp->calibrationdata.ac6) * devp->calibrationdata.ac5) >> 15;
152 x2 = (devp->calibrationdata.mc << 11) / (x1 + devp->calibrationdata.md);
153 devp->calibrationdata.b5 = x1 + x2;
154 *ctp = (float)((devp->calibrationdata.b5 + 8) >> 4)*BMP085_T_RES;
155}
156
157/**
158 * @brief Calcul the true pressure.
159 *
160 * @param[in] devp pointer to the BMP085 device driver sensor
161 * @param[in] up uncompensated pressure
162 * @param[in] oss over sampling setting
163 * @param[out] cpp pointer of the compensated pressure
164 */
165static void calcul_p(BMP085Driver *devp, int32_t up, uint8_t oss, float *cpp) {
166
167 int32_t press;
168 int32_t x1,x2,x3;
169 int32_t b3,b6;
170 uint32_t b4,b7;
171
172 /* Converting the pressure value. */
173 b6 = devp->calibrationdata.b5 - 4000;
174 x1 = (devp->calibrationdata.b2 * ((b6 * b6) >> 12)) >> 11;
175 x2 = (devp->calibrationdata.ac2 * b6) >> 11;
176 x3 = x1 + x2;
177 b3 = ((((int32_t)devp->calibrationdata.ac1 * 4 + x3) << oss) + 2) >> 2;
178 x1 = ((devp->calibrationdata.ac3)*b6) >> 13;
179 x2 = (devp->calibrationdata.b1 * (b6*b6 >> 12)) >> 16;
180 x3 = ((x1 + x2) + 2) >> 2;
181 b4 = devp->calibrationdata.ac4 * (uint32_t)(x3 + 32768) >> 15;
182 b7 = ((uint32_t)up - b3)*(50000 >> oss);
183
184 if (b7 < 0x80000000)
185 press = (b7*2)/b4;
186 else
187 press = (b7/b4)*2;
188
189 x1 = (press >> 8)*(press >> 8);
190 x1 = (x1*3038) >> 16;
191 x2 = (-7357*press) >> 16;
192 *cpp =(float)((press + ((x1 + x2 + 3791) >> 4))*BMP085_P_RES);
193}
194
195/**
196 * @brief Start temperature measurement.
197 *
198 * @param[in] devp pointer to the BMP085 device driver
199 *
200 * @return the operation status
201 */
203
204 uint8_t txbuf[2] = {BMP085_AD_CR, BMP085_CR_T_VAL};
205
206 i2cAcquireBus(devp->config->i2cp);
207 msg_t msg = bmp085I2CWriteRegister(devp->config->i2cp, txbuf, 2);
208 i2cReleaseBus(devp->config->i2cp);
209
210 /* Conversion time for the temperature. */
211 chThdSleepMilliseconds(BMP085_THERMO_CT_LOW);
212 //chThdSleepMilliseconds(devp->config.tct); // TODO: use this instead of the top line:
213
214 return msg;
215}
216
217/**
218 * @brief Start the pressure measurment.
219 *
220 * @param[in] devp pointer to the BMP085 driver
221 * @return msg the operation status
222 */
224
225 uint8_t oss, delay;
226 uint8_t txbuf[2];
227
228 oss = devp->config->oss;
229 txbuf[0] = BMP085_AD_CR;
230
231 /* Check the oss according the bmp085 mode. */
232 if (oss == BMP085_BARO_OSS_0) {
233 txbuf[1] = BMP085_CR_P_VAL0 + (oss << 6);
234 delay = BMP085_BARO_CT_LOW;
235 }
236 else if (oss == BMP085_BARO_OSS_1) {
237 txbuf[1] = BMP085_CR_P_VAL1 + (oss << 6);
238 delay = BMP085_BARO_CT_STD;
239 }
240 else if (oss == BMP085_BARO_OSS_2) {
241 txbuf[1] = BMP085_CR_P_VAL2 + (oss << 6);
242 delay = BMP085_BARO_CT_HR;
243 }
244 else {
245 txbuf[1] = BMP085_CR_P_VAL3 + (oss << 6);
246 delay = BMP085_BARO_CT_LUHR;
247 }
248
249 /* Start the sensor for sampling. */
250#if BMP085_SHARED_I2C
251 i2cAcquireBus(devp->config->i2cp);
252#endif /* BMP085_SHARED_I2C */
253
254 msg_t msg = bmp085I2CWriteRegister(devp->config->i2cp, txbuf, 2);
255
256#if BMP085_SHARED_I2C
257 i2cReleaseBus(devp->config->i2cp);
258#endif /* BMP085_SHARED_I2C */
259
260 /* Conversion time for the pressure, max time for the moment. */
261 chThdSleepMilliseconds(delay);
262
263 return msg;
264}
265
266/**
267 * @brief Read the uncompensated temperature from the BMP085 register.
268 *
269 * @param[in] devp pointer to the BMP085 driver
270 * @param[out] utemp uncompensated temperature read from the sensor register
271 *
272 * @return msg the operation status
273 */
274static msg_t acquire_ut(BMP085Driver *devp, int32_t *utemp) {
275
276 uint8_t rxbuf[2];
277 msg_t msg;
278
279 /* Start the temperature measurement. */
281
282 /* Start the sensor for sampling. */
283#if BMP085_SHARED_I2C
284 i2cAcquireBus(devp->config->i2cp);
285#endif /* BMP085_SHARED_I2C */
286
287 /* Get the temperature. */
288 msg = bmp085I2CReadRegister(devp->config->i2cp, BMP085_AD_T_DR_MSB, rxbuf,
289 2);
290
291#if BMP085_SHARED_I2C
292 i2cReleaseBus(devp->config->i2cp);
293#endif /* BMP085_SHARED_I2C */
294
295 if(msg == MSG_OK){
296 /* Building the uncompensated temperature value. */
297 *utemp = (int32_t)((rxbuf[0] << 8) | rxbuf[1]);
298 }
299
300 return msg;
301}
302
303/**
304 * @brief Read the uncompensated pressure from the BMP085 register.
305 *
306 * @param[in] devp pointer to the BMP085 driver
307 * @param[out] upress uncompensated pressure read from the sensor register
308 *
309 * @return msg the operation status
310 */
311static msg_t acquire_up(BMP085Driver *devp, int32_t *upress) {
312
313 uint8_t rxbuf[3];
314 uint8_t oss;
315 msg_t msg;
316
317 /* Get the oversampling setting from the driver configuratioin. */
318 oss = devp->config->oss;
319
320 /* Start the pressure measurement. */
322
323 /* Start the sensor for sampling. */
324#if BMP085_SHARED_I2C
325 i2cAcquireBus(devp->config->i2cp);
326#endif /* BMP085_SHARED_I2C */
327
328 /* Get the pressure */
329 msg = bmp085I2CReadRegister(devp->config->i2cp, BMP085_AD_P_DR_MSB, rxbuf,
330 3);
331
332#if BMP085_SHARED_I2C
333 i2cReleaseBus(devp->config->i2cp);
334#endif /* BMP085_SHARED_I2C */
335
336 if (msg == MSG_OK) {
337 /* Building the uncompensated pressure value. */
338 *upress = (int32_t)((rxbuf[0] << 16)|(rxbuf[1] << 8)|rxbuf[2]);
339 *upress = *upress >> (8-oss);
340 }
341
342 return msg;
343}
344
345/*==========================================================================*/
346/* Interface implementation. */
347/*==========================================================================*/
348
349/**
350 * @brief Get the barometer number of axes.
351 *
352 * @param[in] ip interface pointer of the BMP085 sensor
353 *
354 * @return barometer number of axes
355 */
356static size_t baro_get_axes_number(void *ip) {
357
358 osalDbgCheck(ip != NULL);
359
361}
362
363/**
364 * @brief Get the thermometer number of axes.
365 *
366 * @param[in] ip interface pointer of the BMP085 sensor
367 *
368 * @return thermometer number of axes
369 */
370static size_t thermo_get_axes_number(void *ip) {
371
372 osalDbgCheck(ip != NULL);
373
375}
376
377/**
378 * @brief Get the sensor number of axes.
379 *
380 * @param[in] ip interface pointer of the BMP085 sensor
381 *
382 * @return sensor number of axes
383 */
384static size_t sens_get_axes_number(void *ip) {
385
386 osalDbgCheck(ip != NULL);
387
389}
390
391/**
392 * @brief Read baromether raw data.
393 *
394 * @param[in] ip interface pointer of the sensor
395 * @param[in] axes buffer for various axes data
396 *
397 * @return msg the result of the reading operation
398 */
399static msg_t baro_read_raw(void *ip, int32_t axes[]) {
400
401 osalDbgCheck((ip != NULL) && (axes != NULL));
402 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
403 "baro_read_raw(), invalid state");
404
405#if BMP085_USE_I2C
406 osalDbgAssert((((BMP085Driver *)ip)->config->i2cp->state == I2C_READY),
407 "baro_read_raw(), channel not ready");
408#if BMP085_SHARED_I2C
409 i2cAcquireBus(((BMP085Driver *)ip)->config->i2cp);
410 i2cStart(((BMP085Driver *)ip)->config->i2cp,
411 ((BMP085Driver *)ip)->config->i2ccfg);
412#endif /* BMP085_SHARED_I2C. */
413
414 /* Measure the uncompensated pressure. */
415 msg_t msg = acquire_up(((BMP085Driver *)ip), axes);
416
417#if BMP085_SHARED_I2C
418 i2cReleaseBus(((BMP085Driver *)ip)->config->i2cp);
419#endif /* BMP085_SHARED_I2C. */
420#endif /* BMP085_USE_I2C. */
421
422 return msg;
423}
424
425/**
426 * @brief Read thermometer raw data.
427 *
428 * @param[in] ip interface pointer of the BMP085 sensor
429 * @param[in] axes buffer for various axes data
430 *
431 * @return msg the result of the reading operation
432 */
433static msg_t thermo_read_raw(void *ip, int32_t axes[]) {
434
435 osalDbgCheck((ip != NULL) && (axes != NULL));
436 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
437 "thermo_read_raw(), invalid state");
438
439#if BMP085_USE_I2C
440 osalDbgAssert((((BMP085Driver *)ip)->config->i2cp->state == I2C_READY),
441 "thermo_read_raw(), channel not ready");
442#if BMP085_SHARED_I2C
443 i2cAcquireBus(((BMP085Driver *)ip)->config->i2cp);
444 i2cStart(((BMP085Driver *)ip)->config->i2cp,
445 ((BMP085Driver *)ip)->config->i2ccfg);
446#endif /* BMP085_SHARED_I2C. */
447
448 /* Measure the uncompensated temperature. */
449 msg_t msg = acquire_ut(((BMP085Driver *)ip), axes);
450
451#if BMP085_SHARED_I2C
452 i2cReleaseBus(((LSM303DLHCDriver *)ip)->config->i2cp);
453#endif /* BMP085_SHARED_I2C. */
454#endif /* BMP085_USE_I2C. */
455
456 return msg;
457}
458
459/**
460 * @brief Read BMP085 sensor raw data.
461 *
462 * @param[in] ip interface pointer of the BMP085 sensor
463 * @param[in] axes buffer for various axes data
464 *
465 * @return msg the result of the reading operation
466 */
467static msg_t sens_read_raw(void *ip, int32_t axes[]) {
468
469 int32_t* bp = axes;
470 msg_t msg;
471
472 msg = baro_read_raw(ip, bp);
473
474 if (msg != MSG_OK)
475 return msg;
476
478
479 msg = thermo_read_raw(ip, bp);
480
481 return msg;
482}
483
484/**
485 * @brief Read barometer cooked data.
486 *
487 * @param[in] ip interface pointer of the BMP085 sensor
488 * @param[in] axes buffer for various axes data
489 *
490 * @return msg the result of the reading operation
491 */
492static msg_t baro_read_cooked(void *ip, float axes[]) {
493
494 uint32_t i;
495 int32_t raw[BMP085_BARO_NUMBER_OF_AXES];
496 msg_t msg;
497 uint8_t oss;
498
499 osalDbgCheck((ip != NULL) && (axes != NULL));
500 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
501 "baro_read_cooked(), invalid state");
502
503 msg = baro_read_raw(ip, raw);
504 oss = ((BMP085Driver *)ip)->config->oss;
505
506 for (i = 0; i < BMP085_BARO_NUMBER_OF_AXES; i++)
507 calcul_p(ip, raw[i], oss, &axes[i]);
508
509 return msg;
510}
511
512/**
513 * @brief Read thermometer cooked data.
514 *
515 * @param[in] ip interface pointer of the BMP085 sensor
516 * @param[in] axes buffer for various axes data
517 *
518 * @return msg the result of the reading operation
519 */
520static msg_t thermo_read_cooked(void *ip, float axes[]) {
521
522 uint32_t i;
523 int32_t raw[BMP085_THERMO_NUMBER_OF_AXES];
524 msg_t msg;
525
526 osalDbgCheck(((ip != NULL) && (axes != NULL)));
527 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
528 "thermo_read_cooked(), invalid state");
529 msg = thermo_read_raw(ip, raw);
530
531 for (i = 0; i < BMP085_THERMO_NUMBER_OF_AXES; i++)
532 calcul_t(ip, raw[i], &axes[i]);
533
534 return msg;
535}
536
537/**
538 * @brief Read BMP085 sensor cooked data.
539 *
540 * @param[in] ip interface pointer of the BMP085 sensor
541 * @param[in] axes buffer for various axes data
542 *
543 * @return msg the result of the reading operation
544 */
545static msg_t sens_read_cooked(void *ip, float axes[]) {
546
547 float* bp = axes;
548 msg_t msg;
549
550 msg = baro_read_cooked(ip, bp);
551
552 if (msg != MSG_OK)
553 return msg;
554
556 msg = thermo_read_cooked(ip, bp);
557
558 return msg;
559}
560
561/**
562 * @brief Set the barometer bias.
563 *
564 * @param[in] ip interface pointer of the BMP085 sensor
565 * @param[in] bp pointer to the bias value
566 *
567 * @return msg the result of the setting operation
568 */
569static msg_t baro_set_bias(void *ip, float *bp) {
570
571 osalDbgCheck((ip != NULL) && (bp !=NULL));
572 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY) ||
573 (((BMP085Driver *)ip)->state == BMP085_STOP),
574 "baro_set_bias(), invalid state");
575 return MSG_OK;
576}
577
578/**
579 * @brief Set the thermometer bias.
580 *
581 * @param[in] ip interface pointer of the BMP085 sensor
582 * @param[in] bp pointer to the bias value
583 *
584 * @return msg the result of the setting operation
585 */
586static msg_t thermo_set_bias(void *ip, float *bp) {
587
588 osalDbgCheck((ip != NULL) && (bp !=NULL));
589 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY) ||
590 (((BMP085Driver *)ip)->state == BMP085_STOP),
591 "thermo_set_bias(), invalid state");
592 return MSG_OK;
593}
594
595/**
596 * @brief Reset the barometer bias.
597 *
598 * @param[in] ip interface pointer of the BMP085 sensor
599 *
600 * @return msg the result of the reset operation
601 */
602static msg_t baro_reset_bias(void *ip) {
603
604 osalDbgCheck(ip != NULL);
605 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY) ||
606 (((BMP085Driver *)ip)->state == BMP085_STOP),
607 "baro_reset_bias(), invalid state");
608
609 return MSG_OK;
610}
611
612/**
613 * @brief Reset the thermometer bias.
614 *
615 * @param[in] ip interface pointer of the BMP085 sensor
616 *
617 * @return msg the result of the reset operation
618 */
619static msg_t thermo_reset_bias(void *ip) {
620
621 osalDbgCheck(ip != NULL);
622 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY) ||
623 (((BMP085Driver *)ip)->state == BMP085_STOP),
624 "thermo_reset_bias(), invalid state");
625
626 return MSG_OK;
627}
628
629/**
630 * @brief Set the barometer sensivity.
631 *
632 * @param[in] ip interface pointer of the BMP085 sensor
633 * @param[in] sp pointer to the sensivity value
634 *
635 * @return msg the result of the setting operation
636 */
637static msg_t baro_set_sensivity(void *ip, float *sp) {
638
639 osalDbgCheck((ip != NULL) && (sp !=NULL));
640 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
641 "baro_set_sensivity(), invalid state");
642
643 return MSG_OK;
644}
645
646/**
647 * @brief Set the thermometer sensivity.
648 *
649 * @param[in] ip interface pointer of the BMP085 sensor
650 * @param[in] sp pointer to the sensivity value
651 *
652 * @return msg the result of the setting operation
653 */
654static msg_t thermo_set_sensivity(void *ip, float *sp) {
655
656 osalDbgCheck((ip != NULL) && (sp !=NULL));
657 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
658 "thermo_set_sensivity(), invalid state");
659
660 return MSG_OK;
661}
662
663/**
664 * @brief Reset the barometer sensivity.
665 *
666 * @param[in] ip interface pointer of the BMP085 sensor
667 *
668 * @return msg the result of the reset operation
669 */
670static msg_t baro_reset_sensivity(void *ip) {
671
672 osalDbgCheck(ip != NULL);
673 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
674 "baro_reset_sensivity(), invalid state");
675
676 return MSG_OK;
677}
678
679/**
680 * @brief Reset the thermometer sensivity.
681 *
682 * @param[in] ip interface pointer of the BMP085 sensor
683 *
684 * @return msg the result of the reset operation
685 */
686static msg_t thermo_reset_sensivity(void *ip) {
687
688 osalDbgCheck(ip != NULL);
689 osalDbgAssert((((BMP085Driver *)ip)->state == BMP085_READY),
690 "thermo_reset_sensivity(), invalid state");
691
692 return MSG_OK;
693}
694
698
704
710
711/*==========================================================================*/
712/* Driver exported functions. */
713/*==========================================================================*/
714
715/**
716 * @brief Initializes an instance.
717 *
718 * @param[out] devp pointer to the @p BMP085Driver object
719 *
720 * @init
721 */
723
727 devp->config = NULL;
728 devp->state = BMP085_STOP;
729}
730
731/**
732 * @brief Configures and activates BMP085 Complex Driver peripheral.
733 *
734 * @param[in] devp pointer to the @p BMP085Driver object
735 * @param[in] config pointer to the @p BMP085Config object
736 *
737 * @api
738 */
739void bmp085Start(BMP085Driver *devp, const BMP085Config *config) {
740
741 osalDbgCheck((devp != NULL) && (config != NULL));
742 osalDbgAssert((devp->state == BMP085_STOP) ||
743 (devp->state == BMP085_READY),
744 "bmp085cStart(), invalid state");
745 devp->config = config;
746#if BMP085_USE_I2C
747#if BMP085_SHARED_I2C
748 i2cAcquireBus((devp)->config->i2cp);
749#endif /* BMP085_SHARED_I2C. */
750 /* Read the Calibrations data. */
751 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
753#if BMP085_SHARED_I2C
754 i2cReleaseBus((devp)->config->i2cp);
755#endif /* BMP085_SHARED_I2C. */
756#endif /* BMP085_USE_I2C. */
757 if(devp->state != BMP085_READY)
758 devp->state = BMP085_READY;
759}
760
761/**
762 * @brief Deactivates the BMP085 Complex Driver peripheral.
763 *
764 * @param[in] devp pointer to the @p BMP085Driver object
765 *
766 * @api
767 */
769
770 osalDbgCheck(devp != NULL);
771 osalDbgAssert((devp->state == BMP085_STOP) ||
772 (devp->state == BMP085_READY),
773 "bmp085Stop(), invalid state");
774#if (BMP085_USE_I2C)
775 if (devp->state == BMP085_STOP) {
776#if BMP085_SHARED_I2C
777 i2cAcquireBus((devp)->config->i2cp);
778 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
779#endif /* BMP085_SHARED_I2C. */
780#if BMP085_SHARED_I2C
781 i2cReleaseBus((devp)->config->i2cp);
782#endif /* BMP085_SHARED_I2C. */
783 }
784#endif /* BMP085_USE_I2C. */
785 if (devp->state != BMP085_STOP)
786 devp->state = BMP085_STOP;
787}
788/** @} */
BMP085 Digital pressure sensor interface module header.
static const struct BaseThermometerVMT vmt_basethermometer
Definition bmp085.c:705
#define BMP085_CR_P_VAL2
Definition bmp085.c:41
static msg_t baro_read_raw(void *ip, int32_t axes[])
Read baromether raw data.
Definition bmp085.c:399
msg_t bmp085I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbufp, size_t n)
Writes a value into a register using I2C.
Definition bmp085.c:92
#define BMP085_BARO_NUMBER_OF_AXES
BMP085 barometer subsystem characteristics.
Definition bmp085.h:70
static const struct BaseBarometerVMT vmt_basebarometer
Definition bmp085.c:699
#define BMP085_CR_T_VAL
Definition bmp085.c:44
static msg_t thermo_set_sensivity(void *ip, float *sp)
Set the thermometer sensivity.
Definition bmp085.c:654
static msg_t baro_reset_bias(void *ip)
Reset the barometer bias.
Definition bmp085.c:602
static msg_t thermo_set_bias(void *ip, float *bp)
Set the thermometer bias.
Definition bmp085.c:586
void bmp085ObjectInit(BMP085Driver *devp)
Initializes an instance.
Definition bmp085.c:722
static msg_t thermo_read_raw(void *ip, int32_t axes[])
Read thermometer raw data.
Definition bmp085.c:433
static msg_t thermo_reset_sensivity(void *ip)
Reset the thermometer sensivity.
Definition bmp085.c:686
static msg_t start_p_measurement(BMP085Driver *devp)
Start the pressure measurment.
Definition bmp085.c:223
#define BMP085_CR_P_VAL1
Definition bmp085.c:40
static void calcul_t(BMP085Driver *devp, int32_t ut, float *ctp)
Calcul the true temperature.
Definition bmp085.c:146
#define BMP085_AD_T_DR_MSB
Definition bmp085.h:89
static void calcul_p(BMP085Driver *devp, int32_t up, uint8_t oss, float *cpp)
Calcul the true pressure.
Definition bmp085.c:165
static msg_t baro_reset_sensivity(void *ip)
Reset the barometer sensivity.
Definition bmp085.c:670
static msg_t acquire_up(BMP085Driver *devp, int32_t *upress)
Read the uncompensated pressure from the BMP085 register.
Definition bmp085.c:311
static msg_t sens_read_cooked(void *ip, float axes[])
Read BMP085 sensor cooked data.
Definition bmp085.c:545
static msg_t baro_set_sensivity(void *ip, float *sp)
Set the barometer sensivity.
Definition bmp085.c:637
static size_t baro_get_axes_number(void *ip)
Get the barometer number of axes.
Definition bmp085.c:356
static msg_t baro_set_bias(void *ip, float *bp)
Set the barometer bias.
Definition bmp085.c:569
msg_t bmp085I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t *rxbufp, size_t n)
Reads registers value using I2C.
Definition bmp085.c:71
#define BMP085_CR_P_VAL0
Definition bmp085.c:39
static size_t thermo_get_axes_number(void *ip)
Get the thermometer number of axes.
Definition bmp085.c:370
static const struct BaseSensorVMT vmt_basesensor
Definition bmp085.c:695
#define BMP085_AD_CC_AC1_MSB
Definition bmp085.h:94
#define BMP085_SAD
Definition bmp085.c:37
static msg_t start_t_measurement(BMP085Driver *devp)
Start temperature measurement.
Definition bmp085.c:202
#define BMP085_AD_P_DR_MSB
Definition bmp085.h:91
#define BMP085_P_RES
Definition bmp085.h:72
static msg_t thermo_read_cooked(void *ip, float axes[])
Read thermometer cooked data.
Definition bmp085.c:520
void bmp085Stop(BMP085Driver *devp)
Deactivates the BMP085 Complex Driver peripheral.
Definition bmp085.c:768
#define BMP085_CR_P_VAL3
Definition bmp085.c:42
static msg_t acquire_ut(BMP085Driver *devp, int32_t *utemp)
Read the uncompensated temperature from the BMP085 register.
Definition bmp085.c:274
static size_t sens_get_axes_number(void *ip)
Get the sensor number of axes.
Definition bmp085.c:384
#define BMP085_THERMO_NUMBER_OF_AXES
BMP085 thermometer subsystem characteristics.
Definition bmp085.h:79
#define BMP085_T_RES
Definition bmp085.h:81
#define BMP085_AD_CR
Definition bmp085.h:88
static msg_t baro_read_cooked(void *ip, float axes[])
Read barometer cooked data.
Definition bmp085.c:492
static msg_t thermo_reset_bias(void *ip)
Reset the thermometer bias.
Definition bmp085.c:619
void bmp085Start(BMP085Driver *devp, const BMP085Config *config)
Configures and activates BMP085 Complex Driver peripheral.
Definition bmp085.c:739
static msg_t bmp085ReadCoefficient(BMP085Driver *devp, uint8_t reg)
Read all the calibration data from the BMP085 EEPROM.
Definition bmp085.c:108
static msg_t sens_read_raw(void *ip, int32_t axes[])
Read BMP085 sensor raw data.
Definition bmp085.c:467
@ BMP085_STOP
Definition bmp085.h:254
@ BMP085_READY
Definition bmp085.h:255
@ BMP085_THERMO_CT_LOW
Definition bmp085.h:236
@ BMP085_BARO_OSS_1
Definition bmp085.h:202
@ BMP085_BARO_OSS_0
Definition bmp085.h:201
@ BMP085_BARO_OSS_2
Definition bmp085.h:203
@ BMP085_BARO_CT_LUHR
Definition bmp085.h:184
@ BMP085_BARO_CT_LOW
Definition bmp085.h:181
@ BMP085_BARO_CT_HR
Definition bmp085.h:183
@ BMP085_BARO_CT_STD
Definition bmp085.h:182
BMP085 configuration structure.
Definition bmp085.h:261
I2CDriver * i2cp
I2C driver associated to this BMP085.
Definition bmp085.h:266
BMP085 driver structure.
Definition bmp085.h:371
const struct BaseBarometerVMT * vmt_basebarometer
BaseBarometer Virtual Methods Table.
Definition bmp085.h:375
const struct BaseThermometerVMT * vmt_basethermometer
BaseThermometer Virtual Methods Table.
Definition bmp085.h:377
const struct BaseSensorVMT * vmt_basesensor
BaseSensor Virtual Methods Table.
Definition bmp085.h:373
BaseBarometer virtual methods table.
BaseSensor virtual methods table.
Definition ex_sensors.h:65
BaseThermometer virtual methods table.
LSM303DLHC 6-axis accelerometer/compass class.
Definition lsm303dlhc.h:653