Skip to content

cores: arduino: Split zephyrCommon.cpp#375

Draft
soburi wants to merge 2 commits intoarduino:mainfrom
soburi:split_zephyrcommon
Draft

cores: arduino: Split zephyrCommon.cpp#375
soburi wants to merge 2 commits intoarduino:mainfrom
soburi:split_zephyrcommon

Conversation

@soburi
Copy link

@soburi soburi commented Mar 1, 2026

Split zephyrCommon.cpp into small cpp files.

@soburi soburi force-pushed the split_zephyrcommon branch 2 times, most recently from a2f7406 to 4fbaf90 Compare March 1, 2026 14:32
@soburi soburi marked this pull request as ready for review March 1, 2026 17:02
Copilot AI review requested due to automatic review settings March 1, 2026 17:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Arduino Zephyr core by splitting the large zephyrCommon.cpp implementation into smaller, more focused compilation units. It also updates multiple sample CMakeLists.txt files to locate devicetree overlay files from variant directories (including revision-specific variants).

Changes:

  • Remove cores/arduino/zephyrCommon.cpp and replace it with separate wiring/utility/interrupt/tone source files.
  • Add cores/arduino/wiring_private.h to share devicetree-derived pin/port constants across the new units.
  • Update sample builds to select overlays from variant directories (including ${NORMALIZED_BOARD_TARGET}_${BOARD_REVISION}) and enable ADC/PWM in the blinky sample config.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
samples/threads_arduino/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/spi_controller/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/serial_event/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/i2cdemo/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/hello_arduino/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/fade/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/button_press_led/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/blinky_arduino/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/attach_interrupt/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/analog_input/CMakeLists.txt Adds variant directory + overlay selection logic.
samples/blinky_arduino/prj.conf Enables ADC/PWM configs for the blinky sample.
cores/arduino/zephyrCommon.cpp Removed; functionality redistributed into new files.
cores/arduino/wiring.cpp Adds yield/delay/micros/millis wiring functions.
cores/arduino/wiring_digital.cpp Adds pinMode/digitalRead/digitalWrite implementation.
cores/arduino/wiring_analog.cpp Adds PWM/ADC/DAC wiring implementation (gated by Kconfig).
cores/arduino/wiring_pulse.cpp Adds pulseIn() implementation.
cores/arduino/WInterrupts.cpp Adds attach/detach/noInterrupts/interrupts implementation.
cores/arduino/WMath.cpp Adds random/randomSeed implementation (when non-minimal libc).
cores/arduino/Tone.cpp Adds tone/noTone implementation.
cores/arduino/wiring_private.h Introduces shared devicetree-derived pin/port constants.
cores/arduino/CMakeLists.txt Replaces zephyrCommon.cpp with the new split source list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

namespace arduino {
namespace zephyr {

constexpr struct gpio_dt_spec arduino_pins[] = {
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arduino_pins is defined in this header with internal linkage, so every .cpp that includes wiring_private.h will get its own copy of the pins table. This can unnecessarily increase flash/RAM usage on embedded targets. Prefer a single definition in a .cpp with an extern declaration here (e.g., extern const gpio_dt_spec arduino_pins[NUM_OF_DIGITAL_PINS];), or use an inline variable approach if the project is guaranteed to build with C++17+.

Suggested change
constexpr struct gpio_dt_spec arduino_pins[] = {
inline constexpr struct gpio_dt_spec arduino_pins[] = {

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need support C++14 .

@soburi soburi force-pushed the split_zephyrcommon branch 2 times, most recently from 8c8d243 to 9fb90ae Compare March 1, 2026 21:42
@soburi soburi requested a review from Copilot March 1, 2026 21:42
@soburi soburi force-pushed the split_zephyrcommon branch from 9fb90ae to 48685d8 Compare March 1, 2026 21:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi force-pushed the split_zephyrcommon branch from 83753ff to 97e1a67 Compare March 1, 2026 23:00
@soburi soburi marked this pull request as draft March 1, 2026 23:52
@per1234 per1234 added the enhancement New feature or request label Mar 2, 2026
@soburi soburi force-pushed the split_zephyrcommon branch 2 times, most recently from e596183 to b216d39 Compare March 2, 2026 22:31
Move constexpr-specified constants and functions used for compile-time
calculations from zephyrCommon.cpp to wiring_private.h

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the split_zephyrcommon branch 2 times, most recently from f5ffc41 to ae2cd5c Compare March 2, 2026 23:00
Split zephyrCommon.cpp into small cpp files.

wirinig_digital.cpp:
  - pinMode
  - digitalWrite
  - digitalRead

wirinig_analog.cpp:
  - analogRead
  - analogWrite
  - analogReference
  - analogReadResolution
  - analogWriteResolution

wirinig_pulse.cpp:
  - pulseIn

WInterrupts.cpp:
  - attachInterrupt
  - detachInterrupt
  - interrupts
  - noInterrupts
  - digitalPinToInterrupt

WMath.cpp:
  - randomSeed
  - random

Tone.cpp:
  - tone
  - noTone

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the split_zephyrcommon branch from ae2cd5c to ed51751 Compare March 2, 2026 23:21
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Built 0.53.2-0.dev+ed51751

CI run PASSED 🟢

ArtifactBoardCoreTestsRAMSketchesWarningsErrors
✅* zephyr_contrib ek_ra8d1 📗 ✅*

11.9%

22-
frdm_mcxn947 3 🏷️ ✅*

57.9%

22-
frdm_rw612 1 🏷️ ✅*

83.0%

22-
✔️* zephyr_main giga 4 🏷️ ✅*

54.5%

4414-
nano33ble 1 🏷️ ✅*

78.7%

2210-
nano_matter 📗 ✔️*

⚠️ 85.7%

2010(2*)
niclasense 2 🏷️ ✅*

⚠️ 87.1%

2010-
opta 4 🏷️ ✔️*

46.6%

5426(2*)
portentac33 3 🏷️ ✔️*

⚠️ 95.1%

5628(8*)
portentah7 3 🏷️ ✔️*

47.3%

5828(2*)
✅* zephyr_unoq unoq 📗 ✅*

26.3%

5210-
Legend

BoardTestStatus description
🔥 🔥 Test run failed to complete.
🔴 Test completed with unexpected errors.
✔️* 🚫 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.

@soburi soburi marked this pull request as ready for review March 2, 2026 23:45
@soburi soburi marked this pull request as draft March 16, 2026 23:05
@CLAassistant
Copy link

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants