diff --git a/.gitignore b/.gitignore index 056645c..d7fc7b4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ build eagle/*#* gui/stmdspgui doc/guide.odt +*.exe +*.dll diff --git a/gui/Makefile b/gui/Makefile index 6b01fc0..25b1872 100644 --- a/gui/Makefile +++ b/gui/Makefile @@ -1,19 +1,52 @@ +UNAME := $(shell uname) + +ifeq ($(UNAME), Linux) + RM = rm -f +else + RM = del +endif + CXX = g++-10 CXXFLAGS = --std=c++20 -ggdb -O0 \ -Wall -Wextra -pedantic \ -Wno-deprecated-copy \ -Iserial/include -IMETL/include -IMETL/dependencies/PEGTL/include \ - $(shell wx-config --cxxflags) + -Wa,-mbig-obj +ifeq ($(UNAME), Linux) +CXXFLAGS += $(shell wx-config --cxxflags) +else +CXXFLAGS += -IC:\wx\include -DSTMDSP_WIN32 +endif + +ifeq ($(UNAME), Linux) CXXFILES = serial/src/serial.cc \ serial/src/impl/unix.cc \ serial/src/impl/list_ports/list_ports_linux.cc \ $(wildcard *.cpp) +else +CXXFILES = serial/src/serial.cc \ + serial/src/impl/win.cc \ + serial/src/impl/list_ports/list_ports_win.cc \ + $(wildcard *.cpp) +endif OFILES = $(patsubst %.cc, %.o, $(patsubst %.cpp, %.o, $(CXXFILES))) +ifeq ($(UNAME), Linux) LIBS = $(shell wx-config --libs) -lwx_gtk3u_stc-3.1 +else +LIBS = -lSetupAPI \ + -LC:\wx\lib\gcc810_x64_dll -lwxbase31u -lwxmsw31u_core -lwxmsw31u_stc +endif + OUTELF = stmdspgui +ifeq ($(UNAME), Linux) +CLEANFILES = $(OUTELF) $(OFILES) +else +CLEANFILES = $(subst /,\\,$(OUTELF)) $(subst /,\\,$(OFILES)) +endif + all: $(OUTELF) $(OUTELF): $(OFILES) @@ -30,5 +63,5 @@ $(OUTELF): $(OFILES) clean: @echo " CLEAN" - @rm -f $(OUTELF) $(OFILES) + @$(RM) $(CLEANFILES) diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp index 2293c71..7a55562 100644 --- a/gui/stmdsp.cpp +++ b/gui/stmdsp.cpp @@ -30,6 +30,7 @@ namespace stmdsp m_serial(file, 1000000/*230400*/, serial::Timeout::simpleTimeout(50)) { if (m_serial.isOpen()) { + m_serial.flush(); m_serial.write("i"); if (auto id = m_serial.read(7); id.starts_with("stmdsp")) { if (id.back() == 'h') diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp index d56a1ab..c15633a 100644 --- a/gui/stmdsp.hpp +++ b/gui/stmdsp.hpp @@ -24,7 +24,12 @@ namespace stmdsp class scanner { private: - constexpr static const char *STMDSP_USB_ID = "USB VID:PID=0483:5740"; + constexpr static const char *STMDSP_USB_ID = +#ifndef STMDSP_WIN32 + "USB VID:PID=0483:5740"; +#else + "USB\\VID_0483&PID_5740"; +#endif public: std::list& scan(); diff --git a/gui/wxmain.cpp b/gui/wxmain.cpp index 1eebe28..98c08ff 100644 --- a/gui/wxmain.cpp +++ b/gui/wxmain.cpp @@ -12,6 +12,7 @@ #include "wxmain.hpp" #include +#include #include #include #include @@ -26,9 +27,12 @@ #include #include -#include #include +#ifndef WIN32 +#include +#endif + #include "wxmain_devdata.h" enum Id { @@ -81,7 +85,7 @@ MainFrame::MainFrame() : m_compile_output = new wxTextCtrl(panelOutput, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(620, 250), - wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL); + wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH2); m_measure_timer = new wxTimer(this, Id::MeasureTimer); m_menu_bar = new wxMenuBar; m_rate_select = new wxComboBox(panelToolbar, wxID_ANY, @@ -89,12 +93,17 @@ MainFrame::MainFrame() : wxDefaultPosition, wxDefaultSize, srateValues.size(), srateValues.data(), wxCB_READONLY); +#ifndef WIN32 m_device_samples = reinterpret_cast(::mmap( nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); m_device_samples_input = reinterpret_cast(::mmap( nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)); +#else + m_device_samples = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX]; + m_device_samples_input = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX]; +#endif m_menu_bar->Append(menuFile, "&File"); m_menu_bar->Append(menuRun, "&Run"); @@ -102,7 +111,7 @@ MainFrame::MainFrame() : SetMenuBar(m_menu_bar); // Toolbar initialization - auto comp = new wxButton(panelToolbar, Id::MCodeCompile, "Compile"); + auto comp = new wxButton(this, wxID_ANY, "Compile", {10, 10}); sizerToolbar->Add(comp, 0, wxLEFT, 4); sizerToolbar->Add(m_rate_select, 0, wxLEFT, 12); panelToolbar->SetSizer(sizerToolbar); @@ -122,7 +131,7 @@ MainFrame::MainFrame() : // Main splitter init. mainSplitter->SetSashGravity(0.5); mainSplitter->SetMinimumPaneSize(20); - mainSplitter->SplitHorizontally(panelCode, panelOutput, 440); + mainSplitter->SplitHorizontally(panelCode, panelOutput, 100); sizerMain->Add(mainSplitter, 1, wxEXPAND, 5); sizerMain->SetSizeHints(this); SetSizer(sizerMain); @@ -138,9 +147,8 @@ MainFrame::MainFrame() : Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY); // Toolbar actions - Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, comp); - Bind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY, m_rate_select); - + Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY, comp); + Bind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY, m_rate_select); // File menu actions Bind(wxEVT_MENU, &MainFrame::onFileNew, this, Id::MFileNew, wxID_ANY, menuFile->Append(MFileNew, "&New")); @@ -169,9 +177,9 @@ MainFrame::MainFrame() : // Code menu actions Bind(wxEVT_MENU, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY, menuCode->Append(MCodeCompile, "&Compile code")); Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY, menuCode->Append(MCodeDisassemble, "Show &Disassembly")); - menuCode->AppendSeparator(); updateMenuOptions(); + comp->Raise(); } // Closes the window @@ -186,8 +194,8 @@ void MainFrame::onCloseEvent(wxCloseEvent& event) delete m_measure_timer; delete m_device; - Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY); - Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, Id::MCodeCompile, wxID_ANY); + Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY); + Unbind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY); event.Skip(); } @@ -203,9 +211,10 @@ void MainFrame::onMeasureTimer(wxTimerEvent&) if (m_conv_result_log) { for (auto& s : samples) { - auto str = std::to_string(s); + auto str = std::to_string(s) + ','; m_conv_result_log->Write(str.c_str(), str.size()); } + m_conv_result_log->Write("\n", 1); } if (m_run_draw_samples->IsChecked()) { samples = m_device->continuous_read_input(); @@ -250,7 +259,7 @@ void MainFrame::onPaint(wxPaintEvent&) this->GetSize().GetHeight() - py - 60 }; - auto *dc = new wxPaintDC(this); + auto *dc = new wxBufferedPaintDC(this); dc->SetBrush(*wxBLACK_BRUSH); dc->SetPen(*wxBLACK_PEN); dc->DrawRectangle(rect); @@ -321,38 +330,56 @@ void MainFrame::prepareEditor() wxString MainFrame::compileEditorCode() { - if (m_device == nullptr) { - m_status_bar->SetStatusText("Need device connected to compile."); - return ""; + stmdsp::platform platform; + if (m_device != nullptr) { + platform = m_device->get_platform(); + } else { + m_status_bar->SetStatusText("Assuming L4 platform..."); + platform = stmdsp::platform::L4; } if (m_temp_file_name.IsEmpty()) m_temp_file_name = wxFileName::CreateTempFileName("stmdspgui"); wxFile file (m_temp_file_name, wxFile::write); - wxString file_text (m_device->get_platform() == stmdsp::platform::L4 ? file_header_l4 - : file_header_h7); + wxString file_text (platform == stmdsp::platform::L4 ? file_header_l4 + : file_header_h7); file_text.Replace("$0", std::to_string(m_device ? m_device->get_buffer_size() : stmdsp::SAMPLES_MAX)); file.Write(wxString(file_text) + m_text_editor->GetText()); file.Close(); - wxFile makefile (m_temp_file_name + ".sh", wxFile::write); - wxString make_text (m_device->get_platform() == stmdsp::platform::L4 ? makefile_text_l4 - : makefile_text_h7); + constexpr const char *script_ext = +#ifndef STMDSP_WIN32 + ".sh"; +#else + ".bat"; +#endif + + wxFile makefile (m_temp_file_name + script_ext, wxFile::write); + wxString make_text (platform == stmdsp::platform::L4 ? makefile_text_l4 + : makefile_text_h7); make_text.Replace("$0", m_temp_file_name); makefile.Write(make_text); makefile.Close(); - wxString make_output = m_temp_file_name + ".sh.log"; - wxString make_command = m_temp_file_name + ".sh > " + make_output + " 2>&1"; - - system(wxString("chmod +x ") + m_temp_file_name + ".sh"); - int result = system(make_command.ToAscii()); - m_compile_output->LoadFile(make_output); + wxString make_output = m_temp_file_name + script_ext + ".log"; + wxString make_command = m_temp_file_name + script_ext + " > " + + make_output + " 2>&1"; + +#ifndef STMDSP_WIN32 + system(wxString("chmod +x ") + m_temp_file_name + script_ext); +#endif + int result = system(make_command.ToAscii()); + wxFile result_file (make_output); + wxString result_text; + result_file.ReadAll(&result_text); + result_file.Close(); + m_compile_output->Clear(); + m_compile_output->WriteText(result_text); wxRemoveFile(m_temp_file_name); - wxRemoveFile(m_temp_file_name + ".sh"); + wxRemoveFile(m_temp_file_name + script_ext); wxRemoveFile(make_output); if (result == 0) { @@ -380,19 +407,21 @@ void MainFrame::onCodeDisassemble(wxCommandEvent&) " > " + output + " 2>&1"; if (system(command.ToAscii()) == 0) { - m_compile_output->LoadFile(output); + wxFile result_file (output); + wxString result_text; + result_file.ReadAll(&result_text); + result_file.Close(); + m_compile_output->Clear(); + m_compile_output->WriteText(result_text); + wxRemoveFile(output); m_status_bar->SetStatusText(wxString::Format(wxT("Done. Line count: %u."), m_compile_output->GetNumberOfLines())); } else { - m_compile_output->ChangeValue(""); m_status_bar->SetStatusText("Failed to load disassembly."); } } else { - m_compile_output->ChangeValue(""); m_status_bar->SetStatusText("Need to compile code before analyzing."); } - - wxRemoveFile(output); } wxMenu *MainFrame::loadTemplates() diff --git a/gui/wxmain_devdata.cpp b/gui/wxmain_devdata.cpp index 0862f63..0f384fa 100644 --- a/gui/wxmain_devdata.cpp +++ b/gui/wxmain_devdata.cpp @@ -17,20 +17,25 @@ const std::array srateNums { 96000 }; -#ifdef WIN32 +#ifdef STMDSP_WIN32 #define NEWLINE "\r\n" +#define COPY "copy" #else #define NEWLINE "\n" +#define COPY "cp" #endif // $0 = temp file name const char *makefile_text_h7 = +#ifdef STMDSP_WIN32 + "echo off" NEWLINE +#endif "arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti " "-mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -mtune=cortex-m7 " "-nostartfiles " "-Wl,-Ttext-segment=0x00000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry " "$0 -o $0.o" NEWLINE - "cp $0.o $0.orig.o" NEWLINE + COPY " $0.o $0.orig.o" NEWLINE "arm-none-eabi-strip -s -S --strip-unneeded $0.o" NEWLINE "arm-none-eabi-objcopy --remove-section .ARM.attributes " "--remove-section .comment " @@ -38,12 +43,15 @@ const char *makefile_text_h7 = "$0.o" NEWLINE "arm-none-eabi-size $0.o" NEWLINE; const char *makefile_text_l4 = +#ifdef STMDSP_WIN32 + "echo off" NEWLINE +#endif "arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti " "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 " "-nostartfiles " "-Wl,-Ttext-segment=0x10000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry " "$0 -o $0.o" NEWLINE - "cp $0.o $0.orig.o" NEWLINE + COPY " $0.o $0.orig.o" NEWLINE "arm-none-eabi-strip -s -S --strip-unneeded $0.o" NEWLINE "arm-none-eabi-objcopy --remove-section .ARM.attributes " "--remove-section .comment "