|
|
@ -21,9 +21,53 @@ struct ADCdConfig : public ADCConfig
|
|
|
|
ADCd *adcdinst;
|
|
|
|
ADCd *adcdinst;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class ADCdRate : unsigned int {
|
|
|
|
|
|
|
|
R2P5,
|
|
|
|
|
|
|
|
R6P5,
|
|
|
|
|
|
|
|
R12P5,
|
|
|
|
|
|
|
|
R24P5,
|
|
|
|
|
|
|
|
R47P5,
|
|
|
|
|
|
|
|
R92P5,
|
|
|
|
|
|
|
|
R247P5,
|
|
|
|
|
|
|
|
R640P5
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ADCd
|
|
|
|
class ADCd
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
|
|
|
|
constexpr static const unsigned int CLOCK_RATE = 40000000;
|
|
|
|
|
|
|
|
constexpr static unsigned int SAMPLES_PER_SECOND(ADCdRate rate) {
|
|
|
|
|
|
|
|
unsigned int sps = 0;
|
|
|
|
|
|
|
|
switch (rate) {
|
|
|
|
|
|
|
|
case ADCdRate::R2P5:
|
|
|
|
|
|
|
|
sps = 15;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R6P5:
|
|
|
|
|
|
|
|
sps = 19;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R12P5:
|
|
|
|
|
|
|
|
sps = 25;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R24P5:
|
|
|
|
|
|
|
|
sps = 37;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R47P5:
|
|
|
|
|
|
|
|
sps = 60;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R92P5:
|
|
|
|
|
|
|
|
sps = 105;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R247P5:
|
|
|
|
|
|
|
|
sps = 260;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ADCdRate::R640P5:
|
|
|
|
|
|
|
|
sps = 653;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return static_cast<unsigned int>(1.f / (sps / static_cast<float>(CLOCK_RATE)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
constexpr explicit ADCd(ADCDriver& adcd, GPTDriver& gptd) :
|
|
|
|
constexpr explicit ADCd(ADCDriver& adcd, GPTDriver& gptd) :
|
|
|
|
m_adcd(&adcd), m_gptd(&gptd), m_adc_config{},
|
|
|
|
m_adcd(&adcd), m_gptd(&gptd), m_adc_config{},
|
|
|
|
m_adc_group_config(ADC_GROUP_CONFIG),
|
|
|
|
m_adc_group_config(ADC_GROUP_CONFIG),
|
|
|
@ -31,6 +75,7 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void start();
|
|
|
|
adcsample_t *getSamples(adcsample_t *buffer, size_t count);
|
|
|
|
adcsample_t *getSamples(adcsample_t *buffer, size_t count);
|
|
|
|
|
|
|
|
void setSampleRate(ADCdRate rate);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
static const GPTConfig m_gpt_config;
|
|
|
|
static const GPTConfig m_gpt_config;
|
|
|
@ -43,6 +88,8 @@ private:
|
|
|
|
bool m_is_adc_finished;
|
|
|
|
bool m_is_adc_finished;
|
|
|
|
|
|
|
|
|
|
|
|
void initPins();
|
|
|
|
void initPins();
|
|
|
|
|
|
|
|
//void selectPins(bool a0, bool a1);
|
|
|
|
|
|
|
|
|
|
|
|
static void adcEndCallback(ADCDriver *adcd);
|
|
|
|
static void adcEndCallback(ADCDriver *adcd);
|
|
|
|
|
|
|
|
|
|
|
|
constexpr static const ADCConversionGroup ADC_GROUP_CONFIG = {
|
|
|
|
constexpr static const ADCConversionGroup ADC_GROUP_CONFIG = {
|
|
|
|