From 2176d1656b5fd9b6562c4f83c0f2202b4b560f87 Mon Sep 17 00:00:00 2001 From: Andrey G Date: Mon, 3 May 2021 23:44:19 +0300 Subject: [PATCH] ADC: internalIndex should be used as getAvgAdcValue argument (#2618) * ADC: internalIndex should be used as getAvgAdcValue argument -plus output messages re-formated * ADC: logger -> efiPrintf --- firmware/console/status_loop.cpp | 2 +- firmware/hw_layer/adc/adc_inputs.cpp | 46 +++++++++++----------------- firmware/hw_layer/adc/adc_inputs.h | 2 +- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index dcea4fb775..12b52d8802 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -265,7 +265,7 @@ void updateDevConsoleState(void) { #endif /* EFI_PROD_CODE */ #if HAL_USE_ADC - printFullAdcReportIfNeeded(&logger); + printFullAdcReportIfNeeded(); #endif /* HAL_USE_ADC */ systime_t nowSeconds = getTimeNowSeconds(); diff --git a/firmware/hw_layer/adc/adc_inputs.cpp b/firmware/hw_layer/adc/adc_inputs.cpp index 3c76a49b00..f3ff9da069 100644 --- a/firmware/hw_layer/adc/adc_inputs.cpp +++ b/firmware/hw_layer/adc/adc_inputs.cpp @@ -323,48 +323,38 @@ static void printAdcValue(int channel) { static uint32_t slowAdcConversionCount = 0; static uint32_t slowAdcErrorsCount = 0; -static void printFullAdcReport(Logging *logger) { +static void printFullAdcReport(void) { #if EFI_USE_FAST_ADC - efiPrintf("fast %d slow %d", fastAdc.conversionCount, slowAdcConversionCount); + efiPrintf("fast %d samples", fastAdc.conversionCount); - for (int index = 0; index < fastAdc.size(); index++) { - appendMsgPrefix(logger); - - adc_channel_e hwIndex = fastAdc.getAdcHardwareIndexByInternalIndex(index); + for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) { + adc_channel_e hwIndex = fastAdc.getAdcHardwareIndexByInternalIndex(internalIndex); if (isAdcChannelValid(hwIndex)) { ioportid_t port = getAdcChannelPort("print", hwIndex); int pin = getAdcChannelPin(hwIndex); - - int adcValue = getAvgAdcValue(hwIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size()); - logger->appendPrintf(" F ch%d %s%d", index, portname(port), pin); - logger->appendPrintf(" ADC%d 12bit=%d", hwIndex, adcValue); + int adcValue = getAvgAdcValue(internalIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size()); float volts = adcToVolts(adcValue); - logger->appendPrintf(" v=%.2f", volts); - - appendMsgPostfix(logger); - scheduleLogging(logger); + /* Human index starts from 1 */ + efiPrintf(" F ch[%2d] @ %s%d ADC%d 12bit=%4d %.2fV", + internalIndex, portname(port), pin, hwIndex - EFI_ADC_0 + 1, adcValue, volts); } } #endif // EFI_USE_FAST_ADC + efiPrintf("slow %d samples", slowAdcConversionCount); - for (int index = 0; index < ADC_MAX_CHANNELS_COUNT; index++) { - appendMsgPrefix(logger); - - adc_channel_e hwIndex = static_cast(index + EFI_ADC_0); + /* we assume that all slow ADC channels are enabled */ + for (int internalIndex = 0; internalIndex < ADC_MAX_CHANNELS_COUNT; internalIndex++) { + adc_channel_e hwIndex = static_cast(internalIndex + EFI_ADC_0); if (isAdcChannelValid(hwIndex)) { ioportid_t port = getAdcChannelPort("print", hwIndex); int pin = getAdcChannelPin(hwIndex); - - int adcValue = slowAdcSamples[index]; - logger->appendPrintf(" S ch%d %s%d", index, portname(port), pin); - logger->appendPrintf(" ADC%d 12bit=%d", hwIndex, adcValue); + int adcValue = slowAdcSamples[internalIndex]; float volts = adcToVolts(adcValue); - logger->appendPrintf(" v=%.2f", volts); - - appendMsgPostfix(logger); - scheduleLogging(logger); + /* Human index starts from 1 */ + efiPrintf(" S ch[%2d] @ %s%d ADC%d 12bit=%4d %.2fV", + internalIndex, portname(port), pin, hwIndex - EFI_ADC_0 + 1, adcValue, volts); } } } @@ -541,10 +531,10 @@ void initAdcInputs() { #endif } -void printFullAdcReportIfNeeded(Logging *logger) { +void printFullAdcReportIfNeeded(void) { if (!adcDebugReporting) return; - printFullAdcReport(logger); + printFullAdcReport(); } #else /* not HAL_USE_ADC */ diff --git a/firmware/hw_layer/adc/adc_inputs.h b/firmware/hw_layer/adc/adc_inputs.h index 83baa28956..cf1a65d2ee 100644 --- a/firmware/hw_layer/adc/adc_inputs.h +++ b/firmware/hw_layer/adc/adc_inputs.h @@ -49,7 +49,7 @@ int getSlowAdcCounter(); int getAdcHardwareIndexByInternalIndex(int index); -void printFullAdcReportIfNeeded(Logging *log); +void printFullAdcReportIfNeeded(void); int getInternalAdcValue(const char *msg, adc_channel_e index); float getMCUInternalTemperature(void);