Skip to content

Commit

Permalink
Merge pull request #10270 from iNavFlight/mmosca-sbus2-26chan
Browse files Browse the repository at this point in the history
Refactor sbus to support futaba's FASSTest26 sbus2 mode (Potentially 36 channels)
  • Loading branch information
mmosca authored Aug 2, 2024
2 parents 3cc11ce + 124a0d3 commit 607144e
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 22 deletions.
39 changes: 38 additions & 1 deletion src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ static const blackboxDeltaFieldDefinition_t blackboxMainFields[] = {
{"servo", 15, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_16)},
{"servo", 16, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_17)},
{"servo", 17, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_18)},
{"servo", 18, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_18)},
{"servo", 19, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_19)},
{"servo", 20, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_20)},
{"servo", 21, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_21)},
{"servo", 22, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_22)},
{"servo", 23, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_23)},
{"servo", 24, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_24)},
{"servo", 25, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_25)},
/*
{"servo", 26, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_26)},
{"servo", 27, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_27)},
{"servo", 27, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_28)},
{"servo", 28, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_29)},
{"servo", 29, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_30)},
{"servo", 30, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_31)},
{"servo", 31, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_32)},
{"servo", 32, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_33)},
{"servo", 33, UNSIGNED, .Ipredict = PREDICT(1500), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(AVERAGE_2), .Pencode = ENCODING(SIGNED_VB), CONDITION(AT_LEAST_SERVOS_34)},
*/

