Double MSP (TLM and MAVLink) throughput for Gemini hardware (#3037)
[ExpressLRS.git] / src / lib / Baro / baro_bmp085.cpp
bloba318eefa0d8370c1e333246ca6c3d62e01b30571
1 #if 0 // UNTESTED
2 #include "baro_bmp085.h"
4 /****
5 * Calculations used in this code taken from Adafruit BMP085 calculation
6 * https://github.com/adafruit/Adafruit-BMP085-Library/blob/master/Adafruit_BMP085.cpp
8 * Code reused under GPL License, see the Adafruit project for full license information
9 * https://github.com/adafruit/Adafruit-BMP085-Library/
10 ****/
12 void BMP085::initialize()
14 if (m_initialized)
15 return;
17 // All the calibration registers are in order of our struct and are 2 bytes long too,
18 // so just read them directly into our calib data
19 readRegister(BMP085_CALIB_COEFFS_START, (uint8_t *)&m_calib, sizeof(m_calib));
22 uint8_t BMP085::getPressureDuration()
24 switch (OVERSAMPLING_PRESSURE)
26 case 0: return 5; // 4.5ms
27 case 1: return 8; // 7.5ms
28 case 2: return 14; // 13.5ms
29 default: // fallthrough
30 case 3: return 26; // 25.5ms
34 void BMP085::startPressure()
36 uint8_t reg_value = BMP085_CMD_MEAS_PRESSURE | (OVERSAMPLING_PRESSURE << 6);
37 writeRegister(BMP085_REG_CONTROL, &reg_value, sizeof(reg_value));
40 int32_t BMP085::computeB5(int32_t UT) const
42 int32_t X1 = (UT - (int32_t)m_calib.ac6) * ((int32_t)m_calib.ac5) >> 15;
43 int32_t X2 = ((int32_t)m_calib.mc << 11) / (X1 + (int32_t)m_calib.md);
44 return X1 + X2;
47 uint32_t BMP085::getPressure()
49 uint8_t buf[3];
50 readRegister(BMP085_REG_PRESSURE_DATA, buf, sizeof(buf));
51 uint32_t raw = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) >> OVERSAMPLING_PRESSURE;
53 int32_t B3, B5, B6, X1, X2, X3, p;
54 uint32_t B4, B7;
56 B5 = computeB5(m_temperatureLast);
58 B6 = B5 - 4000;
59 X1 = ((int32_t)m_calib.b2 * ((B6 * B6) >> 12)) >> 11;
60 X2 = ((int32_t)m_calib.ac2 * B6) >> 11;
61 X3 = X1 + X2;
62 B3 = ((((int32_t)m_calib.ac1 * 4 + X3) << OVERSAMPLING_PRESSURE) + 2) / 4;
64 X1 = ((int32_t)m_calib.ac3 * B6) >> 13;
65 X2 = ((int32_t)m_calib.b1 * ((B6 * B6) >> 12)) >> 16;
66 X3 = ((X1 + X2) + 2) >> 2;
67 B4 = ((uint32_t)m_calib.ac4 * (uint32_t)(X3 + 32768)) >> 15;
68 B7 = ((uint32_t)raw - B3) * (uint32_t)(50000UL >> OVERSAMPLING_PRESSURE);
70 if (B7 < 0x80000000) {
71 p = (B7 * 2) / B4;
72 } else {
73 p = (B7 / B4) * 2;
75 X1 = (p >> 8) * (p >> 8);
76 X1 = (X1 * 3038) >> 16;
77 X2 = (-7357 * p) >> 16;
79 p = p + ((X1 + X2 + (int32_t)3791) >> 4);
80 return p;
83 uint8_t BMP085::getTemperatureDuration()
85 // Max. conversion time 4.5ms
86 return 5;
89 void BMP085::startTemperature()
91 uint8_t reg_value = BMP085_CMD_MEAS_TEMPERATURE;
92 writeRegister(BMP085_REG_CONTROL, &reg_value, sizeof(reg_value));
95 int32_t BMP085::getTemperature()
97 m_temperatureLast = 0;
98 readRegister(BMP085_REG_TEMPERATURE_DATA, (uint8_t *)&m_temperatureLast, sizeof(m_temperatureLast));
99 return m_temperatureLast;
102 bool BMP085::detect()
104 // Assumes Wire.begin() has already been called
105 uint8_t chipid = 0;
106 m_address = BMP085_I2C_ADDR;
107 readRegister(BMP085_REG_CHIPID, &chipid, sizeof(chipid));
108 return chipid == BMP085_CHIPID;
110 #endif