mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Receiver code tidy.
This commit is contained in:
parent
551bbe1d1a
commit
b123e74a73
4 changed files with 50 additions and 20 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "drivers/system.h"
|
||||
#include "drivers/timer.h"
|
||||
#include "drivers/pwm_rx.h"
|
||||
#include "drivers/rx_spi.h"
|
||||
#include "drivers/serial.h"
|
||||
#include "drivers/pwm_output.h"
|
||||
#include "drivers/max7456.h"
|
||||
|
@ -62,6 +63,7 @@
|
|||
#include "io/vtx.h"
|
||||
|
||||
#include "rx/rx.h"
|
||||
#include "rx/rx_spi.h"
|
||||
|
||||
#include "telemetry/telemetry.h"
|
||||
|
||||
|
@ -83,6 +85,9 @@
|
|||
#ifndef DEFAULT_RX_FEATURE
|
||||
#define DEFAULT_RX_FEATURE FEATURE_RX_PARALLEL_PWM
|
||||
#endif
|
||||
#ifndef RX_SPI_DEFAULT_PROTOCOL
|
||||
#define RX_SPI_DEFAULT_PROTOCOL 0
|
||||
#endif
|
||||
|
||||
#define BRUSHED_MOTORS_PWM_RATE 16000
|
||||
#ifdef STM32F4
|
||||
|
@ -454,6 +459,7 @@ void createDefaultConfig(master_t *config)
|
|||
#else
|
||||
config->rxConfig.serialrx_provider = 0;
|
||||
#endif
|
||||
config->rxConfig.rx_spi_protocol = RX_SPI_DEFAULT_PROTOCOL;
|
||||
config->rxConfig.sbus_inversion = 1;
|
||||
config->rxConfig.spektrum_sat_bind = 0;
|
||||
config->rxConfig.spektrum_sat_bind_autoreset = 1;
|
||||
|
@ -720,26 +726,28 @@ void activateConfig(void)
|
|||
|
||||
void validateAndFixConfig(void)
|
||||
{
|
||||
if (!(featureConfigured(FEATURE_RX_PARALLEL_PWM) || featureConfigured(FEATURE_RX_PPM) || featureConfigured(FEATURE_RX_SERIAL) || featureConfigured(FEATURE_RX_MSP))) {
|
||||
if (!(featureConfigured(FEATURE_RX_PARALLEL_PWM) || featureConfigured(FEATURE_RX_PPM) || featureConfigured(FEATURE_RX_SERIAL) || featureConfigured(FEATURE_RX_MSP) || featureConfigured(FEATURE_RX_SPI))) {
|
||||
featureSet(DEFAULT_RX_FEATURE);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_RX_PPM)) {
|
||||
featureClear(FEATURE_RX_PARALLEL_PWM);
|
||||
featureClear(FEATURE_RX_SERIAL | FEATURE_RX_PARALLEL_PWM | FEATURE_RX_MSP | FEATURE_RX_SPI);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_RX_MSP)) {
|
||||
featureClear(FEATURE_RX_SERIAL);
|
||||
featureClear(FEATURE_RX_PARALLEL_PWM);
|
||||
featureClear(FEATURE_RX_PPM);
|
||||
featureClear(FEATURE_RX_SERIAL | FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM | FEATURE_RX_SPI);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_RX_SERIAL)) {
|
||||
featureClear(FEATURE_RX_PARALLEL_PWM);
|
||||
featureClear(FEATURE_RX_PPM);
|
||||
featureClear(FEATURE_RX_PARALLEL_PWM | FEATURE_RX_MSP | FEATURE_RX_PPM | FEATURE_RX_SPI);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_RX_SPI)) {
|
||||
featureClear(FEATURE_RX_SERIAL | FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM | FEATURE_RX_MSP);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_RX_PARALLEL_PWM)) {
|
||||
featureClear(FEATURE_RX_SERIAL | FEATURE_RX_MSP | FEATURE_RX_PPM | FEATURE_RX_SPI);
|
||||
#if defined(STM32F10X)
|
||||
// rssi adc needs the same ports
|
||||
featureClear(FEATURE_RSSI_ADC);
|
||||
|
@ -758,6 +766,20 @@ void validateAndFixConfig(void)
|
|||
featureClear(FEATURE_SOFTSERIAL);
|
||||
}
|
||||
|
||||
#ifdef USE_SOFTSPI
|
||||
if (featureConfigured(FEATURE_SOFTSPI)) {
|
||||
featureClear(FEATURE_RX_PPM | FEATURE_RX_PARALLEL_PWM | FEATURE_SOFTSERIAL | FEATURE_VBAT);
|
||||
#if defined(STM32F10X)
|
||||
featureClear(FEATURE_LED_STRIP);
|
||||
// rssi adc needs the same ports
|
||||
featureClear(FEATURE_RSSI_ADC);
|
||||
// current meter needs the same ports
|
||||
if (masterConfig.batteryConfig.currentMeterType == CURRENT_SENSOR_ADC) {
|
||||
featureClear(FEATURE_CURRENT_METER);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LED_STRIP) && (defined(USE_SOFTSERIAL1) || defined(USE_SOFTSERIAL2))
|
||||
if (featureConfigured(FEATURE_SOFTSERIAL) && (
|
||||
|
|
|
@ -99,13 +99,17 @@ SPIDevice spiDeviceByInstance(SPI_TypeDef *instance)
|
|||
|
||||
void spiInitDevice(SPIDevice device)
|
||||
{
|
||||
SPI_InitTypeDef spiInit;
|
||||
|
||||
spiDevice_t *spi = &(spiHardwareMap[device]);
|
||||
|
||||
#ifdef SDCARD_SPI_INSTANCE
|
||||
if (spi->dev == SDCARD_SPI_INSTANCE)
|
||||
spi->sdcard = true;
|
||||
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
|
||||
|
@ -121,21 +125,24 @@ void spiInitDevice(SPIDevice device)
|
|||
IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_CFG, spi->af);
|
||||
IOConfigGPIOAF(IOGetByTag(spi->mosi), SPI_IO_AF_CFG, spi->af);
|
||||
|
||||
if (spi->nss)
|
||||
if (spi->nss) {
|
||||
IOConfigGPIOAF(IOGetByTag(spi->nss), SPI_IO_CS_CFG, spi->af);
|
||||
}
|
||||
#endif
|
||||
#if defined(STM32F10X)
|
||||
IOConfigGPIO(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG);
|
||||
IOConfigGPIO(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG);
|
||||
IOConfigGPIO(IOGetByTag(spi->mosi), SPI_IO_AF_MOSI_CFG);
|
||||
|
||||
if (spi->nss)
|
||||
if (spi->nss) {
|
||||
IOConfigGPIO(IOGetByTag(spi->nss), SPI_IO_CS_CFG);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Init SPI hardware
|
||||
// Init SPI hardware
|
||||
SPI_I2S_DeInit(spi->dev);
|
||||
|
||||
SPI_InitTypeDef spiInit;
|
||||
spiInit.SPI_Mode = SPI_Mode_Master;
|
||||
spiInit.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
|
||||
spiInit.SPI_DataSize = SPI_DataSize_8b;
|
||||
|
@ -144,11 +151,10 @@ void spiInitDevice(SPIDevice device)
|
|||
spiInit.SPI_CRCPolynomial = 7;
|
||||
spiInit.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
|
||||
if (spi->sdcard) {
|
||||
if (spi->leadingEdge) {
|
||||
spiInit.SPI_CPOL = SPI_CPOL_Low;
|
||||
spiInit.SPI_CPHA = SPI_CPHA_1Edge;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
spiInit.SPI_CPOL = SPI_CPOL_High;
|
||||
spiInit.SPI_CPHA = SPI_CPHA_2Edge;
|
||||
}
|
||||
|
@ -161,8 +167,10 @@ void spiInitDevice(SPIDevice device)
|
|||
SPI_Init(spi->dev, &spiInit);
|
||||
SPI_Cmd(spi->dev, ENABLE);
|
||||
|
||||
if (spi->nss)
|
||||
if (spi->nss) {
|
||||
// Drive NSS high to disable connected SPI device.
|
||||
IOHi(IOGetByTag(spi->nss));
|
||||
}
|
||||
}
|
||||
|
||||
bool spiInit(SPIDevice device)
|
||||
|
|
|
@ -67,7 +67,7 @@ typedef struct SPIDevice_s {
|
|||
rccPeriphTag_t rcc;
|
||||
uint8_t af;
|
||||
volatile uint16_t errorCount;
|
||||
bool sdcard;
|
||||
bool leadingEdge;
|
||||
} spiDevice_t;
|
||||
|
||||
bool spiInit(SPIDevice device);
|
||||
|
|
|
@ -46,7 +46,7 @@ static protocolInitPtr protocolInit;
|
|||
static protocolDataReceivedPtr protocolDataReceived;
|
||||
static protocolSetRcDataFromPayloadPtr protocolSetRcDataFromPayload;
|
||||
|
||||
STATIC_UNIT_TESTED uint16_t rxSpiReadRawRC(rxRuntimeConfig_t *rxRuntimeConfig, uint8_t channel)
|
||||
STATIC_UNIT_TESTED uint16_t rxSpiReadRawRC(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t channel)
|
||||
{
|
||||
BUILD_BUG_ON(NRF24L01_MAX_PAYLOAD_SIZE > RX_SPI_MAX_PAYLOAD_SIZE);
|
||||
if (channel >= rxRuntimeConfig->channelCount) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue