gpio helper (#2195)
* gpios: isBrainPinValid helper * LCD HD44780: do not touch pins if DM_NONE or invalid gpio * Fix isEnabled checks for GPS and Joystick * LCD HD44780: writePad use this method wider
This commit is contained in:
parent
d0c71d758b
commit
2af32084f4
|
@ -231,7 +231,7 @@ typedef enum __attribute__ ((__packed__)) {
|
|||
|
||||
} brain_pin_e;
|
||||
|
||||
/* Plase keep updating this define */
|
||||
/* Plase keep updating this defines */
|
||||
#define BRAIN_PIN_ONCHIP_LAST GPIOK_15
|
||||
#define BRAIN_PIN_ONCHIP_PINS (BRAIN_PIN_ONCHIP_LAST - GPIOA_0 + 1)
|
||||
#define BRAIN_PIN_LAST DRV8860_PIN_16
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "custom_engine.h"
|
||||
#include "allsensors.h"
|
||||
#include "engine_math.h"
|
||||
|
@ -51,7 +52,7 @@ static void toggleTestAndScheduleNext(void *) {
|
|||
* https://github.com/rusefi/rusefi/issues/557 common rail / direct injection scheduling control test
|
||||
*/
|
||||
void runSchedulingPrecisionTestIfNeeded(void) {
|
||||
if (engineConfiguration->test557pin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(engineConfiguration->test557pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ static systime_t timeOfPreviousPrintVersion = 0;
|
|||
|
||||
#if EFI_PROD_CODE
|
||||
static void printOutPin(const char *pinName, brain_pin_e hwPin) {
|
||||
if (hwPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(hwPin)) {
|
||||
logger.appendPrintf("%s%s%s@%s%s", PROTOCOL_OUTPIN, DELIMETER, pinName, hwPortname(hwPin), DELIMETER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ void onConfigurationChangeAlternatorCallback(engine_configuration_s *previousCon
|
|||
void initAlternatorCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
logger = sharedLogger;
|
||||
addConsoleAction("altinfo", showAltInfo);
|
||||
if (CONFIG(alternatorControlPin) == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(CONFIG(alternatorControlPin)))
|
||||
return;
|
||||
|
||||
if (!CONFIG(onOffAlternatorLogic)) {
|
||||
|
|
|
@ -61,7 +61,8 @@ public:
|
|||
}
|
||||
|
||||
int getPeriodMs() override {
|
||||
return engineConfiguration->auxPidPins[index] == GPIO_UNASSIGNED ? NO_PIN_PERIOD : GET_PERIOD_LIMITED(&engineConfiguration->auxPid[index]);
|
||||
return isBrainPinValid(engineConfiguration->auxPidPins[index]) ?
|
||||
GET_PERIOD_LIMITED(&engineConfiguration->auxPid[index]) : NO_PIN_PERIOD;
|
||||
}
|
||||
|
||||
void PeriodicTask() override {
|
||||
|
@ -114,7 +115,7 @@ static void turnAuxPidOn(int index) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (engineConfiguration->auxPidPins[index] == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(engineConfiguration->auxPidPins[index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
void startBoostPin() {
|
||||
#if !EFI_UNIT_TEST
|
||||
// Only init if a pin is set, no need to start PWM without a pin
|
||||
if (CONFIG(boostControlPin) == GPIO_UNASSIGNED){
|
||||
if (!isBrainPinValid(CONFIG(boostControlPin))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -227,8 +227,7 @@ void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
}
|
||||
|
||||
// If we have neither a boost PWM pin nor ETB wastegate, nothing more to do
|
||||
if ((CONFIG(boostControlPin) == GPIO_UNASSIGNED)
|
||||
&& !hasAnyEtbWastegate) {
|
||||
if (!isBrainPinValid(CONFIG(boostControlPin)) && !hasAnyEtbWastegate) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "global.h"
|
||||
#include "engine.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
#include "gppwm_channel.h"
|
||||
#include "pwm_generator_logic.h"
|
||||
|
@ -28,7 +29,7 @@ void initGpPwm(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
auto& cfg = CONFIG(gppwm)[i];
|
||||
|
||||
// If no pin, don't enable this channel.
|
||||
if (cfg.pin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(cfg.pin)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ void initIdleHardware(Logging* sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
|
||||
// This greatly improves PID accuracy for steppers with a small number of steps
|
||||
idlePositionSensitivityThreshold = 1.0f / engineConfiguration->idleStepperTotalSteps;
|
||||
} else if (engineConfiguration->useETBforIdleControl || CONFIG(idle).solenoidPin == GPIO_UNASSIGNED) {
|
||||
} else if (engineConfiguration->useETBforIdleControl || !isBrainPinValid(CONFIG(idle).solenoidPin)) {
|
||||
// here we do nothing for ETB idle and for no idle
|
||||
} else {
|
||||
// we are here for single or double solenoid idle
|
||||
|
@ -176,7 +176,7 @@ void initIdleHardware(Logging* sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
(pwm_gen_callback*)applyIdleSolenoidPinState);
|
||||
|
||||
if (CONFIG(isDoubleSolenoidIdle)) {
|
||||
if (CONFIG(secondSolenoidPin) == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(CONFIG(secondSolenoidPin))) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "Second idle pin should be configured for double solenoid mode.");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -701,22 +701,22 @@ void startIdleThread(Logging*sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
#if ! EFI_UNIT_TEST
|
||||
// this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox
|
||||
// this switch is not used yet
|
||||
if (CONFIG(clutchDownPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(clutchDownPin))) {
|
||||
efiSetPadMode("clutch down switch", CONFIG(clutchDownPin),
|
||||
getInputMode(CONFIG(clutchDownPinMode)));
|
||||
}
|
||||
|
||||
if (CONFIG(clutchUpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(clutchUpPin))) {
|
||||
efiSetPadMode("clutch up switch", CONFIG(clutchUpPin),
|
||||
getInputMode(CONFIG(clutchUpPinMode)));
|
||||
}
|
||||
|
||||
if (CONFIG(throttlePedalUpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(throttlePedalUpPin))) {
|
||||
efiSetPadMode("throttle pedal up switch", CONFIG(throttlePedalUpPin),
|
||||
getInputMode(CONFIG(throttlePedalUpPinMode)));
|
||||
}
|
||||
|
||||
if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->brakePedalPin)) {
|
||||
#if EFI_PROD_CODE
|
||||
efiSetPadMode("brake pedal switch", engineConfiguration->brakePedalPin,
|
||||
getInputMode(engineConfiguration->brakePedalPinMode));
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
#if EFI_DYNO_VIEW
|
||||
#include "dynoview.h"
|
||||
|
@ -154,7 +155,7 @@ int getDynoviewPower(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
* Only updates if we have Vss from input pin.
|
||||
*/
|
||||
void updateDynoView(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if ((CONFIG(vehicleSpeedSensorInputPin) != GPIO_UNASSIGNED) &&
|
||||
if (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin)) &&
|
||||
(!CONFIG(enableCanVss))) {
|
||||
dynoInstance.update(ICU);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "engine.h"
|
||||
#include "allsensors.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "pin_repository.h"
|
||||
#include "trigger_central.h"
|
||||
#include "fuel_math.h"
|
||||
#include "engine_math.h"
|
||||
|
@ -278,7 +279,7 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
void Engine::updateSwitchInputs(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
#if EFI_GPIO_HARDWARE
|
||||
// this value is not used yet
|
||||
if (CONFIG(clutchDownPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(clutchDownPin))) {
|
||||
engine->clutchDownState = efiReadPin(CONFIG(clutchDownPin));
|
||||
}
|
||||
if (hasAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE)) {
|
||||
|
@ -289,14 +290,14 @@ void Engine::updateSwitchInputs(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
engine->acSwitchState = result;
|
||||
}
|
||||
if (CONFIG(clutchUpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(clutchUpPin))) {
|
||||
engine->clutchUpState = efiReadPin(CONFIG(clutchUpPin));
|
||||
}
|
||||
if (CONFIG(throttlePedalUpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(throttlePedalUpPin))) {
|
||||
engine->engineState.idle.throttlePedalUpState = efiReadPin(CONFIG(throttlePedalUpPin));
|
||||
}
|
||||
|
||||
if (engineConfiguration->brakePedalPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->brakePedalPin)) {
|
||||
engine->brakePedalState = efiReadPin(engineConfiguration->brakePedalPin);
|
||||
}
|
||||
#endif // EFI_GPIO_HARDWARE
|
||||
|
|
|
@ -45,14 +45,14 @@ static int retardThresholdRpm;
|
|||
bool LaunchControlBase::isInsideSwitchCondition() const {
|
||||
switch (CONFIG(launchActivationMode)) {
|
||||
case SWITCH_INPUT_LAUNCH:
|
||||
if (CONFIG(launchActivatePin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(launchActivatePin))) {
|
||||
//todo: we should take into consideration if this sw is pulled high or low!
|
||||
engine->launchActivatePinState = efiReadPin(CONFIG(launchActivatePin));
|
||||
}
|
||||
return engine->launchActivatePinState;
|
||||
|
||||
case CLUTCH_INPUT_LAUNCH:
|
||||
if (CONFIG(clutchDownPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(clutchDownPin))) {
|
||||
engine->clutchDownState = efiReadPin(CONFIG(clutchDownPin));
|
||||
|
||||
if (CONFIG(clutchDownPinMode) == PI_PULLDOWN)
|
||||
|
|
|
@ -460,24 +460,24 @@ void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
#if EFI_FUEL_PUMP
|
||||
if (CONFIG(fuelPumpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(fuelPumpPin))) {
|
||||
setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
#endif /* EFI_FUEL_PUMP */
|
||||
|
||||
#if EFI_MAIN_RELAY_CONTROL
|
||||
if (CONFIG(mainRelayPin) != GPIO_UNASSIGNED)
|
||||
if (isBrainPinValid(CONFIG(mainRelayPin)))
|
||||
// the MAIN_RELAY_LOGIC calls engine->isInShutdownMode()
|
||||
setPinState("main_relay", &enginePins.mainRelay, mainRelayLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#else /* EFI_MAIN_RELAY_CONTROL */
|
||||
/**
|
||||
* main relay is always on if ECU is on, that's a good enough initial implementation
|
||||
*/
|
||||
if (CONFIG(mainRelayPin) != GPIO_UNASSIGNED)
|
||||
if (isBrainPinValid(CONFIG(mainRelayPin)))
|
||||
enginePins.mainRelay.setValue(true);
|
||||
#endif /* EFI_MAIN_RELAY_CONTROL */
|
||||
|
||||
if (CONFIG(starterRelayDisablePin) != GPIO_UNASSIGNED)
|
||||
if (isBrainPinValid(CONFIG(starterRelayDisablePin)))
|
||||
setPinState("starter_relay", &enginePins.starterRelayDisable, starterRelayDisableLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
/**
|
||||
|
@ -487,15 +487,15 @@ void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
*/
|
||||
enginePins.o2heater.setValue(engine->rpmCalculator.isRunning());
|
||||
|
||||
if (CONFIG(acRelayPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(acRelayPin))) {
|
||||
setPinState("A/C", &enginePins.acRelay, acRelayLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
// if (CONFIG(alternatorControlPin) != GPIO_UNASSIGNED) {
|
||||
// if (isBrainPinValid(CONFIG(alternatorControlPin))) {
|
||||
// setPinState("alternator", &enginePins.alternatorField, alternatorLogic, engine PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
// }
|
||||
|
||||
if (CONFIG(fanPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(fanPin))) {
|
||||
setPinState("fan", &enginePins.fanRelay, radiatorFanLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
|
@ -572,7 +572,7 @@ static void showFsioInfo(void) {
|
|||
|
||||
for (int i = 0; i < AUX_PID_COUNT ; i++) {
|
||||
brain_pin_e pin = engineConfiguration->auxPidPins[i];
|
||||
if (pin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(pin)) {
|
||||
scheduleMsg(logger, "FSIO aux #%d [%s]", (i + 1),
|
||||
hwPortname(pin));
|
||||
|
||||
|
@ -606,7 +606,7 @@ static void showFsioInfo(void) {
|
|||
}
|
||||
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
||||
brain_pin_e inputPin = CONFIG(fsioDigitalInputs)[i];
|
||||
if (inputPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(inputPin)) {
|
||||
scheduleMsg(logger, "FSIO digital input #%d: %s", i, hwPortname(inputPin));
|
||||
}
|
||||
}
|
||||
|
@ -698,17 +698,17 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC);
|
||||
|
||||
#if EFI_MAIN_RELAY_CONTROL
|
||||
if (CONFIG(mainRelayPin) != GPIO_UNASSIGNED)
|
||||
if (isBrainPinValid(CONFIG(mainRelayPin)))
|
||||
mainRelayLogic = sysPool.parseExpression(MAIN_RELAY_LOGIC);
|
||||
#endif /* EFI_MAIN_RELAY_CONTROL */
|
||||
if (CONFIG(starterRelayDisablePin) != GPIO_UNASSIGNED)
|
||||
if (isBrainPinValid(CONFIG(starterRelayDisablePin)))
|
||||
starterRelayDisableLogic = sysPool.parseExpression(STARTER_RELAY_LOGIC);
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
||||
brain_pin_e brainPin = CONFIG(fsioOutputPins)[i];
|
||||
|
||||
if (brainPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(brainPin)) {
|
||||
int frequency = CONFIG(fsioFrequency)[i];
|
||||
if (frequency == 0) {
|
||||
enginePins.fsioOutputs[i].initPin(getGpioPinName(i), CONFIG(fsioOutputPins)[i]);
|
||||
|
@ -723,7 +723,7 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
||||
brain_pin_e inputPin = CONFIG(fsioDigitalInputs)[i];
|
||||
|
||||
if (inputPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(inputPin)) {
|
||||
efiSetPadMode("FSIO input", inputPin, getInputMode(engineConfiguration->fsioInputModes[i]));
|
||||
}
|
||||
}
|
||||
|
@ -765,25 +765,25 @@ void runHardcodedFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
// see MAIN_RELAY_LOGIC
|
||||
if (CONFIG(mainRelayPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(mainRelayPin))) {
|
||||
enginePins.mainRelay.setValue((getTimeNowSeconds() < 2) || (getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) > LOW_VBATT) || engine->isInShutdownMode());
|
||||
}
|
||||
// see STARTER_RELAY_LOGIC
|
||||
if (CONFIG(starterRelayDisablePin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(starterRelayDisablePin))) {
|
||||
enginePins.starterRelayDisable.setValue(engine->rpmCalculator.getRpm() < engineConfiguration->cranking.rpm);
|
||||
}
|
||||
// see FAN_CONTROL_LOGIC
|
||||
if (CONFIG(fanPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(fanPin))) {
|
||||
auto clt = Sensor::get(SensorType::Clt);
|
||||
enginePins.fanRelay.setValue(!clt.Valid || (enginePins.fanRelay.getLogicValue() && (clt.Value > engineConfiguration->fanOffTemperature)) ||
|
||||
(clt.Value > engineConfiguration->fanOnTemperature) || engine->isCltBroken);
|
||||
}
|
||||
// see AC_RELAY_LOGIC
|
||||
if (CONFIG(acRelayPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(acRelayPin))) {
|
||||
enginePins.acRelay.setValue(getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE) && engine->rpmCalculator.getRpm() > 850);
|
||||
}
|
||||
// see FUEL_PUMP_LOGIC
|
||||
if (CONFIG(fuelPumpPin) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(fuelPumpPin))) {
|
||||
enginePins.fuelPumpRelay.setValue((getTimeNowSeconds() < engine->triggerActivitySecond + engineConfiguration->startUpFuelPumpDuration) || (engine->rpmCalculator.getRpm() > 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "engine_math.h"
|
||||
#include "aux_valves.h"
|
||||
#include "allsensors.h"
|
||||
|
@ -69,7 +70,7 @@ void auxPlainPinTurnOn(AuxActor *current) {
|
|||
|
||||
void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
UNUSED(sharedLogger);
|
||||
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -95,7 +96,7 @@ void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
}
|
||||
|
||||
void recalculateAuxValveTiming(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "high_pressure_fuel_pump.h"
|
||||
#include "spark_logic.h"
|
||||
#include "map.h"
|
||||
|
@ -68,7 +69,7 @@ void hpfpPlainPinTurnOn(HpfpActor *current) {
|
|||
}
|
||||
|
||||
void initHPFP(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (engineConfiguration->hpfpValvePin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(engineConfiguration->hpfpValvePin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -389,7 +389,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE
|
|||
#endif // HW_CHECK_MODE
|
||||
|
||||
#if EFI_CDM_INTEGRATION
|
||||
if (trgEventIndex == 0 && CONFIG(cdmInputPin) != GPIO_UNASSIGNED) {
|
||||
if (trgEventIndex == 0 && isBrainPinValid(CONFIG(cdmInputPin))) {
|
||||
int cdmKnockValue = getCurrentCdmValue(engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
||||
engine->knockLogic(cdmKnockValue);
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ static void testMil(void) {
|
|||
#endif /* TEST_MIL_CODE */
|
||||
|
||||
bool isMilEnabled() {
|
||||
return CONFIG(malfunctionIndicatorPin) != GPIO_UNASSIGNED;
|
||||
return isBrainPinValid(CONFIG(malfunctionIndicatorPin));
|
||||
}
|
||||
|
||||
void initMalfunctionIndicator(void) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "tachometer.h"
|
||||
#include "pwm_generator_logic.h"
|
||||
|
||||
|
@ -67,7 +68,7 @@ void tachSignalCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
tachHasInit = false;
|
||||
if (CONFIG(tachOutputPin) == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(CONFIG(tachOutputPin))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "pin_repository.h"
|
||||
#include "allsensors.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
@ -24,5 +25,5 @@ bool getAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
bool hasAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
return (CONFIG(acSwitch) != GPIO_UNASSIGNED);
|
||||
return (isBrainPinValid(CONFIG(acSwitch)));
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ void OutputPin::setValue(int logicValue) {
|
|||
currentLogicValue = logicValue;
|
||||
|
||||
// Nothing else to do if not configured
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin) {
|
|||
}
|
||||
|
||||
void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_mode_e *outputMode) {
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,7 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_
|
|||
|
||||
// Check that this OutputPin isn't already assigned to another pin (reinit is allowed to change mode)
|
||||
// To avoid this error, call deInit() first
|
||||
if (this->brainPin != GPIO_UNASSIGNED && this->brainPin != brainPin) {
|
||||
if (isBrainPinValid(this->brainPin) && this->brainPin != brainPin) {
|
||||
firmwareError(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned, cannot reassign without unregister first", msg);
|
||||
return;
|
||||
}
|
||||
|
@ -544,7 +544,7 @@ void OutputPin::deInit() {
|
|||
chibios_rt::CriticalSectionLocker csl;
|
||||
|
||||
// nothing to do if not registered in the first place
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
#include "trigger_decoder.h"
|
||||
#include "trigger_central_generated.h"
|
||||
#include "timer.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
class Engine;
|
||||
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
#define HAVE_CAM_INPUT() engineConfiguration->camInputs[0] != GPIO_UNASSIGNED
|
||||
#define HAVE_CAM_INPUT() (isBrainPinValid(engineConfiguration->camInputs[0]))
|
||||
|
||||
class TriggerNoiseFilter {
|
||||
public:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "state_sequence.h"
|
||||
#include "global.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "pin_repository.h"
|
||||
|
||||
int getPreviousIndex(const int currentIndex, const int size) {
|
||||
return (currentIndex + size - 1) % size;
|
||||
|
@ -211,7 +212,7 @@ void startTriggerEmulatorPins() {
|
|||
brain_pin_e pin = CONFIG(triggerSimulatorPins)[i];
|
||||
|
||||
// Only bother trying to set output pins if they're configured
|
||||
if (pin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(pin)) {
|
||||
hasStimPins = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ void initPotentiometers(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
|
||||
for (int i = 0; i < DIGIPOT_COUNT; i++) {
|
||||
brain_pin_e csPin = CONFIG(digitalPotentiometerChipSelect)[i];
|
||||
if (csPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(csPin)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ static void initWave(const char *name, int index) {
|
|||
efiAssertVoid(CUSTOM_ERR_6655, index < MAX_ICU_COUNT, "too many ICUs");
|
||||
WaveReader *reader = &readers[index];
|
||||
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
/**
|
||||
* in case we are running, and we select none for a channel that was running,
|
||||
* this way we ensure that we do not get false report from that channel
|
||||
|
@ -243,7 +243,7 @@ void stopLogicAnalyzerPins() {
|
|||
for (int index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) {
|
||||
brain_pin_e brainPin = activeConfiguration.logicAnalyzerPins[index];
|
||||
|
||||
if (brainPin != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(brainPin)) {
|
||||
stopDigitalCapture("wave input", brainPin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,12 +74,7 @@ static void extIonCallback(void *arg) {
|
|||
}
|
||||
|
||||
void cdmIonInit(void) {
|
||||
if (CONFIG(cdmInputPin) == GPIO_UNASSIGNED) {
|
||||
return;
|
||||
}
|
||||
int pin = (int)CONFIG(cdmInputPin);
|
||||
if (pin <= 0 || pin > (int)GPIO_UNASSIGNED) {
|
||||
// todo: remove this protection once we migrate to new mandatory configuration
|
||||
if (!isBrainPinValid(CONFIG(cdmInputPin))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ bool ButtonDebounce::readPinEvent() {
|
|||
}
|
||||
|
||||
bool ButtonDebounce::readPinState() {
|
||||
if (*m_pin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(*m_pin)) {
|
||||
return false;
|
||||
}
|
||||
efitick_t timeNow = getTimeNowNt();
|
||||
|
|
|
@ -28,7 +28,7 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, palc
|
|||
|
||||
/* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL
|
||||
* and we will fail on next check */
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return;
|
||||
|
||||
ioportid_t port = getHwPort(msg, brainPin);
|
||||
|
@ -61,7 +61,7 @@ void efiExtiDisablePin(brain_pin_e brainPin)
|
|||
{
|
||||
/* paranoid check, in case of GPIO_UNASSIGNED getHwPort will return NULL
|
||||
* and we will fail on next check */
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return;
|
||||
|
||||
ioportid_t port = getHwPort("exti", brainPin);
|
||||
|
|
|
@ -152,7 +152,7 @@ icuchannel_t getInputCaptureChannel(brain_pin_e hwPin) {
|
|||
ICUDriver * getInputCaptureDriver(const char *msg, brain_pin_e hwPin) {
|
||||
UNUSED(msg);
|
||||
|
||||
if (hwPin == GPIO_UNASSIGNED || hwPin == GPIO_INVALID) {
|
||||
if (!isBrainPinValid(hwPin)) {
|
||||
return NULL;
|
||||
}
|
||||
#if STM32_ICU_USE_TIM1
|
||||
|
@ -210,7 +210,7 @@ static void turnOnCapturePin(const char *msg, brain_pin_e brainPin) {
|
|||
* turns pin off and returns digital_input_s back into registeredIcus pool
|
||||
*/
|
||||
void stopDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return;
|
||||
}
|
||||
efiSetPadUnused(brainPin);
|
||||
|
|
|
@ -72,7 +72,7 @@ static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft
|
|||
else
|
||||
camTriggerType[index] = TRIGGER_NONE;
|
||||
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return 0;
|
||||
|
||||
/* try ICU first */
|
||||
|
|
|
@ -102,7 +102,7 @@ static void shaftFallingCallback(bool isPrimary) {
|
|||
int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
||||
(void)msg;
|
||||
brain_pin_e brainPin = isTriggerShaft ? CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index];
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,8 +174,8 @@ void initCan(void) {
|
|||
addConsoleAction("caninfo", canInfo);
|
||||
|
||||
isCanEnabled =
|
||||
(CONFIG_OVERRIDE(canTxPin) != GPIO_UNASSIGNED) && // both pins are set...
|
||||
(CONFIG_OVERRIDE(canRxPin) != GPIO_UNASSIGNED) &&
|
||||
(isBrainPinValid(CONFIG_OVERRIDE(canTxPin))) && // both pins are set...
|
||||
(isBrainPinValid(CONFIG_OVERRIDE(canRxPin))) &&
|
||||
(CONFIG(canWriteEnabled) || CONFIG(canReadEnabled)) ; // ...and either read or write is enabled
|
||||
|
||||
// nothing to do if we aren't enabled...
|
||||
|
|
|
@ -32,6 +32,8 @@ EXTERN_ENGINE;
|
|||
static LoggingWithStorage logger("io_pins");
|
||||
|
||||
bool efiReadPin(brain_pin_e pin) {
|
||||
if (!isBrainPinValid(pin))
|
||||
return false;
|
||||
if (brain_pin_is_onchip(pin))
|
||||
return palReadPad(getHwPort("readPin", pin), getHwPin("readPin", pin));
|
||||
#if (BOARD_EXT_GPIOCHIPS > 0)
|
||||
|
@ -69,7 +71,7 @@ void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brain
|
|||
*/
|
||||
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
|
||||
{
|
||||
if (brainPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
// No pin configured, nothing to do here.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ static const int lineStart[] = { 0, 0x40, 0x14, 0x54 };
|
|||
static int BUSY_WAIT_DELAY = FALSE;
|
||||
static int currentRow = 0;
|
||||
static int currentColumn = 0;
|
||||
static bool lcd_enabled = false;
|
||||
|
||||
static void lcdSleep(int period) {
|
||||
if (BUSY_WAIT_DELAY) {
|
||||
|
@ -111,7 +112,7 @@ static void lcd_HD44780_write(uint8_t data) {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void lcd_HD44780_write_command(uint8_t data) {
|
||||
static void lcd_HD44780_write_command(uint8_t data) {
|
||||
palClearPad(getHwPort("lcd", CONFIG(HD44780_rs)), getHwPin("lcd", CONFIG(HD44780_rs)));
|
||||
|
||||
lcd_HD44780_write(data);
|
||||
|
@ -119,7 +120,7 @@ void lcd_HD44780_write_command(uint8_t data) {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void lcd_HD44780_write_data(uint8_t data) {
|
||||
static void lcd_HD44780_write_data(uint8_t data) {
|
||||
palSetPad(getHwPort("lcd", CONFIG(HD44780_rs)), getHwPin("lcd", CONFIG(HD44780_rs)));
|
||||
|
||||
lcd_HD44780_write(data);
|
||||
|
@ -131,6 +132,9 @@ void lcd_HD44780_write_data(uint8_t data) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void lcd_HD44780_set_position(uint8_t row, uint8_t column) {
|
||||
if (!lcd_enabled)
|
||||
return;
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6657, row <= engineConfiguration->HD44780height, "invalid row");
|
||||
currentRow = row;
|
||||
currentColumn = column;
|
||||
|
@ -138,14 +142,23 @@ void lcd_HD44780_set_position(uint8_t row, uint8_t column) {
|
|||
}
|
||||
|
||||
int getCurrentHD44780row(void) {
|
||||
if (!lcd_enabled)
|
||||
return 0;
|
||||
|
||||
return currentRow;
|
||||
}
|
||||
|
||||
int getCurrentHD44780column(void) {
|
||||
if (!lcd_enabled)
|
||||
return 0;
|
||||
|
||||
return currentColumn;
|
||||
}
|
||||
|
||||
void lcd_HD44780_print_char(char data) {
|
||||
if (!lcd_enabled)
|
||||
return;
|
||||
|
||||
if (data == '\n') {
|
||||
lcd_HD44780_set_position(++currentRow, 0);
|
||||
} else {
|
||||
|
@ -154,6 +167,9 @@ void lcd_HD44780_print_char(char data) {
|
|||
}
|
||||
|
||||
void lcd_HD44780_print_string(const char* string) {
|
||||
if (!lcd_enabled)
|
||||
return;
|
||||
|
||||
while (*string != 0x00)
|
||||
lcd_HD44780_print_char(*string++);
|
||||
}
|
||||
|
@ -177,8 +193,14 @@ void stopHD44780_pins() {
|
|||
efiSetPadUnused(activeConfiguration.HD44780_db7);
|
||||
}
|
||||
|
||||
void startHD44780_pins() {
|
||||
if (engineConfiguration->displayMode == DM_HD44780) {
|
||||
int startHD44780_pins() {
|
||||
if ((engineConfiguration->displayMode == DM_HD44780) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_rs))) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_e))) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_db4))) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_db5))) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_db6))) &&
|
||||
(isBrainPinValid(CONFIG(HD44780_db7)))) {
|
||||
// initialize hardware lines
|
||||
efiSetPadMode("lcd RS", CONFIG(HD44780_rs), PAL_MODE_OUTPUT_PUSHPULL);
|
||||
efiSetPadMode("lcd E", CONFIG(HD44780_e), PAL_MODE_OUTPUT_PUSHPULL);
|
||||
|
@ -187,13 +209,20 @@ void startHD44780_pins() {
|
|||
efiSetPadMode("lcd DB6", CONFIG(HD44780_db6), PAL_MODE_OUTPUT_PUSHPULL);
|
||||
efiSetPadMode("lcd DB7", CONFIG(HD44780_db7), PAL_MODE_OUTPUT_PUSHPULL);
|
||||
// and zero values
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_rs)), getHwPin("lcd", CONFIG(HD44780_rs)), 0);
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_e)), getHwPin("lcd", CONFIG(HD44780_e)), 0);
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_db4)), getHwPin("lcd", CONFIG(HD44780_db4)), 0);
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_db5)), getHwPin("lcd", CONFIG(HD44780_db5)), 0);
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_db6)), getHwPin("lcd", CONFIG(HD44780_db6)), 0);
|
||||
palWritePad(getHwPort("lcd", CONFIG(HD44780_db7)), getHwPin("lcd", CONFIG(HD44780_db7)), 0);
|
||||
writePad("lcd", CONFIG(HD44780_rs), 0);
|
||||
writePad("lcd", CONFIG(HD44780_e), 0);
|
||||
writePad("lcd", CONFIG(HD44780_db4), 0);
|
||||
writePad("lcd", CONFIG(HD44780_db5), 0);
|
||||
writePad("lcd", CONFIG(HD44780_db6), 0);
|
||||
writePad("lcd", CONFIG(HD44780_db7), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* failed to init LCD pins, avoid writes */
|
||||
lcd_enabled = false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void lcd_HD44780_init(Logging *sharedLogger) {
|
||||
|
@ -201,6 +230,10 @@ void lcd_HD44780_init(Logging *sharedLogger) {
|
|||
|
||||
addConsoleAction("lcdinfo", lcdInfo);
|
||||
|
||||
if (engineConfiguration->displayMode == DM_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (engineConfiguration->displayMode > DM_HD44780_OVER_PCF8574) {
|
||||
warning(CUSTOM_ERR_DISPLAY_MODE, "Unexpected displayMode %d", engineConfiguration->displayMode);
|
||||
// I2C pins need initialization, code needs more work & testing
|
||||
|
@ -209,7 +242,8 @@ void lcd_HD44780_init(Logging *sharedLogger) {
|
|||
|
||||
printMsg(logger, "lcd_HD44780_init %d", engineConfiguration->displayMode);
|
||||
|
||||
startHD44780_pins();
|
||||
if (startHD44780_pins() < 0)
|
||||
return;
|
||||
|
||||
chThdSleepMilliseconds(20); // LCD needs some time to wake up
|
||||
lcd_HD44780_write(LCD_HD44780_RESET); // reset 1x
|
||||
|
@ -237,6 +271,8 @@ void lcd_HD44780_init(Logging *sharedLogger) {
|
|||
|
||||
lcd_HD44780_set_position(0, 0);
|
||||
printMsg(logger, "lcd_HD44780_init() done");
|
||||
|
||||
lcd_enabled = true;
|
||||
}
|
||||
|
||||
void lcdShowPanicMessage(char *message) {
|
||||
|
|
|
@ -12,7 +12,7 @@ extern "C"
|
|||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void startHD44780_pins();
|
||||
int startHD44780_pins();
|
||||
void stopHD44780_pins();
|
||||
void lcd_HD44780_init(Logging *sharedLogger);
|
||||
void lcd_HD44780_set_position(uint8_t row, uint8_t column);
|
||||
|
|
|
@ -42,7 +42,7 @@ static void showEgtInfo(void) {
|
|||
scheduleMsg(logger, "EGT spi: %d", CONFIG(max31855spiDevice));
|
||||
|
||||
for (int i = 0; i < EGT_CHANNEL_COUNT; i++) {
|
||||
if (CONFIG(max31855_cs)[i] != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(max31855_cs)[i])) {
|
||||
scheduleMsg(logger, "%d ETG @ %s", i, hwPortname(CONFIG(max31855_cs)[i]));
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ void initMax31855(Logging *sharedLogger, spi_device_e device, egt_cs_array_t max
|
|||
addConsoleAction("egtread", (Void) egtRead);
|
||||
|
||||
for (int i = 0; i < EGT_CHANNEL_COUNT; i++) {
|
||||
if (max31855_cs[i] != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(max31855_cs[i])) {
|
||||
|
||||
initSpiCs(&spiConfig[i], max31855_cs[i]);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "mc33816_memory_map.h"
|
||||
#include "engine.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "pin_repository.h"
|
||||
#include "hardware.h"
|
||||
#include "mc33816_data.h"
|
||||
#include "mpu_util.h"
|
||||
|
@ -66,7 +67,7 @@ static void showStats() {
|
|||
// x9D is product code or something, and 43 is the revision?
|
||||
scheduleMsg(logger, "MC 0x%x %s", mcChipId, validateChipId() ? "hooray!" : "not hooray :(");
|
||||
|
||||
if (CONFIG(mc33816_flag0) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(mc33816_flag0))) {
|
||||
scheduleMsg(logger, "flag0 before %d after %d", flag0before, flag0after);
|
||||
|
||||
scheduleMsg(logger, "flag0 right now %d", efiReadPin(CONFIG(mc33816_flag0)));
|
||||
|
@ -428,13 +429,12 @@ void initMc33816(Logging *sharedLogger) {
|
|||
//
|
||||
// see setTest33816EngineConfiguration for default configuration
|
||||
// Pins
|
||||
if (CONFIG(mc33816_cs) == GPIO_UNASSIGNED ||
|
||||
CONFIG(mc33816_rstb) == GPIO_UNASSIGNED ||
|
||||
CONFIG(mc33816_driven) == GPIO_UNASSIGNED
|
||||
) {
|
||||
if (!isBrainPinValid(CONFIG(mc33816_cs)) ||
|
||||
!isBrainPinValid(CONFIG(mc33816_rstb)) ||
|
||||
!isBrainPinValid(CONFIG(mc33816_driven))) {
|
||||
return;
|
||||
}
|
||||
if (CONFIG(mc33816_flag0) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(mc33816_flag0))) {
|
||||
efiSetPadMode("mc33816 flag0", CONFIG(mc33816_flag0), getInputMode(PI_DEFAULT));
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ static void mcRestart() {
|
|||
chThdSleepMilliseconds(10);
|
||||
resetB.setValue(1);
|
||||
chThdSleepMilliseconds(10);
|
||||
if (CONFIG(mc33816_flag0) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(mc33816_flag0))) {
|
||||
flag0before = efiReadPin(CONFIG(mc33816_flag0));
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ static void mcRestart() {
|
|||
* current configuration of REG_MAIN would toggle flag0 from LOW to HIGH
|
||||
*/
|
||||
download_register(REG_MAIN); // download main register configurations
|
||||
if (CONFIG(mc33816_flag0) != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(CONFIG(mc33816_flag0))) {
|
||||
flag0after = efiReadPin(CONFIG(mc33816_flag0));
|
||||
if (flag0before || !flag0after) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "MC33 flag0 transition no buena");
|
||||
|
|
|
@ -101,8 +101,8 @@ static THD_FUNCTION(GpsThreadEntryPoint, arg) {
|
|||
}
|
||||
|
||||
static bool isGpsEnabled() {
|
||||
return CONFIG(gps_rx_pin) != GPIO_UNASSIGNED ||
|
||||
CONFIG(gps_tx_pin) != GPIO_UNASSIGNED;
|
||||
return (isBrainPinValid(CONFIG(gps_rx_pin)) &&
|
||||
isBrainPinValid(CONFIG(gps_tx_pin)));
|
||||
}
|
||||
|
||||
void initGps(void) {
|
||||
|
|
|
@ -10,6 +10,20 @@
|
|||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
/* Common for firmware and unit tests */
|
||||
bool isBrainPinValid(brain_pin_e brainPin)
|
||||
{
|
||||
if ((brainPin == GPIO_UNASSIGNED) || (brainPin == GPIO_INVALID))
|
||||
return false;
|
||||
|
||||
if (brainPin > BRAIN_PIN_LAST)
|
||||
/* something terribly wrong */
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "os_access.h"
|
||||
#include "pin_repository.h"
|
||||
|
|
|
@ -27,6 +27,8 @@ class PinRepository {
|
|||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
bool isBrainPinValid(brain_pin_e brainPin);
|
||||
|
||||
void initPinRepository(void);
|
||||
EXTERNC bool brain_pin_is_onchip(brain_pin_e brainPin);
|
||||
EXTERNC bool brain_pin_is_ext(brain_pin_e brainPin);
|
||||
|
|
|
@ -110,9 +110,7 @@ int getBrainPinIndex(ioportid_t port, ioportmask_t pin) {
|
|||
}
|
||||
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
return GPIO_NULL;
|
||||
if (brainPin < GPIOA_0 || brainPin > BRAIN_PIN_ONCHIP_LAST) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return GPIO_NULL;
|
||||
}
|
||||
|
@ -124,7 +122,7 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
|||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
|
||||
{
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
if (brain_pin_is_onchip(brainPin))
|
||||
|
|
|
@ -76,9 +76,7 @@ int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
|
|||
}
|
||||
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
return GPIO_NULL;
|
||||
if (brainPin < GPIOA_0 || brainPin > BRAIN_PIN_ONCHIP_LAST) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return GPIO_NULL;
|
||||
}
|
||||
|
@ -90,7 +88,7 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
|||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
|
||||
{
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
if (brain_pin_is_onchip(brainPin))
|
||||
|
|
|
@ -121,9 +121,7 @@ int getPortPinIndex(ioportid_t port, ioportmask_t pin) {
|
|||
}
|
||||
|
||||
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
return GPIO_NULL;
|
||||
if (brainPin < GPIOA_0 || brainPin > BRAIN_PIN_ONCHIP_LAST) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid brain_pin_e: %d", msg, brainPin);
|
||||
return GPIO_NULL;
|
||||
}
|
||||
|
@ -135,7 +133,7 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) {
|
|||
*/
|
||||
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
|
||||
{
|
||||
if (brainPin == GPIO_UNASSIGNED || brainPin == GPIO_INVALID)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return EFI_ERROR_CODE;
|
||||
|
||||
if (brain_pin_is_onchip(brainPin))
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
static BenchController instance;
|
||||
|
||||
void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(engineConfiguration->LIS302DLCsPin))
|
||||
return; // not used
|
||||
|
||||
if (!CONFIG(is_enabled_spi_1))
|
||||
|
|
|
@ -625,7 +625,7 @@ void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (CONFIG(wboHeaterPin) == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(CONFIG(wboHeaterPin))) {
|
||||
scheduleMsg(logger, "cj125 init error! wboHeaterPin is required.");
|
||||
warning(CUSTOM_CJ125_1, "cj heater");
|
||||
globalInstance.errorCode = CJ125_ERROR_DISABLED;
|
||||
|
|
|
@ -87,11 +87,11 @@ static void joystickInfo(void) {
|
|||
}
|
||||
|
||||
static bool isJoystickEnabled() {
|
||||
return CONFIG(joystickCenterPin) != GPIO_UNASSIGNED ||
|
||||
CONFIG(joystickAPin) != GPIO_UNASSIGNED ||
|
||||
// not used so far CONFIG(joystickBPin) != GPIO_UNASSIGNED ||
|
||||
// not used so far CONFIG(joystickCPin) != GPIO_UNASSIGNED ||
|
||||
CONFIG(joystickDPin) != GPIO_UNASSIGNED;
|
||||
return (isBrainPinValid(CONFIG(joystickCenterPin)) &&
|
||||
isBrainPinValid(CONFIG(joystickAPin)) &&
|
||||
// not used so far isBrainPinValid(CONFIG(joystickBPin)) &&
|
||||
// not used so far isBrainPinValid(CONFIG(joystickCPin)) &&
|
||||
isBrainPinValid(CONFIG(joystickDPin)));
|
||||
}
|
||||
|
||||
void stopJoystickPins() {
|
||||
|
|
|
@ -179,7 +179,7 @@ void initSmartGpio() {
|
|||
startSmartCsPins();
|
||||
|
||||
#if (BOARD_TLE6240_COUNT > 0)
|
||||
if (engineConfiguration->tle6240_cs != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->tle6240_cs)) {
|
||||
tle6240.spi_config.ssport = getHwPort("tle6240 CS", engineConfiguration->tle6240_cs);
|
||||
tle6240.spi_config.sspad = getHwPin("tle6240 CS", engineConfiguration->tle6240_cs);
|
||||
tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice);
|
||||
|
@ -190,7 +190,7 @@ void initSmartGpio() {
|
|||
#endif /* (BOARD_TLE6240_COUNT > 0) */
|
||||
|
||||
#if (BOARD_MC33972_COUNT > 0)
|
||||
if (engineConfiguration->mc33972_cs != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->mc33972_cs)) {
|
||||
// todo: reuse initSpiCs method?
|
||||
mc33972.spi_config.ssport = getHwPort("mc33972 CS", engineConfiguration->mc33972_cs);
|
||||
mc33972.spi_config.sspad = getHwPin("mc33972 CS", engineConfiguration->mc33972_cs);
|
||||
|
@ -203,7 +203,7 @@ void initSmartGpio() {
|
|||
#endif /* (BOARD_MC33972_COUNT > 0) */
|
||||
|
||||
#if (BOARD_TLE8888_COUNT > 0)
|
||||
if (engineConfiguration->tle8888_cs != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->tle8888_cs)) {
|
||||
// todo: reuse initSpiCs method?
|
||||
tle8888_cfg.spi_config.ssport = getHwPort("tle8888 CS", engineConfiguration->tle8888_cs);
|
||||
tle8888_cfg.spi_config.sspad = getHwPin("tle8888 CS", engineConfiguration->tle8888_cs);
|
||||
|
@ -220,7 +220,7 @@ void initSmartGpio() {
|
|||
#endif /* (BOARD_TLE8888_COUNT > 0) */
|
||||
|
||||
#if (BOARD_DRV8860_COUNT > 0)
|
||||
if (engineConfiguration->drv8860_cs != GPIO_UNASSIGNED) {
|
||||
if (isBrainPinValid(engineConfiguration->drv8860_cs)) {
|
||||
drv8860.spi_config.ssport = getHwPort("drv8860 CS", engineConfiguration->drv8860_cs);
|
||||
drv8860.spi_config.sspad = getHwPin("drv8860 CS", engineConfiguration->drv8860_cs);
|
||||
drv8860.spi_bus = getSpiDevice(engineConfiguration->drv8860spiDevice);
|
||||
|
|
|
@ -218,7 +218,7 @@ void StepperMotor::initialize(StepperHw *hardware, int totalSteps, Logging *shar
|
|||
}
|
||||
|
||||
void StepDirectionStepper::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin_output_mode_e directionPinMode, float reactionTime, brain_pin_e enablePin, pin_output_mode_e enablePinMode) {
|
||||
if (stepPin == GPIO_UNASSIGNED || directionPin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(stepPin) || !isBrainPinValid(directionPin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft
|
|||
brain_pin_e brainPin = isTriggerShaft ?
|
||||
CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index];
|
||||
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return 0;
|
||||
#if 0
|
||||
centeredDacValue = getDacValue(CONFIG(triggerCompCenterVolt) PASS_ENGINE_PARAMETER_SUFFIX); // usually 2.5V resistor divider
|
||||
|
@ -292,7 +292,7 @@ void stopTriggerInputPins(void) {
|
|||
adc_channel_e getAdcChannelForTrigger(void) {
|
||||
// todo: add other trigger or cam channels?
|
||||
brain_pin_e brainPin = CONFIG(triggerInputPins)[0];
|
||||
if (brainPin == GPIO_UNASSIGNED)
|
||||
if (!isBrainPinValid(brainPin))
|
||||
return EFI_ADC_NONE;
|
||||
return getAdcChannel(brainPin);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ static void speedInfo(void) {
|
|||
}
|
||||
|
||||
bool hasVehicleSpeedSensor() {
|
||||
return CONFIG(vehicleSpeedSensorInputPin) != GPIO_UNASSIGNED;
|
||||
return (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin)));
|
||||
}
|
||||
|
||||
#if HAL_VSS_USE_PAL
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* @author Matthew Kennedy, (c) 2020
|
||||
*/
|
||||
|
||||
#include "pin_repository.h"
|
||||
#include "engine_configuration.h"
|
||||
|
||||
#if EFI_CAN_SUPPORT
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "init.h"
|
||||
#include "pin_repository.h"
|
||||
#include "engine.h"
|
||||
#include "flex_sensor.h"
|
||||
|
||||
|
@ -12,7 +13,7 @@ void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
auto pin = CONFIG(flexSensorPin);
|
||||
|
||||
// Nothing to do if no sensor configured
|
||||
if (pin == GPIO_UNASSIGNED) {
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue