Expand description
LED animation task.
Reads the current [hsm_firmware_logic::TokenState] off
crate::channels::TOKEN_STATE and drives the green (GP16) and yellow
(GP17) LEDs at the cadence dictated by the stateβs
[hsm_firmware_logic::LedPattern].
The task runs an infinite loop with two interleaved concerns:
- Apply the current pattern. Each pattern has a tick interval and a per-tick action (toggle green, toggle yellow, alternate, etc). The task sleeps for the tick interval, then performs the action.
- React to state changes promptly. Sleeping for a 500 ms tick
would make a transition into
Errorinvisible for half a second. To avoid that, the task races the tick timer againstcrate::channels::TOKEN_STATEusingembassy_futures::select. Whichever fires first wins.
Β§Testability
The actual driving logic lives in apply_pattern, which is generic
over the [Led] trait. The embassy task wrapper
animation_task is a thin shell that supplies real Output<'static>
values; host-side tests instantiate apply_pattern directly with
mock LEDs to assert on transition counts.
ConstantsΒ§
- ALTERNATE_
INTERVAL π - Tick interval for the alternate-both pattern (5 Hz).
- FAST_
BLINK_ πINTERVAL - Tick interval for the fast blink pattern (5 Hz).
- SLOW_
PULSE_ πINTERVAL - Tick interval for the slow pulse pattern (green, 1 Hz).
- YELLOW_
BLINK_ πINTERVAL - Tick interval for the yellow blink pattern (2 Hz).
FunctionsΒ§
- animation_
task π - Drive the LEDs based on the current operating state. Spawn once at boot.
- apply_
pattern π - Apply one tick of
patternto the LEDs and return the duration to wait before the next tick.