The Big Refactoring of 2019: DECLARE_ENGINE_PARAMETER_SUFFIX consistency and simplification #657

This commit is contained in:
rusefi 2019-01-09 22:57:33 -05:00
parent 57993ff1b4
commit cbd2d69731
33 changed files with 235 additions and 232 deletions

View File

@ -49,7 +49,7 @@ static void runCommands() {
chThdSleepMilliseconds(1000); // safety chThdSleepMilliseconds(1000); // safety
// Store current serial port speed - we're going to change it // Store current serial port speed - we're going to change it
int savedSerialSpeed = boardConfiguration->tunerStudioSerialSpeed; int savedSerialSpeed = CONFIGB(tunerStudioSerialSpeed);
int prevBaudIdx = -1, baudIdx = -1, baudListIdx = 0; int prevBaudIdx = -1, baudIdx = -1, baudListIdx = 0;
int cmdIdx = 0; int cmdIdx = 0;
@ -75,7 +75,7 @@ static void runCommands() {
} }
chThdSleepMilliseconds(10); // safety chThdSleepMilliseconds(10); // safety
// change the port speed // change the port speed
boardConfiguration->tunerStudioSerialSpeed = restoreAndExit ? savedSerialSpeed : baudRates[baudIdx]; CONFIGB(tunerStudioSerialSpeed) = restoreAndExit ? savedSerialSpeed : baudRates[baudIdx];
// init UART // init UART
startTsPort(tsChannel); startTsPort(tsChannel);
chThdSleepMilliseconds(10); // safety chThdSleepMilliseconds(10); // safety
@ -160,7 +160,7 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c
tsChannel = tsChan; tsChannel = tsChan;
// if a binary protocol uses USB, we cannot init the bluetooth module! // if a binary protocol uses USB, we cannot init the bluetooth module!
if (!boardConfiguration->useSerialPort) { if (!CONFIGB(useSerialPort)) {
scheduleMsg(&btLogger, "Failed! Serial Port connection is disabled!"); scheduleMsg(&btLogger, "Failed! Serial Port connection is disabled!");
return; return;
} }

View File

