17#error "ADC mux not yet supported on STM32H7"
21#define H7_ADC_SPEED (10000)
24#ifndef H7_ADC_OVERSAMPLE
25#define H7_ADC_OVERSAMPLE (4)
28static_assert((H7_ADC_OVERSAMPLE & (H7_ADC_OVERSAMPLE - 1)) == 0,
"H7_ADC_OVERSAMPLE must be a power of 2");
32 while (x >>= 1) result++;
45 adcStart(&
ADCD1, NULL);
49 adcStart(&
ADCD3,
nullptr);
54 SYSCFG->PMCR &= ~(SYSCFG_PMCR_PA0SO | SYSCFG_PMCR_PA1SO | SYSCFG_PMCR_PC2SO | SYSCFG_PMCR_PC3SO);
71 if (adcIsBufferComplete(adcp)) {
83#define ADC_SAMPLING_SLOW ADC_SMPR_SMP_16P5
95 .cfgr = ADC_CFGR_EXTEN_0 | (4 << ADC_CFGR_EXTSEL_Pos),
96 .cfgr2 = (H7_ADC_OVERSAMPLE - 1) << ADC_CFGR2_OVSR_Pos |
102 .ltr1 = 0, .htr1 = 0, .ltr2 = 0, .htr2 = 0, .ltr3 = 0, .htr3 = 0,
107 ADC_SMPR1_SMP_AN0(ADC_SAMPLING_SLOW) |
108 ADC_SMPR1_SMP_AN1(ADC_SAMPLING_SLOW) |
109 ADC_SMPR1_SMP_AN2(ADC_SAMPLING_SLOW) |
110 ADC_SMPR1_SMP_AN3(ADC_SAMPLING_SLOW) |
111 ADC_SMPR1_SMP_AN4(ADC_SAMPLING_SLOW) |
112 ADC_SMPR1_SMP_AN5(ADC_SAMPLING_SLOW) |
113 ADC_SMPR1_SMP_AN6(ADC_SAMPLING_SLOW) |
114 ADC_SMPR1_SMP_AN7(ADC_SAMPLING_SLOW) |
115 ADC_SMPR1_SMP_AN8(ADC_SAMPLING_SLOW) |
116 ADC_SMPR1_SMP_AN9(ADC_SAMPLING_SLOW),
117 ADC_SMPR2_SMP_AN10(ADC_SAMPLING_SLOW) |
118 ADC_SMPR2_SMP_AN11(ADC_SAMPLING_SLOW) |
119 ADC_SMPR2_SMP_AN12(ADC_SAMPLING_SLOW) |
120 ADC_SMPR2_SMP_AN13(ADC_SAMPLING_SLOW) |
121 ADC_SMPR2_SMP_AN14(ADC_SAMPLING_SLOW) |
122 ADC_SMPR2_SMP_AN15(ADC_SAMPLING_SLOW) |
123 ADC_SMPR2_SMP_AN16(ADC_SAMPLING_SLOW) |
124 ADC_SMPR2_SMP_AN17(ADC_SAMPLING_SLOW) |
125 ADC_SMPR2_SMP_AN18(ADC_SAMPLING_SLOW) |
126 ADC_SMPR2_SMP_AN19(ADC_SAMPLING_SLOW)
141 ADC_SQR3_SQ11_N(10) |
142 ADC_SQR3_SQ12_N(11) |
143 ADC_SQR3_SQ13_N(12) |
162 chibios_rt::CriticalSectionLocker csl;
167 constexpr uint32_t samplingRate = H7_ADC_SPEED;
168 constexpr uint32_t timerCountFrequency = samplingRate * 10;
169 constexpr uint32_t timerPeriod = timerCountFrequency / samplingRate;
179 gptStart(&
GPTD3, &gptCfg);
180 gptStartContinuous(&
GPTD3, timerPeriod);
203#ifdef EFI_SOFTWARE_KNOCK
204#include "knock_config.h"
206static_assert((H7_KNOCK_OVERSAMPLE & (H7_KNOCK_OVERSAMPLE - 1)) == 0,
"H7_ADC_OVERSAMPLE must be a power of 2");
210 if (adcIsBufferComplete(adcp)) {
221 ADC_SMPR1_SMP_AN0(KNOCK_SAMPLE_TIME) |
222 ADC_SMPR1_SMP_AN1(KNOCK_SAMPLE_TIME) |
223 ADC_SMPR1_SMP_AN2(KNOCK_SAMPLE_TIME) |
224 ADC_SMPR1_SMP_AN3(KNOCK_SAMPLE_TIME) |
225 ADC_SMPR1_SMP_AN4(KNOCK_SAMPLE_TIME) |
226 ADC_SMPR1_SMP_AN5(KNOCK_SAMPLE_TIME) |
227 ADC_SMPR1_SMP_AN6(KNOCK_SAMPLE_TIME) |
228 ADC_SMPR1_SMP_AN7(KNOCK_SAMPLE_TIME) |
229 ADC_SMPR1_SMP_AN8(KNOCK_SAMPLE_TIME) |
230 ADC_SMPR1_SMP_AN9(KNOCK_SAMPLE_TIME);
233 ADC_SMPR2_SMP_AN10(KNOCK_SAMPLE_TIME) |
234 ADC_SMPR2_SMP_AN11(KNOCK_SAMPLE_TIME) |
235 ADC_SMPR2_SMP_AN12(KNOCK_SAMPLE_TIME) |
236 ADC_SMPR2_SMP_AN13(KNOCK_SAMPLE_TIME) |
237 ADC_SMPR2_SMP_AN14(KNOCK_SAMPLE_TIME) |
238 ADC_SMPR2_SMP_AN15(KNOCK_SAMPLE_TIME) |
239 ADC_SMPR2_SMP_AN16(KNOCK_SAMPLE_TIME) |
240 ADC_SMPR2_SMP_AN17(KNOCK_SAMPLE_TIME) |
241 ADC_SMPR2_SMP_AN18(KNOCK_SAMPLE_TIME) |
242 ADC_SMPR2_SMP_AN19(KNOCK_SAMPLE_TIME);
250 .cfgr2 = (H7_KNOCK_OVERSAMPLE - 1) << ADC_CFGR2_OVSR_Pos |
256 .ltr1 = 0, .htr1 = 0, .ltr2 = 0, .htr2 = 0, .ltr3 = 0, .htr3 = 0,
261 ADC_SQR1_SQ1_N(KNOCK_ADC_CH1),
275 .cfgr2 = (H7_ADC_OVERSAMPLE - 1) << ADC_CFGR2_OVSR_Pos |
281 .ltr1 = 0, .htr1 = 0, .ltr2 = 0, .htr2 = 0, .ltr3 = 0, .htr3 = 0,
286 ADC_SQR1_SQ1_N(KNOCK_ADC_CH2),
static constexpr engine_configuration_s * engineConfiguration
ADCDriver ADCD3
ADC3 driver identifier.
adcerror_t
Possible ADC failure causes.
uint16_t adcsample_t
ADC sample data type.
ADCDriver ADCD1
ADC1 driver identifier.
GPTDriver GPTD3
GPTD3 driver identifier.
void onFastAdcComplete(adcsample_t *)
void assertInterruptPriority(const char *func, uint8_t expectedPrio)
void onKnockSamplingComplete()
const ADCConversionGroup * getKnockConversionGroup(uint8_t channelIdx)
adcsample_t * fastSampleBuffer
static const uint32_t smpr1
bool readSlowAnalogInputs(adcsample_t *convertedSamples)
static constexpr ADCConversionGroup convGroupSlow
adcsample_t getFastAdc(AdcToken token)
static const ADCConversionGroup adcConvGroupCh2
static void knockCompletionCallback(ADCDriver *adcp)
static const uint32_t smpr2
static void adc_callback(ADCDriver *adcp)
float getMcuVrefVoltage()
static constexpr int H7_ADC_SHIFT_BITS
static void knockErrorCallback(ADCDriver *, adcerror_t)
float getMcuTemperature()
static constexpr size_t log2_int(size_t x)
constexpr size_t slowChannelCount
static const ADCConversionGroup adcConvGroupCh1
static constexpr int H7_KNOCK_ADC_SHIFT_BITS
AdcToken enableFastAdcChannel(const char *, adc_channel_e channel)
Driver configuration structure.