aboutsummaryrefslogtreecommitdiffstats
path: root/source/dac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/dac.cpp')
-rw-r--r--source/dac.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/source/dac.cpp b/source/dac.cpp
index 8981fc3..d2bcf37 100644
--- a/source/dac.cpp
+++ b/source/dac.cpp
@@ -1,6 +1,6 @@
/**
* @file dac.cpp
- * @brief Wrapper for ChibiOS's DACDriver.
+ * @brief Manages signal creation using the DAC.
*
* Copyright (C) 2020 Clyne Sullivan
*
@@ -11,28 +11,47 @@
#include "dac.hpp"
-//static const DACConversionGroup dacGroupConfig = {
-// .num_channels = 1,
-// .end_cb = NULL,
-// .error_cb = NULL,
-// .trigger = DAC_TRG(0)
-//};
+constexpr static const auto dacd = &DACD1;
+constexpr static const auto gptd = &GPTD5;
-void DACd::init()
+constexpr static const DACConfig dac_config = {
+ .init = 0,
+ .datamode = DAC_DHRM_12BIT_RIGHT,
+ .cr = 0
+};
+
+constexpr static const DACConversionGroup dac_group_config = {
+ .num_channels = 1,
+ .end_cb = nullptr,
+ .error_cb = nullptr,
+ .trigger = DAC_TRG(3)
+};
+
+constexpr static const GPTConfig gpt_config = {
+ .frequency = 500000,
+ .callback = nullptr,
+ .cr2 = TIM_CR2_MMS_1, /* TRGO */
+ .dier = 0
+};
+
+void dac_init()
{
- initPins();
- dacStart(m_driver, &m_config);
+ palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
+ //palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
+
+ dacStart(dacd, &dac_config);
+ gptStart(gptd, &gpt_config);
}
-void DACd::write(unsigned int channel, uint16_t value)
+void dac_write_start(dacsample_t *buffer, size_t count)
{
- if (channel < 2)
- dacPutChannelX(m_driver, channel, value);
+ dacStartConversion(dacd, &dac_group_config, buffer, count);
+ gptStartContinuous(gptd, 1);
}
-void DACd::initPins()
+void dac_write_stop()
{
- palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); // DAC out1, out2
- palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
+ gptStopTimer(gptd);
+ dacStopConversion(dacd);
}