+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#include "adc.hpp"
const GPTConfig ADCd::m_gpt_config = {
+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#ifndef STMDSP_ADC_HPP_
#define STMDSP_ADC_HPP_
+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#include "dac.hpp"
//static const DACConversionGroup dacGroupConfig = {
+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#ifndef STMDSP_DAC_HPP_
#define STMDSP_DAC_HPP_
+/**\r
+ * @file main.cpp\r
+ * @brief Program entry point.\r
+ *\r
+ * Copyright (C) 2020 Clyne Sullivan\r
+ *\r
+ * Distributed under the GNU GPL v3 or later. You should have received a copy of\r
+ * the GNU General Public License along with this program.\r
+ * If not, see <https://www.gnu.org/licenses/>.\r
+ */\r
+\r
#include "ch.h"\r
#include "hal.h"\r
\r
#include "dac.hpp"\r
#include "usbserial.hpp"\r
\r
+#include <array>\r
+\r
#if CACHE_LINE_SIZE > 0\r
CC_ALIGN(CACHE_LINE_SIZE)\r
#endif\r
-adcsample_t samples[CACHE_SIZE_ALIGN(adcsample_t, 10)];\r
+static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, 100)> adc_samples;\r
\r
-int main(void) {\r
+int main()\r
+{\r
halInit();\r
chSysInit();\r
\r
\r
while (true) {\r
if (usbd.active()) {\r
- if (char c; usbd.read(&c) > 0 && c == 's') {\r
- adc.getSamples(samples, 10);\r
- for (int i = 0; i < 10; i++) {\r
- uint8_t str[5] = {\r
- static_cast<uint8_t>(samples[i] / 1000 % 10 + '0'),\r
- static_cast<uint8_t>(samples[i] / 100 % 10 + '0'),\r
- static_cast<uint8_t>(samples[i] / 10 % 10 + '0'),\r
- static_cast<uint8_t>(samples[i] % 10 + '0'),\r
- ' '\r
- };\r
- usbd.write(str, 5);\r
+ // Expect to receive a byte command 'packet'.\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
+ usbd.write(adc_samples.data(), adc_samples.size());\r
+ break;\r
+ case 'i': // Identify ourself as an stmdsp device\r
+ usbd.write("stmdsp", 6);\r
+ break;\r
+ default:\r
+ break;\r
}\r
- usbd.write("\r\n", 2);\r
}\r
}\r
+\r
chThdSleepMilliseconds(250);\r
}\r
}\r
+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#include "usbserial.hpp"
#include "hal.h"
+/**
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
#ifndef STMDSP_USBSERIAL_HPP_
#define STMDSP_USBSERIAL_HPP_