core: Add peripheral reinit for pinmux switching#184
Open
soburi wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a “rough” mechanism to allow switching a given pin back and forth between peripheral functions (UART/SPI/I2C/PWM/ADC/DAC) by re-initializing/de-initializing Zephyr devices when Arduino APIs begin/end or when analog/pinMode operations occur.
Changes:
- Add explicit device
init()calls inWire.begin(),SPI.begin(), andSerial.begin(). - Add optional device
deinit()calls inWire.end(),SPI.end(), andSerial.end()whenCONFIG_DEVICE_DEINIT_SUPPORTis enabled. - Add a per-pin “last device” tracker and
_reinit_peripheral_if_needed()helper used bypinMode(),analogWrite(), andanalogRead()to re-init peripherals when switching pinmux usage.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/Wire/Wire.cpp | Re-initialize I2C device in begin(); deinit in end() behind CONFIG_DEVICE_DEINIT_SUPPORT. |
| libraries/SPI/SPI.cpp | Re-initialize SPI device in begin(); deinit in end() behind CONFIG_DEVICE_DEINIT_SUPPORT. |
| cores/arduino/zephyrSerial.h | Deinitialize UART device in end() behind CONFIG_DEVICE_DEINIT_SUPPORT. |
| cores/arduino/zephyrSerial.cpp | Re-initialize UART device at start of begin(). |
| cores/arduino/zephyrInternal.h | Expose _reinit_peripheral_if_needed() as a C-linkage internal helper. |
| cores/arduino/zephyrCommon.cpp | Implement _reinit_peripheral_if_needed() and call it from pin/analog APIs to re-init pinmux-related peripherals. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Allow Arduino APIs to switch a pin between GPIO and peripheral functions by re-running the selected device init path when the requested owner changes. This is an interim pinmux handoff mechanism for boards where sketches may move a pin back and forth between serial/GPIO/PWM-style use. Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Co-Authored-by: pennam <m.pennasilico@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
eaaef01 to
ad38122
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4cd4bad to
ad38122
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows Arduino APIs to switch a pin between GPIO and peripheral functions by re-running the selected device init path when the requested owner changes.
This is an interim pinmux handoff mechanism for boards where sketches may move a pin back and forth between serial/GPIO/PWM-style use.
In practice, this code should be excluding.
Here, for merge management purposes, it's made identical to Arduino, but
the next patch, #186, will make this switchable.