Skip to content

Implement SiliconTwin.Abstractions (RP2040Mcu) - #70

Merged
begeistert merged 3 commits into
masterfrom
feat/silicontwin-abstractions
Oct 16, 2026
Merged

begeistert merged 3 commits into
masterfrom
feat/silicontwin-abstractions

Conversation

@begeistert

Copy link
Copy Markdown
Collaborator

Implements the shared embedder contract SiliconTwin.Abstractions (silicon-twin/abstractions#1). The AVR counterpart is PyMCU/AVR8Sharp#31.

Draft until SiliconTwin.Abstractions 0.1.0 is on nuget.org. CI cannot restore until then. It was built and tested locally against the packed package.

  • RP2040Mcu implements IMcu, IGpio (one 30-pin bank resolved through the function mux), IPwmSource, IAdcInput and IPeripheralMap (UART, SPI and I2C, including firmware as I2C slave).
  • New RP2040Machine.RunCycles(budget): slices are sized from the measured CPI. It overshoots by about one instruction and costs the same as plain instruction batches (around 450 Mcycles/s).
  • PinChanged is batched per pad sweep and stamped with the cycle. It is armed only while subscribed.
  • Additive core APIs:
    • PadsChanged
    • GetPadOutputState
    • ReleaseExternalInput and ReleaseGpioExternal, which make an externally driven pad releasable
    • TryInjectByte
  • Known limits:
    • Power and soft reset do not reset peripheral registers.
    • Cycles follows core 0.
    • PWM pads raise no PinChanged; read them through IPwmSource.

Tests:

  • RP2040Sharp.Tests: 589 (538 before, plus 51 contract tests)
  • Integration: 189 passed, 4 skipped

RP2040Mcu implements IMcu, IGpio, IPwmSource, IAdcInput and IPeripheralMap
over RP2040Machine. Run(cycleBudget) is backed by a new RP2040Machine.RunCycles
that sizes instruction slices from the measured CPI. The GPIO bank resolves
output state through the function mux and raises cycle-stamped PinChanged
batches, armed only while subscribed.

Core additions: IoBank0Peripheral.PadsChanged, GetPadOutputState,
ReleaseExternalInput, SioPeripheral.ReleaseGpioExternal and
UartPeripheral.TryInjectByte.
master rewrote pad evaluation while this branch was open, so the conflicts were
semantic rather than textual:

- IoBank0Peripheral.NotifyPads: master added EvaluatePads(mask), this branch
  added the PadsChanged batch event. Edge latching and peripheral inputs must
  run regardless of listeners, so EvaluatePads goes first and only the
  notification half is skipped when nobody subscribes.
- IoBank0Peripheral.ReleaseExternalInput: written against a per-pin _gpioInput
  shadow and a LatchInputEdge helper, neither of which master has any more --
  _padLevel and EvaluatePads replaced them. Re-reading the released pad through
  EvaluatePads(bit) latches the edge the same way. The _externalInput mask also
  went: master tracks only _externalHeld, with the level living in the SIO.
- SioPeripheral: ReleaseGpioExternal and master's GpioMask constants are
  independent additions. Kept both.
- CHANGELOG: both entries kept.

RP2040McuContractTests.Pull_masks_follow_the_pads_registers expected every pull
mask to start at 0. The spec audit fixed PADS_BANK0_GPIOn to its SVD reset value
0x56 (IE, 4 mA, PDE, Schmitt), so on real silicon every GPIO comes out of reset
pulled down. Updated the expectation to the hardware's state.

670 unit + 197 integration tests green.
@begeistert
begeistert marked this pull request as ready for review October 16, 2026 04:01
@begeistert
begeistert requested a review from lmSeryi as a code owner October 16, 2026 04:01
Only CHANGELOG conflicted; both entries kept. 676 unit + 197 integration
tests green with the SPI/DMA fix in.
@begeistert
begeistert merged commit 9289edc into master Oct 16, 2026
4 checks passed
@begeistert
begeistert deleted the feat/silicontwin-abstractions branch October 16, 2026 04:10
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