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

model R bld

This commit is contained in:
tychovrahe 2022-11-10 17:42:01 +01:00
parent 86a3e4feb4
commit 3a93a28882
8 changed files with 184 additions and 145 deletions

View File

@ -21,7 +21,7 @@ CROSS_PORT_OPTS ?=
PRODUCTION ?= 0 PRODUCTION ?= 0
PYOPT ?= 1 PYOPT ?= 1
BITCOIN_ONLY ?= 0 BITCOIN_ONLY ?= 0
TREZOR_MODEL ?= T TREZOR_MODEL ?= R
TREZOR_MEMPERF ?= 0 TREZOR_MEMPERF ?= 0
TREZOR_EMULATOR_FROZEN ?= 0 TREZOR_EMULATOR_FROZEN ?= 0
ADDRESS_SANITIZER ?= 0 ADDRESS_SANITIZER ?= 0

View File

@ -8,9 +8,9 @@ use crate::ui::{
display::Color, display::Color,
geometry::{Point, Rect}, geometry::{Point, Rect},
model_tr::{ model_tr::{
component::{Button, ButtonMsg::Clicked}, bootloader::theme::WHITE,
component::{ButtonController, ButtonControllerMsg, ButtonLayout, ButtonPos},
constant::{HEIGHT, WIDTH}, constant::{HEIGHT, WIDTH},
theme::WHITE,
}, },
}; };
@ -33,8 +33,7 @@ pub struct Confirm {
bg_color: Color, bg_color: Color,
icon: Option<&'static [u8]>, icon: Option<&'static [u8]>,
message: Child<Paragraphs<ParagraphVecShort<&'static str>>>, message: Child<Paragraphs<ParagraphVecShort<&'static str>>>,
left: Child<Button<&'static str>>, buttons: ButtonController<&'static str>,
right: Child<Button<&'static str>>,
confirm_left: bool, confirm_left: bool,
} }
@ -43,8 +42,7 @@ impl Confirm {
bg_color: Color, bg_color: Color,
icon: Option<&'static [u8]>, icon: Option<&'static [u8]>,
message: Paragraphs<ParagraphVecShort<&'static str>>, message: Paragraphs<ParagraphVecShort<&'static str>>,
left: Button<&'static str>, text: &'static str,
right: Button<&'static str>,
confirm_left: bool, confirm_left: bool,
) -> Self { ) -> Self {
let mut instance = Self { let mut instance = Self {
@ -52,8 +50,7 @@ impl Confirm {
bg_color, bg_color,
icon, icon,
message: Child::new(message), message: Child::new(message),
left: Child::new(left), buttons: ButtonController::new(ButtonLayout::cancel_and_text(text)),
right: Child::new(right),
confirm_left, confirm_left,
}; };
instance.bg.clear(); instance.bg.clear();
@ -71,28 +68,32 @@ impl Component for Confirm {
.place(Rect::new(Point::new(10, 0), Point::new(118, 50))); .place(Rect::new(Point::new(10, 0), Point::new(118, 50)));
let button_area = bounds.split_bottom(12).1; let button_area = bounds.split_bottom(12).1;
self.left.place(button_area); self.buttons.place(button_area);
self.right.place(button_area);
bounds bounds
} }
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
if let Some(Clicked) = self.left.event(ctx, event) { match self.buttons.event(ctx, event) {
return if self.confirm_left { Some(ButtonControllerMsg::Triggered(ButtonPos::Left)) => Some(ConfirmMsg::Cancel),
Some(Self::Msg::Confirm) Some(ButtonControllerMsg::Triggered(ButtonPos::Right)) => Some(ConfirmMsg::Confirm),
} else { _ => None,
Some(Self::Msg::Cancel) }
}; // if let Some(Clicked) = self.left.event(ctx, event) {
}; // return if self.confirm_left {
if let Some(Clicked) = self.right.event(ctx, event) { // Some(Self::Msg::Confirm)
return if self.confirm_left { // } else {
Some(Self::Msg::Cancel) // Some(Self::Msg::Cancel)
} else { // };
Some(Self::Msg::Confirm) // };
}; // if let Some(Clicked) = self.right.event(ctx, event) {
}; // return if self.confirm_left {
None // Some(Self::Msg::Cancel)
// } else {
// Some(Self::Msg::Confirm)
// };
// };
//None
} }
fn paint(&mut self) { fn paint(&mut self) {
@ -108,12 +109,10 @@ impl Component for Confirm {
} }
self.message.paint(); self.message.paint();
self.left.paint(); self.buttons.paint();
self.right.paint();
} }
fn bounds(&self, sink: &mut dyn FnMut(Rect)) { fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.left.bounds(sink); self.buttons.bounds(sink);
self.right.bounds(sink);
} }
} }

