mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 08:15:26 +03:00
Fix to syma nrf24l01 protocol (#565)
This commit is contained in:
parent
f262154ea9
commit
32eaa7bcd9
4 changed files with 28 additions and 27 deletions
|
@ -261,7 +261,6 @@ void NRF24L01_SetupBasic(void)
|
|||
NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No auto acknowledgment
|
||||
NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, BV(NRF24L01_02_EN_RXADDR_ERX_P0));
|
||||
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, NRF24L01_03_SETUP_AW_5BYTES); // 5-byte RX/TX address
|
||||
NRF24L01_WriteReg(NRF24L01_08_OBSERVE_TX, 0x00); // Don't count lost or retransmitted packets
|
||||
NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes
|
||||
}
|
||||
|
||||
|
@ -326,6 +325,9 @@ bool NRF24L01_ReadPayloadIfAvailable(uint8_t *data, uint8_t length)
|
|||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
/*
|
||||
* Fast read of payload, for use in interrupt service routine
|
||||
*/
|
||||
bool NRF24L01_ReadPayloadIfAvailableFast(uint8_t *data, uint8_t length)
|
||||
{
|
||||
// number of bits transferred = 8 * (3 + length)
|
||||
|
@ -333,10 +335,13 @@ bool NRF24L01_ReadPayloadIfAvailableFast(uint8_t *data, uint8_t length)
|
|||
// at 50MHz clock rate that is approximately 3 microseconds
|
||||
bool ret = false;
|
||||
ENABLE_NRF24();
|
||||
nrf24TransferByte(R_REGISTER | (REGISTER_MASK & NRF24L01_17_FIFO_STATUS));
|
||||
const uint8_t fifoStatus = nrf24TransferByte(NOP);
|
||||
if ((fifoStatus & BV(NRF24L01_17_FIFO_STATUS_RX_EMPTY)) == 0) {
|
||||
nrf24TransferByte(R_REGISTER | (REGISTER_MASK & NRF24L01_07_STATUS));
|
||||
const uint8_t status = nrf24TransferByte(NOP);
|
||||
if ((status & BV(NRF24L01_07_STATUS_RX_DR)) == 0) {
|
||||
ret = true;
|
||||
// clear RX_DR flag
|
||||
nrf24TransferByte(W_REGISTER | (REGISTER_MASK & NRF24L01_07_STATUS));
|
||||
nrf24TransferByte(BV(NRF24L01_07_STATUS_RX_DR));
|
||||
nrf24TransferByte(R_RX_PAYLOAD);
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
data[i] = nrf24TransferByte(NOP);
|
||||
|
|
|
@ -707,7 +707,7 @@ const clivalue_t valueTable[] = {
|
|||
#ifdef USE_RX_NRF24
|
||||
{ "nrf24rx_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_protocol, .config.lookup = { TABLE_NRF24_RX }, 0 },
|
||||
{ "nrf24rx_id", VAR_UINT32 | MASTER_VALUE, &masterConfig.rxConfig.nrf24rx_id, .config.minmax = { 0, 0 }, 0 },
|
||||
{ "nrf24rx_rf_channel_count", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_rf_channel_count, .config.minmax = { 0, 8 }, 0 },
|
||||
{ "nrf24rx_rf_channel_count", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.nrf24rx_rf_channel_count, .config.minmax = { 0, 8 }, 0 },
|
||||
#endif
|
||||
#ifdef SPEKTRUM_BIND
|
||||
{ "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX}, 0 },
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <platform.h>
|
||||
#include "build/build_config.h"
|
||||
|
||||
|
||||
#ifdef USE_RX_SYMA
|
||||
|
||||
#include "build/build_config.h"
|
||||
|
||||
#include "drivers/rx_nrf24l01.h"
|
||||
#include "drivers/system.h"
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
|||
* uses address received in bind packets
|
||||
* hops between 4 channels generated from address received in bind packets
|
||||
*
|
||||
* SymaX5 Protocol
|
||||
* SymaX5C Protocol
|
||||
* No auto acknowledgment
|
||||
* Payload size is 16, static
|
||||
* Data rate is 1Mbps
|
||||
|
@ -222,20 +222,6 @@ static void setSymaXHoppingChannels(uint32_t addr)
|
|||
}
|
||||
}
|
||||
|
||||
static void symaSetBound(const uint8_t* rxTxAddr)
|
||||
{
|
||||
protocolState = STATE_DATA;
|
||||
// using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode
|
||||
// set the hopping channels as determined by the rxTxAddr received in the bind packet
|
||||
setSymaXHoppingChannels(rxTxAddr[0]);
|
||||
timeOfLastHop = micros();
|
||||
packetCount = 0;
|
||||
// set the NRF24 to use the rxTxAddr received in the bind packet
|
||||
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN);
|
||||
symaRfChannelIndex = 0;
|
||||
NRF24L01_SetChannel(symaRfChannels[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called periodically by the scheduler.
|
||||
* Returns NRF24_RECEIVED_DATA if a data packet was received.
|
||||
|
@ -243,26 +229,35 @@ static void symaSetBound(const uint8_t* rxTxAddr)
|
|||
nrf24_received_t symaNrf24DataReceived(uint8_t *payload)
|
||||
{
|
||||
nrf24_received_t ret = NRF24_RECEIVED_NONE;
|
||||
uint32_t timeNowUs;
|
||||
|
||||
switch (protocolState) {
|
||||
case STATE_BIND:
|
||||
if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
|
||||
const bool bindPacket = symaCheckBindPacket(payload);
|
||||
if (bindPacket) {
|
||||
ret = NRF24_RECEIVED_BIND;
|
||||
symaSetBound(rxTxAddr);
|
||||
protocolState = STATE_DATA;
|
||||
// using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode
|
||||
// set the hopping channels as determined by the rxTxAddr received in the bind packet
|
||||
setSymaXHoppingChannels(rxTxAddr[0]);
|
||||
// set the NRF24 to use the rxTxAddr received in the bind packet
|
||||
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN);
|
||||
packetCount = 0;
|
||||
symaRfChannelIndex = 0;
|
||||
NRF24L01_SetChannel(symaRfChannels[0]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_DATA:
|
||||
// read the payload, processing of payload is deferred
|
||||
if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
|
||||
symaHopToNextChannel();
|
||||
timeOfLastHop = micros();
|
||||
ret = NRF24_RECEIVED_DATA;
|
||||
}
|
||||
timeNowUs = micros();
|
||||
if ((ret == NRF24_RECEIVED_DATA) || (timeNowUs > timeOfLastHop + hopTimeout)) {
|
||||
if (micros() > timeOfLastHop + hopTimeout) {
|
||||
symaHopToNextChannel();
|
||||
timeOfLastHop = timeNowUs;
|
||||
timeOfLastHop = micros();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
#define USE_RX_INAV
|
||||
#define USE_RX_SYMA
|
||||
#define USE_RX_V202
|
||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5
|
||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5C
|
||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_INAV
|
||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_H8_3D
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue