From 7a6f7bd79215eda20377014415030663a9593bd6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 11 Jun 2020 10:33:24 -0400 Subject: [PATCH] added license headers; revised serial interaction --- source/adc.cpp | 11 +++++++++++ source/adc.hpp | 11 +++++++++++ source/dac.cpp | 11 +++++++++++ source/dac.hpp | 11 +++++++++++ source/main.cpp | 43 +++++++++++++++++++++++++++++-------------- source/usbserial.cpp | 11 +++++++++++ source/usbserial.hpp | 11 +++++++++++ 7 files changed, 95 insertions(+), 14 deletions(-) diff --git a/source/adc.cpp b/source/adc.cpp index 6ddabb6..0c58e21 100644 --- a/source/adc.cpp +++ b/source/adc.cpp @@ -1,3 +1,14 @@ +/** + * @file adc.cpp + * @brief Wrapper for ChibiOS's ADCDriver. + * + * Copyright (C) 2020 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 . + */ + #include "adc.hpp" const GPTConfig ADCd::m_gpt_config = { diff --git a/source/adc.hpp b/source/adc.hpp index 6b1789d..456e697 100644 --- a/source/adc.hpp +++ b/source/adc.hpp @@ -1,3 +1,14 @@ +/** + * @file adc.hpp + * @brief Wrapper for ChibiOS's ADCDriver. + * + * Copyright (C) 2020 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_ADC_HPP_ #define STMDSP_ADC_HPP_ diff --git a/source/dac.cpp b/source/dac.cpp index c7c250d..8981fc3 100644 --- a/source/dac.cpp +++ b/source/dac.cpp @@ -1,3 +1,14 @@ +/** + * @file dac.cpp + * @brief Wrapper for ChibiOS's DACDriver. + * + * Copyright (C) 2020 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 . + */ + #include "dac.hpp" //static const DACConversionGroup dacGroupConfig = { diff --git a/source/dac.hpp b/source/dac.hpp index 687e8cf..dc6cc3a 100644 --- a/source/dac.hpp +++ b/source/dac.hpp @@ -1,3 +1,14 @@ +/** + * @file dac.hpp + * @brief Wrapper for ChibiOS's DACDriver. + * + * Copyright (C) 2020 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_ diff --git a/source/main.cpp b/source/main.cpp index 16ca7a8..b8d2fa1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,3 +1,14 @@ +/** + * @file main.cpp + * @brief Program entry point. + * + * Copyright (C) 2020 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 . + */ + #include "ch.h" #include "hal.h" @@ -5,12 +16,15 @@ #include "dac.hpp" #include "usbserial.hpp" +#include + #if CACHE_LINE_SIZE > 0 CC_ALIGN(CACHE_LINE_SIZE) #endif -adcsample_t samples[CACHE_SIZE_ALIGN(adcsample_t, 10)]; +static std::array adc_samples; -int main(void) { +int main() +{ halInit(); chSysInit(); @@ -32,21 +46,22 @@ int main(void) { while (true) { if (usbd.active()) { - if (char c; usbd.read(&c) > 0 && c == 's') { - adc.getSamples(samples, 10); - for (int i = 0; i < 10; i++) { - uint8_t str[5] = { - static_cast(samples[i] / 1000 % 10 + '0'), - static_cast(samples[i] / 100 % 10 + '0'), - static_cast(samples[i] / 10 % 10 + '0'), - static_cast(samples[i] % 10 + '0'), - ' ' - }; - usbd.write(str, 5); + // Expect to receive a byte command 'packet'. + if (char cmd; usbd.read(&cmd) > 0) { + switch (cmd) { + case 'r': // Read in analog signal + adc.getSamples(&adc_samples[0], adc_samples.size()); + usbd.write(adc_samples.data(), adc_samples.size()); + break; + case 'i': // Identify ourself as an stmdsp device + usbd.write("stmdsp", 6); + break; + default: + break; } - usbd.write("\r\n", 2); } } + chThdSleepMilliseconds(250); } } diff --git a/source/usbserial.cpp b/source/usbserial.cpp index cead28a..105e9bf 100644 --- a/source/usbserial.cpp +++ b/source/usbserial.cpp @@ -1,3 +1,14 @@ +/** + * @file usbserial.cpp + * @brief Wrapper for ChibiOS's SerialUSBDriver. + * + * Copyright (C) 2020 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 . + */ + #include "usbserial.hpp" #include "hal.h" diff --git a/source/usbserial.hpp b/source/usbserial.hpp index a65190b..377f73c 100644 --- a/source/usbserial.hpp +++ b/source/usbserial.hpp @@ -1,3 +1,14 @@ +/** + * @file usbserial.hpp + * @brief Wrapper for ChibiOS's SerialUSBDriver. + * + * Copyright (C) 2020 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_USBSERIAL_HPP_ #define STMDSP_USBSERIAL_HPP_