feat(ecs): slice 2 — MattonellaState register image + Mattonella model
ci / test (push) Canceled after 0s
ci / build-arm64 (push) Canceled after 0s

- state.rs: ports of mattonella_state.py (569 L), _dac_setting.py and the
  RegisterField byte plumbing — full 0x6C register image (64 pixel bytes,
  globals 0x40-0x4B, pairwise finetune-DAC nibbles 0x4C-0x6B) with exact
  range checks and enum parsing (ChannelMode, CalibrationTime)
- mattonella.rs: port of mattonella.py (426 L) — DACInterface (enable bit 7
  + 7-bit value RMW), 20 class-level descriptors, pixel batch ops
  (power/frontend/adj/ctrl/mask/ftdac), calibrate, full-state read/write
- 9 integration tests; verified from_bytes(to_bytes(s)) == s round-trip
- fake data_server moved to tests/common and fixed to advance the
  subaddress on multi-byte reads/writes (consecutive registers)
- divergences D1-D5 documented in docs/porting-notes.md
- workspace: 30 tests green
This commit is contained in:
BobBot
2026-11-12 23:36:32 +00:00
parent eff04cfa10
commit c8c4199c5c
9 changed files with 1227 additions and 100 deletions
+21
View File
@@ -48,6 +48,27 @@
8. **`config_crystal` hi/lo aliasing**: the high byte of each register
address is written to subaddress 0x01 of the controller (0x75), so a row
whose low byte IS 0x01 overwrites the next row's hi byte. Mirrored as-is.
9. **`MattonellaState` round-trips its own serialization exactly** —
verified property: `from_bytes(to_bytes(state)) == state` for arbitrary
states (9 slice-2 tests), incl. the pairwise finetune-DAC nibble packing
(pixel `2i` = low nibble, `2i+1` = high nibble of register `0x4C + i`).
## Deliberate divergences from the original
D1. The module-global "current connection" is replaced by explicit
`&mut Connection` arguments on every call.
D2. `ValueError` / `InvalidRange` / `IOError` become `FieldError` /
`StateError` return values (no exceptions).
D3. The batch pixel operations (`set_pixel_power`, `set_pixel_frontend`,
`set_pixel_adj`, `set_pixel_ctrl`) do NOT check the I2C status of their
read step in Python; the Rust port fails explicitly with
`FieldError::Server` (writing back garbage would be worse).
D4. `RegisterField`'s data-driven resolution (int / str / callable
subaddress, n_bits, bit_shift) is unrolled into explicit per-field
`apply` / `extract` calls in `state.rs` — same byte semantics, no
dynamic dispatch.
D5. `_repr_html_` (Jupyter table) has no Rust counterpart; `copy()` maps to
`#[derive(Clone)]`.
## Domain constants (kept identical)