core: Add variant and loop hooks to Arduino main#212
Draft
soburi wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
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 beforesetup(). - Add weak
__loopHook()invoked after eachloop()iteration. - Add a build-flagged
LL_EXTENSION_SYMBOL(main)export and a compile-time guard aroundserialEventRun().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
7
to
+9
| #include "Arduino.h" | ||
| #include "zephyr/kernel.h" | ||
| #include <cstdint> |
Comment on lines
+29
to
+33
| #if ZARD_GENERIC_SERIAL_COUNT > 0 | ||
| if (arduino::serialEventRun) { | ||
| arduino::serialEventRun(); | ||
| } | ||
| #endif |
| #include <zephyr/llext/symbol.h> | ||
| #endif | ||
|
|
||
| // This function will be overwriten by most variants. |
| void __attribute__((weak)) initVariant(void) { | ||
| } | ||
|
|
||
| // This function can be overwriten by one library. |
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>
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.
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.