2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file efiGpio.h
|
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
|
|
|
*/
|
|
|
|
#ifndef EFIGPIO_H_
|
|
|
|
#define EFIGPIO_H_
|
|
|
|
|
|
|
|
#include "io_pins.h"
|
2017-04-21 10:36:51 -07:00
|
|
|
#include "main.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-04-21 10:36:51 -07:00
|
|
|
void initPrimaryPins(void);
|
|
|
|
void initOutputPins(void);
|
|
|
|
|
|
|
|
#if EFI_GPIO || defined(__DOXYGEN__)
|
|
|
|
void turnAllPinsOff(void);
|
|
|
|
#else /* EFI_GPIO */
|
|
|
|
#define turnAllPinsOff() {}
|
|
|
|
#endif /* EFI_GPIO */
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class NamedOutputPin : public OutputPin {
|
|
|
|
public:
|
|
|
|
NamedOutputPin();
|
|
|
|
NamedOutputPin(const char *name);
|
2016-11-03 20:02:58 -07:00
|
|
|
/**
|
|
|
|
* @return true if pin was stopped
|
|
|
|
*/
|
|
|
|
bool stop();
|
2017-01-06 08:02:49 -08:00
|
|
|
// todo: char pointer is a bit of a memory waste here, we can reduce RAM usage by software-based getName() method
|
2015-07-10 06:01:56 -07:00
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
2016-09-03 21:03:27 -07:00
|
|
|
class InjectorOutputPin : public NamedOutputPin {
|
|
|
|
public:
|
|
|
|
InjectorOutputPin();
|
|
|
|
void reset();
|
|
|
|
efitimeus_t overlappingScheduleOffTime;
|
2017-01-06 08:02:49 -08:00
|
|
|
// todo: implement this via address manipulation to reduce memory usage
|
|
|
|
int8_t injectorIndex;
|
2016-09-03 21:03:27 -07:00
|
|
|
bool cancelNextTurningInjectorOff;
|
2017-01-06 08:02:49 -08:00
|
|
|
int8_t overlappingCounter;
|
2016-09-03 21:03:27 -07:00
|
|
|
};
|
|
|
|
|
2016-10-31 19:02:12 -07:00
|
|
|
class IgnitionOutputPin : public NamedOutputPin {
|
|
|
|
public:
|
|
|
|
IgnitionOutputPin();
|
|
|
|
void reset();
|
2016-11-01 20:01:54 -07:00
|
|
|
int signalFallSparkId;
|
|
|
|
bool outOfOrder; // https://sourceforge.net/p/rusefi/tickets/319/
|
2016-10-31 19:02:12 -07:00
|
|
|
};
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
class EnginePins {
|
2016-09-06 21:02:11 -07:00
|
|
|
public:
|
2016-11-03 20:02:58 -07:00
|
|
|
EnginePins();
|
2016-11-01 06:02:29 -07:00
|
|
|
void reset();
|
2016-11-03 20:02:58 -07:00
|
|
|
bool stopPins();
|
2015-07-10 06:01:56 -07:00
|
|
|
OutputPin mainRelay;
|
|
|
|
OutputPin fanRelay;
|
|
|
|
OutputPin acRelay;
|
|
|
|
OutputPin fuelPumpRelay;
|
|
|
|
OutputPin o2heater;
|
|
|
|
// OutputPin alternatorField;
|
2017-01-30 03:02:53 -08:00
|
|
|
/**
|
|
|
|
* brain board RED LED by default
|
|
|
|
*/
|
2017-02-24 16:42:34 -08:00
|
|
|
OutputPin errorLedPin;
|
|
|
|
OutputPin communicationPin; // blue LED on brain board by default
|
|
|
|
OutputPin warningPin; // orange LED on brain board by default
|
|
|
|
OutputPin runningPin; // green LED on brain board by default
|
|
|
|
|
2016-09-13 21:03:14 -07:00
|
|
|
OutputPin idleSolenoidPin;
|
|
|
|
OutputPin alternatorPin;
|
2017-01-30 03:02:53 -08:00
|
|
|
/**
|
|
|
|
* this one is usually on the gauge cluster, not on the ECU
|
|
|
|
*/
|
2016-09-13 22:01:57 -07:00
|
|
|
OutputPin checkEnginePin;
|
|
|
|
NamedOutputPin tachOut;
|
2016-09-14 16:03:00 -07:00
|
|
|
OutputPin etbOutput1;
|
|
|
|
OutputPin etbOutput2;
|
|
|
|
OutputPin fsioOutputs[LE_COMMAND_COUNT];
|
|
|
|
OutputPin triggerDecoderErrorPin;
|
|
|
|
OutputPin hipCs;
|
|
|
|
OutputPin sdCsPin;
|
2016-09-13 21:03:14 -07:00
|
|
|
|
2016-09-03 21:03:27 -07:00
|
|
|
InjectorOutputPin injectors[INJECTION_PIN_COUNT];
|
2016-10-31 19:02:12 -07:00
|
|
|
IgnitionOutputPin coils[IGNITION_PIN_COUNT];
|
2016-09-06 21:02:11 -07:00
|
|
|
NamedOutputPin dizzyOutput;
|
|
|
|
};
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* it's a macro to be sure that stack is not used
|
|
|
|
* @return 0 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* it's a macro to be sure that stack is not used
|
|
|
|
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
|
|
|
|
*/
|
|
|
|
#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value of the pin. On this layer the value is assigned as is, without any conversion.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE \
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
#define getElectricalValue(logicalValue, mode) \
|
|
|
|
(logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#define isPinAssigned(output) ((output)->port != GPIO_NULL)
|
2017-04-21 09:31:17 -07:00
|
|
|
#else /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
#define isPinAssigned(output) (true)
|
2017-04-21 09:31:17 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#define doSetOutputPinValue(pin, logicValue) doSetOutputPinValue2((&outputs[pin]), logicValue)
|
|
|
|
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#define doSetOutputPinValue2(output, logicValue) { \
|
2016-04-26 17:02:05 -07:00
|
|
|
if ((output)->port != GPIO_NULL) { \
|
|
|
|
efiAssertVoid((output)->modePtr!=NULL, "pin mode not initialized"); \
|
|
|
|
pin_output_mode_e mode = *(output)->modePtr; \
|
2015-07-10 06:01:56 -07:00
|
|
|
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \
|
|
|
|
int eValue = getElectricalValue(logicValue, mode); \
|
|
|
|
setPinValue(output, eValue, logicValue); \
|
|
|
|
} \
|
|
|
|
}
|
2017-04-21 09:31:17 -07:00
|
|
|
#else /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
#define doSetOutputPinValue2(output, logicValue) { \
|
|
|
|
pin_output_mode_e mode = OM_DEFAULT; \
|
2017-04-21 09:42:38 -07:00
|
|
|
/* int eValue = getElectricalValue(logicValue, mode); */ \
|
2015-07-10 06:01:56 -07:00
|
|
|
setPinValue(output, eValue, logicValue); \
|
|
|
|
}
|
2017-04-21 09:31:17 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
void turnPinHigh(NamedOutputPin *output);
|
|
|
|
void turnPinLow(NamedOutputPin *output);
|
|
|
|
|
2017-04-21 09:31:17 -07:00
|
|
|
#if EFI_PROD_CODE
|
2017-04-21 09:06:32 -07:00
|
|
|
void initOutputPin(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber);
|
|
|
|
void initOutputPinExt(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber, iomode_t mode);
|
|
|
|
|
2017-04-21 09:31:17 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
2017-04-21 09:06:32 -07:00
|
|
|
void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* EFIGPIO_H_ */
|