diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index ddfd173f73..cb966387e0 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -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) { diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index f0932226c1..dde9de6e3d 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -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 diff --git a/firmware/hw_layer/io_pins.h b/firmware/hw_layer/io_pins.h index 3594da0f12..533d5be6af 100644 --- a/firmware/hw_layer/io_pins.h +++ b/firmware/hw_layer/io_pins.h @@ -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