ChibiOS_*
**/.*
gui/stmdspgui
+*.o
--- /dev/null
+[submodule "gui/gui/serial"]
+ path = gui/gui/serial
+ url = https://github.com/wjwwood/serial
+[submodule "gui/serial"]
+ path = gui/serial
+ url = https://github.com/wjwwood/serial
CXXFLAGS = --std=c++20 -ggdb -Og \
-Wall -Wextra -pedantic \
-Wno-deprecated-copy \
+ -Iserial/include \
$(shell wx-config --cxxflags)
-CXXFILES = $(wildcard *.cpp)
+CXXFILES = $(shell find serial/src -name "*.cc") $(wildcard *.cpp)
+OFILES = $(patsubst %.cc, %.o, $(patsubst %.cpp, %.o, $(CXXFILES)))
LIBS = $(shell wx-config --libs)
OUTELF = stmdspgui
-all: $(CXXFILES)
- @echo " CXX " $(CXXFILES)
- @$(CXX) $(CXXFLAGS) $(CXXFILES) $(LIBS) -o $(OUTELF)
+all: $(OUTELF)
+
+$(OUTELF): $(OFILES)
+ @echo " CXX " $(OUTELF)
+ @$(CXX) $(CXXFLAGS) $(OFILES) $(LIBS) -o $(OUTELF)
+
+.cc.o:
+ @echo " CXX " $<
+ @$(CXX) $(CXXFLAGS) -c $< -o $@
+
+.cpp.o:
+ @echo " CXX " $<
+ @$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
@echo " CLEAN"
- @rm -f $(OUTELF)
+ @rm -f $(OUTELF) $(OFILES)
--- /dev/null
+Subproject commit cbcca7c83745fedd75afb7a0a27ee5c4112435c2
#include "stmdsp.hpp"
-#include <chrono>
-#include <filesystem>
-#include <thread>
-
-using namespace std::chrono_literals;
+#include <serial/serial.h>
namespace stmdsp
{
- void scanner::scan()
+ std::list<std::string>& scanner::scan()
{
- std::string path ("/dev/ttyACM0");
-
- for (unsigned int i = 0; i < 10; i++) {
- path.back() = '0' + i;
- if (std::filesystem::exists(path)) {
- if (device dev (path); dev.open()) {
- dev.write("i", 1);
- std::this_thread::sleep_for(1s);
- char buf[7];
- if (dev.read(buf, 6) == 6) {
- buf[6] = '\0';
- if (std::string(buf) == "stmdsp")
- m_devices.emplace(std::move(dev));
- }
- }
- }
+ auto serialDevices = serial::list_ports();
+ for (auto& device : serialDevices) {
+ if (device.hardware_id.find(STMDSP_USB_ID) != std::string::npos)
+ m_devices.emplace_front(device.port);
}
+
+ return m_devices;
}
}
#define STMDSP_HPP_
#include <fstream>
-#include <set>
+#include <list>
#include <string>
namespace stmdsp
{
- class device
- {
- public:
- device(const std::string& path) :
- m_path(path) {}
-
- bool open() {
- m_stream.open(m_path, std::ios_base::in | std::ios_base::out | std::ios_base::binary);
- return m_stream.is_open();
- }
-
- std::size_t read(char *buffer, std::size_t count) {
- return m_stream.readsome(buffer, count);
- }
-
- std::size_t write(const char *buffer, std::size_t count) {
- m_stream.write(buffer, count);
- return m_stream.good() ? count : 0;
- }
-
- const std::string& path() const {
- return m_path;
- }
-
- auto operator<=>(const device& other) const {
- return m_path <=> other.m_path;
- }
-
- private:
- std::string m_path;
- std::fstream m_stream;
- };
-
class scanner
{
private:
- constexpr static unsigned int STMDSP_VENDOR_ID = 0x0483;
- constexpr static unsigned int STMDSP_DEVICE_ID = 0x5740;
+ constexpr static const char *STMDSP_USB_ID = "USB VID:PID=0483:5740";
public:
- void scan();
- const auto& devices() const {
+ std::list<std::string>& scan();
+ auto& devices() {
return m_devices;
}
private:
- std::set<device> m_devices;
+ std::list<std::string> m_devices;
};
}
#ifndef WXMAIN_HPP_
#define WXMAIN_HPP_
+#include "stmdsp.hpp"
+
#include <wx/button.h>
+#include <wx/combobox.h>
#include <wx/dcclient.h>
#include <wx/frame.h>
#include <wx/stattext.h>
enum Id {
Welcome = 1,
Single,
+ SelectDevice,
RenderTimer
};
{
new wxStaticText(this, Id::Welcome, "Welcome to the GUI.", wxPoint(20, 20));
new wxButton(this, Id::Single, "Single", wxPoint(20, 60));
+ auto combo = new wxComboBox(this, Id::SelectDevice, "", wxPoint(470, 20), wxSize(150, 30));
+ combo->SetEditable(false);
+ stmdsp::scanner scanner;
+ for (auto& dev : scanner.scan())
+ combo->Append(dev);
+ if (combo->GetCount() > 0)
+ combo->SetSelection(0);
+
m_render_timer = new wxTimer(this, Id::RenderTimer);
Bind(wxEVT_BUTTON, &MainFrame::onSinglePressed, this, Id::Single);
\r
#include <array>\r
\r
+static_assert(sizeof(adcsample_t) == sizeof(uint16_t));\r
+\r
#if CACHE_LINE_SIZE > 0\r
CC_ALIGN(CACHE_LINE_SIZE)\r
#endif\r
if (char cmd; usbd.read(&cmd) > 0) {\r
switch (cmd) {\r
case 'r': // Read in analog signal\r
- adc.getSamples(&adc_samples[0], adc_samples.size());\r
+ adc.getSamples(&adc_samples[0], 100);//adc_samples.size());\r
usbd.write(adc_samples.data(), adc_samples.size());\r
break;\r
case 'i': // Identify ourself as an stmdsp device\r