fix L4 DAC trigger; round buffers to even size

master
Clyne 4 years ago
parent 673eba7167
commit 5515642bf8

@ -258,8 +258,6 @@ void MainFrame::onPaint(wxPaintEvent&)
dc->SetBrush(*wxBLACK_BRUSH);
dc->SetPen(*wxBLACK_PEN);
dc->DrawRectangle(rect);
dc->SetBrush(*wxRED_BRUSH);
dc->SetPen(*wxRED_PEN);
auto stoy = [&](stmdsp::adcsample_t s) {
return static_cast<float>(py) + rect.GetHeight() -
(static_cast<float>(rect.GetHeight()) * s / 4095.f);
@ -268,15 +266,17 @@ void MainFrame::onPaint(wxPaintEvent&)
float dx = static_cast<float>(rect.GetWidth()) / scount;
float x = 0;
float lasty = stoy(2048);
dc->SetBrush(wxBrush(wxColour(0xFF, 0, 0, 0x80)));
dc->SetPen(wxPen(wxColour(0xFF, 0, 0, 0x80)));
for (decltype(scount) i = 0; i < scount; i++) {
auto y = stoy(m_device_samples[i]);
dc->DrawLine(x, lasty, x + dx, y);
x += dx, lasty = y;
}
dc->SetBrush(*wxBLUE_BRUSH);
dc->SetPen(*wxBLUE_PEN);
x = 0;
lasty = stoy(2048);
dc->SetBrush(wxBrush(wxColour(0, 0, 0xFF, 0x80)));
dc->SetPen(wxPen(wxColour(0, 0, 0xFF, 0x80)));
for (decltype(scount) i = 0; i < scount; i++) {
auto y = stoy(m_device_samples_input[i]);
dc->DrawLine(x, lasty, x + dx, y);

@ -103,6 +103,8 @@ void MainFrame::onRunEditBSize(wxCommandEvent&)
if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
if (unsigned long n; value.ToULong(&n)) {
if (n >= 100 && n <= stmdsp::SAMPLES_MAX) {
if (n & 1 == 1)
++n;
m_device->continuous_set_buffer_size(n);
} else {
m_status_bar->SetStatusText("Error: Invalid buffer size.");
@ -156,6 +158,9 @@ void MainFrame::onRunGenUpload(wxCommandEvent&)
}
if (samples.size() <= stmdsp::SAMPLES_MAX * 2) {
// DAC buffer must be of even size
if (samples.size() & 1 == 1)
samples.push_back(0);
m_device->siggen_upload(&samples[0], samples.size());
m_status_bar->SetStatusText("Generator ready.");
} else {

@ -26,13 +26,17 @@ const DACConversionGroup DAC::m_group_config = {
.num_channels = 1,
.end_cb = nullptr,
.error_cb = nullptr,
#if defined(TARGET_PLATFORM_H7)
.trigger = 5 // TIM6_TRGO
#elif defined(TARGET_PLATFORM_L4)
.trigger = 0 // TIM6_TRGO
#endif
};
void DAC::begin()
{
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
palSetPadMode(GPIOA, 4, PAL_STM32_MODE_ANALOG);
palSetPadMode(GPIOA, 5, PAL_STM32_MODE_ANALOG);
dacStart(m_driver[0], &m_config);
dacStart(m_driver[1], &m_config);

Loading…
Cancel
Save