mirror of https://github.com/rusefi/rusefi-1.git
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:
parent
306e4a230f
commit
6fe0cadfc0
|
@ -163,6 +163,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EFI_INTERNAL_ADC TRUE
|
#define EFI_INTERNAL_ADC TRUE
|
||||||
|
#define EFI_USE_FAST_ADC TRUE
|
||||||
|
|
||||||
#define EFI_NARROW_EGO_AVERAGING FALSE
|
#define EFI_NARROW_EGO_AVERAGING FALSE
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,8 @@
|
||||||
#define EFI_INTERNAL_ADC TRUE
|
#define EFI_INTERNAL_ADC TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define EFI_USE_FAST_ADC TRUE
|
||||||
|
|
||||||
#define EFI_NARROW_EGO_AVERAGING FALSE
|
#define EFI_NARROW_EGO_AVERAGING FALSE
|
||||||
|
|
||||||
#ifndef EFI_CAN_SUPPORT
|
#ifndef EFI_CAN_SUPPORT
|
||||||
|
|
|
@ -193,6 +193,8 @@
|
||||||
#define EFI_INTERNAL_ADC TRUE
|
#define EFI_INTERNAL_ADC TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define EFI_USE_FAST_ADC TRUE
|
||||||
|
|
||||||
#define EFI_NARROW_EGO_AVERAGING TRUE
|
#define EFI_NARROW_EGO_AVERAGING TRUE
|
||||||
|
|
||||||
#ifndef EFI_CAN_SUPPORT
|
#ifndef EFI_CAN_SUPPORT
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#undef EFI_USE_FAST_ADC
|
||||||
|
#define EFI_USE_FAST_ADC FALSE
|
||||||
|
|
||||||
#undef EFI_MC33816
|
#undef EFI_MC33816
|
||||||
#define EFI_MC33816 FALSE
|
#define EFI_MC33816 FALSE
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,7 @@ static ADCConversionGroup adcgrpcfgSlow = {
|
||||||
|
|
||||||
AdcDevice slowAdc(&adcgrpcfgSlow, slowAdcSampleBuf, ARRAY_SIZE(slowAdcSampleBuf));
|
AdcDevice slowAdc(&adcgrpcfgSlow, slowAdcSampleBuf, ARRAY_SIZE(slowAdcSampleBuf));
|
||||||
|
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
void adc_callback_fast(ADCDriver *adcp);
|
void adc_callback_fast(ADCDriver *adcp);
|
||||||
|
|
||||||
static ADCConversionGroup adcgrpcfgFast = {
|
static ADCConversionGroup adcgrpcfgFast = {
|
||||||
|
@ -214,7 +215,6 @@ static ADCConversionGroup adcgrpcfgFast = {
|
||||||
|
|
||||||
AdcDevice fastAdc(&adcgrpcfgFast, fastAdcSampleBuf, ARRAY_SIZE(fastAdcSampleBuf));
|
AdcDevice fastAdc(&adcgrpcfgFast, fastAdcSampleBuf, ARRAY_SIZE(fastAdcSampleBuf));
|
||||||
|
|
||||||
#if HAL_USE_GPT
|
|
||||||
static void fast_adc_callback(GPTDriver*) {
|
static void fast_adc_callback(GPTDriver*) {
|
||||||
#if EFI_INTERNAL_ADC
|
#if EFI_INTERNAL_ADC
|
||||||
/*
|
/*
|
||||||
|
@ -240,7 +240,7 @@ static void fast_adc_callback(GPTDriver*) {
|
||||||
fastAdc.conversionCount++;
|
fastAdc.conversionCount++;
|
||||||
#endif /* EFI_INTERNAL_ADC */
|
#endif /* EFI_INTERNAL_ADC */
|
||||||
}
|
}
|
||||||
#endif /* HAL_USE_GPT */
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
|
||||||
static float mcuTemperature;
|
static float mcuTemperature;
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) {
|
||||||
|
|
||||||
#endif /* EFI_ENABLE_MOCK_ADC */
|
#endif /* EFI_ENABLE_MOCK_ADC */
|
||||||
|
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
if (adcHwChannelEnabled[hwChannel] == ADC_FAST) {
|
if (adcHwChannelEnabled[hwChannel] == ADC_FAST) {
|
||||||
int internalIndex = fastAdc.internalAdcIndexByHardwareIndex[hwChannel];
|
int internalIndex = fastAdc.internalAdcIndexByHardwareIndex[hwChannel];
|
||||||
// todo if ADC_BUF_DEPTH_FAST EQ 1
|
// 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());
|
int value = getAvgAdcValue(internalIndex, fastAdc.samples, ADC_BUF_DEPTH_FAST, fastAdc.size());
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
|
||||||
if (adcHwChannelEnabled[hwChannel] != ADC_SLOW) {
|
if (adcHwChannelEnabled[hwChannel] != ADC_SLOW) {
|
||||||
// todo: make this not happen during hardware continuous integration
|
// todo: make this not happen during hardware continuous integration
|
||||||
warning(CUSTOM_OBD_WRONG_ADC_MODE, "ADC is off [%s] index=%d", msg, hwChannel);
|
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);
|
return slowAdc.getAdcValueByHwChannel(hwChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAL_USE_GPT
|
#if EFI_USE_FAST_ADC
|
||||||
static GPTConfig fast_adc_config = {
|
static GPTConfig fast_adc_config = {
|
||||||
GPT_FREQ_FAST,
|
GPT_FREQ_FAST,
|
||||||
fast_adc_callback,
|
fast_adc_callback,
|
||||||
0, 0
|
0, 0
|
||||||
};
|
};
|
||||||
#endif /* HAL_USE_GPT */
|
#endif /* EFI_USE_FAST_ADC */
|
||||||
|
|
||||||
adc_channel_mode_e getAdcMode(adc_channel_e hwChannel) {
|
adc_channel_mode_e getAdcMode(adc_channel_e hwChannel) {
|
||||||
if (slowAdc.isHwUsed(hwChannel)) {
|
if (slowAdc.isHwUsed(hwChannel)) {
|
||||||
return ADC_SLOW;
|
return ADC_SLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
if (fastAdc.isHwUsed(hwChannel)) {
|
if (fastAdc.isHwUsed(hwChannel)) {
|
||||||
return ADC_FAST;
|
return ADC_FAST;
|
||||||
}
|
}
|
||||||
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
|
||||||
return ADC_OFF;
|
return ADC_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,6 +374,7 @@ adc_channel_e AdcDevice::getAdcHardwareIndexByInternalIndex(int index) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printFullAdcReport(Logging *logger) {
|
static void printFullAdcReport(Logging *logger) {
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
scheduleMsg(logger, "fast %d slow %d", fastAdc.conversionCount, slowAdc.conversionCount);
|
scheduleMsg(logger, "fast %d slow %d", fastAdc.conversionCount, slowAdc.conversionCount);
|
||||||
|
|
||||||
for (int index = 0; index < fastAdc.size(); index++) {
|
for (int index = 0; index < fastAdc.size(); index++) {
|
||||||
|
@ -389,6 +396,7 @@ static void printFullAdcReport(Logging *logger) {
|
||||||
scheduleLogging(logger);
|
scheduleLogging(logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
|
||||||
for (int index = 0; index < slowAdc.size(); index++) {
|
for (int index = 0; index < slowAdc.size(); index++) {
|
||||||
appendMsgPrefix(logger);
|
appendMsgPrefix(logger);
|
||||||
|
@ -492,8 +500,15 @@ void addChannel(const char *name, adc_channel_e setting, adc_channel_mode_e mode
|
||||||
|
|
||||||
adcHwChannelEnabled[setting] = mode;
|
adcHwChannelEnabled[setting] = mode;
|
||||||
|
|
||||||
AdcDevice& dev = (mode == ADC_SLOW) ? slowAdc : fastAdc;
|
AdcDevice* dev = &slowAdc;
|
||||||
dev.enableChannelAndPin(name, setting);
|
|
||||||
|
#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) {
|
void removeChannel(const char *name, adc_channel_e setting) {
|
||||||
|
@ -581,14 +596,12 @@ void initAdcInputs() {
|
||||||
// Start the slow ADC thread
|
// Start the slow ADC thread
|
||||||
slowAdcController.Start();
|
slowAdcController.Start();
|
||||||
|
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
fastAdc.init();
|
fastAdc.init();
|
||||||
/*
|
|
||||||
* Initializes the PWM driver.
|
|
||||||
*/
|
|
||||||
#if HAL_USE_GPT
|
|
||||||
gptStart(EFI_INTERNAL_FAST_ADC_GPT, &fast_adc_config);
|
gptStart(EFI_INTERNAL_FAST_ADC_GPT, &fast_adc_config);
|
||||||
gptStartContinuous(EFI_INTERNAL_FAST_ADC_GPT, GPT_PERIOD_FAST);
|
gptStartContinuous(EFI_INTERNAL_FAST_ADC_GPT, GPT_PERIOD_FAST);
|
||||||
#endif /* HAL_USE_GPT */
|
#endif // EFI_USE_FAST_ADC
|
||||||
|
|
||||||
addConsoleActionI("adc", (VoidInt) printAdcValue);
|
addConsoleActionI("adc", (VoidInt) printAdcValue);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -17,8 +17,10 @@ void portInitAdc() {
|
||||||
// Init slow ADC
|
// Init slow ADC
|
||||||
adcStart(&ADCD1, NULL);
|
adcStart(&ADCD1, NULL);
|
||||||
|
|
||||||
|
#if EFI_USE_FAST_ADC
|
||||||
// Init fast ADC (MAP sensor)
|
// Init fast ADC (MAP sensor)
|
||||||
adcStart(&ADCD2, NULL);
|
adcStart(&ADCD2, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Enable internal temperature reference
|
// Enable internal temperature reference
|
||||||
adcSTM32EnableTSVREFE(); // Internal temperature sensor
|
adcSTM32EnableTSVREFE(); // Internal temperature sensor
|
||||||
|
|
Loading…
Reference in New Issue