diff --git a/src/main/drivers/barometer_bmp085.c b/src/main/drivers/barometer_bmp085.c index a67f34f3fe..c67eb4e6d5 100644 --- a/src/main/drivers/barometer_bmp085.c +++ b/src/main/drivers/barometer_bmp085.c @@ -31,18 +31,22 @@ #include "barometer_bmp085.h" +#ifdef BARO + +#if defined(BARO_EOC_GPIO) // BMP085, Standard address 0x77 -static bool convDone = false; -static uint16_t convOverrun = 0; +static bool isConversionComplete = false; +static uint16_t bmp085ConversionOverrun = 0; // EXTI14 for BMP085 End of Conversion Interrupt void EXTI15_10_IRQHandler(void) { if (EXTI_GetITStatus(EXTI_Line14) == SET) { EXTI_ClearITPendingBit(EXTI_Line14); - convDone = true; + isConversionComplete = true; } } +#endif typedef struct { int16_t ac1; @@ -149,7 +153,7 @@ bool bmp085Detect(const bmp085Config_t *config, baro_t *baro) if (bmp085InitDone) return true; -#if defined(BARO) && defined(BARO_XCLR_GPIO) && defined(BARO_EOC_GPIO) +#if defined(BARO_XCLR_GPIO) && defined(BARO_EOC_GPIO) if (config) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -193,8 +197,8 @@ bool bmp085Detect(const bmp085Config_t *config, baro_t *baro) bmp085.al_version = BMP085_GET_BITSLICE(data, BMP085_AL_VERSION); /* get AL Version */ bmp085_get_cal_param(); /* readout bmp085 calibparam structure */ bmp085InitDone = true; - baro->ut_delay = 6000; // 1.5ms margin according to the spec (4.5ms T convetion time) - baro->up_delay = 27000; // 6000+21000=27000 1.5ms margin according to the spec (25.5ms P convetion time with OSS=3) + baro->ut_delay = 6000; // 1.5ms margin according to the spec (4.5ms T conversion time) + baro->up_delay = 27000; // 6000+21000=27000 1.5ms margin according to the spec (25.5ms P conversion time with OSS=3) baro->start_ut = bmp085_start_ut; baro->get_ut = bmp085_get_ut; baro->start_up = bmp085_start_up; @@ -263,7 +267,9 @@ static int32_t bmp085_get_pressure(uint32_t up) static void bmp085_start_ut(void) { - convDone = false; +#if defined(BARO_EOC_GPIO) + isConversionComplete = false; +#endif i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, BMP085_T_MEASURE); } @@ -271,9 +277,12 @@ static void bmp085_get_ut(void) { uint8_t data[2]; - // wait in case of cockup - if (!convDone) - convOverrun++; +#if defined(BARO_EOC_GPIO) + if (!isConversionComplete) { + bmp085ConversionOverrun++; + return; // keep old value + } +#endif i2cRead(BMP085_I2C_ADDR, BMP085_ADC_OUT_MSB_REG, 2, data); bmp085_ut = (data[0] << 8) | data[1]; @@ -284,7 +293,11 @@ static void bmp085_start_up(void) uint8_t ctrl_reg_data; ctrl_reg_data = BMP085_P_MEASURE + (bmp085.oversampling_setting << 6); - convDone = false; + +#if defined(BARO_EOC_GPIO) + isConversionComplete = false; +#endif + i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, ctrl_reg_data); } @@ -296,9 +309,13 @@ static void bmp085_get_up(void) { uint8_t data[3]; +#if defined(BARO_EOC_GPIO) // wait in case of cockup - if (!convDone) - convOverrun++; + if (!isConversionComplete) { + bmp085ConversionOverrun++; + return; // keep old value + } +#endif i2cRead(BMP085_I2C_ADDR, BMP085_ADC_OUT_MSB_REG, 3, data); bmp085_up = (((uint32_t) data[0] << 16) | ((uint32_t) data[1] << 8) | (uint32_t) data[2]) @@ -338,3 +355,5 @@ static void bmp085_get_cal_param(void) bmp085.cal_param.mc = (data[18] << 8) | data[19]; bmp085.cal_param.md = (data[20] << 8) | data[21]; } + +#endif