1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +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;
}
bool spiInit(SPIDevice device)
bool spiInit(SPIDevice device, bool leadingEdge)
{
switch (device) {
case SPIINVALID:
@ -77,7 +77,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_1:
#ifdef USE_SPI_DEVICE_1
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;
@ -85,7 +85,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_2:
#ifdef USE_SPI_DEVICE_2
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;
@ -93,7 +93,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_3:
#if defined(USE_SPI_DEVICE_3) && !defined(STM32F1)
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;
@ -101,7 +101,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_4:
#if defined(USE_SPI_DEVICE_4)
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;
@ -109,7 +109,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_5:
#if defined(USE_SPI_DEVICE_5)
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;
@ -117,7 +117,7 @@ bool spiInit(SPIDevice device)
case SPIDEV_6:
#if defined(USE_SPI_DEVICE_6)
spiInitDevice(device);
spiInitDevice(device, leadingEdge);
return true;
#else
break;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -44,7 +44,7 @@ static SPI_InitTypeDef defaultInit = {
.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
};
void spiInitDevice(SPIDevice device)
void spiInitDevice(SPIDevice device, bool leadingEdge)
{
spiDevice_t *spi = &(spiDevice[device]);
@ -53,16 +53,9 @@ void spiInitDevice(SPIDevice device)
}
#ifndef USE_SPI_TRANSACTION
#ifdef SDCARD_SPI_INSTANCE
if (spi->dev == SDCARD_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
#ifdef RX_SPI_INSTANCE
if (spi->dev == RX_SPI_INSTANCE) {
spi->leadingEdge = true;
}
#endif
spi->leadingEdge = leadingEdge;
#else
UNUSED(leadingEdge);
#endif
// 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)
{
spiDeviceByInstance(RX_SPI_INSTANCE);
rxIntIO = extiPin; /* config receiver IRQ pin */
IOInit(rxIntIO, OWNER_RX_SPI_EXTI, 0);
EXTIHandlerInit(&a7105extiCallbackRec, a7105extiHandler);

View file

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

View file

@ -208,6 +208,41 @@ static IO_t busSwitchResetPin = IO_NONE;
}
#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)
{
#ifdef USE_SPI
@ -220,22 +255,22 @@ static void configureSPIAndQuadSPI(void)
spiPreinit();
#ifdef USE_SPI_DEVICE_1
spiInit(SPIDEV_1);
spiInit(SPIDEV_1, requiresSpiLeadingEdge(SPIDEV_1));
#endif
#ifdef USE_SPI_DEVICE_2
spiInit(SPIDEV_2);
spiInit(SPIDEV_2, requiresSpiLeadingEdge(SPIDEV_2));
#endif
#ifdef USE_SPI_DEVICE_3
spiInit(SPIDEV_3);
spiInit(SPIDEV_3, requiresSpiLeadingEdge(SPIDEV_3));
#endif
#ifdef USE_SPI_DEVICE_4
spiInit(SPIDEV_4);
spiInit(SPIDEV_4, requiresSpiLeadingEdge(SPIDEV_4));
#endif
#ifdef USE_SPI_DEVICE_5
spiInit(SPIDEV_5);
spiInit(SPIDEV_5, requiresSpiLeadingEdge(SPIDEV_5));
#endif
#ifdef USE_SPI_DEVICE_6
spiInit(SPIDEV_6);
spiInit(SPIDEV_6, requiresSpiLeadingEdge(SPIDEV_6));
#endif
#endif // USE_SPI
@ -248,12 +283,13 @@ static void configureSPIAndQuadSPI(void)
#endif // USE_QUAD_SPI
}
#ifdef USE_SDCARD
void sdCardAndFSInit()
{
sdcard_init(sdcardConfig());
afatfs_init();
}
#endif
void init(void)
{