View File

@ -15,8 +15,7 @@ use crate::ui::{
}; };
use crate::ui::model_tr::{ use crate::ui::model_tr::{
bootloader::theme::bld_button_default, component::{Button, ButtonPos, ButtonStyleSheet},
component::{Button, ButtonPos},
constant::{HEIGHT, WIDTH}, constant::{HEIGHT, WIDTH},
}; };
@ -55,13 +54,13 @@ impl Intro {
title: Child::new(Title::new(bld_version)), title: Child::new(Title::new(bld_version)),
host: Child::new(Button::with_text( host: Child::new(Button::with_text(
ButtonPos::Left, ButtonPos::Left,
"INSTALL FIRMWARE", "INSTALL FW",
bld_button_default(), ButtonStyleSheet::default(true, false, None, None),
)), )),
menu: Child::new(Button::with_text( menu: Child::new(Button::with_text(
ButtonPos::Right, ButtonPos::Right,
"MENU", "MENU",
bld_button_default(), ButtonStyleSheet::default(true, false, None, None),
)), )),
text: Child::new(p1), text: Child::new(p1),
}; };

View File

@ -1,9 +1,18 @@
#[cfg(feature = "ui_debug")]
use crate::trace::Tracer;
use crate::ui::{ use crate::ui::{
component::{Child, Component, Event, EventCtx, Pad}, component::{Child, Component, ComponentExt, Event, EventCtx, Pad},
geometry::{Point, Rect}, constant::screen,
display,
display::Font,
geometry::{Offset, Rect},
model_tr::{ model_tr::{
bootloader::{theme::BLD_BG, title::Title, ReturnToC}, bootloader::{
constant::{HEIGHT, WIDTH}, theme::{BLD_BG, BLD_FG},
ReturnToC,
},
component::{ChoiceFactory, ChoicePage, ChoicePageMsg},
theme::ICON_BIN,
}, },
}; };
@ -20,33 +29,71 @@ impl ReturnToC for MenuMsg {
} }
} }
const CHOICE_LENGTH: usize = 3;
pub struct MenuChoiceFactory;
impl MenuChoiceFactory {
const CHOICES: [(&'static str, &'static str, &'static [u8]); CHOICE_LENGTH] = [
("WIPE", "DEVICE", ICON_BIN.0),
("REBOOT", "TREZOR", ICON_BIN.0),
("EXIT", "MENU", ICON_BIN.0),
];
pub fn new() -> Self {
Self {}
}
fn get(&self, choice_index: u8) -> (&'static str, &'static str, &'static [u8]) {
MenuChoiceFactory::CHOICES[choice_index as usize]
}
}
impl ChoiceFactory for MenuChoiceFactory {
fn count(&self) -> u8 {
CHOICE_LENGTH as u8
}
fn paint_center(&self, choice_index: u8, _area: Rect, _inverse: bool) {
let content = self.get(choice_index);
let text_1 = content.0;
let text_2 = content.1;
let icon = content.2;
display::icon(screen().center() + Offset::y(-20), icon, BLD_FG, BLD_BG);
display::text_center(
screen().center() + Offset::y(0),
text_1,
Font::NORMAL,
BLD_FG,
BLD_BG,
);
display::text_center(
screen().center() + Offset::y(10),
text_2,
Font::NORMAL,
BLD_FG,
BLD_BG,
);
}
#[cfg(feature = "ui_debug")]
fn trace(&self, t: &mut dyn Tracer, name: &str, choice_index: u8) {
t.field(name, &self.get(choice_index));
}
}
pub struct Menu { pub struct Menu {
bg: Pad, bg: Pad,
title: Child<Title>, pg: Child<ChoicePage<MenuChoiceFactory>>,
// close: Child<Button<&'static str>>,
// reboot: Child<Button<&'static str>>,
// reset: Child<Button<&'static str>>,
} }
impl Menu { impl Menu {
pub fn new(bld_version: &'static str) -> Self { pub fn new() -> Self {
// let content_reboot = IconText::new("REBOOT", REBOOT); let choices = MenuChoiceFactory::new();
// let content_reset = IconText::new("FACTORY RESET", ERASE);
let mut instance = Self { let mut instance = Self {
bg: Pad::with_background(BLD_BG), bg: Pad::with_background(BLD_BG),
title: Child::new(Title::new(bld_version)), pg: ChoicePage::new(choices).with_carousel(true).into_child(),
// close: Child::new(
// Button::with_icon(CLOSE)
// .styled(button_bld_menu())
// .with_expanded_touch_area(Insets::uniform(13)),
// ),
// reboot: Child::new(
// Button::with_icon_and_text(content_reboot).styled(button_bld_menu_item()),
// ),
// reset: Child::new(
// Button::with_icon_and_text(content_reset).styled(button_bld_menu_item()),
// ),
}; };
instance.bg.clear(); instance.bg.clear();
instance instance
@ -57,48 +104,26 @@ impl Component for Menu {
type Msg = MenuMsg; type Msg = MenuMsg;
fn place(&mut self, bounds: Rect) -> Rect { fn place(&mut self, bounds: Rect) -> Rect {
self.bg self.bg.place(bounds);
.place(Rect::new(Point::new(0, 0), Point::new(WIDTH, HEIGHT))); self.pg.place(bounds);
self.title
.place(Rect::new(Point::new(10, 0), Point::new(128, 8)));
// self.close.place(Rect::new(
// Point::new(187, 15),
// Point::new(187 + 38, 15 + 38),
// ));
// self.reboot
// .place(Rect::new(Point::new(16, 66), Point::new(16 + 209, 66 + 48)));
// self.reset.place(Rect::new(
// Point::new(16, 122),
// Point::new(16 + 209, 122 + 48),
// ));
bounds bounds
} }
fn event(&mut self, _ctx: &mut EventCtx, _event: Event) -> Option<Self::Msg> { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
// if let Some(Clicked) = self.close.event(ctx, event) { match self.pg.event(ctx, event) {
// return Some(Self::Msg::Close); Some(ChoicePageMsg::Choice(0)) => Some(MenuMsg::FactoryReset),
// } Some(ChoicePageMsg::Choice(1)) => Some(MenuMsg::Reboot),
// if let Some(Clicked) = self.reboot.event(ctx, event) { Some(ChoicePageMsg::Choice(2)) => Some(MenuMsg::Close),
// return Some(Self::Msg::Reboot); _ => None,
// } }
// if let Some(Clicked) = self.reset.event(ctx, event) {
// return Some(Self::Msg::FactoryReset);
// }
None
} }
fn paint(&mut self) { fn paint(&mut self) {
self.bg.paint(); self.bg.paint();
self.title.paint(); self.pg.paint();
// self.close.paint();
// self.reboot.paint();
// self.reset.paint();
} }
fn bounds(&self, _sink: &mut dyn FnMut(Rect)) { fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
// self.close.bounds(sink); self.pg.bounds(sink)
// self.reboot.bounds(sink);
// self.reset.bounds(sink);
} }
} }

View File

@ -28,10 +28,9 @@ use crate::ui::{
confirm::Confirm, confirm::Confirm,
intro::Intro, intro::Intro,
menu::Menu, menu::Menu,
theme::{bld_button_cancel, bld_button_default, BLD_BG, BLD_FG}, theme::{BLD_BG, BLD_FG, LOGO_EMPTY},
}, },
component::{Button, ButtonPos, ResultScreen}, component::ResultScreen,
theme::LOGO_EMPTY,
}, },
util::{from_c_array, from_c_str}, util::{from_c_array, from_c_str},
}; };
@ -128,15 +127,11 @@ extern "C" fn screen_install_confirm(
message.add(Paragraph::new(&theme::TEXT_BOLD, "Seed will be erased!").centered()); message.add(Paragraph::new(&theme::TEXT_BOLD, "Seed will be erased!").centered());
} }
let left = Button::with_text(ButtonPos::Left, "CANCEL", bld_button_cancel());
let right = Button::with_text(ButtonPos::Right, "INSTALL", bld_button_default());
let mut frame = Confirm::new( let mut frame = Confirm::new(
BLD_BG, BLD_BG,
ICON, ICON,
Paragraphs::new(message).with_placement(LinearPlacement::vertical().align_at_center()), Paragraphs::new(message).with_placement(LinearPlacement::vertical().align_at_center()),
left, "INSTALL",
right,
false, false,
); );
@ -161,19 +156,14 @@ extern "C" fn screen_wipe_confirm() -> u32 {
let message = let message =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center()); Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let left = Button::with_text(ButtonPos::Left, "WIPE", bld_button_default()); let mut frame = Confirm::new(BLD_BG, ICON, message, "WIPE", true);
let right = Button::with_text(ButtonPos::Right, "CANCEL", bld_button_cancel());
let mut frame = Confirm::new(BLD_BG, ICON, message, left, right, true);
run(&mut frame) run(&mut frame)
} }
#[no_mangle] #[no_mangle]
extern "C" fn screen_menu(bld_version: *const cty::c_char) -> u32 { extern "C" fn screen_menu(_bld_version: *const cty::c_char) -> u32 {
let bld_version = unwrap!(unsafe { from_c_str(bld_version) }); run(&mut Menu::new())
run(&mut Menu::new(bld_version))
} }
#[no_mangle] #[no_mangle]
@ -209,7 +199,14 @@ fn screen_progress(
let fill_to = (loader_area.width() as u32 * progress as u32) / 1000; let fill_to = (loader_area.width() as u32 * progress as u32) / 1000;
display::bar_with_text_and_fill(loader_area, Some(text), fg_color, bg_color, 0, fill_to as _); display::bar_with_text_and_fill(
loader_area,
Some(&text),
fg_color,
bg_color,
0,
fill_to as _,
);
// display::text_center( // display::text_center(
// Point::new(constant::WIDTH / 2, 100), // Point::new(constant::WIDTH / 2, 100),

View File

@ -1,12 +1,10 @@
use crate::ui::{ use crate::ui::{
component::text::TextStyle, component::text::TextStyle,
display::{Color, Font}, display::{Color, Font},
model_tr::{
component::{ButtonStyle, ButtonStyleSheet},
theme::{BG, BLACK, FG, WHITE},
},
}; };
pub const WHITE: Color = Color::white();
pub const BLACK: Color = Color::black();
pub const BLD_BG: Color = BLACK; pub const BLD_BG: Color = BLACK;
pub const BLD_FG: Color = WHITE; pub const BLD_FG: Color = WHITE;
@ -16,35 +14,37 @@ pub const RADIUS: u8 = 2;
// Size of icons in the UI (i.e. inside buttons). // Size of icons in the UI (i.e. inside buttons).
pub const ICON_SIZE: i32 = 16; pub const ICON_SIZE: i32 = 16;
pub fn bld_button_default() -> ButtonStyleSheet { pub const LOGO_EMPTY: &[u8] = include_res!("model_tr/res/trezor_empty.toif");
ButtonStyleSheet {
normal: &ButtonStyle {
font: Font::NORMAL,
text_color: BG,
border_horiz: true,
},
active: &ButtonStyle {
font: Font::NORMAL,
text_color: FG,
border_horiz: true,
},
}
}
pub fn bld_button_cancel() -> ButtonStyleSheet { // pub fn bld_button_default() -> ButtonStyleSheet {
ButtonStyleSheet { // ButtonStyleSheet {
normal: &ButtonStyle { // normal: &ButtonStyle {
font: Font::NORMAL, // font: Font::NORMAL,
text_color: FG, // text_color: BG,
border_horiz: false, // border_horiz: true,
}, // },
active: &ButtonStyle { // active: &ButtonStyle {
font: Font::NORMAL, // font: Font::NORMAL,
text_color: BG, // text_color: FG,
border_horiz: false, // border_horiz: true,
}, // },
} // }
} // }
//
// pub fn bld_button_cancel() -> ButtonStyleSheet {
// ButtonStyleSheet {
// normal: &ButtonStyle {
// font: Font::NORMAL,
// text_color: FG,
// border_horiz: false,
// },
// active: &ButtonStyle {
// font: Font::NORMAL,
// text_color: BG,
// border_horiz: false,
// },
// }
// }
pub const TEXT_NORMAL: TextStyle = TextStyle::new(Font::NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG); pub const TEXT_NORMAL: TextStyle = TextStyle::new(Font::NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG);
pub const TEXT_BOLD: TextStyle = TextStyle::new(Font::NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG); pub const TEXT_BOLD: TextStyle = TextStyle::new(Font::NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG);

View File

@ -1,29 +1,39 @@
#[cfg(feature = "micropython")]
mod bip39; mod bip39;
mod button; mod button;
mod button_controller; mod button_controller;
#[cfg(feature = "micropython")]
mod changing_text; mod changing_text;
mod choice; mod choice;
mod choice_item; mod choice_item;
mod common; mod common;
mod confirm; mod confirm;
mod dialog; mod dialog;
#[cfg(feature = "micropython")]
mod flow; mod flow;
#[cfg(feature = "micropython")]
mod flow_pages; mod flow_pages;
#[cfg(feature = "micropython")]
mod flow_pages_poc_helpers; mod flow_pages_poc_helpers;
mod frame; mod frame;
mod loader; mod loader;
#[cfg(feature = "micropython")]
mod page; mod page;
#[cfg(feature = "micropython")]
mod passphrase; mod passphrase;
#[cfg(feature = "micropython")]
mod pin; mod pin;
mod result; mod result;
mod result_anim; mod result_anim;
mod result_popup; mod result_popup;
mod scrollbar; mod scrollbar;
#[cfg(feature = "micropython")]
mod share_words; mod share_words;
mod simple_choice; mod simple_choice;
use super::theme; use super::theme;
#[cfg(feature = "micropython")]
pub use bip39::{Bip39Entry, Bip39EntryMsg}; pub use bip39::{Bip39Entry, Bip39EntryMsg};
pub use button::{ pub use button::{
Button, ButtonAction, ButtonActions, ButtonContent, ButtonDetails, ButtonLayout, ButtonMsg, Button, ButtonAction, ButtonActions, ButtonContent, ButtonDetails, ButtonLayout, ButtonMsg,
@ -32,21 +42,29 @@ pub use button::{
pub use confirm::{HoldToConfirm, HoldToConfirmMsg}; pub use confirm::{HoldToConfirm, HoldToConfirmMsg};
pub use button_controller::{ButtonController, ButtonControllerMsg}; pub use button_controller::{ButtonController, ButtonControllerMsg};
#[cfg(feature = "micropython")]
pub use changing_text::ChangingTextLine; pub use changing_text::ChangingTextLine;
pub use choice::{ChoiceFactory, ChoicePage, ChoicePageMsg}; pub use choice::{ChoiceFactory, ChoicePage, ChoicePageMsg};
pub use choice_item::ChoiceItem; pub use choice_item::ChoiceItem;
pub use dialog::{Dialog, DialogMsg}; pub use dialog::{Dialog, DialogMsg};
#[cfg(feature = "micropython")]
pub use flow::{Flow, FlowMsg}; pub use flow::{Flow, FlowMsg};
#[cfg(feature = "micropython")]
pub use flow_pages::{FlowPages, Page}; pub use flow_pages::{FlowPages, Page};
#[cfg(feature = "micropython")]
pub use flow_pages_poc_helpers::LineAlignment; pub use flow_pages_poc_helpers::LineAlignment;
pub use frame::Frame; pub use frame::Frame;
pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet}; pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet};
#[cfg(feature = "micropython")]
pub use page::ButtonPage; pub use page::ButtonPage;
#[cfg(feature = "micropython")]
pub use passphrase::{PassphraseEntry, PassphraseEntryMsg}; pub use passphrase::{PassphraseEntry, PassphraseEntryMsg};
#[cfg(feature = "micropython")]
pub use pin::{PinEntry, PinEntryMsg}; pub use pin::{PinEntry, PinEntryMsg};
pub use result::ResultScreen; pub use result::ResultScreen;
pub use result_anim::{ResultAnim, ResultAnimMsg}; pub use result_anim::{ResultAnim, ResultAnimMsg};
pub use result_popup::{ResultPopup, ResultPopupMsg}; pub use result_popup::{ResultPopup, ResultPopupMsg};
pub use scrollbar::ScrollBar; pub use scrollbar::ScrollBar;
#[cfg(feature = "micropython")]
pub use share_words::ShareWords; pub use share_words::ShareWords;
pub use simple_choice::{SimpleChoice, SimpleChoiceMsg}; pub use simple_choice::{SimpleChoice, SimpleChoiceMsg};

View File

@ -3,11 +3,12 @@ use crate::ui::{
text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt}, text::paragraphs::{Paragraph, ParagraphVecShort, Paragraphs, VecExt},
Component, Component,
}, },
display::Color,
geometry::LinearPlacement, geometry::LinearPlacement,
model_tr::{ model_tr::{
component::ResultScreen, component::ResultScreen,
constant, constant,
theme::{BLACK, TEXT_BOLD, TEXT_NORMAL, WHITE}, theme::{TEXT_BOLD, TEXT_NORMAL},
}, },
util::from_c_str, util::from_c_str,
}; };
@ -40,7 +41,7 @@ extern "C" fn screen_fatal_error(msg: *const cty::c_char, file: *const cty::c_ch
let m_bottom = let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center()); Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true); let mut frame = ResultScreen::new(Color::white(), Color::black(), m_top, m_bottom, true);
frame.place(constant::screen()); frame.place(constant::screen());
frame.paint(); frame.paint();
0 0
@ -72,7 +73,7 @@ extern "C" fn screen_error_shutdown(label: *const cty::c_char, msg: *const cty::
let m_bottom = let m_bottom =
Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center()); Paragraphs::new(messages).with_placement(LinearPlacement::vertical().align_at_center());
let mut frame = ResultScreen::new(WHITE, BLACK, m_top, m_bottom, true); let mut frame = ResultScreen::new(Color::white(), Color::black(), m_top, m_bottom, true);
frame.place(constant::screen()); frame.place(constant::screen());
frame.paint(); frame.paint();
0 0