refactoring - reducing GPIO complexity
This commit is contained in:
parent
ac16341b2b
commit
6938538fac
|
@ -549,15 +549,14 @@ static OutputPin *leds[] = { &enginePins.warningPin, &enginePins.runningPin, &en
|
||||||
extern pin_output_mode_e DEFAULT_OUTPUT;
|
extern pin_output_mode_e DEFAULT_OUTPUT;
|
||||||
|
|
||||||
static void initStatusLeds(void) {
|
static void initStatusLeds(void) {
|
||||||
outputPinRegisterExt2("led: comm status", &enginePins.communicationPin,
|
enginePins.communicationPin.initPin("led: comm status", engineConfiguration->communicationPin, &DEFAULT_OUTPUT);
|
||||||
engineConfiguration->communicationPin, &DEFAULT_OUTPUT);
|
|
||||||
// we initialize this here so that we can blink it on start-up
|
// we initialize this here so that we can blink it on start-up
|
||||||
outputPinRegisterExt2("MalfunctionIndicator", &enginePins.checkEnginePin, boardConfiguration->malfunctionIndicatorPin, &DEFAULT_OUTPUT);
|
enginePins.checkEnginePin.initPin("MalfunctionIndicator", boardConfiguration->malfunctionIndicatorPin, &DEFAULT_OUTPUT);
|
||||||
|
|
||||||
|
|
||||||
#if EFI_WARNING_LED || defined(__DOXYGEN__)
|
#if EFI_WARNING_LED || defined(__DOXYGEN__)
|
||||||
outputPinRegisterExt2("led: warning status", &enginePins.warningPin, LED_WARNING_BRAIN_PIN, &DEFAULT_OUTPUT);
|
enginePins.warningPin.initPin("led: warning status", LED_WARNING_BRAIN_PIN, &DEFAULT_OUTPUT);
|
||||||
outputPinRegisterExt2("led: running status", &enginePins.runningPin, engineConfiguration->runningPin,
|
enginePins.runningPin.initPin("led: running status", engineConfiguration->runningPin, &DEFAULT_OUTPUT);
|
||||||
&DEFAULT_OUTPUT);
|
|
||||||
#endif /* EFI_WARNING_LED */
|
#endif /* EFI_WARNING_LED */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,10 @@ void initOutputPins(void) {
|
||||||
#endif /* EFI_GPIO_HARDWARE */
|
#endif /* EFI_GPIO_HARDWARE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutputPin::initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
|
||||||
|
outputPinRegisterExt2(msg, this, brainPin, outputMode);
|
||||||
|
}
|
||||||
|
|
||||||
void outputPinRegisterExt2(const char *msg, OutputPin *outputPin, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
|
void outputPinRegisterExt2(const char *msg, OutputPin *outputPin, brain_pin_e brainPin, pin_output_mode_e *outputMode) {
|
||||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||||
if (brainPin == GPIO_UNASSIGNED)
|
if (brainPin == GPIO_UNASSIGNED)
|
||||||
|
|
|
@ -33,6 +33,8 @@ public:
|
||||||
bool getLogicValue();
|
bool getLogicValue();
|
||||||
void unregister();
|
void unregister();
|
||||||
bool isPinAssigned();
|
bool isPinAssigned();
|
||||||
|
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e *outputMode);
|
||||||
|
|
||||||
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
||||||
ioportid_t port;
|
ioportid_t port;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
@ -123,14 +125,12 @@ public:
|
||||||
|
|
||||||
#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
|
#define getElectricalValue0(mode) ((mode) == OM_INVERTED || (mode) == OM_OPENDRAIN_INVERTED)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* it's a macro to be sure that stack is not used
|
* it's a macro to be sure that stack is not used
|
||||||
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
|
* @return 1 for OM_DEFAULT and OM_OPENDRAIN
|
||||||
*/
|
*/
|
||||||
#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
|
#define getElectricalValue1(mode) ((mode) == OM_DEFAULT || (mode) == OM_OPENDRAIN)
|
||||||
|
|
||||||
|
|
||||||
#define getElectricalValue(logicalValue, mode) \
|
#define getElectricalValue(logicalValue, mode) \
|
||||||
(logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
|
(logicalValue ? getElectricalValue1(mode) : getElectricalValue0(mode))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue