gpio: add additional gpio_spec_dt helpers

Add helpers to allow providing a `struct gpio_spec_dt` directly to
`gpio_pin_get`, `gpio_pin_set` and `gpio_pin_toggle` functions.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2021-06-23 20:47:18 +10:00 committed by Kumar Gala
commit 7ea37c9bb7

View file

@ -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.