Initialize lazily only on stm32 - #184
Draft
jandelgado wants to merge 1 commit into
Draft
Conversation
jandelgado
force-pushed
the
move_signal_inversion_to_hal
branch
5 times, most recently
from
August 2, 2026 16:34
075747c to
e9fef89
Compare
jandelgado
force-pushed
the
initialize_lazily_only_on_stm32
branch
from
August 3, 2026 06:28
98c4212 to
b530689
Compare
jandelgado
force-pushed
the
move_signal_inversion_to_hal
branch
from
August 3, 2026 12:36
e9fef89 to
7f64f68
Compare
jandelgado
force-pushed
the
initialize_lazily_only_on_stm32
branch
from
August 3, 2026 12:37
b530689 to
d3549b3
Compare
jandelgado
force-pushed
the
move_signal_inversion_to_hal
branch
from
August 3, 2026 14:27
7f64f68 to
7961ad3
Compare
jandelgado
force-pushed
the
initialize_lazily_only_on_stm32
branch
from
August 3, 2026 14:27
d3549b3 to
6c48c1d
Compare
…M32 needs it Deferring pinMode()/analogWriteResolution() to the first analogWrite() call was only ever needed on STM32duino, which forbids touching hardware from a global constructor. All other Arduino-compatible platforms paid for the "already set up" flag and its branch on every analogWrite() call for no reason. ArduinoHal gains a kLazyInit_ template parameter (default false = eager init in the constructor). The flag is stored via a private EBO base that is empty when kLazyInit_ is false, so the eager path has zero extra storage and the branch is resolved at compile time via tag dispatch. jled.h sets kLazyInit_ = true only for ARDUINO_ARCH_STM32.
jandelgado
force-pushed
the
initialize_lazily_only_on_stm32
branch
from
August 3, 2026 15:02
6c48c1d to
171f10b
Compare
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.
The Arduino-based HAL currently lazily initializes the GPIO by calling pinMode on the first call to analogWrite. This lazy initialization was introduced because STM32 needs special treatment here (see #18): STM32duino forbids touching hardware from a global constructor. The cost for all other platforms is an extra flag (byte) and a branch on every analogWrite call, even though only STM32 needs it.
This PR makes lazy initialization opt-in via a
kLazyInit_template parameter (default false), moving init back into the constructor for every platform except STM32, which setskLazyInit_ = trueinjled.h. No public API is changed, the default behavior for non-STM32 platforms now costs zero extra storage/runtime.