1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
/*
ChibiOS - Copyright (C) 2016..2017 Theodore Ateba
This file is part of ChibiOS.
ChibiOS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file bmp085.h
*
* @brief BMP085 Digital pressure sensor interface module header.
*
* @author Theodore Ateba, tf.ateba@gmail.com
*
* @date 19 July 2016
*
* @{
*/
#ifndef BMP085_H
#define BMP085_H
#include "hal_barometer.h"
#include "hal_thermometer.h"
/*==========================================================================*/
/* Driver constants. */
/*==========================================================================*/
/**
* @name Version identification
* @{
*/
/**
* @brief BMP085 driver version string.
*/
#define EX_BMP085_VERSION "1.0.0"
/**
* @brief BMP085 driver version major number.
*/
#define EX_BMP085_MAJOR 1
/**
* @brief BMP085 driver version minor number.
*/
#define EX_BMP085_MINOR 0
/**
* @brief BMP085 driver version patch number.
*/
#define EX_BMP085_PATCH 0
/** @}*/
/**
* @brief BMP085 barometer subsystem characteristics.
* @{
*/
#define BMP085_BARO_NUMBER_OF_AXES 1U /**< Number of axes. */
#define BMP085_P_RES 0.01 /**< Press resolution. */
#define BMP085_CR_P_VAL0 0x34 /**< Press control reg value 0. */
#define BMP085_CR_P_VAL1 0x74 /**< Press control reg value 1. */
#define BMP085_CR_P_VAL2 0xB4 /**< Press control reg value 2. */
#define BMP085_CR_P_VAL3 0xF4 /**< Press control reg value 3. */
/** @} */
/**
* @brief BMP085 thermometer subsystem characteristics.
* @{
*/
#define BMP085_THERMO_NUMBER_OF_AXES 1U /**< Number of axis. */
#define BMP085_T_RES 0.1 /**< Temp resolution. */
#define BMP085_CR_T_VAL 0x2E /**< Temp control register value. */
/** @} */
#define BMP085_SAD 0x77 /**< Slave address. */
/**
* @name BMP085 Registers addresses.
* @{
*/
#define BMP085_AD_CR 0xF4 /**< Control register address. */
#define BMP085_AD_T_DR_MSB 0xF6 /**< Temp MSB data register addr. */
#define BMP085_AD_T_DR_LSB 0xF7 /**< Temp LSB data register addr. */
#define BMP085_AD_P_DR_MSB 0xF6 /**< Press MSB data register addr. */
#define BMP085_AD_P_DR_LSB 0xF7 /**< Press LSB data register addr. */
#define BMP085_AD_P_DR_XLSB 0xF8 /**< Press XLSB data register addr.*/
#define BMP085_AD_CC_AC1_MSB 0xAA /**< AC1 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC1_LSB 0xAB /**< AC1 LSB calib coef reg addr. */
#define BMP085_AD_CC_AC2_MSB 0xAC /**< AC2 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC2_LSB 0xAD /**< AC2 LSB calib coef reg addr. */
#define BMP085_AD_CC_AC3_MSB 0xAE /**< AC3 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC3_LSB 0xAF /**< AC3 LSB calib coef reg addr. */
#define BMP085_AD_CC_AC4_MSB 0xB0 /**< AC4 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC4_LSB 0xB1 /**< AC4 LSB calib coef reg addr. */
#define BMP085_AD_CC_AC5_MSB 0xB2 /**< AC5 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC5_LSB 0xB3 /**< AC5 LSB calib coef reg addr. */
#define BMP085_AD_CC_AC6_MSB 0xB4 /**< AC6 MSB calib coef reg addr. */
#define BMP085_AD_CC_AC6_LSB 0xB5 /**< AC6 LSB calib coef reg addr. */
#define BMP085_AD_CC_B1_MSB 0xB6 /**< B1 MSB calib coef reg addr. */
#define BMP085_AD_CC_B1_LSB 0xB7 /**< B1 LSB calib coef reg addr. */
#define BMP085_AD_CC_B2_MSB 0xB8 /**< B2 MSB calib coef reg addr. */
#define BMP085_AD_CC_B2_LSB 0xB9 /**< B2 LSB calib coef reg addr. */
#define BMP085_AD_CC_MB_MSB 0xBA /**< MB MSB calib coef reg addr. */
#define BMP085_AD_CC_MB_LSB 0xBB /**< MB LSB calib coef reg addr. */
#define BMP085_AD_CC_MC_MSB 0xBC /**< MC MSB calib coef reg addr. */
#define BMP085_AD_CC_MC_LSB 0xBD /**< MC LSB calib coef reg addr. */
#define BMP085_AD_CC_MD_MSB 0xBE /**< MD MSB calib coef reg addr. */
#define BMP085_AD_CC_MD_LSB 0xBF /**< MD LSB calib coef reg addr. */
/** @} */
/*==========================================================================*/
/* Driver pre-compile time settings. */
/*==========================================================================*/
/**
* @name Configuration options
* @{
*/
/**
* @brief BMP085 I2C interface selector.
* @details If set to @p TRUE the support for I2C is included.
* @note The default is @p TRUE.
*/
#if !defined(BMP085_USE_I2C) || defined(__DOXYGEN__)
#define BMP085_USE_I2C TRUE
#endif
/**
* @brief BMP085 barometer subsystem advanced configurations switch.
* @details If set to @p TRUE more configurations are available.
* @note The default is @p FALSE.
*/
#if !defined(BMP085_BARO_USE_ADVANCED) || defined(__DOXYGEN__)
#define BMP085_BARO_USE_AVANCED FALSE
#endif
/**
* @brief BMP085 termomether subsystem advanced configurations switch.
* @details If set to @p TRUE more configurations are available.
* @note The default is @p FALSE.
*/
#if !defined(BMP085_THERMO_USE_ADVANCED) || defined(__DOXYGEN__)
#define BMP085_THERMO_USE_AVANCED FALSE
#endif
/**
* @brief BMP085 shared I2C switch.
* @details If set to @p TRUE the device acquires I2C bus ownership
* on each transaction.
* @note The default is @p FALSE. Requires I2C_USE_MUTUAL_EXCLUSION.
*/
#if !defined(BMP085_SHARED_I2C) || defined(__DOXYGEN__)
#define BMP085_SHARED_I2C FALSE
#endif
/** @} */
/*==========================================================================*/
/* Derived constants and error checks. */
/*==========================================================================*/
#if !HAL_USE_I2C
#error "BMP085_USE_I2C requires HAL_USE_I2C"
#endif
#if BMP085_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
#error "BMP085_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
#endif
/*==========================================================================*/
/* Driver data structures and types. */
/*==========================================================================*/
/**
* @name BMP085 barometer subsystem data structures and types.
* @{
*/
/**
* @brief BMP085 barometer subsystem pressure conversion time.
*/
typedef enum {
BMP085_BARO_CT_LOW = 0x05, /**< Convers time in ultra low power mode. */
BMP085_BARO_CT_STD = 0x18, /**< Convers time in standard mode. */
BMP085_BARO_CT_HR = 0x0E, /**< Convers time in high resolution mode. */
BMP085_BARO_CT_LUHR = 0x1A /**< Convers time in ultra high res. mode. */
} bmp085_baro_ct_t;
/**
* @brief BMP085 barometer subsystem mode.
*/
typedef enum {
BMP085_BARO_MODE_LOW = 0x00, /**< BMP085 ultra low power mode. */
BMP085_BARO_MODE_STD = 0x01, /**< BMP085 standard mode. */
BMP085_BARO_MODE_HR = 0x02, /**< BMP085 high resolution mode. */
BMP085_BARO_MODE_LUHR = 0x03 /**< BMP085 ultra high res. mode. */
} bmp085_baro_mode_t;
/**
* @brief BMP085 barometer oversampling setting.
*/
typedef enum {
BMP085_BARO_OSS_0 = 0x00, /**< Ultra low power sampling rate. */
BMP085_BARO_OSS_1 = 0x01, /**< Standard mode sampling rate. */
BMP085_BARO_OSS_2 = 0x02, /**< High resolution sampling rate. */
BMP085_BARO_OSS_3 = 0x04 /**< ultra high resolution sampling rate. */
}bmp085_baro_oss_t;
/**
* @brief BMP085 barometer subsystem configuration structure.
*/
typedef struct {
/**
* @brief BMP085 barometer subsystem pressure conversion time.
*/
bmp085_baro_ct_t ct;
/**
* @brief BMP085 barometer subsystem mode.
*/
bmp085_baro_mode_t mode;
/**
* @brief BMP085 barometer subsystem oversampling setting.
*/
bmp085_baro_oss_t oss;
} BMP085BaroConfig;
/** @} */
/**
* @name BMP085 thermometer subsystem data structures and types.
* @{
*/
/**
* @brief BMP085 thermometer subsystem temperature conversion time.
*/
typedef enum {
BMP085_THERMO_CT_LOW = 0x05, /**< Conv time in ultra low power mode. */
BMP085_THERMO_CT_STD = 0x18, /**< Conv time in standard mode. */
BMP085_THERMO_CT_HR = 0x0E, /**< Conv time in high resolution mode. */
BMP085_THERMO_CT_LUHR = 0x1A /**< Conv time in ultra high res. mode. */
} bmp085_thermo_ct_t;
/**
* @brief BMP085 thermometer subsystem configuration structure.
*/
typedef struct {
/**
* @brief BMP085 thermometer subsystem temperature conversion time.
*/
bmp085_thermo_ct_t conversionTime;
} BMP085ThermoConfig;
/** @} */
/**
* @name BMP085 main system data structures and types.
* @{
*/
/**
* @brief Driver state machine possible states.
*/
typedef enum {
BMP085_UNINIT = 0, /**< Not initialized. */
BMP085_STOP = 1, /**< Stopped. */
BMP085_READY = 2 /**< Ready. */
} bmp085_state_t;
/**
* @brief BMP085 configuration structure.
*/
typedef struct {
/**
* @brief I2C driver associated to this BMP085.
*/
I2CDriver *i2cp;
/**
* @brief I2C configuration associated to this BMP085 subsystem.
*/
const I2CConfig *i2ccfg;
/**
* @brief BMP085 barometer subsystem configuration structure
*/
const BMP085BaroConfig *barocfg;
/**
* @brief BMP085 thermometer subsystem configuration structure
*/
const BMP085ThermoConfig *thermocfg;
} BMP085Config;
/**
* @brief Structure representing a BMP085 driver.
*/
typedef struct BMP085Driver BMP085Driver;
/**
* @brief @p BMP085 barometer subsystem specific methods.
*/
#define _bmp085_baro_methods \
_base_barometer_methods
/**
* @brief @p BMP085 thermometer subsystem specific methods.
*/
#define _bmp085_thermo_methods \
_base_thermometer_methods
/**
* @extends BaseBarometerVMT
*
* @brief @p BMP085 barometer virtual methods table.
*/
struct BMP085BAROVMT {
_bmp085_baro_methods
};
/**
* @extends BaseThermometerVMT
*
* @brief @p BMP085 thermometer virtual methods table.
*/
struct BMP085THERMOVMT {
_bmp085_thermo_methods
};
/**
* @brief @p BMP085Driver specific data.
*/
#define _bmp085_data \
_base_barometer_data \
_base_thermometer_data \
/* Driver state. */ \
bmp085_state_t state; \
/* Current configuration data. */ \
const BMP085Config *config; \
/* Current barometer sensitivity. */ \
float barosensitivity[BMP085_BARO_NUMBER_OF_AXES]; \
/* Barometer bias data. */ \
int32_t barobias[BMP085_BARO_NUMBER_OF_AXES]; \
/* Current thermometer sensitivity. */ \
float thermosensitivity[BMP085_THERMO_NUMBER_OF_AXES]; \
/* Thermometer bias data. */ \
int32_t thermobias[BMP085_THERMO_NUMBER_OF_AXES];
struct BMP085Driver {
/** @brief BaseSensor Virtual Methods Table. */
const struct BaseSensorVMT *vmt_basesensor;
/** @brief BaseBarometer Virtual Methods Table. */
const struct BaseBarometerVMT *vmt_basebarometer;
/** @brief BaseThermometer Virtual Methods Table. */
const struct BaseThermometerVMT *vmt_basethermometer;
_bmp085_data
};
/** @} */
/*==========================================================================*/
/* Driver macros. */
/*==========================================================================*/
/*==========================================================================*/
/* External declarations. */
/*==========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
void bmp085ObjectInit(BMP085Driver *devp);
void bmp085Start(BMP085Driver *devp, const BMP085Config *config);
void bmp085Stop(BMP085Driver *devp);
#ifdef __cplusplus
}
#endif
#endif /* BMP085_H */
/** @} */
|