diff --git a/include/drivers/gpio.h b/include/drivers/gpio.h index 021a4e5e018..25899f9a85d 100644 --- a/include/drivers/gpio.h +++ b/include/drivers/gpio.h @@ -1115,6 +1115,21 @@ static inline int gpio_pin_get(const struct device *port, gpio_pin_t pin) return ret; } +/** + * @brief Get logical level of an input pin from a @p gpio_dt_spec. + * + * This is equivalent to: + * + * gpio_pin_get(spec->port, spec->pin); + * + * @param spec GPIO specification from devicetree + * @retval a value from gpio_pin_get() + */ +static inline int gpio_pin_get_dt(const struct gpio_dt_spec *spec) +{ + return gpio_pin_get(spec->port, spec->pin); +} + /** * @brief Set physical level of an output pin. * @@ -1190,6 +1205,22 @@ static inline int gpio_pin_set(const struct device *port, gpio_pin_t pin, return gpio_pin_set_raw(port, pin, value); } +/** + * @brief Set logical level of a output pin from a @p gpio_dt_spec. + * + * This is equivalent to: + * + * gpio_pin_set(spec->port, spec->pin, value); + * + * @param spec GPIO specification from devicetree + * @param value Value assigned to the pin. + * @retval a value from gpio_pin_set() + */ +static inline int gpio_pin_set_dt(const struct gpio_dt_spec *spec, int value) +{ + return gpio_pin_set(spec->port, spec->pin, value); +} + /** * @brief Toggle pin level. * @@ -1212,6 +1243,21 @@ static inline int gpio_pin_toggle(const struct device *port, gpio_pin_t pin) return gpio_port_toggle_bits(port, (gpio_port_pins_t)BIT(pin)); } +/** + * @brief Toggle pin level from a @p gpio_dt_spec. + * + * This is equivalent to: + * + * gpio_pin_toggle(spec->port, spec->pin); + * + * @param spec GPIO specification from devicetree + * @retval a value from gpio_pin_toggle() + */ +static inline int gpio_pin_toggle_dt(const struct gpio_dt_spec *spec) +{ + return gpio_pin_toggle(spec->port, spec->pin); +} + /** * @brief Helper to initialize a struct gpio_callback properly * @param callback A valid Application's callback structure pointer.