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: Extend the driver API #84548

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ajf58
Copy link
Collaborator

@ajf58 ajf58 commented Jan 25, 2025

Edit:

The original goal of this PR was to add just the gpio_get_config. This PR has now widened to include a lot more functionality, extending the both the existing APIs to be more feature-complete, and adding new APIs that were missing.

Tested locally using a physical test fixture supporting the GPIO loopback.

@zephyrbot zephyrbot added area: GPIO platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico) labels Jan 25, 2025
@ajf58 ajf58 force-pushed the rpi-pico-add-gpio-get-config-api branch from 0b86b90 to 4416912 Compare January 25, 2025 09:08
@ajf58
Copy link
Collaborator Author

ajf58 commented Jan 25, 2025

cc: @drensber

@soburi soburi requested a review from ThreeEights January 31, 2025 08:23
@ajf58 ajf58 changed the title drivers: gpio_rpi_pico: Add gpio_get_config API drivers: gpio_rpi_pico: Extend the driver API Feb 4, 2025
@ajf58 ajf58 force-pushed the rpi-pico-add-gpio-get-config-api branch from 099ef80 to 2bfaa02 Compare February 4, 2025 22:21
if (flags & GPIO_INPUT) {
gpio_set_dir(pin, GPIO_IN);
} else {
gpio_set_input_enabled(pin, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that the RP2xxx series is documented as supporting reading from input pins at any time, does it make sense to disable the pad here? It seems to me that the pad should only be disabled if the application explicitly requests. (Of course, that leaves the question of should there be a Zephyr way to explicitly disable an input ...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a a good question. Zephyr's unit tests for gpio_pin_get_config require that pin config is explicit, i.e. if gpio_pin_get_config set GPIO_INPUT on every pin, the test will fail.

Of course, that leaves the question of should there be a Zephyr way to explicitly disable an input

I think it is explicit already: if someone wants an output that's also an input, they should use GPIO_INPUT | GPIO_OUTPUT.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you hate that? :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That a tab is 8 characters wide and the column limit is 100? Yes on both fronts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Everyone who learned how to properly use a keyboard knows that the correct setting for tabs is 5 spaces, adjusted as needed to suit the document. :-)

ajf58 added 5 commits February 8, 2025 13:19
Out of reset the pads are input enabled, output disabled. Disconnect the
pad's input and output buffers, as well as any pullups. This can reduce
input leakage current.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Reorder gpio_rpi_configure to disable input buffers when not in use.
gpio_rpi_get_config can then determine whether a pin is configured as an
input without requiring additional state variables, as well as reducing
input leakage current.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
Implement `gpio_get_pending_int`.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
THe driver didn't implement this API, so add it.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
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 <andrew.featherstone@gmail.com>
@ajf58 ajf58 force-pushed the rpi-pico-add-gpio-get-config-api branch from 2bfaa02 to c39f6f3 Compare February 8, 2025 14:06
Copy link
Collaborator Author

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

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

This push:

  1. Rebases onto a newer revision of main.
  2. Applies whitespaces requested in the review (although I would like to understand their rationale).
  3. Corrects compliance issues that came up under CI.

drivers/gpio/gpio_rpi_pico.c Show resolved Hide resolved
drivers/gpio/gpio_rpi_pico.c Show resolved Hide resolved
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That a tab is 8 characters wide and the column limit is 100? Yes on both fronts.

if (flags & GPIO_INPUT) {
gpio_set_dir(pin, GPIO_IN);
} else {
gpio_set_input_enabled(pin, false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a a good question. Zephyr's unit tests for gpio_pin_get_config require that pin config is explicit, i.e. if gpio_pin_get_config set GPIO_INPUT on every pin, the test will fail.

Of course, that leaves the question of should there be a Zephyr way to explicitly disable an input

I think it is explicit already: if someone wants an output that's also an input, they should use GPIO_INPUT | GPIO_OUTPUT.

@ajf58 ajf58 requested review from soburi and ThreeEights February 8, 2025 19:34
Comment on lines +255 to +258
}
if (inputs) {
*inputs &= map;
}
Copy link
Member

Choose a reason for hiding this comment

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

Here too, add a blank after }.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No.

256-258 is related to 259-261, See also 249-254, 107-112. These are logically grouped together, and that's represented by the code not have vertical whitespace between them.

@ajf58
Copy link
Collaborator Author

ajf58 commented Feb 9, 2025

At this point I think this PR it GTG.
@soburi , please take some time to read the reviewer guidelines at https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/contribute/reviewer_expectations.rst?plain=1#L39-L55 . I feel those 3 points are applicable.

@soburi
Copy link
Member

soburi commented Feb 9, 2025

At this point I think this PR it GTG. @soburi , please take some time to read the reviewer guidelines at https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/contribute/reviewer_expectations.rst?plain=1#L39-L55 . I feel those 3 points are applicable.

I believe there is no problem based on the following wording in the document you showed.

Style changes that the reviewer disagrees with but that are not documented as part of the project can be pointed out as non-blocking,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: GPIO platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants