Skip to content

Commit

Permalink
Merge pull request #10166 from iNavFlight/mmosca-crsf-bind
Browse files Browse the repository at this point in the history
bind_rx cli command now supports CRSF based receivers
  • Loading branch information
mmosca authored Jun 22, 2024
2 parents 411186a + 46477ef commit addfa59
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ bool cliMode = false;
#include "rx/rx.h"
#include "rx/spektrum.h"
#include "rx/srxl2.h"
#include "rx/crsf.h"

#include "scheduler/scheduler.h"

Expand Down Expand Up @@ -3224,6 +3225,12 @@ void cliRxBind(char *cmdline){
srxl2Bind();
cliPrint("Binding SRXL2 receiver...");
break;
#endif
#if defined(USE_SERIALRX_CRSF)
case SERIALRX_CRSF:
crsfBind();
cliPrint("Binding CRSF receiver...");
break;
#endif
}
}
Expand Down
25 changes: 24 additions & 1 deletion src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@

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

#include "scheduler/scheduler.h"

Expand Down Expand Up @@ -1030,6 +1032,7 @@ static bool mspFcProcessOutCommand(uint16_t cmdMSP, sbuf_t *dst, mspPostProcessF
case MSP_MIXER:
sbufWriteU8(dst, 3); // mixerMode no longer supported, send 3 (QuadX) as fallback
break;


case MSP_RX_CONFIG:
sbufWriteU8(dst, rxConfig()->serialrx_provider);
Expand Down Expand Up @@ -2887,7 +2890,7 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)
} else
return MSP_RESULT_ERROR;
break;

case MSP_SET_FAILSAFE_CONFIG:
if (dataSize == 20) {
failsafeConfigMutable()->failsafe_delay = sbufReadU8(src);
Expand Down Expand Up @@ -3352,6 +3355,26 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src)

break;

case MSP2_BETAFLIGHT_BIND:
if (rxConfig()->receiverType == RX_TYPE_SERIAL) {
switch (rxConfig()->serialrx_provider) {
default:
return MSP_RESULT_ERROR;
#if defined(USE_SERIALRX_SRXL2)
case SERIALRX_SRXL2:
srxl2Bind();
break;
#endif
#if defined(USE_SERIALRX_CRSF)
case SERIALRX_CRSF:
crsfBind();
break;
#endif
}
} else {
return MSP_RESULT_ERROR;
}
break;

default:
return MSP_RESULT_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/main/msp/msp_protocol_v2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
#define MSP2_COMMON_SET_RADAR_POS 0x100B //SET radar position information
#define MSP2_COMMON_SET_RADAR_ITD 0x100C //SET radar information to display

#define MSP2_BETAFLIGHT_BIND 0x3000
20 changes: 20 additions & 0 deletions src/main/rx/crsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,24 @@ bool crsfRxIsActive(void)
{
return serialPort != NULL;
}


void crsfBind(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
11 changes: 11 additions & 0 deletions src/main/rx/crsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ typedef enum {
CRSF_FRAMETYPE_DISPLAYPORT_CMD = 0x7D, // displayport control command
} 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
};

typedef struct crsfFrameDef_s {
uint8_t deviceAddress;
uint8_t frameLength;
Expand All @@ -124,3 +133,5 @@ struct rxConfig_s;
struct rxRuntimeConfig_s;
bool crsfRxInit(const struct rxConfig_s *initialRxConfig, struct rxRuntimeConfig_s *rxRuntimeConfig);
bool crsfRxIsActive(void);

void crsfBind(void);

0 comments on commit addfa59

Please sign in to comment.