rusefi/firmware/controllers/system/efiGpio.cpp

139 lines
2.9 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file efiGpio.cpp
*
* @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 09:42:38 -07:00
#if EFI_GPIO || defined(__DOXYGEN__)
2015-07-10 06:01:56 -07:00
#include "efiGpio.h"
#include "io_pins.h"
pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT;
// todo: clean this mess, this should become 'static'/private
2016-11-03 20:02:58 -07:00
EnginePins enginePins;
extern LoggingWithStorage sharedLogger;
2015-07-10 06:01:56 -07:00
NamedOutputPin::NamedOutputPin() : OutputPin() {
name = NULL;
}
NamedOutputPin::NamedOutputPin(const char *name) : OutputPin() {
this->name = name;
}
2016-09-03 21:03:27 -07:00
InjectorOutputPin::InjectorOutputPin() : NamedOutputPin() {
reset();
2016-11-30 15:02:19 -08:00
injectorIndex = -1;
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
}
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;
}
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();
}
}
2016-11-03 20:02:58 -07:00
bool NamedOutputPin::stop() {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
if (isInitialized() && getLogicValue()) {
setValue(false);
scheduleMsg(&sharedLogger, "turning off %s", name);
return true;
}
#endif
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() {
modePtr = &OUTPUT_MODE_DEFAULT;
#if EFI_PROD_CODE || defined(__DOXYGEN__)
port = NULL;
pin = 0;
#endif
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() {
2015-07-10 06:01:56 -07:00
#if EFI_PROD_CODE || defined(__DOXYGEN__)
return port != NULL;
#else
return false;
#endif
}
void OutputPin::setValue(int logicValue) {
doSetOutputPinValue2(this, logicValue);
}
2016-01-11 14:01:33 -08:00
bool OutputPin::getLogicValue() {
2015-07-10 06:01:56 -07:00
return currentLogicValue;
}
void OutputPin::unregister() {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
port = NULL;
#endif
}
void OutputPin::setDefaultPinState(pin_output_mode_e *outputMode) {
pin_output_mode_e mode = *outputMode;
assertOMode(mode);
this->modePtr = outputMode;
setValue(false); // initial state
}
#endif /* EFI_GPIO */