mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 04:45:24 +03:00
Merge pull request #4936 from mikeller/fix_frsky_spi_rx
Improved FrSky SPI RX detection / LED output.
This commit is contained in:
commit
2979056b66
18 changed files with 79 additions and 45 deletions
|
@ -31,7 +31,7 @@ typedef struct rxFrSkySpiConfig_s {
|
|||
|
||||
PG_DECLARE(rxFrSkySpiConfig_t, rxFrSkySpiConfig);
|
||||
|
||||
void frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
bool frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
rx_spi_received_e frSkySpiDataReceived(uint8_t *packet);
|
||||
void frSkySpiSetRcData(uint16_t *rcData, const uint8_t *payload);
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ rx_spi_received_e frSkyDHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
if (packet[0] == 0x11) {
|
||||
if ((packet[1] == rxFrSkySpiConfig()->bindTxId[0]) &&
|
||||
(packet[2] == rxFrSkySpiConfig()->bindTxId[1])) {
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
nextChannel(1);
|
||||
#if defined(USE_RX_FRSKY_SPI_TELEMETRY)
|
||||
if ((packet[3] % 4) == 2) {
|
||||
|
@ -228,7 +228,7 @@ rx_spi_received_e frSkyDHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
|
||||
if (cmpTimeUs(currentPacketReceivedTime, lastPacketReceivedTime) > (timeoutUs * SYNC_DELAY_MAX)) {
|
||||
#if defined(USE_RX_FRSKY_SPI_PA_LNA)
|
||||
RxEnable();
|
||||
TxDisable();
|
||||
#endif
|
||||
if (timeoutUs == 1) {
|
||||
#if defined(USE_RX_FRSKY_SPI_PA_LNA) && defined(USE_RX_FRSKY_SPI_DIVERSITY) // SE4311 chip
|
||||
|
@ -249,9 +249,9 @@ rx_spi_received_e frSkyDHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
nextChannel(1);
|
||||
} else {
|
||||
if (ledIsOn) {
|
||||
IOLo(frSkyLedPin);
|
||||
LedOff();
|
||||
} else {
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
}
|
||||
ledIsOn = !ledIsOn;
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ static setRcDataFn *setRcData;
|
|||
|
||||
IO_t gdoPin;
|
||||
static IO_t bindPin = DEFIO_IO(NONE);
|
||||
IO_t frSkyLedPin;
|
||||
static IO_t frSkyLedPin;
|
||||
|
||||
#if defined(USE_RX_FRSKY_SPI_PA_LNA)
|
||||
static IO_t txEnPin;
|
||||
|
@ -105,17 +105,35 @@ void setRssiDbm(uint8_t value)
|
|||
#endif // USE_RX_FRSKY_SPI_TELEMETRY
|
||||
|
||||
#if defined(USE_RX_FRSKY_SPI_PA_LNA)
|
||||
void RxEnable(void)
|
||||
{
|
||||
IOLo(txEnPin);
|
||||
}
|
||||
|
||||
void TxEnable(void)
|
||||
{
|
||||
IOHi(txEnPin);
|
||||
}
|
||||
|
||||
void TxDisable(void)
|
||||
{
|
||||
IOLo(txEnPin);
|
||||
}
|
||||
#endif
|
||||
|
||||
void LedOn(void)
|
||||
{
|
||||
#if defined(RX_FRSKY_SPI_LED_PIN_INVERTED)
|
||||
IOLo(frSkyLedPin);
|
||||
#else
|
||||
IOHi(frSkyLedPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void LedOff(void)
|
||||
{
|
||||
#if defined(RX_FRSKY_SPI_LED_PIN_INVERTED)
|
||||
IOHi(frSkyLedPin);
|
||||
#else
|
||||
IOLo(frSkyLedPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void frSkySpiBind(void)
|
||||
{
|
||||
bindRequested = true;
|
||||
|
@ -381,7 +399,7 @@ rx_spi_received_e frSkySpiDataReceived(uint8_t *packet)
|
|||
break;
|
||||
case STATE_BIND:
|
||||
if (checkBindRequested(true) || rxFrSkySpiConfig()->autoBind) {
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
initTuneRx();
|
||||
|
||||
protocolState = STATE_BIND_TUNING;
|
||||
|
@ -419,9 +437,9 @@ rx_spi_received_e frSkySpiDataReceived(uint8_t *packet)
|
|||
} else {
|
||||
uint8_t ctr = 40;
|
||||
while (ctr--) {
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
delay(50);
|
||||
IOLo(frSkyLedPin);
|
||||
LedOff();
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
@ -481,22 +499,24 @@ void switchAntennae(void)
|
|||
|
||||
static bool frSkySpiDetect(void)
|
||||
{
|
||||
uint8_t tmp[2];
|
||||
tmp[0] = cc2500ReadReg(CC2500_30_PARTNUM | CC2500_READ_BURST); //CC2500 read registers chip part num
|
||||
tmp[1] = cc2500ReadReg(CC2500_31_VERSION | CC2500_READ_BURST); //CC2500 read registers chip version
|
||||
if (tmp[0] == 0x80 && tmp[1]==0x03){
|
||||
const uint8_t chipPartNum = cc2500ReadReg(CC2500_30_PARTNUM | CC2500_READ_BURST); //CC2500 read registers chip part num
|
||||
const uint8_t chipVersion = cc2500ReadReg(CC2500_31_VERSION | CC2500_READ_BURST); //CC2500 read registers chip version
|
||||
if (chipPartNum == 0x80 && chipVersion == 0x03) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
#if !defined(RX_FRSKY_SPI_DISABLE_CHIP_DETECTION)
|
||||
if (!frSkySpiDetect()) {
|
||||
rxRuntimeConfig->channelCount = 0;
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
UNUSED(frSkySpiDetect);
|
||||
#endif
|
||||
|
||||
spiProtocol = rxConfig->rx_spi_protocol;
|
||||
|
||||
|
@ -561,7 +581,7 @@ void frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
|||
#if defined(USE_RX_FRSKY_SPI_DIVERSITY)
|
||||
IOHi(antSelPin);
|
||||
#endif
|
||||
RxEnable();
|
||||
TxDisable();
|
||||
#endif // USE_RX_FRSKY_SPI_PA_LNA
|
||||
|
||||
missingPackets = 0;
|
||||
|
@ -569,5 +589,7 @@ void frSkySpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
|
|||
|
||||
start_time = millis();
|
||||
protocolState = STATE_INIT;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -47,12 +47,14 @@ extern timeDelta_t timeoutUs;
|
|||
extern int16_t rssiDbm;
|
||||
|
||||
extern IO_t gdoPin;
|
||||
extern IO_t frSkyLedPin;
|
||||
|
||||
void setRssiDbm(uint8_t value);
|
||||
|
||||
void RxEnable(void);
|
||||
void TxEnable(void);
|
||||
void TxDisable(void);
|
||||
|
||||
void LedOn(void);
|
||||
void LedOff(void);
|
||||
|
||||
void switchAntennae(void);
|
||||
|
||||
|
|
|
@ -351,7 +351,7 @@ rx_spi_received_e frSkyXHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
missingPackets = 0;
|
||||
timeoutUs = 1;
|
||||
receiveDelayUs = 0;
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
if (skipChannels) {
|
||||
channelsToSkip = packet[5] << 2;
|
||||
if (packet[4] >= listLength) {
|
||||
|
@ -431,9 +431,9 @@ rx_spi_received_e frSkyXHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
}
|
||||
if (cmpTimeUs(micros(), packetTimerUs) > timeoutUs * SYNC_DELAY_MAX) {
|
||||
if (ledIsOn) {
|
||||
IOLo(frSkyLedPin);
|
||||
LedOff();
|
||||
} else {
|
||||
IOHi(frSkyLedPin);
|
||||
LedOn();
|
||||
}
|
||||
ledIsOn = !ledIsOn;
|
||||
|
||||
|
@ -500,7 +500,7 @@ rx_spi_received_e frSkyXHandlePacket(uint8_t * const packet, uint8_t * const pro
|
|||
nextChannel(channelsToSkip);
|
||||
cc2500Strobe(CC2500_SRX);
|
||||
#ifdef USE_RX_FRSKY_SPI_PA_LNA
|
||||
RxEnable();
|
||||
TxDisable();
|
||||
#if defined(USE_RX_FRSKY_SPI_DIVERSITY)
|
||||
if (missingPackets >= 2) {
|
||||
switchAntennae();
|
||||
|
|
|
@ -349,7 +349,7 @@ static rx_spi_received_e flySkyReadAndProcess (uint8_t *payload, const uint32_t
|
|||
return result;
|
||||
}
|
||||
|
||||
void flySkyInit (const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig)
|
||||
bool flySkyInit (const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig)
|
||||
{
|
||||
protocol = rxConfig->rx_spi_protocol;
|
||||
|
||||
|
@ -395,6 +395,8 @@ void flySkyInit (const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rx
|
|||
A7105Strobe(A7105_RX); // start listening
|
||||
|
||||
resetTimeout(micros());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void flySkySetRcDataFromPayload (uint16_t *rcData, const uint8_t *payload)
|
||||
|
|
|
@ -30,7 +30,6 @@ PG_DECLARE(flySkyConfig_t, flySkyConfig);
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void flySkyInit(const struct rxConfig_s *rxConfig,
|
||||
struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool flySkyInit(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void flySkySetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e flySkyDataReceived(uint8_t *payload);
|
||||
|
|
|
@ -294,9 +294,11 @@ static void cx10Nrf24Setup(rx_spi_protocol_e protocol)
|
|||
NRF24L01_SetRxMode(); // enter receive mode to start listening for packets
|
||||
}
|
||||
|
||||
void cx10Nrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool cx10Nrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT;
|
||||
cx10Nrf24Setup((rx_spi_protocol_e)rxConfig->rx_spi_protocol);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void cx10Nrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool cx10Nrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void cx10Nrf24SetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e cx10Nrf24DataReceived(uint8_t *payload);
|
||||
|
|
|
@ -278,9 +278,11 @@ static void h8_3dNrf24Setup(rx_spi_protocol_e protocol, const uint32_t *rxSpiId)
|
|||
NRF24L01_SetRxMode(); // enter receive mode to start listening for packets
|
||||
}
|
||||
|
||||
void h8_3dNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool h8_3dNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT;
|
||||
h8_3dNrf24Setup((rx_spi_protocol_e)rxConfig->rx_spi_protocol, &rxConfig->rx_spi_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void h8_3dNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool h8_3dNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void h8_3dNrf24SetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e h8_3dNrf24DataReceived(uint8_t *payload);
|
||||
|
|
|
@ -419,9 +419,11 @@ static void inavNrf24Setup(rx_spi_protocol_e protocol, const uint32_t *rxSpiId,
|
|||
writeAckPayload(ackPayload, payloadSize);
|
||||
}
|
||||
|
||||
void inavNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool inavNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT_MAX;
|
||||
inavNrf24Setup((rx_spi_protocol_e)rxConfig->rx_spi_protocol, &rxConfig->rx_spi_id, rxConfig->rx_spi_rf_channel_count);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void inavNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool inavNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void inavNrf24SetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e inavNrf24DataReceived(uint8_t *payload);
|
||||
|
||||
|
|
|
@ -294,9 +294,11 @@ static void symaNrf24Setup(rx_spi_protocol_e protocol)
|
|||
NRF24L01_SetRxMode(); // enter receive mode to start listening for packets
|
||||
}
|
||||
|
||||
void symaNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool symaNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT;
|
||||
symaNrf24Setup((rx_spi_protocol_e)rxConfig->rx_spi_protocol);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void symaNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool symaNrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void symaNrf24SetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e symaNrf24DataReceived(uint8_t *payload);
|
||||
|
||||
|
|
|
@ -254,9 +254,11 @@ static void v202Nrf24Setup(rx_spi_protocol_e protocol)
|
|||
NRF24L01_SetRxMode(); // enter receive mode to start listening for packets
|
||||
}
|
||||
|
||||
void v202Nrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
bool v202Nrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||
{
|
||||
rxRuntimeConfig->channelCount = V2X2_RC_CHANNEL_COUNT;
|
||||
v202Nrf24Setup((rx_spi_protocol_e)rxConfig->rx_spi_protocol);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,6 @@
|
|||
|
||||
struct rxConfig_s;
|
||||
struct rxRuntimeConfig_s;
|
||||
void v202Nrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
bool v202Nrf24Init(const struct rxConfig_s *rxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
|
||||
void v202Nrf24SetRcDataFromPayload(uint16_t *rcData, const uint8_t *payload);
|
||||
rx_spi_received_e v202Nrf24DataReceived(uint8_t *payload);
|
||||
|
|
|
@ -48,7 +48,7 @@ uint16_t rxSpiRcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
|
|||
STATIC_UNIT_TESTED uint8_t rxSpiPayload[RX_SPI_MAX_PAYLOAD_SIZE];
|
||||
STATIC_UNIT_TESTED uint8_t rxSpiNewPacketAvailable; // set true when a new packet is received
|
||||
|
||||
typedef void (*protocolInitFnPtr)(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
typedef bool (*protocolInitFnPtr)(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
typedef rx_spi_received_e (*protocolDataReceivedFnPtr)(uint8_t *payload);
|
||||
typedef void (*protocolSetRcDataFromPayloadFnPtr)(uint16_t *rcData, const uint8_t *payload);
|
||||
|
||||
|
@ -163,8 +163,7 @@ bool rxSpiInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
|||
const rx_spi_type_e spiType = feature(FEATURE_SOFTSPI) ? RX_SPI_SOFTSPI : RX_SPI_HARDSPI;
|
||||
rxSpiDeviceInit(spiType);
|
||||
if (rxSpiSetProtocol(rxConfig->rx_spi_protocol)) {
|
||||
protocolInit(rxConfig, rxRuntimeConfig);
|
||||
ret = true;
|
||||
ret = protocolInit(rxConfig, rxRuntimeConfig);
|
||||
}
|
||||
rxSpiNewPacketAvailable = false;
|
||||
rxRuntimeConfig->rxRefreshRate = 20000;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue