AP_Baro: added option to probe any i2c baro using GND_PROBE_EXT

This adds a hwdef.dat define HAL_PROBE_EXTERNAL_I2C_BAROS. When set,
we get a new parameter GND_PROBE_EXT that is a bitmask of i2c
barometers to look for.

This allows boards that have no builtin baro to work without
rebuilding
This commit is contained in:
Andrew Tridgell 2018-08-23 10:42:06 +10:00
parent f937589810
commit 1439b1a730
7 changed files with 141 additions and 2 deletions

View File

@ -50,6 +50,10 @@
#define HAL_BARO_FILTER_DEFAULT 0 // turned off by default
#endif
#ifndef HAL_BARO_PROBE_EXT_DEFAULT
#define HAL_BARO_PROBE_EXT_DEFAULT 0
#endif
extern const AP_HAL::HAL& hal;
// table of user settable parameters
@ -143,6 +147,15 @@ const AP_Param::GroupInfo AP_Baro::var_info[] = {
// @Increment: 1
AP_GROUPINFO("FLTR_RNG", 13, AP_Baro, _filter_range, HAL_BARO_FILTER_DEFAULT),
#ifdef HAL_PROBE_EXTERNAL_I2C_BAROS
// @Param: PROBE_EXT
// @DisplayName: External barometers to probe
// @Description: This sets which types of external i2c barometer to look for. It is a bitmask of barometer types
// @Bitmask: 0:BMP085,1:BMP280,2:MS5611,3:MS5607,4:MS5637,5:FBM320,6:DPS280,7:LPS25H,8:Keller
// @User: Advanced
AP_GROUPINFO("PROBE_EXT", 14, AP_Baro, _baro_probe_ext, HAL_BARO_PROBE_EXT_DEFAULT),
#endif
AP_GROUPEND
};
@ -596,6 +609,10 @@ void AP_Baro::init(void)
#endif
}
#ifdef HAL_PROBE_EXTERNAL_I2C_BAROS
_probe_i2c_barometers();
#endif
#if CONFIG_HAL_BOARD != HAL_BOARD_F4LIGHT // most boards requires external baro
if (_num_drivers == 0 || _num_sensors == 0 || drivers[0] == nullptr) {
@ -604,6 +621,83 @@ void AP_Baro::init(void)
#endif
}
/*
probe all the i2c barometers enabled with GND_PROBE_EXT. This is
used on boards without a builtin barometer
*/
void AP_Baro::_probe_i2c_barometers(void)
{
uint32_t probe = _baro_probe_ext.get();
if (probe & PROBE_BMP085) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_BMP085::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_BMP085_I2C_ADDR))));
}
}
if (probe & PROBE_BMP280) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_BMP280::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_BMP280_I2C_ADDR))));
ADD_BACKEND(AP_Baro_BMP280::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_BMP280_I2C_ADDR2))));
}
}
if (probe & PROBE_MS5611) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_MS56XX::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_MS5611_I2C_ADDR))));
}
}
if (probe & PROBE_MS5607) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_MS56XX::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_MS5607_I2C_ADDR)),
AP_Baro_MS56XX::BARO_MS5607));
}
}
if (probe & PROBE_MS5637) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_MS56XX::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_MS5637_I2C_ADDR)),
AP_Baro_MS56XX::BARO_MS5637));
}
}
if (probe & PROBE_FBM320) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_FBM320::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_FBM320_I2C_ADDR))));
ADD_BACKEND(AP_Baro_FBM320::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_FBM320_I2C_ADDR2))));
}
}
if (probe & PROBE_DPS280) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_DPS280::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_DPS280_I2C_ADDR))));
ADD_BACKEND(AP_Baro_DPS280::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_DPS280_I2C_ADDR2))));
}
}
if (probe & PROBE_LPS25H) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_LPS2XH::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_LPS25H_I2C_ADDR))));
}
}
if (probe & PROBE_LPS25H) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_KellerLD::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_KELLERLD_I2C_ADDR))));
}
}
if (probe & PROBE_MS5837) {
FOREACH_I2C_EXTERNAL(i) {
ADD_BACKEND(AP_Baro_MS56XX::probe(*this,
std::move(hal.i2c_mgr->get_device(i, HAL_BARO_MS5837_I2C_ADDR)), AP_Baro_MS56XX::BARO_MS5837));
}
}
}
bool AP_Baro::should_df_log() const
{
DataFlash_Class *instance = DataFlash_Class::instance();

View File

@ -197,6 +197,20 @@ private:
uint32_t _log_baro_bit = -1;
// bitmask values for GND_PROBE_EXT
enum {
PROBE_BMP085=(1<<0),
PROBE_BMP280=(1<<1),
PROBE_MS5611=(1<<2),
PROBE_MS5607=(1<<3),
PROBE_MS5637=(1<<4),
PROBE_FBM320=(1<<5),
PROBE_DPS280=(1<<6),
PROBE_LPS25H=(1<<7),
PROBE_KELLER=(1<<8),
PROBE_MS5837=(1<<9),
};
struct sensor {
baro_type_t type; // 0 for air pressure (default), 1 for water pressure
uint32_t last_update_ms; // last update time in ms
@ -229,7 +243,9 @@ private:
uint32_t _last_notify_ms;
bool _add_backend(AP_Baro_Backend *backend);
void _probe_i2c_barometers(void);
AP_Int8 _filter_range; // valid value range from mean value
AP_Int32 _baro_probe_ext;
};
namespace AP {

View File

@ -7,7 +7,10 @@
#include "AP_Baro_Backend.h"
#ifndef HAL_BARO_BMP280_I2C_ADDR
#define HAL_BARO_BMP280_I2C_ADDR (0x76)
#define HAL_BARO_BMP280_I2C_ADDR (0x76)
#endif
#ifndef HAL_BARO_BMP280_I2C_ADDR2
#define HAL_BARO_BMP280_I2C_ADDR2 (0x77)
#endif
class AP_Baro_BMP280 : public AP_Baro_Backend

View File

@ -6,6 +6,13 @@
#include "AP_Baro_Backend.h"
#ifndef HAL_BARO_DPS280_I2C_ADDR
#define HAL_BARO_DPS280_I2C_ADDR 0x76
#endif
#ifndef HAL_BARO_DPS280_I2C_ADDR2
#define HAL_BARO_DPS280_I2C_ADDR2 0x77
#endif
class AP_Baro_DPS280 : public AP_Baro_Backend {
public:
AP_Baro_DPS280(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);

View File

@ -6,6 +6,14 @@
#include "AP_Baro_Backend.h"
#ifndef HAL_BARO_FBM320_I2C_ADDR
#define HAL_BARO_FBM320_I2C_ADDR 0x6C
#endif
#ifndef HAL_BARO_FBM320_I2C_ADDR2
#define HAL_BARO_FBM320_I2C_ADDR2 0x6D
#endif
class AP_Baro_FBM320 : public AP_Baro_Backend {
public:
AP_Baro_FBM320(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::Device> dev);

View File

@ -7,7 +7,10 @@
#include "AP_Baro_Backend.h"
#define HAL_BARO_LPS25H_I2C_BUS 0
#define HAL_BARO_LPS25H_I2C_ADDR 0x5D
#ifndef HAL_BARO_LPS25H_I2C_ADDR
# define HAL_BARO_LPS25H_I2C_ADDR 0x5D
#endif
class AP_Baro_LPS2XH : public AP_Baro_Backend

View File

@ -10,10 +10,18 @@
#define HAL_BARO_MS5611_I2C_ADDR 0x77
#endif
#ifndef HAL_BARO_MS5607_I2C_ADDR
#define HAL_BARO_MS5607_I2C_ADDR 0x77
#endif
#ifndef HAL_BARO_MS5837_I2C_ADDR
#define HAL_BARO_MS5837_I2C_ADDR 0x76
#endif
#ifndef HAL_BARO_MS5637_I2C_ADDR
#define HAL_BARO_MS5637_I2C_ADDR 0x76
#endif
class AP_Baro_MS56XX : public AP_Baro_Backend
{
public: