From 0b86b90cfd46aaed878dde538ec7c4de3abfd481 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` and extend test coverage using the Pico 2 board with a suitable GPIO loopback. Signed-off-by: Andrew Featherstone --- drivers/gpio/gpio_rpi_pico.c | 26 +++++++++++++++++++ .../boards/rpi_pico2_rp2350a_m33.conf | 1 + .../boards/rpi_pico2_rp2350a_m33.overlay | 16 ++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.conf create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.overlay diff --git a/drivers/gpio/gpio_rpi_pico.c b/drivers/gpio/gpio_rpi_pico.c index 8b3d18e8717a..e7bbdeef9f4d 100644 --- a/drivers/gpio/gpio_rpi_pico.c +++ b/drivers/gpio/gpio_rpi_pico.c @@ -80,6 +80,29 @@ 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) +{ + *flags = 0; + + if (gpio_get_dir(pin)) { + *flags |= gpio_get(pin) ? GPIO_OUTPUT_HIGH : GPIO_OUTPUT_LOW; + } else { + *flags |= GPIO_INPUT; + } + + // 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; + } + + return 0; +} +#endif + static int gpio_rpi_port_get_raw(const struct device *dev, uint32_t *value) { *value = gpio_get_all(); @@ -180,6 +203,9 @@ static int gpio_rpi_manage_callback(const struct device *dev, 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, diff --git a/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.conf b/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.conf new file mode 100644 index 000000000000..b9d02cf11d5d --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.conf @@ -0,0 +1 @@ +CONFIG_SKIP_PULL_TEST=y diff --git a/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.overlay b/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.overlay new file mode 100644 index 000000000000..2c7981b8b28f --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/rpi_pico2_rp2350a_m33.overlay @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2025 Andrew Featherstone + */ + +/ { + resources { + compatible = "test-gpio-basic-api"; + /* Choice of pins on the header is arbitrary, but doesn't + * conflict with the external pulldown. + */ + out-gpios = <&pico_header 16 0>; + in-gpios = <&pico_header 17 0>; + }; +};