From 06be6ebf3a1c8f02ca311267c6dfb451826d28d0 Mon Sep 17 00:00:00 2001 From: Andrew Featherstone Date: Wed, 22 Jan 2025 21:35:10 +0000 Subject: [PATCH] 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 --- drivers/gpio/gpio_rpi_pico.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/gpio/gpio_rpi_pico.c b/drivers/gpio/gpio_rpi_pico.c index 848c97954e8..2e2e592eee8 100644 --- a/drivers/gpio/gpio_rpi_pico.c +++ b/drivers/gpio/gpio_rpi_pico.c @@ -96,6 +96,37 @@ static int gpio_rpi_configure(const struct device *dev, return 0; } +#ifdef CONFIG_GPIO_GET_CONFIG +static int gpio_rpi_get_config(const struct device *dev, gpio_pin_t pin, gpio_flags_t *flags) +{ + struct gpio_rpi_data *data = dev->data; + + *flags = 0; + + /* RP2xxxx supports Bus Keeper mode where both pull-up and pull-down are enabled. */ + if (gpio_is_pulled_up(pin)) { + *flags |= GPIO_PULL_UP; + } + if (gpio_is_pulled_down(pin)) { + *flags |= GPIO_PULL_DOWN; + } + + if (gpio_get_dir(pin)) { + *flags |= gpio_get_out_level(pin) ? GPIO_OUTPUT_HIGH : GPIO_OUTPUT_LOW; + if (data->single_ended_mask & BIT(pin)) { + *flags |= + data->open_drain_mask & BIT(pin) ? GPIO_OPEN_DRAIN : GPIO_PUSH_PULL; + } + } + + if (pads_bank0_hw->io[pin] & PADS_BANK0_GPIO0_IE_BITS) { + *flags |= GPIO_INPUT; + } + + return 0; +} +#endif + static int gpio_rpi_port_get_raw(const struct device *dev, uint32_t *value) { *value = gpio_get_all(); @@ -235,6 +266,9 @@ static int gpio_rpi_port_get_direction(const struct device *port, gpio_port_pins static DEVICE_API(gpio, gpio_rpi_driver_api) = { .pin_configure = gpio_rpi_configure, +#ifdef CONFIG_GPIO_GET_CONFIG + .pin_get_config = gpio_rpi_get_config, +#endif .port_get_raw = gpio_rpi_port_get_raw, .port_set_masked_raw = gpio_rpi_port_set_masked_raw, .port_set_bits_raw = gpio_rpi_port_set_bits_raw,