diff --git a/firmware/config/engines/dodge_ram.cpp b/firmware/config/engines/dodge_ram.cpp index db7fe13913..b99fcdb556 100644 --- a/firmware/config/engines/dodge_ram.cpp +++ b/firmware/config/engines/dodge_ram.cpp @@ -24,7 +24,7 @@ void setDodgeRam1996(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->specs.firingOrder = FO_1_8_4_3_6_5_7_2; boardConfiguration->triggerInputPins[0] = GPIOC_6; - boardConfiguration->triggerInputPins[1] = GPIOA_8; + boardConfiguration->triggerInputPins[1] = GPIOA_5; engineConfiguration->vbattAdcChannel = EFI_ADC_NONE; // todo: conflict with what? } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index e19babceff..c5846397bf 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -311,7 +311,7 @@ static void printAnalogChannelInfoExt(const char *name, adc_channel_e hwChannel, static void printAnalogChannelInfo(const char *name, adc_channel_e hwChannel) { #if HAL_USE_ADC || defined(__DOXYGEN__) if (hwChannel != EFI_ADC_NONE) { - printAnalogChannelInfoExt(name, hwChannel, getVoltage(hwChannel)); + printAnalogChannelInfoExt(name, hwChannel, getVoltage("print", hwChannel)); } #endif } diff --git a/firmware/controllers/sensors/allsensors.cpp b/firmware/controllers/sensors/allsensors.cpp index 7d24956ccc..154f491de5 100644 --- a/firmware/controllers/sensors/allsensors.cpp +++ b/firmware/controllers/sensors/allsensors.cpp @@ -24,5 +24,5 @@ bool getAcToggle(Engine *engine) { * for now we are looking for a pull-up. High level means input switch is floating (which is OFF position) * low value means input is ground - which means ON. */ - return getVoltageDivided(engine->engineConfiguration->acSwitchAdc) < 2.5; + return getVoltageDivided("A/C", engine->engineConfiguration->acSwitchAdc) < 2.5; } diff --git a/firmware/controllers/sensors/ego.cpp b/firmware/controllers/sensors/ego.cpp index 6aebc6fc02..b0055ac6e8 100644 --- a/firmware/controllers/sensors/ego.cpp +++ b/firmware/controllers/sensors/ego.cpp @@ -9,7 +9,7 @@ EXTERN_ENGINE; float getAfr(DECLARE_ENGINE_PARAMETER_F) { afr_sensor_s * sensor = &engineConfiguration->afr; - float volts = getVoltageDivided(sensor->hwChannel); + float volts = getVoltageDivided("ego", sensor->hwChannel); return interpolate(sensor->v1, sensor->value1, sensor->v2, sensor->value2, volts); } diff --git a/firmware/controllers/sensors/maf.cpp b/firmware/controllers/sensors/maf.cpp index c40965f8f4..bcfb846c0d 100644 --- a/firmware/controllers/sensors/maf.cpp +++ b/firmware/controllers/sensors/maf.cpp @@ -17,7 +17,7 @@ float getMaf(DECLARE_ENGINE_PARAMETER_F) { * @return kg/hour value */ float getRealMaf(DECLARE_ENGINE_PARAMETER_F) { - int mafAdc = getAdcValue(engineConfiguration->mafAdcChannel); + int mafAdc = getAdcValue("maf", engineConfiguration->mafAdcChannel); /** * here we drop from 12 bit ADC to 8 bit index */ diff --git a/firmware/controllers/sensors/maf.h b/firmware/controllers/sensors/maf.h index c30e5526ee..fc0b9e77b4 100644 --- a/firmware/controllers/sensors/maf.h +++ b/firmware/controllers/sensors/maf.h @@ -14,7 +14,7 @@ #include "main.h" -#define getMafT(ec) (getVoltageDivided(ec->mafAdcChannel)) +#define getMafT(ec) (getVoltageDivided("maf", ec->mafAdcChannel)) float getMaf(void); float getRealMaf(DECLARE_ENGINE_PARAMETER_F); diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index 65304d5e70..6f1e36857b 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -76,12 +76,12 @@ float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_S) { * @return Manifold Absolute Pressure, in kPa */ float getRawMap(DECLARE_ENGINE_PARAMETER_F) { - float voltage = getVoltageDivided(engineConfiguration->map.sensor.hwChannel); + float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel); return getMapByVoltage(voltage PASS_ENGINE_PARAMETER); } float getBaroPressure(DECLARE_ENGINE_PARAMETER_F) { - float voltage = getVoltageDivided(engineConfiguration->baroSensor.hwChannel); + float voltage = getVoltageDivided("map", engineConfiguration->baroSensor.hwChannel); return decodePressure(voltage, &engineConfiguration->baroSensor); } diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index 97141df812..4372c9d96c 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -78,7 +78,7 @@ float getKelvinTemperature(float resistance, ThermistorConf *thermistor) { } float getResistance(Thermistor *thermistor) { - float voltage = getVoltageDivided(thermistor->channel); + float voltage = getVoltageDivided("term", thermistor->channel); efiAssert(thermistor->config != NULL, "thermistor config is null", NAN); float resistance = getR2InVoltageDividor(voltage, _5_VOLTS, thermistor->config->bias_resistor); return resistance; diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 2ba6f8a24e..5e5d4e8a31 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -72,7 +72,7 @@ static float getTpsValue(int adc DECLARE_ENGINE_PARAMETER_S) { * Return voltage on TPS AND channel * */ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_F) { - return getVoltageDivided(engineConfiguration->tpsAdcChannel); + return getVoltageDivided("tps", engineConfiguration->tpsAdcChannel); } /* diff --git a/firmware/controllers/sensors/voltage.cpp b/firmware/controllers/sensors/voltage.cpp index 920bba380c..e896de9687 100644 --- a/firmware/controllers/sensors/voltage.cpp +++ b/firmware/controllers/sensors/voltage.cpp @@ -13,9 +13,9 @@ #include "voltage.h" float getVRef(engine_configuration_s *engineConfiguration) { - return getVoltageDivided(engineConfiguration->vRefAdcChannel); + return getVoltageDivided("vref", engineConfiguration->vRefAdcChannel); } float getVBatt(engine_configuration_s *engineConfiguration) { - return getVoltage(engineConfiguration->vbattAdcChannel) * engineConfiguration->vbattDividerCoeff; + return getVoltage("vbatt", engineConfiguration->vbattAdcChannel) * engineConfiguration->vbattDividerCoeff; } diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a861dfd9d4..082d129896 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -368,7 +368,7 @@ static char pinNameBuffer[16]; static void printThermistor(const char *msg, Thermistor *thermistor) { adc_channel_e adcChannel = thermistor->channel; - float voltage = getVoltageDivided(adcChannel); + float voltage = getVoltageDivided("term", adcChannel); float r = getResistance(thermistor); float t = getTemperatureC(thermistor); diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 34b1456411..761200b24a 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -353,7 +353,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL if (eventIndex == engineConfiguration->ignMathCalculateAtIndex) { if (engineConfiguration->externalKnockSenseAdc != EFI_ADC_NONE) { - float externalKnockValue = getVoltageDivided(engineConfiguration->externalKnockSenseAdc); + float externalKnockValue = getVoltageDivided("knock", engineConfiguration->externalKnockSenseAdc); engine->knockNow = externalKnockValue > 2.5; engine->knockEver |= engine->knockNow; } diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index 4f713203c5..026e85f17e 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -119,7 +119,7 @@ static void showHipInfo(void) { nonZeroResponse); scheduleMsg(logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); - scheduleMsg(logger, "value=%f@#%d", getVoltageDivided(engineConfiguration->hipOutputChannel), + scheduleMsg(logger, "value=%f@#%d", getVoltageDivided("hip", engineConfiguration->hipOutputChannel), engineConfiguration->hipOutputChannel); } diff --git a/firmware/hw_layer/adc_external.h b/firmware/hw_layer/adc_external.h index a4122c9ae5..d777cdc7b2 100644 --- a/firmware/hw_layer/adc_external.h +++ b/firmware/hw_layer/adc_external.h @@ -13,6 +13,6 @@ #define getAdcValue(channel) getMcp3208adc(channel) #define adcToVoltsDivided(adc) (5.0f / 4095 * adc) -#define getVoltageDivided(channel) (channel == EFI_ADC_NONE ? 66.66 : adcToVoltsDivided(getAdcValue(channel))) +#define getVoltageDivided(msg, channel) (channel == EFI_ADC_NONE ? 66.66 : adcToVoltsDivided(getAdcValue(msg, channel))) #endif /* ADC_EXTERNAL_H_ */ diff --git a/firmware/hw_layer/adc_inputs.cpp b/firmware/hw_layer/adc_inputs.cpp index fbcee923ef..b2d8e28021 100644 --- a/firmware/hw_layer/adc_inputs.cpp +++ b/firmware/hw_layer/adc_inputs.cpp @@ -18,6 +18,7 @@ #include "pin_repository.h" #include "engine_math.h" #include "board_test.h" +#include "engine_controller.h" static adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX]; @@ -187,9 +188,9 @@ static void pwmpcb_fast(PWMDriver *pwmp) { #endif } -int getInternalAdcValue(adc_channel_e hwChannel) { +int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) { if (hwChannel == EFI_ADC_NONE) { - warning(OBD_PCM_Processor_Fault, "ADC: should not be asking for NONE"); + warning(OBD_PCM_Processor_Fault, "ADC: should not be asking for NONE %s", msg); return -1; } @@ -404,7 +405,7 @@ void AdcDevice::addChannel(adc_channel_e hwChannel) { } static void printAdcValue(adc_channel_e channel) { - int value = getAdcValue(channel); + int value = getAdcValue("print", channel); float volts = adcToVoltsDivided(value); scheduleMsg(&logger, "adc voltage : %f", volts); } @@ -465,12 +466,15 @@ static void adc_callback_slow(ADCDriver *adcp, adcsample_t *buffer, size_t n) { } } +static char errorMsgBuff[10]; + static void addChannel(const char *name, adc_channel_e setting, adc_channel_mode_e mode) { if (setting == EFI_ADC_NONE) { return; } if (adcHwChannelEnabled[setting] != ADC_OFF) { - firmwareError("ADC mapping error: input for %s already used?", name); + getPinNameByAdcChannel(setting, errorMsgBuff); + firmwareError("ADC mapping error: input %s for %s already used?", errorMsgBuff, name); } adcHwChannelEnabled[setting] = mode; diff --git a/firmware/hw_layer/adc_inputs.h b/firmware/hw_layer/adc_inputs.h index 4595d13264..02a8ca1dd4 100644 --- a/firmware/hw_layer/adc_inputs.h +++ b/firmware/hw_layer/adc_inputs.h @@ -24,7 +24,7 @@ adc_channel_e getAdcChannel(brain_pin_e pin); int getAdcHardwareIndexByInternalIndex(int index); void pokeAdcInputs(void); -int getInternalAdcValue(adc_channel_e index); +int getInternalAdcValue(const char *msg, adc_channel_e index); /* Depth of the conversion buffer, channels are sampled X times each.*/ #define ADC_BUF_DEPTH_SLOW 1 @@ -43,7 +43,7 @@ typedef struct { // time_t time; } adc_state; -#define getAdcValue(hwChannel) getInternalAdcValue(hwChannel) +#define getAdcValue(msg, hwChannel) getInternalAdcValue(msg, hwChannel) // todo: migrate to adcToVoltageInputDividerCoefficient #define adcToVoltsDivided(adc) (adcToVolts(adc) * engineConfiguration->analogInputDividerCoefficient) diff --git a/firmware/hw_layer/algo/adc_math.h b/firmware/hw_layer/algo/adc_math.h index a541d19d94..f2f43054ef 100644 --- a/firmware/hw_layer/algo/adc_math.h +++ b/firmware/hw_layer/algo/adc_math.h @@ -16,8 +16,8 @@ #define voltsToAdc(volts) ((volts) * (ADC_MAX_VALUE / ADC_VCC)) -#define getVoltage(hwChannel) (adcToVolts(getAdcValue(hwChannel))) +#define getVoltage(msg, hwChannel) (adcToVolts(getAdcValue(msg, hwChannel))) -#define getVoltageDivided(hwChannel) (getVoltage(hwChannel) * engineConfiguration->analogInputDividerCoefficient) +#define getVoltageDivided(msg, hwChannel) (getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient) #endif /* ADC_MATH_H_ */ diff --git a/unit_tests/boards.cpp b/unit_tests/boards.cpp index 094855ac66..157e11fb16 100644 --- a/unit_tests/boards.cpp +++ b/unit_tests/boards.cpp @@ -9,7 +9,7 @@ float testMafValue = 0; -float getVoltageDivided(int channel) { +float getVoltageDivided(const char *msg, int channel) { switch(channel) { case TEST_MAF_CHANNEL: return testMafValue; @@ -17,11 +17,11 @@ float getVoltageDivided(int channel) { return 0; } -float getVoltage(int channel) { +float getVoltage(const char *msg, int channel) { return 0; } -int getAdcValue(int channel) { +int getAdcValue(const char *msg, int channel) { return 0; } diff --git a/unit_tests/boards.h b/unit_tests/boards.h index 15d9a0a4f1..4577a22d89 100644 --- a/unit_tests/boards.h +++ b/unit_tests/boards.h @@ -12,8 +12,8 @@ #define TEST_MAF_CHANNEL 10000013 -float getVoltageDivided(int); -float getVoltage(int channel); -int getAdcValue(int channel); +float getVoltageDivided(const char *msg, int); +float getVoltage(const char *msg, int channel); +int getAdcValue(const char *msg, int channel); #endif /* BOARDS_H_ */