You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
970 B
C++
43 lines
970 B
C++
4 years ago
|
#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;
|
||
|
}
|
||
|
|