diff --git a/core/embed/rust/src/ui/display/mod.rs b/core/embed/rust/src/ui/display/mod.rs index e95fb11bb..390c977ef 100644 --- a/core/embed/rust/src/ui/display/mod.rs +++ b/core/embed/rust/src/ui/display/mod.rs @@ -49,44 +49,44 @@ use crate::trezorhal::{ }; use crate::ui::constant::WIDTH; -pub fn backlight() -> u16 { - display::backlight(-1) as u16 +pub fn backlight() -> u8 { + display::backlight(-1) as u8 } #[cfg(feature = "backlight")] -pub fn set_backlight(val: u16) { +pub fn set_backlight(val: u8) { display::backlight(val as i32); } #[cfg(feature = "backlight")] -pub fn fade_backlight(target: u16) { +pub fn fade_backlight(target: u8) { const FADE_DURATION_MS: u32 = 50; fade_backlight_duration(target, FADE_DURATION_MS); } #[cfg(feature = "backlight")] -pub fn fade_backlight_duration(target: u16, duration_ms: u32) { +pub fn fade_backlight_duration(target: u8, duration_ms: u32) { let target = target as i32; let duration_ms = duration_ms as i32; let current = backlight() as i32; for i in 0..duration_ms { let val = i32::lerp(current, target, i as f32 / duration_ms as f32); - set_backlight(val as u16); + set_backlight(val as u8); time::sleep(Duration::from_millis(1)); } //account for imprecise rounding - set_backlight(target as u16); + set_backlight(target as u8); } #[cfg(not(feature = "backlight"))] -pub fn set_backlight(_: u16) {} +pub fn set_backlight(_: u8) {} #[cfg(not(feature = "backlight"))] -pub fn fade_backlight(_: u16) {} +pub fn fade_backlight(_: u8) {} #[cfg(not(feature = "backlight"))] -pub fn fade_backlight_duration(_: u16, _: u32) {} +pub fn fade_backlight_duration(_: u8, _: u32) {} #[cfg(not(feature = "framebuffer"))] /// Fill a whole rectangle with a specific color. diff --git a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs index 22a391d6c..1e2e470dd 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs @@ -1,4 +1,4 @@ -use core::sync::atomic::{AtomicU16, Ordering}; +use core::sync::atomic::{AtomicU8, Ordering}; use crate::{ error::Error, @@ -63,7 +63,7 @@ impl FlowState for SetBrightness { } } -static BRIGHTNESS: AtomicU16 = AtomicU16::new(0); +static BRIGHTNESS: AtomicU8 = AtomicU8::new(0); #[allow(clippy::not_unsafe_ptr_arg_deref)] pub extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { @@ -72,13 +72,13 @@ pub extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *m impl SetBrightness { fn new_obj(_args: &[Obj], kwargs: &Map) -> Result { - let current: Option = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?; + let current: Option = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?; let content_slider = Frame::left_aligned( TR::brightness__title.into(), NumberInputSliderDialog::new( - theme::backlight::get_backlight_min(), - theme::backlight::get_backlight_max(), - current.unwrap_or(theme::backlight::get_backlight_normal()), + theme::backlight::get_backlight_min() as u16, + theme::backlight::get_backlight_max() as u16, + current.unwrap_or(theme::backlight::get_backlight_normal()) as u16, ), ) .with_subtitle(TR::homescreen__settings_subtitle.into()) @@ -87,7 +87,7 @@ impl SetBrightness { .map(|msg| match msg { FrameMsg::Content(NumberInputSliderDialogMsg::Changed(n)) => { display::backlight(n as _); - BRIGHTNESS.store(n, Ordering::Relaxed); + BRIGHTNESS.store(n as u8, Ordering::Relaxed); None } FrameMsg::Button(_) => Some(FlowMsg::Info), @@ -114,7 +114,7 @@ impl SetBrightness { .with_swipe(SwipeDirection::Left, SwipeSettings::default()) .map(move |msg| match msg { FrameMsg::Content(()) => { - let _ = storage::set_brightness(BRIGHTNESS.load(Ordering::Relaxed) as u8); + let _ = storage::set_brightness(BRIGHTNESS.load(Ordering::Relaxed)); Some(FlowMsg::Confirmed) } FrameMsg::Button(_) => Some(FlowMsg::Info), diff --git a/core/embed/rust/src/ui/model_mercury/mod.rs b/core/embed/rust/src/ui/model_mercury/mod.rs index 0c57214d1..85dde610d 100644 --- a/core/embed/rust/src/ui/model_mercury/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/mod.rs @@ -33,27 +33,27 @@ impl UIFeaturesCommon for ModelMercuryFeatures { } #[cfg(feature = "backlight")] - fn get_backlight_none() -> u16 { + fn get_backlight_none() -> u8 { backlight::get_backlight_none() } #[cfg(feature = "backlight")] - fn get_backlight_normal() -> u16 { + fn get_backlight_normal() -> u8 { backlight::get_backlight_normal() } #[cfg(feature = "backlight")] - fn get_backlight_low() -> u16 { + fn get_backlight_low() -> u8 { backlight::get_backlight_low() } #[cfg(feature = "backlight")] - fn get_backlight_dim() -> u16 { + fn get_backlight_dim() -> u8 { backlight::get_backlight_dim() } #[cfg(feature = "backlight")] - fn get_backlight_max() -> u16 { + fn get_backlight_max() -> u8 { backlight::get_backlight_max() } diff --git a/core/embed/rust/src/ui/model_mercury/theme/backlight.rs b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs index 7dca47cc3..fd92eed53 100644 --- a/core/embed/rust/src/ui/model_mercury/theme/backlight.rs +++ b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs @@ -10,43 +10,41 @@ const BACKLIGHT_MIN: u8 = 10; const BACKLIGHT_MAX: u8 = 255; #[cfg(feature = "bootloader")] -pub fn get_backlight_normal() -> u16 { - BACKLIGHT_NORMAL.into() +pub fn get_backlight_normal() -> u8 { + BACKLIGHT_NORMAL } #[cfg(not(feature = "bootloader"))] -pub fn get_backlight_normal() -> u16 { +pub fn get_backlight_normal() -> u8 { storage::get_brightness() .unwrap_or(BACKLIGHT_NORMAL) .clamp(BACKLIGHT_MIN, BACKLIGHT_MAX) - .into() } #[cfg(feature = "bootloader")] -pub fn get_backlight_low() -> u16 { - BACKLIGHT_LOW.into() +pub fn get_backlight_low() -> u8 { + BACKLIGHT_LOW } #[cfg(not(feature = "bootloader"))] -pub fn get_backlight_low() -> u16 { +pub fn get_backlight_low() -> u8 { storage::get_brightness() .unwrap_or(BACKLIGHT_LOW) .clamp(BACKLIGHT_MIN, BACKLIGHT_LOW) - .into() } -pub fn get_backlight_dim() -> u16 { - BACKLIGHT_DIM.into() +pub fn get_backlight_dim() -> u8 { + BACKLIGHT_DIM } -pub fn get_backlight_none() -> u16 { - BACKLIGHT_NONE.into() +pub fn get_backlight_none() -> u8 { + BACKLIGHT_NONE } -pub fn get_backlight_max() -> u16 { - BACKLIGHT_MAX.into() +pub fn get_backlight_max() -> u8 { + BACKLIGHT_MAX } -pub fn get_backlight_min() -> u16 { - BACKLIGHT_MIN.into() +pub fn get_backlight_min() -> u8 { + BACKLIGHT_MIN } diff --git a/core/embed/rust/src/ui/model_tt/component/page.rs b/core/embed/rust/src/ui/model_tt/component/page.rs index b893d12a9..1d59d7ba5 100644 --- a/core/embed/rust/src/ui/model_tt/component/page.rs +++ b/core/embed/rust/src/ui/model_tt/component/page.rs @@ -43,7 +43,7 @@ pub struct ButtonPage { /// Whether to pass-through right swipe to parent component. swipe_right: bool, /// Fade to given backlight level on next paint(). - fade: Cell>, + fade: Cell>, } impl ButtonPage diff --git a/core/embed/rust/src/ui/model_tt/component/set_brightness.rs b/core/embed/rust/src/ui/model_tt/component/set_brightness.rs index d47c84de8..0de97478f 100644 --- a/core/embed/rust/src/ui/model_tt/component/set_brightness.rs +++ b/core/embed/rust/src/ui/model_tt/component/set_brightness.rs @@ -17,12 +17,12 @@ use super::{ pub struct SetBrightnessDialog(NumberInputSliderDialog); impl SetBrightnessDialog { - pub fn new(current: Option) -> Self { + pub fn new(current: Option) -> Self { let current = current.unwrap_or(theme::backlight::get_backlight_normal()); Self(NumberInputSliderDialog::new( - theme::backlight::get_backlight_min(), - theme::backlight::get_backlight_max(), - current, + theme::backlight::get_backlight_min() as u16, + theme::backlight::get_backlight_max() as u16, + current as u16, )) } } diff --git a/core/embed/rust/src/ui/model_tt/component/simple_page.rs b/core/embed/rust/src/ui/model_tt/component/simple_page.rs index a24bf9b65..4941fef3f 100644 --- a/core/embed/rust/src/ui/model_tt/component/simple_page.rs +++ b/core/embed/rust/src/ui/model_tt/component/simple_page.rs @@ -18,7 +18,7 @@ pub struct SimplePage { scrollbar: ScrollBar, axis: Axis, swipe_right_to_go_back: bool, - fade: Cell>, + fade: Cell>, } impl SimplePage 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 3539900d4..5902c903e 100644 --- a/core/embed/rust/src/ui/model_tt/component/swipe.rs +++ b/core/embed/rust/src/ui/model_tt/component/swipe.rs @@ -20,8 +20,8 @@ pub struct Swipe { pub allow_down: bool, pub allow_left: bool, pub allow_right: bool, - backlight_start: u16, - backlight_end: u16, + backlight_start: u8, + backlight_end: u8, origin: Option, } @@ -82,7 +82,7 @@ impl Swipe { let start = self.backlight_start as f32; let end = self.backlight_end as f32; let value = start + ratio * (end - start); - display::set_backlight(value as u16); + display::set_backlight(value as u8); } } diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 7417679a7..f68f377b6 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -1316,7 +1316,7 @@ extern "C" fn new_request_number(n_args: usize, args: *const Obj, kwargs: *mut M extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { - let current: Option = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?; + let current: Option = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?; let obj = LayoutObj::new(Frame::centered( theme::label_title(), TR::brightness__title.into(), diff --git a/core/embed/rust/src/ui/model_tt/mod.rs b/core/embed/rust/src/ui/model_tt/mod.rs index 4754ee74e..eb97b3e3e 100644 --- a/core/embed/rust/src/ui/model_tt/mod.rs +++ b/core/embed/rust/src/ui/model_tt/mod.rs @@ -34,27 +34,27 @@ impl UIFeaturesCommon for ModelTTFeatures { } #[cfg(feature = "backlight")] - fn get_backlight_none() -> u16 { + fn get_backlight_none() -> u8 { backlight::get_backlight_none() } #[cfg(feature = "backlight")] - fn get_backlight_normal() -> u16 { + fn get_backlight_normal() -> u8 { backlight::get_backlight_normal() } #[cfg(feature = "backlight")] - fn get_backlight_low() -> u16 { + fn get_backlight_low() -> u8 { backlight::get_backlight_low() } #[cfg(feature = "backlight")] - fn get_backlight_dim() -> u16 { + fn get_backlight_dim() -> u8 { backlight::get_backlight_dim() } #[cfg(feature = "backlight")] - fn get_backlight_max() -> u16 { + fn get_backlight_max() -> u8 { backlight::get_backlight_max() } diff --git a/core/embed/rust/src/ui/model_tt/theme/backlight.rs b/core/embed/rust/src/ui/model_tt/theme/backlight.rs index 7dca47cc3..fd92eed53 100644 --- a/core/embed/rust/src/ui/model_tt/theme/backlight.rs +++ b/core/embed/rust/src/ui/model_tt/theme/backlight.rs @@ -10,43 +10,41 @@ const BACKLIGHT_MIN: u8 = 10; const BACKLIGHT_MAX: u8 = 255; #[cfg(feature = "bootloader")] -pub fn get_backlight_normal() -> u16 { - BACKLIGHT_NORMAL.into() +pub fn get_backlight_normal() -> u8 { + BACKLIGHT_NORMAL } #[cfg(not(feature = "bootloader"))] -pub fn get_backlight_normal() -> u16 { +pub fn get_backlight_normal() -> u8 { storage::get_brightness() .unwrap_or(BACKLIGHT_NORMAL) .clamp(BACKLIGHT_MIN, BACKLIGHT_MAX) - .into() } #[cfg(feature = "bootloader")] -pub fn get_backlight_low() -> u16 { - BACKLIGHT_LOW.into() +pub fn get_backlight_low() -> u8 { + BACKLIGHT_LOW } #[cfg(not(feature = "bootloader"))] -pub fn get_backlight_low() -> u16 { +pub fn get_backlight_low() -> u8 { storage::get_brightness() .unwrap_or(BACKLIGHT_LOW) .clamp(BACKLIGHT_MIN, BACKLIGHT_LOW) - .into() } -pub fn get_backlight_dim() -> u16 { - BACKLIGHT_DIM.into() +pub fn get_backlight_dim() -> u8 { + BACKLIGHT_DIM } -pub fn get_backlight_none() -> u16 { - BACKLIGHT_NONE.into() +pub fn get_backlight_none() -> u8 { + BACKLIGHT_NONE } -pub fn get_backlight_max() -> u16 { - BACKLIGHT_MAX.into() +pub fn get_backlight_max() -> u8 { + BACKLIGHT_MAX } -pub fn get_backlight_min() -> u16 { - BACKLIGHT_MIN.into() +pub fn get_backlight_min() -> u8 { + BACKLIGHT_MIN } diff --git a/core/embed/rust/src/ui/ui_features.rs b/core/embed/rust/src/ui/ui_features.rs index d45e48cae..41e507ff5 100644 --- a/core/embed/rust/src/ui/ui_features.rs +++ b/core/embed/rust/src/ui/ui_features.rs @@ -11,19 +11,19 @@ pub trait UIFeaturesCommon { fn fadeout() {} fn backlight_on() {} - fn get_backlight_none() -> u16 { + fn get_backlight_none() -> u8 { 0 } - fn get_backlight_normal() -> u16 { + fn get_backlight_normal() -> u8 { 0 } - fn get_backlight_low() -> u16 { + fn get_backlight_low() -> u8 { 0 } - fn get_backlight_dim() -> u16 { + fn get_backlight_dim() -> u8 { 0 } - fn get_backlight_max() -> u16 { + fn get_backlight_max() -> u8 { 0 }