mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
Configurable baro (BMP280)
- busDevice_t is now has a discriminator. - busDevice_t is added to baroDev_t. - BMP280 I2C and SPI drivers are consolidated.
This commit is contained in:
parent
b3898fa9d1
commit
52d447d2ef
14 changed files with 152 additions and 209 deletions
|
@ -20,12 +20,16 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "build/debug.h"
|
||||
|
||||
#include "common/maths.h"
|
||||
|
||||
#include "config/parameter_group.h"
|
||||
#include "config/parameter_group_ids.h"
|
||||
|
||||
#include "drivers/bus.h"
|
||||
#include "drivers/io.h"
|
||||
|
||||
#include "drivers/barometer/barometer.h"
|
||||
#include "drivers/barometer/barometer_bmp085.h"
|
||||
#include "drivers/barometer/barometer_bmp280.h"
|
||||
|
@ -107,6 +111,18 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
|||
; // fallthough
|
||||
case BARO_BMP280:
|
||||
#if defined(USE_BARO_BMP280) || defined(USE_BARO_SPI_BMP280)
|
||||
|
||||
// XXX Temporary for testing.
|
||||
// XXX Setup busDevice_t (dev->busdev) for BMP280
|
||||
#if defined(USE_BARO_SPI_BMP280)
|
||||
dev->busdev.bustype = BUSTYPE_SPI;
|
||||
dev->busdev.busdev_u.spi.instance = BMP280_SPI_INSTANCE;
|
||||
dev->busdev.busdev_u.spi.csnPin = IOGetByTag(IO_TAG(BMP280_CS_PIN));
|
||||
#elif defined(USE_BARO_BMP280)
|
||||
dev->busdev.bustype = BUSTYPE_I2C;
|
||||
dev->busdev.busdev_u.i2c.device = BARO_I2C_INSTANCE;
|
||||
dev->busdev.busdev_u.i2c.address = BMP280_I2C_ADDR;
|
||||
#endif
|
||||
if (bmp280Detect(dev)) {
|
||||
baroHardware = BARO_BMP280;
|
||||
break;
|
||||
|
@ -206,15 +222,15 @@ uint32_t baroUpdate(void)
|
|||
switch (state) {
|
||||
default:
|
||||
case BAROMETER_NEEDS_SAMPLES:
|
||||
baro.dev.get_ut();
|
||||
baro.dev.start_up();
|
||||
baro.dev.get_ut(&baro.dev);
|
||||
baro.dev.start_up(&baro.dev);
|
||||
state = BAROMETER_NEEDS_CALCULATION;
|
||||
return baro.dev.up_delay;
|
||||
break;
|
||||
|
||||
case BAROMETER_NEEDS_CALCULATION:
|
||||
baro.dev.get_up();
|
||||
baro.dev.start_ut();
|
||||
baro.dev.get_up(&baro.dev);
|
||||
baro.dev.start_ut(&baro.dev);
|
||||
baro.dev.calculate(&baroPressure, &baroTemperature);
|
||||
baroPressureSum = recalculateBarometerTotal(barometerConfig()->baro_sample_count, baroPressureSum, baroPressure);
|
||||
state = BAROMETER_NEEDS_SAMPLES;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue