zephyrCommon: fix issues with invalid pin numbers#178
Open
soburi wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Zephyr-based Arduino core against invalid digital pin numbers (e.g., -1) and extends peripheral lifecycle handling to better support dynamic pinctrl/device deinit scenarios, alongside several analog/timing API additions.
Changes:
- Add early-return guards to prevent out-of-bounds access of the
arduino_pinsarray across multiple GPIO/interrupt/timing APIs. - Introduce optional peripheral re-init / de-init hooks (CONFIG-gated) for I2C/SPI/UART and add a pin-to-peripheral reinit helper.
- Add/extend analog + timing APIs (DAC support, read/write resolution APIs, cycle/time conversion macros, and inline delay helpers).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/Wire/Wire.cpp | Adds CONFIG-gated device init/deinit calls in begin()/end() |
| libraries/SPI/SPI.cpp | Adds CONFIG-gated device init/deinit calls in begin()/end() |
| cores/arduino/zephyrSerial.h | Adds CONFIG-gated UART deinit in end() |
| cores/arduino/zephyrSerial.cpp | Adds CONFIG-gated UART init in begin() |
| cores/arduino/zephyrInternal.h | Exposes CONFIG-gated peripheral reinit helper prototype |
| cores/arduino/zephyrCommon.cpp | Adds invalid-pin guards, tone concurrency changes, analog resolution/DAC support, and peripheral reinit logic |
| cores/arduino/time_macros.h | New timing/cycle conversion macros |
| cores/arduino/overloads.h | New overload/resolution getter declarations |
| cores/arduino/inlines.h | New inline implementations for delay APIs |
| cores/arduino/Arduino.h | Adds DAC declarations, resolution APIs, extra includes, and namespace exposure |
| Kconfig | Removes Rust core option; tweaks ARDUINO_MAX_TONES help text |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dfa2f94 to
9334e8f
Compare
9334e8f to
f24e62c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a7ff7cb to
ea2881d
Compare
de05e42 to
36d9450
Compare
Passing -1 to digital I/O functions may happen when libraries do not properly sanitize their inputs, leading to undefined behavior. This commit adds a check to ensure that the pin number is valid before accessing the arduino_pins array. Signed-off-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
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.
Passing -1 to digital I/O functions may happen when libraries do not
properly sanitize their inputs, leading to undefined behavior. This
commit adds a check to ensure that the pin number is valid before
accessing the arduino_pins array.
Note:
The code related to CONFIG_PINCTRL_DYNAMIC will also be included,
as CONFIG is disabled in this repository. so not affected.