1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

fixup! feat(core/rust): cleaner backlight functions

This commit is contained in:
tychovrahe 2022-10-04 08:17:04 +02:00
parent c8871aac1a
commit 59197d364a

View File

@ -35,30 +35,30 @@ pub use icon::{Icon, IconAndName};
#[cfg(any(feature = "model_tt", feature = "model_tr"))]
pub use loader::{loader, loader_indeterminate, LOADER_MAX, LOADER_MIN};
pub fn backlight() -> i32 {
display::backlight(-1)
pub fn backlight() -> u16 {
display::backlight(-1) as u16
}
pub fn set_backlight(val: i32) {
display::backlight(val);
pub fn set_backlight(val: u16) {
display::backlight(val as i32);
}
pub fn fade_backlight(target: i32) {
const BACKLIGHT_DELAY: Duration = Duration::from_millis(14);
const BACKLIGHT_STEP: usize = 15;
pub fn fade_backlight(target: u16) {
const FADE_DURATION_MS: u32 = 50;
fade_backlight_duration(target, FADE_DURATION_MS);
}
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 fade_backlight_duration(target: u16, 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 {
set_backlight((current + (i * (target - current)) / duration_ms) as u16);
time::sleep(Duration::from_millis(1));
}
// account for imprecise rounding
set_backlight(target as u16);
}
/// Fill a whole rectangle with a specific color.