mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-24 00:35:34 +03:00
Minor updates to NRF24 protols
This commit is contained in:
parent
bb0831354c
commit
892edb25ce
5 changed files with 55 additions and 16 deletions
|
@ -690,6 +690,7 @@ const clivalue_t valueTable[] = {
|
||||||
#ifdef USE_RX_NRF24
|
#ifdef USE_RX_NRF24
|
||||||
{ "nrf24rx_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_protocol, .config.lookup = { TABLE_NRF24_RX }, 0 },
|
{ "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_id", VAR_UINT32 | MASTER_VALUE, &masterConfig.rxConfig.nrf24rx_id, .config.minmax = { 0, 0 }, 0 },
|
||||||
|
{ "nrf24rx_channel_count", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_channel_count, .config.minmax = { 0, 8 }, 0 },
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPEKTRUM_BIND
|
#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 },
|
{ "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX}, 0 },
|
||||||
|
|
|
@ -1050,7 +1050,7 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_RX_CONFIG:
|
case MSP_RX_CONFIG:
|
||||||
headSerialReply(21);
|
headSerialReply(22);
|
||||||
serialize8(masterConfig.rxConfig.serialrx_provider);
|
serialize8(masterConfig.rxConfig.serialrx_provider);
|
||||||
serialize16(masterConfig.rxConfig.maxcheck);
|
serialize16(masterConfig.rxConfig.maxcheck);
|
||||||
serialize16(masterConfig.rxConfig.midrc);
|
serialize16(masterConfig.rxConfig.midrc);
|
||||||
|
@ -1058,11 +1058,12 @@ static bool processOutCommand(uint8_t cmdMSP)
|
||||||
serialize8(masterConfig.rxConfig.spektrum_sat_bind);
|
serialize8(masterConfig.rxConfig.spektrum_sat_bind);
|
||||||
serialize16(masterConfig.rxConfig.rx_min_usec);
|
serialize16(masterConfig.rxConfig.rx_min_usec);
|
||||||
serialize16(masterConfig.rxConfig.rx_max_usec);
|
serialize16(masterConfig.rxConfig.rx_max_usec);
|
||||||
serialize8(0); // for compatibillity with betaflight
|
serialize8(0); // for compatibility with betaflight
|
||||||
serialize8(0); // for compatibillity with betaflight
|
serialize8(0); // for compatibility with betaflight
|
||||||
serialize16(0); // for compatibillity with betaflight
|
serialize16(0); // for compatibility with betaflight
|
||||||
serialize8(masterConfig.rxConfig.nrf24rx_protocol);
|
serialize8(masterConfig.rxConfig.nrf24rx_protocol);
|
||||||
serialize32(masterConfig.rxConfig.nrf24rx_id);
|
serialize32(masterConfig.rxConfig.nrf24rx_id);
|
||||||
|
serialize8(masterConfig.rxConfig.nrf24rx_channel_count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_FAILSAFE_CONFIG:
|
case MSP_FAILSAFE_CONFIG:
|
||||||
|
@ -1603,6 +1604,9 @@ static bool processInCommand(void)
|
||||||
if (currentPort->dataSize > 17) {
|
if (currentPort->dataSize > 17) {
|
||||||
masterConfig.rxConfig.nrf24rx_id = read32();
|
masterConfig.rxConfig.nrf24rx_id = read32();
|
||||||
}
|
}
|
||||||
|
if (currentPort->dataSize > 18) {
|
||||||
|
masterConfig.rxConfig.nrf24rx_channel_count = read8();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_SET_FAILSAFE_CONFIG:
|
case MSP_SET_FAILSAFE_CONFIG:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#ifdef USE_RX_INAV
|
#ifdef USE_RX_INAV
|
||||||
|
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
|
#include "build/debug.h"
|
||||||
|
|
||||||
#include "drivers/rx_nrf24l01.h"
|
#include "drivers/rx_nrf24l01.h"
|
||||||
#include "drivers/system.h"
|
#include "drivers/system.h"
|
||||||
|
@ -94,10 +95,12 @@ STATIC_UNIT_TESTED uint8_t rxTxAddr[RX_TX_ADDR_LEN] = {0x4b,0x5c,0x6d,0x7e,0x8f}
|
||||||
uint32_t *nrf24rxIdPtr;
|
uint32_t *nrf24rxIdPtr;
|
||||||
|
|
||||||
// radio channels for frequency hopping
|
// radio channels for frequency hopping
|
||||||
#define INAV_RF_CHANNEL_COUNT 4
|
#define INAV_RF_CHANNEL_COUNT_MAX 8
|
||||||
STATIC_UNIT_TESTED const uint8_t inavRfChannelCount = INAV_RF_CHANNEL_COUNT;
|
#define INAV_RF_CHANNEL_HOPPING_COUNT_DEFAULT 4
|
||||||
|
STATIC_UNIT_TESTED uint8_t inavRfChannelHoppingCount;
|
||||||
|
STATIC_UNIT_TESTED uint8_t inavRfChannelCount;
|
||||||
STATIC_UNIT_TESTED uint8_t inavRfChannelIndex;
|
STATIC_UNIT_TESTED uint8_t inavRfChannelIndex;
|
||||||
STATIC_UNIT_TESTED uint8_t inavRfChannels[INAV_RF_CHANNEL_COUNT];
|
STATIC_UNIT_TESTED uint8_t inavRfChannels[INAV_RF_CHANNEL_COUNT_MAX];
|
||||||
#define INAV_RF_BIND_CHANNEL 0x4c
|
#define INAV_RF_BIND_CHANNEL 0x4c
|
||||||
|
|
||||||
static uint32_t timeOfLastHop;
|
static uint32_t timeOfLastHop;
|
||||||
|
@ -114,6 +117,10 @@ STATIC_UNIT_TESTED bool inavCheckBindPacket(const uint8_t *payload)
|
||||||
rxTxAddr[2] = payload[4];
|
rxTxAddr[2] = payload[4];
|
||||||
rxTxAddr[3] = payload[5];
|
rxTxAddr[3] = payload[5];
|
||||||
rxTxAddr[4] = payload[6];
|
rxTxAddr[4] = payload[6];
|
||||||
|
inavRfChannelHoppingCount = payload[7];
|
||||||
|
if (inavRfChannelHoppingCount > INAV_RF_CHANNEL_COUNT_MAX) {
|
||||||
|
inavRfChannelHoppingCount = INAV_RF_CHANNEL_COUNT_MAX;
|
||||||
|
}
|
||||||
if (nrf24rxIdPtr != NULL && *nrf24rxIdPtr == 0) {
|
if (nrf24rxIdPtr != NULL && *nrf24rxIdPtr == 0) {
|
||||||
// copy the rxTxAddr so it can be saved
|
// copy the rxTxAddr so it can be saved
|
||||||
memcpy(nrf24rxIdPtr, rxTxAddr, sizeof(uint32_t));
|
memcpy(nrf24rxIdPtr, rxTxAddr, sizeof(uint32_t));
|
||||||
|
@ -176,16 +183,26 @@ static void inavHopToNextChannel(void)
|
||||||
inavRfChannelIndex = 0;
|
inavRfChannelIndex = 0;
|
||||||
}
|
}
|
||||||
NRF24L01_SetChannel(inavRfChannels[inavRfChannelIndex]);
|
NRF24L01_SetChannel(inavRfChannels[inavRfChannelIndex]);
|
||||||
|
#ifdef DEBUG_NRF24_INAV
|
||||||
|
debug[0] = inavRfChannels[inavRfChannelIndex];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// The hopping channels are determined by the low bits of rxTxAddr
|
// The hopping channels are determined by the low bits of rxTxAddr
|
||||||
STATIC_UNIT_TESTED void inavSetHoppingChannels(uint8_t addr)
|
STATIC_UNIT_TESTED void inavSetHoppingChannels(uint8_t addr)
|
||||||
{
|
{
|
||||||
addr &= 0x07;
|
if (inavRfChannelHoppingCount == 0) {
|
||||||
inavRfChannels[0] = 0x10 + addr;
|
// just stay on bind channel, useful for debugging
|
||||||
inavRfChannels[1] = 0x1C + addr;
|
inavRfChannelCount = 1;
|
||||||
inavRfChannels[2] = 0x28 + addr;
|
inavRfChannels[0] = INAV_RF_BIND_CHANNEL;
|
||||||
inavRfChannels[3] = 0x34 + addr;
|
return;
|
||||||
|
}
|
||||||
|
inavRfChannelCount = inavRfChannelHoppingCount;
|
||||||
|
uint8_t ch = 0x10 + (addr & 0x07);
|
||||||
|
for (int ii = 0; ii < INAV_RF_CHANNEL_COUNT_MAX; ++ii) {
|
||||||
|
inavRfChannels[ii] = ch;
|
||||||
|
ch += 0x0c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inavSetBound(void)
|
static void inavSetBound(void)
|
||||||
|
@ -197,6 +214,9 @@ static void inavSetBound(void)
|
||||||
timeOfLastHop = micros();
|
timeOfLastHop = micros();
|
||||||
inavRfChannelIndex = 0;
|
inavRfChannelIndex = 0;
|
||||||
NRF24L01_SetChannel(inavRfChannels[0]);
|
NRF24L01_SetChannel(inavRfChannels[0]);
|
||||||
|
#ifdef DEBUG_NRF24_INAV
|
||||||
|
debug[0] = inavRfChannels[0];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -208,6 +228,9 @@ nrf24_received_t inavNrf24DataReceived(uint8_t *payload)
|
||||||
#if defined(TELEMETRY_NRF24_LTM)
|
#if defined(TELEMETRY_NRF24_LTM)
|
||||||
static ltm_frame_e ltmFrameType = LTM_FRAME_START;
|
static ltm_frame_e ltmFrameType = LTM_FRAME_START;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef DEBUG_NRF24_INAV
|
||||||
|
debug[1] = protocolState;
|
||||||
|
#endif
|
||||||
|
|
||||||
nrf24_received_t ret = NRF24_RECEIVED_NONE;
|
nrf24_received_t ret = NRF24_RECEIVED_NONE;
|
||||||
uint32_t timeNowUs;
|
uint32_t timeNowUs;
|
||||||
|
@ -249,6 +272,10 @@ nrf24_received_t inavNrf24DataReceived(uint8_t *payload)
|
||||||
ltmFrameType = LTM_FRAME_START;
|
ltmFrameType = LTM_FRAME_START;
|
||||||
}
|
}
|
||||||
NRF24L01_WriteAckPayload(ackPayload, ackPayloadSize, NRF24L01_PIPE0);
|
NRF24L01_WriteAckPayload(ackPayload, ackPayloadSize, NRF24L01_PIPE0);
|
||||||
|
#ifdef DEBUG_NRF24_INAV
|
||||||
|
debug[2] = ackPayload[1]; // frame type, 'A', 'S' etc
|
||||||
|
debug[3] = ackPayload[2]; // pitch for AFrame
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +288,7 @@ nrf24_received_t inavNrf24DataReceived(uint8_t *payload)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inavNrf24Setup(nrf24_protocol_t protocol, const uint32_t *nrf24rx_id)
|
static void inavNrf24Setup(nrf24_protocol_t protocol, const uint32_t *nrf24rx_id, int rfChannelHoppingCount)
|
||||||
{
|
{
|
||||||
UNUSED(protocol);
|
UNUSED(protocol);
|
||||||
|
|
||||||
|
@ -274,10 +301,13 @@ static void inavNrf24Setup(nrf24_protocol_t protocol, const uint32_t *nrf24rx_id
|
||||||
nrf24rxIdPtr = (uint32_t*)nrf24rx_id;
|
nrf24rxIdPtr = (uint32_t*)nrf24rx_id;
|
||||||
if (nrf24rx_id == NULL || *nrf24rx_id == 0) {
|
if (nrf24rx_id == NULL || *nrf24rx_id == 0) {
|
||||||
protocolState = STATE_BIND;
|
protocolState = STATE_BIND;
|
||||||
|
inavRfChannelCount = 1;
|
||||||
|
inavRfChannelIndex = 0;
|
||||||
NRF24L01_SetChannel(INAV_RF_BIND_CHANNEL);
|
NRF24L01_SetChannel(INAV_RF_BIND_CHANNEL);
|
||||||
} else {
|
} else {
|
||||||
memcpy(rxTxAddr, nrf24rx_id, sizeof(uint32_t));
|
memcpy(rxTxAddr, nrf24rx_id, sizeof(uint32_t));
|
||||||
rxTxAddr[4] = 0xD2;
|
rxTxAddr[4] = 0xD2;
|
||||||
|
inavRfChannelHoppingCount = rfChannelHoppingCount;
|
||||||
inavSetBound();
|
inavSetBound();
|
||||||
}
|
}
|
||||||
NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, NRF24L01_06_RF_SETUP_RF_DR_250Kbps | NRF24L01_06_RF_SETUP_RF_PWR_n12dbm);
|
NRF24L01_WriteReg(NRF24L01_06_RF_SETUP, NRF24L01_06_RF_SETUP_RF_DR_250Kbps | NRF24L01_06_RF_SETUP_RF_PWR_n12dbm);
|
||||||
|
@ -297,7 +327,7 @@ static void inavNrf24Setup(nrf24_protocol_t protocol, const uint32_t *nrf24rx_id
|
||||||
void inavNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
void inavNrf24Init(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
{
|
{
|
||||||
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT;
|
rxRuntimeConfig->channelCount = RC_CHANNEL_COUNT;
|
||||||
inavNrf24Setup((nrf24_protocol_t)rxConfig->nrf24rx_protocol, &rxConfig->nrf24rx_id);
|
inavNrf24Setup((nrf24_protocol_t)rxConfig->nrf24rx_protocol, &rxConfig->nrf24rx_id, rxConfig->nrf24rx_channel_count);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ typedef struct rxConfig_s {
|
||||||
uint8_t sbus_inversion; // default sbus (Futaba, FrSKY) is inverted. Support for uninverted OpenLRS (and modified FrSKY) receivers.
|
uint8_t sbus_inversion; // default sbus (Futaba, FrSKY) is inverted. Support for uninverted OpenLRS (and modified FrSKY) receivers.
|
||||||
uint8_t nrf24rx_protocol; // type of nrf24 protocol (0 = v202 250kbps). Must be enabled by FEATURE_RX_NRF24 first.
|
uint8_t nrf24rx_protocol; // type of nrf24 protocol (0 = v202 250kbps). Must be enabled by FEATURE_RX_NRF24 first.
|
||||||
uint32_t nrf24rx_id;
|
uint32_t nrf24rx_id;
|
||||||
|
uint8_t nrf24rx_channel_count;
|
||||||
uint8_t spektrum_sat_bind; // number of bind pulses for Spektrum satellite receivers
|
uint8_t spektrum_sat_bind; // number of bind pulses for Spektrum satellite receivers
|
||||||
uint8_t spektrum_sat_bind_autoreset; // whenever we will reset (exit) binding mode after hard reboot
|
uint8_t spektrum_sat_bind_autoreset; // whenever we will reset (exit) binding mode after hard reboot
|
||||||
uint8_t rssi_channel;
|
uint8_t rssi_channel;
|
||||||
|
|
|
@ -74,10 +74,11 @@
|
||||||
//#define USE_RX_SYMA
|
//#define USE_RX_SYMA
|
||||||
//#define USE_RX_V202
|
//#define USE_RX_V202
|
||||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5C
|
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5C
|
||||||
#define NRF24_DEFAULT_PROTOCOL NRF24RX_INAV
|
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_INAV
|
||||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_H8_3D
|
#define NRF24_DEFAULT_PROTOCOL NRF24RX_H8_3D
|
||||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_CX10A
|
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_CX10A
|
||||||
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_V202_1M
|
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_V202_1M
|
||||||
|
//#define DEBUG_NRF24_INAV
|
||||||
|
|
||||||
#define DEFAULT_RX_FEATURE FEATURE_RX_NRF24
|
#define DEFAULT_RX_FEATURE FEATURE_RX_NRF24
|
||||||
#define TELEMETRY_LTM
|
#define TELEMETRY_LTM
|
||||||
|
@ -85,7 +86,9 @@
|
||||||
#define SKIP_RX_PWM_PPM
|
#define SKIP_RX_PWM_PPM
|
||||||
#undef SERIAL_RX
|
#undef SERIAL_RX
|
||||||
#undef SKIP_TASK_STATISTICS
|
#undef SKIP_TASK_STATISTICS
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define DEFAULT_RX_FEATURE FEATURE_RX_PPM
|
#define DEFAULT_RX_FEATURE FEATURE_RX_PPM
|
||||||
#undef SKIP_RX_MSP
|
#undef SKIP_RX_MSP
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue