Skip to content

Commit a88b1b8

Browse files
mwerner96jhedberg
authored andcommitted
include: drivers: gpio_emul: add gpio_dt_spec helpers
Add gpio_dt_spec based helpers for easier access to: * gpio_emul_input_set * gpio_emul_output_get * gpio_emul_flags_get Signed-off-by: Maximilian Werner <[email protected]>
1 parent cbcf81e commit a88b1b8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

include/zephyr/drivers/gpio/gpio_emul.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ static inline int gpio_emul_input_set(const struct device *port, gpio_pin_t pin,
7373
return gpio_emul_input_set_masked(port, BIT(pin), value ? BIT(pin) : 0);
7474
}
7575

76+
/**
77+
* @brief Modify the value of one emulated GPIO input pin from a @p gpio_dt_spec
78+
*
79+
* This is equivalent to:
80+
*
81+
* gpio_emul_input_set(spec->port, spec->pin, value);
82+
*
83+
* @param spec The emulated GPIO specification from devicetree
84+
* @param value New values to assign to the pin
85+
*
86+
* @return a value from gpio_emul_input_set()
87+
*/
88+
static inline int gpio_emul_input_set_dt(const struct gpio_dt_spec *spec, int value)
89+
{
90+
return gpio_emul_input_set(spec->port, spec->pin, value);
91+
}
92+
7693
/**
7794
* @brief Read the value of one or more emulated GPIO output @p pins
7895
*
@@ -108,6 +125,22 @@ static inline int gpio_emul_output_get(const struct device *port, gpio_pin_t pin
108125
return ret;
109126
}
110127

128+
/**
129+
* @brief Read the value of one emulated GPIO output pin from a @p gpio_dt_spec
130+
*
131+
* This is equivalent to:
132+
*
133+
* gpio_emul_output_get(spec->port, spec->pin);
134+
*
135+
* @param spec The emulated GPIO specification from devicetree
136+
*
137+
* @return a value from gpio_emul_output_get()
138+
*/
139+
static inline int gpio_emul_output_get_dt(const struct gpio_dt_spec *spec)
140+
{
141+
return gpio_emul_output_get(spec->port, spec->pin);
142+
}
143+
111144
/**
112145
* @brief Get @p flags for a given emulated GPIO @p pin
113146
*
@@ -122,6 +155,25 @@ static inline int gpio_emul_output_get(const struct device *port, gpio_pin_t pin
122155
*/
123156
int gpio_emul_flags_get(const struct device *port, gpio_pin_t pin, gpio_flags_t *flags);
124157

158+
/**
159+
* @brief Get @p flags for a given emulated GPIO pin from a @p gpio_dt_spec
160+
*
161+
* This is equivalent to:
162+
*
163+
* gpio_emul_flags_get(spec->port, spec->pin, flags);
164+
*
165+
* For more information on available flags, see @ref gpio_interface.
166+
*
167+
* @param spec The emulated GPIO specification from devicetree
168+
* @param flags a pointer to where the flags for the pin will be stored
169+
*
170+
* @return a value from gpio_emul_flags_get()
171+
*/
172+
static inline int gpio_emul_flags_get_dt(const struct gpio_dt_spec *spec, gpio_flags_t *flags)
173+
{
174+
return gpio_emul_flags_get(spec->port, spec->pin, flags);
175+
}
176+
125177
/**
126178
* @}
127179
*/

0 commit comments

Comments
 (0)