From 123cc4c756cc8a22f66351ab65595c5a20e53e27 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 31 Jul 2021 10:47:00 -0400 Subject: reorganized source, wip --- source/periph/dac.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 source/periph/dac.hpp (limited to 'source/periph/dac.hpp') diff --git a/source/periph/dac.hpp b/source/periph/dac.hpp new file mode 100644 index 0000000..4360c26 --- /dev/null +++ b/source/periph/dac.hpp @@ -0,0 +1,36 @@ +/** + * @file dac.hpp + * @brief Manages signal creation using the DAC. + * + * Copyright (C) 2021 Clyne Sullivan + * + * Distributed under the GNU GPL v3 or later. You should have received a copy of + * the GNU General Public License along with this program. + * If not, see . + */ + +#ifndef STMDSP_DAC_HPP_ +#define STMDSP_DAC_HPP_ + +#include "hal.h" +#undef DAC + +class DAC +{ +public: + static void begin(); + + static void start(int channel, dacsample_t *buffer, size_t count); + static void stop(int channel); + + static int sigGenWantsMore(); + +private: + static DACDriver *m_driver[2]; + + static const DACConfig m_config; + static const DACConversionGroup m_group_config; +}; + +#endif // STMDSP_DAC_HPP_ + -- cgit v1.2.3 From 3dd57491b1e81a9d93054eff19ca0e6c65c85b9b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 20 Nov 2021 14:29:08 -0500 Subject: fixed signal generator input data streaming --- source/communication.cpp | 25 +++++++++++++------------ source/periph/dac.cpp | 13 ++++++++++++- source/periph/dac.hpp | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'source/periph/dac.hpp') diff --git a/source/communication.cpp b/source/communication.cpp index ec02a42..b5ee28e 100644 --- a/source/communication.cpp +++ b/source/communication.cpp @@ -112,22 +112,23 @@ void updateGenerator(unsigned char *cmd) if (EM.assert(USBSerial::read(&cmd[1], 2) == 2, Error::BadParamSize)) { unsigned int count = cmd[1] | (cmd[2] << 8); if (EM.assert(count <= MAX_SAMPLE_BUFFER_SIZE, Error::BadParam)) { - if (run_status == RunStatus::Idle) { + if (!DAC::isSigGenRunning()) { Samples::Generator.setSize(count); USBSerial::read( reinterpret_cast(Samples::Generator.data()), Samples::Generator.bytesize()); - } else if (run_status == RunStatus::Running) { - int more; - do { - chThdSleepMicroseconds(10); - more = DAC::sigGenWantsMore(); - } while (more == -1); - - // Receive streamed samples in half-buffer chunks. - USBSerial::read(reinterpret_cast( - more == 0 ? Samples::Generator.data() : Samples::Generator.middata()), - Samples::Generator.bytesize() / 2); + } else { + const int more = DAC::sigGenWantsMore(); + if (more == -1) { + USBSerial::write(reinterpret_cast("\0"), 1); + } else { + USBSerial::write(reinterpret_cast("\1"), 1); + + // Receive streamed samples in half-buffer chunks. + USBSerial::read(reinterpret_cast( + more == 0 ? Samples::Generator.data() : Samples::Generator.middata()), + Samples::Generator.bytesize() / 2); + } } } } diff --git a/source/periph/dac.cpp b/source/periph/dac.cpp index 1ff8867..35c2908 100644 --- a/source/periph/dac.cpp +++ b/source/periph/dac.cpp @@ -61,7 +61,18 @@ void DAC::start(int channel, dacsample_t *buffer, size_t count) int DAC::sigGenWantsMore() { - return dacIsDone; + if (dacIsDone != -1) { + int tmp = dacIsDone; + dacIsDone = -1; + return tmp; + } else { + return -1; + } +} + +int DAC::isSigGenRunning() +{ + return m_driver[1]->state == DAC_ACTIVE; } void DAC::stop(int channel) diff --git a/source/periph/dac.hpp b/source/periph/dac.hpp index 4360c26..7250a52 100644 --- a/source/periph/dac.hpp +++ b/source/periph/dac.hpp @@ -24,6 +24,7 @@ public: static void stop(int channel); static int sigGenWantsMore(); + static int isSigGenRunning(); private: static DACDriver *m_driver[2]; -- cgit v1.2.3