bmp085.h 13 KB

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