Skip to content

Refactor microcontroller wrappers, refactor nRF52 devices#502

Merged
ducky64 merged 38 commits into
masterfrom
micro-wrapper-next
May 30, 2026
Merged

Refactor microcontroller wrappers, refactor nRF52 devices#502
ducky64 merged 38 commits into
masterfrom
micro-wrapper-next

Conversation

@ducky64
Copy link
Copy Markdown
Collaborator

@ducky64 ducky64 commented May 29, 2026

Refactors the microcontroller wrapper:

  • Adds a BaseIoControllerWrapper utility class, which has a utility to perform the remapping from device-space to model-space.
    • Remapping matches on pin types to require all leaf IOs are part of the remapping dict
    • Refactors _export_tap_ios into this class
  • Restructures the remapping into utility functions and adds a convenience wrapper to use in microcontroller blocks.
  • Refactors STM32s, LPC1549 to eliminate BaseIoControllerExportable and use explicit _wrap_inner

Note, ideally both the from and to remapping would be put in the wrapping class, however the to remapping requires the model block to be solved, which the current generator structure does not support. A future structure that enables this might be separating param-only generators from structural (circuit) generators.

Updates the RP2040 to use this new style, adding a _model param to the device to remove requirement for some ports. Migrates the nRF52 devices to use microcontroller wrappers. Also removes the implicit Power tag from iovdd, as consistent with avoiding implicit tags on multiple power rails.

Adds a unit test based on the RP2040 that tests automatic assignment, specified assignment (checking remapping), and overflow.

Also refactors the base pin map util to:

  • save the original pin name (like GPIO0) and persist it across remaps (to pin numbers)
  • always display this instead of the "resource name"

TODOs for future PRs:

  • Deprecate BaseIoControllerExportable
  • Refactor other microcontrollers

@ducky64 ducky64 requested a review from Copilot May 30, 2026 19:34
@ducky64 ducky64 marked this pull request as ready for review May 30, 2026 19:35
Copy link
Copy Markdown

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

Refactors the microcontroller “model vs footprint” wrapping approach by introducing new wrapper utilities for IO export/remapping, migrating several MCU/device implementations (notably RP2040 and nRF52840 modules) to the new style, and updating generated example outputs accordingly.

Changes:

  • Introduces BaseIoControllerWrapped / BaseIoControllerWrapper utilities to standardize IO export/tap and pin assignment remapping.
  • Migrates multiple MCU blocks (STM32*, LPC1549, RP2040, nRF52840 modules) off BaseIoControllerExportable/old wrapped infrastructure and updates pinmap behavior to preserve original pin names across remaps.
  • Adds wrapper-focused unit tests and updates various example .svgpcb.js / .net.ref outputs to match new net/instance structures.

Reviewed changes

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

