found formula library; cleaned up wxmain file split

master
Clyne 4 years ago
parent 5515642bf8
commit c59fdd8805

@ -2,7 +2,7 @@ CXX = g++-10
CXXFLAGS = --std=c++20 -ggdb -O0 \ CXXFLAGS = --std=c++20 -ggdb -O0 \
-Wall -Wextra -pedantic \ -Wall -Wextra -pedantic \
-Wno-deprecated-copy \ -Wno-deprecated-copy \
-Iserial/include \ -Iserial/include -IMETL/include -IMETL/dependencies/PEGTL/include \
$(shell wx-config --cxxflags) $(shell wx-config --cxxflags)
CXXFILES = serial/src/serial.cc \ CXXFILES = serial/src/serial.cc \

File diff suppressed because it is too large Load Diff

@ -10,7 +10,6 @@
*/ */
#include "wxmain.hpp" #include "wxmain.hpp"
#include "wxsiggen.hpp"
#include <wx/combobox.h> #include <wx/combobox.h>
#include <wx/dcclient.h> #include <wx/dcclient.h>
@ -55,9 +54,6 @@ enum Id {
MCodeDisassemble MCodeDisassemble
}; };
#include "wxmain_mfile.h"
#include "wxmain_mrun.h"
MainFrame::MainFrame() : MainFrame::MainFrame() :
wxFrame(nullptr, wxID_ANY, "stmdspgui", wxDefaultPosition, wxSize(640, 800)) wxFrame(nullptr, wxID_ANY, "stmdspgui", wxDefaultPosition, wxSize(640, 800))
{ {

@ -0,0 +1,167 @@
#include "wxmain_devdata.h"
const std::array<wxString, 6> srateValues {
"8 kS/s",
"16 kS/s",
"20 kS/s",
"32 kS/s",
"48 kS/s",
"96 kS/s"
};
const std::array<unsigned int, 6> srateNums {
8000,
16000,
20000,
32000,
48000,
96000
};
const char *makefile_text_h7 = R"make(
all:
@arm-none-eabi-g++ -x c++ -Os -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
@cp $0.o $0.orig.o
@arm-none-eabi-strip -s -S --strip-unneeded $0.o
@arm-none-eabi-objcopy --remove-section .ARM.attributes \
--remove-section .comment \
--remove-section .noinit \
$0.o
arm-none-eabi-size $0.o
)make";
const char *makefile_text_l4 = R"make(
all:
@arm-none-eabi-g++ -x c++ -Os -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
@cp $0.o $0.orig.o
@arm-none-eabi-strip -s -S --strip-unneeded $0.o
@arm-none-eabi-objcopy --remove-section .ARM.attributes \
--remove-section .comment \
--remove-section .noinit \
$0.o
arm-none-eabi-size $0.o
)make";
const char *file_header_h7 = R"cpp(
#include <cstdint>
using adcsample_t = uint16_t;
constexpr unsigned int SIZE = $0;
adcsample_t *process_data(adcsample_t *samples, unsigned int size);
extern "C" void process_data_entry()
{
((void (*)())process_data)();
}
constexpr double PI = 3.14159265358979323846L;
__attribute__((naked))
auto sin(double x) {
asm("vmov.f64 r1, r2, d0;"
"eor r0, r0;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto cos(double x) {
asm("vmov.f64 r1, r2, d0;"
"mov r0, #1;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto tan(double x) {
asm("vmov.f64 r1, r2, d0;"
"mov r0, #2;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto sqrt(double x) {
asm("vsqrt.f64 d0, d0; bx lr");
return 0;
}
auto readalt() {
adcsample_t s;
asm("svc 3; mov %0, r0" : "=&r"(s));
return s;
}
// End stmdspgui header code
)cpp";
const char *file_header_l4 = R"cpp(
#include <cstdint>
using adcsample_t = uint16_t;
constexpr unsigned int SIZE = $0;
adcsample_t *process_data(adcsample_t *samples, unsigned int size);
extern "C" void process_data_entry()
{
((void (*)())process_data)();
}
constexpr float PI = 3.14159265358979L;
__attribute__((naked))
auto sin(float x) {
asm("vmov.f32 r1, s0;"
"eor r0, r0;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto cos(float x) {
asm("vmov.f32 r1, s0;"
"mov r0, #1;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto tan(float x) {
asm("vmov.f32 r1, s0;"
"mov r0, #2;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto sqrt(float) {
asm("vsqrt.f32 s0, s0; bx lr");
return 0;
}
auto readalt() {
adcsample_t s;
asm("push {r4-r6}; svc 3; mov %0, r0; pop {r4-r6}" : "=&r"(s));
return s;
}
// End stmdspgui header code
)cpp";
const char *file_content =
R"cpp(adcsample_t *process_data(adcsample_t *samples, unsigned int size)
{
return samples;
}
)cpp";

@ -1,165 +1,16 @@
static const std::array<wxString, 6> srateValues { #ifndef WXMAIN_DEVDATA_H_
"8 kS/s", #define WXMAIN_DEVDATA_H_
"16 kS/s",
"20 kS/s",
"32 kS/s",
"48 kS/s",
"96 kS/s"
};
static const std::array<unsigned int, 6> srateNums {
8000,
16000,
20000,
32000,
48000,
96000
};
static const char *makefile_text_h7 = R"make( #include <array>
all: #include <wx/string.h>
@arm-none-eabi-g++ -x c++ -Os -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
@cp $0.o $0.orig.o
@arm-none-eabi-strip -s -S --strip-unneeded $0.o
@arm-none-eabi-objcopy --remove-section .ARM.attributes \
--remove-section .comment \
--remove-section .noinit \
$0.o
arm-none-eabi-size $0.o
)make";
static const char *makefile_text_l4 = R"make(
all:
@arm-none-eabi-g++ -x c++ -Os -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
@cp $0.o $0.orig.o
@arm-none-eabi-strip -s -S --strip-unneeded $0.o
@arm-none-eabi-objcopy --remove-section .ARM.attributes \
--remove-section .comment \
--remove-section .noinit \
$0.o
arm-none-eabi-size $0.o
)make";
static const char *file_header_h7 = R"cpp( extern const std::array<wxString, 6> srateValues;
#include <cstdint> extern const std::array<unsigned int, 6> srateNums;
extern const char *makefile_text_h7;
extern const char *makefile_text_l4;
extern const char *file_header_h7;
extern const char *file_header_l4;
extern const char *file_content;
using adcsample_t = uint16_t; #endif // WXMAIN_DEVDATA_H_
constexpr unsigned int SIZE = $0;
adcsample_t *process_data(adcsample_t *samples, unsigned int size);
extern "C" void process_data_entry()
{
((void (*)())process_data)();
}
constexpr double PI = 3.14159265358979323846L;
__attribute__((naked))
auto sin(double x) {
asm("vmov.f64 r1, r2, d0;"
"eor r0, r0;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto cos(double x) {
asm("vmov.f64 r1, r2, d0;"
"mov r0, #1;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto tan(double x) {
asm("vmov.f64 r1, r2, d0;"
"mov r0, #2;"
"svc 1;"
"vmov.f64 d0, r1, r2;"
"bx lr");
return 0;
}
__attribute__((naked))
auto sqrt(double x) {
asm("vsqrt.f64 d0, d0; bx lr");
return 0;
}
auto readalt() {
adcsample_t s;
asm("svc 3; mov %0, r0" : "=&r"(s));
return s;
}
// End stmdspgui header code
)cpp";
static const char *file_header_l4 = R"cpp(
#include <cstdint>
using adcsample_t = uint16_t;
constexpr unsigned int SIZE = $0;
adcsample_t *process_data(adcsample_t *samples, unsigned int size);
extern "C" void process_data_entry()
{
((void (*)())process_data)();
}
constexpr float PI = 3.14159265358979L;
__attribute__((naked))
auto sin(float x) {
asm("vmov.f32 r1, s0;"
"eor r0, r0;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto cos(float x) {
asm("vmov.f32 r1, s0;"
"mov r0, #1;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto tan(float x) {
asm("vmov.f32 r1, s0;"
"mov r0, #2;"
"svc 1;"
"vmov.f32 s0, r1;"
"bx lr");
return 0;
}
__attribute__((naked))
auto sqrt(float) {
asm("vsqrt.f32 s0, s0; bx lr");
return 0;
}
auto readalt() {
adcsample_t s;
asm("push {r4-r6}; svc 3; mov %0, r0; pop {r4-r6}" : "=&r"(s));
return s;
}
// End stmdspgui header code
)cpp";
static const char *file_content =
R"cpp(adcsample_t *process_data(adcsample_t *samples, unsigned int size)
{
return samples;
}
)cpp";

@ -1,3 +1,8 @@
#include "wxmain.hpp"
#include "wxmain_devdata.h"
#include <wx/menu.h>
void MainFrame::onFileNew(wxCommandEvent&) void MainFrame::onFileNew(wxCommandEvent&)
{ {
m_open_file_path = ""; m_open_file_path = "";

@ -1,3 +1,10 @@
#include "wxmain.hpp"
#include "wxmain_devdata.h"
#include "wxsiggen.hpp"
#include <wx/menuitem.h>
#include <wx/textdlg.h>
void MainFrame::onRunConnect(wxCommandEvent& ce) void MainFrame::onRunConnect(wxCommandEvent& ce)
{ {
auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData()); auto menuItem = dynamic_cast<wxMenuItem *>(ce.GetEventUserData());
@ -103,7 +110,7 @@ void MainFrame::onRunEditBSize(wxCommandEvent&)
if (wxString value = dialog.GetValue(); !value.IsEmpty()) { if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
if (unsigned long n; value.ToULong(&n)) { if (unsigned long n; value.ToULong(&n)) {
if (n >= 100 && n <= stmdsp::SAMPLES_MAX) { if (n >= 100 && n <= stmdsp::SAMPLES_MAX) {
if (n & 1 == 1) if ((n & 1) == 1)
++n; ++n;
m_device->continuous_set_buffer_size(n); m_device->continuous_set_buffer_size(n);
} else { } else {
@ -159,7 +166,7 @@ void MainFrame::onRunGenUpload(wxCommandEvent&)
if (samples.size() <= stmdsp::SAMPLES_MAX * 2) { if (samples.size() <= stmdsp::SAMPLES_MAX * 2) {
// DAC buffer must be of even size // DAC buffer must be of even size
if (samples.size() & 1 == 1) if ((samples.size() & 1) == 1)
samples.push_back(0); samples.push_back(0);
m_device->siggen_upload(&samples[0], samples.size()); m_device->siggen_upload(&samples[0], samples.size());
m_status_bar->SetStatusText("Generator ready."); m_status_bar->SetStatusText("Generator ready.");
@ -168,24 +175,15 @@ void MainFrame::onRunGenUpload(wxCommandEvent&)
stmdsp::SAMPLES_MAX * 2)); stmdsp::SAMPLES_MAX * 2));
} }
} else { } else {
// Formula extern std::vector<stmdsp::dacsample_t> siggen_formula_parse(const std::string&);
m_status_bar->SetStatusText("Sorry, formulas not supported yet."); auto samples = siggen_formula_parse(result.ToStdString());
} if (samples.size() > 0) {
// if (wxString values = dialog.GetValue(); !values.IsEmpty()) { m_device->siggen_upload(&samples[0], samples.size());
// if (values[0] == '/') { m_status_bar->SetStatusText("Generator ready.");
// m_wav_clip = new wav::clip(values.Mid(1)); } else {
// if (m_wav_clip->valid()) { m_status_bar->SetStatusText("Error: Bad formula.");
// m_status_bar->SetStatusText("Generator ready."); }
// } else { }
// delete m_wav_clip;
// m_wav_clip = nullptr;
// m_status_bar->SetStatusText("Error: Bad WAV file.");
// }
// } else {
// }
// } else {
// m_status_bar->SetStatusText("Error: No samples given.");
// }
} else { } else {
m_status_bar->SetStatusText("Ready."); m_status_bar->SetStatusText("Ready.");
} }

@ -0,0 +1,28 @@
#include "stmdsp.hpp"
#include "exprtk.hpp"
#include <string>
#include <vector>
std::vector<stmdsp::dacsample_t> siggen_formula_parse(const std::string& formulaString)
{
double x = 0;
exprtk::symbol_table<double> symbol_table;
symbol_table.add_variable("x", x);
symbol_table.add_constants();
exprtk::expression<double> expression;
expression.register_symbol_table(symbol_table);
exprtk::parser<double> parser;
parser.compile(formulaString, expression);
std::vector<stmdsp::dacsample_t> samples;
for (x = 0; samples.size() < stmdsp::SAMPLES_MAX; x += 1) {
auto y = static_cast<stmdsp::dacsample_t>(expression.value());
samples.push_back(y);
}
return samples;
}

@ -79,7 +79,9 @@ void SiggenDialog::onSourceChange(wxCommandEvent& ce)
return; return;
m_result.Clear(); m_result.Clear();
if (int selection = radio->GetSelection(); selection >= 0 && selection < Sources.size()) { if (unsigned int selection = static_cast<unsigned int>(radio->GetSelection());
selection < Sources.size())
{
m_instruction->SetLabel(Instructions[selection]); m_instruction->SetLabel(Instructions[selection]);
m_source_list->Show(selection == 0); m_source_list->Show(selection == 0);
m_source_math->Show(selection == 1); m_source_math->Show(selection == 1);

Loading…
Cancel
Save