From 734d5962ad8a72cee59fbd12e9d101328096d574 Mon Sep 17 00:00:00 2001 From: Tao Date: Mon, 11 Nov 2024 19:24:01 +0000 Subject: [PATCH 1/2] sbus_output: add msp support This is untested --- src/main/msp/msp.c | 32 ++++++++++++++++++++++++++++++-- src/main/msp/msp_protocol.h | 2 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/msp/msp.c b/src/main/msp/msp.c index 4f47c5283..8aa0974c2 100644 --- a/src/main/msp/msp.c +++ b/src/main/msp/msp.c @@ -124,6 +124,7 @@ #include "pg/usb.h" #include "pg/vcd.h" #include "pg/vtx_table.h" +#include "pg/sbus_output.h" #include "rx/rx.h" #include "rx/rx_bind.h" @@ -1011,7 +1012,7 @@ static bool mspCommonProcessOutCommand(int16_t cmdMSP, sbuf_t *dst, mspPostProce * * sbufWriteU8(dst, currentPidProfile->yourFancyParameterA); * sbufWriteU8(dst, currentPidProfile->yourFancyParameterB); - */ + */ break; default: @@ -1696,6 +1697,18 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst) break; #endif +#ifdef USE_SBUS_OUTPUT + case MSP_SBUS_OUTPUT_CONFIG: + for (int i = 0; i < SBUS_OUT_CHANNELS; i++) { + sbufWriteU8(dst, sbusOutConfigMutable()->sourceType[i]); + sbufWriteU8(dst, sbusOutConfigMutable()->sourceIndex[i]); + sbufWriteS16(dst, sbusOutConfigMutable()->sourceRangeLow[i]); + sbufWriteS16(dst, sbusOutConfigMutable()->sourceRangeHigh[i]); + } + sbufWriteU8(dst, sbusOutConfigMutable()->frameRate); + break; +#endif + case MSP_DATAFLASH_SUMMARY: serializeDataflashSummaryReply(dst); break; @@ -3238,6 +3251,21 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, break; #endif +#ifdef USE_SBUS_OUTPUT + case MSP_SET_SBUS_OUTPUT_CONFIG: + if (sbufBytesRemaining(src) >= 6 * SBUS_OUT_CHANNELS + 1) { + for (int i = 0; i < SBUS_OUT_CHANNELS; i++) { + sbusOutConfigMutable()->sourceType[i] = sbufReadU8(src); + sbusOutConfigMutable()->sourceIndex[i] = sbufReadU8(src); + sbusOutConfigMutable()->sourceRangeLow[i] = sbufReadS16(src); + sbusOutConfigMutable()->sourceRangeHigh[i] = sbufReadS16(src); + } + // You need to reset FC after updating ->sbusRate. + sbusOutConfigMutable()->frameRate = sbufReadU8(src); + } + break; +#endif + case MSP_SET_NAME: memset(pilotConfigMutable()->name, 0, ARRAYLEN(pilotConfig()->name)); for (unsigned int i = 0; i < MIN(MAX_NAME_LENGTH, dataSize); i++) { @@ -3565,7 +3593,7 @@ static mspResult_e mspCommonProcessInCommand(mspDescriptor_t srcDesc, int16_t cm * currentPidProfile->yourFancyParameterA = sbufReadU8(src); * currentPidProfile->yourFancyParameterB = sbufReadU8(src); * } - */ + */ break; default: diff --git a/src/main/msp/msp_protocol.h b/src/main/msp/msp_protocol.h index d258537fa..46bf54367 100644 --- a/src/main/msp/msp_protocol.h +++ b/src/main/msp/msp_protocol.h @@ -193,6 +193,8 @@ #define MSP_SET_GOVERNOR_PROFILE 149 #define MSP_LED_STRIP_SETTINGS 150 #define MSP_SET_LED_STRIP_SETTINGS 151 +#define MSP_SBUS_OUTPUT_CONFIG 152 +#define MSP_SET_SBUS_OUTPUT_CONFIG 153 #define MSP_EXPERIMENTAL 158 #define MSP_SET_EXPERIMENTAL 159 From a65c95cda1066b731228067e2b1a76d39bdf80e2 Mon Sep 17 00:00:00 2001 From: Tao Date: Thu, 5 Dec 2024 19:36:11 +0000 Subject: [PATCH 2/2] sbus_out: modify msp protocol: reduce write size --- src/main/msp/msp.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/msp/msp.c b/src/main/msp/msp.c index 8aa0974c2..b8e95e9d7 100644 --- a/src/main/msp/msp.c +++ b/src/main/msp/msp.c @@ -3252,18 +3252,25 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, #endif #ifdef USE_SBUS_OUTPUT - case MSP_SET_SBUS_OUTPUT_CONFIG: - if (sbufBytesRemaining(src) >= 6 * SBUS_OUT_CHANNELS + 1) { - for (int i = 0; i < SBUS_OUT_CHANNELS; i++) { - sbusOutConfigMutable()->sourceType[i] = sbufReadU8(src); - sbusOutConfigMutable()->sourceIndex[i] = sbufReadU8(src); - sbusOutConfigMutable()->sourceRangeLow[i] = sbufReadS16(src); - sbusOutConfigMutable()->sourceRangeHigh[i] = sbufReadS16(src); + case MSP_SET_SBUS_OUTPUT_CONFIG: { + // Write format is customized for the size and responsiveness. + // The first byte will be the target output channel index (0-based). + // The following bytes will be the type/index/low/high for that channel. + // `frameRate` is piggyback to any (all) indices for simplicity. + if (sbufBytesRemaining(src) >= 1) { + uint8_t index = sbufReadU8(src); + if (index < SBUS_OUT_CHANNELS && sbufBytesRemaining(src) >= 7) { + sbusOutConfigMutable()->sourceType[index] = sbufReadU8(src); + sbusOutConfigMutable()->sourceIndex[index] = sbufReadU8(src); + sbusOutConfigMutable()->sourceRangeLow[index] = sbufReadS16(src); + sbusOutConfigMutable()->sourceRangeHigh[index] = sbufReadS16(src); + + // You need to reset FC after updating ->frameRate. + sbusOutConfigMutable()->frameRate = sbufReadU8(src); } - // You need to reset FC after updating ->sbusRate. - sbusOutConfigMutable()->frameRate = sbufReadU8(src); } break; + } #endif case MSP_SET_NAME: