Skip to content

Commit

Permalink
Merge pull request #11472 from klutvott123/crsf-baud-negotiation
Browse files Browse the repository at this point in the history
Make negotiated baud configurable for CRSF
  • Loading branch information
haslinghuis authored Mar 22, 2022
2 parents 015e9e2 + 06bf20e commit 61f43fe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ const clivalue_t valueTable[] = {
#endif
#if defined(USE_SERIALRX_CRSF)
{ "crsf_use_rx_snr", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, crsf_use_rx_snr) },
#if defined(USE_CRSF_V3)
{ "crsf_use_negotiated_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_RX_CONFIG, offsetof(rxConfig_t, crsf_use_negotiated_baud) },
#endif
#endif
{ "airmode_start_throttle_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_RX_CONFIG, offsetof(rxConfig_t, airModeActivateThreshold) },
{ "rx_min_usec", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_RX_CONFIG, offsetof(rxConfig_t, rx_min_usec) },
Expand Down
1 change: 1 addition & 0 deletions src/main/pg/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void pgResetFn_rxConfig(rxConfig_t *rxConfig)
.sbus_baud_fast = false,
.crsf_use_rx_snr = false,
.msp_override_channels_mask = 0,
.crsf_use_negotiated_baud = false,
);

#ifdef RX_CHANNELS_TAER
Expand Down
1 change: 1 addition & 0 deletions src/main/pg/rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct rxConfig_s {
uint8_t sbus_baud_fast; // Select SBus fast baud rate
uint8_t crsf_use_rx_snr; // Use RX SNR (in dB) instead of RSSI dBm for CRSF
uint32_t msp_override_channels_mask; // Channels to override when the MSP override mode is enabled
uint8_t crsf_use_negotiated_baud; // Use negotiated baud rate for CRSF V3
} rxConfig_t;

PG_DECLARE(rxConfig_t, rxConfig);
5 changes: 5 additions & 0 deletions src/main/rx/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ void crsfRxUpdateBaudrate(uint32_t baudrate)
{
serialSetBaudRate(serialPort, baudrate);
}

bool crsfRxUseNegotiatedBaud(void)
{
return rxConfig()->crsf_use_negotiated_baud;
}
#endif

bool crsfRxIsActive(void)
Expand Down
1 change: 1 addition & 0 deletions src/main/rx/crsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ struct rxConfig_s;
struct rxRuntimeState_s;
bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeState_s *rxRuntimeState);
void crsfRxUpdateBaudrate(uint32_t baudrate);
bool crsfRxUseNegotiatedBaud(void);
bool crsfRxIsActive(void);
4 changes: 2 additions & 2 deletions src/main/telemetry/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void speedNegotiationProcess(uint32_t currentTime)
crsfRxSendTelemetryData();
} else {
if (crsfSpeed.hasPendingReply) {
bool found = crsfSpeed.index < BAUD_COUNT ? true : false;
bool found = ((crsfSpeed.index < BAUD_COUNT) && crsfRxUseNegotiatedBaud()) ? true : false;
sbuf_t crsfSpeedNegotiationBuf;
sbuf_t *dst = &crsfSpeedNegotiationBuf;
crsfInitializeFrame(dst);
Expand All @@ -440,7 +440,7 @@ void speedNegotiationProcess(uint32_t currentTime)
crsfFinalize(dst);
crsfRxSendTelemetryData();
crsfSpeed.hasPendingReply = false;
crsfSpeed.isNewSpeedValid = true;
crsfSpeed.isNewSpeedValid = found;
crsfSpeed.confirmationTime = currentTime;
return;
} else if (crsfSpeed.isNewSpeedValid) {
Expand Down

0 comments on commit 61f43fe

Please sign in to comment.