|
|
@ -38,42 +38,43 @@ static ADCConversionGroup adc_group_config = {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
constexpr static const GPTConfig gpt_config = {
|
|
|
|
constexpr static const GPTConfig gpt_config = {
|
|
|
|
.frequency = 2400000,
|
|
|
|
.frequency = 14400000,
|
|
|
|
.callback = nullptr,
|
|
|
|
.callback = nullptr,
|
|
|
|
.cr2 = TIM_CR2_MMS_1, /* TRGO */
|
|
|
|
.cr2 = TIM_CR2_MMS_1, /* TRGO */
|
|
|
|
.dier = 0
|
|
|
|
.dier = 0
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t adc_sample_rate_settings[] = {
|
|
|
|
static uint32_t adc_sample_rate_settings[] = {
|
|
|
|
10, ADC_SMPR_SMP_47P5, // 3125
|
|
|
|
10, ADC_SMPR_SMP_47P5, 4608, // 3125
|
|
|
|
11, ADC_SMPR_SMP_12P5, // 3750
|
|
|
|
11, ADC_SMPR_SMP_12P5, 3840, // 3750
|
|
|
|
9, ADC_SMPR_SMP_47P5, // 6250
|
|
|
|
9, ADC_SMPR_SMP_47P5, 2304, // 6250
|
|
|
|
10, ADC_SMPR_SMP_12P5, // 7500
|
|
|
|
10, ADC_SMPR_SMP_12P5, 1920, // 7500
|
|
|
|
8, ADC_SMPR_SMP_47P5, // 12K5
|
|
|
|
8, ADC_SMPR_SMP_47P5, 1152, // 12K5
|
|
|
|
9, ADC_SMPR_SMP_12P5, // 15K
|
|
|
|
9, ADC_SMPR_SMP_12P5, 960, // 15K
|
|
|
|
7, ADC_SMPR_SMP_47P5, // 25K
|
|
|
|
7, ADC_SMPR_SMP_47P5, 576, // 25K
|
|
|
|
8, ADC_SMPR_SMP_12P5, // 30K
|
|
|
|
8, ADC_SMPR_SMP_12P5, 480, // 30K
|
|
|
|
5, ADC_SMPR_SMP_47P5, // 40K
|
|
|
|
5, ADC_SMPR_SMP_47P5, 360, // 40K
|
|
|
|
4, ADC_SMPR_SMP_47P5, // 50K
|
|
|
|
4, ADC_SMPR_SMP_47P5, 288, // 50K
|
|
|
|
7, ADC_SMPR_SMP_12P5, // 60K
|
|
|
|
7, ADC_SMPR_SMP_12P5, 240, // 60K
|
|
|
|
6, ADC_SMPR_SMP_12P5, // 80K
|
|
|
|
6, ADC_SMPR_SMP_12P5, 180, // 80K
|
|
|
|
5, ADC_SMPR_SMP_12P5, // 96K
|
|
|
|
5, ADC_SMPR_SMP_12P5, 150, // 96K
|
|
|
|
2, ADC_SMPR_SMP_47P5, // 100K
|
|
|
|
2, ADC_SMPR_SMP_47P5, 144, // 100K
|
|
|
|
4, ADC_SMPR_SMP_12P5, // 120K
|
|
|
|
4, ADC_SMPR_SMP_12P5, 120, // 120K
|
|
|
|
3, ADC_SMPR_SMP_12P5, // 160K
|
|
|
|
3, ADC_SMPR_SMP_12P5, 90, // 160K
|
|
|
|
1, ADC_SMPR_SMP_47P5, // 200K
|
|
|
|
1, ADC_SMPR_SMP_47P5, 72, // 200K
|
|
|
|
2, ADC_SMPR_SMP_12P5, // 240K
|
|
|
|
2, ADC_SMPR_SMP_12P5, 60, // 240K
|
|
|
|
0, ADC_SMPR_SMP_47P5, // 400K
|
|
|
|
0, ADC_SMPR_SMP_47P5, 36, // 400K
|
|
|
|
1, ADC_SMPR_SMP_12P5, // 480K
|
|
|
|
1, ADC_SMPR_SMP_12P5, 30, // 480K
|
|
|
|
1, ADC_SMPR_SMP_2P5, // 800K
|
|
|
|
1, ADC_SMPR_SMP_2P5, 18, // 800K
|
|
|
|
0, ADC_SMPR_SMP_12P5, // 960K
|
|
|
|
0, ADC_SMPR_SMP_12P5, 15, // 960K
|
|
|
|
0, ADC_SMPR_SMP_2P5 // 1M6
|
|
|
|
0, ADC_SMPR_SMP_2P5, 9 // 1M6
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static bool adc_is_read_finished = false;
|
|
|
|
static bool adc_is_read_finished = false;
|
|
|
|
static adcsample_t *adc_current_buffer = nullptr;
|
|
|
|
static adcsample_t *adc_current_buffer = nullptr;
|
|
|
|
static size_t adc_current_buffer_size = 0;
|
|
|
|
static size_t adc_current_buffer_size = 0;
|
|
|
|
static adc::operation_t adc_operation_func = nullptr;
|
|
|
|
static adc::operation_t adc_operation_func = nullptr;
|
|
|
|
|
|
|
|
static unsigned int adc_gpt_divisor = 1;
|
|
|
|
|
|
|
|
|
|
|
|
namespace adc
|
|
|
|
namespace adc
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -84,12 +85,16 @@ namespace adc
|
|
|
|
gptStart(gptd, &gpt_config);
|
|
|
|
gptStart(gptd, &gpt_config);
|
|
|
|
adcStart(adcd, &adc_config);
|
|
|
|
adcStart(adcd, &adc_config);
|
|
|
|
adcSTM32EnableVREF(adcd);
|
|
|
|
adcSTM32EnableVREF(adcd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_rate(rate::R96K);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_rate(rate new_rate)
|
|
|
|
void set_rate(rate new_rate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto presc = adc_sample_rate_settings[static_cast<unsigned int>(new_rate) * 2] << 18;
|
|
|
|
auto index = static_cast<unsigned int>(new_rate);
|
|
|
|
auto smp = adc_sample_rate_settings[static_cast<unsigned int>(new_rate) * 2 + 1];
|
|
|
|
auto presc = adc_sample_rate_settings[index * 3] << 18;
|
|
|
|
|
|
|
|
auto smp = adc_sample_rate_settings[index * 3 + 1];
|
|
|
|
|
|
|
|
adc_gpt_divisor = adc_sample_rate_settings[index * 3 + 2];
|
|
|
|
|
|
|
|
|
|
|
|
adcStop(adcd);
|
|
|
|
adcStop(adcd);
|
|
|
|
// Set ADC prescaler
|
|
|
|
// Set ADC prescaler
|
|
|
@ -99,12 +104,17 @@ namespace adc
|
|
|
|
adcStart(adcd, &adc_config);
|
|
|
|
adcStart(adcd, &adc_config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int get_gpt_divisor()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return adc_gpt_divisor;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
adcsample_t *read(adcsample_t *buffer, size_t count)
|
|
|
|
adcsample_t *read(adcsample_t *buffer, size_t count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
adc_is_read_finished = false;
|
|
|
|
adc_is_read_finished = false;
|
|
|
|
adc_group_config.circular = false;
|
|
|
|
adc_group_config.circular = false;
|
|
|
|
adcStartConversion(adcd, &adc_group_config, buffer, count);
|
|
|
|
adcStartConversion(adcd, &adc_group_config, buffer, count);
|
|
|
|
gptStartContinuous(gptd, 25);
|
|
|
|
gptStartContinuous(gptd, adc_gpt_divisor);
|
|
|
|
while (!adc_is_read_finished);
|
|
|
|
while (!adc_is_read_finished);
|
|
|
|
return buffer;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,7 +126,7 @@ namespace adc
|
|
|
|
adc_operation_func = operation_func;
|
|
|
|
adc_operation_func = operation_func;
|
|
|
|
adc_group_config.circular = true;
|
|
|
|
adc_group_config.circular = true;
|
|
|
|
adcStartConversion(adcd, &adc_group_config, buffer, count);
|
|
|
|
adcStartConversion(adcd, &adc_group_config, buffer, count);
|
|
|
|
gptStartContinuous(gptd, 25);
|
|
|
|
gptStartContinuous(gptd, adc_gpt_divisor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void read_set_operation_func(operation_t operation_func)
|
|
|
|
void read_set_operation_func(operation_t operation_func)
|
|
|
|