From ee274be303987c28fd26e88411378557f1ff566b Mon Sep 17 00:00:00 2001
From: Clyne Sullivan <clyne@bitgloo.com>
Date: Tue, 20 Oct 2020 20:14:08 -0400
Subject: firmware can port to L432KC; gui: edit buffer size

---
 gui/stmdsp.cpp | 11 +++++++++++
 gui/stmdsp.hpp |  2 ++
 gui/wxmain.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++---
 gui/wxmain.hpp |  1 +
 4 files changed, 57 insertions(+), 3 deletions(-)

(limited to 'gui')

diff --git a/gui/stmdsp.cpp b/gui/stmdsp.cpp
index 87b608d..633c61a 100644
--- a/gui/stmdsp.cpp
+++ b/gui/stmdsp.cpp
@@ -41,6 +41,17 @@ namespace stmdsp
         }
     }*/
 
+    void device::continuous_set_buffer_size(unsigned int size) {
+        if (connected()) {
+            uint8_t request[3] = {
+                'B',
+                static_cast<uint8_t>(size),
+                static_cast<uint8_t>(size >> 8)
+            };
+            m_serial.write(request, 3);
+        }
+    }
+
     void device::continuous_start() {
         if (connected())
             m_serial.write("R");
diff --git a/gui/stmdsp.hpp b/gui/stmdsp.hpp
index a9b8b7e..46113bf 100644
--- a/gui/stmdsp.hpp
+++ b/gui/stmdsp.hpp
@@ -8,6 +8,8 @@
 
 namespace stmdsp
 {
+    constexpr unsigned int SAMPLES_MAX = 4000;
+
     class scanner
     {
     private:
diff --git a/gui/wxmain.cpp b/gui/wxmain.cpp
index aa57066..c9e8b3d 100644
--- a/gui/wxmain.cpp
+++ b/gui/wxmain.cpp
@@ -28,6 +28,7 @@ enum Id {
     MRunMeasure,
     MRunUpload,
     MRunUnload,
+    MRunEditBSize,
     MRunGenUpload,
     MRunGenStart,
     MCodeCompile,
@@ -103,6 +104,8 @@ MainFrame::MainFrame() : wxFrame(nullptr, wxID_ANY, "stmdspgui", wxPoint(50, 50)
          menuRun->Append(MRunUpload, "&Upload code"));
     Bind(wxEVT_MENU, &MainFrame::onRunUnload, this, Id::MRunUnload, wxID_ANY,
          menuRun->Append(MRunUnload, "U&nload code"));
+    Bind(wxEVT_MENU, &MainFrame::onRunEditBSize, this, Id::MRunEditBSize, wxID_ANY,
+         menuRun->Append(MRunEditBSize, "Set &buffer size..."));
 
     menuRun->AppendSeparator();
     Bind(wxEVT_MENU, &MainFrame::onRunGenUpload, this, Id::MRunGenUpload, wxID_ANY,
@@ -409,10 +412,38 @@ void MainFrame::onRunStart(wxCommandEvent& ce)
     }
 }
 
+void MainFrame::onRunEditBSize([[maybe_unused]] wxCommandEvent&)
+{
+    if (m_device != nullptr && m_device->connected()) {
+        wxTextEntryDialog dialog (this, "Enter new buffer size (100-4000)", "Set Buffer Size");
+        if (dialog.ShowModal() == wxID_OK) {
+            if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
+                if (unsigned long n; value.ToULong(&n)) {
+                    if (n >= 100 && n <= stmdsp::SAMPLES_MAX) {
+                        m_device->continuous_set_buffer_size(n);
+                    } else {
+                        m_status_bar->SetStatusText("Error: Invalid buffer size.");
+                    }
+                } else {
+                    m_status_bar->SetStatusText("Error: Invalid buffer size.");
+                }
+            } else {
+                m_status_bar->SetStatusText("Ready.");
+            }
+        } else {
+            m_status_bar->SetStatusText("Ready.");
+        }
+    } else {
+        wxMessageBox("No device connected!", "Run", wxICON_WARNING);
+        m_status_bar->SetStatusText("Please connect.");
+    }
+}
+
 void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
 {
     if (m_device != nullptr && m_device->connected()) {
-        wxTextEntryDialog dialog (this, "Enter generator values", "Hey");
+        wxTextEntryDialog dialog (this, "Enter generator values below. Values must be whole numbers "
+                                        "between zero and 4095.", "Enter Generator Values");
         if (dialog.ShowModal() == wxID_OK) {
             if (wxString values = dialog.GetValue(); !values.IsEmpty()) {
                 std::vector<stmdsp::dacsample_t> samples;
@@ -436,8 +467,17 @@ void MainFrame::onRunGenUpload([[maybe_unused]] wxCommandEvent&)
                     }
                 }
 
-                m_device->siggen_upload(&samples[0], samples.size());
+                if (samples.size() <= stmdsp::SAMPLES_MAX) {
+                    m_device->siggen_upload(&samples[0], samples.size());
+                    m_status_bar->SetStatusText("Generator ready.");
+                } else {
+                    m_status_bar->SetStatusText("Error: Too many samples.");
+                }
+            } else {
+                m_status_bar->SetStatusText("Error: No samples given.");
             }
+        } else {
+            m_status_bar->SetStatusText("Ready.");
         }
     } else {
         wxMessageBox("No device connected!", "Run", wxICON_WARNING);
@@ -500,7 +540,7 @@ void MainFrame::onRunCompile([[maybe_unused]] wxCommandEvent&)
 void MainFrame::onCodeDisassemble([[maybe_unused]] wxCommandEvent&)
 {
     auto output = m_temp_file_name + ".asm.log";
-    wxString command = wxString("arm-none-eabi-objdump -d ") + m_temp_file_name + ".orig.o"
+    wxString command = wxString("arm-none-eabi-objdump -d --no-show-raw-insn ") + m_temp_file_name + ".orig.o"
                                 " > " + output + " 2>&1";
 
     if (system(command.ToAscii()) == 0) {
diff --git a/gui/wxmain.hpp b/gui/wxmain.hpp
index 0da0b79..60c3ee1 100644
--- a/gui/wxmain.hpp
+++ b/gui/wxmain.hpp
@@ -36,6 +36,7 @@ public:
     void onRunStart(wxCommandEvent&);
     void onRunUpload(wxCommandEvent&);
     void onRunUnload(wxCommandEvent&);
+    void onRunEditBSize(wxCommandEvent&);
     void onRunGenUpload(wxCommandEvent&);
     void onRunGenStart(wxCommandEvent&);
 
-- 
cgit v1.2.3