]> code.bitgloo.com Git - clyne/stmdspgui.git/commitdiff
built-in openocd support 1/head
authorClyne Sullivan <clyne@bitgloo.com>
Wed, 25 May 2022 09:00:16 +0000 (21:00 -1200)
committerClyne Sullivan <clyne@bitgloo.com>
Wed, 25 May 2022 09:00:16 +0000 (21:00 -1200)
.gitignore
openocd.cfg [new file with mode: 0644]
source/gui_help.cpp [new file with mode: 0644]
source/main.cpp

index 9c562a6e88b1526c822f9796dcd0f8b2213bfe58..b23a6a31545e33629a7857cc5f500b654d7abd2b 100644 (file)
@@ -1,4 +1,5 @@
 build/
+openocd/
 imgui.ini
 stmdspgui
 stmdspgui.exe
diff --git a/openocd.cfg b/openocd.cfg
new file mode 100644 (file)
index 0000000..33f2c52
--- /dev/null
@@ -0,0 +1,2 @@
+source [find interface/stlink.cfg]\r
+source [find target/stm32l4x.cfg]
\ No newline at end of file
diff --git a/source/gui_help.cpp b/source/gui_help.cpp
new file mode 100644 (file)
index 0000000..a17d9fa
--- /dev/null
@@ -0,0 +1,113 @@
+#include "imgui.h"
+#include "ImGuiFileDialog.h"
+
+#include <cstdlib>
+#include <iostream>
+#include <string>
+#include <thread>
+
+void log(const std::string& str);
+
+static bool showDownloadFirmware = false;
+static bool showHelp = false;
+static std::string firmwareFile;
+
+static void helpDownloadThread();
+
+void helpRenderMenu()
+{
+    if (ImGui::BeginMenu("Help")) {
+        if (ImGui::MenuItem("Open wiki...")) {
+#ifdef STMDSP_WIN32
+            system("start "
+#else
+            system("xdg-open "
+#endif
+                "https://code.bitgloo.com/clyne/stmdspgui/wiki");
+        }
+
+        if (ImGui::MenuItem("Download firmware...")) {
+            showDownloadFirmware = true;
+        }
+
+        ImGui::Separator();
+        if (ImGui::MenuItem("About")) {
+            showHelp = true;
+        }
+
+        ImGui::EndMenu();
+    }
+}
+
+void helpRenderDialog()
+{
+    if (showDownloadFirmware) {
+       showDownloadFirmware = false;
+        ImGuiFileDialog::Instance()->OpenModal(
+            "ChooseFileFW", "Choose Firmware File", ".hex", ".");
+    }
+
+    if (ImGuiFileDialog::Instance()->Display("ChooseFileFW",
+                                             ImGuiWindowFlags_NoCollapse,
+                                             ImVec2(460, 540)))
+    {
+        if (ImGuiFileDialog::Instance()->IsOk()) {
+            firmwareFile = ImGuiFileDialog::Instance()->GetFilePathName();
+#ifdef STMDSP_WIN32
+            size_t i = 0;
+            while ((i = firmwareFile.find('\\', i)) != std::string::npos) {
+                firmwareFile.replace(i, 1, "\\\\");
+                i += 2;
+            }
+#endif
+
+           std::thread(helpDownloadThread).detach();
+        }
+
+        ImGuiFileDialog::Instance()->Close();
+    }
+
+    if (showHelp) {
+        ImGui::Begin("help");
+
+        ImGui::Text("stmdspgui\nCompiled on " __DATE__ ".\n\nWritten by Clyne Sullivan.\n");
+
+        if (ImGui::Button("Close")) {
+            showHelp = false;
+        }
+
+        ImGui::End();
+    }
+
+    if (!firmwareFile.empty()) {
+       ImGui::Begin("Downloading");
+
+       ImGui::Text("Downloading firmware to device...");
+
+       ImGui::End();
+    }
+}
+
+void helpDownloadThread()
+{
+    std::string command (
+#ifdef STMDSP_WIN32
+        "openocd\\bin\\openocd.exe"
+#else
+       "openocd"
+#endif
+       " -f openocd.cfg -c \"program $0 reset exit\"");
+
+    command.replace(command.find("$0"), 2, firmwareFile);
+
+    std::cout << "Run: " << command << std::endl;
+
+    if (system(command.c_str()) == 0) {
+       log("Programming finished.");    
+    } else {
+       log("Error while programming device!");
+    }
+
+    firmwareFile.clear();
+}
+
index b5514e4186e28bc148f62f395c486ec261f37f27..aa9f7c42d81623a71010f5549facf3de7eba570f 100644 (file)
@@ -37,6 +37,8 @@ bool guiInitialize();
 bool guiHandleEvents();
 void guiShutdown();
 void guiRender();
+void helpRenderMenu();
+void helpRenderDialog();
 
 void log(const std::string& str);
 
@@ -90,8 +92,6 @@ void log(const std::string& str)
 template<bool first>
 void renderWindow()
 {
-    static bool showHelp = false;
-
     // Start the new window frame and render the menu bar.
     ImGui_ImplOpenGL2_NewFrame();
     ImGui_ImplSDL2_NewFrame();
@@ -101,24 +101,7 @@ void renderWindow()
         fileRenderMenu();
         deviceRenderMenu();
         codeRenderMenu();
-
-        if (ImGui::BeginMenu("Help")) {
-            if (ImGui::MenuItem("Open wiki...")) {
-#ifdef STMDSP_WIN32
-                system("start "
-#else
-                system("xdg-open "
-#endif
-                    "https://code.bitgloo.com/clyne/stmdspgui/wiki");
-            }
-
-            ImGui::Separator();
-            if (ImGui::MenuItem("About")) {
-                showHelp = true;
-            }
-
-            ImGui::EndMenu();
-        }
+       helpRenderMenu();
 
         ImGui::EndMainMenuBar();
     }
@@ -142,6 +125,7 @@ void renderWindow()
     codeRenderToolbar();
     deviceRenderToolbar();
     fileRenderDialog();
+    helpRenderDialog();
     deviceRenderWidgets();
     ImGui::PopFont();
 
@@ -160,18 +144,6 @@ void renderWindow()
 
     deviceRenderDraw();
 
-    if (showHelp) {
-        ImGui::Begin("help");
-
-        ImGui::Text("stmdspgui\nCompiled on " __DATE__ ".\n\nWritten by Clyne Sullivan.\n");
-
-        if (ImGui::Button("Close")) {
-            showHelp = false;
-        }
-
-        ImGui::End();
-    }
-
     // Draw everything to the screen.
     guiRender();
 }