ChibiOS  21.6.0
bmp085.h
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.h
23  * @brief BMP085 Digital pressure sensor interface module header.
24  *
25  * @addtogroup BMP085
26  * @ingroup EX_BOSCH
27  * @{
28  */
29 
30 #ifndef BMP085_H
31 #define BMP085_H
32 
33 #include "ex_barometer.h"
34 #include "ex_thermometer.h"
35 
36 /*==========================================================================*/
37 /* Driver constants. */
38 /*==========================================================================*/
39 
40 /**
41  * @name Version identification
42  * @{
43  */
44 
45 /**
46  * @brief BMP085 driver version string.
47  */
48 #define EX_BMP085_VERSION "1.0.1"
49 
50 /**
51  * @brief BMP085 driver version major number.
52  */
53 #define EX_BMP085_MAJOR 1
54 
55 /**
56  * @brief BMP085 driver version minor number.
57  */
58 #define EX_BMP085_MINOR 0
59 
60 /**
61  * @brief BMP085 driver version patch number.
62  */
63 #define EX_BMP085_PATCH 1
64 /** @}*/
65 
66 /**
67  * @brief BMP085 barometer subsystem characteristics.
68  * @{
69  */
70 #define BMP085_BARO_NUMBER_OF_AXES 1U /**< Number of axes */
71 
72 #define BMP085_P_RES 0.01 /**< LSB/hP */
73 /** @} */
74 
75 /**
76  * @brief BMP085 thermometer subsystem characteristics.
77  * @{
78  */
79 #define BMP085_THERMO_NUMBER_OF_AXES 1U /**< Number of axes */
80 
81 #define BMP085_T_RES 0.1 /**< LSB/C° */
82 /** @} */
83 
84 /**
85  * @name BMP085 Registers addresses.
86  * @{
87  */
88 #define BMP085_AD_CR 0xF4 /**< Control register address. */
89 #define BMP085_AD_T_DR_MSB 0xF6 /**< Temp MSB data register addr. */
90 #define BMP085_AD_T_DR_LSB 0xF7 /**< Temp LSB data register addr. */
91 #define BMP085_AD_P_DR_MSB 0xF6 /**< Press MSB data register addr. */
92 #define BMP085_AD_P_DR_LSB 0xF7 /**< Press LSB data register addr. */
93 #define BMP085_AD_P_DR_XLSB 0xF8 /**< Press XLSB data register addr.*/
94 #define BMP085_AD_CC_AC1_MSB 0xAA /**< AC1 MSB calib coef reg addr. */
95 #define BMP085_AD_CC_AC1_LSB 0xAB /**< AC1 LSB calib coef reg addr. */
96 #define BMP085_AD_CC_AC2_MSB 0xAC /**< AC2 MSB calib coef reg addr. */
97 #define BMP085_AD_CC_AC2_LSB 0xAD /**< AC2 LSB calib coef reg addr. */
98 #define BMP085_AD_CC_AC3_MSB 0xAE /**< AC3 MSB calib coef reg addr. */
99 #define BMP085_AD_CC_AC3_LSB 0xAF /**< AC3 LSB calib coef reg addr. */
100 #define BMP085_AD_CC_AC4_MSB 0xB0 /**< AC4 MSB calib coef reg addr. */
101 #define BMP085_AD_CC_AC4_LSB 0xB1 /**< AC4 LSB calib coef reg addr. */
102 #define BMP085_AD_CC_AC5_MSB 0xB2 /**< AC5 MSB calib coef reg addr. */
103 #define BMP085_AD_CC_AC5_LSB 0xB3 /**< AC5 LSB calib coef reg addr. */
104 #define BMP085_AD_CC_AC6_MSB 0xB4 /**< AC6 MSB calib coef reg addr. */
105 #define BMP085_AD_CC_AC6_LSB 0xB5 /**< AC6 LSB calib coef reg addr. */
106 #define BMP085_AD_CC_B1_MSB 0xB6 /**< B1 MSB calib coef reg addr. */
107 #define BMP085_AD_CC_B1_LSB 0xB7 /**< B1 LSB calib coef reg addr. */
108 #define BMP085_AD_CC_B2_MSB 0xB8 /**< B2 MSB calib coef reg addr. */
109 #define BMP085_AD_CC_B2_LSB 0xB9 /**< B2 LSB calib coef reg addr. */
110 #define BMP085_AD_CC_MB_MSB 0xBA /**< MB MSB calib coef reg addr. */
111 #define BMP085_AD_CC_MB_LSB 0xBB /**< MB LSB calib coef reg addr. */
112 #define BMP085_AD_CC_MC_MSB 0xBC /**< MC MSB calib coef reg addr. */
113 #define BMP085_AD_CC_MC_LSB 0xBD /**< MC LSB calib coef reg addr. */
114 #define BMP085_AD_CC_MD_MSB 0xBE /**< MD MSB calib coef reg addr. */
115 #define BMP085_AD_CC_MD_LSB 0xBF /**< MD LSB calib coef reg addr. */
116 /** @} */
117 
118 /*==========================================================================*/
119 /* Driver pre-compile time settings. */
120 /*==========================================================================*/
121 
122 /**
123  * @name Configuration options
124  * @{
125  */
126 
127 /**
128  * @brief BMP085 I2C interface selector.
129  * @details If set to @p TRUE the support for I2C is included.
130  * @note The default is @p TRUE.
131  */
132 #if !defined(BMP085_USE_I2C) || defined(__DOXYGEN__)
133 #define BMP085_USE_I2C TRUE
134 #endif
135 
136 /**
137  * @brief BMP085 sensor subsystem advanced configurations switch.
138  * @details If set to @p TRUE more configurations are available.
139  * @note The default is @p TRUE.
140  */
141 #if !defined(BMP085_USE_ADVANCED) || defined(__DOXYGEN__)
142 #define BMP085_USE_ADVANCED TRUE
143 #endif
144 
145 /**
146  * @brief BMP085 shared I2C switch.
147  * @details If set to @p TRUE the device acquires I2C bus ownership
148  * on each transaction.
149  * @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION.
150  */
151 #if !defined(BMP085_SHARED_I2C) || defined(__DOXYGEN__)
152 #define BMP085_SHARED_I2C FALSE
153 #endif
154 /** @} */
155 
156 /*==========================================================================*/
157 /* Derived constants and error checks. */
158 /*==========================================================================*/
159 
160 #if !HAL_USE_I2C
161 #error "BMP085_USE_I2C requires HAL_USE_I2C"
162 #endif
163 
164 #if BMP085_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
165 #error "BMP085_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
166 #endif
167 
168 /*==========================================================================*/
169 /* Driver data structures and types. */
170 /*==========================================================================*/
171 
172 /**
173  * @name BMP085 barometer subsystem data structures and types.
174  * @{
175  */
176 
177 /**
178  * @brief BMP085 barometer subsystem pressure conversion time.
179  */
180 typedef enum {
181  BMP085_BARO_CT_LOW = 0x05, /**< Convers time in ultra low power mode. */
182  BMP085_BARO_CT_STD = 0x18, /**< Convers time in standard mode. */
183  BMP085_BARO_CT_HR = 0x0E, /**< Convers time in high resolution mode. */
184  BMP085_BARO_CT_LUHR = 0x1A /**< Convers time in ultra high res. mode. */
186 
187 /**
188  * @brief BMP085 barometer subsystem mode.
189  */
190 typedef enum {
191  BMP085_BARO_MODE_LOW = 0x00, /**< BMP085 ultra low power mode. */
192  BMP085_BARO_MODE_STD = 0x01, /**< BMP085 standard mode. */
193  BMP085_BARO_MODE_HR = 0x02, /**< BMP085 high resolution mode. */
194  BMP085_BARO_MODE_LUHR = 0x03 /**< BMP085 ultra high res. mode. */
196 
197 /**
198  * @brief BMP085 barometer oversampling setting.
199  */
200 typedef enum {
201  BMP085_BARO_OSS_0 = 0x00, /**< Ultra low power sampling rate. */
202  BMP085_BARO_OSS_1 = 0x01, /**< Standard mode sampling rate. */
203  BMP085_BARO_OSS_2 = 0x02, /**< High resolution sampling rate. */
204  BMP085_BARO_OSS_3 = 0x04 /**< ultra high resolution sampling rate. */
206 
207 /**
208  * @brief BMP085 barometer subsystem calibration data.
209  */
210 typedef struct {
211  int16_t ac1;
212  int16_t ac2;
213  int16_t ac3;
214  int16_t b1;
215  int16_t b2;
216  int16_t mb;
217  int16_t mc;
218  int16_t md;
219  uint16_t ac4;
220  uint16_t ac5;
221  uint16_t ac6;
222  int32_t b5;
223 } bmp085_cd_t;
224 
225 /** @} */
226 
227 /**
228  * @name BMP085 thermometer subsystem data structures and types.
229  * @{
230  */
231 
232 /**
233  * @brief BMP085 thermometer subsystem temperature conversion time.
234  */
235 typedef enum {
236  BMP085_THERMO_CT_LOW = 0x05, /**< Conv time in ultra low power mode. */
237  BMP085_THERMO_CT_STD = 0x18, /**< Conv time in standard mode. */
238  BMP085_THERMO_CT_HR = 0x0E, /**< Conv time in high resolution mode. */
239  BMP085_THERMO_CT_LUHR = 0x1A /**< Conv time in ultra high res. mode. */
241 
242 /** @} */
243 
244 /**
245  * @name BMP085 main system data structures and types.
246  * @{
247  */
248 
249 /**
250  * @brief Driver state machine possible states.
251  */
252 typedef enum {
253  BMP085_UNINIT = 0, /**< Not initialized. */
254  BMP085_STOP = 1, /**< Stopped. */
255  BMP085_READY = 2 /**< Ready. */
257 
258 /**
259  * @brief BMP085 configuration structure.
260  */
261 typedef struct {
262 #if BMP085_USE_I2C || defined(__DOXYGEN__)
263  /**
264  * @brief I2C driver associated to this BMP085.
265  */
267 
268  /**
269  * @brief I2C configuration associated to this BMP085 subsystem.
270  */
272 #endif /* BMP085_USE_I2C */
273  /**
274  * @brief HTS221 initial sensitivity.
275  * @note Value are respectively related to hygrometer
276  * and thermometer.
277  */
278  float* sensitivity;
279  /**
280  * @brief HTS221 initial bias.
281  * @note Value are respectively related to hygrometer
282  * and thermometer.
283  */
284  float* bias;
285  /**
286  * @brief HTS221 output data rate selection.
287  */
289 #if BMP085_USE_ADVANCED || defined(__DOXYGEN__)
290  /**
291  * @brief BMP085 barometer subsystem pressure conversion time.
292  */
294 
295  /**
296  * @brief BMP085 barometer subsystem mode.
297  */
299 
300  /**
301  * @brief BMP085 barometer subsystem oversampling setting.
302  */
304 
305  /**
306  * @brief BMP085 thermometer subsystem temperature conversion time.
307  */
309 #endif /* BMP085_USE_ADVANCED */
310 } BMP085Config;
311 
312 /**
313  * @brief Structure representing a BMP085 driver.
314  */
315 typedef struct BMP085Driver BMP085Driver;
316 
317 /**
318  * @brief @p BMP085 barometer subsystem specific methods.
319  */
320 #define _bmp085_baro_methods \
321  _base_barometer_methods
322 
323 /**
324  * @brief @p BMP085 thermometer subsystem specific methods.
325  */
326 #define _bmp085_thermo_methods \
327  _base_thermometer_methods
328 
329 /**
330  * @extends BaseBarometerVMT
331  *
332  * @brief @p BMP085 barometer virtual methods table.
333  */
336 };
337 
338 /**
339  * @extends BaseThermometerVMT
340  *
341  * @brief @p BMP085 thermometer virtual methods table.
342  */
345 };
346 
347 /**
348  * @brief @p BMP085Driver specific data.
349  */
350 #define _bmp085_data \
351  _base_barometer_data \
352  _base_thermometer_data \
353  /* Driver state. */ \
354  bmp085_state_t state; \
355  /* Current configuration data. */ \
356  const BMP085Config *config; \
357  /* Current barometer sensitivity. */ \
358  float barosensitivity[BMP085_BARO_NUMBER_OF_AXES]; \
359  /* Barometer bias data. */ \
360  int32_t barobias[BMP085_BARO_NUMBER_OF_AXES]; \
361  /* Current thermometer sensitivity. */ \
362  float thermosensitivity[BMP085_THERMO_NUMBER_OF_AXES]; \
363  /* Thermometer bias data. */ \
364  int32_t thermobias[BMP085_THERMO_NUMBER_OF_AXES]; \
365  /* BMP085 calibration data. */ \
366  bmp085_cd_t calibrationdata;
367 
368 /**
369  * @brief BMP085 driver structure.
370  */
371 struct BMP085Driver {
372  /** @brief BaseSensor Virtual Methods Table. */
374  /** @brief BaseBarometer Virtual Methods Table. */
376  /** @brief BaseThermometer Virtual Methods Table. */
378  _bmp085_data;
379 };
380 
381 /** @} */
382 
383 /*==========================================================================*/
384 /* Driver macros. */
385 /*==========================================================================*/
386 
387 /*==========================================================================*/
388 /* External declarations. */
389 /*==========================================================================*/
390 
391 #ifdef __cplusplus
392 extern "C" {
393 #endif
394  void bmp085ObjectInit(BMP085Driver *devp);
395  void bmp085Start(BMP085Driver *devp, const BMP085Config *config);
396  void bmp085Stop(BMP085Driver *devp);
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* BMP085_H */
402 
403 /** @} */
I2CDriver
Structure representing an I2C driver.
Definition: hal_i2c_lld.h:88
ex_barometer.h
Generic barometer interface header.
BMP085_UNINIT
@ BMP085_UNINIT
Definition: bmp085.h:253
BMP085Config::i2ccfg
const I2CConfig * i2ccfg
I2C configuration associated to this BMP085 subsystem.
Definition: bmp085.h:271
BMP085_BARO_CT_LOW
@ BMP085_BARO_CT_LOW
Definition: bmp085.h:181
bmp085_baro_mode_t
bmp085_baro_mode_t
BMP085 barometer subsystem mode.
Definition: bmp085.h:190
_bmp085_data
#define _bmp085_data
BMP085Driver specific data.
Definition: bmp085.h:350
bmp085_cd_t
BMP085 barometer subsystem calibration data.
Definition: bmp085.h:210
BMP085_THERMO_CT_HR
@ BMP085_THERMO_CT_HR
Definition: bmp085.h:238
BMP085Config::mode
bmp085_baro_mode_t mode
BMP085 barometer subsystem mode.
Definition: bmp085.h:298
BMP085_BARO_CT_LUHR
@ BMP085_BARO_CT_LUHR
Definition: bmp085.h:184
BMP085_BARO_OSS_3
@ BMP085_BARO_OSS_3
Definition: bmp085.h:204
BMP085_BARO_CT_STD
@ BMP085_BARO_CT_STD
Definition: bmp085.h:182
BMP085Config::bias
float * bias
HTS221 initial bias.
Definition: bmp085.h:284
bmp085_thermo_ct_t
bmp085_thermo_ct_t
BMP085 thermometer subsystem temperature conversion time.
Definition: bmp085.h:235
bmp085Start
void bmp085Start(BMP085Driver *devp, const BMP085Config *config)
Configures and activates BMP085 Complex Driver peripheral.
Definition: bmp085.c:739
BaseBarometerVMT
BaseBarometer virtual methods table.
Definition: ex_barometer.h:70
BMP085_BARO_MODE_LOW
@ BMP085_BARO_MODE_LOW
Definition: bmp085.h:191
_bmp085_thermo_methods
#define _bmp085_thermo_methods
BMP085 thermometer subsystem specific methods.
Definition: bmp085.h:326
BMP085Driver::vmt_basebarometer
const struct BaseBarometerVMT * vmt_basebarometer
BaseBarometer Virtual Methods Table.
Definition: bmp085.h:375
BMP085Config::tct
bmp085_thermo_ct_t tct
BMP085 thermometer subsystem temperature conversion time.
Definition: bmp085.h:308
BMP085BAROVMT
BMP085 barometer virtual methods table.
Definition: bmp085.h:334
_bmp085_baro_methods
#define _bmp085_baro_methods
BMP085 barometer subsystem specific methods.
Definition: bmp085.h:320
bmp085Stop
void bmp085Stop(BMP085Driver *devp)
Deactivates the BMP085 Complex Driver peripheral.
Definition: bmp085.c:768
BMP085_BARO_OSS_1
@ BMP085_BARO_OSS_1
Definition: bmp085.h:202
BMP085_THERMO_CT_LOW
@ BMP085_THERMO_CT_LOW
Definition: bmp085.h:236
BMP085_BARO_OSS_2
@ BMP085_BARO_OSS_2
Definition: bmp085.h:203
BMP085Config::i2cp
I2CDriver * i2cp
I2C driver associated to this BMP085.
Definition: bmp085.h:266
BaseThermometerVMT
BaseThermometer virtual methods table.
Definition: ex_thermometer.h:70
BMP085_READY
@ BMP085_READY
Definition: bmp085.h:255
BMP085Driver::vmt_basethermometer
const struct BaseThermometerVMT * vmt_basethermometer
BaseThermometer Virtual Methods Table.
Definition: bmp085.h:377
BMP085Config::bct
bmp085_baro_ct_t bct
BMP085 barometer subsystem pressure conversion time.
Definition: bmp085.h:293
bmp085_baro_ct_t
bmp085_baro_ct_t
BMP085 barometer subsystem pressure conversion time.
Definition: bmp085.h:180
BMP085_BARO_OSS_0
@ BMP085_BARO_OSS_0
Definition: bmp085.h:201
BMP085Driver
BMP085 driver structure.
Definition: bmp085.h:371
bmp085_state_t
bmp085_state_t
Driver state machine possible states.
Definition: bmp085.h:252
BMP085_STOP
@ BMP085_STOP
Definition: bmp085.h:254
BMP085Config::oss
bmp085_baro_oss_t oss
BMP085 barometer subsystem oversampling setting.
Definition: bmp085.h:303
BMP085Config
BMP085 configuration structure.
Definition: bmp085.h:261
BMP085_THERMO_CT_STD
@ BMP085_THERMO_CT_STD
Definition: bmp085.h:237
BaseSensorVMT
BaseSensor virtual methods table.
Definition: ex_sensors.h:65
BMP085_THERMO_CT_LUHR
@ BMP085_THERMO_CT_LUHR
Definition: bmp085.h:239
BMP085THERMOVMT
BMP085 thermometer virtual methods table.
Definition: bmp085.h:343
ex_thermometer.h
Generic thermometer interface header.
bmp085ObjectInit
void bmp085ObjectInit(BMP085Driver *devp)
Initializes an instance.
Definition: bmp085.c:722
BMP085_BARO_MODE_LUHR
@ BMP085_BARO_MODE_LUHR
Definition: bmp085.h:194
bmp085_baro_oss_t
bmp085_baro_oss_t
BMP085 barometer oversampling setting.
Definition: bmp085.h:200
BMP085Config::sensitivity
float * sensitivity
HTS221 initial sensitivity.
Definition: bmp085.h:278
BMP085_BARO_MODE_HR
@ BMP085_BARO_MODE_HR
Definition: bmp085.h:193
BMP085Config::outputdatarate
float * outputdatarate
HTS221 output data rate selection.
Definition: bmp085.h:288
BMP085_BARO_MODE_STD
@ BMP085_BARO_MODE_STD
Definition: bmp085.h:192
BMP085Driver::vmt_basesensor
const struct BaseSensorVMT * vmt_basesensor
BaseSensor Virtual Methods Table.
Definition: bmp085.h:373
BMP085_BARO_CT_HR
@ BMP085_BARO_CT_HR
Definition: bmp085.h:183
I2CConfig
Type of I2C driver configuration structure.
Definition: hal_i2c_lld.h:75