allow disabling fast ADC (#2406)

* mostly guard against no fast adc

* disable on h7

* guard more

* guard adc init

* you can't do that in c++

* we need that

* s

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-02-28 02:30:19 -10:00 committed by GitHub
parent 306e4a230f
commit 6fe0cadfc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 12 deletions

View File

@ -163,6 +163,7 @@
#endif
#define EFI_INTERNAL_ADC TRUE
#define EFI_USE_FAST_ADC TRUE
#define EFI_NARROW_EGO_AVERAGING FALSE

View File

@ -144,6 +144,8 @@
#define EFI_INTERNAL_ADC TRUE
#endif
#define EFI_USE_FAST_ADC TRUE
#define EFI_NARROW_EGO_AVERAGING FALSE
#ifndef EFI_CAN_SUPPORT

View File

@ -193,6 +193,8 @@
#define EFI_INTERNAL_ADC TRUE
#endif
#define EFI_USE_FAST_ADC TRUE
#define EFI_NARROW_EGO_AVERAGING TRUE
#ifndef EFI_CAN_SUPPORT

View File

@ -2,6 +2,9 @@
#pragma once
#undef EFI_USE_FAST_ADC
#define EFI_USE_FAST_ADC FALSE
#undef EFI_MC33816
#define EFI_MC33816 FALSE

View File

@ -166,6 +166,7 @@ static ADCConversionGroup adcgrpcfgSlow = {
AdcDevice slowAdc(&adcgrpcfgSlow, slowAdcSampleBuf, ARRAY_SIZE(slowAdcSampleBuf));
#if EFI_USE_FAST_ADC
void adc_callback_fast(ADCDriver *adcp);
static ADCConversionGroup adcgrpcfgFast = {
@ -214,7 +215,6 @@ static ADCConversionGroup adcgrpcfgFast = {
AdcDevice fastAdc(&adcgrpcfgFast, fastAdcSampleBuf, ARRAY_SIZE(fastAdcSampleBuf));
#if HAL_USE_GPT
static void fast_adc_callback(GPTDriver*) {
#if EFI_INTERNAL_ADC
/*
@ -240,7 +240,7 @@ static void fast_adc_callback(GPTDriver*) {
fastAdc.conversionCount++;
#endif /* EFI_INTERNAL_ADC */
}
#endif /* HAL_USE_GPT */
#endif // EFI_USE_FAST_ADC
static float mcuTemperature;
@ -259,7 +259,7 @@ int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) {
#endif /* EFI_ENABLE_MOCK_ADC */
#if EFI_USE_FAST_ADC
if (adcHwChannelEnabled[hwChannel] == ADC_FAST) {
int internalIndex = fastAdc.internalAdcIndexByHardwareIndex[hwChannel];
// todo if ADC_BUF_DEPTH_FAST EQ 1
@ -267,6 +267,8 @@ int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) {
int value = getAvgAdcValue(internalIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size());
return value;
}
#endif // EFI_USE_FAST_ADC
if (adcHwChannelEnabled[hwChannel] != ADC_SLOW) {
// todo: make this not happen during hardware continuous integration
warning(CUSTOM_OBD_WRONG_ADC_MODE, "ADC is off [%s] index=%d", msg, hwChannel);
@ -275,21 +277,25 @@ int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) {
return slowAdc.getAdcValueByHwChannel(hwChannel);
}
#if HAL_USE_GPT
#if EFI_USE_FAST_ADC
static GPTConfig fast_adc_config = {
GPT_FREQ_FAST,
fast_adc_callback,
0, 0
};
#endif /* HAL_USE_GPT */
#endif /* EFI_USE_FAST_ADC */
adc_channel_mode_e getAdcMode(adc_channel_e hwChannel) {
if (slowAdc.isHwUsed(hwChannel)) {
return ADC_SLOW;
}
#if EFI_USE_FAST_ADC
if (fastAdc.isHwUsed(hwChannel)) {
return ADC_FAST;
}
#endif // EFI_USE_FAST_ADC
return ADC_OFF;
}
@ -368,6 +374,7 @@ adc_channel_e AdcDevice::getAdcHardwareIndexByInternalIndex(int index) const {
}
static void printFullAdcReport(Logging *logger) {
#if EFI_USE_FAST_ADC
scheduleMsg(logger, "fast %d slow %d", fastAdc.conversionCount, slowAdc.conversionCount);
for (int index = 0; index < fastAdc.size(); index++) {
@ -389,6 +396,7 @@ static void printFullAdcReport(Logging *logger) {
scheduleLogging(logger);
}
}
#endif // EFI_USE_FAST_ADC
for (int index = 0; index < slowAdc.size(); index++) {
appendMsgPrefix(logger);
@ -492,8 +500,15 @@ void addChannel(const char *name, adc_channel_e setting, adc_channel_mode_e mode
adcHwChannelEnabled[setting] = mode;
AdcDevice& dev = (mode == ADC_SLOW) ? slowAdc : fastAdc;
dev.enableChannelAndPin(name, setting);
AdcDevice* dev = &slowAdc;
#if EFI_USE_FAST_ADC
if (mode == ADC_FAST) {
dev = &fastAdc;
}
#endif
dev->enableChannelAndPin(name, setting);
}
void removeChannel(const char *name, adc_channel_e setting) {
@ -581,14 +596,12 @@ void initAdcInputs() {
// Start the slow ADC thread
slowAdcController.Start();
#if EFI_USE_FAST_ADC
fastAdc.init();
/*
* Initializes the PWM driver.
*/
#if HAL_USE_GPT
gptStart(EFI_INTERNAL_FAST_ADC_GPT, &fast_adc_config);
gptStartContinuous(EFI_INTERNAL_FAST_ADC_GPT, GPT_PERIOD_FAST);
#endif /* HAL_USE_GPT */
#endif // EFI_USE_FAST_ADC
addConsoleActionI("adc", (VoidInt) printAdcValue);
#else

View File

@ -17,8 +17,10 @@ void portInitAdc() {
// Init slow ADC
adcStart(&ADCD1, NULL);
#if EFI_USE_FAST_ADC
// Init fast ADC (MAP sensor)
adcStart(&ADCD2, NULL);
#endif
// Enable internal temperature reference
adcSTM32EnableTSVREFE(); // Internal temperature sensor