1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 04:45:24 +03:00

Fixed handling of SPI parameters for Unified Targets. (#9218)

Fixed handling of SPI parameters for Unified Targets.
This commit is contained in:
Michael Keller 2019-11-25 18:47:02 +13:00 committed by mikeller
parent 78befad3b8
commit e28cf4323b
10 changed files with 63 additions and 52 deletions

View file

@ -69,7 +69,7 @@ SPI_TypeDef *spiInstanceByDevice(SPIDevice device)
return spiDevice[device].dev; return spiDevice[device].dev;
} }
bool spiInit(SPIDevice device) bool spiInit(SPIDevice device, bool leadingEdge)
{ {
switch (device) { switch (device) {
case SPIINVALID: case SPIINVALID:
@ -77,7 +77,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_1: case SPIDEV_1:
#ifdef USE_SPI_DEVICE_1 #ifdef USE_SPI_DEVICE_1
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;
@ -85,7 +85,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_2: case SPIDEV_2:
#ifdef USE_SPI_DEVICE_2 #ifdef USE_SPI_DEVICE_2
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;
@ -93,7 +93,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_3: case SPIDEV_3:
#if defined(USE_SPI_DEVICE_3) && !defined(STM32F1) #if defined(USE_SPI_DEVICE_3) && !defined(STM32F1)
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;
@ -101,7 +101,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_4: case SPIDEV_4:
#if defined(USE_SPI_DEVICE_4) #if defined(USE_SPI_DEVICE_4)
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;
@ -109,7 +109,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_5: case SPIDEV_5:
#if defined(USE_SPI_DEVICE_5) #if defined(USE_SPI_DEVICE_5)
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;
@ -117,7 +117,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_6: case SPIDEV_6:
#if defined(USE_SPI_DEVICE_6) #if defined(USE_SPI_DEVICE_6)
spiInitDevice(device); spiInitDevice(device, leadingEdge);
return true; return true;
#else #else
break; break;

View file

@ -122,7 +122,7 @@ void spiPreinitRegister(ioTag_t iotag, uint8_t iocfg, uint8_t init);
void spiPreinitByIO(IO_t io); void spiPreinitByIO(IO_t io);
void spiPreinitByTag(ioTag_t tag); void spiPreinitByTag(ioTag_t tag);
bool spiInit(SPIDevice device); bool spiInit(SPIDevice device, bool leadingEdge);
void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor); void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor);
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t data); uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t data);
bool spiIsBusBusy(SPI_TypeDef *instance); bool spiIsBusBusy(SPI_TypeDef *instance);

View file

@ -91,7 +91,7 @@ void spiPreinit(void)
flashPreInit(flashConfig()); flashPreInit(flashConfig());
#endif #endif
#if defined(USE_RX_SPI) && !defined(USE_RX_SOFTSPI) #if defined(USE_RX_SPI)
rxSpiDevicePreInit(rxSpiConfig()); rxSpiDevicePreInit(rxSpiConfig());
#endif #endif

View file

