-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core/rust): introduce UIFeaturesXXX trait as an abstraction …
…over different UI implementation [no changelog]
- Loading branch information
1 parent
ba741b8
commit 535a052
Showing
18 changed files
with
776 additions
and
628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,5 @@ | ||
#include <stdbool.h> | ||
|
||
#include "common.h" | ||
|
||
uint32_t screen_install_confirm(const char* vendor_str, uint8_t vendor_str_len, | ||
const char* version_str, | ||
const uint8_t* fingerprint, | ||
bool should_keep_seed, bool is_newvendor, | ||
int version_cmp); | ||
uint32_t screen_wipe_confirm(void); | ||
void screen_install_progress(int16_t progress, bool initialize, | ||
bool initial_setup); | ||
void screen_wipe_progress(int16_t progress, bool initialize); | ||
uint32_t screen_intro(const char* bld_version_str, const char* vendor_str, | ||
uint8_t vendor_str_len, const char* version_str, | ||
bool fw_ok); | ||
uint32_t screen_menu(secbool firmware_present); | ||
void screen_connect(bool initial_setup); | ||
void screen_fatal_error_rust(const char* title, const char* msg, | ||
const char* footer); | ||
void screen_wipe_success(void); | ||
void screen_wipe_fail(void); | ||
uint32_t screen_install_success(uint8_t restart_seconds, bool initial_setup, | ||
bool complete_draw); | ||
uint32_t screen_install_fail(void); | ||
void screen_welcome(void); | ||
void screen_boot_empty(bool fading); | ||
void screen_boot_full(void); | ||
uint32_t screen_unlock_bootloader_confirm(void); | ||
void screen_unlock_bootloader_success(void); | ||
void display_image(int16_t x, int16_t y, const uint8_t* data, uint32_t datalen); | ||
void display_icon(int16_t x, int16_t y, const uint8_t* data, uint32_t datalen, | ||
uint16_t fg_color, uint16_t bg_color); | ||
void bld_continue_label(uint16_t bg_color); | ||
#include "rust_ui_bootloader.h" | ||
#include "rust_ui_common.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "common.h" | ||
|
||
uint32_t screen_install_confirm(const char* vendor_str, uint8_t vendor_str_len, | ||
const char* version_str, | ||
const uint8_t* fingerprint, | ||
bool should_keep_seed, bool is_newvendor, | ||
int version_cmp); | ||
uint32_t screen_wipe_confirm(void); | ||
void screen_install_progress(int16_t progress, bool initialize, | ||
bool initial_setup); | ||
void screen_wipe_progress(int16_t progress, bool initialize); | ||
uint32_t screen_intro(const char* bld_version_str, const char* vendor_str, | ||
uint8_t vendor_str_len, const char* version_str, | ||
bool fw_ok); | ||
uint32_t screen_menu(secbool firmware_present); | ||
void screen_connect(bool initial_setup); | ||
void screen_wipe_success(void); | ||
void screen_wipe_fail(void); | ||
uint32_t screen_install_success(uint8_t restart_seconds, bool initial_setup, | ||
bool complete_draw); | ||
uint32_t screen_install_fail(void); | ||
void screen_welcome(void); | ||
void screen_boot_empty(bool fading); | ||
uint32_t screen_unlock_bootloader_confirm(void); | ||
void screen_unlock_bootloader_success(void); | ||
void bld_continue_label(uint16_t bg_color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "common.h" | ||
|
||
void screen_fatal_error_rust(const char* title, const char* msg, | ||
const char* footer); | ||
|
||
void screen_boot_full(void); | ||
|
||
void display_image(int16_t x, int16_t y, const uint8_t* data, uint32_t datalen); | ||
void display_icon(int16_t x, int16_t y, const uint8_t* data, uint32_t datalen, | ||
uint16_t fg_color, uint16_t bg_color); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
use crate::{ | ||
strutil::hexlify, | ||
trezorhal::secbool::secbool, | ||
ui::{ | ||
ui_features::{ModelUI, UIFeaturesBootloader}, | ||
util::{from_c_array, from_c_str}, | ||
}, | ||
}; | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_welcome() { | ||
ModelUI::screen_welcome(); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn bld_continue_label(bg_color: cty::uint16_t) { | ||
ModelUI::bld_continue_label(bg_color.into()); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_install_success( | ||
restart_seconds: u8, | ||
initial_setup: bool, | ||
complete_draw: bool, | ||
) { | ||
ModelUI::screen_install_success(restart_seconds, initial_setup, complete_draw); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_install_fail() { | ||
ModelUI::screen_install_fail(); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_install_confirm( | ||
vendor_str: *const cty::c_char, | ||
vendor_str_len: u8, | ||
version: *const cty::c_char, | ||
fingerprint: *const cty::uint8_t, | ||
should_keep_seed: bool, | ||
is_newvendor: bool, | ||
version_cmp: cty::c_int, | ||
) -> u32 { | ||
let text = unwrap!(unsafe { from_c_array(vendor_str, vendor_str_len as usize) }); | ||
let version = unwrap!(unsafe { from_c_str(version) }); | ||
|
||
let mut fingerprint_buffer: [u8; 64] = [0; 64]; | ||
let fingerprint_str = unsafe { | ||
let fingerprint_slice = core::slice::from_raw_parts(fingerprint, 32); | ||
hexlify(fingerprint_slice, &mut fingerprint_buffer); | ||
core::str::from_utf8_unchecked(fingerprint_buffer.as_ref()) | ||
}; | ||
|
||
ModelUI::screen_install_confirm( | ||
text, | ||
version, | ||
fingerprint_str, | ||
should_keep_seed, | ||
is_newvendor, | ||
version_cmp, | ||
) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_wipe_confirm() -> u32 { | ||
ModelUI::screen_wipe_confirm() | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_unlock_bootloader_confirm() -> u32 { | ||
ModelUI::screen_unlock_bootloader_confirm() | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_unlock_bootloader_success() { | ||
ModelUI::screen_unlock_bootloader_success(); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_menu(firmware_present: secbool) -> u32 { | ||
ModelUI::screen_menu(firmware_present) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_intro( | ||
bld_version: *const cty::c_char, | ||
vendor_str: *const cty::c_char, | ||
vendor_str_len: u8, | ||
version: *const cty::c_char, | ||
fw_ok: bool, | ||
) -> u32 { | ||
let vendor = unwrap!(unsafe { from_c_array(vendor_str, vendor_str_len as usize) }); | ||
let version = unwrap!(unsafe { from_c_str(version) }); | ||
let bld_version = unwrap!(unsafe { from_c_str(bld_version) }); | ||
|
||
ModelUI::screen_intro(bld_version, vendor, version, fw_ok) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_boot_empty(fading: bool) { | ||
ModelUI::screen_boot_empty(fading) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_wipe_progress(progress: u16, initialize: bool) { | ||
ModelUI::screen_wipe_progress(progress, initialize) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_install_progress(progress: u16, initialize: bool, initial_setup: bool) { | ||
ModelUI::screen_install_progress(progress, initialize, initial_setup) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_connect(initial_setup: bool) { | ||
ModelUI::screen_connect(initial_setup) | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_wipe_success() { | ||
ModelUI::screen_wipe_success() | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_wipe_fail() { | ||
ModelUI::screen_wipe_fail() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Reexporting the `screens` module according to the | ||
//! current feature (Trezor model) | ||
|
||
use crate::ui::{ | ||
component::image::Image, | ||
display::{Color, Icon}, | ||
geometry::{Alignment2D, Point}, | ||
ui_features::{ModelUI, UIFeaturesCommon}, | ||
}; | ||
|
||
use crate::ui::util::from_c_str; | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_fatal_error_rust( | ||
title: *const cty::c_char, | ||
msg: *const cty::c_char, | ||
footer: *const cty::c_char, | ||
) { | ||
let title = unsafe { from_c_str(title) }.unwrap_or(""); | ||
let msg = unsafe { from_c_str(msg) }.unwrap_or(""); | ||
let footer = unsafe { from_c_str(footer) }.unwrap_or(""); | ||
|
||
ModelUI::screen_fatal_error(title, msg, footer); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn screen_boot_full() { | ||
ModelUI::screen_boot_full(); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn display_icon( | ||
x: cty::int16_t, | ||
y: cty::int16_t, | ||
data: *const cty::uint8_t, | ||
data_len: cty::uint32_t, | ||
fg_color: cty::uint16_t, | ||
bg_color: cty::uint16_t, | ||
) { | ||
let data_slice = unsafe { core::slice::from_raw_parts(data, data_len as usize) }; | ||
let icon = Icon::new(data_slice); | ||
icon.draw( | ||
Point::new(x, y), | ||
Alignment2D::TOP_LEFT, | ||
Color::from_u16(fg_color), | ||
Color::from_u16(bg_color), | ||
); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn display_image( | ||
x: cty::int16_t, | ||
y: cty::int16_t, | ||
data: *const cty::uint8_t, | ||
data_len: cty::uint32_t, | ||
) { | ||
let data_slice = unsafe { core::slice::from_raw_parts(data, data_len as usize) }; | ||
let image = Image::new(data_slice); | ||
image.draw(Point::new(x, y), Alignment2D::TOP_LEFT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod common_c; | ||
|
||
#[cfg(feature = "bootloader")] | ||
pub mod bootloader_c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.