From 0da292001df119a7be8016c65dbe97eaa2ad10a2 Mon Sep 17 00:00:00 2001 From: 3djc Date: Wed, 1 Oct 2025 11:07:08 +0200 Subject: [PATCH] feat(h7): increase GVAR limit to 15 (#6597) Co-authored-by: elecpower --- companion/src/constants.h | 2 +- .../src/firmwares/adjustmentreference.cpp | 6 ++ companion/src/firmwares/boards.h | 13 +++++ .../src/firmwares/customfunctiondata.cpp | 2 +- .../src/firmwares/edgetx/yaml_modeldata.cpp | 58 ++++++++++++------- .../src/firmwares/edgetx/yaml_rawsource.cpp | 3 +- .../src/firmwares/opentx/opentxinterface.cpp | 4 +- companion/src/firmwares/rawsource.cpp | 3 + radio/src/datastructs.h | 10 ++-- radio/src/gui/128x64/model_flightmodes.cpp | 10 +++- radio/src/gvars.h | 4 ++ .../storage/yaml/yaml_datastructs_funcs.cpp | 4 ++ .../storage/yaml/yaml_datastructs_pa01.cpp | 6 +- .../storage/yaml/yaml_datastructs_st16.cpp | 6 +- .../storage/yaml/yaml_datastructs_t15pro.cpp | 6 +- .../storage/yaml/yaml_datastructs_tx15.cpp | 6 +- 16 files changed, 100 insertions(+), 43 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 50bfcfc5e..b46395efa 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -30,7 +30,7 @@ #define CPN_MAX_EXPOS 64 #define CPN_MAX_CURVES 32 #define CPN_MAX_POINTS 17 -#define CPN_MAX_GVARS 9 +#define CPN_MAX_GVARS 15 // 0, 9, 15 #define CPN_MAX_ENCODERS 2 // rotary encoders #define CPN_MAX_CHNOUT 32 // number of real output channels #define CPN_MAX_LOGICAL_SWITCHES 64 // number of custom switches diff --git a/companion/src/firmwares/adjustmentreference.cpp b/companion/src/firmwares/adjustmentreference.cpp index 739dd8c0d..86d87e043 100644 --- a/companion/src/firmwares/adjustmentreference.cpp +++ b/companion/src/firmwares/adjustmentreference.cpp @@ -21,6 +21,7 @@ #include "adjustmentreference.h" #include "modeldata.h" +#include "eeprominterface.h" AdjustmentReference::AdjustmentReference(int value) { @@ -80,5 +81,10 @@ QString AdjustmentReference::toString(const ModelData * model, const bool sign) const bool AdjustmentReference::isAvailable() const { + Firmware *firmware = getCurrentFirmware(); + + if (type == ADJUST_REF_GVAR && abs(value) > firmware->getCapability(Gvars)) + return false; + return true; } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 1507e8137..6ad445293 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -837,3 +837,16 @@ inline bool HAS_EEPROM_YAML(Board::Type board) { return IS_FAMILY_HORUS_OR_T16(board); } + +inline bool IS_STM32H5(Board::Type board) +{ + return false; +} + +inline bool IS_STM32H7(Board::Type board) +{ + return IS_FLYSKY_PA01(board) || + IS_FLYSKY_ST16(board) || + IS_JUMPER_T15PRO(board) || + IS_RADIOMASTER_TX15(board); +} diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 8366bc81d..0518bfda0 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -262,7 +262,7 @@ bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * mode (model ? model->timers[index - FuncSetTimer1].isModeOff() : false))) || ((index == FuncScreenshot) && !IS_HORUS_OR_TARANIS(fw->getBoard())) || ((index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) && !fw->getCapability(DangerousFunctions)) || - ((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) || + ((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && ((index - FuncAdjustGV1) >= fw->getCapability(Gvars))) || ((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard())) || ((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))) || ((index == FuncRGBLed && !(Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO) || Boards::getCapability(fw->getBoard(), Board::FunctionSwitchColors)))) || diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 0886a600a..7e1146b28 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -512,30 +512,46 @@ bool convert::decode(const Node& node, TimerData& rhs) static int32_t YamlReadLimitValue(const YAML::Node& node, int32_t shift = 0) { - std::string val = node.as(); - if ((val.size() >= 4) - && (val[0] == '-') - && (val[1] == 'G') - && (val[2] == 'V') - && (val[3] >= '1') - && (val[3] <= '9')) { - - return -10000 - std::stoi(val.substr(3)); - } - - if ((val.size() >= 3) - && (val[0] == 'G') - && (val[1] == 'V') - && (val[2] >= '1') - && (val[2] <= '9')) { - - return 10000 + std::stoi(val.substr(2)); - } + Firmware *firmware = getCurrentFirmware(); + std::string val_str = node.as(); try { - return std::stoi(val) + shift; + return std::stoi(val_str) + shift; } catch(...) { - throw YAML::TypedBadConversion(node.Mark()); + try { + const char* val = val_str.data(); + int multiplier = 1; + + if (val_str.size() >= 4 + && val[0] == '-') { + + multiplier = -1; + val_str = val_str.substr(1); + } + + if (val_str.size() >= 3 + && val[0] == 'G' + && val[1] == 'V') { + + int32_t num = 0; + + try { + num = std::stoi(val_str.substr(2)); + } catch (...) { + throw; + } + + if (num <= firmware->getCapability(Gvars)) + return ((10000 * multiplier) + (num * multiplier)); + else + return 0; + + } else { + throw "Invalid value"; + } + } catch(...) { + throw YAML::TypedBadConversion(node.Mark()); + } } } diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 88c2f8bf8..416ea9757 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -137,6 +137,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) RawSource YamlRawSourceDecode(const std::string& src_str) { + Firmware *firmware = getCurrentFirmware(); Board::Type board = getCurrentBoard(); Boards b = Boards(board); RawSource rhs; @@ -251,7 +252,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::stringstream src(src_str_tmp.substr(3)); int gv = 0; src >> gv; - if (gv < CPN_MAX_GVARS) + if (gv < firmware->getCapability(Gvars)) rhs = RawSource(SOURCE_TYPE_GVAR, gv + 1); } else if (val_len > 5 && diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 0086bd6f1..cfe992c15 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -95,7 +95,9 @@ int OpenTxFirmware::getCapability(::Capability capability) else return id.contains("heli") ? 1 : 0; case Gvars: - if (IS_HORUS_OR_TARANIS(board)) + if (IS_STM32H7(board) || IS_STM32H5(board)) + return id.contains("nogvars") ? 0 : 15; + else if (IS_HORUS_OR_TARANIS(board)) return id.contains("nogvars") ? 0 : 9; else if (id.contains("gvars")) return 9; diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index 98bdcfe23..68f699bd9 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -324,6 +324,9 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings if (type == SOURCE_TYPE_CYC && !firmware->getCapability(Heli)) return false; + if (type == SOURCE_TYPE_GVAR && abs(index) > firmware->getCapability(Gvars)) + return false; + if (model) { if (type == SOURCE_TYPE_TIMER && model->timers[abs(index) - 1].isModeOff()) return false; diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 154f652a2..0715096e1 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -51,7 +51,7 @@ static inline void check_struct() CHKSIZE(GVarData, 7); CHKSIZE(RFAlarmData, 2); CHKSIZE(TrainerData, 16); - CHKSIZE(FlightModeData, 22 + 2 * MAX_TRIMS + LEN_FLIGHT_MODE_NAME); + CHKSIZE(FlightModeData, 4 + 2 * MAX_GVARS + 2 * MAX_TRIMS + LEN_FLIGHT_MODE_NAME); CHKSIZE(CustomFunctionData, 11); #if defined(PCBX7) || defined(PCBXLITE) || defined(PCBX9LITE) @@ -119,15 +119,15 @@ static inline void check_struct() CHKSIZE(ModelData, 27693); #endif #elif defined(PCBST16) - CHKSIZE(ModelData, 27761); + CHKSIZE(ModelData, 27911); #elif defined(PCBPA01) - CHKSIZE(ModelData, 27522); + CHKSIZE(ModelData, 27672); #elif defined(RADIO_T15) CHKSIZE(ModelData, 27683); #elif defined(RADIO_T15PRO) - CHKSIZE(ModelData, 27761); + CHKSIZE(ModelData, 27911); #elif defined(RADIO_TX15) - CHKSIZE(ModelData, 27761); + CHKSIZE(ModelData, 27911); #elif defined(RADIO_H7RS) // CHKSIZE() #elif defined(PCBHORUS) diff --git a/radio/src/gui/128x64/model_flightmodes.cpp b/radio/src/gui/128x64/model_flightmodes.cpp index 8388edb0d..e02fc389e 100644 --- a/radio/src/gui/128x64/model_flightmodes.cpp +++ b/radio/src/gui/128x64/model_flightmodes.cpp @@ -39,7 +39,7 @@ enum MenuModelFlightModeItems { ITEM_MODEL_FLIGHT_MODE_TRIMS2, ITEM_MODEL_FLIGHT_MODE_FADE_IN, ITEM_MODEL_FLIGHT_MODE_FADE_OUT, -#if defined(GVARS) +#if MAX_GVARS > 0 ITEM_MODEL_FLIGHT_MODE_GVARS_LABEL, ITEM_MODEL_FLIGHT_MODE_GV1, ITEM_MODEL_FLIGHT_MODE_GV2, @@ -50,6 +50,14 @@ enum MenuModelFlightModeItems { ITEM_MODEL_FLIGHT_MODE_GV7, ITEM_MODEL_FLIGHT_MODE_GV8, ITEM_MODEL_FLIGHT_MODE_GV9, +#if MAX_GVARS > 9 + ITEM_MODEL_FLIGHT_MODE_GV10, + ITEM_MODEL_FLIGHT_MODE_GV11, + ITEM_MODEL_FLIGHT_MODE_GV12, + ITEM_MODEL_FLIGHT_MODE_GV13, + ITEM_MODEL_FLIGHT_MODE_GV14, + ITEM_MODEL_FLIGHT_MODE_GV15, +#endif #endif ITEM_MODEL_FLIGHT_MODE_MAX }; diff --git a/radio/src/gvars.h b/radio/src/gvars.h index 877d7af38..85f1b3eae 100644 --- a/radio/src/gvars.h +++ b/radio/src/gvars.h @@ -25,7 +25,11 @@ #define GVAR_MAX 1024 #define GVAR_MIN -GVAR_MAX +#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32H5) +#define MAX_GVARS 15 +#else #define MAX_GVARS 9 +#endif // GVars have one value per flight mode #define GVAR_VALUE(gv, fm) g_model.flightModeData[fm].gvars[gv] diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 17a222a69..4dc05da5b 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -48,7 +48,11 @@ static inline void check_yaml_funcs() { static_assert(offsetof(ModuleData, ppm) == 4,""); check_size(); +#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32H5) + static_assert(MAX_GVARS == 15,""); +#else static_assert(MAX_GVARS == 9,""); +#endif } static bool w_semver(void* user, uint8_t* data, uint32_t bitoffs, diff --git a/radio/src/storage/yaml/yaml_datastructs_pa01.cpp b/radio/src/storage/yaml/yaml_datastructs_pa01.cpp index 4cf06b8c7..af8b6ab38 100644 --- a/radio/src/storage/yaml/yaml_datastructs_pa01.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_pa01.cpp @@ -567,7 +567,7 @@ static const struct YamlNode struct_FlightModeData[] = { YAML_PADDING( 6 ), YAML_UNSIGNED( "fadeIn", 8 ), YAML_UNSIGNED( "fadeOut", 8 ), - YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active), + YAML_ARRAY("gvars", 16, 15, struct_signed_16, gvar_is_active), YAML_END }; static const struct YamlNode struct_GVarData[] = { @@ -902,11 +902,11 @@ static const struct YamlNode struct_ModelData[] = { YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL), YAML_ARRAY("customFn", 88, 64, struct_CustomFunctionData, cfn_is_active), YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), - YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), + YAML_ARRAY("flightModeData", 448, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), YAML_ARRAY("switchWarning", 2, 32, struct_swtchWarn, nullptr), - YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), + YAML_ARRAY("gvars", 56, 15, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), YAML_STRUCT("rssiAlarms", 0, struct_RssiAlarmData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_st16.cpp b/radio/src/storage/yaml/yaml_datastructs_st16.cpp index 3255a773f..985f94be4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_st16.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_st16.cpp @@ -567,7 +567,7 @@ static const struct YamlNode struct_FlightModeData[] = { YAML_PADDING( 6 ), YAML_UNSIGNED( "fadeIn", 8 ), YAML_UNSIGNED( "fadeOut", 8 ), - YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active), + YAML_ARRAY("gvars", 16, 15, struct_signed_16, gvar_is_active), YAML_END }; static const struct YamlNode struct_GVarData[] = { @@ -902,11 +902,11 @@ static const struct YamlNode struct_ModelData[] = { YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL), YAML_ARRAY("customFn", 88, 64, struct_CustomFunctionData, cfn_is_active), YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), - YAML_ARRAY("flightModeData", 384, 9, struct_FlightModeData, fmd_is_active), + YAML_ARRAY("flightModeData", 480, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), YAML_ARRAY("switchWarning", 2, 32, struct_swtchWarn, nullptr), - YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), + YAML_ARRAY("gvars", 56, 15, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), YAML_STRUCT("rssiAlarms", 0, struct_RssiAlarmData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_t15pro.cpp b/radio/src/storage/yaml/yaml_datastructs_t15pro.cpp index 3255a773f..985f94be4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t15pro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t15pro.cpp @@ -567,7 +567,7 @@ static const struct YamlNode struct_FlightModeData[] = { YAML_PADDING( 6 ), YAML_UNSIGNED( "fadeIn", 8 ), YAML_UNSIGNED( "fadeOut", 8 ), - YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active), + YAML_ARRAY("gvars", 16, 15, struct_signed_16, gvar_is_active), YAML_END }; static const struct YamlNode struct_GVarData[] = { @@ -902,11 +902,11 @@ static const struct YamlNode struct_ModelData[] = { YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL), YAML_ARRAY("customFn", 88, 64, struct_CustomFunctionData, cfn_is_active), YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), - YAML_ARRAY("flightModeData", 384, 9, struct_FlightModeData, fmd_is_active), + YAML_ARRAY("flightModeData", 480, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), YAML_ARRAY("switchWarning", 2, 32, struct_swtchWarn, nullptr), - YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), + YAML_ARRAY("gvars", 56, 15, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), YAML_STRUCT("rssiAlarms", 0, struct_RssiAlarmData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tx15.cpp b/radio/src/storage/yaml/yaml_datastructs_tx15.cpp index 3255a773f..985f94be4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx15.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx15.cpp @@ -567,7 +567,7 @@ static const struct YamlNode struct_FlightModeData[] = { YAML_PADDING( 6 ), YAML_UNSIGNED( "fadeIn", 8 ), YAML_UNSIGNED( "fadeOut", 8 ), - YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active), + YAML_ARRAY("gvars", 16, 15, struct_signed_16, gvar_is_active), YAML_END }; static const struct YamlNode struct_GVarData[] = { @@ -902,11 +902,11 @@ static const struct YamlNode struct_ModelData[] = { YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL), YAML_ARRAY("customFn", 88, 64, struct_CustomFunctionData, cfn_is_active), YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), - YAML_ARRAY("flightModeData", 384, 9, struct_FlightModeData, fmd_is_active), + YAML_ARRAY("flightModeData", 480, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), YAML_ARRAY("switchWarning", 2, 32, struct_swtchWarn, nullptr), - YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), + YAML_ARRAY("gvars", 56, 15, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), YAML_STRUCT("rssiAlarms", 0, struct_RssiAlarmData, NULL),