added license headers; revised serial interaction

pull/1/head
Clyne 5 years ago
parent 7f0a54a8ee
commit 7a6f7bd792

@ -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" #include "adc.hpp"
const GPTConfig ADCd::m_gpt_config = { const GPTConfig ADCd::m_gpt_config = {

@ -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_ #ifndef STMDSP_ADC_HPP_
#define STMDSP_ADC_HPP_ #define STMDSP_ADC_HPP_

@ -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" #include "dac.hpp"
//static const DACConversionGroup dacGroupConfig = { //static const DACConversionGroup dacGroupConfig = {

@ -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_ #ifndef STMDSP_DAC_HPP_
#define STMDSP_DAC_HPP_ #define STMDSP_DAC_HPP_

@ -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 <https://www.gnu.org/licenses/>.
*/
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
@ -5,12 +16,15 @@
#include "dac.hpp" #include "dac.hpp"
#include "usbserial.hpp" #include "usbserial.hpp"
#include <array>
#if CACHE_LINE_SIZE > 0 #if CACHE_LINE_SIZE > 0
CC_ALIGN(CACHE_LINE_SIZE) CC_ALIGN(CACHE_LINE_SIZE)
#endif #endif
adcsample_t samples[CACHE_SIZE_ALIGN(adcsample_t, 10)]; static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, 100)> adc_samples;
int main(void) { int main()
{
halInit(); halInit();
chSysInit(); chSysInit();
@ -32,21 +46,22 @@ int main(void) {
while (true) { while (true) {
if (usbd.active()) { if (usbd.active()) {
if (char c; usbd.read(&c) > 0 && c == 's') { // Expect to receive a byte command 'packet'.
adc.getSamples(samples, 10); if (char cmd; usbd.read(&cmd) > 0) {
for (int i = 0; i < 10; i++) { switch (cmd) {
uint8_t str[5] = { case 'r': // Read in analog signal
static_cast<uint8_t>(samples[i] / 1000 % 10 + '0'), adc.getSamples(&adc_samples[0], adc_samples.size());
static_cast<uint8_t>(samples[i] / 100 % 10 + '0'), usbd.write(adc_samples.data(), adc_samples.size());
static_cast<uint8_t>(samples[i] / 10 % 10 + '0'), break;
static_cast<uint8_t>(samples[i] % 10 + '0'), case 'i': // Identify ourself as an stmdsp device
' ' usbd.write("stmdsp", 6);
}; break;
usbd.write(str, 5); default:
break;
} }
usbd.write("\r\n", 2);
} }
} }
chThdSleepMilliseconds(250); chThdSleepMilliseconds(250);
} }
} }

@ -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 "usbserial.hpp"
#include "hal.h" #include "hal.h"

@ -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_ #ifndef STMDSP_USBSERIAL_HPP_
#define STMDSP_USBSERIAL_HPP_ #define STMDSP_USBSERIAL_HPP_

Loading…
Cancel
Save