Refactor microcontroller wrappers, refactor nRF52 devices#502
Merged
Conversation
There was a problem hiding this comment.
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/BaseIoControllerWrapperutilities 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.refoutputs 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
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
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.
Refactors the microcontroller wrapper:
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:
TODOs for future PRs: