mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
Protect mag and baro against NULL instance
This commit is contained in:
parent
2a748e73d0
commit
9c45eee0e6
2 changed files with 27 additions and 13 deletions
|
@ -157,21 +157,28 @@ bool baroDetect(baroDev_t *dev, baroSensor_e baroHardwareToUse)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (barometerConfig()->baro_bustype) {
|
switch (barometerConfig()->baro_bustype) {
|
||||||
case BUSTYPE_I2C:
|
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
|
case BUSTYPE_I2C:
|
||||||
dev->busdev.bustype = BUSTYPE_I2C;
|
dev->busdev.bustype = BUSTYPE_I2C;
|
||||||
dev->busdev.busdev_u.i2c.device = I2C_CFG_TO_DEV(barometerConfig()->baro_i2c_device);
|
dev->busdev.busdev_u.i2c.device = I2C_CFG_TO_DEV(barometerConfig()->baro_i2c_device);
|
||||||
dev->busdev.busdev_u.i2c.address = barometerConfig()->baro_i2c_address;
|
dev->busdev.busdev_u.i2c.address = barometerConfig()->baro_i2c_address;
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case BUSTYPE_SPI:
|
|
||||||
#ifdef USE_SPI
|
#ifdef USE_SPI
|
||||||
dev->busdev.bustype = BUSTYPE_SPI;
|
case BUSTYPE_SPI:
|
||||||
spiBusSetInstance(&dev->busdev, spiInstanceByDevice(SPI_CFG_TO_DEV(barometerConfig()->baro_spi_device)));
|
{
|
||||||
dev->busdev.busdev_u.spi.csnPin = IOGetByTag(barometerConfig()->baro_spi_csn);
|
SPI_TypeDef *instance = spiInstanceByDevice(SPI_CFG_TO_DEV(barometerConfig()->baro_spi_device));
|
||||||
#endif
|
if (!instance) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->busdev.bustype = BUSTYPE_SPI;
|
||||||
|
spiBusSetInstance(&dev->busdev, instance);
|
||||||
|
dev->busdev.busdev_u.spi.csnPin = IOGetByTag(barometerConfig()->baro_spi_csn);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -133,16 +133,23 @@ bool compassDetect(magDev_t *dev)
|
||||||
busdev->bustype = BUSTYPE_I2C;
|
busdev->bustype = BUSTYPE_I2C;
|
||||||
busdev->busdev_u.i2c.device = I2C_CFG_TO_DEV(compassConfig()->mag_i2c_device);
|
busdev->busdev_u.i2c.device = I2C_CFG_TO_DEV(compassConfig()->mag_i2c_device);
|
||||||
busdev->busdev_u.i2c.address = compassConfig()->mag_i2c_address;
|
busdev->busdev_u.i2c.address = compassConfig()->mag_i2c_address;
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SPI
|
#ifdef USE_SPI
|
||||||
case BUSTYPE_SPI:
|
case BUSTYPE_SPI:
|
||||||
busdev->bustype = BUSTYPE_SPI;
|
{
|
||||||
spiBusSetInstance(busdev, spiInstanceByDevice(SPI_CFG_TO_DEV(compassConfig()->mag_spi_device)));
|
SPI_TypeDef *instance = spiInstanceByDevice(SPI_CFG_TO_DEV(compassConfig()->mag_spi_device));
|
||||||
busdev->busdev_u.spi.csnPin = IOGetByTag(compassConfig()->mag_spi_csn);
|
if (!instance) {
|
||||||
#endif
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
busdev->bustype = BUSTYPE_SPI;
|
||||||
|
spiBusSetInstance(busdev, instance);
|
||||||
|
busdev->busdev_u.spi.csnPin = IOGetByTag(compassConfig()->mag_spi_csn);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USE_MAG_AK8963) && (defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250))
|
#if defined(USE_MAG_AK8963) && (defined(USE_GYRO_SPI_MPU6500) || defined(USE_GYRO_SPI_MPU9250))
|
||||||
case BUSTYPE_MPU_SLAVE:
|
case BUSTYPE_MPU_SLAVE:
|
||||||
|
@ -155,8 +162,8 @@ bool compassDetect(magDev_t *dev)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue