2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file efiGpio.cpp
|
2017-04-21 10:36:51 -07:00
|
|
|
* @brief EFI-related GPIO code
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
* @date Sep 26, 2014
|
2017-01-03 03:05:22 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
2017-04-21 12:14:37 -07:00
|
|
|
#include "engine.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "efiGpio.h"
|
|
|
|
|
2017-04-21 12:14:37 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
|
|
|
#include "io_pins.h"
|
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-04-21 12:14:37 -07:00
|
|
|
EXTERN_ENGINE;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-04-21 16:23:20 -07:00
|
|
|
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
|
|
|
#include "engine_sniffer.h"
|
|
|
|
extern WaveChart waveChart;
|
|
|
|
#endif /* EFI_ENGINE_SNIFFER */
|
|
|
|
|
2017-04-21 13:36:50 -07:00
|
|
|
// todo: clean this mess, this should become 'static'/private
|
|
|
|
EnginePins enginePins;
|
|
|
|
extern LoggingWithStorage sharedLogger;
|
|
|
|
|
2017-08-03 18:28:44 -07:00
|
|
|
pin_output_mode_e DEFAULT_OUTPUT = OM_DEFAULT;
|
2016-09-03 21:03:27 -07:00
|
|
|
|
2016-09-27 08:01:57 -07:00
|
|
|
static const char *sparkNames[IGNITION_PIN_COUNT] = { "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8",
|
|
|
|
"c9", "cA", "cB", "cD"};
|
|
|
|
|
|
|
|
static const char *injectorNames[INJECTION_PIN_COUNT] = { "i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8",
|
|
|
|
"j9", "iA", "iB", "iC"};
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
EnginePins::EnginePins() {
|
2016-09-06 21:02:11 -07:00
|
|
|
dizzyOutput.name = DIZZY_NAME;
|
2016-09-13 22:01:57 -07:00
|
|
|
tachOut.name = TACH_NAME;
|
2016-09-27 08:01:57 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < IGNITION_PIN_COUNT;i++) {
|
|
|
|
enginePins.coils[i].name = sparkNames[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT;i++) {
|
2016-11-30 15:02:19 -08:00
|
|
|
enginePins.injectors[i].injectorIndex = i;
|
2016-09-27 08:01:57 -07:00
|
|
|
enginePins.injectors[i].name = injectorNames[i];
|
|
|
|
}
|
2016-09-06 21:02:11 -07:00
|
|
|
}
|
|
|
|
|
2017-04-21 13:52:02 -07:00
|
|
|
/**
|
|
|
|
* Sets the value of the pin. On this layer the value is assigned as is, without any conversion.
|
|
|
|
*/
|
|
|
|
|
2017-06-04 13:35:13 -07:00
|
|
|
#if EFI_PROD_CODE
|
2017-04-21 13:52:02 -07:00
|
|
|
#define setPinValue(outputPin, electricalValue, logicValue) \
|
|
|
|
{ \
|
|
|
|
if ((outputPin)->currentLogicValue != (logicValue)) { \
|
|
|
|
palWritePad((outputPin)->port, (outputPin)->pin, (electricalValue)); \
|
|
|
|
(outputPin)->currentLogicValue = (logicValue); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else /* EFI_PROD_CODE */
|
|
|
|
#define setPinValue(outputPin, electricalValue, logicValue) \
|
|
|
|
{ \
|
|
|
|
if ((outputPin)->currentLogicValue != (logicValue)) { \
|
|
|
|
(outputPin)->currentLogicValue = (logicValue); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
bool EnginePins::stopPins() {
|
|
|
|
bool result = false;
|
|
|
|
for (int i = 0; i < IGNITION_PIN_COUNT; i++) {
|
|
|
|
result |= coils[i].stop();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT; i++) {
|
|
|
|
result |= injectors[i].stop();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-04 13:35:13 -07:00
|
|
|
void EnginePins::unregisterPins() {
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
fuelPumpRelay.unregisterOutput(activeConfiguration.bc.fuelPumpPin, engineConfiguration->bc.fuelPumpPin);
|
|
|
|
fanRelay.unregisterOutput(activeConfiguration.bc.fanPin, engineConfiguration->bc.fanPin);
|
|
|
|
hipCs.unregisterOutput(activeConfiguration.bc.hip9011CsPin, engineConfiguration->bc.hip9011CsPin);
|
|
|
|
triggerDecoderErrorPin.unregisterOutput(activeConfiguration.bc.triggerErrorPin,
|
|
|
|
engineConfiguration->bc.triggerErrorPin);
|
|
|
|
|
2017-06-04 15:29:57 -07:00
|
|
|
sdCsPin.unregisterOutput(activeConfiguration.bc.sdCardCsPin, engineConfiguration->bc.sdCardCsPin);
|
2017-08-27 21:08:37 -07:00
|
|
|
accelerometerCs.unregisterOutput(activeConfiguration.LIS302DLCsPin, engineConfiguration->LIS302DLCsPin);
|
2017-06-04 15:29:57 -07:00
|
|
|
etbOutput1.unregisterOutput(activeConfiguration.bc.etbDirectionPin1,
|
|
|
|
engineConfiguration->bc.etbDirectionPin1);
|
|
|
|
etbOutput2.unregisterOutput(activeConfiguration.bc.etbDirectionPin2,
|
|
|
|
engineConfiguration->bc.etbDirectionPin2);
|
|
|
|
checkEnginePin.unregisterOutput(activeConfiguration.bc.malfunctionIndicatorPin,
|
|
|
|
engineConfiguration->bc.malfunctionIndicatorPin);
|
|
|
|
dizzyOutput.unregisterOutput(activeConfiguration.dizzySparkOutputPin,
|
|
|
|
engineConfiguration->dizzySparkOutputPin);
|
|
|
|
tachOut.unregisterOutput(activeConfiguration.bc.tachOutputPin,
|
|
|
|
engineConfiguration->bc.tachOutputPin);
|
|
|
|
idleSolenoidPin.unregisterOutput(activeConfiguration.bc.idle.solenoidPin,
|
|
|
|
engineConfiguration->bc.idle.solenoidPin);
|
|
|
|
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0;i < FSIO_COMMAND_COUNT;i++) {
|
2017-11-19 07:23:47 -08:00
|
|
|
fsioOutputs[i].unregisterOutput(activeConfiguration.bc.fsioOutputPins[i],
|
|
|
|
engineConfiguration->bc.fsioOutputPins[i]);
|
2017-06-04 15:29:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
alternatorPin.unregisterOutput(activeConfiguration.bc.alternatorControlPin,
|
|
|
|
engineConfiguration->bc.alternatorControlPin);
|
|
|
|
mainRelay.unregisterOutput(activeConfiguration.bc.mainRelayPin,
|
|
|
|
engineConfiguration->bc.mainRelayPin);
|
|
|
|
|
2017-06-04 13:35:13 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
}
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
void EnginePins::reset() {
|
2016-11-01 06:02:29 -07:00
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT;i++) {
|
|
|
|
injectors[i].reset();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < IGNITION_PIN_COUNT;i++) {
|
|
|
|
coils[i].reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 15:53:43 -07:00
|
|
|
void EnginePins::stopIgnitionPins(void) {
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
for (int i = 0; i < IGNITION_PIN_COUNT; i++) {
|
|
|
|
NamedOutputPin *output = &enginePins.coils[i];
|
|
|
|
output->unregisterOutput(activeConfiguration.bc.ignitionPins[i],
|
|
|
|
engineConfiguration->bc.ignitionPins[i]);
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnginePins::stopInjectionPins(void) {
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT; i++) {
|
|
|
|
NamedOutputPin *output = &enginePins.injectors[i];
|
|
|
|
output->unregisterOutput(activeConfiguration.bc.injectionPins[i],
|
|
|
|
engineConfiguration->bc.injectionPins[i]);
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnginePins::startIgnitionPins(void) {
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
|
|
|
|
NamedOutputPin *output = &enginePins.coils[i];
|
|
|
|
// todo: we need to check if mode has changed
|
|
|
|
if (boardConfiguration->ignitionPins[i] != activeConfiguration.bc.ignitionPins[i]) {
|
|
|
|
output->initPin(output->name, boardConfiguration->ignitionPins[i],
|
|
|
|
&boardConfiguration->ignitionPinMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// todo: we need to check if mode has changed
|
|
|
|
if (engineConfiguration->dizzySparkOutputPin != activeConfiguration.dizzySparkOutputPin) {
|
|
|
|
enginePins.dizzyOutput.initPin("dizzy tach", engineConfiguration->dizzySparkOutputPin,
|
|
|
|
&engineConfiguration->dizzySparkOutputPinMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnginePins::startInjectionPins(void) {
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
// todo: should we move this code closer to the injection logic?
|
|
|
|
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
|
|
|
|
NamedOutputPin *output = &enginePins.injectors[i];
|
|
|
|
// todo: we need to check if mode has changed
|
|
|
|
if (engineConfiguration->bc.injectionPins[i] != activeConfiguration.bc.injectionPins[i]) {
|
|
|
|
|
|
|
|
output->initPin(output->name, boardConfiguration->injectionPins[i],
|
|
|
|
&boardConfiguration->injectionPinMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:14:37 -07:00
|
|
|
NamedOutputPin::NamedOutputPin() : OutputPin() {
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
2017-04-21 16:23:20 -07:00
|
|
|
void NamedOutputPin::setHigh() {
|
|
|
|
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
|
|
|
// signal->hi_time = hTimeNow();
|
|
|
|
#endif /* EFI_DEFAILED_LOGGING */
|
|
|
|
|
|
|
|
// turn the output level ACTIVE
|
|
|
|
setValue(true);
|
|
|
|
|
|
|
|
// sleep for the needed duration
|
|
|
|
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
|
|
|
// explicit check here is a performance optimization to speed up no-chart mode
|
|
|
|
if (ENGINE(isEngineChartEnabled)) {
|
|
|
|
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
|
|
|
const char *pinName = name;
|
|
|
|
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
|
|
|
|
|
|
|
addEngineSniffferEvent(pinName, WC_UP);
|
|
|
|
}
|
|
|
|
#endif /* EFI_ENGINE_SNIFFER */
|
|
|
|
// dbgDurr = hal_lld_get_counter_value() - dbgStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NamedOutputPin::setLow() {
|
|
|
|
// turn off the output
|
|
|
|
setValue(false);
|
|
|
|
|
|
|
|
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
|
|
|
systime_t after = hTimeNow();
|
|
|
|
debugInt(&signal->logging, "a_time", after - signal->hi_time);
|
|
|
|
scheduleLogging(&signal->logging);
|
|
|
|
#endif /* EFI_DEFAILED_LOGGING */
|
|
|
|
|
|
|
|
#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
|
|
|
|
if (ENGINE(isEngineChartEnabled)) {
|
|
|
|
// this is a performance optimization - array index is cheaper then invoking a method with 'switch'
|
|
|
|
const char *pinName = name;
|
|
|
|
|
|
|
|
addEngineSniffferEvent(pinName, WC_DOWN);
|
|
|
|
}
|
|
|
|
#endif /* EFI_ENGINE_SNIFFER */
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:14:37 -07:00
|
|
|
InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() {
|
|
|
|
reset();
|
|
|
|
injectorIndex = -1;
|
|
|
|
}
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
bool NamedOutputPin::stop() {
|
2017-04-21 13:36:50 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
2016-11-03 20:02:58 -07:00
|
|
|
if (isInitialized() && getLogicValue()) {
|
|
|
|
setValue(false);
|
|
|
|
scheduleMsg(&sharedLogger, "turning off %s", name);
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-21 13:36:50 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2016-11-03 20:02:58 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-03 21:03:27 -07:00
|
|
|
void InjectorOutputPin::reset() {
|
|
|
|
overlappingScheduleOffTime = 0;
|
|
|
|
cancelNextTurningInjectorOff = false;
|
2016-09-22 06:03:20 -07:00
|
|
|
overlappingCounter = 0;
|
2016-09-04 22:03:25 -07:00
|
|
|
// todo: this could be refactored by calling some super-reset method
|
|
|
|
currentLogicValue = INITIAL_PIN_STATE;
|
2016-09-03 21:03:27 -07:00
|
|
|
}
|
|
|
|
|
2016-10-31 19:02:12 -07:00
|
|
|
IgnitionOutputPin::IgnitionOutputPin() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IgnitionOutputPin::reset() {
|
2016-11-01 20:01:54 -07:00
|
|
|
outOfOrder = false;
|
|
|
|
signalFallSparkId = 0;
|
2016-10-31 19:02:12 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
OutputPin::OutputPin() {
|
2017-04-21 15:11:36 -07:00
|
|
|
modePtr = &DEFAULT_OUTPUT;
|
2017-04-21 12:14:37 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
2015-07-10 06:01:56 -07:00
|
|
|
port = NULL;
|
|
|
|
pin = 0;
|
2017-04-21 12:14:37 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2016-07-23 16:03:19 -07:00
|
|
|
currentLogicValue = INITIAL_PIN_STATE;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-01-11 14:01:33 -08:00
|
|
|
bool OutputPin::isInitialized() {
|
2017-04-21 12:14:37 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
2015-07-10 06:01:56 -07:00
|
|
|
return port != NULL;
|
2017-04-21 12:14:37 -07:00
|
|
|
#else /* EFI_GPIO_HARDWARE */
|
2017-07-10 18:43:03 -07:00
|
|
|
return true;
|
2017-04-21 12:14:37 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OutputPin::setValue(int logicValue) {
|
2017-04-21 13:52:02 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
if (port != GPIO_NULL) {
|
|
|
|
efiAssertVoid(modePtr!=NULL, "pin mode not initialized");
|
|
|
|
pin_output_mode_e mode = *modePtr;
|
|
|
|
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e");
|
|
|
|
int eValue = getElectricalValue(logicValue, mode);
|
|
|
|
setPinValue(this, eValue, logicValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* EFI_PROD_CODE */
|
|
|
|
setPinValue(this, eValue, logicValue);
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-01-11 14:01:33 -08:00
|
|
|
bool OutputPin::getLogicValue() {
|
2015-07-10 06:01:56 -07:00
|
|
|
return currentLogicValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) {
|
|
|
|
pin_output_mode_e mode = *outputMode;
|
|
|
|
assertOMode(mode);
|
|
|
|
this->modePtr = outputMode;
|
|
|
|
setValue(false); // initial state
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:14:37 -07:00
|
|
|
void initOutputPins(void) {
|
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
|
|
|
/**
|
|
|
|
* want to make sure it's all zeros so that we can compare in initOutputPinExt() method
|
|
|
|
*/
|
|
|
|
// todo: it's too late to clear now? this breaks default status LEDs
|
|
|
|
// todo: fix this?
|
|
|
|
// memset(&outputs, 0, sizeof(outputs));
|
|
|
|
|
|
|
|
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
2017-04-21 15:11:36 -07:00
|
|
|
enginePins.sdCsPin.initPin("spi CS5", boardConfiguration->sdCardCsPin);
|
2017-04-21 12:14:37 -07:00
|
|
|
#endif /* HAL_USE_SPI */
|
|
|
|
|
|
|
|
// todo: should we move this code closer to the fuel pump logic?
|
2017-06-18 22:57:04 -07:00
|
|
|
enginePins.fuelPumpRelay.initPin("fuel pump relay", boardConfiguration->fuelPumpPin, &boardConfiguration->fuelPumpPinMode);
|
2017-04-21 12:14:37 -07:00
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
enginePins.mainRelay.initPin("main relay", boardConfiguration->mainRelayPin, &boardConfiguration->mainRelayPinMode);
|
2017-04-21 12:14:37 -07:00
|
|
|
|
2017-06-18 21:53:18 -07:00
|
|
|
enginePins.fanRelay.initPin("fan relay", boardConfiguration->fanPin, &boardConfiguration->fanPinMode);
|
2017-04-21 15:11:36 -07:00
|
|
|
enginePins.o2heater.initPin("o2 heater", boardConfiguration->o2heaterPin);
|
|
|
|
enginePins.acRelay.initPin("A/C relay", boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode);
|
2017-04-21 12:14:37 -07:00
|
|
|
|
|
|
|
// digit 1
|
|
|
|
/*
|
|
|
|
ledRegister(LED_HUGE_0, GPIOB, 2);
|
|
|
|
ledRegister(LED_HUGE_1, GPIOE, 7);
|
|
|
|
ledRegister(LED_HUGE_2, GPIOE, 8);
|
|
|
|
ledRegister(LED_HUGE_3, GPIOE, 9);
|
|
|
|
ledRegister(LED_HUGE_4, GPIOE, 10);
|
|
|
|
ledRegister(LED_HUGE_5, GPIOE, 11);
|
|
|
|
ledRegister(LED_HUGE_6, GPIOE, 12);
|
|
|
|
|
|
|
|
// digit 2
|
|
|
|
ledRegister(LED_HUGE_7, GPIOE, 13);
|
|
|
|
ledRegister(LED_HUGE_8, GPIOE, 14);
|
|
|
|
ledRegister(LED_HUGE_9, GPIOE, 15);
|
|
|
|
ledRegister(LED_HUGE_10, GPIOB, 10);
|
|
|
|
ledRegister(LED_HUGE_11, GPIOB, 11);
|
|
|
|
ledRegister(LED_HUGE_12, GPIOB, 12);
|
|
|
|
ledRegister(LED_HUGE_13, GPIOB, 13);
|
|
|
|
|
|
|
|
// digit 3
|
|
|
|
ledRegister(LED_HUGE_14, GPIOE, 0);
|
|
|
|
ledRegister(LED_HUGE_15, GPIOE, 2);
|
|
|
|
ledRegister(LED_HUGE_16, GPIOE, 4);
|
|
|
|
ledRegister(LED_HUGE_17, GPIOE, 6);
|
|
|
|
ledRegister(LED_HUGE_18, GPIOE, 5);
|
|
|
|
ledRegister(LED_HUGE_19, GPIOE, 3);
|
|
|
|
ledRegister(LED_HUGE_20, GPIOE, 1);
|
|
|
|
*/
|
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
|
|
|
}
|
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
void OutputPin::initPin(const char *msg, brain_pin_e brainPin) {
|
|
|
|
initPin(msg, brainPin, &DEFAULT_OUTPUT);
|
2017-04-21 14:50:28 -07:00
|
|
|
}
|
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
void OutputPin::initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
|
2017-04-21 14:38:13 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
2017-04-21 14:14:14 -07:00
|
|
|
if (brainPin == GPIO_UNASSIGNED)
|
|
|
|
return;
|
2017-07-28 11:27:37 -07:00
|
|
|
ioportid_t port = getHwPort(msg, brainPin);
|
|
|
|
int pin = getHwPin(msg, brainPin);
|
2017-04-21 14:14:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used for digital GPIO pins only, for peripheral pins see mySetPadMode
|
|
|
|
*/
|
2017-04-21 12:14:37 -07:00
|
|
|
if (port == GPIO_NULL) {
|
|
|
|
// that's for GRIO_NONE
|
2017-04-21 15:11:36 -07:00
|
|
|
this->port = port;
|
2017-04-21 12:14:37 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertOMode(*outputMode);
|
|
|
|
iomode_t mode = (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) ?
|
2017-04-21 14:14:14 -07:00
|
|
|
PAL_MODE_OUTPUT_PUSHPULL : PAL_MODE_OUTPUT_OPENDRAIN;
|
2017-04-21 12:14:37 -07:00
|
|
|
|
2017-04-21 14:26:50 -07:00
|
|
|
/**
|
|
|
|
* @brief Initialize the hardware output pin while also assigning it a logical name
|
|
|
|
*/
|
2017-04-21 15:11:36 -07:00
|
|
|
if (this->port != NULL && (this->port != port || this->pin != pin)) {
|
2017-04-21 14:26:50 -07:00
|
|
|
/**
|
|
|
|
* here we check if another physical pin is already assigned to this logical output
|
|
|
|
*/
|
|
|
|
// todo: need to clear '&outputs' in io_pins.c
|
2017-04-21 15:11:36 -07:00
|
|
|
warning(CUSTOM_OBD_PIN_CONFLICT, "outputPin [%s] already assigned to %x%d", msg, this->port, this->pin);
|
2017-04-21 14:26:50 -07:00
|
|
|
engine->withError = true;
|
|
|
|
return;
|
|
|
|
}
|
2017-04-21 15:11:36 -07:00
|
|
|
this->currentLogicValue = INITIAL_PIN_STATE;
|
|
|
|
this->port = port;
|
|
|
|
this->pin = pin;
|
2017-04-21 14:26:50 -07:00
|
|
|
|
2017-05-15 05:40:54 -07:00
|
|
|
efiSetPadMode(msg, brainPin, mode);
|
2017-04-21 12:14:37 -07:00
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
setDefaultPinState(outputMode);
|
2017-04-21 14:38:13 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
|
|
|
}
|
|
|
|
|
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
void initPrimaryPins(void) {
|
2017-04-21 15:11:36 -07:00
|
|
|
enginePins.errorLedPin.initPin("led: ERROR status", LED_ERROR_BRAIN_PIN);
|
2017-04-21 12:14:37 -07:00
|
|
|
}
|
|
|
|
|
2017-04-21 12:28:47 -07:00
|
|
|
/**
|
|
|
|
* This method is part of fatal error handling.
|
|
|
|
* Please note that worst case scenario the pins might get re-enabled by some other code :(
|
|
|
|
* The whole method is pretty naive, but that's at least something.
|
|
|
|
*/
|
|
|
|
void turnAllPinsOff(void) {
|
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT; i++) {
|
|
|
|
enginePins.injectors[i].setValue(false);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < IGNITION_PIN_COUNT; i++) {
|
|
|
|
enginePins.coils[i].setValue(false);
|
|
|
|
}
|
|
|
|
}
|
2017-04-21 13:33:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated - use hwPortname() instead
|
|
|
|
*/
|
|
|
|
const char *portname(ioportid_t GPIOx) {
|
|
|
|
if (GPIOx == GPIOA)
|
|
|
|
return "PA";
|
|
|
|
if (GPIOx == GPIOB)
|
|
|
|
return "PB";
|
|
|
|
if (GPIOx == GPIOC)
|
|
|
|
return "PC";
|
|
|
|
if (GPIOx == GPIOD)
|
|
|
|
return "PD";
|
|
|
|
#if defined(STM32F4XX)
|
|
|
|
if (GPIOx == GPIOE)
|
|
|
|
return "PE";
|
|
|
|
if (GPIOx == GPIOH)
|
|
|
|
return "PH";
|
|
|
|
#endif
|
|
|
|
if (GPIOx == GPIOF)
|
|
|
|
return "PF";
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2017-04-21 13:20:06 -07:00
|
|
|
#else /* EFI_GPIO_HARDWARE */
|
|
|
|
const char *hwPortname(brain_pin_e brainPin) {
|
|
|
|
(void)brainPin;
|
|
|
|
return "N/A";
|
|
|
|
}
|
2017-04-21 12:14:37 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2017-04-21 13:33:51 -07:00
|
|
|
|
|
|
|
|