Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Barometer-Example LoRaWAN-demo-72-bootcamp
Fork of BMP085 by
BMP085.h
00001 /** 00002 * Bosch BMP085 Barometer driver 00003 */ 00004 00005 #ifndef BMP085_H 00006 #define BMP085_H 00007 00008 #include <stdint.h> 00009 #include "mbed.h" 00010 00011 #define BMP085_ADDR (0x77<<1) 00012 00013 typedef enum { 00014 BMP085_CAL_AC1 = 0xAA, 00015 BMP085_CAL_AC2 = 0xAC, 00016 BMP085_CAL_AC3 = 0xAE, 00017 BMP085_CAL_AC4 = 0xB0, 00018 BMP085_CAL_AC5 = 0xB2, 00019 BMP085_CAL_AC6 = 0xB4, 00020 BMP085_CAL_B1 = 0xB6, 00021 BMP085_CAL_B2 = 0xB8, 00022 BMP085_CAL_MB = 0xBA, 00023 BMP085_CAL_MC = 0xBC, 00024 BMP085_CAL_MD = 0xBE, 00025 BMP085_CHIPID = 0xD0, 00026 BMP085_VERSION = 0xD1, 00027 BMP085_SOFTRESET = 0xE0, 00028 BMP085_CTRL = 0xF4, 00029 BMP085_DATA_TEMP = 0xF6, 00030 BMP085_DATA_PRESSURE = 0xF6, 00031 BMP085_CMD_READ_TEMP = 0x2E, 00032 BMP085_CMD_READ_PRESSURE = 0x34 00033 } BMP085_Register; 00034 00035 typedef enum { 00036 BMP085_MODE_ULTRA_LOW_POWER = 0, 00037 BMP085_MODE_STANDARD = 1, 00038 BMP085_MODE_HIGH_RESOLUTION = 2, 00039 BMP085_MODE_ULTRA_HIGH_RESOLUTION = 3 00040 } BMP085_Mode; 00041 00042 typedef enum { 00043 BMP085_IDLE, 00044 BMP085_BUSY, 00045 BMP085_TIMEOUT 00046 } BMP085_State; 00047 00048 typedef struct { 00049 int16_t ac1; 00050 int16_t ac2; 00051 int16_t ac3; 00052 uint16_t ac4; 00053 uint16_t ac5; 00054 uint16_t ac6; 00055 int16_t b1; 00056 int16_t b2; 00057 int16_t mb; 00058 int16_t mc; 00059 int16_t md; 00060 } BMP085_Calibration_Data; 00061 00062 class BMP085 { 00063 public: 00064 BMP085(PinName sda, PinName scl, BMP085_Mode mode = BMP085_MODE_STANDARD) : _i2c(sda, scl), _mode(mode), _state(BMP085_IDLE) { init(); }; 00065 BMP085(I2C & i2c, BMP085_Mode mode = BMP085_MODE_STANDARD) : _i2c(i2c), _mode(mode), _state(BMP085_IDLE) { init(); }; 00066 00067 float get_temperature(void) { return _temperature; }; 00068 float get_pressure(void) { return _pressure; }; 00069 void measure(); 00070 void _callback_handler_timeout(); 00071 protected: 00072 void init(void); 00073 uint16_t read_cal_register(BMP085_Register reg); 00074 uint16_t read_uc_temperature(void); 00075 uint32_t read_uc_pressure(void); 00076 I2C _i2c; 00077 BMP085_Mode _mode; 00078 BMP085_State _state; 00079 float _temperature; 00080 float _pressure; 00081 BMP085_Calibration_Data _cal_data; 00082 private: 00083 int transfer(char *tx, int tx_len, char *rx, int rx_len); 00084 int wait(float delay); 00085 00086 event_callback_t _callback; 00087 void _callback_handler(int event); 00088 uint8_t _tx_buf[2]; 00089 uint8_t _rx_buf[3]; 00090 00091 Timer _timeout; 00092 }; 00093 00094 #endif /* BMP085_H */
Generated on Thu Jul 14 2022 12:06:53 by
1.7.2
