Skip to content

Commit

Permalink
Add FLRC F-modes to ELRS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
CapnBry committed Jul 3, 2023
1 parent 6ba117d commit c0df818
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 188 deletions.
7 changes: 0 additions & 7 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ static const char* const lookupTableFreqDomain[] = {
"NONE",
#endif
};

static const char* const lookupTableSwitchMode[] = {
"WIDE", "HYBRID",
};
#endif

#define LOOKUP_TABLE_ENTRY(name) { name, ARRAYLEN(name) }
Expand Down Expand Up @@ -648,7 +644,6 @@ const lookupTableEntry_t lookupTables[] = {
#endif
#ifdef USE_RX_EXPRESSLRS
LOOKUP_TABLE_ENTRY(lookupTableFreqDomain),
LOOKUP_TABLE_ENTRY(lookupTableSwitchMode),
#endif
};

Expand Down Expand Up @@ -1693,8 +1688,6 @@ const clivalue_t valueTable[] = {
#ifdef USE_RX_EXPRESSLRS
{ "expresslrs_uid", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = 6, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, UID) },
{ "expresslrs_domain", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_FREQ_DOMAIN }, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, domain) },
{ "expresslrs_rate_index", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 3 }, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, rateIndex) },
{ "expresslrs_switch_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_SWITCH_MODE }, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, switchMode) },
{ "expresslrs_model_id", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, UINT8_MAX }, PG_RX_EXPRESSLRS_SPI_CONFIG, offsetof(rxExpressLrsSpiConfig_t, modelId) },
#endif

Expand Down
1 change: 0 additions & 1 deletion src/main/cli/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ typedef enum {
#endif
#ifdef USE_RX_EXPRESSLRS
TABLE_FREQ_DOMAIN,
TABLE_SWITCH_MODE,
#endif
LOOKUP_TABLE_COUNT
} lookupTableIndex_e;
Expand Down
29 changes: 16 additions & 13 deletions src/main/drivers/rx/rx_sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,17 @@ void sx127xStartReceiving(void)
sx127xSetMode(SX127x_OPMODE_RXCONTINUOUS);
}

void sx127xConfig(const sx127xBandwidth_e bw, const sx127xSpreadingFactor_e sf, const sx127xCodingRate_e cr,
const uint32_t freq, const uint8_t preambleLen, const bool iqInverted)
void sx127xConfig(const uint8_t bw, const uint8_t sfbt, const uint8_t cr,
const uint32_t freq, const uint8_t preambleLength, const bool iqInverted,
const uint32_t flrcSyncWord, const uint16_t flrcCrcSeed, const bool isFlrc)
{
UNUSED(flrcSyncWord); UNUSED(flrcCrcSeed); UNUSED(isFlrc);

sx127xConfigLoraDefaults(iqInverted);
sx127xSetPreambleLength(preambleLen);
sx127xSetPreambleLength(preambleLength);
sx127xSetOutputPower(SX127x_MAX_POWER);
sx127xSetSpreadingFactor(sf);
sx127xSetBandwidthCodingRate(bw, cr, sf, false, false);
sx127xSetSpreadingFactor(sfbt);
sx127xSetBandwidthCodingRate(bw, cr, sfbt, false, false);
sx127xSetFrequencyReg(freq);
}

Expand Down Expand Up @@ -384,22 +387,22 @@ int32_t sx127xGetFrequencyError(const sx127xBandwidth_e bw)
return fErrorHZ;
}

void sx127xAdjustFrequency(int32_t offset, const uint32_t freq)
void sx127xAdjustFrequency(int32_t *offset, const uint32_t freq)
{
if (sx127xGetFrequencyErrorbool()) { //logic is flipped compared to original code
if (offset > SX127x_FREQ_CORRECTION_MIN) {
offset -= 1;
if (*offset > SX127x_FREQ_CORRECTION_MIN) {
*offset -= 1;
} else {
offset = 0; //reset because something went wrong
*offset = 0; //reset because something went wrong
}
} else {
if (offset < SX127x_FREQ_CORRECTION_MAX) {
offset += 1;
if (*offset < SX127x_FREQ_CORRECTION_MAX) {
*offset += 1;
} else {
offset = 0; //reset because something went wrong
*offset = 0; //reset because something went wrong
}
}
sx127xSetPPMoffsetReg(offset, freq); //as above but corrects a different PPM offset based on freq error
sx127xSetPPMoffsetReg(*offset, freq); //as above but corrects a different PPM offset based on freq error
}

uint8_t sx127xUnsignedGetLastPacketRSSI(void)
Expand Down
7 changes: 4 additions & 3 deletions src/main/drivers/rx/rx_sx127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,14 @@ void sx127xSetFrequencyReg(const uint32_t freq);
void sx127xTransmitData(const uint8_t *data, const uint8_t length);
void sx127xReceiveData(uint8_t *data, const uint8_t length);
void sx127xStartReceiving(void);
void sx127xConfig(const sx127xBandwidth_e bw, const sx127xSpreadingFactor_e sf, const sx127xCodingRate_e cr, const uint32_t freq, const uint8_t preambleLen, const bool iqInverted);

void sx127xConfig(const uint8_t bw, const uint8_t sfbt, const uint8_t cr,
const uint32_t freq, const uint8_t preambleLength, const bool iqInverted,
const uint32_t flrcSyncWord, const uint16_t flrcCrcSeed, const bool isFlrc);
uint32_t sx127xGetCurrBandwidth(const sx127xBandwidth_e bw);
uint32_t sx127xGetCurrBandwidthNormalisedShifted(const sx127xBandwidth_e bw);
void sx127xSetPPMoffsetReg(const int32_t offset, const uint32_t freq);
int32_t sx127xGetFrequencyError(const sx127xBandwidth_e bw);
void sx127xAdjustFrequency(int32_t offset, const uint32_t freq);
void sx127xAdjustFrequency(int32_t *offset, const uint32_t freq);
uint8_t sx127xUnsignedGetLastPacketRSSI(void);
int8_t sx127xGetLastPacketRSSI(void);
int8_t sx127xGetCurrRSSI(void);
Expand Down

0 comments on commit c0df818

Please sign in to comment.