diff --git a/core/embed/rust/src/ui/display.rs b/core/embed/rust/src/ui/display.rs index 77738373c..4ad89cd79 100644 --- a/core/embed/rust/src/ui/display.rs +++ b/core/embed/rust/src/ui/display.rs @@ -1,4 +1,4 @@ -use crate::trezorhal::display; +use crate::{micropython::time, time::Duration, trezorhal::display}; #[cfg(not(feature = "model_tt"))] use crate::ui::model_t1::constant; @@ -23,8 +23,30 @@ pub fn screen() -> Rect { Rect::from_top_left_and_size(Point::zero(), size()) } -pub fn backlight(val: i32) -> i32 { - display::backlight(val) +pub fn backlight() -> i32 { + display::backlight(-1) +} + +pub fn set_backlight(val: i32) { + display::backlight(val); +} + +pub fn fade_backlight(target: i32) { + const BACKLIGHT_DELAY: Duration = Duration::from_millis(14); + const BACKLIGHT_STEP: usize = 15; + + let current = backlight(); + if current < target { + for val in (current..target).step_by(BACKLIGHT_STEP) { + set_backlight(val); + time::sleep(BACKLIGHT_DELAY); + } + } else { + for val in (target..current).rev().step_by(BACKLIGHT_STEP) { + set_backlight(val); + time::sleep(BACKLIGHT_DELAY); + } + } } pub fn rect(r: Rect, fg_color: Color) { diff --git a/core/embed/rust/src/ui/model_tt/component/swipe.rs b/core/embed/rust/src/ui/model_tt/component/swipe.rs index 0edd852bc..91d3f79c5 100644 --- a/core/embed/rust/src/ui/model_tt/component/swipe.rs +++ b/core/embed/rust/src/ui/model_tt/component/swipe.rs @@ -77,7 +77,7 @@ impl Swipe { let start = self.backlight_start as f32; let end = self.backlight_end as f32; let value = start + ratio * (end - start); - display::backlight(value as i32); + display::set_backlight(value as i32); } }