Skip to content

Commit

Permalink
update rx and telemetry code
Browse files Browse the repository at this point in the history
  • Loading branch information
shanggl committed Jan 24, 2024
1 parent 2b4ac6e commit 698b44f
Show file tree
Hide file tree
Showing 34 changed files with 723 additions and 674 deletions.
3 changes: 2 additions & 1 deletion src/main/rx/a7105_flysky.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ static void checkRSSI(void)
setRssiDirect(tmp, RSSI_SOURCE_RX_PROTOCOL);
}

static bool isValidPacket(const uint8_t *packet) {
static bool isValidPacket(const uint8_t *packet)
{
const flySky2ARcDataPkt_t *rcPacket = (const flySky2ARcDataPkt_t*) packet;
return (rcPacket->rxId == rxId && rcPacket->txId == txId);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/rx/cc2500_frsky_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ static void buildTelemetryFrame(uint8_t *packet)
case FRSKY_SPI_A1_SOURCE_EXTADC:
a1Value = (adcGetChannel(ADC_EXTERNAL1) & 0xff0) >> 4;
break;
#if defined(USE_TELEMETRY_FRSKY_HUB)
case FRSKY_SPI_A1_SOURCE_CONST:
a1Value = A1_CONST_D & 0xff;
break;
#endif
case FRSKY_SPI_A1_SOURCE_VBAT:
default:
a1Value = (getBatteryVoltage() / 5) & 0xff;
Expand All @@ -150,7 +152,8 @@ static void buildTelemetryFrame(uint8_t *packet)

#define FRSKY_D_CHANNEL_SCALING (2.0f / 3)

static void decodeChannelPair(uint16_t *channels, const uint8_t *packet, const uint8_t highNibbleOffset) {
static void decodeChannelPair(uint16_t *channels, const uint8_t *packet, const uint8_t highNibbleOffset)
{
channels[0] = FRSKY_D_CHANNEL_SCALING * (uint16_t)((packet[highNibbleOffset] & 0xf) << 8 | packet[0]);
channels[1] = FRSKY_D_CHANNEL_SCALING * (uint16_t)((packet[highNibbleOffset] & 0xf0) << 4 | packet[1]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/rx/cc2500_frsky_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ const cc2500RegisterConfigElement_t cc2500FrskyXLbtV2Config[] =
{ CC2500_08_PKTCTRL0, 0x05 },
};

static void initialise() {
static void initialise(void)
{
rxSpiStartupSpeed();

cc2500Reset();
Expand Down
14 changes: 10 additions & 4 deletions src/main/rx/cc2500_frsky_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ static uint8_t remoteToProcessIndex = 0;
static uint8_t packetLength;
static uint16_t telemetryDelayUs;

static uint16_t crcTable(uint8_t val) {
static uint16_t crcTable(uint8_t val)
{
uint16_t word;
word = (*(&crcTable_Short[val & 0x0f]));
val /= 16;
return word ^ (0x1081 * val);
}

static uint16_t calculateCrc(const uint8_t *data, uint8_t len) {
static uint16_t calculateCrc(const uint8_t *data, uint8_t len)
{
uint16_t crc = 0;
for (unsigned i = 0; i < len; i++) {
crc = (crc << 8) ^ crcTable((uint8_t)(crc >> 8) ^ *data++);
Expand Down Expand Up @@ -225,9 +227,10 @@ static void buildTelemetryFrame(uint8_t *packet)
outFrameMarker->raw = responseToSend.raw & SEQUENCE_MARKER_REMOTE_PART;
outFrameMarker->data.packetSequenceId = localPacketId;

#if defined(USE_TELEMETRY_SMARTPORT)
frame[6] = appendSmartPortData(&frame[7]);
memcpy(&telemetryTxBuffer[localPacketId], &frame[6], TELEMETRY_FRAME_SIZE);

#endif
localPacketId = (localPacketId + 1) % TELEMETRY_SEQUENCE_LENGTH;
}
}
Expand All @@ -238,13 +241,16 @@ static void buildTelemetryFrame(uint8_t *packet)
frame[14]=lcrc;
}

#if defined(USE_TELEMETRY_SMARTPORT)
static bool frSkyXReadyToSend(void)
{
return true;
}
#endif

#if defined(USE_TELEMETRY_SMARTPORT)
static void frSkyXTelemetrySendByte(uint8_t c) {
static void frSkyXTelemetrySendByte(uint8_t c)
{
if (c == FSSP_DLE || c == FSSP_START_STOP) {
telemetryOutBuffer[telemetryOutWriter] = FSSP_DLE;
telemetryOutWriter = (telemetryOutWriter + 1) % TELEMETRY_OUT_BUFFER_SIZE;
Expand Down
4 changes: 3 additions & 1 deletion src/main/rx/cc2500_redpine.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const cc2500RegisterConfigElement_t cc2500RedPineConfig[] =
{ CC2500_3E_PATABLE, 0xFF }
};

static void initialise()
static void initialise(void)
{
cc2500Reset();

Expand Down Expand Up @@ -400,10 +400,12 @@ void redpineSetRcData(uint16_t *rcData, const uint8_t *packet)
{
if (packet[CHANNEL_START] == VTX_STATUS_FRAME && packet[CHANNEL_START + 1] == 0) {
if (!ARMING_FLAG(ARMED)) {
#ifdef USE_VTX
vtxSettingsConfigMutable()->band = packet[5] + 1;
vtxSettingsConfigMutable()->channel = packet[6];
vtxSettingsConfigMutable()->power = packet[7];
saveConfigAndNotify();
#endif
}
} else {
uint16_t channelValue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/rx/cc2500_sfhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const cc2500RegisterConfigElement_t cc2500SfhssConfigPart2[] =
{ CC2500_3E_PATABLE, 0xFF }
};

static void initialise()
static void initialise(void)
{
cc2500Reset();

Expand Down
18 changes: 18 additions & 0 deletions src/main/rx/crsf.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 698b44f

Please sign in to comment.