Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: gpio_rpi_pico: Add gpio_get_config API #84548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to handle the flags that are handled by gpio_rpi_configure symmetrically.

{
*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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henrikbrixandersen

Let me confirm one thing.
Currently, Pico2 has an errata that causes incorrect behavior when GPIO_INPUT and GPIO_PULL_DOWN are specified at the same time. For this reason, it specifies SKIP_PULL here to avoid testing this case, but is this solution okay?

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>;
};
};
Loading