mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
Drop software SPI RX support
This commit is contained in:
parent
8f1df0635f
commit
c60eecbff0
7 changed files with 6 additions and 170 deletions
|
@ -16,7 +16,6 @@ COMMON_SRC = \
|
||||||
drivers/bus_spi.c \
|
drivers/bus_spi.c \
|
||||||
drivers/bus_spi_config.c \
|
drivers/bus_spi_config.c \
|
||||||
drivers/bus_spi_pinconfig.c \
|
drivers/bus_spi_pinconfig.c \
|
||||||
drivers/bus_spi_soft.c \
|
|
||||||
drivers/buttons.c \
|
drivers/buttons.c \
|
||||||
drivers/display.c \
|
drivers/display.c \
|
||||||
drivers/exti.c \
|
drivers/exti.c \
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Cleanflight and Betaflight.
|
|
||||||
*
|
|
||||||
* Cleanflight and Betaflight are free software. You can redistribute
|
|
||||||
* this software and/or modify this software under the terms of the
|
|
||||||
* GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option)
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* Cleanflight and Betaflight are distributed in the hope that they
|
|
||||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this software.
|
|
||||||
*
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <platform.h>
|
|
||||||
|
|
||||||
#ifdef USE_SOFTSPI
|
|
||||||
|
|
||||||
#include "build/build_config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "drivers/io.h"
|
|
||||||
#include "io_impl.h"
|
|
||||||
#include "drivers/bus_spi.h"
|
|
||||||
#include "bus_spi_soft.h"
|
|
||||||
|
|
||||||
|
|
||||||
void softSpiInit(const softSPIDevice_t *dev)
|
|
||||||
{
|
|
||||||
// SCK as output
|
|
||||||
IOInit(IOGetByTag(dev->sckTag), OWNER_SPI_SCK, RESOURCE_INDEX(SOFT_SPIDEV_1) + 10);
|
|
||||||
#if defined(STM32F10X)
|
|
||||||
IOConfigGPIO(IOGetByTag(dev->sckTag), IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_50MHz));
|
|
||||||
#elif defined(STM32F3) || defined(STM32F4)
|
|
||||||
IOConfigGPIOAF(IOGetByTag(dev->sckTag), SPI_IO_AF_CFG, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// MOSI as output
|
|
||||||
IOInit(IOGetByTag(dev->mosiTag), OWNER_SPI_MOSI, RESOURCE_INDEX(SOFT_SPIDEV_1) + 10);
|
|
||||||
#if defined(STM32F10X)
|
|
||||||
IOConfigGPIO(IOGetByTag(dev->mosiTag), IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_50MHz));
|
|
||||||
#elif defined(STM32F3) || defined(STM32F4)
|
|
||||||
IOConfigGPIOAF(IOGetByTag(dev->mosiTag), SPI_IO_AF_CFG, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// MISO as input
|
|
||||||
IOInit(IOGetByTag(dev->misoTag), OWNER_SPI_MISO, RESOURCE_INDEX(SOFT_SPIDEV_1) + 10);
|
|
||||||
#if defined(STM32F10X)
|
|
||||||
IOConfigGPIO(IOGetByTag(dev->misoTag), IO_CONFIG(GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz));
|
|
||||||
#elif defined(STM32F3) || defined(STM32F4)
|
|
||||||
IOConfigGPIOAF(IOGetByTag(dev->misoTag), SPI_IO_AF_CFG, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NSS as output
|
|
||||||
if (dev->nssTag != IOTAG_NONE) {
|
|
||||||
IOInit(IOGetByTag(dev->nssTag), OWNER_SPI_CS, RESOURCE_INDEX(SOFT_SPIDEV_1) + 10);
|
|
||||||
#if defined(STM32F10X)
|
|
||||||
IOConfigGPIO(IOGetByTag(dev->nssTag), IO_CONFIG(GPIO_Mode_Out_PP, GPIO_Speed_50MHz));
|
|
||||||
#elif defined(STM32F3) || defined(STM32F4)
|
|
||||||
IOConfigGPIOAF(IOGetByTag(dev->nssTag), SPI_IO_AF_CFG, 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t softSpiTransferByte(const softSPIDevice_t *dev, uint8_t byte)
|
|
||||||
{
|
|
||||||
for (int ii = 0; ii < 8; ++ii) {
|
|
||||||
if (byte & 0x80) {
|
|
||||||
IOHi(IOGetByTag(dev->mosiTag));
|
|
||||||
} else {
|
|
||||||
IOLo(IOGetByTag(dev->mosiTag));
|
|
||||||
}
|
|
||||||
IOHi(IOGetByTag(dev->sckTag));
|
|
||||||
byte <<= 1;
|
|
||||||
if (IORead(IOGetByTag(dev->misoTag)) == 1) {
|
|
||||||
byte |= 1;
|
|
||||||
}
|
|
||||||
IOLo(IOGetByTag(dev->sckTag));
|
|
||||||
}
|
|
||||||
return byte;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Cleanflight and Betaflight.
|
|
||||||
*
|
|
||||||
* Cleanflight and Betaflight are free software. You can redistribute
|
|
||||||
* this software and/or modify this software under the terms of the
|
|
||||||
* GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, either version 3 of the License, or (at your option)
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* Cleanflight and Betaflight are distributed in the hope that they
|
|
||||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this software.
|
|
||||||
*
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "drivers/io_types.h"
|
|
||||||
|
|
||||||
typedef enum softSPIDevice {
|
|
||||||
SOFT_SPIDEV_1 = 0
|
|
||||||
} softSPIDevice_e;
|
|
||||||
|
|
||||||
typedef struct softSPIDevice_s {
|
|
||||||
ioTag_t sckTag;
|
|
||||||
ioTag_t mosiTag;
|
|
||||||
ioTag_t misoTag;
|
|
||||||
ioTag_t nssTag;
|
|
||||||
} softSPIDevice_t;
|
|
||||||
|
|
||||||
|
|
||||||
void softSpiInit(const softSPIDevice_t *dev);
|
|
||||||
uint8_t softSpiTransferByte(const softSPIDevice_t *dev, uint8_t data);
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
|
|
||||||
#include "drivers/bus_spi.h"
|
#include "drivers/bus_spi.h"
|
||||||
#include "drivers/bus_spi_soft.h"
|
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/io_impl.h"
|
#include "drivers/io_impl.h"
|
||||||
#include "drivers/rcc.h"
|
#include "drivers/rcc.h"
|
||||||
|
@ -43,18 +42,7 @@
|
||||||
#define DISABLE_RX() {IOHi(DEFIO_IO(RX_NSS_PIN));}
|
#define DISABLE_RX() {IOHi(DEFIO_IO(RX_NSS_PIN));}
|
||||||
#define ENABLE_RX() {IOLo(DEFIO_IO(RX_NSS_PIN));}
|
#define ENABLE_RX() {IOLo(DEFIO_IO(RX_NSS_PIN));}
|
||||||
|
|
||||||
#ifdef USE_RX_SOFTSPI
|
void rxSpiDeviceInit(void)
|
||||||
static const softSPIDevice_t softSPIDevice = {
|
|
||||||
.sckTag = IO_TAG(RX_SCK_PIN),
|
|
||||||
.mosiTag = IO_TAG(RX_MOSI_PIN),
|
|
||||||
.misoTag = IO_TAG(RX_MISO_PIN),
|
|
||||||
// Note: Nordic Semiconductor uses 'CSN', STM uses 'NSS'
|
|
||||||
.nssTag = IO_TAG(RX_NSS_PIN),
|
|
||||||
};
|
|
||||||
static bool useSoftSPI = false;
|
|
||||||
#endif // USE_RX_SOFTSPI
|
|
||||||
|
|
||||||
void rxSpiDeviceInit(rx_spi_type_e spiType)
|
|
||||||
{
|
{
|
||||||
static bool hardwareInitialised = false;
|
static bool hardwareInitialised = false;
|
||||||
|
|
||||||
|
@ -62,19 +50,10 @@ void rxSpiDeviceInit(rx_spi_type_e spiType)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_RX_SOFTSPI
|
|
||||||
if (spiType == RX_SPI_SOFTSPI) {
|
|
||||||
useSoftSPI = true;
|
|
||||||
softSpiInit(&softSPIDevice);
|
|
||||||
}
|
|
||||||
const SPIDevice rxSPIDevice = SOFT_SPIDEV_1;
|
|
||||||
#else
|
|
||||||
UNUSED(spiType);
|
|
||||||
const SPIDevice rxSPIDevice = spiDeviceByInstance(RX_SPI_INSTANCE);
|
const SPIDevice rxSPIDevice = spiDeviceByInstance(RX_SPI_INSTANCE);
|
||||||
const IO_t rxCsPin = DEFIO_IO(RX_NSS_PIN);
|
const IO_t rxCsPin = DEFIO_IO(RX_NSS_PIN);
|
||||||
IOInit(rxCsPin, OWNER_RX_SPI_CS, rxSPIDevice + 1);
|
IOInit(rxCsPin, OWNER_RX_SPI_CS, rxSPIDevice + 1);
|
||||||
IOConfigGPIO(rxCsPin, SPI_IO_CS_CFG);
|
IOConfigGPIO(rxCsPin, SPI_IO_CS_CFG);
|
||||||
#endif // USE_RX_SOFTSPI
|
|
||||||
|
|
||||||
DISABLE_RX();
|
DISABLE_RX();
|
||||||
|
|
||||||
|
@ -86,18 +65,11 @@ void rxSpiDeviceInit(rx_spi_type_e spiType)
|
||||||
|
|
||||||
uint8_t rxSpiTransferByte(uint8_t data)
|
uint8_t rxSpiTransferByte(uint8_t data)
|
||||||
{
|
{
|
||||||
#ifdef USE_RX_SOFTSPI
|
|
||||||
if (useSoftSPI) {
|
|
||||||
return softSpiTransferByte(&softSPIDevice, data);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef RX_SPI_INSTANCE
|
#ifdef RX_SPI_INSTANCE
|
||||||
return spiTransferByte(RX_SPI_INSTANCE, data);
|
return spiTransferByte(RX_SPI_INSTANCE, data);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t rxSpiWriteByte(uint8_t data)
|
uint8_t rxSpiWriteByte(uint8_t data)
|
||||||
|
|
|
@ -22,14 +22,9 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
RX_SPI_SOFTSPI,
|
|
||||||
RX_SPI_HARDSPI
|
|
||||||
} rx_spi_type_e;
|
|
||||||
|
|
||||||
#define RX_SPI_MAX_PAYLOAD_SIZE 32
|
#define RX_SPI_MAX_PAYLOAD_SIZE 32
|
||||||
|
|
||||||
void rxSpiDeviceInit(rx_spi_type_e spiType);
|
void rxSpiDeviceInit(void);
|
||||||
uint8_t rxSpiTransferByte(uint8_t data);
|
uint8_t rxSpiTransferByte(uint8_t data);
|
||||||
uint8_t rxSpiWriteByte(uint8_t data);
|
uint8_t rxSpiWriteByte(uint8_t data);
|
||||||
uint8_t rxSpiWriteCommand(uint8_t command, uint8_t data);
|
uint8_t rxSpiWriteCommand(uint8_t command, uint8_t data);
|
||||||
|
|
|
@ -258,7 +258,7 @@ void spiPreInit(void)
|
||||||
#ifdef FLASH_CS_PIN
|
#ifdef FLASH_CS_PIN
|
||||||
spiPreInitCs(IO_TAG(FLASH_CS_PIN));
|
spiPreInitCs(IO_TAG(FLASH_CS_PIN));
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_RX_SPI) && !defined(USE_RX_SOFTSPI)
|
#if defined(USE_RX_SPI)
|
||||||
spiPreInitCs(IO_TAG(RX_NSS_PIN));
|
spiPreInitCs(IO_TAG(RX_NSS_PIN));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,8 +171,7 @@ bool rxSpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
const rx_spi_type_e spiType = feature(FEATURE_SOFTSPI) ? RX_SPI_SOFTSPI : RX_SPI_HARDSPI;
|
rxSpiDeviceInit();
|
||||||
rxSpiDeviceInit(spiType);
|
|
||||||
if (rxSpiSetProtocol(rxConfig->rx_spi_protocol)) {
|
if (rxSpiSetProtocol(rxConfig->rx_spi_protocol)) {
|
||||||
ret = protocolInit(rxConfig, rxRuntimeConfig);
|
ret = protocolInit(rxConfig, rxRuntimeConfig);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue