diff --git a/core/Makefile b/core/Makefile index 04b327435..4aebf6db6 100644 --- a/core/Makefile +++ b/core/Makefile @@ -121,7 +121,7 @@ pyright: python ../tools/pyright_tool.py clippy: - cd embed/rust ; cargo clippy + cd embed/rust ; cargo clippy --all-features ## code generation: diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index a7432a627..be3eadc3a 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -8,11 +8,14 @@ build = "build.rs" [features] default = ["model_tt"] bitcoin_only = [] -model_tt = [] -model_t1 = [] -model_tr = [] +model_tt = ["touch"] +model_t1 = ["buttons"] +model_tr = ["buttons"] ui = [] ui_debug = [] +buttons = [] +touch = [] +clippy = [] test = ["cc", "glob"] [lib] diff --git a/core/embed/rust/src/lib.rs b/core/embed/rust/src/lib.rs index 5f57eab3a..2fc1779b0 100644 --- a/core/embed/rust/src/lib.rs +++ b/core/embed/rust/src/lib.rs @@ -19,7 +19,7 @@ pub mod ui; mod util; #[cfg(not(test))] -#[cfg(not(feature = "test"))] +#[cfg(any(not(feature = "test"), feature = "clippy"))] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { use cstr_core::CStr; diff --git a/core/embed/rust/src/ui/component/base.rs b/core/embed/rust/src/ui/component/base.rs index c71c5d881..006cc4352 100644 --- a/core/embed/rust/src/ui/component/base.rs +++ b/core/embed/rust/src/ui/component/base.rs @@ -7,9 +7,9 @@ use crate::{ ui::{component::Map, geometry::Rect}, }; -#[cfg(any(feature = "model_t1", feature = "model_tr"))] +#[cfg(feature = "buttons")] use crate::ui::event::ButtonEvent; -#[cfg(feature = "model_tt")] +#[cfg(feature = "touch")] use crate::ui::event::TouchEvent; /// Type used by components that do not return any messages. @@ -219,9 +219,9 @@ where #[derive(Copy, Clone, PartialEq, Eq)] pub enum Event { - #[cfg(any(feature = "model_t1", feature = "model_tr"))] + #[cfg(feature = "buttons")] Button(ButtonEvent), - #[cfg(feature = "model_tt")] + #[cfg(feature = "touch")] Touch(TouchEvent), /// Previously requested timer was triggered. This invalidates the timer /// token (another timer has to be requested). diff --git a/core/embed/rust/src/ui/constant.rs b/core/embed/rust/src/ui/constant.rs new file mode 100644 index 000000000..d329c74bb --- /dev/null +++ b/core/embed/rust/src/ui/constant.rs @@ -0,0 +1,13 @@ +//! Reexporting the `constant` module according to the +//! current feature (Trezor model) + +#[cfg(feature = "model_t1")] +pub use super::model_t1::constant::*; +#[cfg(all(feature = "model_tr", not(feature = "model_t1")))] +pub use super::model_tr::constant::*; +#[cfg(all( + feature = "model_tt", + not(feature = "model_tr"), + not(feature = "model_t1") +))] +pub use super::model_tt::constant::*; diff --git a/core/embed/rust/src/ui/display.rs b/core/embed/rust/src/ui/display.rs index bbf1ce385..a5da26e76 100644 --- a/core/embed/rust/src/ui/display.rs +++ b/core/embed/rust/src/ui/display.rs @@ -1,12 +1,6 @@ +use super::constant; use crate::{micropython::time, time::Duration, trezorhal::display}; -#[cfg(feature = "model_t1")] -use crate::ui::model_t1::constant; -#[cfg(feature = "model_tr")] -use crate::ui::model_tr::constant; -#[cfg(feature = "model_tt")] -use crate::ui::model_tt::constant; - use super::geometry::{Offset, Point, Rect}; pub fn backlight() -> i32 { @@ -233,7 +227,7 @@ impl Color { self.0 } - pub fn neg(self) -> Self { + pub fn negate(self) -> Self { Self(!self.0) } } diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs index 756f9a86f..cf95cebd8 100644 --- a/core/embed/rust/src/ui/layout/obj.rs +++ b/core/embed/rust/src/ui/layout/obj.rs @@ -15,23 +15,17 @@ use crate::{ time::Duration, ui::{ component::{Child, Component, Event, EventCtx, Never, TimerToken}, + constant, geometry::Rect, }, util, }; -#[cfg(any(feature = "model_t1", feature = "model_tr"))] +#[cfg(feature = "buttons")] use crate::ui::event::ButtonEvent; -#[cfg(feature = "model_tt")] +#[cfg(feature = "touch")] use crate::ui::event::TouchEvent; -#[cfg(feature = "model_t1")] -use crate::ui::model_t1::constant; -#[cfg(feature = "model_tr")] -use crate::ui::model_tr::constant; -#[cfg(feature = "model_tt")] -use crate::ui::model_tt::constant; - /// Conversion trait implemented by components that know how to convert their /// message values into MicroPython `Obj`s. We can automatically implement /// `ComponentMsgObj` for components whose message types implement `TryInto`. @@ -354,7 +348,7 @@ extern "C" fn ui_layout_set_timer_fn(this: Obj, timer_fn: Obj) -> Obj { unsafe { util::try_or_raise(block) } } -#[cfg(feature = "model_tt")] +#[cfg(feature = "touch")] extern "C" fn ui_layout_touch_event(n_args: usize, args: *const Obj) -> Obj { let block = |args: &[Obj], _kwargs: &Map| { if args.len() != 4 { @@ -372,12 +366,12 @@ extern "C" fn ui_layout_touch_event(n_args: usize, args: *const Obj) -> Obj { unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) } } -#[cfg(any(feature = "model_t1", feature = "model_tr"))] +#[cfg(not(feature = "touch"))] extern "C" fn ui_layout_touch_event(_n_args: usize, _args: *const Obj) -> Obj { Obj::const_none() } -#[cfg(any(feature = "model_t1", feature = "model_tr"))] +#[cfg(feature = "buttons")] extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj { let block = |args: &[Obj], _kwargs: &Map| { if args.len() != 3 { @@ -391,7 +385,7 @@ extern "C" fn ui_layout_button_event(n_args: usize, args: *const Obj) -> Obj { unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) } } -#[cfg(feature = "model_tt")] +#[cfg(not(feature = "buttons"))] extern "C" fn ui_layout_button_event(_n_args: usize, _args: *const Obj) -> Obj { Obj::const_none() } diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index 8fe91294d..1ca837741 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -3,6 +3,7 @@ pub mod macros; pub mod animation; pub mod component; +pub mod constant; pub mod display; pub mod event; pub mod geometry; diff --git a/core/embed/rust/src/ui/model_t1/component/button.rs b/core/embed/rust/src/ui/model_t1/component/button.rs index 3f3a725b1..cf9ee45d0 100644 --- a/core/embed/rust/src/ui/model_t1/component/button.rs +++ b/core/embed/rust/src/ui/model_t1/component/button.rs @@ -92,7 +92,7 @@ impl> Button { let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2); - return (area, start_of_baseline); + (area, start_of_baseline) } } @@ -130,7 +130,7 @@ where match &self.content { ButtonContent::Text(text) => { - let background_color = style.text_color.neg(); + let background_color = style.text_color.negate(); if style.border_horiz { display::rect_fill_rounded1(self.area, background_color, theme::BG); } else { diff --git a/core/embed/rust/src/ui/model_tr/component/button.rs b/core/embed/rust/src/ui/model_tr/component/button.rs index 3f3a725b1..cf9ee45d0 100644 --- a/core/embed/rust/src/ui/model_tr/component/button.rs +++ b/core/embed/rust/src/ui/model_tr/component/button.rs @@ -92,7 +92,7 @@ impl> Button { let start_of_baseline = area.bottom_left() + Offset::new(border_width, -2); - return (area, start_of_baseline); + (area, start_of_baseline) } } @@ -130,7 +130,7 @@ where match &self.content { ButtonContent::Text(text) => { - let background_color = style.text_color.neg(); + let background_color = style.text_color.negate(); if style.border_horiz { display::rect_fill_rounded1(self.area, background_color, theme::BG); } else { diff --git a/core/embed/rust/src/ui/model_tt/component/button.rs b/core/embed/rust/src/ui/model_tt/component/button.rs index 46032c101..f0ce8ddec 100644 --- a/core/embed/rust/src/ui/model_tt/component/button.rs +++ b/core/embed/rust/src/ui/model_tt/component/button.rs @@ -255,8 +255,8 @@ where fn paint(&mut self) { let style = self.style(); - self.paint_background(&style); - self.paint_content(&style); + self.paint_background(style); + self.paint_content(style); } fn bounds(&self, sink: &mut dyn FnMut(Rect)) { diff --git a/core/embed/rust/src/ui/model_tt/component/frame.rs b/core/embed/rust/src/ui/model_tt/component/frame.rs index 86bcac91d..0a05f4b92 100644 --- a/core/embed/rust/src/ui/model_tt/component/frame.rs +++ b/core/embed/rust/src/ui/model_tt/component/frame.rs @@ -25,7 +25,7 @@ where } pub fn inner(&self) -> &T { - &self.content.inner() + self.content.inner() } } diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs index fc19e97e2..b91b24b02 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs @@ -92,7 +92,7 @@ impl Component for Bip39Input { let style = self.button.style(); // First, paint the button background. - self.button.paint_background(&style); + self.button.paint_background(style); // Paint the entered content (the prefix of the suggested word). let text = self.textbox.content(); diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs index b4f008d07..548d4d0a4 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs @@ -115,7 +115,7 @@ impl Component for Slip39Input { let style = self.button.style(); // First, paint the button background. - self.button.paint_background(&style); + self.button.paint_background(style); // Content starts in the left-center point, offset by 16px to the right and 8px // to the bottom.