mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 16:48:09 +00:00
feat(core): make brightness an u8
[no changelog]
This commit is contained in:
parent
a15dd6598f
commit
6f96585d4b
core/embed/rust/src/ui
@ -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.
|
||||
|
@ -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<Obj, Error> {
|
||||
let current: Option<u16> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
|
||||
let current: Option<u8> = 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),
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ pub struct ButtonPage<T> {
|
||||
/// Whether to pass-through right swipe to parent component.
|
||||
swipe_right: bool,
|
||||
/// Fade to given backlight level on next paint().
|
||||
fade: Cell<Option<u16>>,
|
||||
fade: Cell<Option<u8>>,
|
||||
}
|
||||
|
||||
impl<T> ButtonPage<T>
|
||||
|
@ -17,12 +17,12 @@ use super::{
|
||||
pub struct SetBrightnessDialog(NumberInputSliderDialog);
|
||||
|
||||
impl SetBrightnessDialog {
|
||||
pub fn new(current: Option<u16>) -> Self {
|
||||
pub fn new(current: Option<u8>) -> 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,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ pub struct SimplePage<T> {
|
||||
scrollbar: ScrollBar,
|
||||
axis: Axis,
|
||||
swipe_right_to_go_back: bool,
|
||||
fade: Cell<Option<u16>>,
|
||||
fade: Cell<Option<u8>>,
|
||||
}
|
||||
|
||||
impl<T> SimplePage<T>
|
||||
|
@ -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<Point>,
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<u16> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
|
||||
let current: Option<u8> = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?;
|
||||
let obj = LayoutObj::new(Frame::centered(
|
||||
theme::label_title(),
|
||||
TR::brightness__title.into(),
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user