aboutsummaryrefslogtreecommitdiffstats
path: root/source/adc.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-06-11 10:15:31 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-06-11 10:15:31 -0400
commit7f0a54a8ee175106254982dc12c184d7c25849b4 (patch)
tree4415a7f58bdb2d17266c9bfa267f5f903e5177a6 /source/adc.cpp
parent14eb7970debdafdd7e8486eced64d4b718a821a7 (diff)
made classes for drivers
Diffstat (limited to 'source/adc.cpp')
-rw-r--r--source/adc.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/adc.cpp b/source/adc.cpp
new file mode 100644
index 0000000..6ddabb6
--- /dev/null
+++ b/source/adc.cpp
@@ -0,0 +1,42 @@
+#include "adc.hpp"
+
+const GPTConfig ADCd::m_gpt_config = {
+ .frequency = 1000000,
+ .callback = NULL,
+ .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
+ .dier = 0
+};
+
+void ADCd::start()
+{
+ initPins();
+ gptStart(m_gptd, &m_gpt_config);
+
+ m_adc_config.difsel = 0;
+ m_adc_config.adcdinst = this;
+
+ adcStart(m_adcd, &m_adc_config);
+ adcSTM32EnableVREF(m_adcd);
+}
+
+adcsample_t *ADCd::getSamples(adcsample_t *buffer, size_t count)
+{
+ m_is_adc_finished = false;
+ adcStartConversion(m_adcd, &m_adc_group_config, buffer, count);
+ gptStartContinuous(m_gptd, 100); // 10kHz
+ while (!m_is_adc_finished);
+ return buffer;
+}
+
+void ADCd::initPins()
+{
+ palSetPadMode(GPIOA, 0, PAL_MODE_INPUT_ANALOG);
+}
+
+void ADCd::adcEndCallback(ADCDriver *adcd)
+{
+ auto *_this = reinterpret_cast<const ADCdConfig *>(adcd->config)->adcdinst;
+ gptStopTimer(_this->m_gptd);
+ _this->m_is_adc_finished = true;
+}
+