Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CRSF RX binding via cli #13119

Merged
merged 2 commits into from Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/rx/crsf.c
Expand Up @@ -681,4 +681,22 @@ bool crsfRxIsActive(void)
{
return serialPort != NULL;
}

void crsfRxBind(void)
{
if (serialPort != NULL) {
uint8_t bindFrame[] = {
CRSF_SYNC_BYTE,
0x07, // frame length
CRSF_FRAMETYPE_COMMAND,
CRSF_ADDRESS_CRSF_RECEIVER,
CRSF_ADDRESS_FLIGHT_CONTROLLER,
CRSF_COMMAND_SUBCMD_RX,
CRSF_COMMAND_SUBCMD_RX_BIND,
0x9E, // Command CRC8
0xE8, // Packet CRC8
};
serialWriteBuf(serialPort, bindFrame, 9);
}
}
#endif
1 change: 1 addition & 0 deletions src/main/rx/crsf.h
Expand Up @@ -88,3 +88,4 @@ bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeState_
void crsfRxUpdateBaudrate(uint32_t baudrate);
bool crsfRxUseNegotiatedBaud(void);
bool crsfRxIsActive(void);
void crsfRxBind(void);
5 changes: 5 additions & 0 deletions src/main/rx/crsf_protocol.h
Expand Up @@ -60,9 +60,14 @@ typedef enum {
} crsfFrameType_e;

enum {
CRSF_COMMAND_SUBCMD_RX = 0x10, // receiver command
CRSF_COMMAND_SUBCMD_GENERAL = 0x0A, // general command
};

enum {
CRSF_COMMAND_SUBCMD_RX_BIND = 0x01, // bind command
};

enum {
CRSF_COMMAND_SUBCMD_GENERAL_CRSF_SPEED_PROPOSAL = 0x70, // proposed new CRSF port speed
CRSF_COMMAND_SUBCMD_GENERAL_CRSF_SPEED_RESPONSE = 0x71, // response to the proposed CRSF port speed
Expand Down
11 changes: 10 additions & 1 deletion src/main/rx/rx_bind.c
Expand Up @@ -24,12 +24,13 @@

#include "rx/rx_spi_common.h"
#include "rx/srxl2.h"
#include "rx/crsf.h"

#include "rx_bind.h"

static bool doRxBind(bool doBind)
{
#if !defined(USE_SERIALRX_SRXL2) && !defined(USE_RX_FRSKY_SPI) && !defined(USE_RX_SFHSS_SPI) && !defined(USE_RX_FLYSKY) && !defined(USE_RX_SPEKTRUM) && !defined(USE_RX_EXPRESSLRS)
#if !defined(USE_SERIALRX_SRXL2) && !defined(USE_RX_FRSKY_SPI) && !defined(USE_RX_SFHSS_SPI) && !defined(USE_RX_FLYSKY) && !defined(USE_RX_SPEKTRUM) && !defined(USE_RX_EXPRESSLRS) && !defined(USE_RX_CRSF)
UNUSED(doBind);
#endif

Expand All @@ -40,6 +41,14 @@ static bool doRxBind(bool doBind)
switch (rxRuntimeState.serialrxProvider) {
default:
return false;
#if defined(USE_RX_CRSF)
case SERIALRX_CRSF:
if (doBind) {
crsfRxBind();
}

break;
#endif
#if defined(USE_SERIALRX_SRXL2)
case SERIALRX_SRXL2:
if (doBind) {
Expand Down
1 change: 1 addition & 0 deletions src/main/target/common_pre.h
Expand Up @@ -152,6 +152,7 @@
#define USE_RX_SPI

#define USE_RX_CC2500
#define USE_RX_CRSF
#define USE_RX_EXPRESSLRS
#define USE_RX_SX1280
#define USE_RX_SX127X
Expand Down