Expand description
State machine task.
Owns the single instance of [TokenState] and applies transitions in
response to events posted on crate::channels::EVENT_CHANNEL. After
each transition it republishes the new state on
crate::channels::TOKEN_STATE so the animation task can update the
LEDs, and pulses crate::channels::TOUCH_CONFIRMED when it enters
the [TokenState::Signing] state so the dispatch loop can resume.
ยงInternal timers
The state task races EVENT_CHANNEL against two optional deadlines:
- Session timeout: armed when entering [
TokenState::Authenticated]. Re-armed on every event that proves the user is still active (a successfulSignComplete, or a freshPinVerified). If the deadline fires first, the task posts [Event::SessionEnded] internally, which drops the SM back to [TokenState::Idle]. - Error display window: armed when entering [
TokenState::Error]. When the deadline elapses, posts [Event::ErrorDisplayElapsed] which returns the SM to [TokenState::Idle].
Both deadlines share the same race future via select3; whichever
fires first wins. The non-armed case uses a far-future deadline so it
cannot interrupt the channel receive.
Functionsยง
- derive_
timer_ ๐event - Translate a timer expiration into the corresponding internal event.
- earliest ๐
- Return the earlier of two optional deadlines, or a far-future deadline if neither is armed.
- state_
task ๐ - Drive the token state machine. Spawn once at boot.
- update_
timers ๐ - Re-arm or clear the timers based on the SM state and the latest event.