Handle NULL SPI instance case

This commit is contained in:
jflyper 2018-09-16 03:09:45 +09:00
parent 9cec06dfc5
commit 4193890b27
5 changed files with 17 additions and 3 deletions

View File

@ -228,6 +228,12 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro, const gyro
gyro->bus.bustype = BUSTYPE_SPI; gyro->bus.bustype = BUSTYPE_SPI;
spiBusSetInstance(&gyro->bus, spiInstanceByDevice(SPI_CFG_TO_DEV(config->spiBus))); spiBusSetInstance(&gyro->bus, spiInstanceByDevice(SPI_CFG_TO_DEV(config->spiBus)));
// SPI instance may be NULL if the bus is non-existent
if (!gyro->bus.busdev_u.spi.instance) {
return false;
}
gyro->bus.busdev_u.spi.csnPin = IOGetByTag(config->csnTag); gyro->bus.busdev_u.spi.csnPin = IOGetByTag(config->csnTag);
IOInit(gyro->bus.busdev_u.spi.csnPin, OWNER_GYRO_CS, RESOURCE_INDEX(config->index)); IOInit(gyro->bus.busdev_u.spi.csnPin, OWNER_GYRO_CS, RESOURCE_INDEX(config->index));
IOConfigGPIO(gyro->bus.busdev_u.spi.csnPin, SPI_IO_CS_CFG); IOConfigGPIO(gyro->bus.busdev_u.spi.csnPin, SPI_IO_CS_CFG);

View File

@ -62,7 +62,7 @@ SPIDevice spiDeviceByInstance(SPI_TypeDef *instance)
SPI_TypeDef *spiInstanceByDevice(SPIDevice device) SPI_TypeDef *spiInstanceByDevice(SPIDevice device)
{ {
if (device >= SPIDEV_COUNT) { if (device == SPIINVALID || device >= SPIDEV_COUNT) {
return NULL; return NULL;
} }

View File

@ -76,6 +76,10 @@ void spiInitDevice(SPIDevice device)
{ {
spiDevice_t *spi = &(spiDevice[device]); spiDevice_t *spi = &(spiDevice[device]);
if (!spi->dev) {
return;
}
#ifdef SDCARD_SPI_INSTANCE #ifdef SDCARD_SPI_INSTANCE
if (spi->dev == SDCARD_SPI_INSTANCE) { if (spi->dev == SDCARD_SPI_INSTANCE) {
spi->leadingEdge = true; spi->leadingEdge = true;

View File

@ -37,6 +37,10 @@ void spiInitDevice(SPIDevice device)
{ {
spiDevice_t *spi = &(spiDevice[device]); spiDevice_t *spi = &(spiDevice[device]);
if (!spi->dev) {
return;
}
#ifdef SDCARD_SPI_INSTANCE #ifdef SDCARD_SPI_INSTANCE
if (spi->dev == SDCARD_SPI_INSTANCE) { if (spi->dev == SDCARD_SPI_INSTANCE) {
spi->leadingEdge = true; spi->leadingEdge = true;

View File

@ -45,13 +45,13 @@
#define USE_GYRO_SPI_MPU6500 #define USE_GYRO_SPI_MPU6500
// Other USE_ACCs and USE_GYROs should follow // Other USE_ACCs and USE_GYROs should follow
#define GYRO_1_SPI_INSTANCE SPI1 #define GYRO_1_SPI_INSTANCE NULL
#define GYRO_1_CS_PIN NONE #define GYRO_1_CS_PIN NONE
#define GYRO_1_ALIGN ALIGN_DEFAULT #define GYRO_1_ALIGN ALIGN_DEFAULT
#define ACC_1_ALIGN ALIGN_DEFAULT #define ACC_1_ALIGN ALIGN_DEFAULT
#define GYRO_1_EXTI_PIN PB15 // XXX Should be gone #define GYRO_1_EXTI_PIN PB15 // XXX Should be gone
#define GYRO_2_SPI_INSTANCE SPI1 #define GYRO_2_SPI_INSTANCE NULL
#define GYRO_2_CS_PIN NONE #define GYRO_2_CS_PIN NONE
#define GYRO_2_ALIGN ALIGN_DEFAULT #define GYRO_2_ALIGN ALIGN_DEFAULT
#define ACC_2_ALIGN ALIGN_DEFAULT #define ACC_2_ALIGN ALIGN_DEFAULT