mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-01 12:22:34 +00:00
fix(core): change incorrect usage of "deadline" in Rust timer code
This commit is contained in:
parent
73019d079d
commit
ddeb11d88d
@ -418,7 +418,7 @@ impl EventCtx {
|
|||||||
pub const ANIM_FRAME_TIMER: TimerToken = TimerToken(1);
|
pub const ANIM_FRAME_TIMER: TimerToken = TimerToken(1);
|
||||||
|
|
||||||
/// How long into the future we should schedule the animation frame timer.
|
/// How long into the future we should schedule the animation frame timer.
|
||||||
const ANIM_FRAME_DEADLINE: Duration = Duration::from_millis(1);
|
const ANIM_FRAME_DURATION: Duration = Duration::from_millis(1);
|
||||||
|
|
||||||
// 0 == `TimerToken::INVALID`,
|
// 0 == `TimerToken::INVALID`,
|
||||||
// 1 == `Self::ANIM_FRAME_TIMER`.
|
// 1 == `Self::ANIM_FRAME_TIMER`.
|
||||||
@ -464,10 +464,10 @@ impl EventCtx {
|
|||||||
self.paint_requested = true;
|
self.paint_requested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request a timer event to be delivered after `deadline` elapses.
|
/// Request a timer event to be delivered after `duration` elapses.
|
||||||
pub fn request_timer(&mut self, deadline: Duration) -> TimerToken {
|
pub fn request_timer(&mut self, duration: Duration) -> TimerToken {
|
||||||
let token = self.next_timer_token();
|
let token = self.next_timer_token();
|
||||||
self.register_timer(token, deadline);
|
self.register_timer(token, duration);
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ impl EventCtx {
|
|||||||
pub fn request_anim_frame(&mut self) {
|
pub fn request_anim_frame(&mut self) {
|
||||||
if !self.anim_frame_scheduled {
|
if !self.anim_frame_scheduled {
|
||||||
self.anim_frame_scheduled = true;
|
self.anim_frame_scheduled = true;
|
||||||
self.register_timer(Self::ANIM_FRAME_TIMER, Self::ANIM_FRAME_DEADLINE);
|
self.register_timer(Self::ANIM_FRAME_TIMER, Self::ANIM_FRAME_DURATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,8 +549,8 @@ impl EventCtx {
|
|||||||
self.transition_out = None;
|
self.transition_out = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_timer(&mut self, token: TimerToken, deadline: Duration) {
|
fn register_timer(&mut self, token: TimerToken, duration: Duration) {
|
||||||
if self.timers.push((token, deadline)).is_err() {
|
if self.timers.push((token, duration)).is_err() {
|
||||||
// The timer queue is full, this would be a development error in the layout
|
// The timer queue is full, this would be a development error in the layout
|
||||||
// layer. Let's panic in the debug env.
|
// layer. Let's panic in the debug env.
|
||||||
#[cfg(feature = "ui_debug")]
|
#[cfg(feature = "ui_debug")]
|
||||||
|
@ -173,7 +173,7 @@ impl LayoutObjInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Timer callback is expected to be a callable object of the following
|
/// Timer callback is expected to be a callable object of the following
|
||||||
/// form: `def timer(token: int, deadline_in_ms: int)`.
|
/// form: `def timer(token: int, duration_ms: int)`.
|
||||||
fn obj_set_timer_fn(&mut self, timer_fn: Obj) {
|
fn obj_set_timer_fn(&mut self, timer_fn: Obj) {
|
||||||
self.timer_fn = timer_fn;
|
self.timer_fn = timer_fn;
|
||||||
}
|
}
|
||||||
@ -226,13 +226,13 @@ impl LayoutObjInner {
|
|||||||
// painting by now, and we're prepared for a paint pass.
|
// painting by now, and we're prepared for a paint pass.
|
||||||
|
|
||||||
// Drain any pending timers into the callback.
|
// Drain any pending timers into the callback.
|
||||||
while let Some((token, deadline)) = self.event_ctx.pop_timer() {
|
while let Some((token, duration)) = self.event_ctx.pop_timer() {
|
||||||
let token = token.try_into();
|
let token = token.try_into();
|
||||||
let deadline = deadline.try_into();
|
let duration = duration.try_into();
|
||||||
if let (Ok(token), Ok(deadline)) = (token, deadline) {
|
if let (Ok(token), Ok(duration)) = (token, duration) {
|
||||||
self.timer_fn.call_with_n_args(&[token, deadline])?;
|
self.timer_fn.call_with_n_args(&[token, duration])?;
|
||||||
} else {
|
} else {
|
||||||
// Failed to convert token or deadline into `Obj`, skip.
|
// Failed to convert token or duration into `Obj`, skip.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ impl MultiTapKeyboard {
|
|||||||
|
|
||||||
// If the key has more then one character, we need to set it as pending, so we
|
// If the key has more then one character, we need to set it as pending, so we
|
||||||
// can cycle through on the repeated clicks. We also request a timer so we can
|
// can cycle through on the repeated clicks. We also request a timer so we can
|
||||||
// reset the pending state after a deadline.
|
// reset the pending state after it elapses.
|
||||||
//
|
//
|
||||||
// Note: It might seem that we should make sure to `request_paint` in case we
|
// Note: It might seem that we should make sure to `request_paint` in case we
|
||||||
// progress into a pending state (to display the pending marker), but such
|
// progress into a pending state (to display the pending marker), but such
|
||||||
|
@ -1633,7 +1633,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
/// """Attach a timer setter function.
|
/// """Attach a timer setter function.
|
||||||
///
|
///
|
||||||
/// The layout object can call the timer setter with two arguments,
|
/// The layout object can call the timer setter with two arguments,
|
||||||
/// `token` and `deadline`. When `deadline` is reached, the layout object
|
/// `token` and `duration`. When `duration` elapses, the layout object
|
||||||
/// expects a callback to `self.timer(token)`.
|
/// expects a callback to `self.timer(token)`.
|
||||||
/// """
|
/// """
|
||||||
///
|
///
|
||||||
@ -1655,7 +1655,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
/// """Callback for the timer set by `attach_timer_fn`.
|
/// """Callback for the timer set by `attach_timer_fn`.
|
||||||
///
|
///
|
||||||
/// This function should be called by the executor after the corresponding
|
/// This function should be called by the executor after the corresponding
|
||||||
/// deadline is reached.
|
/// duration elapses.
|
||||||
/// """
|
/// """
|
||||||
///
|
///
|
||||||
/// def paint(self) -> bool:
|
/// def paint(self) -> bool:
|
||||||
|
@ -1112,7 +1112,7 @@ class LayoutObj(Generic[T]):
|
|||||||
def attach_timer_fn(self, fn: Callable[[int, int], None], attach_type: AttachType | None) -> None:
|
def attach_timer_fn(self, fn: Callable[[int, int], None], attach_type: AttachType | None) -> None:
|
||||||
"""Attach a timer setter function.
|
"""Attach a timer setter function.
|
||||||
The layout object can call the timer setter with two arguments,
|
The layout object can call the timer setter with two arguments,
|
||||||
`token` and `deadline`. When `deadline` is reached, the layout object
|
`token` and `duration`. When `duration` elapses, the layout object
|
||||||
expects a callback to `self.timer(token)`.
|
expects a callback to `self.timer(token)`.
|
||||||
"""
|
"""
|
||||||
if utils.USE_TOUCH:
|
if utils.USE_TOUCH:
|
||||||
@ -1128,7 +1128,7 @@ class LayoutObj(Generic[T]):
|
|||||||
def timer(self, token: int) -> T | None:
|
def timer(self, token: int) -> T | None:
|
||||||
"""Callback for the timer set by `attach_timer_fn`.
|
"""Callback for the timer set by `attach_timer_fn`.
|
||||||
This function should be called by the executor after the corresponding
|
This function should be called by the executor after the corresponding
|
||||||
deadline is reached.
|
duration elapses.
|
||||||
"""
|
"""
|
||||||
def paint(self) -> bool:
|
def paint(self) -> bool:
|
||||||
"""Paint the layout object on screen.
|
"""Paint the layout object on screen.
|
||||||
|
@ -283,7 +283,7 @@ class Layout(Generic[T]):
|
|||||||
# Turn the brightness on.
|
# Turn the brightness on.
|
||||||
backlight_fade(self.BACKLIGHT_LEVEL)
|
backlight_fade(self.BACKLIGHT_LEVEL)
|
||||||
|
|
||||||
def _set_timer(self, token: int, deadline: int) -> None:
|
def _set_timer(self, token: int, duration: int) -> None:
|
||||||
"""Timer callback for Rust layouts."""
|
"""Timer callback for Rust layouts."""
|
||||||
|
|
||||||
async def timer_task() -> None:
|
async def timer_task() -> None:
|
||||||
@ -300,7 +300,8 @@ class Layout(Generic[T]):
|
|||||||
assert token not in self.timers
|
assert token not in self.timers
|
||||||
task = timer_task()
|
task = timer_task()
|
||||||
self.timers[token] = task
|
self.timers[token] = task
|
||||||
loop.schedule(task, token, deadline)
|
deadline = utime.ticks_add(utime.ticks_ms(), duration)
|
||||||
|
loop.schedule(task, deadline=deadline)
|
||||||
|
|
||||||
def _emit_message(self, msg: Any) -> None:
|
def _emit_message(self, msg: Any) -> None:
|
||||||
"""Process a message coming out of the Rust layout. Set is as a result and shut
|
"""Process a message coming out of the Rust layout. Set is as a result and shut
|
||||||
|
@ -28,7 +28,7 @@ if __debug__:
|
|||||||
|
|
||||||
def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None:
|
def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None:
|
||||||
# Simple drawing not supported for layouts that set timers.
|
# Simple drawing not supported for layouts that set timers.
|
||||||
def dummy_set_timer(token: int, deadline: int) -> None:
|
def dummy_set_timer(token: int, duration: int) -> None:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
layout.attach_timer_fn(dummy_set_timer, None)
|
layout.attach_timer_fn(dummy_set_timer, None)
|
||||||
|
@ -28,7 +28,7 @@ if __debug__:
|
|||||||
|
|
||||||
def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None:
|
def draw_simple(layout: trezorui2.LayoutObj[Any]) -> None:
|
||||||
# Simple drawing not supported for layouts that set timers.
|
# Simple drawing not supported for layouts that set timers.
|
||||||
def dummy_set_timer(token: int, deadline: int) -> None:
|
def dummy_set_timer(token: int, duration: int) -> None:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
layout.attach_timer_fn(dummy_set_timer, None)
|
layout.attach_timer_fn(dummy_set_timer, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user