Skip to content

core: Add variant and loop hooks to Arduino main#212

Draft
soburi wants to merge 1 commit into
zephyrproject-rtos:nextfrom
soburi:init_variant
Draft

core: Add variant and loop hooks to Arduino main#212
soburi wants to merge 1 commit into
zephyrproject-rtos:nextfrom
soburi:init_variant

Conversation

@soburi

@soburi soburi commented Jul 5, 2026

Copy link
Copy Markdown
Member

Call the weak initVariant() hook before setup() so board variants can run their initialization code from the common Arduino entry point.

Add a weak __loopHook() call after each loop() iteration, guard serialEventRun() when no generic serial devices exist, and export main() for LLEXT builds.

Copilot AI review requested due to automatic review settings July 5, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds new weak hooks to the common Arduino entry point so variants/libraries can run initialization and per-loop() logic from a single shared main(), and makes main() exportable for Zephyr LLEXT builds.

Changes:

  • Add weak initVariant() hook invoked before setup().
  • Add weak __loopHook() invoked after each loop() iteration.
  • Add a build-flagged LL_EXTENSION_SYMBOL(main) export and a compile-time guard around serialEventRun().

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

Comment thread cores/arduino/main.cpp
Comment on lines 7 to +9
#include "Arduino.h"
#include "zephyr/kernel.h"
#include <cstdint>
Comment thread cores/arduino/main.cpp
Comment on lines +29 to +33
#if ZARD_GENERIC_SERIAL_COUNT > 0
if (arduino::serialEventRun) {
arduino::serialEventRun();
}
#endif
Comment thread cores/arduino/main.cpp
#include <zephyr/llext/symbol.h>
#endif

// This function will be overwriten by most variants.
Comment thread cores/arduino/main.cpp
void __attribute__((weak)) initVariant(void) {
}

// This function can be overwriten by one library.
Comment thread cores/arduino/main.cpp
Comment on lines +19 to +20
void __attribute__((weak)) __loopHook(void) {
}
Call the weak initVariant() hook before setup() so board variants can run
their initialization code from the common Arduino entry point.

Add a weak __loopHook() call after each loop() iteration, guard
serialEventRun() when no generic serial devices exist, and export main() for
LLEXT builds.

Co-authored-by: Kurt Eckhardt <kurte@rockisland.com>
Co-authored-by: Martino Facchin <m.facchin@arduino.cc>
@soburi soburi marked this pull request as draft July 5, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants