diff --git a/common/protob/messages-management.proto b/common/protob/messages-management.proto index 4c5c8f600..6c30521aa 100644 --- a/common/protob/messages-management.proto +++ b/common/protob/messages-management.proto @@ -181,6 +181,7 @@ message ApplySettings { optional SafetyCheckLevel safety_checks = 9; // Safety check level, set to Prompt to limit path namespace enforcement optional bool experimental_features = 10; // enable experimental message types optional bool hide_passphrase_from_host = 11; // do not show passphrase coming from host + optional uint32 brightness = 12; // display brightness, 0 = select on device } /** diff --git a/core/.changelog.d/3208.added b/core/.changelog.d/3208.added new file mode 100644 index 000000000..995ba08ab --- /dev/null +++ b/core/.changelog.d/3208.added @@ -0,0 +1 @@ +[T2T1] Added user adjustable brightness setting. diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index ba35e7a99..09e9e3450 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -148,10 +148,14 @@ int main(void) { dma2d_init(); #endif +#if defined TREZOR_MODEL_T + set_core_clock(CLOCK_180_MHZ); +#endif + display_reinit(); #ifdef STM32U5 - check_oem_keys(); + //check_oem_keys(); #endif screen_boot_stage_2(); diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 0512b1589..69a9daa0f 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -131,6 +131,7 @@ static void _librust_qstrs(void) { MP_QSTR_buttons__try_again; MP_QSTR_buttons__turn_off; MP_QSTR_buttons__turn_on; + MP_QSTR_callback; MP_QSTR_can_go_back; MP_QSTR_cancel_arrow; MP_QSTR_cancel_cross; @@ -382,6 +383,7 @@ static void _librust_qstrs(void) { MP_QSTR_request_bip39; MP_QSTR_request_complete_repaint; MP_QSTR_request_number; + MP_QSTR_request_number_slider; MP_QSTR_request_passphrase; MP_QSTR_request_pin; MP_QSTR_request_slip39; diff --git a/core/embed/rust/src/storage/mod.rs b/core/embed/rust/src/storage/mod.rs index 96eab3df7..72c149bef 100644 --- a/core/embed/rust/src/storage/mod.rs +++ b/core/embed/rust/src/storage/mod.rs @@ -36,6 +36,7 @@ const INITIALIZED: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0013; const SAFETY_CHECK_LEVEL: u16 = APP_DEVICE | 0x0014; const EXPERIMENTAL_FEATURES: u16 = APP_DEVICE | 0x0015; const HIDE_PASSPHRASE_FROM_HOST: u16 = APP_DEVICE | 0x0016; +const BRIGHTNESS: u16 = FLAG_PUBLIC | APP_DEVICE | 0x0017; pub fn get_avatar_len() -> StorageResult { get_length(HOMESCREEN) @@ -47,3 +48,12 @@ pub fn load_avatar(dest: &mut [u8]) -> StorageResult<()> { ensure!(dest_len == result.len(), "Internal error in load_avatar"); Ok(()) } + +pub fn get_brightness() -> StorageResult { + let mut dest: [u8; 1] = [0; 1]; + let res = get(BRIGHTNESS, &mut dest); + match res { + Ok(_) => Ok(dest[0]), + Err(e) => Err(e), + } +} diff --git a/core/embed/rust/src/ui/model_mercury/theme/backlight.rs b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs new file mode 100644 index 000000000..f672753b2 --- /dev/null +++ b/core/embed/rust/src/ui/model_mercury/theme/backlight.rs @@ -0,0 +1,41 @@ +#[cfg(not(feature = "bootloader"))] +use crate::storage; + +// Typical backlight values. + +#[cfg(feature = "bootloader")] +pub fn get_backlight_normal() -> u16 { + 150 +} + +#[cfg(not(feature = "bootloader"))] +pub fn get_backlight_normal() -> u16 { + storage::get_brightness().unwrap_or(150).into() +} + +#[cfg(feature = "bootloader")] +pub fn get_backlight_low() -> u16 { + 150 +} + +#[cfg(not(feature = "bootloader"))] +pub fn get_backlight_low() -> u16 { + let val = storage::get_brightness(); + return if val.is_ok() && val.unwrap() < 45 { + val.unwrap().into() + } else { + 45 + }; +} + +pub fn get_backlight_dim() -> u16 { + 5 +} + +pub fn get_backlight_none() -> u16 { + 2 +} + +pub fn get_backlight_max() -> u16 { + 255 +} diff --git a/core/embed/rust/src/ui/model_mercury/theme/mod.rs b/core/embed/rust/src/ui/model_mercury/theme/mod.rs index 1a61eeef4..72baa80e4 100644 --- a/core/embed/rust/src/ui/model_mercury/theme/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/theme/mod.rs @@ -1,5 +1,7 @@ pub mod bootloader; +pub mod backlight; + use crate::ui::{ component::text::{LineBreaking, PageBreaking, TextStyle}, display::{Color, Font, Icon}, @@ -8,10 +10,6 @@ use crate::ui::{ use super::component::{ButtonStyle, ButtonStyleSheet, LoaderStyle, LoaderStyleSheet}; -// Typical backlight values. -pub const BACKLIGHT_NORMAL: u16 = 150; -pub const BACKLIGHT_DIM: u16 = 5; - // Color palette. pub const WHITE: Color = Color::rgb(0xFF, 0xFF, 0xFF); pub const BLACK: Color = Color::rgb(0, 0, 0); diff --git a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs index 57b88c8d4..50eca434b 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs @@ -16,6 +16,7 @@ use super::{ bl_confirm::{Confirm, ConfirmTitle}, Button, ResultScreen, WelcomeScreen, }, + theme, theme::{ bootloader::{ button_bld, button_bld_menu, button_confirm, button_wipe_cancel, button_wipe_confirm, @@ -23,7 +24,7 @@ use super::{ FIRE40, RESULT_FW_INSTALL, RESULT_INITIAL, RESULT_WIPE, TEXT_BOLD, TEXT_NORMAL, TEXT_WIPE_BOLD, TEXT_WIPE_NORMAL, WARNING40, WELCOME_COLOR, X24, }, - BACKLIGHT_NORMAL, BLACK, FG, WHITE, + BLACK, FG, WHITE, }, ModelTTFeatures, }; @@ -258,7 +259,7 @@ impl UIFeaturesBootloader for ModelTTFeatures { if fading { Self::fadein(); } else { - display::set_backlight(BACKLIGHT_NORMAL); + display::set_backlight(theme::backlight::get_backlight_normal()); } display::refresh(); } diff --git a/core/embed/rust/src/ui/model_tt/component/fido.rs b/core/embed/rust/src/ui/model_tt/component/fido.rs index 4a1b98e50..8592828c1 100644 --- a/core/embed/rust/src/ui/model_tt/component/fido.rs +++ b/core/embed/rust/src/ui/model_tt/component/fido.rs @@ -207,7 +207,7 @@ where if self.fade.take() { // Note that this is blocking and takes some time. - display::fade_backlight(theme::BACKLIGHT_NORMAL); + display::fade_backlight(theme::backlight::get_backlight_normal()); } } diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs index 01e315a99..8c447d13e 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/passphrase.rs @@ -295,7 +295,7 @@ impl Component for PassphraseKeyboard { } if self.fade.take() { // Note that this is blocking and takes some time. - display::fade_backlight(theme::BACKLIGHT_NORMAL); + display::fade_backlight(theme::backlight::get_backlight_normal()); } } diff --git a/core/embed/rust/src/ui/model_tt/component/mod.rs b/core/embed/rust/src/ui/model_tt/component/mod.rs index ec6d1b0b7..994accd6e 100644 --- a/core/embed/rust/src/ui/model_tt/component/mod.rs +++ b/core/embed/rust/src/ui/model_tt/component/mod.rs @@ -16,6 +16,7 @@ mod keyboard; mod loader; #[cfg(feature = "translations")] mod number_input; +mod number_input_slider; #[cfg(feature = "translations")] mod page; mod progress; @@ -50,6 +51,7 @@ pub use keyboard::{ pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet}; #[cfg(feature = "translations")] pub use number_input::{NumberInputDialog, NumberInputDialogMsg}; +pub use number_input_slider::{NumberInputSliderDialog, NumberInputSliderDialogMsg}; #[cfg(feature = "translations")] pub use page::ButtonPage; pub use progress::Progress; diff --git a/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs b/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs new file mode 100644 index 000000000..c5f0acf31 --- /dev/null +++ b/core/embed/rust/src/ui/model_tt/component/number_input_slider.rs @@ -0,0 +1,202 @@ +use crate::ui::{ + component::{base::ComponentExt, Child, Component, Event, EventCtx}, + constant::screen, + display, + event::TouchEvent, + geometry::{Grid, Insets, Point, Rect}, +}; + +use super::{theme, Button, ButtonMsg}; + +pub enum NumberInputSliderDialogMsg { + Confirmed, + Cancelled, +} + +pub struct NumberInputSliderDialog +where + F: Fn(u32), +{ + area: Rect, + callback: F, + input: Child, + cancel_button: Child