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
This commit is contained in:
Andrey G 2021-05-03 23:44:19 +03:00 committed by GitHub
parent 941c40d488
commit 2176d1656b
3 changed files with 20 additions and 30 deletions

View File

@ -265,7 +265,7 @@ void updateDevConsoleState(void) {
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
#if HAL_USE_ADC #if HAL_USE_ADC
printFullAdcReportIfNeeded(&logger); printFullAdcReportIfNeeded();
#endif /* HAL_USE_ADC */ #endif /* HAL_USE_ADC */
systime_t nowSeconds = getTimeNowSeconds(); systime_t nowSeconds = getTimeNowSeconds();

View File

@ -323,48 +323,38 @@ static void printAdcValue(int channel) {
static uint32_t slowAdcConversionCount = 0; static uint32_t slowAdcConversionCount = 0;
static uint32_t slowAdcErrorsCount = 0; static uint32_t slowAdcErrorsCount = 0;
static void printFullAdcReport(Logging *logger) { static void printFullAdcReport(void) {
#if EFI_USE_FAST_ADC #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++) { for (int internalIndex = 0; internalIndex < fastAdc.size(); internalIndex++) {
appendMsgPrefix(logger); adc_channel_e hwIndex = fastAdc.getAdcHardwareIndexByInternalIndex(internalIndex);
adc_channel_e hwIndex = fastAdc.getAdcHardwareIndexByInternalIndex(index);
if (isAdcChannelValid(hwIndex)) { if (isAdcChannelValid(hwIndex)) {
ioportid_t port = getAdcChannelPort("print", hwIndex); ioportid_t port = getAdcChannelPort("print", hwIndex);
int pin = getAdcChannelPin(hwIndex); int pin = getAdcChannelPin(hwIndex);
int adcValue = getAvgAdcValue(internalIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size());
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);
float volts = adcToVolts(adcValue); float volts = adcToVolts(adcValue);
logger->appendPrintf(" v=%.2f", volts); /* Human index starts from 1 */
efiPrintf(" F ch[%2d] @ %s%d ADC%d 12bit=%4d %.2fV",
appendMsgPostfix(logger); internalIndex, portname(port), pin, hwIndex - EFI_ADC_0 + 1, adcValue, volts);
scheduleLogging(logger);
} }
} }
#endif // EFI_USE_FAST_ADC #endif // EFI_USE_FAST_ADC
efiPrintf("slow %d samples", slowAdcConversionCount);
for (int index = 0; index < ADC_MAX_CHANNELS_COUNT; index++) { /* we assume that all slow ADC channels are enabled */
appendMsgPrefix(logger); for (int internalIndex = 0; internalIndex < ADC_MAX_CHANNELS_COUNT; internalIndex++) {
adc_channel_e hwIndex = static_cast<adc_channel_e>(internalIndex + EFI_ADC_0);
adc_channel_e hwIndex = static_cast<adc_channel_e>(index + EFI_ADC_0);
if (isAdcChannelValid(hwIndex)) { if (isAdcChannelValid(hwIndex)) {
ioportid_t port = getAdcChannelPort("print", hwIndex); ioportid_t port = getAdcChannelPort("print", hwIndex);
int pin = getAdcChannelPin(hwIndex); int pin = getAdcChannelPin(hwIndex);
int adcValue = slowAdcSamples[internalIndex];
int adcValue = slowAdcSamples[index];
logger->appendPrintf(" S ch%d %s%d", index, portname(port), pin);
logger->appendPrintf(" ADC%d 12bit=%d", hwIndex, adcValue);
float volts = adcToVolts(adcValue); float volts = adcToVolts(adcValue);
logger->appendPrintf(" v=%.2f", volts); /* Human index starts from 1 */
efiPrintf(" S ch[%2d] @ %s%d ADC%d 12bit=%4d %.2fV",
appendMsgPostfix(logger); internalIndex, portname(port), pin, hwIndex - EFI_ADC_0 + 1, adcValue, volts);
scheduleLogging(logger);
} }
} }
} }
@ -541,10 +531,10 @@ void initAdcInputs() {
#endif #endif
} }
void printFullAdcReportIfNeeded(Logging *logger) { void printFullAdcReportIfNeeded(void) {
if (!adcDebugReporting) if (!adcDebugReporting)
return; return;
printFullAdcReport(logger); printFullAdcReport();
} }
#else /* not HAL_USE_ADC */ #else /* not HAL_USE_ADC */

View File

@ -49,7 +49,7 @@ int getSlowAdcCounter();
int getAdcHardwareIndexByInternalIndex(int index); int getAdcHardwareIndexByInternalIndex(int index);
void printFullAdcReportIfNeeded(Logging *log); void printFullAdcReportIfNeeded(void);
int getInternalAdcValue(const char *msg, adc_channel_e index); int getInternalAdcValue(const char *msg, adc_channel_e index);
float getMCUInternalTemperature(void); float getMCUInternalTemperature(void);