diff --git a/radio/src/gui/colorlcd/access_settings.cpp b/radio/src/gui/colorlcd/access_settings.cpp index ae48eb0afcc..22cae94ea51 100644 --- a/radio/src/gui/colorlcd/access_settings.cpp +++ b/radio/src/gui/colorlcd/access_settings.cpp @@ -707,14 +707,6 @@ void RxOptions::checkEvents() Dialog::checkEvents(); } -#define CH_ENABLE_SPORT 4 -#define CH_ENABLE_SBUS 5 - -#define CH_MAP_SBUS_IN (1 << 5) /* 0x20 */ -#define CH_MAP_SPORT (1 << 6) /* 0x40 */ -#define CH_MAP_SBUS_OUT (1 << 7) /* 0x80 */ -#define CH_MAP_FBUS (CH_MAP_SPORT | CH_MAP_SBUS_OUT) /* 0xC0 */ - static uint8_t getShiftedChannel(int8_t moduleIdx, int ch) { return g_model.moduleData[moduleIdx].channelsStart + ch; @@ -749,7 +741,7 @@ class OutputMappingChoice : public Choice } public: - OutputMappingChoice(Window* parent, uint32_t capabilities, + OutputMappingChoice(Window* parent, uint32_t capabilities, uint8_t rx_model_id, uint8_t module, uint8_t channels, uint8_t output_pin) : Choice(parent, rect_t{}, 0, channels - 1, std::bind(&OutputMappingChoice::get_output_mapping, this), @@ -760,23 +752,7 @@ class OutputMappingChoice : public Choice channels(channels), rx_pin(output_pin) { - if (capabilities & (1 << RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)) { - if (CH_ENABLE_SPORT == output_pin) { - setTextHandler([=] (int val) { - if (val == channels) return std::string(STR_SPORT); - return get_channel_text(val); - }); - setMax(channels); - return; - } else if (CH_ENABLE_SBUS == output_pin) { - setTextHandler([=] (int val) { - if (val == channels) return std::string(STR_SBUSOUT); - return get_channel_text(val); - }); - setMax(channels); - return; - } - } else if (capabilities & (1 << RECEIVER_CAPABILITY_CONFIGURABLE_PORTS)) { + if (isPXX2ReceiverOptionAvailable(rx_model_id, RECEIVER_OPTION_D_TELE_PORT)) { setTextHandler([=] (int val) { switch(val) { case CH_MAP_SBUS_IN: @@ -806,6 +782,24 @@ class OutputMappingChoice : public Choice setMax(CH_MAP_FBUS); return; } + + if (capabilities & (1 << RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)) { + if (CH_ENABLE_SPORT == output_pin) { + setTextHandler([=] (int val) { + if (val == channels) return std::string(STR_SPORT); + return get_channel_text(val); + }); + setMax(channels); + return; + } else if (CH_ENABLE_SBUS == output_pin) { + setTextHandler([=] (int val) { + if (val == channels) return std::string(STR_SBUSOUT); + return get_channel_text(val); + }); + setMax(channels); + return; + } + } setTextHandler(std::bind(&OutputMappingChoice::get_channel_text, this, std::placeholders::_1)); @@ -819,8 +813,8 @@ void RxOptions::update() auto& hwSettings = getPXX2HardwareAndSettingsBuffer(); auto& rxInfo = hwSettings.modules[moduleIdx].receivers[receiverIdx].information; - // uint8_t receiverModelId = rxInfo.modelID; - uint8_t receiverVariant = rxInfo.variant; + uint8_t rxModelId = rxInfo.modelID; + uint8_t rxVariant = rxInfo.variant; uint8_t capabilities = rxInfo.capabilities; FlexGridLayout grid(line_col_dsc, line_row_dsc, 2); @@ -858,7 +852,7 @@ void RxOptions::update() hwSettings.receiverSettings.telemetryDisabled = val; }); - if (isModuleR9MAccess(moduleIdx) && receiverVariant == PXX2_VARIANT_EU && + if (isModuleR9MAccess(moduleIdx) && rxVariant == PXX2_VARIANT_EU && hwSettings.moduleSettings.txPower > 14 /*25mW*/) { // read only field in this case tele25mw->disable(); @@ -933,7 +927,7 @@ void RxOptions::update() new StaticText(line, rect_t{}, std::string(STR_PIN) + i_str); uint8_t channels = sentModuleChannels(moduleIdx); - new OutputMappingChoice(line, capabilities, moduleIdx, channels, i); + new OutputMappingChoice(line, capabilities, rxModelId, moduleIdx, channels, i); } line = form->newLine(&grid); diff --git a/radio/src/gui/common/stdlcd/model_receiver_options.cpp b/radio/src/gui/common/stdlcd/model_receiver_options.cpp index 5fa6ca23564..8b1a06d5951 100644 --- a/radio/src/gui/common/stdlcd/model_receiver_options.cpp +++ b/radio/src/gui/common/stdlcd/model_receiver_options.cpp @@ -58,14 +58,6 @@ enum { #define IS_RECEIVER_CAPABILITY_ENABLED(capability) (reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilities & (1 << capability)) #define IF_RECEIVER_CAPABILITY(capability, count) uint8_t(IS_RECEIVER_CAPABILITY_ENABLED(capability) ? count : HIDDEN_ROW) -#define CH_ENABLE_SPORT 4 -#define CH_ENABLE_SBUS 5 - -#define CH_MAP_SBUS_IN (1 << 5) /* 0x20 */ -#define CH_MAP_SPORT (1 << 6) /* 0x40 */ -#define CH_MAP_SBUS_OUT (1 << 7) /* 0x80 */ -#define CH_MAP_FBUS (CH_MAP_SPORT | CH_MAP_SBUS_OUT) /* 0xC0 */ - bool isSPortModeAvailable(int mode) { uint8_t receiverId = reusableBuffer.hardwareAndSettings.receiverSettings.receiverId; @@ -237,35 +229,34 @@ void menuModelReceiverOptions(event_t event) } if (isPXX2ReceiverOptionAvailable(receiverModelId, RECEIVER_OPTION_D_TELE_PORT)) { - if (mapping == 0b01000000) { + if (mapping == CH_MAP_SPORT) { lcdDrawText(7 * FW, y, STR_SPORT, attr); mapping = channelMax + 1; - } - else if (mapping == 0b10000000) { + } else if (mapping == CH_MAP_SBUS_OUT) { lcdDrawText(7 * FW, y, STR_SBUSOUT, attr); mapping = channelMax + 2; - } - else if (mapping == 0b11000000) { + } else if (mapping == CH_MAP_FBUS) { lcdDrawText(7 * FW, y, STR_FBUS, attr); mapping = channelMax + 3; } if (pin == 0) { selectionMax = channelMax + 4; - if (mapping == 0b10100000) { + if (mapping == CH_MAP_SBUS_IN) { lcdDrawText(7 * FW, y, STR_SBUSIN, attr); mapping = selectionMax; } } - else if (IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)) { - if (CH_ENABLE_SPORT == pin) { - if (++selectionMax == mapping) { - lcdDrawText(7 * FW, y, STR_SPORT, attr); - } + else { + selectionMax = channelMax + 3; + } + } else if (IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6)) { + if (CH_ENABLE_SPORT == pin) { + if (++selectionMax == mapping) { + lcdDrawText(7 * FW, y, STR_SPORT, attr); } - else if (CH_ENABLE_SBUS == pin) { - if (++selectionMax == mapping) { - lcdDrawText(7 * FW, y, STR_SBUSOUT, attr); - } + } else if (CH_ENABLE_SBUS == pin) { + if (++selectionMax == mapping) { + lcdDrawText(7 * FW, y, STR_SBUSOUT, attr); } } } @@ -275,14 +266,15 @@ void menuModelReceiverOptions(event_t event) mapping = checkIncDec(event, mapping, 0, selectionMax); if (checkIncDec_Ret) { if (isPXX2ReceiverOptionAvailable(receiverModelId, RECEIVER_OPTION_D_TELE_PORT)) { - if (mapping == channelMax + 1) - mapping = 0b01000000; // S.Port - else if (mapping == channelMax + 2) - mapping = 0b10000000; // SBUS Out - else if (mapping == channelMax + 3) - mapping = 0b11000000; // FBUS - else if (mapping == channelMax + 4) - mapping = 0b10100000; // SBUS In + if (mapping == channelMax + 1) { + mapping = CH_MAP_SPORT; + } else if (mapping == channelMax + 2) { + mapping = CH_MAP_SBUS_OUT; + } else if (mapping == channelMax + 3) { + mapping = CH_MAP_FBUS; + } else if (mapping == channelMax + 4) { + mapping = CH_MAP_SBUS_IN; + } } reusableBuffer.hardwareAndSettings.receiverSettings.outputsMapping[pin] = mapping; reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; diff --git a/radio/src/pulses/pxx2.h b/radio/src/pulses/pxx2.h index 6c8c746cc5a..f634ea8fe12 100644 --- a/radio/src/pulses/pxx2.h +++ b/radio/src/pulses/pxx2.h @@ -71,6 +71,16 @@ #define PXX2_AUTH_REFUSED_FLAG 0xA5 +// Channel mapping constants +#define CH_ENABLE_SPORT 4 +#define CH_ENABLE_SBUS 5 + +#define CH_MAP_SPORT 0x40 +#define CH_MAP_SBUS_OUT 0x80 +#define CH_MAP_FBUS 0xC0 +#define CH_MAP_SBUS_IN 0xA0 + + enum PXX2ModuleModelID { PXX2_MODULE_NONE, PXX2_MODULE_XJT, @@ -126,7 +136,6 @@ enum ReceiverCapabilities { RECEIVER_CAPABILITY_FPORT2, RECEIVER_CAPABILITY_RACING_MODE, RECEIVER_CAPABILITY_SBUS24, - RECEIVER_CAPABILITY_CONFIGURABLE_PORTS, RECEIVER_CAPABILITY_COUNT };