Show a summary per file
File Description
examples/TofArray/TofArray.svgpcb.js Regenerated placement/netlist output reflecting wrapper/pin export refactors.
examples/TofArray/TofArray.net.ref Regenerated net reference output reflecting wrapper/pin export refactors.
examples/TestBlinkyBasic/TestBlinkyBasic.svgpcb.js Updates generated net names to match refactored MCU wrapper port naming.
examples/TestBlinkyBasic/TestBlinkyBasic.net.ref Updates net reference name to match refactored MCU wrapper port naming.
examples/SwdDebugger/SwdDebugger.svgpcb.js Regenerated placement/netlist output reflecting wrapper/pin export refactors.
examples/SwdDebugger/SwdDebugger.net.ref Regenerated net reference output reflecting wrapper/pin export refactors.
examples/Multimeter/Multimeter.svgpcb.js Regenerated placement/netlist output and updated USB net naming to new wrapper structure.
examples/Multimeter/Multimeter.net.ref Regenerated net reference output and updated USB net naming to new wrapper structure.
examples/Keyboard/Keyboard.svgpcb.js Regenerated placement/netlist output reflecting wrapper/pin export refactors.
examples/Keyboard/Keyboard.net.ref Regenerated net reference output reflecting wrapper/pin export refactors.
examples/BldcController/BldcController.svgpcb.js Updates generated hierarchy comment/path naming for refactored MCU wrapper structure.
examples/BldcController/BldcController.net.ref Updates edg_path to match refactored wrapper structure.
examples/BasicKeyboard/BasicKeyboard.svgpcb.js Updates generated net names to match refactored MCU wrapper port naming.
examples/BasicKeyboard/BasicKeyboard.net.ref Updates net reference name to match refactored MCU wrapper port naming.
edg/parts/microcontroller/test_mcu_wrapper.py Adds unit tests covering auto/spec pin assignment, remapping, and over-allocation errors.
edg/parts/microcontroller/Stm32l432.py Moves to explicit _wrap_inner usage and updates generator params for wrapper-driven generation.
edg/parts/microcontroller/Stm32g431.py Moves to explicit _wrap_inner usage and updates generator params for wrapper-driven generation.
edg/parts/microcontroller/Stm32g031.py Moves to explicit _wrap_inner usage and updates generator params for wrapper-driven generation.
edg/parts/microcontroller/Stm32f103.py Refactors USB pull-up export into transform-based _wrap_inner flow and updates generator params.
edg/parts/microcontroller/Rp2040.py Adds _model mode, makes some ports optional in model mode, and migrates Xiao RP2040 to new wrapper approach.
edg/parts/microcontroller/nRF52840.py Refactors nRF52840 devices/modules to new wrapper approach and introduces a base device model + footprint wrappers.
edg/parts/microcontroller/Lpc1549.py Moves to explicit _wrap_inner usage and updates generator params for wrapper-driven generation.
edg/electronics_model/BoardScopedTransform.py Hardens handling of missing fp_external_blocks values for subboard transforms.
edg/abstract_parts/test_pinmappable.py Updates pinmappable tests to reflect “preserve original pin name across remaps” behavior.
edg/abstract_parts/PinMappable.py Extends pin resource modeling to preserve/display original pin names across remaps.
edg/abstract_parts/IoControllerWrapped.py Removes legacy wrapped-controller helper in favor of new base wrapper utilities.
edg/abstract_parts/IoController.py Adds _generator_param_all_ios and shifts export/tap helper responsibility into wrapper utilities.
edg/abstract_parts/BaseIoControllerWrapped.py Adds new wrapper utilities for model↔footprint pin assignment remapping and IO export/tap patterns.
edg/abstract_parts/init.py Re-exports new wrapper utilities and removes legacy wrapped-controller export.

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

Comment on lines 61 to 65
VoltageSink(
voltage_limits=(1.62, 3.63) * Volt, # Table 628
current_draw=(1.2, 4.3) * mAmp + self.io_current_draw.upper(), # Table 629
),
[Power],
)
Comment on lines +30 to +42
remapped_assigns: Dict[str, Tuple[Optional[str], Optional[str]]] = {}
for assign in pin_assigns:
name, pindef = assign.split("=")
name = name.strip()
split = pindef.split(",")
split = [s.strip() for s in split]
if len(split) == 1: # should be a bundle name, since pins should have two parts
assert name not in remapping
remapped_assigns[name] = (pindef, None)
elif len(split) == 2:
pinname, pinnum = split[0], split[1]
assert pinname in remapping
remapped_assigns[name] = (pinname, remapping[pinname])
Comment on lines +494 to +498
class Holyiot_18010_Device(
Nrf52840_Interfaces,
IoControllerWithSwdTargetConnector,
IoControllerPowerRequired,
BaseIoControllerExportable,
BaseIoControllerWrapper,
BaseIoController,
InternalSubcircuit,
@ducky64 ducky64 merged commit 86ac330 into master May 30, 2026
12 checks passed
@ducky64 ducky64 deleted the micro-wrapper-next branch May 30, 2026 19:53
ducky64 added a commit that referenced this pull request May 31, 2026
Refactors the ESP32 and iCE40 microcontroller devices to use the new
wrapper APIs microcontroller style from #502, #497

Deprecates BaseIoControllerExportable, now that all usages have been
refactored out.

Add pin filtering to PinMapUtil and implement it in device models. This
is needed to restrict automatic allocation in wrapped microcontroller
models, otherwise they allocate pins that don't exist on the modules.
Add pin filtering to all wrappers.

Allow pin names as part of pin_assign specifications; this is needed by
wrapper remapping if the pin name and GPIO name don't line up.

Fix the ground connection style of wrappers to account for when ground
is unneeded in power source mode.

Other refactorings:
- Cleans up the _export_ios_inner implementation, to use a single dict
and to not request() transformed-out IOs
- Move the microcontroller wrapper test to the ESP32C3 as a more complex
example with fewer pins to deal with
- Deletes the owlbot example. It was a misnomer, and it uses the
horribly abstraction breaking camera I2C pins which are no longer
supported

Resolves #389
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