diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 1551ffec8..bab5e977e 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -497,6 +497,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) case HasInternalModuleSupport: return (IS_STM32(board) && !IS_TARANIS_X9(board)); + case HasExternalModuleSupport: + return (IS_STM32(board) && !IS_RADIOMASTER_T8(board)); + case SportMaxBaudRate: if (IS_FAMILY_T16(board) || IS_FLYSKY_NV14(board) || IS_TARANIS_X7_ACCESS(board) || (IS_TARANIS(board) && !IS_TARANIS_XLITE(board) && !IS_TARANIS_X7(board) && !IS_TARANIS_X9LITE(board))) diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 6faba0022..71f298fef 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -150,6 +150,7 @@ namespace Board { HasColorLcd, HasSDCard, HasInternalModuleSupport, + HasExternalModuleSupport, SportMaxBaudRate }; diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index 181c27b0e..6cefde027 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -606,6 +606,38 @@ AbstractStaticItemModel * GeneralSettings::stickDeadZoneItemModel() return mdl; } +QString GeneralSettings::uartSampleModeToString() const +{ + return uartSampleModeToString(uartSampleMode); +} + +// static +QString GeneralSettings::uartSampleModeToString(int value) +{ + switch(value) { + case UART_SAMPLE_MODE_NORMAL: + return tr("Normal"); + case UART_SAMPLE_MODE_ONEBIT: + return tr("OneBit"); + default: + return CPN_STR_UNKNOWN_ITEM; + } +} + +// static +AbstractStaticItemModel * GeneralSettings::uartSampleModeItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName(AIM_GS_UARTSAMPLEMODE); + + for (int i = 0; i < UART_SAMPLE_MODE_COUNT; i++) { + mdl->appendToItemList(uartSampleModeToString(i), i); + } + + mdl->loadItemList(); + return mdl; +} + /* TrainerMix */ diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index 97ace924c..19248b203 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -41,6 +41,7 @@ constexpr char AIM_GS_BLUETOOTHMODE[] {"gs.bluetoothmode"}; constexpr char AIM_GS_SERIALMODE[] {"gs.serialmode%1"}; constexpr char AIM_GS_INTMODULEBAUDRATE[] {"gs.intmodulebaudrate"}; constexpr char AIM_GS_STICKDEADZONE[] {"gs.stickdeadzone"}; +constexpr char AIM_GS_UARTSAMPLEMODE[] {"gs.uartsamplemode"}; constexpr char AIM_TRAINERMIX_MODE[] {"trainermix.mode"}; constexpr char AIM_TRAINERMIX_SRC[] {"trainermix.src"}; @@ -153,6 +154,12 @@ class GeneralSettings { SP_COUNT, }; + enum UartSampleMode { + UART_SAMPLE_MODE_NORMAL, + UART_SAMPLE_MODE_ONEBIT, + UART_SAMPLE_MODE_COUNT + }; + GeneralSettings() { clear(); } void clear(); void init(); @@ -274,6 +281,7 @@ class GeneralSettings { QString bluetoothModeToString() const; QString serialPortModeToString(int port_nr) const; QString internalModuleBaudrateToString() const; + QString uartSampleModeToString() const; static QString antennaModeToString(int value); static QString bluetoothModeToString(int value); @@ -281,9 +289,12 @@ class GeneralSettings { static QString moduleBaudrateToString(int value); static FieldRange getPPM_MultiplierRange(); static FieldRange getTxCurrentCalibration(); + static QString uartSampleModeToString(int value); + static AbstractStaticItemModel * antennaModeItemModel(); static AbstractStaticItemModel * bluetoothModeItemModel(); static AbstractStaticItemModel * serialModeItemModel(int port_nr); static AbstractStaticItemModel * internalModuleBaudrateItemModel(); static AbstractStaticItemModel * stickDeadZoneItemModel(); + static AbstractStaticItemModel * uartSampleModeItemModel(); }; diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 7b9bdf0a6..f90bc896c 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -98,6 +98,7 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings int auxmodelid = editorItemModels->registerItemModel(GeneralSettings::serialModeItemModel(GeneralSettings::SP_AUX1)); int vcpmodelid = editorItemModels->registerItemModel(GeneralSettings::serialModeItemModel(GeneralSettings::SP_VCP)); int baudmodelid = editorItemModels->registerItemModel(GeneralSettings::internalModuleBaudrateItemModel()); + int uartmodelid = editorItemModels->registerItemModel(GeneralSettings::uartSampleModeItemModel()); id = editorItemModels->registerItemModel(ModuleData::internalModuleItemModel()); tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id)), FIM_INTERNALMODULES); @@ -123,29 +124,26 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings addParams(row, spnStickDeadZone); } - addSection(tr("Pots"), row); - count = Boards::getCapability(board, Board::Pots); count -= firmware->getCapability(HasFlySkyGimbals) ? 2 : 0; if (count > 0) { + addSection(tr("Pots"), row); for (int i = 0; i < count; i++) { addPot(i, row); } } - addSection(tr("Sliders"), row); - count = Boards::getCapability(board, Board::Sliders); if (count) { + addSection(tr("Sliders"), row); for (int i = 0; i < count; i++) { addSlider(i, row); } } - addSection(tr("Switches"), row); - count = Boards::getCapability(board, Board::Switches); if (count) { + addSection(tr("Switches"), row); for (int i = 0; i < count; i++) { addSwitch(i, row); } @@ -216,11 +214,20 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings row++; } + if (Boards::getCapability(board, Board::HasExternalModuleSupport)) { + addLabel(tr("Sample Mode"), row, 0); + AutoComboBox *uartSampleMode = new AutoComboBox(this); + uartSampleMode->setModel(editorItemModels->getItemModel(uartmodelid)); + uartSampleMode->setField(generalSettings.uartSampleMode); + addParams(row, uartSampleMode); + } + // All values except 0 are mutually exclusive ExclusiveComboGroup *exclGroup = new ExclusiveComboGroup( this, [=](const QVariant &value) { return value == 0; }); - addSection(tr("Serial port"), row); + if (firmware->getCapability(HasAuxSerialMode) || firmware->getCapability(HasAux2SerialMode) || firmware->getCapability(HasVCPSerialMode)) + addSection(tr("Serial ports"), row); if (firmware->getCapability(HasAuxSerialMode)) { QString lbl = "AUX1"; diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index 1c5f8f5eb..2b8661aa9 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -77,6 +77,7 @@ set(GUI_SRC radio_trainer.cpp radio_version.cpp hw_intmodule.cpp + hw_extmodule.cpp hw_inputs.cpp hw_serial.cpp radio_hardware.cpp diff --git a/radio/src/gui/colorlcd/hw_extmodule.cpp b/radio/src/gui/colorlcd/hw_extmodule.cpp new file mode 100644 index 000000000..db58573ec --- /dev/null +++ b/radio/src/gui/colorlcd/hw_extmodule.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "hw_extmodule.h" + +#include "opentx.h" + +#define SET_DIRTY() storageDirty(EE_GENERAL) + +static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(3), + LV_GRID_TEMPLATE_LAST}; + +static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; + +ExternalModuleWindow::ExternalModuleWindow(Window *parent) : + FormGroup::Line(parent), lastModule(g_eeGeneral.internalModule) +{ + FlexGridLayout grid(col_dsc, row_dsc, 2); + setLayout(&grid); + + new StaticText(this, rect_t{}, STR_SAMPLE_MODE, 0, COLOR_THEME_PRIMARY1); + + auto box = new FormGroup(this, rect_t{}); + box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); + lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0); + + new Choice(box, rect_t{}, STR_SAMPLE_MODES, 0, UART_SAMPLE_MODE_MAX, + getSampleMode, setSampleMode); +} + +int ExternalModuleWindow::getSampleMode() { return g_eeGeneral.uartSampleMode; } + +void ExternalModuleWindow::setSampleMode(int modeValue) +{ + g_eeGeneral.uartSampleMode = modeValue; + SET_DIRTY(); + restartModule(EXTERNAL_MODULE); +} diff --git a/radio/src/gui/colorlcd/hw_extmodule.h b/radio/src/gui/colorlcd/hw_extmodule.h new file mode 100644 index 000000000..d8fcd2706 --- /dev/null +++ b/radio/src/gui/colorlcd/hw_extmodule.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include "form.h" + +class ExternalModuleWindow : public FormGroup::Line +{ + public: + ExternalModuleWindow(Window* parent); + + protected: + uint8_t lastModule = 0; + lv_obj_t* br_box = nullptr; + + static int getSampleMode(); + static void setSampleMode(int modeValue); +}; diff --git a/radio/src/gui/colorlcd/radio_hardware.cpp b/radio/src/gui/colorlcd/radio_hardware.cpp index 030d7740c..e66e712ef 100644 --- a/radio/src/gui/colorlcd/radio_hardware.cpp +++ b/radio/src/gui/colorlcd/radio_hardware.cpp @@ -28,6 +28,7 @@ #include "hal/adc_driver.h" #include "aux_serial_driver.h" #include "hw_intmodule.h" +#include "hw_extmodule.h" #include "hw_serial.h" #include "hw_inputs.h" @@ -121,8 +122,14 @@ void RadioHardwarePage::build(FormWindow * window) #if defined(HARDWARE_INTERNAL_MODULE) new Subtitle(window, rect_t{}, TR_INTERNALRF, 0, COLOR_THEME_PRIMARY1); - auto mod = new InternalModuleWindow(window); - mod->padLeft(lv_dpx(8)); + auto intMod = new InternalModuleWindow(window); + intMod->padLeft(lv_dpx(8)); +#endif + +#if defined(HARDWARE_EXTERNAL_MODULE) + new Subtitle(window, rect_t{}, TR_EXTERNALRF, 0, COLOR_THEME_PRIMARY1); + auto extMod = new ExternalModuleWindow(window); + extMod->padLeft(lv_dpx(8)); #endif #if defined(BLUETOOTH) diff --git a/radio/src/targets/horus/telemetry_driver.cpp b/radio/src/targets/horus/telemetry_driver.cpp index 5475df6eb..0f48fe80b 100644 --- a/radio/src/targets/horus/telemetry_driver.cpp +++ b/radio/src/targets/horus/telemetry_driver.cpp @@ -91,6 +91,9 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode) } USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; + if (g_eeGeneral.uartSampleMode == UART_SAMPLE_MODE_ONEBIT) { + USART_OneBitMethodCmd(TELEMETRY_USART, ENABLE); + } USART_Init(TELEMETRY_USART, &USART_InitStructure); #if defined(PCBX12S)