aboutsummaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-08-22 10:31:45 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-08-22 10:31:45 -0400
commitb3eccbc1b9f0194d9f71345113acdc4518b991c1 (patch)
tree67e77c98ac03776e43347f2bd7e9daa5e6510013 /source
parent989f4038c6d2a3e5bbee04fa25df181810af621e (diff)
working: continuous signal passthrough
Diffstat (limited to 'source')
-rw-r--r--source/adc.cpp11
-rw-r--r--source/main.cpp24
2 files changed, 25 insertions, 10 deletions
diff --git a/source/adc.cpp b/source/adc.cpp
index f2903c3..9e0491e 100644
--- a/source/adc.cpp
+++ b/source/adc.cpp
@@ -77,7 +77,7 @@ namespace adc
adc_operation_func = operation_func;
adc_group_config.circular = true;
adcStartConversion(adcd, &adc_group_config, buffer, count);
- gptStartContinuous(gptd, 100); // 10kHz
+ gptStartContinuous(gptd, 1000); // 10kHz
}
void read_stop()
@@ -131,13 +131,10 @@ void adc_read_callback(ADCDriver *driver)
adc_is_read_finished = true;
} else if (adc_operation_func != nullptr) {
auto half_size = adc_current_buffer_size / 2;
- if (driver->state == ADC_ACTIVE) {
- // Half full
- adc_operation_func(adc_current_buffer, half_size);
- } else if (driver->state == ADC_COMPLETE) {
- // Second half full
+ if (adcIsBufferComplete(driver))
adc_operation_func(adc_current_buffer + half_size, half_size);
- }
+ else
+ adc_operation_func(adc_current_buffer, half_size);
}
}
diff --git a/source/main.cpp b/source/main.cpp
index f1170a6..162771a 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -19,13 +19,19 @@
#include <array>
static_assert(sizeof(adcsample_t) == sizeof(uint16_t));
+static_assert(sizeof(dacsample_t) == sizeof(uint16_t));
#if CACHE_LINE_SIZE > 0
CC_ALIGN(CACHE_LINE_SIZE)
#endif
static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, 2048)> adc_samples;
+#if CACHE_LINE_SIZE > 0
+CC_ALIGN(CACHE_LINE_SIZE)
+#endif
static std::array<dacsample_t, CACHE_SIZE_ALIGN(dacsample_t, 2048)> dac_samples;
+static volatile bool signal_operate_done = false;
+
static void signal_operate(adcsample_t *buffer, size_t count);
int main()
@@ -54,11 +60,21 @@ int main()
}
break;
case 'R':
- adc::read_start(signal_operate, &adc_samples[0], adc_samples.size() * sizeof(adcsample_t));
+ dac_samples.fill(0);
+ adc::read_start(signal_operate, &adc_samples[0], adc_samples.size());
+ dac::write_start(&dac_samples[0], dac_samples.size());
+ break;
+ case 's':
+ while (!signal_operate_done);
+ usbserial::write(dac_samples.data(), dac_samples.size() * sizeof(adcsample_t));
break;
case 'S':
+ dac::write_stop();
adc::read_stop();
break;
+ case 'e':
+
+ break;
case 'W':
if (usbserial::read(&cmd[1], 2) < 2)
break;
@@ -85,8 +101,10 @@ int main()
}
}
-void signal_operate([[maybe_unused]] adcsample_t *buffer, [[maybe_unused]] size_t count)
+void signal_operate(adcsample_t *buffer, size_t count)
{
-
+ auto dac_buffer = &dac_samples[buffer == &adc_samples[0] ? 0 : 1024];
+ std::copy(buffer, buffer + count, dac_buffer);
+ signal_operate_done = buffer == &adc_samples[1024];
}