Add bus parameters to barometerConfig_t, cli handling
This commit is contained in:
parent
62909821ec
commit
d2c71a6f7e
|
@ -49,9 +49,9 @@ typedef enum I2CDevice {
|
||||||
#define I2C_CFG_TO_DEV(x) ((x) - 1)
|
#define I2C_CFG_TO_DEV(x) ((x) - 1)
|
||||||
#define I2C_DEV_TO_CFG(x) ((x) + 1)
|
#define I2C_DEV_TO_CFG(x) ((x) + 1)
|
||||||
|
|
||||||
// I2C device address range in 8-bit address mode
|
// I2C device address range in 7-bit address mode
|
||||||
#define I2C_ADDR8_MIN 8
|
#define I2C_ADDR7_MIN 8
|
||||||
#define I2C_ADDR8_MAX 119
|
#define I2C_ADDR7_MAX 119
|
||||||
|
|
||||||
typedef struct i2cConfig_s {
|
typedef struct i2cConfig_s {
|
||||||
ioTag_t ioTagScl[I2CDEV_COUNT];
|
ioTag_t ioTagScl[I2CDEV_COUNT];
|
||||||
|
|
|
@ -57,6 +57,15 @@ SPIDevice spiDeviceByInstance(SPI_TypeDef *instance)
|
||||||
return SPIINVALID;
|
return SPIINVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPI_TypeDef *spiInstanceByDevice(SPIDevice device)
|
||||||
|
{
|
||||||
|
if (device >= SPIDEV_COUNT) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return spiDevice[device].dev;
|
||||||
|
}
|
||||||
|
|
||||||
void spiInitDevice(SPIDevice device)
|
void spiInitDevice(SPIDevice device)
|
||||||
{
|
{
|
||||||
spiDevice_t *spi = &(spiDevice[device]);
|
spiDevice_t *spi = &(spiDevice[device]);
|
||||||
|
|
|
@ -82,6 +82,10 @@ typedef enum SPIDevice {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Macros to convert between CLI bus number and SPIDevice.
|
||||||
|
#define SPI_CFG_TO_DEV(x) ((x) - 1)
|
||||||
|
#define SPI_DEV_TO_CFG(x) ((x) + 1)
|
||||||
|
|
||||||
void spiPreInitCs(ioTag_t iotag);
|
void spiPreInitCs(ioTag_t iotag);
|
||||||
bool spiInit(SPIDevice device);
|
bool spiInit(SPIDevice device);
|
||||||
void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor);
|
void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor);
|
||||||
|
@ -93,6 +97,7 @@ bool spiTransfer(SPI_TypeDef *instance, uint8_t *rxData, const uint8_t *txData,
|
||||||
uint16_t spiGetErrorCounter(SPI_TypeDef *instance);
|
uint16_t spiGetErrorCounter(SPI_TypeDef *instance);
|
||||||
void spiResetErrorCounter(SPI_TypeDef *instance);
|
void spiResetErrorCounter(SPI_TypeDef *instance);
|
||||||
SPIDevice spiDeviceByInstance(SPI_TypeDef *instance);
|
SPIDevice spiDeviceByInstance(SPI_TypeDef *instance);
|
||||||
|
SPI_TypeDef *spiInstanceByDevice(SPIDevice device);
|
||||||
|
|
||||||
bool spiBusTransfer(const busDevice_t *bus, uint8_t *rxData, const uint8_t *txData, int length);
|
bool spiBusTransfer(const busDevice_t *bus, uint8_t *rxData, const uint8_t *txData, int length);
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,15 @@ SPI_HandleTypeDef* spiHandleByInstance(SPI_TypeDef *instance)
|
||||||
return &spiDevice[spiDeviceByInstance(instance)].hspi;
|
return &spiDevice[spiDeviceByInstance(instance)].hspi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPI_TypeDef *spiInstanceByDevice(SPIDevice device)
|
||||||
|
{
|
||||||
|
if (device >= SPIDEV_COUNT) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return spiDevice[device].dev;
|
||||||
|
}
|
||||||
|
|
||||||
DMA_HandleTypeDef* dmaHandleByInstance(SPI_TypeDef *instance)
|
DMA_HandleTypeDef* dmaHandleByInstance(SPI_TypeDef *instance)
|
||||||
{
|
{
|
||||||
return &spiDevice[spiDeviceByInstance(instance)].hdma;
|
return &spiDevice[spiDeviceByInstance(instance)].hdma;
|
||||||
|
|
|
@ -2983,6 +2983,9 @@ const cliResourceValue_t resourceTable[] = {
|
||||||
#ifdef USE_ESCSERIAL
|
#ifdef USE_ESCSERIAL
|
||||||
{ OWNER_ESCSERIAL, PG_ESCSERIAL_CONFIG, offsetof(escSerialConfig_t, ioTag), 0 },
|
{ OWNER_ESCSERIAL, PG_ESCSERIAL_CONFIG, offsetof(escSerialConfig_t, ioTag), 0 },
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef BARO
|
||||||
|
{ OWNER_BARO_CS, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_spi_cs), 0 },
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static ioTag_t *getIoTag(const cliResourceValue_t value, uint8_t index)
|
static ioTag_t *getIoTag(const cliResourceValue_t value, uint8_t index)
|
||||||
|
|
|
@ -255,6 +255,10 @@ static const char * const lookupTableFailsafe[] = {
|
||||||
"AUTO-LAND", "DROP"
|
"AUTO-LAND", "DROP"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char * const lookupTableBusType[] = {
|
||||||
|
"NONE", "I2C", "SPI"
|
||||||
|
};
|
||||||
|
|
||||||
const lookupTableEntry_t lookupTables[] = {
|
const lookupTableEntry_t lookupTables[] = {
|
||||||
{ lookupTableOffOn, sizeof(lookupTableOffOn) / sizeof(char *) },
|
{ lookupTableOffOn, sizeof(lookupTableOffOn) / sizeof(char *) },
|
||||||
{ lookupTableUnit, sizeof(lookupTableUnit) / sizeof(char *) },
|
{ lookupTableUnit, sizeof(lookupTableUnit) / sizeof(char *) },
|
||||||
|
@ -297,6 +301,7 @@ const lookupTableEntry_t lookupTables[] = {
|
||||||
#ifdef OSD
|
#ifdef OSD
|
||||||
{ lookupTableOsdType, sizeof(lookupTableOsdType) / sizeof(char *) },
|
{ lookupTableOsdType, sizeof(lookupTableOsdType) / sizeof(char *) },
|
||||||
#endif
|
#endif
|
||||||
|
{ lookupTableBusType, sizeof(lookupTableBusType) / sizeof(char *) },
|
||||||
};
|
};
|
||||||
|
|
||||||
const clivalue_t valueTable[] = {
|
const clivalue_t valueTable[] = {
|
||||||
|
@ -342,6 +347,11 @@ const clivalue_t valueTable[] = {
|
||||||
|
|
||||||
// PG_BAROMETER_CONFIG
|
// PG_BAROMETER_CONFIG
|
||||||
#ifdef BARO
|
#ifdef BARO
|
||||||
|
{ "baro_bustype", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BUS_TYPE }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_bustype) },
|
||||||
|
{ "baro_spi_device", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 5 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_spi_device) },
|
||||||
|
{ "baro_i2c_device", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 5 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_i2c_device) },
|
||||||
|
{ "baro_i2c_address", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2C_ADDR7_MAX }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_i2c_address) },
|
||||||
|
|
||||||
{ "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BARO_HARDWARE }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_hardware) },
|
{ "baro_hardware", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_BARO_HARDWARE }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_hardware) },
|
||||||
{ "baro_tab_size", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, BARO_SAMPLE_COUNT_MAX }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_sample_count) },
|
{ "baro_tab_size", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, BARO_SAMPLE_COUNT_MAX }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_sample_count) },
|
||||||
{ "baro_noise_lpf", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 1000 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_noise_lpf) },
|
{ "baro_noise_lpf", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, 1000 }, PG_BAROMETER_CONFIG, offsetof(barometerConfig_t, baro_noise_lpf) },
|
||||||
|
@ -734,7 +744,7 @@ const clivalue_t valueTable[] = {
|
||||||
{ "led_inversion", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, ((1 << STATUS_LED_NUMBER) - 1) }, PG_STATUS_LED_CONFIG, offsetof(statusLedConfig_t, inversion) },
|
{ "led_inversion", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, ((1 << STATUS_LED_NUMBER) - 1) }, PG_STATUS_LED_CONFIG, offsetof(statusLedConfig_t, inversion) },
|
||||||
#ifdef USE_DASHBOARD
|
#ifdef USE_DASHBOARD
|
||||||
{ "dashboard_i2c_bus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_DASHBOARD_CONFIG, offsetof(dashboardConfig_t, device) },
|
{ "dashboard_i2c_bus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_DASHBOARD_CONFIG, offsetof(dashboardConfig_t, device) },
|
||||||
{ "dashboard_i2c_addr", VAR_UINT8 | MASTER_VALUE, .config.minmax = { I2C_ADDR8_MIN, I2C_ADDR8_MAX }, PG_DASHBOARD_CONFIG, offsetof(dashboardConfig_t, address) },
|
{ "dashboard_i2c_addr", VAR_UINT8 | MASTER_VALUE, .config.minmax = { I2C_ADDR7_MIN, I2C_ADDR7_MAX }, PG_DASHBOARD_CONFIG, offsetof(dashboardConfig_t, address) },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ typedef enum {
|
||||||
#ifdef OSD
|
#ifdef OSD
|
||||||
TABLE_OSD,
|
TABLE_OSD,
|
||||||
#endif
|
#endif
|
||||||
|
TABLE_BUS_TYPE,
|
||||||
LOOKUP_TABLE_COUNT
|
LOOKUP_TABLE_COUNT
|
||||||
} lookupTableIndex_e;
|
} lookupTableIndex_e;
|
||||||
|
|
||||||
|
|
|
@ -48,15 +48,61 @@
|
||||||
|
|
||||||
baro_t baro; // barometer access functions
|
baro_t baro; // barometer access functions
|
||||||
|
|
||||||
PG_REGISTER_WITH_RESET_TEMPLATE(barometerConfig_t, barometerConfig, PG_BAROMETER_CONFIG, 0);
|
PG_REGISTER_WITH_RESET_FN(barometerConfig_t, barometerConfig, PG_BAROMETER_CONFIG, 0);
|
||||||
|
|
||||||
PG_RESET_TEMPLATE(barometerConfig_t, barometerConfig,
|
void pgResetFn_barometerConfig(barometerConfig_t *barometerConfig)
|
||||||
.baro_hardware = 1,
|
{
|
||||||
.baro_sample_count = 21,
|
barometerConfig->baro_sample_count = 21;
|
||||||
.baro_noise_lpf = 600,
|
barometerConfig->baro_noise_lpf = 600;
|
||||||
.baro_cf_vel = 985,
|
barometerConfig->baro_cf_vel = 985;
|
||||||
.baro_cf_alt = 965
|
barometerConfig->baro_cf_alt = 965;
|
||||||
);
|
|
||||||
|
#ifdef USE_BARO_BMP085
|
||||||
|
barometerConfig->baro_hardware = BARO_BMP085;
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_I2C;
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(BARO_I2C_INSTANCE);
|
||||||
|
barometerConfig->baro_i2c_address = BMP085_I2C_ADDR;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(SPIINVALID);
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG_NONE;
|
||||||
|
#elif defined(USE_BARO_MS5611) || defined(USE_BARO_SPI_MS5611)
|
||||||
|
barometerConfig->baro_hardware = BARO_MS5611;
|
||||||
|
#if defined(USE_BARO_SPI_MS5611)
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_SPI;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(spiDeviceByInstance(MS5611_SPI_INSTANCE));
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG(MS5611_CS_PIN);
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(I2CINVALID);
|
||||||
|
barometerConfig->baro_i2c_address = 0;
|
||||||
|
#else
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_I2C;
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(BARO_I2C_INSTANCE);
|
||||||
|
barometerConfig->baro_i2c_address = MS5611_I2C_ADDR;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(SPIINVALID);
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG_NONE;
|
||||||
|
#endif
|
||||||
|
#elif defined(USE_BARO_BMP280) || defined(USE_BARO_SPI_BMP280)
|
||||||
|
barometerConfig->baro_hardware = BARO_BMP280;
|
||||||
|
#if defined(USE_BARO_SPI_BMP280)
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_SPI;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(spiDeviceByInstance(BMP280_SPI_INSTANCE));
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG(BMP280_CS_PIN);
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(I2CINVALID);
|
||||||
|
barometerConfig->baro_i2c_address = 0;
|
||||||
|
#else
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_I2C;
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(BARO_I2C_INSTANCE);
|
||||||
|
barometerConfig->baro_i2c_address = BMP280_I2C_ADDR;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(SPIINVALID);
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG_NONE;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
barometerConfig->baro_hardware = BARO_NONE;
|
||||||
|
barometerConfig->baro_bustype = BUSTYPE_NONE;
|
||||||
|
barometerConfig->baro_i2c_device = I2C_DEV_TO_CFG(I2CINVALID);
|
||||||
|
barometerConfig->baro_i2c_address = 0;
|
||||||
|
barometerConfig->baro_spi_device = SPI_DEV_TO_CFG(SPIINVALID);
|
||||||
|
barometerConfig->baro_spi_cs = IO_TAG_NONE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef BARO
|
#ifdef BARO
|
||||||
|
|
||||||
|
@ -78,6 +124,12 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
||||||
UNUSED(dev);
|
UNUSED(dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
dev->busdev.bustype = barometerConfig()->baro_bustype;
|
||||||
|
dev->busdev.busdev_u.i2c.device = I2C_CFG_TO_DEV(barometerConfig()->baro_i2c_device);
|
||||||
|
dev->busdev.busdev_u.i2c.address = barometerConfig()->baro_i2c_address;
|
||||||
|
spiBusSetInstance(&dev->busdev, spiInstanceByDevice(SPI_CFG_TO_DEV(barometerConfig()->baro_spi_device)));
|
||||||
|
dev->busdev.busdev_u.spi.csnPin = IOGetByTag(barometerConfig()->baro_spi_cs);
|
||||||
|
|
||||||
#ifdef USE_BARO_BMP085
|
#ifdef USE_BARO_BMP085
|
||||||
const bmp085Config_t *bmp085Config = NULL;
|
const bmp085Config_t *bmp085Config = NULL;
|
||||||
|
|
||||||
|
@ -96,10 +148,6 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
||||||
; // fallthough
|
; // fallthough
|
||||||
case BARO_BMP085:
|
case BARO_BMP085:
|
||||||
#ifdef USE_BARO_BMP085
|
#ifdef USE_BARO_BMP085
|
||||||
dev->busdev.bustype = BUSTYPE_I2C;
|
|
||||||
dev->busdev.busdev_u.i2c.device = BARO_I2C_INSTANCE;
|
|
||||||
dev->busdev.busdev_u.i2c.address = BMP085_I2C_ADDR;
|
|
||||||
|
|
||||||
if (bmp085Detect(bmp085Config, dev)) {
|
if (bmp085Detect(bmp085Config, dev)) {
|
||||||
baroHardware = BARO_BMP085;
|
baroHardware = BARO_BMP085;
|
||||||
break;
|
break;
|
||||||
|
@ -109,15 +157,6 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
||||||
|
|
||||||
case BARO_MS5611:
|
case BARO_MS5611:
|
||||||
#if defined(USE_BARO_MS5611) || defined(USE_BARO_SPI_MS5611)
|
#if defined(USE_BARO_MS5611) || defined(USE_BARO_SPI_MS5611)
|
||||||
#if defined(USE_BARO_SPI_MS5611)
|
|
||||||
dev->busdev.bustype = BUSTYPE_SPI;
|
|
||||||
spiBusSetInstance(&dev->busdev, MS5611_SPI_INSTANCE);
|
|
||||||
dev->busdev.busdev_u.spi.csnPin = IOGetByTag(IO_TAG(MS5611_CS_PIN));
|
|
||||||
#elif defined(USE_BARO_MS5611)
|
|
||||||
dev->busdev.bustype = BUSTYPE_I2C;
|
|
||||||
dev->busdev.busdev_u.i2c.device = BARO_I2C_INSTANCE;
|
|
||||||
dev->busdev.busdev_u.i2c.address = MS5611_I2C_ADDR;
|
|
||||||
#endif
|
|
||||||
if (ms5611Detect(dev)) {
|
if (ms5611Detect(dev)) {
|
||||||
baroHardware = BARO_MS5611;
|
baroHardware = BARO_MS5611;
|
||||||
break;
|
break;
|
||||||
|
@ -127,18 +166,6 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
||||||
|
|
||||||
case BARO_BMP280:
|
case BARO_BMP280:
|
||||||
#if defined(USE_BARO_BMP280) || defined(USE_BARO_SPI_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;
|
|
||||||
spiBusSetInstance(&dev->busdev, 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)) {
|
if (bmp280Detect(dev)) {
|
||||||
baroHardware = BARO_BMP280;
|
baroHardware = BARO_BMP280;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -31,6 +31,11 @@ typedef enum {
|
||||||
#define BARO_SAMPLE_COUNT_MAX 48
|
#define BARO_SAMPLE_COUNT_MAX 48
|
||||||
|
|
||||||
typedef struct barometerConfig_s {
|
typedef struct barometerConfig_s {
|
||||||
|
uint8_t baro_bustype;
|
||||||
|
uint8_t baro_spi_device;
|
||||||
|
ioTag_t baro_spi_cs;
|
||||||
|
uint8_t baro_i2c_device;
|
||||||
|
uint8_t baro_i2c_address;
|
||||||
uint8_t baro_hardware; // Barometer hardware to use
|
uint8_t baro_hardware; // Barometer hardware to use
|
||||||
uint8_t baro_sample_count; // size of baro filter array
|
uint8_t baro_sample_count; // size of baro filter array
|
||||||
uint16_t baro_noise_lpf; // additional LPF to reduce baro noise
|
uint16_t baro_noise_lpf; // additional LPF to reduce baro noise
|
||||||
|
|
Loading…
Reference in New Issue