Skip to content

Commit 26305f6

Browse files
authored
Added crsf-shot (#1018)
1 parent d1aa774 commit 26305f6

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/crsf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#define TYPE_SETTINGS_ENTRY 0x2B
3535
#define TYPE_SETTINGS_READ 0x2C
3636
#define TYPE_SETTINGS_WRITE 0x2D
37+
#define TYPE_RADIO_ID 0x3A
38+
39+
// Frame Subtype
40+
#define SUBTYPE_TIMING_UPDATE 0x10
3741

3842
#define TELEMETRY_RX_PACKET_SIZE 64
3943

src/protocol/crsf_uart.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
#include "telemetry.h"
2525
#endif
2626

27+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
28+
2729
#define CRSF_DATARATE 400000
28-
#define CRSF_FRAME_PERIOD 4000 // 4ms
30+
#define CRSF_FRAME_PERIOD 4000 // 250Hz 4ms
31+
#define CRSF_FRAME_PERIOD_MIN 2000 // 500Hz 2ms
32+
#define CRSF_FRAME_PERIOD_MAX 40000 // 25Hz 40ms
2933
#define CRSF_CHANNELS 16
3034
#define CRSF_PACKET_SIZE 26
3135

@@ -57,6 +61,7 @@ u8 crsf_crc8(const u8 *ptr, u8 len) {
5761
return crc;
5862
}
5963

64+
static u32 updateInterval = CRSF_FRAME_PERIOD;
6065

6166
#if HAS_EXTENDED_TELEMETRY
6267
static u8 telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE];
@@ -128,7 +133,7 @@ static void processCrossfireTelemetryFrame()
128133
for (i=1; i <= TELEM_CRSF_TX_SNR; i++) {
129134
if (getCrossfireTelemetryValue(2+i, &value, 1)) { // payload starts at third byte of rx packet
130135
if (i == TELEM_CRSF_TX_POWER) {
131-
static const s32 power_values[] = { 0, 10, 25, 100, 500, 1000, 2000, 250 };
136+
static const s32 power_values[] = { 0, 10, 25, 100, 500, 1000, 2000, 250, 50 };
132137
if ((u8)value >= (sizeof power_values / sizeof (s32)))
133138
continue;
134139
value = power_values[value];
@@ -160,6 +165,15 @@ static void processCrossfireTelemetryFrame()
160165
memcpy(&value, &telemetryRxBuffer[3], 4);
161166
set_telemetry(TELEM_CRSF_FLIGHT_MODE, value);
162167
break;
168+
169+
case TYPE_RADIO_ID:
170+
if (telemetryRxBuffer[3] == ADDR_RADIO && telemetryRxBuffer[5] == SUBTYPE_TIMING_UPDATE) {
171+
if (getCrossfireTelemetryValue(6, (s32 *)&updateInterval, 4)) {
172+
// offset is not used since deviationTX handles the offset by itself (mixer_runtime)
173+
// values are in 10th of micro-seconds
174+
updateInterval /= 10;
175+
}
176+
}
163177
}
164178
}
165179

@@ -185,7 +199,7 @@ static void processCrossfireTelemetryData(u8 data, u8 status) {
185199

186200
if ((telemetryRxBuffer[1] + 2) == telemetryRxBufferCount) {
187201
if (checkCrossfireTelemetryFrameCRC()) {
188-
if (telemetryRxBuffer[2] < TYPE_PING_DEVICES) {
202+
if (telemetryRxBuffer[2] < TYPE_PING_DEVICES || telemetryRxBuffer[2] == TYPE_RADIO_ID) {
189203
processCrossfireTelemetryFrame(); // Broadcast frame
190204
#if SUPPORT_CRSF_CONFIG
191205
} else {
@@ -286,7 +300,7 @@ static u16 serial_cb()
286300
UART_Send(packet, length);
287301
state = ST_DATA1;
288302

289-
return CRSF_FRAME_PERIOD - mixer_runtime;
303+
return constrain(updateInterval, CRSF_FRAME_PERIOD_MIN, CRSF_FRAME_PERIOD_MAX) - mixer_runtime;
290304
}
291305

292306
return CRSF_FRAME_PERIOD; // avoid compiler warning

0 commit comments

Comments
 (0)