Add pattern chaining support to XBLK format

Pattern entry bytes 108-109 now hold next_pattern (0xFF=loop forever,
0-8=chain to index) and loop_count. MCU will poll LP5562 STATUS register
to detect engine completion and load the successor pattern.

Updated XBLK format spec, Rust Pattern struct (serializer + deserializer),
and React Native app design doc (binary format, data model, resolved
open questions).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
michael
2026-03-05 15:52:33 -08:00
parent a32c242859
commit 2fade7ad8b
3 changed files with 319 additions and 1 deletions

View File

@@ -42,13 +42,27 @@ Offset Size Field
42 32 Engine 2 commands
74 2 Engine 3 command count
76 32 Engine 3 commands
108 4 Reserved
108 1 Next pattern index (0xFF = loop forever, 0-8 = chain to that index)
109 1 Loop count (how many full cycles before chaining, 0 = use next_pattern as-is)
110 2 Reserved
```
Max capacity: `(1024 - 16) / 112 = 9` patterns.
The 16-command-per-engine limit is a hardware constraint of the LP5562 (48 bytes engine SRAM). The `branch` command enables infinite looping, so pattern duration is unlimited.
### Pattern Chaining
A pattern can specify a successor via `next_pattern_index`. When set to anything other than 0xFF, the pattern's engine programs should use finite-count `branch(0, N)` instead of `branch(0, 0)` (infinite loop). When all engines stop (detected by polling LP5562 STATUS register 0x0C for engine interrupt bits), the MCU loads the next pattern.
The LP5562 has no interrupt output pin — the MCU must poll STATUS periodically. During the idle loop, a poll every ~500ms is sufficient and costs negligible power vs. the LED current.
Chain examples:
- `next=0xFF`: Loop forever (default, current behavior)
- `next=1, loops=0`: Play once, then switch to pattern 1
- `next=0, loops=3`: Play 3 full cycles, then switch to pattern 0 (can create A→B→A→B sequences)
- Circular chains (A→B→A) create alternating pattern sequences
## Boot Sequence
1. Init LP5562 (enable, clock, current)