Skip to content

Commit

Permalink
drivers: gpio_rpi_pico: Add gpio_get_config API
Browse files Browse the repository at this point in the history
Implement the `gpio_get_config` and extend test coverage using the
Pico 2 board with a suitable GPIO loopback.

Signed-off-by: Andrew Featherstone <[email protected]>
  • Loading branch information
ajf58 committed Jan 25, 2025
1 parent 03fa6a0 commit 4416912
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
26 changes: 26 additions & 0 deletions drivers/gpio/gpio_rpi_pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SKIP_PULL_TEST=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2025 Andrew Featherstone <[email protected]>
*/

/ {
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>;
};
};

0 comments on commit 4416912

Please sign in to comment.