]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
added license headers; revised serial interaction
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 11 Jun 2020 14:33:24 +0000 (10:33 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 11 Jun 2020 14:33:24 +0000 (10:33 -0400)
source/adc.cpp
source/adc.hpp
source/dac.cpp
source/dac.hpp
source/main.cpp
source/usbserial.cpp
source/usbserial.hpp

index 6ddabb6baeefa599ac409391614d269bcd2c2cfa..0c58e21d5404d0f0d912cb6af9a312ba530b37b4 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #include "adc.hpp"
 
 const GPTConfig ADCd::m_gpt_config = {
index 6b1789d941d771b6d33bedf2a621790105163353..456e697a948e9a7c09eecd9fc30f9e171d55ca9c 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #ifndef STMDSP_ADC_HPP_
 #define STMDSP_ADC_HPP_
 
index c7c250db63d4a3c3cd4837ca110347b87bad47e3..8981fc321e985abc1b2dcb3bbb0dd789c547aab4 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #include "dac.hpp"
 
 //static const DACConversionGroup dacGroupConfig = {
index 687e8cf6584e6acb64cae891fb43ff71978295ff..dc6cc3aa953b1742fbae37e5cfbb466022be2f48 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #ifndef STMDSP_DAC_HPP_
 #define STMDSP_DAC_HPP_
 
index 16ca7a86e693c564bb613bf88effbc9ba448480f..b8d2fa148d0f847dca09f5ecc5d19654d56846cd 100644 (file)
@@ -1,3 +1,14 @@
+/**\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
@@ -32,21 +46,22 @@ int main(void) {
 \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
index cead28a94e88281a1cbee43ec29812a6ce42304d..105e9bf57e4d285128dfc882f6e46f80cecd49c1 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #include "usbserial.hpp"
 
 #include "hal.h"
index a65190b5362dd0e85b8d436368a9b4d46e27ba7c..377f73cd5a6318a1f16e7b6403c9fa5e8c77c757 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
+ */
+
 #ifndef STMDSP_USBSERIAL_HPP_
 #define STMDSP_USBSERIAL_HPP_