diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2020-10-20 12:27:21 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2020-10-20 12:27:21 -0400 |
commit | 30cd119dba0e2caf48b6bf5016f60dcede62f511 (patch) | |
tree | dfc6d4321938bfb2e32cf9b6ca6af82274ac2625 /source | |
parent | f1ad9796741daa8368f4885bbce360522df24367 (diff) |
signal gen with dac channel 2
Diffstat (limited to 'source')
-rw-r--r-- | source/dac.cpp | 30 | ||||
-rw-r--r-- | source/dac.hpp | 4 | ||||
-rw-r--r-- | source/main.cpp | 34 |
3 files changed, 53 insertions, 15 deletions
diff --git a/source/dac.cpp b/source/dac.cpp index 74b69e3..c39da38 100644 --- a/source/dac.cpp +++ b/source/dac.cpp @@ -12,6 +12,7 @@ #include "dac.hpp" constexpr static const auto dacd = &DACD1; +constexpr static const auto dacd2 = &DACD2; constexpr static const auto gptd = &GPTD6; constexpr static const DACConfig dac_config = { @@ -34,27 +35,40 @@ constexpr static const GPTConfig gpt_config = { .dier = 0 }; +static unsigned int dacs_running = 0; + namespace dac { void init() { palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); - //palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); dacStart(dacd, &dac_config); + dacStart(dacd2, &dac_config); gptStart(gptd, &gpt_config); } - - void write_start(dacsample_t *buffer, size_t count) + + void write_start(unsigned int channel, dacsample_t *buffer, size_t count) { - dacStartConversion(dacd, &dac_group_config, buffer, count); - gptStartContinuous(gptd, 25); + if (channel < 2) { + dacStartConversion(channel == 0 ? dacd : dacd2, &dac_group_config, buffer, count); + + if (dacs_running == 0) + gptStartContinuous(gptd, 25); + dacs_running |= 1 << channel; + } } - void write_stop() + void write_stop(unsigned int channel) { - gptStopTimer(gptd); - dacStopConversion(dacd); + if (channel < 2) { + dacStopConversion(channel == 0 ? dacd : dacd2); + + dacs_running &= ~(1 << channel); + if (dacs_running == 0) + gptStopTimer(gptd); + } } } diff --git a/source/dac.hpp b/source/dac.hpp index 9d529bf..dec1b36 100644 --- a/source/dac.hpp +++ b/source/dac.hpp @@ -17,8 +17,8 @@ namespace dac { void init(); - void write_start(dacsample_t *buffer, size_t count); - void write_stop(); + void write_start(unsigned int channel, dacsample_t *buffer, size_t count); + void write_stop(unsigned int channel); } #endif // STMDSP_DAC_HPP_ diff --git a/source/main.cpp b/source/main.cpp index c46685f..63bd66b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -77,6 +77,10 @@ static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, MAX_SAMPLE_BUFFER_S CC_ALIGN(CACHE_LINE_SIZE) #endif static std::array<dacsample_t, CACHE_SIZE_ALIGN(dacsample_t, MAX_SAMPLE_BUFFER_SIZE)> dac_samples; +#if CACHE_LINE_SIZE > 0 +CC_ALIGN(CACHE_LINE_SIZE) +#endif +static std::array<dacsample_t, CACHE_SIZE_ALIGN(dacsample_t, MAX_SAMPLE_BUFFER_SIZE)> dac2_samples; static uint8_t elf_file_store[MAX_ELF_FILE_SIZE]; static elf::entry_t elf_entry = nullptr; @@ -112,6 +116,7 @@ int main() } static unsigned int dac_sample_count = MAX_SAMPLE_BUFFER_SIZE; +static unsigned int dac2_sample_count = MAX_SAMPLE_BUFFER_SIZE; static unsigned int adc_sample_count = MAX_SAMPLE_BUFFER_SIZE; static bool adc_preloaded = false; static bool dac_preloaded = false; @@ -133,6 +138,8 @@ void main_loop() usbserial::read(&adc_samples[0], adc_sample_count * sizeof(adcsample_t)); break; + case 'b': + break; case 'B': if (run_status == RunStatus::Idle) { if (usbserial::read(&cmd[1], 2) == 2) { @@ -155,7 +162,17 @@ void main_loop() usbserial::write(dac_samples.data(), dac_sample_count * sizeof(dacsample_t)); break; case 'D': - usbserial::read(&dac_samples[0], dac_sample_count * sizeof(dacsample_t)); + if (usbserial::read(&cmd[1], 2) == 2) { + unsigned int count = cmd[1] | (cmd[2] << 8); + if (count <= MAX_SAMPLE_BUFFER_SIZE / 2) { + dac2_sample_count = count; + usbserial::read(&dac2_samples[0], dac2_sample_count * sizeof(dacsample_t)); + } else { + error_queue_add(Error::BadParam); + } + } else { + error_queue_add(Error::BadParamSize); + } break; // 'E' - Reads in and loads the compiled conversion code binary from USB. @@ -211,7 +228,7 @@ void main_loop() if (!adc_preloaded) adc::read_start(signal_operate_measure, &adc_samples[0], adc_sample_count); if (!dac_preloaded) - dac::write_start(&dac_samples[0], dac_sample_count); + dac::write_start(0, &dac_samples[0], dac_sample_count); } else { error_queue_add(Error::NotIdle); } @@ -232,7 +249,7 @@ void main_loop() if (!adc_preloaded) adc::read_start(signal_operate, &adc_samples[0], adc_sample_count); if (!dac_preloaded) - dac::write_start(&dac_samples[0], dac_sample_count); + dac::write_start(0, &dac_samples[0], dac_sample_count); } else { error_queue_add(Error::NotIdle); } @@ -251,13 +268,20 @@ void main_loop() case 'S': if (run_status == RunStatus::Running) { if (!dac_preloaded) - dac::write_stop(); + dac::write_stop(0); if (!adc_preloaded) adc::read_stop(); run_status = RunStatus::Idle; } break; + case 'W': + dac::write_start(1, &dac2_samples[0], dac2_sample_count); + break; + case 'w': + dac::write_stop(1); + break; + default: break; } @@ -272,7 +296,7 @@ void conversion_abort() { elf_entry = nullptr; if (!dac_preloaded) - dac::write_stop(); + dac::write_stop(0); if (!adc_preloaded) adc::read_stop(); error_queue_add(Error::ConversionAborted); |