Skip to content

Commit 06be6eb

Browse files
ajf58kartben
authored andcommitted
drivers: gpio_rpi_pico: Add gpio_get_config API
Implement the `gpio_get_config` N.b. adding this API results in a new test failure in `test_gpio_config_trigger`. This suggests that there is some kind of dependency between this and the now-enabled `pin_get_config` test cases. Note that this adds a read-only API, it is unlikely to be the cause of the failure. Signed-off-by: Andrew Featherstone <[email protected]>
1 parent c1b6971 commit 06be6eb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

drivers/gpio/gpio_rpi_pico.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,37 @@ static int gpio_rpi_configure(const struct device *dev,
9696
return 0;
9797
}
9898

99+
#ifdef CONFIG_GPIO_GET_CONFIG
100+
static int gpio_rpi_get_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t *flags)
101+
{
102+
struct gpio_rpi_data *data = dev->data;
103+
104+
*flags = 0;
105+
106+
/* RP2xxxx supports Bus Keeper mode where both pull-up and pull-down are enabled. */
107+
if (gpio_is_pulled_up(pin)) {
108+
*flags |= GPIO_PULL_UP;
109+
}
110+
if (gpio_is_pulled_down(pin)) {
111+
*flags |= GPIO_PULL_DOWN;
112+
}
113+
114+
if (gpio_get_dir(pin)) {
115+
*flags |= gpio_get_out_level(pin) ? GPIO_OUTPUT_HIGH : GPIO_OUTPUT_LOW;
116+
if (data->single_ended_mask & BIT(pin)) {
117+
*flags |=
118+
data->open_drain_mask & BIT(pin) ? GPIO_OPEN_DRAIN : GPIO_PUSH_PULL;
119+
}
120+
}
121+
122+
if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS) {
123+
*flags |= GPIO_INPUT;
124+
}
125+
126+
return 0;
127+
}
128+
#endif
129+
99130
static int gpio_rpi_port_get_raw(const struct device *dev, uint32_t *value)
100131
{
101132
*value = gpio_get_all();
@@ -235,6 +266,9 @@ static int gpio_rpi_port_get_direction(const struct device *port, gpio_port_pins
235266

236267
static DEVICE_API(gpio, gpio_rpi_driver_api) = {
237268
.pin_configure = gpio_rpi_configure,
269+
#ifdef CONFIG_GPIO_GET_CONFIG
270+
.pin_get_config = gpio_rpi_get_config,
271+
#endif
238272
.port_get_raw = gpio_rpi_port_get_raw,
239273
.port_set_masked_raw = gpio_rpi_port_set_masked_raw,
240274
.port_set_bits_raw = gpio_rpi_port_set_bits_raw,

0 commit comments

Comments
 (0)