Skip to main content

Module state

Module state 

Source
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 successful SignComplete, or a fresh PinVerified). 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.