From 48144a49b411af6c8d56e5eccae70cc9b3a8074b Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Tue, 11 Feb 2025 14:31:22 +0300 Subject: [PATCH] io_pins: efiReadPin() variant with pin_input_mode_e argument Will invert state in case of inverted mode. --- firmware/hw_layer/io_pins.cpp | 12 ++++++++++++ firmware/hw_layer/io_pins.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index accf7a6bab..50819d2c15 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -134,3 +134,15 @@ void setMockState(brain_pin_e pin, bool state) { } #endif /* EFI_PROD_CODE */ + +bool efiIsInputPinInverted(pin_input_mode_e mode) +{ + return ((mode == PI_INVERTED_DEFAULT) || + (mode == PI_INVERTED_PULLUP) || + (mode == PI_INVERTED_PULLDOWN)); +} + +bool efiReadPin(brain_pin_e pin, pin_input_mode_e mode) +{ + return efiReadPin(pin) ^ efiIsInputPinInverted(mode); +} diff --git a/firmware/hw_layer/io_pins.h b/firmware/hw_layer/io_pins.h index 4f91a06f10..f73d63d0ae 100644 --- a/firmware/hw_layer/io_pins.h +++ b/firmware/hw_layer/io_pins.h @@ -33,6 +33,8 @@ void efiSetPadUnused(brain_pin_e brainPin); #if EFI_GPIO_HARDWARE bool efiReadPin(brain_pin_e pin); +bool efiReadPin(brain_pin_e pin, pin_input_mode_e mode); +bool efiIsInputPinInverted(pin_input_mode_e mode); iomode_t getInputMode(pin_input_mode_e mode);