diff --git a/esphome/components/esp32/gpio.h b/esphome/components/esp32/gpio.h index 23b723e0b4..d69ac1c493 100644 --- a/esphome/components/esp32/gpio.h +++ b/esphome/components/esp32/gpio.h @@ -13,6 +13,7 @@ class ESP32InternalGPIOPin : public InternalGPIOPin { void set_inverted(bool inverted) { inverted_ = inverted; } void set_drive_strength(gpio_drive_cap_t drive_strength) { drive_strength_ = drive_strength; } void set_flags(gpio::Flags flags) { flags_ = flags; } + void setup() override; void pin_mode(gpio::Flags flags) override; bool digital_read() override; @@ -21,6 +22,7 @@ class ESP32InternalGPIOPin : public InternalGPIOPin { void detach_interrupt() const override; ISRInternalGPIOPin to_isr() const override; uint8_t get_pin() const override { return (uint8_t) pin_; } + gpio::Flags get_flags() const override { return flags_; } bool is_inverted() const override { return inverted_; } protected: diff --git a/esphome/components/esp8266/gpio.h b/esphome/components/esp8266/gpio.h index 0474d0baa6..dd6407885e 100644 --- a/esphome/components/esp8266/gpio.h +++ b/esphome/components/esp8266/gpio.h @@ -22,6 +22,7 @@ class ESP8266GPIOPin : public InternalGPIOPin { void detach_interrupt() const override; ISRInternalGPIOPin to_isr() const override; uint8_t get_pin() const override { return pin_; } + gpio::Flags get_flags() const override { return flags_; } bool is_inverted() const override { return inverted_; } protected: diff --git a/esphome/components/host/gpio.h b/esphome/components/host/gpio.h index c0920467d6..a60d535912 100644 --- a/esphome/components/host/gpio.h +++ b/esphome/components/host/gpio.h @@ -21,6 +21,7 @@ class HostGPIOPin : public InternalGPIOPin { void detach_interrupt() const override; ISRInternalGPIOPin to_isr() const override; uint8_t get_pin() const override { return pin_; } + gpio::Flags get_flags() const override { return flags_; } bool is_inverted() const override { return inverted_; } protected: diff --git a/esphome/components/libretiny/gpio_arduino.h b/esphome/components/libretiny/gpio_arduino.h index a43ed28c5e..9adc425a41 100644 --- a/esphome/components/libretiny/gpio_arduino.h +++ b/esphome/components/libretiny/gpio_arduino.h @@ -20,6 +20,7 @@ class ArduinoInternalGPIOPin : public InternalGPIOPin { void detach_interrupt() const override; ISRInternalGPIOPin to_isr() const override; uint8_t get_pin() const override { return pin_; } + gpio::Flags get_flags() const override { return flags_; } bool is_inverted() const override { return inverted_; } protected: diff --git a/esphome/components/rp2040/gpio.h b/esphome/components/rp2040/gpio.h index ef9500d5dd..9bc66d9e4b 100644 --- a/esphome/components/rp2040/gpio.h +++ b/esphome/components/rp2040/gpio.h @@ -22,6 +22,7 @@ class RP2040GPIOPin : public InternalGPIOPin { void detach_interrupt() const override; ISRInternalGPIOPin to_isr() const override; uint8_t get_pin() const override { return pin_; } + gpio::Flags get_flags() const override { return flags_; } bool is_inverted() const override { return inverted_; } protected: diff --git a/esphome/core/gpio.h b/esphome/core/gpio.h index 1b6f2ba1e6..19d57a0af8 100644 --- a/esphome/core/gpio.h +++ b/esphome/core/gpio.h @@ -53,6 +53,16 @@ class GPIOPin { virtual void pin_mode(gpio::Flags flags) = 0; + /** + * @brief Retrieve GPIO pin flags. + * + * @note This is currently optional to limit changes but will be mandatory in a future update. + * It is primarily applied to internal pins for now. + * + * @return The GPIO flags describing the pin mode and properties. Returns `gpio::Flags::FLAG_NONE` if not overridden. + */ + virtual gpio::Flags get_flags() const { return gpio::Flags::FLAG_NONE; } + virtual bool digital_read() = 0; virtual void digital_write(bool value) = 0;