fix gpio the right way (#1990)

* fix the right way

* use the api

* explain

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-11-26 21:24:41 -08:00 committed by GitHub
parent 0840b91f7f
commit a3a49b02ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -395,7 +395,7 @@ void OutputPin::toggle() {
}
bool OutputPin::getAndSet(int logicValue) {
bool oldValue = currentLogicValue;
bool oldValue = getLogicValue();
setValue(logicValue);
return oldValue;
}
@ -442,7 +442,8 @@ void OutputPin::setValue(int logicValue) {
}
bool OutputPin::getLogicValue() const {
return currentLogicValue;
// Compare against 1 since it could also be INITIAL_PIN_STATE (which means 0, but we haven't initialized the pin yet)
return currentLogicValue == 1;
}
void OutputPin::setDefaultPinState(const pin_output_mode_e *outputMode) {

View File

@ -74,7 +74,7 @@ public:
brain_pin_e brainPin;
#endif /* EFI_GPIO_HARDWARE */
int8_t currentLogicValue = 0;
int8_t currentLogicValue = INITIAL_PIN_STATE;
/**
* 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

View File

@ -10,6 +10,7 @@
#include "global.h"
#define INITIAL_PIN_STATE -1
#define GPIO_NULL NULL
// mode >= 0 is always true since that's an unsigned