@ -36,7 +36,7 @@
#include "nvic.h" #include "nvic.h"
#include "rcc.h" #include "rcc.h"
void spiInitDevice(SPIDevice device) void spiInitDevice(SPIDevice device, bool leadingEdge)
{ {
spiDevice_t *spi = &(spiDevice[device]); spiDevice_t *spi = &(spiDevice[device]);
@ -44,16 +44,7 @@ void spiInitDevice(SPIDevice device)
return; return;
} }
#ifdef SDCARD_SPI_INSTANCE spi->leadingEdge = leadingEdge;
if (spi->dev == SDCARD_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
#ifdef RX_SPI_INSTANCE
if (spi->dev == RX_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
// Enable SPI clock // Enable SPI clock
RCC_ClockCmd(spi->rcc, ENABLE); RCC_ClockCmd(spi->rcc, ENABLE);

View file

@ -83,5 +83,5 @@ typedef struct SPIDevice_s {
extern spiDevice_t spiDevice[SPIDEV_COUNT]; extern spiDevice_t spiDevice[SPIDEV_COUNT];
void spiInitDevice(SPIDevice device); void spiInitDevice(SPIDevice device, bool leadingEdge);
uint32_t spiTimeoutUserCallback(SPI_TypeDef *instance); uint32_t spiTimeoutUserCallback(SPI_TypeDef *instance);

View file

@ -85,7 +85,7 @@ static LL_SPI_InitTypeDef defaultInit =
.CRCCalculation = SPI_CRCCALCULATION_DISABLE, .CRCCalculation = SPI_CRCCALCULATION_DISABLE,
}; };
void spiInitDevice(SPIDevice device) void spiInitDevice(SPIDevice device, bool leadingEdge)
{ {
spiDevice_t *spi = &(spiDevice[device]); spiDevice_t *spi = &(spiDevice[device]);
@ -94,16 +94,9 @@ void spiInitDevice(SPIDevice device)
} }
#ifndef USE_SPI_TRANSACTION #ifndef USE_SPI_TRANSACTION
#ifdef SDCARD_SPI_INSTANCE spi->leadingEdge = leadingEdge;
if (spi->dev == SDCARD_SPI_INSTANCE) { #else
spi->leadingEdge = true; UNUSED(leadingEdge);
}
#endif
#ifdef RX_SPI_INSTANCE
if (spi->dev == RX_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
#endif #endif
// Enable SPI clock // Enable SPI clock

View file

@ -44,7 +44,7 @@ static SPI_InitTypeDef defaultInit = {
.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8, .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
}; };
void spiInitDevice(SPIDevice device) void spiInitDevice(SPIDevice device, bool leadingEdge)
{ {
spiDevice_t *spi = &(spiDevice[device]); spiDevice_t *spi = &(spiDevice[device]);
@ -53,16 +53,9 @@ void spiInitDevice(SPIDevice device)
} }
#ifndef USE_SPI_TRANSACTION #ifndef USE_SPI_TRANSACTION
#ifdef SDCARD_SPI_INSTANCE spi->leadingEdge = leadingEdge;
if (spi->dev == SDCARD_SPI_INSTANCE) { #else
spi->leadingEdge = true; UNUSED(leadingEdge);
}
#endif
#ifdef RX_SPI_INSTANCE
if (spi->dev == RX_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
#endif #endif
// Enable SPI clock // Enable SPI clock

View file

@ -54,7 +54,6 @@ void a7105extiHandler(extiCallbackRec_t* cb)
void A7105Init(uint32_t id, IO_t extiPin, IO_t txEnPin) void A7105Init(uint32_t id, IO_t extiPin, IO_t txEnPin)
{ {
spiDeviceByInstance(RX_SPI_INSTANCE);
rxIntIO = extiPin; /* config receiver IRQ pin */ rxIntIO = extiPin; /* config receiver IRQ pin */
IOInit(rxIntIO, OWNER_RX_SPI_EXTI, 0); IOInit(rxIntIO, OWNER_RX_SPI_EXTI, 0);
EXTIHandlerInit(&a7105extiCallbackRec, a7105extiHandler); EXTIHandlerInit(&a7105extiCallbackRec, a7105extiHandler);

View file

@ -71,7 +71,6 @@ bool cyrf6936RxFinished(uint32_t *timeStamp)
bool cyrf6936Init(IO_t extiPin) bool cyrf6936Init(IO_t extiPin)
{ {
spiDeviceByInstance(RX_SPI_INSTANCE);
rxIntIO = extiPin; rxIntIO = extiPin;
IOInit(rxIntIO, OWNER_RX_SPI_EXTI, 0); IOInit(rxIntIO, OWNER_RX_SPI_EXTI, 0);
EXTIHandlerInit(&cyrf6936extiCallbackRec, cyrf6936ExtiHandler); EXTIHandlerInit(&cyrf6936extiCallbackRec, cyrf6936ExtiHandler);

View file

@ -208,6 +208,41 @@ static IO_t busSwitchResetPin = IO_NONE;
} }
#endif #endif
bool requiresSpiLeadingEdge(SPIDevice device)
{
#if defined(CONFIG_IN_SDCARD) || defined(CONFIG_IN_EXTERNAL_FLASH)
#if !defined(SDCARD_SPI_INSTANCE) && !defined(RX_SPI_INSTANCE)
UNUSED(device);
#endif
#if defined(SDCARD_SPI_INSTANCE)
if (device == spiDeviceByInstance(SDCARD_SPI_INSTANCE)) {
return true;
}
#endif
#if defined(RX_SPI_INSTANCE)
if (device == spiDeviceByInstance(RX_SPI_INSTANCE)) {
return true;
}
#endif
#else
#if !defined(USE_SDCARD) && !defined(USE_RX_SPI)
UNUSED(device);
#endif
#if defined(USE_SDCARD)
if (device == SPI_CFG_TO_DEV(sdcardConfig()->device)) {
return true;
}
#endif
#if defined(USE_RX_SPI)
if (device == SPI_CFG_TO_DEV(rxSpiConfig()->spibus)) {
return true;
}
#endif
#endif // CONFIG_IN_SDCARD || CONFIG_IN_EXTERNAL_FLASH
return false;
}
static void configureSPIAndQuadSPI(void) static void configureSPIAndQuadSPI(void)
{ {
#ifdef USE_SPI #ifdef USE_SPI
@ -220,22 +255,22 @@ static void configureSPIAndQuadSPI(void)
spiPreinit(); spiPreinit();
#ifdef USE_SPI_DEVICE_1 #ifdef USE_SPI_DEVICE_1
spiInit(SPIDEV_1); spiInit(SPIDEV_1, requiresSpiLeadingEdge(SPIDEV_1));
#endif #endif
#ifdef USE_SPI_DEVICE_2 #ifdef USE_SPI_DEVICE_2
spiInit(SPIDEV_2); spiInit(SPIDEV_2, requiresSpiLeadingEdge(SPIDEV_2));
#endif #endif
#ifdef USE_SPI_DEVICE_3 #ifdef USE_SPI_DEVICE_3
spiInit(SPIDEV_3); spiInit(SPIDEV_3, requiresSpiLeadingEdge(SPIDEV_3));
#endif #endif
#ifdef USE_SPI_DEVICE_4 #ifdef USE_SPI_DEVICE_4
spiInit(SPIDEV_4); spiInit(SPIDEV_4, requiresSpiLeadingEdge(SPIDEV_4));
#endif #endif
#ifdef USE_SPI_DEVICE_5 #ifdef USE_SPI_DEVICE_5
spiInit(SPIDEV_5); spiInit(SPIDEV_5, requiresSpiLeadingEdge(SPIDEV_5));
#endif #endif
#ifdef USE_SPI_DEVICE_6 #ifdef USE_SPI_DEVICE_6
spiInit(SPIDEV_6); spiInit(SPIDEV_6, requiresSpiLeadingEdge(SPIDEV_6));
#endif #endif
#endif // USE_SPI #endif // USE_SPI
@ -248,12 +283,13 @@ static void configureSPIAndQuadSPI(void)
#endif // USE_QUAD_SPI #endif // USE_QUAD_SPI
} }
#ifdef USE_SDCARD
void sdCardAndFSInit() void sdCardAndFSInit()
{ {
sdcard_init(sdcardConfig()); sdcard_init(sdcardConfig());
afatfs_init(); afatfs_init();
} }
#endif
void init(void) void init(void)
{ {