Skip to content

Commit b536884

Browse files
committed
Implements CRSF 0x26 RC Extended Channels Packed Payload (tbs-fpv/tbs-crsf-spec#28)
(cherry picked from commit ea78554)
1 parent a7a1f37 commit b536884

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

radio/src/pulses/crossfire.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,35 @@ uint8_t createCrossfireChannelsFrame(uint8_t moduleIdx, uint8_t * frame, int16_t
133133
return buf - frame;
134134
}
135135

136+
// Range for pulses (channels output) is [-1024:+1024]
137+
uint8_t createCrossfireExtendedChannelsFrame(uint8_t moduleIdx, uint8_t * frame, int16_t * pulses)
138+
{
139+
//
140+
// sends extended channel data
141+
ModuleData *md = &g_model.moduleData[moduleIdx];
142+
143+
uint8_t * buf = frame;
144+
*buf++ = MODULE_ADDRESS;
145+
*buf++ = 24; // 1(ID) + 22(channel data) + 1(CRC)
146+
uint8_t * crc_start = buf;
147+
*buf++ = EXTENDED_CHANNELS_ID;
148+
uint32_t bits = 0;
149+
uint8_t bitsavailable = 0;
150+
for (int i=0; i<CROSSFIRE_CHANNELS_COUNT; i++) {
151+
uint32_t val = limit(0, CROSSFIRE_CENTER + (CROSSFIRE_CENTER_CH_OFFSET(i) * 4) / 5 + (pulses[i+16] * 4) / 5, 2 * CROSSFIRE_CENTER);
152+
bits |= val << bitsavailable;
153+
bitsavailable += CROSSFIRE_CH_BITS;
154+
while (bitsavailable >= 8) {
155+
*buf++ = bits;
156+
bits >>= 8;
157+
bitsavailable -= 8;
158+
}
159+
}
160+
161+
*buf++ = crc8(crc_start, 23);
162+
return buf - frame;
163+
}
164+
136165
static void setupPulsesCrossfire(uint8_t module, uint8_t*& p_buf,
137166
uint8_t endpoint, int16_t* channels,
138167
uint8_t nChannels)
@@ -185,6 +214,7 @@ static void setupPulsesCrossfire(uint8_t module, uint8_t*& p_buf,
185214
} else {
186215
/* TODO: nChannels */
187216
p_buf += createCrossfireChannelsFrame(module, p_buf, channels);
217+
p_buf += createCrossfireExtendedChannelsFrame(module, p_buf, channels);
188218
}
189219
}
190220
}

radio/src/telemetry/crossfire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define LINK_TX_ID 0x1D
4747
#define ATTITUDE_ID 0x1E
4848
#define FLIGHT_MODE_ID 0x21
49+
#define EXTENDED_CHANNELS_ID 0x26
4950
#define PING_DEVICES_ID 0x28
5051
#define DEVICE_INFO_ID 0x29
5152
#define REQUEST_SETTINGS_ID 0x2A

0 commit comments

Comments
 (0)