core: Add peripheral reinit for pinmux switching#184
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.
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
2253386 to
6e9c007
Compare
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>
6e9c007 to
6806d96
Compare
|
Could you please merge this? |
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 is temporary fix.
Here, for merge management purposes, it's made identical to Arduino, but
the next patch, #186, will make this switchable.