1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 21:35:44 +03:00

Merge pull request #4234 from jflyper/bfdev-max7456-preinit-output-hi

Preinit for MAX7456 on Kakute F4 requires output hi.
This commit is contained in:
Martin Budden 2017-09-26 11:39:50 +01:00 committed by GitHub
commit 793ed1a7f3
3 changed files with 21 additions and 2 deletions

View file

@ -87,6 +87,8 @@ typedef enum SPIDevice {
#define SPI_DEV_TO_CFG(x) ((x) + 1) #define SPI_DEV_TO_CFG(x) ((x) + 1)
void spiPreInitCs(ioTag_t iotag); void spiPreInitCs(ioTag_t iotag);
void spiPreInitCsOutPU(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);
uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t data); uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t data);

View file

@ -25,7 +25,14 @@
// Bring a pin for possible CS line to pull-up state in preparation for // Bring a pin for possible CS line to pull-up state in preparation for
// sequential initialization by relevant drivers. // sequential initialization by relevant drivers.
// Note that the pin is set to input for safety at this point.
// There are two versions:
// spiPreInitCs set the pin to input with pullup (IOCFG_IPU) for safety at this point.
// spiPreInitCsOutPU which actually drive the pin for digital hi.
//
// The later is required for SPI slave devices on some targets, interfaced through level shifters, such as Kakute F4.
// Note that with this handling, a pin declared as CS pin for MAX7456 needs special care when re-purposing the pin for other, especially, input uses.
// This will/should be fixed when we go fully reconfigurable.
void spiPreInitCs(ioTag_t iotag) void spiPreInitCs(ioTag_t iotag)
{ {
@ -35,3 +42,13 @@ void spiPreInitCs(ioTag_t iotag)
IOConfigGPIO(io, IOCFG_IPU); IOConfigGPIO(io, IOCFG_IPU);
} }
} }
void spiPreInitCsOutPU(ioTag_t iotag)
{
IO_t io = IOGetByTag(iotag);
if (io) {
IOInit(io, OWNER_SPI_PREINIT, 0);
IOConfigGPIO(io, IOCFG_OUT_PP);
IOHi(io);
}
}

View file

@ -213,7 +213,7 @@ void spiPreInit(void)
spiPreInitCs(IO_TAG(L3GD20_CS_PIN)); spiPreInitCs(IO_TAG(L3GD20_CS_PIN));
#endif #endif
#ifdef USE_MAX7456 #ifdef USE_MAX7456
spiPreInitCs(IO_TAG(MAX7456_SPI_CS_PIN)); spiPreInitCsOutPU(IO_TAG(MAX7456_SPI_CS_PIN)); // XXX 3.2 workaround for Kakute F4. See comment for spiPreInitCSOutPU.
#endif #endif
#ifdef USE_SDCARD #ifdef USE_SDCARD
spiPreInitCs(IO_TAG(SDCARD_SPI_CS_PIN)); spiPreInitCs(IO_TAG(SDCARD_SPI_CS_PIN));