-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
PICO IOConfigGPIO don't change output level when calling a second time #14707
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
PICO IOConfigGPIO don't change output level when calling a second time #14707
Conversation
…e to update direction / pullups. Code was calling gpio_init, which set the output level to low, even when the pin was already initialised to gpio mode.
|
Do you want to test this code? You can flash it directly from Betaflight Configurator:
WARNING: It may be unstable. Use only for testing! |
WalkthroughRefactors IOConfigGPIO in src/platform/PICO/io_pico.c to initialize the GPIO when current function is NULL, warn if the function is not SIO, and adjust logging format. Direction and pull configuration remain unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant I as IOConfigGPIO
participant G as GPIO HAL
participant L as Log
C->>I: IOConfigGPIO(ioPin, ...)
I->>G: gpio_get_function(ioPin)
G-->>I: currentFunction
alt currentFunction == GPIO_FUNC_NULL
I->>G: gpio_init(ioPin)
note right of I: Initialize when function is NULL
else currentFunction != GPIO_FUNC_SIO
I->>L: warn("gpio %d for 0x%02x: function=%d", ...)
note right of I: Proceed despite non-SIO
end
I->>G: gpio_set_dir(ioPin, ...)
I->>G: gpio_set_pulls(ioPin, ...)
I-->>C: return
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/platform/PICO/io_pico.c (1)
144-150: LGTM! Core fix correctly prevents output level reset.The logic now properly handles re-configuration:
- GPIO_FUNC_NULL: Initializes the pin (first-time setup)
- GPIO_FUNC_SIO: Skips initialization, preserving the existing output level (fixes the chip-select issue)
- Other functions: Warns but allows reconfiguration
This correctly addresses the issue where calling IOConfigGPIO a second time would unintentionally reset the output level to low.
Minor observation: Line 149's
bprintfincludes\n, while line 142's doesn't. Consider using consistent newline handling across log messages for uniformity.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/platform/PICO/io_pico.c(1 hunks)
🔇 Additional comments (1)
src/platform/PICO/io_pico.c (1)
142-142: LGTM! Improved log message format.The updated log message is more informative, using hex format for the configuration parameter and providing helpful inline documentation of the direction values.
PICO IOConfigGPIO don't change output level when calling a second time to update direction / pullups.
Code was calling gpio_init, which set the output level to low, even when the pin was already initialised as gpio.
This was noticed when debugging a SPI device (SD card), which left the CSn low (device enabled) after initialisation,
due to starting as an input, then changing to an output.
Summary by CodeRabbit