refactoring - reducing GPIO complexity
This commit is contained in:
parent
9666d81a38
commit
fcac9862b9
|
@ -41,6 +41,28 @@ EnginePins::EnginePins() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
|
||||
bool EnginePins::stopPins() {
|
||||
bool result = false;
|
||||
for (int i = 0; i < IGNITION_PIN_COUNT; i++) {
|
||||
|
@ -120,7 +142,18 @@ bool OutputPin::isInitialized() {
|
|||
}
|
||||
|
||||
void OutputPin::setValue(int logicValue) {
|
||||
doSetOutputPinValue2(this, logicValue);
|
||||
#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 */
|
||||
}
|
||||
|
||||
bool OutputPin::getLogicValue() {
|
||||
|
|
|
@ -32,10 +32,10 @@ public:
|
|||
void setDefaultPinState(pin_output_mode_e *defaultState);
|
||||
bool getLogicValue();
|
||||
void unregister();
|
||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||
ioportid_t port;
|
||||
uint8_t pin;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
||||
int8_t currentLogicValue;
|
||||
// 4 byte pointer is a bit of a memory waste here
|
||||
pin_output_mode_e *modePtr;
|
||||
|
@ -129,27 +129,6 @@ public:
|
|||
*/
|
||||
#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))
|
||||
|
@ -160,28 +139,6 @@ public:
|
|||
#define isPinAssigned(output) (true)
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
#define doSetOutputPinValue(pin, logicValue) doSetOutputPinValue2((&outputs[pin]), logicValue)
|
||||
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#define doSetOutputPinValue2(output, logicValue) { \
|
||||
if ((output)->port != GPIO_NULL) { \
|
||||
efiAssertVoid((output)->modePtr!=NULL, "pin mode not initialized"); \
|
||||
pin_output_mode_e mode = *(output)->modePtr; \
|
||||
efiAssertVoid(mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \
|
||||
int eValue = getElectricalValue(logicValue, mode); \
|
||||
setPinValue(output, eValue, logicValue); \
|
||||
} \
|
||||
}
|
||||
#else /* EFI_PROD_CODE */
|
||||
#define doSetOutputPinValue2(output, logicValue) { \
|
||||
pin_output_mode_e mode = OM_DEFAULT; \
|
||||
/* int eValue = getElectricalValue(logicValue, mode); */ \
|
||||
setPinValue(output, eValue, logicValue); \
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
|
||||
void turnPinHigh(NamedOutputPin *output);
|
||||
void turnPinLow(NamedOutputPin *output);
|
||||
|
||||
|
|
Loading…
Reference in New Issue