ChibiOS  19.1.4
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  */
71 msg_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,
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  */
92 msg_t bmp085I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbufp, size_t n) {
93 
94  return i2cMasterTransmitTimeout(i2cp, BMP085_SAD, txbufp, n + 1, NULL, 0,
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  */
108 static 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  */
146 static 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  */
165 static 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. */
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  */
274 static 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. */
280  start_t_measurement(devp);
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  */
311 static 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. */
321  start_p_measurement(devp);
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  */
356 static 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  */
370 static 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  */
384 static size_t sens_get_axes_number(void *ip) {
385 
386  osalDbgCheck(ip != NULL);
387 
388  return (baro_get_axes_number(ip) + thermo_get_axes_number(ip));
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  */
399 static 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  */
433 static 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  */
467 static 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  */
492 static 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  */
520 static 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  */
545 static 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  */
569 static 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  */
586 static 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  */
602 static 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  */
619 static 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  */
637 static 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  */
654 static 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  */
670 static 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  */
686 static 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 
695 static const struct BaseSensorVMT vmt_basesensor = {
697 };
698 
699 static const struct BaseBarometerVMT vmt_basebarometer = {
703 };
704 
705 static const struct BaseThermometerVMT vmt_basethermometer = {
709 };
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 
724  devp->vmt_basesensor = &vmt_basesensor;
725  devp->vmt_basebarometer = &vmt_basebarometer;
726  devp->vmt_basethermometer = &vmt_basethermometer;
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  */
739 void 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 /** @} */
#define BMP085_AD_CR
Definition: bmp085.h:88
msg_t bmp085I2CReadRegister(I2CDriver *i2cp, uint8_t reg, uint8_t *rxbufp, size_t n)
Reads registers value using I2C.
Definition: bmp085.c:71
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:170
static msg_t thermo_set_sensivity(void *ip, float *sp)
Set the thermometer sensivity.
Definition: bmp085.c:654
static void calcul_p(BMP085Driver *devp, int32_t up, uint8_t oss, float *cpp)
Calcul the true pressure.
Definition: bmp085.c:165
void i2cStart(I2CDriver *i2cp, const I2CConfig *config)
Configures and activates the I2C peripheral.
Definition: hal_i2c.c:93
#define chThdSleepMilliseconds(msec)
Delays the invoking thread for the specified number of milliseconds.
Definition: chthreads.h:197
static msg_t thermo_reset_sensivity(void *ip)
Reset the thermometer sensivity.
Definition: bmp085.c:686
static msg_t baro_set_sensivity(void *ip, float *sp)
Set the barometer sensivity.
Definition: bmp085.c:637
static msg_t thermo_set_bias(void *ip, float *bp)
Set the thermometer bias.
Definition: bmp085.c:586
static msg_t thermo_reset_bias(void *ip)
Reset the thermometer bias.
Definition: bmp085.c:619
static void calcul_t(BMP085Driver *devp, int32_t ut, float *ctp)
Calcul the true temperature.
Definition: bmp085.c:146
#define BMP085_P_RES
Definition: bmp085.h:72
static msg_t baro_read_cooked(void *ip, float axes[])
Read barometer cooked data.
Definition: bmp085.c:492
HAL subsystem header.
void i2cAcquireBus(I2CDriver *i2cp)
Gains exclusive access to the I2C bus.
Definition: hal_i2c.c:261
static msg_t baro_reset_sensivity(void *ip)
Reset the barometer sensivity.
Definition: bmp085.c:670
void i2cReleaseBus(I2CDriver *i2cp)
Releases exclusive access to the I2C bus.
Definition: hal_i2c.c:277
BaseThermometer virtual methods table.
const struct BaseBarometerVMT * vmt_basebarometer
BaseBarometer Virtual Methods Table.
Definition: bmp085.h:375
static size_t sens_get_axes_number(void *ip)
Get the sensor number of axes.
Definition: bmp085.c:384
BaseBarometer virtual methods table.
Definition: hal_barometer.h:70
static msg_t sens_read_raw(void *ip, int32_t axes[])
Read BMP085 sensor raw data.
Definition: bmp085.c:467
static msg_t baro_set_bias(void *ip, float *bp)
Set the barometer bias.
Definition: bmp085.c:569
void bmp085Start(BMP085Driver *devp, const BMP085Config *config)
Configures and activates BMP085 Complex Driver peripheral.
Definition: bmp085.c:739
BMP085 Digital pressure sensor interface module header.
void bmp085Stop(BMP085Driver *devp)
Deactivates the BMP085 Complex Driver peripheral.
Definition: bmp085.c:768
const struct BaseThermometerVMT * vmt_basethermometer
BaseThermometer Virtual Methods Table.
Definition: bmp085.h:377
static msg_t sens_read_cooked(void *ip, float axes[])
Read BMP085 sensor cooked data.
Definition: bmp085.c:545
void bmp085ObjectInit(BMP085Driver *devp)
Initializes an instance.
Definition: bmp085.c:722
static size_t baro_get_axes_number(void *ip)
Get the barometer number of axes.
Definition: bmp085.c:356
Structure representing an I2C driver.
Definition: hal_i2c_lld.h:88
#define BMP085_THERMO_NUMBER_OF_AXES
BMP085 thermometer subsystem characteristics.
Definition: bmp085.h:79
static msg_t thermo_read_raw(void *ip, int32_t axes[])
Read thermometer raw data.
Definition: bmp085.c:433
I2CDriver * i2cp
I2C driver associated to this BMP085.
Definition: bmp085.h:266
static msg_t baro_read_raw(void *ip, int32_t axes[])
Read baromether raw data.
Definition: bmp085.c:399
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
Definition: chtime.h:55
static msg_t bmp085ReadCoefficient(BMP085Driver *devp, uint8_t reg)
Read all the calibration data from the BMP085 EEPROM.
Definition: bmp085.c:108
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:278
#define BMP085_AD_CC_AC1_MSB
Definition: bmp085.h:94
static size_t thermo_get_axes_number(void *ip)
Get the thermometer number of axes.
Definition: bmp085.c:370
static msg_t acquire_ut(BMP085Driver *devp, int32_t *utemp)
Read the uncompensated temperature from the BMP085 register.
Definition: bmp085.c:274
#define MSG_OK
Normal wakeup message.
Definition: chschd.h:39
static msg_t start_p_measurement(BMP085Driver *devp)
Start the pressure measurment.
Definition: bmp085.c:223
BMP085 driver structure.
Definition: bmp085.h:371
#define BMP085_T_RES
Definition: bmp085.h:81
#define BMP085_AD_T_DR_MSB
Definition: bmp085.h:89
const struct BaseSensorVMT * vmt_basesensor
BaseSensor Virtual Methods Table.
Definition: bmp085.h:373
BMP085 configuration structure.
Definition: bmp085.h:261
#define BMP085_AD_P_DR_MSB
Definition: bmp085.h:91
LSM303DLHC 6-axis accelerometer/compass class.
Definition: lsm303dlhc.h:650
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:258
const I2CConfig * config
Current configuration data.
Definition: hal_i2c_lld.h:96
static msg_t baro_reset_bias(void *ip)
Reset the barometer bias.
Definition: bmp085.c:602
static msg_t thermo_read_cooked(void *ip, float axes[])
Read thermometer cooked data.
Definition: bmp085.c:520
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 start_t_measurement(BMP085Driver *devp)
Start temperature measurement.
Definition: bmp085.c:202
BaseSensor virtual methods table.
Definition: hal_sensors.h:65
#define BMP085_BARO_NUMBER_OF_AXES
BMP085 barometer subsystem characteristics.
Definition: bmp085.h:70
int32_t msg_t
Definition: chtypes.h:51
msg_t bmp085I2CWriteRegister(I2CDriver *i2cp, uint8_t *txbufp, size_t n)
Writes a value into a register using I2C.
Definition: bmp085.c:92