rusefi/firmware/controllers/system/efiGpio.h

155 lines
5.0 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file efiGpio.h
*
* @date Sep 26, 2014
2015-12-31 13:02:30 -08:00
* @author Andrey Belomutskiy, (c) 2012-2016
2015-07-10 06:01:56 -07:00
*/
#ifndef EFIGPIO_H_
#define EFIGPIO_H_
#include "main.h"
#include "io_pins.h"
2016-07-23 16:03:19 -07:00
#define INITIAL_PIN_STATE -1
2015-07-10 06:01:56 -07:00
// mode >= 0 is always true since that's an unsigned
#define assertOMode(mode) { \
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \
}
/**
* @brief Single output pin reference and state
*/
class OutputPin {
public:
OutputPin();
2016-01-11 14:01:33 -08:00
bool isInitialized();
2015-07-10 06:01:56 -07:00
void setValue(int logicValue);
void setDefaultPinState(pin_output_mode_e *defaultState);
2016-01-11 14:01:33 -08:00
bool getLogicValue();
2015-07-10 06:01:56 -07:00
void unregister();
#if EFI_PROD_CODE || defined(__DOXYGEN__)
2016-01-11 20:01:35 -08:00
ioportid_t port;
2015-07-10 06:01:56 -07:00
int pin;
#endif /* EFI_PROD_CODE */
pin_output_mode_e *modePtr;
/**
* we track current pin status so that we do not touch the actual hardware if we want to write new pin bit
* which is same as current pin value. This maybe helps in case of status leds, but maybe it's a total over-engineering
*/
int currentLogicValue;
};
class NamedOutputPin : public OutputPin {
public:
NamedOutputPin();
NamedOutputPin(const char *name);
const char *name;
};
2016-09-03 21:03:27 -07:00
class InjectorOutputPin : public NamedOutputPin {
public:
InjectorOutputPin();
void reset();
efitimeus_t overlappingScheduleOffTime;
bool cancelNextTurningInjectorOff;
};
2016-09-06 21:02:11 -07:00
class engine_pins_s {
public:
engine_pins_s();
2015-07-10 06:01:56 -07:00
OutputPin mainRelay;
OutputPin fanRelay;
OutputPin acRelay;
OutputPin fuelPumpRelay;
OutputPin o2heater;
// OutputPin alternatorField;
OutputPin errorLedPin;
2016-09-13 21:03:14 -07:00
OutputPin idleSolenoidPin;
OutputPin alternatorPin;
2016-09-13 22:01:57 -07:00
OutputPin checkEnginePin;
NamedOutputPin tachOut;
2016-09-13 21:03:14 -07:00
2015-07-10 06:01:56 -07:00
2016-09-03 21:03:27 -07:00
InjectorOutputPin injectors[INJECTION_PIN_COUNT];
2015-07-10 06:01:56 -07:00
NamedOutputPin 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)
#else
#define isPinAssigned(output) (true)
#endif
#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); \
} \
}
#else
#define doSetOutputPinValue2(output, logicValue) { \
pin_output_mode_e mode = OM_DEFAULT; \
int eValue = getElectricalValue(logicValue, mode); \
setPinValue(output, eValue, logicValue); \
}
#endif
void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode);
2016-09-12 17:02:56 -07:00
void seTurnPinHigh(InjectorOutputPin *output);
2016-09-03 22:01:54 -07:00
void seTurnPinLow(InjectorOutputPin *output);
2015-07-10 06:01:56 -07:00
void turnPinHigh(NamedOutputPin *output);
void turnPinLow(NamedOutputPin *output);
2016-07-23 19:02:52 -07:00
void turnSparkPinHigh(NamedOutputPin *output);
void turnSparkPinLow(NamedOutputPin *output);
2015-07-10 06:01:56 -07:00
#endif /* EFIGPIO_H_ */