Skip to content

Commit 45717cd

Browse files
maciejbaczmanskirlubos
authored andcommitted
[nrf fromtree] gpio: add gpio_pin_is_input_dt and gpio_pin_is_output_dt helpers
Add helpers to allow providing a `struct gpio_dt_spec` directly to `gpio_pin_is_input` and `gpio_pin_is_output` functions. Signed-off-by: Maciej Baczmanski <[email protected]> (cherry picked from commit a2e449b)
1 parent 765155f commit 45717cd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/zephyr/drivers/gpio.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ static inline int gpio_pin_is_input(const struct device *port, gpio_pin_t pin)
815815
return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
816816
}
817817

818+
/**
819+
* @brief Check if a single pin from @p gpio_dt_spec is configured for input
820+
*
821+
* This is equivalent to:
822+
*
823+
* gpio_pin_is_input(spec->port, spec->pin);
824+
*
825+
* @param spec GPIO specification from devicetree.
826+
*
827+
* @return A value from gpio_pin_is_input().
828+
*/
829+
static inline int gpio_pin_is_input_dt(const struct gpio_dt_spec *spec)
830+
{
831+
return gpio_pin_is_input(spec->port, spec->pin);
832+
}
833+
818834
/**
819835
* @brief Check if @p pin is configured for output
820836
*
@@ -844,6 +860,22 @@ static inline int gpio_pin_is_output(const struct device *port, gpio_pin_t pin)
844860
return (int)!!((gpio_port_pins_t)BIT(pin) & pins);
845861
}
846862

863+
/**
864+
* @brief Check if a single pin from @p gpio_dt_spec is configured for output
865+
*
866+
* This is equivalent to:
867+
*
868+
* gpio_pin_is_output(spec->port, spec->pin);
869+
*
870+
* @param spec GPIO specification from devicetree.
871+
*
872+
* @return A value from gpio_pin_is_output().
873+
*/
874+
static inline int gpio_pin_is_output_dt(const struct gpio_dt_spec *spec)
875+
{
876+
return gpio_pin_is_output(spec->port, spec->pin);
877+
}
878+
847879
/**
848880
* @brief Get a configuration of a single pin.
849881
*

0 commit comments

Comments
 (0)