{"navState", -1, SIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
{"navFlags", -1, UNSIGNED, .Ipredict = PREDICT(0), .Iencode = ENCODING(SIGNED_VB), .Ppredict = PREDICT(PREVIOUS), .Pencode = ENCODING(SIGNED_VB), CONDITION(ALWAYS)},
Expand Down Expand Up @@ -675,7 +694,25 @@ static bool testBlackboxConditionUncached(FlightLogFieldCondition condition)
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_16:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_17:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_18:
return ((FlightLogFieldCondition)getServoCount() >= condition - FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_1 + 1) && blackboxIncludeFlag(BLACKBOX_FEATURE_SERVOS);
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_19:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_20:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_21:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_22:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_23:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_24:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_25:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_26:
/*
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_27:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_28:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_29:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_30:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_31:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_32:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_33:
case FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_34:
*/
return ((FlightLogFieldCondition)MIN(getServoCount(), 26) >= condition - FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_1 + 1) && blackboxIncludeFlag(BLACKBOX_FEATURE_SERVOS);

case FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_0:
case FLIGHT_LOG_FIELD_CONDITION_NONZERO_PID_D_1:
Expand Down
18 changes: 18 additions & 0 deletions src/main/blackbox/blackbox_fielddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ typedef enum FlightLogFieldCondition {
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_16,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_17,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_18,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_19,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_20,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_21,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_22,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_23,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_24,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_25,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_26,
/*
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_27,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_28,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_29,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_30,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_31,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_32,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_33,
FLIGHT_LOG_FIELD_CONDITION_AT_LEAST_SERVOS_34,
*/

FLIGHT_LOG_FIELD_CONDITION_MAG,
FLIGHT_LOG_FIELD_CONDITION_BARO,
Expand Down
2 changes: 1 addition & 1 deletion src/main/drivers/pwm_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define MAX_MOTORS 12
#endif

#define MAX_SERVOS 18
#define MAX_SERVOS 34

#define PWM_TIMER_HZ 1000000

Expand Down
12 changes: 11 additions & 1 deletion src/main/flight/servos.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "config/parameter_group.h"
#include "programming/logic_condition.h"

#define MAX_SUPPORTED_SERVOS 18
#define MAX_SUPPORTED_SERVOS 34

// These must be consecutive
typedef enum {
Expand Down Expand Up @@ -75,6 +75,16 @@ typedef enum {
INPUT_RC_CH22 = 47,
INPUT_RC_CH23 = 48,
INPUT_RC_CH24 = 49,
INPUT_RC_CH25 = 50,
INPUT_RC_CH26 = 51,
INPUT_RC_CH27 = 52,
INPUT_RC_CH28 = 53,
INPUT_RC_CH29 = 54,
INPUT_RC_CH30 = 55,
INPUT_RC_CH31 = 56,
INPUT_RC_CH32 = 57,
INPUT_RC_CH33 = 58,
INPUT_RC_CH34 = 59,
#endif
INPUT_SOURCE_COUNT
} inputSource_e;
Expand Down
4 changes: 2 additions & 2 deletions src/main/io/servo_sbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ void sbusServoUpdate(uint8_t index, uint16_t value)
case 13: sbusFrame.channels.chan13 = sbusEncodeChannelValue(value); break;
case 14: sbusFrame.channels.chan14 = sbusEncodeChannelValue(value); break;
case 15: sbusFrame.channels.chan15 = sbusEncodeChannelValue(value); break;
case 16: sbusFrame.channels.flags = value > PWM_RANGE_MIDDLE ? (sbusFrame.channels.flags | SBUS_FLAG_CHANNEL_17) : (sbusFrame.channels.flags & ~SBUS_FLAG_CHANNEL_17) ; break;
case 17: sbusFrame.channels.flags = value > PWM_RANGE_MIDDLE ? (sbusFrame.channels.flags | SBUS_FLAG_CHANNEL_18) : (sbusFrame.channels.flags & ~SBUS_FLAG_CHANNEL_18) ; break;
case 16: sbusFrame.channels.flags = value > PWM_RANGE_MIDDLE ? (sbusFrame.channels.flags | SBUS_FLAG_CHANNEL_DG1) : (sbusFrame.channels.flags & ~SBUS_FLAG_CHANNEL_DG1) ; break;
case 17: sbusFrame.channels.flags = value > PWM_RANGE_MIDDLE ? (sbusFrame.channels.flags | SBUS_FLAG_CHANNEL_DG2) : (sbusFrame.channels.flags & ~SBUS_FLAG_CHANNEL_DG2) ; break;
default:
break;
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/rx/rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ typedef enum {
SERIALRX_SBUS2,
} rxSerialReceiverType_e;

#ifdef USE_24CHANNELS
#define MAX_SUPPORTED_RC_CHANNEL_COUNT 26
#else
#define MAX_SUPPORTED_RC_CHANNEL_COUNT 18
#endif
#define MAX_SUPPORTED_RC_CHANNEL_COUNT 34

#define NON_AUX_CHANNEL_COUNT 4
#define MAX_AUX_CHANNEL_COUNT (MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT)
Expand Down
61 changes: 55 additions & 6 deletions src/main/rx/sbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@
typedef enum {
STATE_SBUS_SYNC = 0,
STATE_SBUS_PAYLOAD,
STATE_SBUS26_PAYLOAD,
STATE_SBUS_WAIT_SYNC
} sbusDecoderState_e;

typedef struct sbusFrameData_s {
sbusDecoderState_e state;
volatile sbusFrame_t frame;
volatile sbusFrame_t frameHigh;
volatile bool frameDone;
volatile bool is26channels;
uint8_t buffer[SBUS_FRAME_SIZE];
uint8_t position;
timeUs_t lastActivityTimeUs;
Expand All @@ -79,7 +82,10 @@ static void sbusDataReceive(uint16_t c, void *data)
sbusFrameData->lastActivityTimeUs = currentTimeUs;

// Handle inter-frame gap. We dwell in STATE_SBUS_WAIT_SYNC state ignoring all incoming bytes until we get long enough quite period on the wire
if (sbusFrameData->state == STATE_SBUS_WAIT_SYNC && timeSinceLastByteUs >= rxConfig()->sbusSyncInterval) {
if (timeSinceLastByteUs >= rxConfig()->sbusSyncInterval) {
sbusFrameData->state = STATE_SBUS_SYNC;
} else if ((sbusFrameData->state == STATE_SBUS_PAYLOAD || sbusFrameData->state == STATE_SBUS26_PAYLOAD) && timeSinceLastByteUs >= 300) {
// payload is pausing too long, possible if some telemetry have been sent between frames, or false positves mid frame
sbusFrameData->state = STATE_SBUS_SYNC;
}

Expand All @@ -89,6 +95,10 @@ static void sbusDataReceive(uint16_t c, void *data)
sbusFrameData->position = 0;
sbusFrameData->buffer[sbusFrameData->position++] = (uint8_t)c;
sbusFrameData->state = STATE_SBUS_PAYLOAD;
} else if ((uint8_t)c == SBUS2_HIGHFRAME_BEGIN_BYTE) {
sbusFrameData->position = 0;
sbusFrameData->buffer[sbusFrameData->position++] = (uint8_t)c;
sbusFrameData->state = STATE_SBUS26_PAYLOAD;
}
break;

Expand All @@ -115,7 +125,6 @@ static void sbusDataReceive(uint16_t c, void *data)
frameTime = -1;
}


frameValid = true;
sbusFrameData->state = STATE_SBUS_WAIT_SYNC;
break;
Expand All @@ -134,6 +143,40 @@ static void sbusDataReceive(uint16_t c, void *data)
}
break;

case STATE_SBUS26_PAYLOAD:
sbusFrameData->buffer[sbusFrameData->position++] = (uint8_t)c;

if (sbusFrameData->position == SBUS_FRAME_SIZE) {
const sbusFrame_t * frame = (sbusFrame_t *)&sbusFrameData->buffer[0];
bool frameValid = false;

// Do some sanity check
switch (frame->endByte) {
case 0x00:
case 0x04: // S.BUS 2 telemetry page 1
case 0x14: // S.BUS 2 telemetry page 2
case 0x24: // S.BUS 2 telemetry page 3
case 0x34: // S.BUS 2 telemetry page 4
frameTime = -1; // ignore this one, as you can't fit telemetry between this and the next frame.
frameValid = true;
sbusFrameData->state = STATE_SBUS_SYNC; // Next piece of data should be a sync byte
break;

default: // Failed end marker
frameValid = false;
sbusFrameData->state = STATE_SBUS_WAIT_SYNC;
break;
}

// Frame seems sane, pass data to decoder
if (!sbusFrameData->frameDone && frameValid) {
memcpy((void *)&sbusFrameData->frameHigh, (void *)&sbusFrameData->buffer[0], SBUS_FRAME_SIZE);
sbusFrameData->frameDone = true;
sbusFrameData->is26channels = true;
}
}
break;

case STATE_SBUS_WAIT_SYNC:
// Stay at this state and do nothing. Exit will be handled before byte is processed if the
// inter-frame gap is long enough
Expand All @@ -149,14 +192,20 @@ static uint8_t sbusFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
return RX_FRAME_PENDING;
}

uint8_t retValue = 0;
// Decode channel data and store return value
const uint8_t retValue = sbusChannelsDecode(rxRuntimeConfig, (void *)&sbusFrameData->frame.channels);
if (sbusFrameData->is26channels)
{
retValue = sbus26ChannelsDecode(rxRuntimeConfig, (void *)&sbusFrameData->frame.channels, false);
retValue |= sbus26ChannelsDecode(rxRuntimeConfig, (void *)&sbusFrameData->frameHigh.channels, true);

} else {
retValue = sbusChannelsDecode(rxRuntimeConfig, (void *)&sbusFrameData->frame.channels);
}

// Reset the frameDone flag - tell ISR that we're ready to receive next frame
sbusFrameData->frameDone = false;

//taskSendSbus2Telemetry(micros());

// Calculate "virtual link quality based on packet loss metric"
if (retValue & RX_FRAME_COMPLETE) {
lqTrackerAccumulate(rxRuntimeConfig->lqTracker, ((retValue & RX_FRAME_DROPPED) || (retValue & RX_FRAME_FAILSAFE)) ? 0 : RSSI_MAX_VALUE);
Expand All @@ -168,7 +217,7 @@ static uint8_t sbusFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
static bool sbusInitEx(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, uint32_t sbusBaudRate)
{
static uint16_t sbusChannelData[SBUS_MAX_CHANNEL];
static sbusFrameData_t sbusFrameData;
static sbusFrameData_t sbusFrameData = { .is26channels = false};

rxRuntimeConfig->channelData = sbusChannelData;
rxRuntimeConfig->frameData = &sbusFrameData;
Expand Down
1 change: 1 addition & 0 deletions src/main/rx/sbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#define SBUS_DEFAULT_INTERFRAME_DELAY_US 3000 // According to FrSky interframe is 6.67ms, we go smaller just in case
#define SBUS_MIN_SYNC_DELAY_US MS2US(2) // 2ms

#include "rx/rx.h"

Expand Down
55 changes: 53 additions & 2 deletions src/main/rx/sbus_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "common/utils.h"
#include "common/maths.h"

#include "build/debug.h"

#include "rx/sbus_channels.h"


Expand All @@ -34,6 +36,55 @@

STATIC_ASSERT(SBUS_FRAME_SIZE == sizeof(sbusFrame_t), SBUS_FRAME_SIZE_doesnt_match_sbusFrame_t);

uint8_t sbus26ChannelsDecode(rxRuntimeConfig_t *rxRuntimeConfig, const sbusChannels_t *channels, bool highChannels)
{
uint8_t offset = highChannels ? 16 : 0;
uint16_t *sbusChannelData = rxRuntimeConfig->channelData;
sbusChannelData[0 + offset] = channels->chan0;
sbusChannelData[1 + offset] = channels->chan1;
sbusChannelData[2 + offset] = channels->chan2;
sbusChannelData[3 + offset] = channels->chan3;
sbusChannelData[4 + offset] = channels->chan4;
sbusChannelData[5 + offset] = channels->chan5;
sbusChannelData[6 + offset] = channels->chan6;
sbusChannelData[7 + offset] = channels->chan7;
sbusChannelData[8 + offset] = channels->chan8;
sbusChannelData[9 + offset] = channels->chan9;
sbusChannelData[10 + offset] = channels->chan10;
sbusChannelData[11 + offset] = channels->chan11;
sbusChannelData[12 + offset] = channels->chan12;
sbusChannelData[13 + offset] = channels->chan13;
sbusChannelData[14 + offset] = channels->chan14;
sbusChannelData[15 + offset] = channels->chan15;

if (!highChannels) {
if (channels->flags & SBUS_FLAG_CHANNEL_DG1) {
sbusChannelData[32] = SBUS_DIGITAL_CHANNEL_MAX;
} else {
sbusChannelData[32] = SBUS_DIGITAL_CHANNEL_MIN;
}

if (channels->flags & SBUS_FLAG_CHANNEL_DG2) {
sbusChannelData[33] = SBUS_DIGITAL_CHANNEL_MAX;
} else {
sbusChannelData[33] = SBUS_DIGITAL_CHANNEL_MIN;
}
}

if (channels->flags & SBUS_FLAG_FAILSAFE_ACTIVE) {
// internal failsafe enabled and rx failsafe flag set
// RX *should* still be sending valid channel data, so use it.
return RX_FRAME_COMPLETE | RX_FRAME_FAILSAFE;
}

if (channels->flags & SBUS_FLAG_SIGNAL_LOSS) {
// The received data is a repeat of the last valid data so can be considered complete.
return RX_FRAME_COMPLETE | RX_FRAME_DROPPED;
}

return RX_FRAME_COMPLETE;
}

uint8_t sbusChannelsDecode(rxRuntimeConfig_t *rxRuntimeConfig, const sbusChannels_t *channels)
{
uint16_t *sbusChannelData = rxRuntimeConfig->channelData;
Expand All @@ -54,13 +105,13 @@ uint8_t sbusChannelsDecode(rxRuntimeConfig_t *rxRuntimeConfig, const sbusChannel
sbusChannelData[14] = channels->chan14;
sbusChannelData[15] = channels->chan15;

if (channels->flags & SBUS_FLAG_CHANNEL_17) {
if (channels->flags & SBUS_FLAG_CHANNEL_DG1) {
sbusChannelData[16] = SBUS_DIGITAL_CHANNEL_MAX;
} else {
sbusChannelData[16] = SBUS_DIGITAL_CHANNEL_MIN;
}

if (channels->flags & SBUS_FLAG_CHANNEL_18) {
if (channels->flags & SBUS_FLAG_CHANNEL_DG2) {
sbusChannelData[17] = SBUS_DIGITAL_CHANNEL_MAX;
} else {
sbusChannelData[17] = SBUS_DIGITAL_CHANNEL_MIN;
Expand Down
10 changes: 6 additions & 4 deletions src/main/rx/sbus_channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
#include <stdint.h>
#include "rx/rx.h"

#define SBUS_MAX_CHANNEL 18
#define SBUS_MAX_CHANNEL 34

#define SBUS_FLAG_CHANNEL_17 (1 << 0)
#define SBUS_FLAG_CHANNEL_18 (1 << 1)
#define SBUS_FLAG_CHANNEL_DG1 (1 << 0)
#define SBUS_FLAG_CHANNEL_DG2 (1 << 1)
#define SBUS_FLAG_SIGNAL_LOSS (1 << 2)
#define SBUS_FLAG_FAILSAFE_ACTIVE (1 << 3)

#define SBUS_CHANNEL_DATA_LENGTH sizeof(sbusChannels_t)
#define SBUS_FRAME_SIZE (SBUS_CHANNEL_DATA_LENGTH + 2)

#define SBUS_FRAME_BEGIN_BYTE 0x0F
#define SBUS_FRAME_BEGIN_BYTE ((uint8_t)0x0F)
#define SBUS2_HIGHFRAME_BEGIN_BYTE ((uint8_t)0x2F)

#define SBUS_BAUDRATE 100000
#define SBUS_BAUDRATE_FAST 200000
Expand Down Expand Up @@ -78,5 +79,6 @@ uint16_t sbusDecodeChannelValue(uint16_t sbusValue, bool safeValuesOnly);
uint16_t sbusEncodeChannelValue(uint16_t rcValue);

uint8_t sbusChannelsDecode(rxRuntimeConfig_t *rxRuntimeConfig, const sbusChannels_t *channels);
uint8_t sbus26ChannelsDecode(rxRuntimeConfig_t *rxRuntimeConfig, const sbusChannels_t *channels, bool highChannels);

void sbusChannelsInit(rxRuntimeConfig_t *rxRuntimeConfig);

0 comments on commit 607144e

Please sign in to comment.