Skip to content

refactor(variants): display and user button of 48 boards from the board description (note 0011, cut E1) - #38

Merged
marcelverdult merged 24 commits into
devfrom
refactor/11e-variant-peripherals
Oct 26, 2026
Merged

marcelverdult merged 24 commits into
devfrom
refactor/11e-variant-peripherals

Conversation

@marcelverdult

Copy link
Copy Markdown
Owner

CI only, not for merge into integration. Based on integration at 07fa9c5c (cuts A to D, 9c and 10c merged), so the diff against dev also shows those commits. This PR's own commits are the last four (44369a74, 6bbee986, 6b99b97f, 0c090d6a).

Cut E1 of note 0011: 48 variants carried the same display and user button lines in target.cpp (DISPLAY_CLASS display; and MomentaryButton user_btn(PIN_USER_BTN, 1000, true); inside #ifdef DISPLAY_CLASS, in four forms). They now live once in the new src/helpers/VariantTarget.cpp, for every variant whose target.h defines the new opt-in DISPLAY_TARGET_GLOBALS, built from the board's description: DISPLAY_CLASS, DISPLAY_PERIPH_POWER (new: the display's constructor argument, &board.periph_power in 7 variants, NULL in 2) and USER_BTN_PULL (new: the button with the pin's pull resistor, 5 variants). In variants/: 48 target.cpp deletions only (237 lines), 48 target.h additions only (62 lines). Not weak, for the reason of cut D.

The first commit is the design of cut E. It recommended not to build E now (small benefit per file; E2, GPS and sensors, collides with the open upstream redesign meshcore-dev#1799). E1 was built on Marcel's decision; E2 stays not built.

Evidence:

  • Host tests: four new environments (one per board description) pin the blocks verbatim (display constructor and argument; button pin, pin mode with and without pull resistor, active low, long press at 1000 ms, multi-click window), then run the same cases against the shared globals. All 26 host environments pass on the test commit and the code commit: 835 cases, 1 skipped, none failed. 8 mutations, all caught.
  • Constructor chains of all 10 display classes the 48 variants build, with source lines (in the note): none touches a pin, bus or clock or reads another global; ST7789LCDDisplay and NV3001BDisplay (an SPIClass mutex) and E290Display (page buffer) allocate, so what the move can change is the order of heap allocations at start-up.
  • Builds of 64 environments before and after, same worktree, SOURCE_DATE_EPOCH fixed. Controls: identical images, except PicoW_repeater (linker veneers in another order, every other symbol at the same address) and an ESP32 environment without display (ELF hash fields only). In the 54 edited environments: flash -44 to +88, RAM -8 to +16. nm on all 54: display and user_btn keep name, size and binding; the construction moved to VariantTarget.cpp's initializer. Three environments with further size changes were rebuilt in another worktree and compared object by object: only target.cpp.o differs, the changed functions are Xtensa encoding and alignment differences or a kept inline copy that moved, and in ThinkNode_M5_Repeater the GxEPDDisplay constructor is now inlined (not compared instruction by instruction).
  • No hardware evidence (without board).

…the board description

Inventory of the radio blocks in the 89 target.cpp (tools/refactoring/
variant_target_globals.py), why objects cannot be weak, the opt-in macro
RADIOLIB_TARGET_GLOBALS in target.h, the split into D1 (31 nRF52) and
D2 (22 ESP32 with the shared radio_init()), rejected alternatives and the
open upstream pull requests that touch the same lines.
…riants

A new host suite (native_variant_target_globals) builds the shared variant
code against the target.h of a variant with the real AutoDiscoverRTCClock,
with the radio block of the 31 nRF52 variants of cut C copied verbatim: the
radio is built from a Module on the board pins in SX126x order with SPI
passed, radio_driver wraps it and the board, rtc_clock falls back to and
ticks fallback_clock, and the shared radio_init() starts that radio. The
variant stand-ins move into variant_stubs.h and gain a Module stand-in.
… variants

RadioLibTarget.cpp defines radio, radio_driver, fallback_clock and
rtc_clock for the variants whose target.h defines the new opt-in macro
RADIOLIB_TARGET_GLOBALS, built from the P_LORA_* pins: on nRF52 the radio
is a Module on SPI, the fallback clock a VolatileRTCClock. Not weak: a weak
object would still be constructed into a variant's own one. Other platforms
and the SX1276 pin order stop the build with an #error until described.

The 31 nRF52 variants of cut C delete their block from target.cpp
(deletions only) and add the macro line to target.h (additions only).
The host suite now runs its cases against the shared globals.
…riants

A host suite in four environments, one per board description that occurs
among the 22 ESP32 variants of cut D2 (SX1262 on an own bus on the default
host, without P_LORA_SCLK, SX1276, own bus on another host), with their
blocks and radio_init() bodies copied verbatim: the Module's pins in the
chip's order, its bus (own, on which host, or none), what radio_driver
wraps, the fallback clock, and that radio_init() starts the fallback clock,
the RTC and then the radio on its bus, passing the result through. The SPI
stand-in gets bus numbers, the radio stand-in tells the module's bus apart.
…r 22 ESP32 variants

RadioLibTarget.cpp describes the radio globals for ESP32 as well: the pins
in the chip's order (SX1276: DIO0, RESET, DIO1), an own SPIClass where the
board names P_LORA_SCLK, on P_LORA_SPI_HOST if set, otherwise no bus so that
RadioLib starts its default one, and an ESP32RTCClock as fallback clock. For
those variants with an SX126x or SX1276 it adds a weak radio_init(): start
the fallback clock and the RTC, then the radio on its bus.

The 22 ESP32 variants left by cut C delete their block and radio_init()
from target.cpp (deletions only) and add the opt-in, and five of them
P_LORA_SPI_HOST (FSPI, or 0 on the C6), to target.h (additions only).
Inventory of the display, button, GPS and sensor globals of the 89
target.cpp (variant_target_globals.py --peripherals), what a shared
definition would need, the cost of these lines so far and the open
upstream pull requests on them.
…descriptions

Characterization for cut E1 of note 0011: the display and user_btn blocks
of heltec_v3, heltec_t1, heltec_v4 and promicro, verbatim, against the
real MomentaryButton, in one native environment each.
…ard description

Cut E1 of note 0011. src/helpers/VariantTarget.cpp defines display and
user_btn for the variants whose target.h defines DISPLAY_TARGET_GLOBALS,
from DISPLAY_CLASS, DISPLAY_PERIPH_POWER (new, the display's constructor
argument where there is one) and USER_BTN_PULL (new, the button with the
pin's pull resistor). Not weak, as the radio globals of cut D. In the 48
variants target.cpp loses the two declarations (deletions only), target.h
gains the opt-in and where needed one description line.
Host tests, mutations, constructor chains of the 10 display classes and
the builds of 64 environments before and after.
@marcelverdult
marcelverdult merged commit 1f9e722 into dev Oct 26, 2026
15 checks passed
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.

1 participant