core: Derive Arduino pin configuration from Zephyr connector definitions#522
core: Derive Arduino pin configuration from Zephyr connector definitions#522soburi wants to merge 8 commits into
Conversation
Move the constant array derived from devicetree to wiring_private.h and convert it to constexpr. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Define `invalid_pin_number` and replace `pin_size_t(-1)`. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅ |
58.7% |
2 | - | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
68 | 26 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 16 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
80 | 22 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.5% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
In preparation for improvements to allow the use of GPIOs without device tree definitions, the interface will be changed to specify port and pin instead of `gpio_dt_spec`. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
pillo79
left a comment
There was a problem hiding this comment.
Absolutely love this patch set! It got me thinking all day and I did take the opportunity to push it a step further, refactoring the "zephyr,user" logic as well in a separate file. A few iterations later and I think I have something nice that neatly cleans up the Arduino.h header file to only contain high level code.
Please take a look at the changes in my fork (or just compare my version of your branch):
- commits 1 & 2 are unchanged;
- commit 3 is modified (it was missing the basic definition of a few functions that only get defined later);
- commit 4 is added by me and moves most existing DT macros to a new
dt_user_pins.hheader - commit 5 & 6 have been rewritten to do the same as your commits, but taking advantage of this new layout: the connector file is called
dt_connector.hand it includes a few extra definitions that minimize DT code outside these files. - commits 7 & 8 are unchanged.
Have to leave for today, haven't tested it yet so no PR yet 😅 but I wanted to give you a heads up so you have some extra time - please take a look if this could be a workable solution. Letme know what you guys think and feel free to take anything from my branch.
Move DIGITAL_PIN_*, LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, and DIGITAL_PIN_GPIOS_FIND_PIN/NODE from Arduino.h into the new dt_user_pins.h header. Move PWM_DT_SPEC, PWM_PINS, ADC_DT_SPEC, ADC_PINS from wiring_private.h into dt_user_pins.h, renaming them to the ZARD_ namespace (ZARD_PWM_DT_SPEC, ZARD_PWM_PINS, ZARD_ADC_DT_SPEC, ZARD_ADC_PINS). Rename the enum helpers DN_ENUMS/AN_ENUMS/DAC_ENUMS to ZARD_DN_ENUMS/ZARD_AN_ENUMS/ZARD_DAC_ENUMS. Arduino.h gains a single unconditional #include "dt_user_pins.h". No functional change. Signed-off-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1f958b9 to
ad15675
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a connector-derived pin configuration path that uses Zephyr connector devicetree definitions (notably arduino_header + gpio-map) when /zephyr,user/digital-pin-gpios is not present, reducing overlay duplication and broadening board compatibility. It also migrates the FRDM-MCXN947 variant to the new connector-based approach and adds new documentation describing both configuration modes and their pin-number semantics.
Changes:
- Add connector-based derivation of Arduino digital pin definitions, GPIO flags, built-in LED selection, and optional ADC/PWM association/provisioning from connector maps.
- Refactor core GPIO helpers to support both
digital-pin-gpiosand global GPIO numbering modes. - Add configuration guide/reference documentation and update FRDM-MCXN947 overlays to use connector mapping (plus ADC/PWM enablement).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.overlay | Migrates FRDM-MCXN947 to connector-based GPIO map and adds ADC/PWM connector + pinmux/channel config. |
| variants/frdm_mcxn947_mcxn947_cpu0/frdm_mcxn947_mcxn947_cpu0.conf | Enables ADC and PWM Kconfig needed for the new FRDM mapping. |
| documentation/variants.md | Updates variant documentation to reflect connector-derived/global-pin behavior and bus-label naming. |
| documentation/configuration-reference.md | Adds a detailed reference describing precedence rules and global GPIO numbering semantics. |
| documentation/configuration-guide.md | Adds a practical guide describing “support levels” and how to configure boards. |
| cores/arduino/zephyrCommon.cpp | Switches digital-pin-to-port/pin lookups to the new local/global GPIO helpers. |
| cores/arduino/wiring_pulse.cpp | Updates pulseIn to use local/global GPIO helpers rather than gpio_dt_spec. |
| cores/arduino/wiring_private.h | Introduces connector/global GPIO lookup tables and shared helpers for both DT paths. |
| cores/arduino/wiring_digital.cpp | Routes pinMode/digitalRead/digitalWrite through the new GPIO helpers. |
| cores/arduino/wiring_analog.cpp | Extends ADC/PWM support to work from either zephyr,user properties or connector maps. |
| cores/arduino/WInterrupts.cpp | Updates interrupt routing to use local/global GPIO helpers. |
| cores/arduino/Tone.cpp | Updates tone pin tracking and connector-mode MAX_TONE_PINS sizing. |
| cores/arduino/dt_user_pins.h | Adds helper macros for the zephyr,user (explicit list) pin-definition path. |
| cores/arduino/dt_connector.h | Adds helper macros for connector-based derivation and global GPIO numbering. |
| cores/arduino/connectors/arduino_header_r3.h | Defines connector-specific naming and feature classification for Arduino Header R3. |
| cores/arduino/Arduino.h | Selects between user-pin and connector paths and refactors LED + pin enum generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.7% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.3% |
72 | 40 | - |
nano33ble
| 1 🏷️ | ✅* |
78.9% |
42 | 18 | - | |
nano_connect
| 📗 | ✅* |
48.0% |
32 | 18 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 10 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 10 | - | |
nicla_vision
| 4 🏷️ | ✔️* |
39.5% |
56 | 28 | (2*) | |
opta
| 4 🏷️ | ✅* |
42.4% |
66 | 44 | - | |
portentac33
| 2 🏷️ | ✅* |
81.8% |
70 | 70 | - | |
portentah7
| 3 🏷️ | ✅* |
41.2% |
84 | 52 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.5% |
56 | 12 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
When digital-pin-gpios is absent, derive Arduino pin numbers and GPIO configuration from the Arduino connector gpio-map. Use global GPIO numbering for connector-based configurations and derive built-in LED definitions and GPIO flags from devicetree. This allows ArduinoCore-Zephyr to be used on boards that have arduino-header defined, without requiring specific configuration in ArduinoCore-Zephyr. Co-authored-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Generate ADC and PWM channel mappings from connector io-channel-map and pwm-map definitions when the legacy zephyr,user properties are absent. Co-authored-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add guide for adding new board configuration and configuration reference. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Define the Arduino header and its ADC and PWM mappings using connector nodes. Enable ADC and PWM support and remove the legacy digital-pin-gpios configuration. Use arduino_serial, arduino_i2c, and arduino_spi aliases for the peripherals exposed through the Arduino header. This changes Serial1 from LPUART4 to LPUART2. The connector definitions are based on the newer Zephyr board configuration and can be removed when the bundled Zephyr version is updated. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
ad15675 to
c6c508b
Compare
The proposal was acceptable in principle, so I incorporated it almost exactly as is. |
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.7% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.3% |
72 | 40 | - |
nano33ble
| 1 🏷️ | ✅* |
78.9% |
42 | 18 | - | |
nano_connect
| 📗 | ✅* |
48.0% |
32 | 18 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 10 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 10 | - | |
nicla_vision
| 4 🏷️ | ✔️* |
39.5% |
56 | 28 | (2*) | |
opta
| 4 🏷️ | ✅* |
42.4% |
66 | 44 | - | |
portentac33
| 2 🏷️ | ✅* |
81.8% |
70 | 70 | - | |
portentah7
| 3 🏷️ | ✅* |
41.2% |
84 | 52 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.5% |
56 | 12 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
|
Memory usage change @ c6c508b
Click for full report table
Click for full report CSV |
Summary
This PR adds a connector-based pin configuration path for boards that do
not define
zephyr,user/digital-pin-gpios.Many Zephyr boards already describe an Arduino-compatible connector using
an
arduino_headernode and itsgpio-map. The new configuration path usesthis existing devicetree information instead of duplicating the digital pin
mapping in
zephyr,user/digital-pin-gpios.Changes
The configuration path is selected based on the presence of
zephyr,user/digital-pin-gpios:digital-pin-gpiosis present, preserve the existing configurationpath using
digital-pin-gpios,adc-pin-gpios,io-channels,pwm-pin-gpios, andpwms.digital-pin-gpiosis absent:gpio-map.io-channel-mapandpwm-mapdefinitions when available.Note on FRDM-MCXN947 migration
Serial1through FLEXCOMM2 LPUART2 instead of FLEXCOMM4 LPUART4.Motivation
ArduinoCore-zephyr currently requires variant overlays that may duplicate
pin information already present in Zephyr's board devicetree.
Using connector definitions makes basic Arduino GPIO support available to
a wider range of Zephyr boards with Arduino-compatible headers and reduces
the amount of board-specific configuration maintained in this repository.
Note
This change needs to apply arduino/zephyr#22 simultaneously.