@ -148,7 +148,7 @@ static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINE
bool consoleInBinaryMode = false; bool consoleInBinaryMode = false;
void runConsoleLoop(ts_channel_s *console) { void runConsoleLoop(ts_channel_s *console) {
if (boardConfiguration->startConsoleInBinaryMode) { if (CONFIGB(startConsoleInBinaryMode)) {
// switch to binary protocol // switch to binary protocol
consoleInBinaryMode = true; consoleInBinaryMode = true;
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__) #if EFI_TUNER_STUDIO || defined(__DOXYGEN__)

View File

@ -400,21 +400,21 @@ void printOverallStatus(systime_t nowSeconds) {
getTimeNowSeconds(), getTimeNowSeconds(),
DELIMETER); DELIMETER);
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
printOutPin(CRANK1, boardConfiguration->triggerInputPins[0]); printOutPin(CRANK1, CONFIGB(triggerInputPins)[0]);
printOutPin(CRANK2, boardConfiguration->triggerInputPins[1]); printOutPin(CRANK2, CONFIGB(triggerInputPins)[1]);
printOutPin(VVT_NAME, engineConfiguration->camInput); printOutPin(VVT_NAME, engineConfiguration->camInput);
printOutPin(HIP_NAME, boardConfiguration->hip9011IntHoldPin); printOutPin(HIP_NAME, CONFIGB(hip9011IntHoldPin));
printOutPin(TACH_NAME, boardConfiguration->tachOutputPin); printOutPin(TACH_NAME, CONFIGB(tachOutputPin));
printOutPin(DIZZY_NAME, engineConfiguration->dizzySparkOutputPin); printOutPin(DIZZY_NAME, engineConfiguration->dizzySparkOutputPin);
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
printOutPin(WA_CHANNEL_1, boardConfiguration->logicAnalyzerPins[0]); printOutPin(WA_CHANNEL_1, CONFIGB(logicAnalyzerPins)[0]);
printOutPin(WA_CHANNEL_2, boardConfiguration->logicAnalyzerPins[1]); printOutPin(WA_CHANNEL_2, CONFIGB(logicAnalyzerPins)[1]);
#endif /* EFI_WAVE_ANALYZER */ #endif /* EFI_WAVE_ANALYZER */
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
printOutPin(enginePins.coils[i].name, boardConfiguration->ignitionPins[i]); printOutPin(enginePins.coils[i].name, CONFIGB(ignitionPins)[i]);
printOutPin(enginePins.injectors[i].name, boardConfiguration->injectionPins[i]); printOutPin(enginePins.injectors[i].name, CONFIGB(injectionPins)[i]);
} }
for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) { for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) {
printOutPin(enginePins.auxValve[i].name, engineConfiguration->auxValves[i]); printOutPin(enginePins.auxValve[i].name, engineConfiguration->auxValves[i]);
@ -558,7 +558,7 @@ static OutputPin *leds[] = { &enginePins.warningLedPin, &enginePins.runningLedPi
static void initStatusLeds(void) { static void initStatusLeds(void) {
enginePins.communicationLedPin.initPin("led: comm status", engineConfiguration->communicationLedPin); enginePins.communicationLedPin.initPin("led: comm status", engineConfiguration->communicationLedPin);
// we initialize this here so that we can blink it on start-up // we initialize this here so that we can blink it on start-up
enginePins.checkEnginePin.initPin("MalfunctionIndicator", boardConfiguration->malfunctionIndicatorPin, &boardConfiguration->malfunctionIndicatorPinMode); enginePins.checkEnginePin.initPin("MalfunctionIndicator", CONFIGB(malfunctionIndicatorPin), &CONFIGB(malfunctionIndicatorPinMode));
#if EFI_WARNING_LED || defined(__DOXYGEN__) #if EFI_WARNING_LED || defined(__DOXYGEN__)

View File

@ -35,7 +35,7 @@ static void startPwmTest(int freq) {
/** /**
* See custom_engine.cpp for pinout * See custom_engine.cpp for pinout
*/ */
// currently this is PB9 by default - see boardConfiguration->injectionPins // currently this is PB9 by default - see CONFIGB(injectionPins)
startSimplePwm(&pwmTest[1], "tester", &enginePins.injectors[0], freq / 1.3333333333, 0.5f, applyPinState); startSimplePwm(&pwmTest[1], "tester", &enginePins.injectors[0], freq / 1.3333333333, 0.5f, applyPinState);
// currently this is PE2 by default // currently this is PE2 by default
startSimplePwm(&pwmTest[2], "tester", &enginePins.injectors[1], freq / 1000, 0.5f, applyPinState); startSimplePwm(&pwmTest[2], "tester", &enginePins.injectors[1], freq / 1000, 0.5f, applyPinState);

View File

@ -61,7 +61,7 @@ static const ignition_table_t defaultIatTiming = {
}; };
bool isStep1Condition(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { bool isStep1Condition(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
return boardConfiguration->enabledStep1Limiter && rpm >= engineConfiguration->step1rpm; return CONFIGB(enabledStep1Limiter) && rpm >= engineConfiguration->step1rpm;
} }
/** /**
@ -97,7 +97,7 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME
float idleAdvance = interpolate2d("idleAdvance", rpm, config->idleAdvanceBins, config->idleAdvance, IDLE_ADVANCE_CURVE_SIZE); float idleAdvance = interpolate2d("idleAdvance", rpm, config->idleAdvanceBins, config->idleAdvance, IDLE_ADVANCE_CURVE_SIZE);
// interpolate between idle table and normal (running) table using TPS threshold // interpolate between idle table and normal (running) table using TPS threshold
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
advanceAngle = interpolateClamped(0.0f, idleAdvance, boardConfiguration->idlePidDeactivationTpsThreshold, advanceAngle, tps); advanceAngle = interpolateClamped(0.0f, idleAdvance, CONFIGB(idlePidDeactivationTpsThreshold), advanceAngle, tps);
} }
engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance; engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance;

View File

@ -77,7 +77,7 @@ static msg_t AltCtrlThread(int param) {
float vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE); float vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE);
float targetVoltage = engineConfiguration->targetVBatt; float targetVoltage = engineConfiguration->targetVBatt;
if (boardConfiguration->onOffAlternatorLogic) { if (CONFIGB(onOffAlternatorLogic)) {
float h = 0.1; float h = 0.1;
bool newState = (vBatt < targetVoltage - h) || (currentPlainOnOffState && vBatt < targetVoltage); bool newState = (vBatt < targetVoltage - h) || (currentPlainOnOffState && vBatt < targetVoltage);
enginePins.alternatorPin.setValue(newState); enginePins.alternatorPin.setValue(newState);
@ -93,7 +93,7 @@ static msg_t AltCtrlThread(int param) {
currentAltDuty = altPid.getValue(targetVoltage, vBatt); currentAltDuty = altPid.getValue(targetVoltage, vBatt);
if (boardConfiguration->isVerboseAlternator) { if (CONFIGB(isVerboseAlternator)) {
scheduleMsg(logger, "alt duty: %.2f/vbatt=%.2f/p=%.2f/i=%.2f/d=%.2f int=%.2f", currentAltDuty, vBatt, scheduleMsg(logger, "alt duty: %.2f/vbatt=%.2f/p=%.2f/i=%.2f/d=%.2f int=%.2f", currentAltDuty, vBatt,
altPid.getP(), altPid.getI(), altPid.getD(), altPid.getIntegration()); altPid.getP(), altPid.getI(), altPid.getD(), altPid.getIntegration());
} }
@ -109,7 +109,7 @@ static msg_t AltCtrlThread(int param) {
void showAltInfo(void) { void showAltInfo(void) {
scheduleMsg(logger, "alt=%s @%s t=%dms", boolToString(engineConfiguration->isAlternatorControlEnabled), scheduleMsg(logger, "alt=%s @%s t=%dms", boolToString(engineConfiguration->isAlternatorControlEnabled),
hwPortname(boardConfiguration->alternatorControlPin), hwPortname(CONFIGB(alternatorControlPin)),
engineConfiguration->alternatorControl.period); engineConfiguration->alternatorControl.period);
scheduleMsg(logger, "p=%.2f/i=%.2f/d=%.2f offset=%.2f", engineConfiguration->alternatorControl.pFactor, scheduleMsg(logger, "p=%.2f/i=%.2f/d=%.2f offset=%.2f", engineConfiguration->alternatorControl.pFactor,
0, 0, engineConfiguration->alternatorControl.offset); // todo: i & d 0, 0, engineConfiguration->alternatorControl.offset); // todo: i & d
@ -139,8 +139,8 @@ static void applyAlternatorPinState(PwmConfig *state, int stateIndex) {
void setDefaultAlternatorParameters(void) { void setDefaultAlternatorParameters(void) {
engineConfiguration->alternatorOffAboveTps = 120; engineConfiguration->alternatorOffAboveTps = 120;
boardConfiguration->alternatorControlPin = GPIO_UNASSIGNED; CONFIGB(alternatorControlPin) = GPIO_UNASSIGNED;
boardConfiguration->alternatorControlPinMode = OM_DEFAULT; CONFIGB(alternatorControlPinMode) = OM_DEFAULT;
engineConfiguration->targetVBatt = 14; engineConfiguration->targetVBatt = 14;
engineConfiguration->alternatorControl.offset = 0; engineConfiguration->alternatorControl.offset = 0;
@ -155,17 +155,17 @@ void onConfigurationChangeAlternatorCallback(engine_configuration_s *previousCon
void initAlternatorCtrl(Logging *sharedLogger) { void initAlternatorCtrl(Logging *sharedLogger) {
logger = sharedLogger; logger = sharedLogger;
addConsoleAction("altinfo", showAltInfo); addConsoleAction("altinfo", showAltInfo);
if (boardConfiguration->alternatorControlPin == GPIO_UNASSIGNED) if (CONFIGB(alternatorControlPin) == GPIO_UNASSIGNED)
return; return;
if (boardConfiguration->onOffAlternatorLogic) { if (CONFIGB(onOffAlternatorLogic)) {
enginePins.alternatorPin.initPin("on/off alternator", boardConfiguration->alternatorControlPin); enginePins.alternatorPin.initPin("on/off alternator", CONFIGB(alternatorControlPin));
} else { } else {
startSimplePwmExt(&alternatorControl, startSimplePwmExt(&alternatorControl,
"Alternator control", "Alternator control",
&engine->executor, &engine->executor,
boardConfiguration->alternatorControlPin, CONFIGB(alternatorControlPin),
&enginePins.alternatorPin, &enginePins.alternatorPin,
engineConfiguration->alternatorPwmFrequency, 0.1, applyAlternatorPinState); engineConfiguration->alternatorPwmFrequency, 0.1, applyAlternatorPinState);
} }

View File

@ -228,7 +228,7 @@ static void periodicSlowCallback(Engine *engine);
static void scheduleNextSlowInvocation(void) { static void scheduleNextSlowInvocation(void) {
// schedule next invocation // schedule next invocation
int periodMs = boardConfiguration->generalPeriodicThreadPeriod; int periodMs = CONFIGB(generalPeriodicThreadPeriod);
if (periodMs == 0) if (periodMs == 0)
periodMs = 50; // this might happen while resetting configuration periodMs = 50; // this might happen while resetting configuration
chVTSetAny(&periodicSlowTimer, MS2ST(periodMs), (vtfunc_t) &periodicSlowCallback, engine); chVTSetAny(&periodicSlowTimer, MS2ST(periodMs), (vtfunc_t) &periodicSlowCallback, engine);
@ -370,7 +370,7 @@ static void printAnalogChannelInfoExt(const char *name, adc_channel_e hwChannel,
} }
if (fastAdc.isHwUsed(hwChannel)) { if (fastAdc.isHwUsed(hwChannel)) {
scheduleMsg(&logger, "fast enabled=%s", boolToString(boardConfiguration->isFastAdcEnabled)); scheduleMsg(&logger, "fast enabled=%s", boolToString(CONFIGB(isFastAdcEnabled)));
} }
float voltage = adcVoltage * dividerCoeff; float voltage = adcVoltage * dividerCoeff;
@ -735,7 +735,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE); initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
if (boardConfiguration->isEngineControlEnabled) { if (CONFIGB(isEngineControlEnabled)) {
/** /**
* This method initialized the main listener which actually runs injectors & ignition * This method initialized the main listener which actually runs injectors & ignition
*/ */

View File

@ -99,18 +99,18 @@ void idleDebug(const char *msg, percent_t value) {
static void showIdleInfo(void) { static void showIdleInfo(void) {
const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode); const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode);
scheduleMsg(logger, "idleMode=%s position=%.2f isStepper=%s", idleModeStr, scheduleMsg(logger, "idleMode=%s position=%.2f isStepper=%s", idleModeStr,
getIdlePosition(), boolToString(boardConfiguration->useStepperIdle)); getIdlePosition(), boolToString(CONFIGB(useStepperIdle)));
if (boardConfiguration->useStepperIdle) { if (CONFIGB(useStepperIdle)) {
scheduleMsg(logger, "directionPin=%s reactionTime=%.2f", hwPortname(boardConfiguration->idle.stepperDirectionPin), scheduleMsg(logger, "directionPin=%s reactionTime=%.2f", hwPortname(CONFIGB(idle).stepperDirectionPin),
engineConfiguration->idleStepperReactionTime); engineConfiguration->idleStepperReactionTime);
scheduleMsg(logger, "stepPin=%s steps=%d", hwPortname(boardConfiguration->idle.stepperStepPin), scheduleMsg(logger, "stepPin=%s steps=%d", hwPortname(CONFIGB(idle).stepperStepPin),
engineConfiguration->idleStepperTotalSteps); engineConfiguration->idleStepperTotalSteps);
scheduleMsg(logger, "enablePin=%s/%d", hwPortname(engineConfiguration->stepperEnablePin), scheduleMsg(logger, "enablePin=%s/%d", hwPortname(engineConfiguration->stepperEnablePin),
engineConfiguration->stepperEnablePinMode); engineConfiguration->stepperEnablePinMode);
} else { } else {
scheduleMsg(logger, "idle valve freq=%d on %s", boardConfiguration->idle.solenoidFrequency, scheduleMsg(logger, "idle valve freq=%d on %s", CONFIGB(idle).solenoidFrequency,
hwPortname(boardConfiguration->idle.solenoidPin)); hwPortname(CONFIGB(idle).solenoidPin));
} }
@ -125,7 +125,7 @@ void setIdleMode(idle_mode_e value) {
} }
static void applyIACposition(percent_t position) { static void applyIACposition(percent_t position) {
if (boardConfiguration->useStepperIdle) { if (CONFIGB(useStepperIdle)) {
iacMotor.setTargetPosition(position / 100 * engineConfiguration->idleStepperTotalSteps); iacMotor.setTargetPosition(position / 100 * engineConfiguration->idleStepperTotalSteps);
} else { } else {
/** /**
@ -138,7 +138,7 @@ static void applyIACposition(percent_t position) {
static percent_t manualIdleController(float cltCorrection) { static percent_t manualIdleController(float cltCorrection) {
percent_t correctedPosition = cltCorrection * boardConfiguration->manIdlePosition; percent_t correctedPosition = cltCorrection * CONFIGB(manIdlePosition);
// let's put the value into the right range // let's put the value into the right range
correctedPosition = maxF(correctedPosition, 0.01); correctedPosition = maxF(correctedPosition, 0.01);
@ -153,7 +153,7 @@ void setIdleValvePosition(int positionPercent) {
scheduleMsg(logger, "setting idle valve position %d", positionPercent); scheduleMsg(logger, "setting idle valve position %d", positionPercent);
showIdleInfo(); showIdleInfo();
// todo: this is not great that we have to write into configuration here // todo: this is not great that we have to write into configuration here
boardConfiguration->manIdlePosition = positionPercent; CONFIGB(manIdlePosition) = positionPercent;
} }
static percent_t blipIdlePosition; static percent_t blipIdlePosition;
@ -191,7 +191,7 @@ percent_t getIdlePosition(void) {
*/ */
static percent_t automaticIdleController() { static percent_t automaticIdleController() {
percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
if (tpsPos > boardConfiguration->idlePidDeactivationTpsThreshold) { if (tpsPos > CONFIGB(idlePidDeactivationTpsThreshold)) {
// Don't store old I and D terms if PID doesn't work anymore. // Don't store old I and D terms if PID doesn't work anymore.
// Otherwise they will affect the idle position much later, when the throttle is closed. // Otherwise they will affect the idle position much later, when the throttle is closed.
if (mightResetPid) { if (mightResetPid) {
@ -240,7 +240,7 @@ static percent_t automaticIdleController() {
#if EFI_IDLE_INCREMENTAL_PID_CIC || defined(__DOXYGEN__) #if EFI_IDLE_INCREMENTAL_PID_CIC || defined(__DOXYGEN__)
// Treat the 'newValue' as if it contains not an actual IAC position, but an incremental delta. // Treat the 'newValue' as if it contains not an actual IAC position, but an incremental delta.
// So we add this delta to the base IAC position, with a smooth taper for TPS transients. // So we add this delta to the base IAC position, with a smooth taper for TPS transients.
newValue = baseIdlePosition + interpolateClamped(0.0f, newValue, boardConfiguration->idlePidDeactivationTpsThreshold, 0.0f, tpsPos); newValue = baseIdlePosition + interpolateClamped(0.0f, newValue, CONFIGB(idlePidDeactivationTpsThreshold), 0.0f, tpsPos);
// apply the PID limits // apply the PID limits
newValue = maxF(newValue, CONFIG(idleRpmPid.minValue)); newValue = maxF(newValue, CONFIG(idleRpmPid.minValue));
@ -254,7 +254,7 @@ static percent_t automaticIdleController() {
// Currently it's user-defined. But eventually we'll use a real calculated and stored IAC position instead. // Currently it's user-defined. But eventually we'll use a real calculated and stored IAC position instead.
int idlePidLowerRpm = targetRpm + CONFIG(idlePidRpmDeadZone); int idlePidLowerRpm = targetRpm + CONFIG(idlePidRpmDeadZone);
if (CONFIG(idlePidRpmUpperLimit) > 0) { if (CONFIG(idlePidRpmUpperLimit) > 0) {
if (boardConfiguration->useIacTableForCoasting) { if (CONFIGB(useIacTableForCoasting)) {
percent_t iacPosForCoasting = interpolate2d("iacCoasting", clt, CONFIG(iacCoastingBins), CONFIG(iacCoasting), CLT_CURVE_SIZE); percent_t iacPosForCoasting = interpolate2d("iacCoasting", clt, CONFIG(iacCoastingBins), CONFIG(iacCoasting), CLT_CURVE_SIZE);
newValue = interpolateClamped(idlePidLowerRpm, newValue, idlePidLowerRpm + CONFIG(idlePidRpmUpperLimit), iacPosForCoasting, rpm); newValue = interpolateClamped(idlePidLowerRpm, newValue, idlePidLowerRpm + CONFIG(idlePidRpmUpperLimit), iacPosForCoasting, rpm);
} else { } else {
@ -293,11 +293,11 @@ static msg_t ivThread(int param) {
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
// this value is not used yet // this value is not used yet
if (boardConfiguration->clutchDownPin != GPIO_UNASSIGNED) { if (CONFIGB(clutchDownPin) != GPIO_UNASSIGNED) {
engine->clutchDownState = efiReadPin(boardConfiguration->clutchDownPin); engine->clutchDownState = efiReadPin(CONFIGB(clutchDownPin));
} }
if (boardConfiguration->clutchUpPin != GPIO_UNASSIGNED) { if (CONFIGB(clutchUpPin) != GPIO_UNASSIGNED) {
engine->clutchUpState = efiReadPin(boardConfiguration->clutchUpPin); engine->clutchUpState = efiReadPin(CONFIGB(clutchUpPin));
} }
if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) { if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) {
@ -346,7 +346,7 @@ static msg_t ivThread(int param) {
percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
float additionalAir = (float)engineConfiguration->iacByTpsTaper; float additionalAir = (float)engineConfiguration->iacByTpsTaper;
iacPosition += interpolateClamped(0.0f, 0.0f, boardConfiguration->idlePidDeactivationTpsThreshold, additionalAir, tpsPos); iacPosition += interpolateClamped(0.0f, 0.0f, CONFIGB(idlePidDeactivationTpsThreshold), additionalAir, tpsPos);
// taper transition from cranking to running (uint32_t to float conversion is safe here) // taper transition from cranking to running (uint32_t to float conversion is safe here)
if (engineConfiguration->afterCrankingIACtaperDuration > 0) if (engineConfiguration->afterCrankingIACtaperDuration > 0)
@ -426,7 +426,7 @@ void setIdleDT(int value) {
void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration) { void onConfigurationChangeIdleCallback(engine_configuration_s *previousConfiguration) {
shouldResetPid = !idlePid.isSame(&previousConfiguration->idleRpmPid); shouldResetPid = !idlePid.isSame(&previousConfiguration->idleRpmPid);
idleSolenoid.setFrequency(boardConfiguration->idle.solenoidFrequency); idleSolenoid.setFrequency(CONFIGB(idle).solenoidFrequency);
} }
void startIdleBench(void) { void startIdleBench(void) {
@ -455,8 +455,8 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
} }
static void initIdleHardware() { static void initIdleHardware() {
if (boardConfiguration->useStepperIdle) { if (CONFIGB(useStepperIdle)) {
iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin, iacMotor.initialize(CONFIGB(idle).stepperStepPin, CONFIGB(idle).stepperDirectionPin,
engineConfiguration->stepperDirectionPinMode, engineConfiguration->idleStepperReactionTime, engineConfiguration->stepperDirectionPinMode, engineConfiguration->idleStepperReactionTime,
engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin, logger); engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin, logger);
// This greatly improves PID accuracy for steppers with a small number of steps // This greatly improves PID accuracy for steppers with a small number of steps
@ -467,8 +467,8 @@ static void initIdleHardware() {
*/ */
startSimplePwmExt(&idleSolenoid, "Idle Valve", startSimplePwmExt(&idleSolenoid, "Idle Valve",
&engine->executor, &engine->executor,
boardConfiguration->idle.solenoidPin, &enginePins.idleSolenoidPin, CONFIGB(idle).solenoidPin, &enginePins.idleSolenoidPin,
boardConfiguration->idle.solenoidFrequency, boardConfiguration->manIdlePosition / 100, CONFIGB(idle).solenoidFrequency, CONFIGB(manIdlePosition) / 100,
applyIdleSolenoidPinState); applyIdleSolenoidPinState);
idlePositionSensitivityThreshold = 0.0f; idlePositionSensitivityThreshold = 0.0f;
} }
@ -486,14 +486,14 @@ void startIdleThread(Logging*sharedLogger) {
// this is idle switch INPUT - sometimes there is a switch on the throttle pedal // this is idle switch INPUT - sometimes there is a switch on the throttle pedal
// this switch is not used yet // this switch is not used yet
if (boardConfiguration->clutchDownPin != GPIO_UNASSIGNED) { if (CONFIGB(clutchDownPin) != GPIO_UNASSIGNED) {
efiSetPadMode("clutch down switch", boardConfiguration->clutchDownPin, efiSetPadMode("clutch down switch", CONFIGB(clutchDownPin),
getInputMode(boardConfiguration->clutchDownPinMode)); getInputMode(CONFIGB(clutchDownPinMode)));
} }
if (boardConfiguration->clutchUpPin != GPIO_UNASSIGNED) { if (CONFIGB(clutchUpPin) != GPIO_UNASSIGNED) {
efiSetPadMode("clutch up switch", boardConfiguration->clutchUpPin, efiSetPadMode("clutch up switch", CONFIGB(clutchUpPin),
getInputMode(boardConfiguration->clutchUpPinMode)); getInputMode(CONFIGB(clutchUpPinMode)));
} }
if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) { if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) {

View File

@ -139,7 +139,7 @@ static void doRunFuel(int humanIndex, const char *delayStr, const char * onTimeS
scheduleMsg(logger, "Invalid index: %d", humanIndex); scheduleMsg(logger, "Invalid index: %d", humanIndex);
return; return;
} }
brain_pin_e b = boardConfiguration->injectionPins[humanIndex - 1]; brain_pin_e b = CONFIGB(injectionPins)[humanIndex - 1];
pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.injectors[humanIndex - 1], b); pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.injectors[humanIndex - 1], b);
} }
@ -154,7 +154,7 @@ static void fuelbench2(const char *delayStr, const char *indexStr, const char *
} }
static void fanBenchExt(const char *durationMs) { static void fanBenchExt(const char *durationMs) {
pinbench("0", durationMs, "100", "1", &enginePins.fanRelay, boardConfiguration->fanPin); pinbench("0", durationMs, "100", "1", &enginePins.fanRelay, CONFIGB(fanPin));
} }
void fanBench(void) { void fanBench(void) {
@ -162,11 +162,11 @@ void fanBench(void) {
} }
void milBench(void) { void milBench(void) {
pinbench("0", "500", "500", "16", &enginePins.checkEnginePin, boardConfiguration->malfunctionIndicatorPin); pinbench("0", "500", "500", "16", &enginePins.checkEnginePin, CONFIGB(malfunctionIndicatorPin));
} }
void fuelPumpBenchExt(const char *durationMs) { void fuelPumpBenchExt(const char *durationMs) {
pinbench("0", durationMs, "100", "1", &enginePins.fuelPumpRelay, boardConfiguration->fuelPumpPin); pinbench("0", durationMs, "100", "1", &enginePins.fuelPumpRelay, CONFIGB(fuelPumpPin));
} }
void fuelPumpBench(void) { void fuelPumpBench(void) {
@ -184,7 +184,7 @@ static void doRunSpark(int humanIndex, const char *delayStr, const char * onTime
scheduleMsg(logger, "Invalid index: %d", humanIndex); scheduleMsg(logger, "Invalid index: %d", humanIndex);
return; return;
} }
brain_pin_e b = boardConfiguration->ignitionPins[humanIndex - 1]; brain_pin_e b = CONFIGB(ignitionPins)[humanIndex - 1];
pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.coils[humanIndex - 1], b); pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.coils[humanIndex - 1], b);
} }

View File

@ -212,7 +212,7 @@ static void showLine(lcd_line_e line, int screenY) {
#if EFI_FILE_LOGGING || defined(__DOXYGEN__) #if EFI_FILE_LOGGING || defined(__DOXYGEN__)
{ {
char sdState; char sdState;
if (boardConfiguration->isSdCardEnabled) { if (CONFIGB(isSdCardEnabled)) {
sdState = isSdCardAlive() ? 'L' : 'n'; sdState = isSdCardAlive() ? 'L' : 'n';
} else { } else {
sdState = 'D'; sdState = 'D';

View File

@ -205,7 +205,7 @@ static void endAveraging(void *arg) {
static void applyMapMinBufferLength() { static void applyMapMinBufferLength() {
// check range // check range
mapMinBufferLength = maxI(minI(boardConfiguration->mapMinBufferLength, MAX_MAP_BUFFER_LENGTH), 1); mapMinBufferLength = maxI(minI(CONFIGB(mapMinBufferLength), MAX_MAP_BUFFER_LENGTH), 1);
// reset index // reset index
averagedMapBufIdx = 0; averagedMapBufIdx = 0;
// fill with maximum values // fill with maximum values
@ -266,14 +266,14 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType,
return; return;
} }
if (boardConfiguration->mapMinBufferLength != mapMinBufferLength) { if (CONFIGB(mapMinBufferLength) != mapMinBufferLength) {
applyMapMinBufferLength(); applyMapMinBufferLength();
} }
measurementsPerRevolution = measurementsPerRevolutionCounter; measurementsPerRevolution = measurementsPerRevolutionCounter;
measurementsPerRevolutionCounter = 0; measurementsPerRevolutionCounter = 0;
int samplingCount = boardConfiguration->measureMapOnlyInOneCylinder ? 1 : engineConfiguration->specs.cylindersCount; int samplingCount = CONFIGB(measureMapOnlyInOneCylinder) ? 1 : engineConfiguration->specs.cylindersCount;
for (int i = 0; i < samplingCount; i++) { for (int i = 0; i < samplingCount; i++) {
angle_t samplingStart = ENGINE(engineState.mapAveragingStart[i]); angle_t samplingStart = ENGINE(engineState.mapAveragingStart[i]);

View File

@ -46,7 +46,7 @@ static float lastAfr = stoichAfr;
void initEgoAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void initEgoAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// Our averaging is intended for use only with Narrow EGOs. // Our averaging is intended for use only with Narrow EGOs.
if (boardConfiguration->afr_type == ES_NarrowBand) { if (CONFIGB(afr_type) == ES_NarrowBand) {
totalEgoCnt = prevEgoCnt = 0; totalEgoCnt = prevEgoCnt = 0;
egoAfrBuf.clear(); egoAfrBuf.clear();
useAveraging = true; useAveraging = true;
@ -93,7 +93,7 @@ void initEgoAveraging(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_CJ125 || defined(__DOXYGEN__) #if EFI_CJ125 || defined(__DOXYGEN__)
if (boardConfiguration->isCJ125Enabled) { if (CONFIGB(isCJ125Enabled)) {
return cjHasAfrSensor(PASS_ENGINE_PARAMETER_SIGNATURE); return cjHasAfrSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
#endif /* EFI_CJ125 */ #endif /* EFI_CJ125 */
@ -102,7 +102,7 @@ bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) { float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_CJ125 || defined(__DOXYGEN__) #if EFI_CJ125 || defined(__DOXYGEN__)
if (boardConfiguration->isCJ125Enabled) { if (CONFIGB(isCJ125Enabled)) {
return cjGetAfr(PASS_ENGINE_PARAMETER_SIGNATURE); return cjGetAfr(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
#endif /* EFI_CJ125 */ #endif /* EFI_CJ125 */
@ -110,7 +110,7 @@ float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
float volts = getVoltageDivided("ego", sensor->hwChannel); float volts = getVoltageDivided("ego", sensor->hwChannel);
if (boardConfiguration->afr_type == ES_NarrowBand) { if (CONFIGB(afr_type) == ES_NarrowBand) {
float afr = interpolate2d("narrow", volts, engineConfiguration->narrowToWideOxygenBins, engineConfiguration->narrowToWideOxygen, NARROW_BAND_WIDE_BAND_CONVERSION_SIZE); float afr = interpolate2d("narrow", volts, engineConfiguration->narrowToWideOxygenBins, engineConfiguration->narrowToWideOxygen, NARROW_BAND_WIDE_BAND_CONVERSION_SIZE);
#ifdef EFI_NARROW_EGO_AVERAGING #ifdef EFI_NARROW_EGO_AVERAGING
if (useAveraging) if (useAveraging)
@ -170,6 +170,6 @@ static void initEgoSensor(afr_sensor_s *sensor, ego_sensor_e type) {
} }
void setEgoSensor(ego_sensor_e type DECLARE_ENGINE_PARAMETER_SUFFIX) { void setEgoSensor(ego_sensor_e type DECLARE_ENGINE_PARAMETER_SUFFIX) {
boardConfiguration->afr_type = type; CONFIGB(afr_type) = type;
initEgoSensor(&engineConfiguration->afr, type); initEgoSensor(&engineConfiguration->afr, type);
} }

View File

@ -145,7 +145,7 @@ float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX) {
*/ */
float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) { float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->hasFrequencyReportingMapSensor) { if (engineConfiguration->hasFrequencyReportingMapSensor) {
return interpolateMsg("rmap", boardConfiguration->mapFrequency0Kpa, 0, boardConfiguration->mapFrequency100Kpa, 100, mapFreq); return interpolateMsg("rmap", CONFIGB(mapFrequency0Kpa), 0, CONFIGB(mapFrequency100Kpa), 100, mapFreq);
} }
float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel); float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel);
@ -222,7 +222,7 @@ static void printMAPInfo(void) {
if (engineConfiguration->hasFrequencyReportingMapSensor) { if (engineConfiguration->hasFrequencyReportingMapSensor) {
scheduleMsg(logger, "instant value=%.2fHz @ %s", mapFreq, hwPortname(boardConfiguration->frequencyReportingMapInputPin)); scheduleMsg(logger, "instant value=%.2fHz @ %s", mapFreq, hwPortname(CONFIGB(frequencyReportingMapInputPin)));
} else { } else {
scheduleMsg(logger, "map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type, scheduleMsg(logger, "map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type,
getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type), getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type),
@ -265,7 +265,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
if (engineConfiguration->hasFrequencyReportingMapSensor) { if (engineConfiguration->hasFrequencyReportingMapSensor) {
digital_input_s* digitalMapInput = addWaveAnalyzerDriver("map freq", boardConfiguration->frequencyReportingMapInputPin); digital_input_s* digitalMapInput = addWaveAnalyzerDriver("map freq", CONFIGB(frequencyReportingMapInputPin));
startInputDriver(digitalMapInput, true); startInputDriver(digitalMapInput, true);
digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL); digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL);

View File

@ -166,9 +166,9 @@ void EnginePins::startIgnitionPins(void) {
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
NamedOutputPin *output = &enginePins.coils[i]; NamedOutputPin *output = &enginePins.coils[i];
// todo: we need to check if mode has changed // todo: we need to check if mode has changed
if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) { if (CONFIGB(ignitionPins)[i] != activeConfiguration.bc.ignitionPins[i]) {
output->initPin(output->name, boardConfiguration->ignitionPins[i], output->initPin(output->name, CONFIGB(ignitionPins)[i],
&boardConfiguration->ignitionPinMode); &CONFIGB(ignitionPinMode));
} }
} }
// todo: we need to check if mode has changed // todo: we need to check if mode has changed
@ -188,8 +188,8 @@ void EnginePins::startInjectionPins(void) {
// todo: we need to check if mode has changed // todo: we need to check if mode has changed
if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) { if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) {
output->initPin(output->name, boardConfiguration->injectionPins[i], output->initPin(output->name, CONFIGB(injectionPins)[i],
&boardConfiguration->injectionPinMode); &CONFIGB(injectionPinMode));
} }
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
@ -322,17 +322,17 @@ void initOutputPins(void) {
// memset(&outputs, 0, sizeof(outputs)); // memset(&outputs, 0, sizeof(outputs));
#if HAL_USE_SPI || defined(__DOXYGEN__) #if HAL_USE_SPI || defined(__DOXYGEN__)
enginePins.sdCsPin.initPin("spi CS5", boardConfiguration->sdCardCsPin); enginePins.sdCsPin.initPin("spi CS5", CONFIGB(sdCardCsPin));
#endif /* HAL_USE_SPI */ #endif /* HAL_USE_SPI */
// todo: should we move this code closer to the fuel pump logic? // todo: should we move this code closer to the fuel pump logic?
enginePins.fuelPumpRelay.initPin("fuel pump relay", boardConfiguration->fuelPumpPin, &boardConfiguration->fuelPumpPinMode); enginePins.fuelPumpRelay.initPin("fuel pump relay", CONFIGB(fuelPumpPin), &CONFIGB(fuelPumpPinMode));
enginePins.mainRelay.initPin("main relay", boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode); enginePins.mainRelay.initPin("main relay", CONFIGB(mainRelayPin), &CONFIGB(mainRelayPinMode));
enginePins.fanRelay.initPin("fan relay", boardConfiguration->fanPin, &boardConfiguration->fanPinMode); enginePins.fanRelay.initPin("fan relay", CONFIGB(fanPin), &CONFIGB(fanPinMode));
enginePins.o2heater.initPin("o2 heater", boardConfiguration->o2heaterPin); enginePins.o2heater.initPin("o2 heater", CONFIGB(o2heaterPin));
enginePins.acRelay.initPin("A/C relay", boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode); enginePins.acRelay.initPin("A/C relay", CONFIGB(acRelayPin), &CONFIGB(acRelayPinMode));
// digit 1 // digit 1
/* /*

View File

@ -38,11 +38,11 @@ static void tachSignalCallback(trigger_event_e ckpSignalType,
} }
void initTachometer(void) { void initTachometer(void) {
if (boardConfiguration->tachOutputPin == GPIO_UNASSIGNED) { if (CONFIGB(tachOutputPin) == GPIO_UNASSIGNED) {
return; return;
} }
enginePins.tachOut.initPin("analog tach output", boardConfiguration->tachOutputPin, &boardConfiguration->tachOutputPinMode); enginePins.tachOut.initPin("analog tach output", CONFIGB(tachOutputPin), &CONFIGB(tachOutputPinMode));
addTriggerEventListener(tachSignalCallback, "tach", engine); addTriggerEventListener(tachSignalCallback, "tach", engine);
} }

View File

@ -353,7 +353,7 @@ static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (GET_RPM() < CONFIG(fuelClosedLoopRpmThreshold) || if (GET_RPM() < CONFIG(fuelClosedLoopRpmThreshold) ||
ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) || ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) ||
getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) || getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) ||
ENGINE(sensors.currentAfr) < boardConfiguration->fuelClosedLoopAfrLowThreshold || ENGINE(sensors.currentAfr) < CONFIGB(fuelClosedLoopAfrLowThreshold) ||
ENGINE(sensors.currentAfr) > engineConfiguration->fuelClosedLoopAfrHighThreshold) { ENGINE(sensors.currentAfr) > engineConfiguration->fuelClosedLoopAfrHighThreshold) {
engine->engineState.fuelPidCorrection = 0; engine->engineState.fuelPidCorrection = 0;
fuelPid.reset(); fuelPid.reset();

View File

@ -202,7 +202,7 @@ void RpmCalculator::setStopSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (!boardConfiguration->isFasterEngineSpinUpEnabled) if (!CONFIGB(isFasterEngineSpinUpEnabled))
return; return;
// Only a completely stopped and non-spinning engine can enter the spinning-up state. // Only a completely stopped and non-spinning engine can enter the spinning-up state.
if (isStopped(PASS_ENGINE_PARAMETER_SIGNATURE) && !isSpinning) { if (isStopped(PASS_ENGINE_PARAMETER_SIGNATURE) && !isSpinning) {

View File

@ -100,7 +100,7 @@ void initEngineEmulator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_POTENTIOMETER #if EFI_POTENTIOMETER
#if HAL_USE_SPI || defined(__DOXYGEN__) #if HAL_USE_SPI || defined(__DOXYGEN__)
initPotentiometers(sharedLogger, &engineConfiguration->bc); initPotentiometers(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* HAL_USE_SPI */ #endif /* HAL_USE_SPI */
#endif /* EFI_POTENTIOMETER */ #endif /* EFI_POTENTIOMETER */

View File

@ -16,6 +16,8 @@
#if HAL_USE_SPI || defined(__DOXYGEN__) #if HAL_USE_SPI || defined(__DOXYGEN__)
EXTERN_ENGINE;
/** /**
* MCP42010 digital potentiometer driver * MCP42010 digital potentiometer driver
* *
@ -90,22 +92,22 @@ static void setPotValue1(int value) {
#endif /* EFI_POTENTIOMETER */ #endif /* EFI_POTENTIOMETER */
void initPotentiometers(Logging *sharedLogger, board_configuration_s *boardConfiguration) { void initPotentiometers(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
logger = sharedLogger; logger = sharedLogger;
#if EFI_POTENTIOMETER #if EFI_POTENTIOMETER
if (boardConfiguration->digitalPotentiometerSpiDevice == SPI_NONE) { if (CONFIGB(digitalPotentiometerSpiDevice) == SPI_NONE) {
scheduleMsg(logger, "digiPot spi disabled"); scheduleMsg(logger, "digiPot spi disabled");
return; return;
} }
turnOnSpi(boardConfiguration->digitalPotentiometerSpiDevice); turnOnSpi(CONFIGB(digitalPotentiometerSpiDevice));
for (int i = 0; i < DIGIPOT_COUNT; i++) { for (int i = 0; i < DIGIPOT_COUNT; i++) {
brain_pin_e csPin = boardConfiguration->digitalPotentiometerChipSelect[i]; brain_pin_e csPin = CONFIGB(digitalPotentiometerChipSelect)[i];
if (csPin == GPIO_UNASSIGNED) { if (csPin == GPIO_UNASSIGNED) {
continue; continue;
} }
initPotentiometer(&potConfig[i], getSpiDevice(boardConfiguration->digitalPotentiometerSpiDevice), initPotentiometer(&potConfig[i], getSpiDevice(CONFIGB(digitalPotentiometerSpiDevice)),
csPin); csPin);
} }

View File

@ -21,7 +21,7 @@ typedef struct {
} Mcp42010Driver; } Mcp42010Driver;
//void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, ioportid_t port, ioportmask_t pin); //void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, ioportid_t port, ioportmask_t pin);
void initPotentiometers(Logging *sharedLogger, board_configuration_s *boardConfiguration); void initPotentiometers(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void setPotResistance(Mcp42010Driver *driver, int channel, int resistance); void setPotResistance(Mcp42010Driver *driver, int channel, int resistance);
#endif #endif

View File

@ -43,12 +43,12 @@ static const SPIConfig accelerometerCfg = {
void configureAccelerometerPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void configureAccelerometerPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// engineConfiguration->LIS302DLCsPin = GPIOE_3; // we have a conflict with VVT output on Miata // engineConfiguration->LIS302DLCsPin = GPIOE_3; // we have a conflict with VVT output on Miata
// boardConfiguration->is_enabled_spi_1 = true; // we have a conflict with PA5 input pin // CONFIGB(is_enabled_spi_1) = true; // we have a conflict with PA5 input pin
// stm32f4discovery defaults // stm32f4discovery defaults
boardConfiguration->spi1mosiPin = GPIOA_7; CONFIGB(spi1mosiPin) = GPIOA_7;
boardConfiguration->spi1misoPin = GPIOA_6; CONFIGB(spi1misoPin) = GPIOA_6;
boardConfiguration->spi1sckPin = GPIOA_5; CONFIGB(spi1sckPin) = GPIOA_5;
} }
@ -76,7 +76,7 @@ void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED) if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
return; // not used return; // not used
if (!boardConfiguration->is_enabled_spi_1) if (!CONFIGB(is_enabled_spi_1))
return; // temporary return; // temporary
#if HAL_USE_SPI || defined(__DOXYGEN__) #if HAL_USE_SPI || defined(__DOXYGEN__)
driver = getSpiDevice(engineConfiguration->accelerometerSpiDevice); driver = getSpiDevice(engineConfiguration->accelerometerSpiDevice);
@ -86,8 +86,8 @@ void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
initSpiCs((SPIConfig *)driver->config, engineConfiguration->LIS302DLCsPin); initSpiCs((SPIConfig *)driver->config, engineConfiguration->LIS302DLCsPin);
// memsCs.initPin("LIS302 CS", engineConfiguration->LIS302DLCsPin); // memsCs.initPin("LIS302 CS", engineConfiguration->LIS302DLCsPin);
// memsCfg.ssport = getHwPort("mmc", boardConfiguration->sdCardCsPin); // memsCfg.ssport = getHwPort("mmc", CONFIGB(sdCardCsPin));
// memsCfg.sspad = getHwPin("mmc", boardConfiguration->sdCardCsPin); // memsCfg.sspad = getHwPin("mmc", CONFIGB(sdCardCsPin));
/* LIS302DL initialization.*/ /* LIS302DL initialization.*/

View File

@ -630,7 +630,7 @@ static void configureInputs(void) {
addChannel("OilP", engineConfiguration->oilPressure.hwChannel, ADC_SLOW); addChannel("OilP", engineConfiguration->oilPressure.hwChannel, ADC_SLOW);
addChannel("AC", engineConfiguration->acSwitchAdc, ADC_SLOW); addChannel("AC", engineConfiguration->acSwitchAdc, ADC_SLOW);
if (boardConfiguration->isCJ125Enabled) { if (CONFIGB(isCJ125Enabled)) {
addChannel("cj125ur", engineConfiguration->cj125ur, ADC_SLOW); addChannel("cj125ur", engineConfiguration->cj125ur, ADC_SLOW);
addChannel("cj125ua", engineConfiguration->cj125ua, ADC_SLOW); addChannel("cj125ua", engineConfiguration->cj125ua, ADC_SLOW);
} }
@ -682,7 +682,7 @@ void initAdcInputs(bool boardTestMode) {
pwmEnablePeriodicNotification(EFI_INTERNAL_SLOW_ADC_PWM); pwmEnablePeriodicNotification(EFI_INTERNAL_SLOW_ADC_PWM);
#endif /* HAL_USE_PWM */ #endif /* HAL_USE_PWM */
if (boardConfiguration->isFastAdcEnabled) { if (CONFIGB(isFastAdcEnabled)) {
fastAdc.init(); fastAdc.init();
/* /*
* Initializes the PWM driver. * Initializes the PWM driver.

View File

@ -105,8 +105,8 @@ void commonTxInit(int eid) {
* send CAN message from txmsg buffer * send CAN message from txmsg buffer
*/ */
static void sendCanMessage2(int size) { static void sendCanMessage2(int size) {
CANDriver *device = detectCanDevice(boardConfiguration->canRxPin, CANDriver *device = detectCanDevice(CONFIGB(canRxPin),
boardConfiguration->canTxPin); CONFIGB(canTxPin));
if (device == NULL) { if (device == NULL) {
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue"); warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
return; return;
@ -227,8 +227,8 @@ static void canInfoNBCBroadcast(can_nbc_e typeOfNBC) {
} }
static void canRead(void) { static void canRead(void) {
CANDriver *device = detectCanDevice(boardConfiguration->canRxPin, CANDriver *device = detectCanDevice(CONFIGB(canRxPin),
boardConfiguration->canTxPin); CONFIGB(canTxPin));
if (device == NULL) { if (device == NULL) {
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue"); warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
return; return;
@ -276,8 +276,8 @@ static void canInfo(void) {
return; return;
} }
scheduleMsg(&logger, "CAN TX %s", hwPortname(boardConfiguration->canTxPin)); scheduleMsg(&logger, "CAN TX %s", hwPortname(CONFIGB(canTxPin)));
scheduleMsg(&logger, "CAN RX %s", hwPortname(boardConfiguration->canRxPin)); scheduleMsg(&logger, "CAN RX %s", hwPortname(CONFIGB(canRxPin)));
scheduleMsg(&logger, "type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType, scheduleMsg(&logger, "type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType,
boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled), boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled),
engineConfiguration->canSleepPeriod); engineConfiguration->canSleepPeriod);
@ -297,8 +297,8 @@ void postCanState(TunerStudioOutputChannels *tsOutputChannels) {
} }
void enableFrankensoCan(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void enableFrankensoCan(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
boardConfiguration->canTxPin = GPIOB_6; CONFIGB(canTxPin) = GPIOB_6;
boardConfiguration->canRxPin = GPIOB_12; CONFIGB(canRxPin) = GPIOB_12;
engineConfiguration->canReadEnabled = false; engineConfiguration->canReadEnabled = false;
} }
@ -308,17 +308,17 @@ void stopCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
void startCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void startCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiSetPadMode("CAN TX", boardConfiguration->canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF)); efiSetPadMode("CAN TX", CONFIGB(canTxPin), PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
efiSetPadMode("CAN RX", boardConfiguration->canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF)); efiSetPadMode("CAN RX", CONFIGB(canRxPin), PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
} }
void initCan(void) { void initCan(void) {
isCanEnabled = (boardConfiguration->canTxPin != GPIO_UNASSIGNED) && (boardConfiguration->canRxPin != GPIO_UNASSIGNED); isCanEnabled = (CONFIGB(canTxPin) != GPIO_UNASSIGNED) && (CONFIGB(canRxPin) != GPIO_UNASSIGNED);
if (isCanEnabled) { if (isCanEnabled) {
if (!isValidCanTxPin(boardConfiguration->canTxPin)) if (!isValidCanTxPin(CONFIGB(canTxPin)))
firmwareError(CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(boardConfiguration->canTxPin)); firmwareError(CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(CONFIGB(canTxPin)));
if (!isValidCanRxPin(boardConfiguration->canRxPin)) if (!isValidCanRxPin(CONFIGB(canRxPin)))
firmwareError(CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(boardConfiguration->canRxPin)); firmwareError(CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(CONFIGB(canRxPin)));
} }
addConsoleAction("caninfo", canInfo); addConsoleAction("caninfo", canInfo);

View File

@ -56,17 +56,17 @@ static void extIonCallback(EXTDriver *extp, expchannel_t channel) {
void cdmIonInit(void) { void cdmIonInit(void) {
// todo: allow 'GPIOA_0' once we migrate to new mandatory configuration // todo: allow 'GPIOA_0' once we migrate to new mandatory configuration
if (boardConfiguration->cdmInputPin == GPIOA_0 || boardConfiguration->cdmInputPin == GPIO_UNASSIGNED) { if (CONFIGB(cdmInputPin) == GPIOA_0 || CONFIGB(cdmInputPin) == GPIO_UNASSIGNED) {
return; return;
} }
int pin = (int)boardConfiguration->cdmInputPin; int pin = (int)CONFIGB(cdmInputPin);
if (pin <= 0 || pin > (int)GPIO_UNASSIGNED) { if (pin <= 0 || pin > (int)GPIO_UNASSIGNED) {
// todo: remove this protection once we migrate to new mandatory configuration // todo: remove this protection once we migrate to new mandatory configuration
return; return;
} }
enableExti(boardConfiguration->cdmInputPin, EXT_CH_MODE_RISING_EDGE, extIonCallback); enableExti(CONFIGB(cdmInputPin), EXT_CH_MODE_RISING_EDGE, extIonCallback);
} }

View File

@ -97,13 +97,13 @@ void unlockSpi(void) {
} }
static void initSpiModules(board_configuration_s *boardConfiguration) { static void initSpiModules(board_configuration_s *boardConfiguration) {
if (boardConfiguration->is_enabled_spi_1) { if (CONFIGB(is_enabled_spi_1)) {
turnOnSpi(SPI_DEVICE_1); turnOnSpi(SPI_DEVICE_1);
} }
if (boardConfiguration->is_enabled_spi_2) { if (CONFIGB(is_enabled_spi_2)) {
turnOnSpi(SPI_DEVICE_2); turnOnSpi(SPI_DEVICE_2);
} }
if (boardConfiguration->is_enabled_spi_3) { if (CONFIGB(is_enabled_spi_3)) {
turnOnSpi(SPI_DEVICE_3); turnOnSpi(SPI_DEVICE_3);
} }
} }
@ -196,7 +196,7 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
mapAveragingAdcCallback(fastAdc.samples[fastMapSampleIndex]); mapAveragingAdcCallback(fastAdc.samples[fastMapSampleIndex]);
#endif /* EFI_MAP_AVERAGING */ #endif /* EFI_MAP_AVERAGING */
#if EFI_HIP_9011 || defined(__DOXYGEN__) #if EFI_HIP_9011 || defined(__DOXYGEN__)
if (boardConfiguration->isHip9011Enabled) { if (CONFIGB(isHip9011Enabled)) {
hipAdcCallback(fastAdc.samples[hipSampleIndex]); hipAdcCallback(fastAdc.samples[hipSampleIndex]);
} }
#endif #endif
@ -390,13 +390,13 @@ void initHardware(Logging *l) {
#endif #endif
bool isBoardTestMode_b; bool isBoardTestMode_b;
if (boardConfiguration->boardTestModeJumperPin != GPIO_UNASSIGNED) { if (CONFIGB(boardTestModeJumperPin) != GPIO_UNASSIGNED) {
efiSetPadMode("board test", boardConfiguration->boardTestModeJumperPin, efiSetPadMode("board test", CONFIGB(boardTestModeJumperPin),
PAL_MODE_INPUT_PULLUP); PAL_MODE_INPUT_PULLUP);
isBoardTestMode_b = (!efiReadPin(boardConfiguration->boardTestModeJumperPin)); isBoardTestMode_b = (!efiReadPin(CONFIGB(boardTestModeJumperPin)));
// we can now relese this pin, it is actually used as output sometimes // we can now relese this pin, it is actually used as output sometimes
unmarkPin(boardConfiguration->boardTestModeJumperPin); unmarkPin(CONFIGB(boardTestModeJumperPin));
} else { } else {
isBoardTestMode_b = false; isBoardTestMode_b = false;
} }
@ -415,7 +415,7 @@ void initHardware(Logging *l) {
initOutputPins(); initOutputPins();
#if EFI_MAX_31855 #if EFI_MAX_31855
initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), boardConfiguration->max31855_cs); initMax31855(sharedLogger, getSpiDevice(CONFIGB(max31855spiDevice)), CONFIGB(max31855_cs));
#endif /* EFI_MAX_31855 */ #endif /* EFI_MAX_31855 */
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT

View File

@ -54,21 +54,21 @@ static void extCallback(EXTDriver *extp, expchannel_t channel) {
joyTotal++; joyTotal++;
joystick_button_e button; joystick_button_e button;
// todo: I guess it's time to reduce code duplication and start working with an array // todo: I guess it's time to reduce code duplication and start working with an array
if (channel == getHwPin("joy", boardConfiguration->joystickCenterPin)) { if (channel == getHwPin("joy", CONFIGB(joystickCenterPin))) {
joyCenter++; joyCenter++;
button = JB_CENTER; button = JB_CENTER;
} else if (channel == getHwPin("joy", boardConfiguration->joystickAPin)) { } else if (channel == getHwPin("joy", CONFIGB(joystickAPin))) {
joyA++; joyA++;
button = JB_BUTTON_A; button = JB_BUTTON_A;
/* not used so far /* not used so far
} else if (channel == getHwPin("joy", boardConfiguration->joystickBPin)) { } else if (channel == getHwPin("joy", CONFIGB(joystickBPin))) {
joyB++; joyB++;
button = JB_BUTTON_B; button = JB_BUTTON_B;
} else if (channel == getHwPin("joy", boardConfiguration->joystickCPin)) { } else if (channel == getHwPin("joy", CONFIGB(joystickCPin))) {
joyC++; joyC++;
button = JB_BUTTON_C; button = JB_BUTTON_C;
*/ */
} else if (channel == getHwPin("joy", boardConfiguration->joystickDPin)) { } else if (channel == getHwPin("joy", CONFIGB(joystickDPin))) {
joyD++; joyD++;
button = JB_BUTTON_D; button = JB_BUTTON_D;
} else { } else {
@ -84,19 +84,19 @@ static void extCallback(EXTDriver *extp, expchannel_t channel) {
static void joystickInfo(void) { static void joystickInfo(void) {
scheduleMsg(sharedLogger, "total %d center=%d@%s", joyTotal, joyCenter, scheduleMsg(sharedLogger, "total %d center=%d@%s", joyTotal, joyCenter,
hwPortname(boardConfiguration->joystickCenterPin)); hwPortname(CONFIGB(joystickCenterPin)));
scheduleMsg(sharedLogger, "a=%d@%s", joyA, hwPortname(boardConfiguration->joystickAPin)); scheduleMsg(sharedLogger, "a=%d@%s", joyA, hwPortname(CONFIGB(joystickAPin)));
scheduleMsg(sharedLogger, "b=%d@%s", joyB, hwPortname(boardConfiguration->joystickBPin)); scheduleMsg(sharedLogger, "b=%d@%s", joyB, hwPortname(CONFIGB(joystickBPin)));
scheduleMsg(sharedLogger, "c=%d@%s", joyC, hwPortname(boardConfiguration->joystickCPin)); scheduleMsg(sharedLogger, "c=%d@%s", joyC, hwPortname(CONFIGB(joystickCPin)));
scheduleMsg(sharedLogger, "d=%d@%s", joyD, hwPortname(boardConfiguration->joystickDPin)); scheduleMsg(sharedLogger, "d=%d@%s", joyD, hwPortname(CONFIGB(joystickDPin)));
} }
static bool isJoystickEnabled() { static bool isJoystickEnabled() {
return boardConfiguration->joystickCenterPin != GPIO_UNASSIGNED || return CONFIGB(joystickCenterPin) != GPIO_UNASSIGNED ||
boardConfiguration->joystickAPin != GPIO_UNASSIGNED || CONFIGB(joystickAPin) != GPIO_UNASSIGNED ||
// not used so far boardConfiguration->joystickBPin != GPIO_UNASSIGNED || // not used so far CONFIGB(joystickBPin) != GPIO_UNASSIGNED ||
// not used so far boardConfiguration->joystickCPin != GPIO_UNASSIGNED || // not used so far CONFIGB(joystickCPin) != GPIO_UNASSIGNED ||
boardConfiguration->joystickDPin != GPIO_UNASSIGNED; CONFIGB(joystickDPin) != GPIO_UNASSIGNED;
} }
void initJoystick(Logging *shared) { void initJoystick(Logging *shared) {
@ -104,17 +104,17 @@ void initJoystick(Logging *shared) {
return; return;
sharedLogger = shared; sharedLogger = shared;
enableExti(boardConfiguration->joystickCenterPin, EXT_CH_MODE_RISING_EDGE, extCallback); enableExti(CONFIGB(joystickCenterPin), EXT_CH_MODE_RISING_EDGE, extCallback);
enableExti(boardConfiguration->joystickAPin, EXT_CH_MODE_RISING_EDGE, extCallback); enableExti(CONFIGB(joystickAPin), EXT_CH_MODE_RISING_EDGE, extCallback);
// not used so far applyPin(boardConfiguration->joystickBPin); // not used so far applyPin(CONFIGB(joystickBPin));
// not used so far applyPin(boardConfiguration->joystickCPin); // not used so far applyPin(CONFIGB(joystickCPin));
enableExti(boardConfiguration->joystickDPin, EXT_CH_MODE_RISING_EDGE, extCallback); enableExti(CONFIGB(joystickDPin), EXT_CH_MODE_RISING_EDGE, extCallback);
efiSetPadMode("joy center", boardConfiguration->joystickCenterPin, PAL_MODE_INPUT_PULLUP); efiSetPadMode("joy center", CONFIGB(joystickCenterPin), PAL_MODE_INPUT_PULLUP);
efiSetPadMode("joy A", boardConfiguration->joystickAPin, PAL_MODE_INPUT_PULLUP); efiSetPadMode("joy A", CONFIGB(joystickAPin), PAL_MODE_INPUT_PULLUP);
// not used so far efiSetPadMode("joy B", boardConfiguration->joystickBPin, PAL_MODE_INPUT_PULLUP); // not used so far efiSetPadMode("joy B", CONFIGB(joystickBPin), PAL_MODE_INPUT_PULLUP);
// not used so far efiSetPadMode("joy C", boardConfiguration->joystickCPin, PAL_MODE_INPUT_PULLUP); // not used so far efiSetPadMode("joy C", CONFIGB(joystickCPin), PAL_MODE_INPUT_PULLUP);
efiSetPadMode("joy D", boardConfiguration->joystickDPin, PAL_MODE_INPUT_PULLUP); efiSetPadMode("joy D", CONFIGB(joystickDPin), PAL_MODE_INPUT_PULLUP);
addConsoleAction("joystickinfo", joystickInfo); addConsoleAction("joystickinfo", joystickInfo);

View File

@ -15,10 +15,9 @@
#include "pin_repository.h" #include "pin_repository.h"
#include "string.h" #include "string.h"
#include "engine_configuration.h" #include "engine.h"
extern engine_configuration_s *engineConfiguration; EXTERN_ENGINE;
extern board_configuration_s *boardConfiguration;
static Logging *logger; static Logging *logger;
@ -84,18 +83,18 @@ static void writePad(const char *msg, brain_pin_e pin, int bit) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void lcd_HD44780_write(uint8_t data) { static void lcd_HD44780_write(uint8_t data) {
if (engineConfiguration->displayMode == DM_HD44780) { if (engineConfiguration->displayMode == DM_HD44780) {
writePad("lcd", boardConfiguration->HD44780_db7, writePad("lcd", CONFIGB(HD44780_db7),
data & 0x80 ? 1 : 0); data & 0x80 ? 1 : 0);
writePad("lcd", boardConfiguration->HD44780_db6, writePad("lcd", CONFIGB(HD44780_db6),
data & 0x40 ? 1 : 0); data & 0x40 ? 1 : 0);
writePad("lcd", boardConfiguration->HD44780_db5, writePad("lcd", CONFIGB(HD44780_db5),
data & 0x20 ? 1 : 0); data & 0x20 ? 1 : 0);
writePad("lcd", boardConfiguration->HD44780_db4, writePad("lcd", CONFIGB(HD44780_db4),
data & 0x10 ? 1 : 0); data & 0x10 ? 1 : 0);
writePad("lcd", boardConfiguration->HD44780_e, 1); // En high writePad("lcd", CONFIGB(HD44780_e), 1); // En high
lcdSleep(10); // enable pulse must be >450ns lcdSleep(10); // enable pulse must be >450ns
writePad("lcd", boardConfiguration->HD44780_e, 0); // En low writePad("lcd", CONFIGB(HD44780_e), 0); // En low
lcdSleep(40); // commands need > 37us to settle lcdSleep(40); // commands need > 37us to settle
} else { } else {
@ -124,7 +123,7 @@ static void lcd_HD44780_write(uint8_t data) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void lcd_HD44780_write_command(uint8_t data) { void lcd_HD44780_write_command(uint8_t data) {
palClearPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs)); palClearPad(getHwPort("lcd", CONFIGB(HD44780_rs)), getHwPin("lcd", CONFIGB(HD44780_rs)));
lcd_HD44780_write(data); lcd_HD44780_write(data);
lcd_HD44780_write(data << 4); lcd_HD44780_write(data << 4);
@ -132,13 +131,13 @@ void lcd_HD44780_write_command(uint8_t data) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void lcd_HD44780_write_data(uint8_t data) { void lcd_HD44780_write_data(uint8_t data) {
palSetPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs)); palSetPad(getHwPort("lcd", CONFIGB(HD44780_rs)), getHwPin("lcd", CONFIGB(HD44780_rs)));
lcd_HD44780_write(data); lcd_HD44780_write(data);
lcd_HD44780_write(data << 4); lcd_HD44780_write(data << 4);
currentColumn++; currentColumn++;
palClearPad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs)); palClearPad(getHwPort("lcd", CONFIGB(HD44780_rs)), getHwPin("lcd", CONFIGB(HD44780_rs)));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -169,14 +168,15 @@ void lcd_HD44780_print_string(const char* string) {
while (*string != 0x00) while (*string != 0x00)
lcd_HD44780_print_char(*string++); lcd_HD44780_print_char(*string++);
} }
//getHwPin(boardConfiguration->HD44780_db7)
static void lcdInfo(void) { //getHwPin(CONFIGB(HD44780_db7))
scheduleMsg(logger, "HD44780 RS=%s", hwPortname(boardConfiguration->HD44780_rs)); static void lcdInfo(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
scheduleMsg(logger, "HD44780 E=%s", hwPortname(boardConfiguration->HD44780_e)); scheduleMsg(logger, "HD44780 RS=%s", hwPortname(CONFIGB(HD44780_rs)));
scheduleMsg(logger, "HD44780 D4=%s", hwPortname(boardConfiguration->HD44780_db4)); scheduleMsg(logger, "HD44780 E=%s", hwPortname(CONFIGB(HD44780_e)));
scheduleMsg(logger, "HD44780 D5=%s", hwPortname(boardConfiguration->HD44780_db5)); scheduleMsg(logger, "HD44780 D4=%s", hwPortname(CONFIGB(HD44780_db4)));
scheduleMsg(logger, "HD44780 D6=%s", hwPortname(boardConfiguration->HD44780_db6)); scheduleMsg(logger, "HD44780 D5=%s", hwPortname(CONFIGB(HD44780_db5)));
scheduleMsg(logger, "HD44780 D7=%s", hwPortname(boardConfiguration->HD44780_db7)); scheduleMsg(logger, "HD44780 D6=%s", hwPortname(CONFIGB(HD44780_db6)));
scheduleMsg(logger, "HD44780 D7=%s", hwPortname(CONFIGB(HD44780_db7)));
} }
void lcd_HD44780_init(Logging *sharedLogger) { void lcd_HD44780_init(Logging *sharedLogger) {
@ -194,19 +194,19 @@ void lcd_HD44780_init(Logging *sharedLogger) {
if (engineConfiguration->displayMode == DM_HD44780) { if (engineConfiguration->displayMode == DM_HD44780) {
// initialize hardware lines // initialize hardware lines
efiSetPadMode("lcd RS", boardConfiguration->HD44780_rs, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd RS", CONFIGB(HD44780_rs), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("lcd E", boardConfiguration->HD44780_e, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd E", CONFIGB(HD44780_e), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("lcd DB4", boardConfiguration->HD44780_db4, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd DB4", CONFIGB(HD44780_db4), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("lcd DB5", boardConfiguration->HD44780_db5, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd DB5", CONFIGB(HD44780_db5), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("lcd DB6", boardConfiguration->HD44780_db6, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd DB6", CONFIGB(HD44780_db6), PAL_MODE_OUTPUT_PUSHPULL);
efiSetPadMode("lcd DB7", boardConfiguration->HD44780_db7, PAL_MODE_OUTPUT_PUSHPULL); efiSetPadMode("lcd DB7", CONFIGB(HD44780_db7), PAL_MODE_OUTPUT_PUSHPULL);
// and zero values // and zero values
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_rs), getHwPin("lcd", boardConfiguration->HD44780_rs), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_rs)), getHwPin("lcd", CONFIGB(HD44780_rs)), 0);
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_e), getHwPin("lcd", boardConfiguration->HD44780_e), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_e)), getHwPin("lcd", CONFIGB(HD44780_e)), 0);
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db4), getHwPin("lcd", boardConfiguration->HD44780_db4), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_db4)), getHwPin("lcd", CONFIGB(HD44780_db4)), 0);
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db5), getHwPin("lcd", boardConfiguration->HD44780_db5), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_db5)), getHwPin("lcd", CONFIGB(HD44780_db5)), 0);
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db6), getHwPin("lcd", boardConfiguration->HD44780_db6), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_db6)), getHwPin("lcd", CONFIGB(HD44780_db6)), 0);
palWritePad(getHwPort("lcd", boardConfiguration->HD44780_db7), getHwPin("lcd", boardConfiguration->HD44780_db7), 0); palWritePad(getHwPort("lcd", CONFIGB(HD44780_db7)), getHwPin("lcd", CONFIGB(HD44780_db7)), 0);
} }
chThdSleepMilliseconds(20); // LCD needs some time to wake up chThdSleepMilliseconds(20); // LCD needs some time to wake up

View File

@ -39,11 +39,11 @@ static void showEgtInfo(void) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
printSpiState(logger, boardConfiguration); printSpiState(logger, boardConfiguration);
scheduleMsg(logger, "EGT spi: %d", boardConfiguration->max31855spiDevice); scheduleMsg(logger, "EGT spi: %d", CONFIGB(max31855spiDevice));
for (int i = 0; i < EGT_CHANNEL_COUNT; i++) { for (int i = 0; i < EGT_CHANNEL_COUNT; i++) {
if (boardConfiguration->max31855_cs[i] != GPIO_UNASSIGNED) { if (CONFIGB(max31855_cs)[i] != GPIO_UNASSIGNED) {
scheduleMsg(logger, "%d ETG @ %s", i, hwPortname(boardConfiguration->max31855_cs[i])); scheduleMsg(logger, "%d ETG @ %s", i, hwPortname(CONFIGB(max31855_cs)[i]));
} }
} }
#endif #endif

View File

@ -340,7 +340,7 @@ static void cjCalibrate(void) {
} }
static void cjStart(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void cjStart(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (!boardConfiguration->isCJ125Enabled) { if (!CONFIGB(isCJ125Enabled)) {
scheduleMsg(logger, "cj125 is disabled."); scheduleMsg(logger, "cj125 is disabled.");
return; return;
} }
@ -395,12 +395,12 @@ static void cjSetIdleHeater(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
static void cjStartHeaterControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void cjStartHeaterControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (boardConfiguration->wboHeaterPin != GPIO_UNASSIGNED) { if (CONFIGB(wboHeaterPin) != GPIO_UNASSIGNED) {
scheduleMsg(logger, "cj125: Starting heater control"); scheduleMsg(logger, "cj125: Starting heater control");
// todo: use custom pin state method, turn pin off while not running // todo: use custom pin state method, turn pin off while not running
startSimplePwmExt(&wboHeaterControl, "wboHeaterPin", startSimplePwmExt(&wboHeaterControl, "wboHeaterPin",
&engine->executor, &engine->executor,
boardConfiguration->wboHeaterPin, CONFIGB(wboHeaterPin),
&wboHeaterPin, CJ125_HEATER_PWM_FREQ, 0.0f, applyPinState); &wboHeaterPin, CJ125_HEATER_PWM_FREQ, 0.0f, applyPinState);
cjSetIdleHeater(PASS_ENGINE_PARAMETER_SIGNATURE); cjSetIdleHeater(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
@ -441,32 +441,32 @@ static void cjInitPid(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// engineConfiguration->spi2SckMode = PAL_STM32_OTYPE_OPENDRAIN; // 4 // engineConfiguration->spi2SckMode = PAL_STM32_OTYPE_OPENDRAIN; // 4
// engineConfiguration->spi2MosiMode = PAL_STM32_OTYPE_OPENDRAIN; // 4 // engineConfiguration->spi2MosiMode = PAL_STM32_OTYPE_OPENDRAIN; // 4
// engineConfiguration->spi2MisoMode = PAL_STM32_PUDR_PULLUP; // 32 // engineConfiguration->spi2MisoMode = PAL_STM32_PUDR_PULLUP; // 32
// boardConfiguration->cj125CsPin = GPIOA_15; // CONFIGB(cj125CsPin) = GPIOA_15;
// engineConfiguration->cj125CsPinMode = OM_OPENDRAIN; // engineConfiguration->cj125CsPinMode = OM_OPENDRAIN;
void cj125defaultPinout(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void cj125defaultPinout(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engineConfiguration->cj125ua = EFI_ADC_13; // PC3 engineConfiguration->cj125ua = EFI_ADC_13; // PC3
engineConfiguration->cj125ur = EFI_ADC_4; // PA4 engineConfiguration->cj125ur = EFI_ADC_4; // PA4
boardConfiguration->wboHeaterPin = GPIOC_13; CONFIGB(wboHeaterPin) = GPIOC_13;
boardConfiguration->isCJ125Enabled = false; CONFIGB(isCJ125Enabled) = false;
boardConfiguration->spi2mosiPin = GPIOB_15; CONFIGB(spi2mosiPin) = GPIOB_15;
boardConfiguration->spi2misoPin = GPIOB_14; CONFIGB(spi2misoPin) = GPIOB_14;
boardConfiguration->spi2sckPin = GPIOB_13; CONFIGB(spi2sckPin) = GPIOB_13;
boardConfiguration->cj125CsPin = GPIOB_0; CONFIGB(cj125CsPin) = GPIOB_0;
boardConfiguration->isCJ125Enabled = true; CONFIGB(isCJ125Enabled) = true;
boardConfiguration->is_enabled_spi_2 = true; CONFIGB(is_enabled_spi_2) = true;
} }
static void cjStartSpi(DECLARE_ENGINE_PARAMETER_SIGNATURE) { static void cjStartSpi(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
cj125Cs.initPin("cj125 CS", boardConfiguration->cj125CsPin, cj125Cs.initPin("cj125 CS", CONFIGB(cj125CsPin),
&engineConfiguration->cj125CsPinMode); &engineConfiguration->cj125CsPinMode);
#if EFI_PROD_CODE #if EFI_PROD_CODE
cj125spicfg.ssport = getHwPort("cj125", boardConfiguration->cj125CsPin); cj125spicfg.ssport = getHwPort("cj125", CONFIGB(cj125CsPin));
cj125spicfg.sspad = getHwPin("cj125", boardConfiguration->cj125CsPin); cj125spicfg.sspad = getHwPin("cj125", CONFIGB(cj125CsPin));
driver = getSpiDevice(engineConfiguration->cj125SpiDevice); driver = getSpiDevice(engineConfiguration->cj125SpiDevice);
scheduleMsg(logger, "cj125: Starting SPI driver"); scheduleMsg(logger, "cj125: Starting SPI driver");
spiStart(driver, &cj125spicfg); spiStart(driver, &cj125spicfg);
@ -590,7 +590,7 @@ static msg_t cjThread(void)
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__) #if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
static bool cjCheckConfig(void) { static bool cjCheckConfig(void) {
if (!boardConfiguration->isCJ125Enabled) { if (!CONFIGB(isCJ125Enabled)) {
scheduleMsg(logger, "cj125 is disabled. Failed!"); scheduleMsg(logger, "cj125 is disabled. Failed!");
return false; return false;
} }
@ -646,7 +646,7 @@ float cjGetAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
bool cjHasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { bool cjHasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (!boardConfiguration->isCJ125Enabled) if (!CONFIGB(isCJ125Enabled))
return false; return false;
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST
// check if controller is functioning // check if controller is functioning
@ -680,7 +680,7 @@ void cjPostState(TunerStudioOutputChannels *tsOutputChannels) {
void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
logger = sharedLogger; logger = sharedLogger;
if (!boardConfiguration->isCJ125Enabled) if (!CONFIGB(isCJ125Enabled))
return; return;
if (CONFIG(cj125ur) == EFI_ADC_NONE || CONFIG(cj125ua) == EFI_ADC_NONE) { if (CONFIG(cj125ur) == EFI_ADC_NONE || CONFIG(cj125ua) == EFI_ADC_NONE) {
@ -688,7 +688,7 @@ void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
return; return;
} }
if (boardConfiguration->wboHeaterPin == GPIO_UNASSIGNED) { if (CONFIGB(wboHeaterPin) == GPIO_UNASSIGNED) {
scheduleMsg(logger, "cj125 init error! wboHeaterPin is required."); scheduleMsg(logger, "cj125 init error! wboHeaterPin is required.");
return; return;
} }

View File

@ -240,11 +240,11 @@ static int getSpiAf(SPIDriver *driver) {
brain_pin_e getMisoPin(spi_device_e device) { brain_pin_e getMisoPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1misoPin; return CONFIGB(spi1misoPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2misoPin; return CONFIGB(spi2misoPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3misoPin; return CONFIGB(spi3misoPin);
default: default:
break; break;
} }
@ -254,11 +254,11 @@ brain_pin_e getMisoPin(spi_device_e device) {
brain_pin_e getMosiPin(spi_device_e device) { brain_pin_e getMosiPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1mosiPin; return CONFIGB(spi1mosiPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2mosiPin; return CONFIGB(spi2mosiPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3mosiPin; return CONFIGB(spi3mosiPin);
default: default:
break; break;
} }
@ -268,11 +268,11 @@ brain_pin_e getMosiPin(spi_device_e device) {
brain_pin_e getSckPin(spi_device_e device) { brain_pin_e getSckPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1sckPin; return CONFIGB(spi1sckPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2sckPin; return CONFIGB(spi2sckPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3sckPin; return CONFIGB(spi3sckPin);
default: default:
break; break;
} }

View File

@ -237,11 +237,11 @@ static int getSpiAf(SPIDriver *driver) {
brain_pin_e getMisoPin(spi_device_e device) { brain_pin_e getMisoPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1misoPin; return CONFIGB(spi1misoPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2misoPin; return CONFIGB(spi2misoPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3misoPin; return CONFIGB(spi3misoPin);
default: default:
break; break;
} }
@ -251,11 +251,11 @@ brain_pin_e getMisoPin(spi_device_e device) {
brain_pin_e getMosiPin(spi_device_e device) { brain_pin_e getMosiPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1mosiPin; return CONFIGB(spi1mosiPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2mosiPin; return CONFIGB(spi2mosiPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3mosiPin; return CONFIGB(spi3mosiPin);
default: default:
break; break;
} }
@ -265,11 +265,11 @@ brain_pin_e getMosiPin(spi_device_e device) {
brain_pin_e getSckPin(spi_device_e device) { brain_pin_e getSckPin(spi_device_e device) {
switch(device) { switch(device) {
case SPI_DEVICE_1: case SPI_DEVICE_1:
return boardConfiguration->spi1sckPin; return CONFIGB(spi1sckPin);
case SPI_DEVICE_2: case SPI_DEVICE_2:
return boardConfiguration->spi2sckPin; return CONFIGB(spi2sckPin);
case SPI_DEVICE_3: case SPI_DEVICE_3:
return boardConfiguration->spi3sckPin; return CONFIGB(spi3sckPin);
default: default:
break; break;
} }

View File

@ -186,6 +186,7 @@ void runRusEfi(void) {
* In order to have complete flexibility configuration has to go before anything else. * In order to have complete flexibility configuration has to go before anything else.
*/ */
readConfiguration(&sharedLogger); readConfiguration(&sharedLogger);
// TODO: need to fix this place!!! should be a version of PASS_ENGINE_PARAMETER_SIGNATURE somehow
prepareVoidConfiguration(&activeConfiguration); prepareVoidConfiguration(&activeConfiguration);
/** /**
@ -239,7 +240,7 @@ void runRusEfi(void) {
updateDevConsoleState(); updateDevConsoleState();
#endif /* EFI_CLI_SUPPORT */ #endif /* EFI_CLI_SUPPORT */
chThdSleepMilliseconds(boardConfiguration->consoleLoopPeriod); chThdSleepMilliseconds(CONFIGB(consoleLoopPeriod));
} }
} }

View File

@ -97,7 +97,7 @@ static void resetTrigger(EngineTestHelper &eth) {
static void testNoiselessDecoderProcedure(EngineTestHelper &eth, int errorToleranceCnt DECLARE_ENGINE_PARAMETER_SUFFIX) { static void testNoiselessDecoderProcedure(EngineTestHelper &eth, int errorToleranceCnt DECLARE_ENGINE_PARAMETER_SUFFIX) {
printf("*** (bc->useNoiselessTriggerDecoder = %s)\r\n", printf("*** (bc->useNoiselessTriggerDecoder = %s)\r\n",
boardConfiguration->useNoiselessTriggerDecoder ? "true" : "false"); CONFIGB(useNoiselessTriggerDecoder) ? "true" : "false");
resetTrigger(eth); resetTrigger(eth);
@ -195,13 +195,13 @@ void testNoiselessDecoder(void) {
#if 0 #if 0
// try normal trigger mode, no noise filtering // try normal trigger mode, no noise filtering
boardConfiguration->useNoiselessTriggerDecoder = false; CONFIGB(useNoiselessTriggerDecoder) = false;
// for test validation, it should be 1 trigger error // for test validation, it should be 1 trigger error
testNoiselessDecoderProcedure(eth, 1 PASS_ENGINE_PARAMETER_SUFFIX); testNoiselessDecoderProcedure(eth, 1 PASS_ENGINE_PARAMETER_SUFFIX);
#endif #endif
// now enable our noise filtering algo // now enable our noise filtering algo
boardConfiguration->useNoiselessTriggerDecoder = true; CONFIGB(useNoiselessTriggerDecoder) = true;
// should be 0 errors! // should be 0 errors!
testNoiselessDecoderProcedure(eth, 0 PASS_ENGINE_PARAMETER_SUFFIX); testNoiselessDecoderProcedure(eth, 0 PASS_ENGINE_PARAMETER_SUFFIX);