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