Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Checks: >-
-clang-analyzer-core.FixedAddressDereference,
-clang-diagnostic-cast-qual
HeaderFilterRegex: '.*'
ExcludeHeaderFilterRegex: '/external/'
ExtraArgs:
- -Wno-unknown-warning-option
- -Qunused-arguments
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "external/cryptoauthlib"]
path = external/cryptoauthlib
url = https://github.com/BitBoxSwiss/cryptoauthlib.git
[submodule "tools/ttf2ugui"]
path = tools/ttf2ugui
url = https://github.com/BitBoxSwiss/ttf2ugui
[submodule "external/optiga-trust-m"]
path = external/optiga-trust-m
url = https://github.com/BitBoxSwiss/optiga-trust-m.git
Expand Down
35 changes: 23 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ set(DBB-FIRMWARE-UI-SOURCES
${CMAKE_SOURCE_DIR}/src/screen.c
${CMAKE_SOURCE_DIR}/src/ui/graphics/graphics.c
${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_11X10.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_11X12.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_13X14.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_15X16.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_17X18.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/monogram_5X9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/password_9X9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/password_11X12.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_11.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_12.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/lvgl_font_compat.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/monogram_16.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/password_9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/password_12.c
${CMAKE_SOURCE_DIR}/src/ui/screen_saver.c
${CMAKE_SOURCE_DIR}/src/ui/screen_stack.c
${CMAKE_SOURCE_DIR}/src/ui/screen_process.c
Expand Down Expand Up @@ -96,9 +94,11 @@ set(DBB-BOOTLOADER-SOURCES
${CMAKE_SOURCE_DIR}/src/memory/memory_spi.c
${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c
${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_11X10.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/monogram_5X9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_11.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_12.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/arial_9.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/lvgl_font_compat.c
${CMAKE_SOURCE_DIR}/src/ui/fonts/monogram_16.c
${CMAKE_SOURCE_DIR}/src/ui/graphics/graphics.c
${CMAKE_SOURCE_DIR}/src/screen.c
${CMAKE_SOURCE_DIR}/src/hardfault.c
Expand Down Expand Up @@ -179,9 +179,17 @@ set(INCLUDES
${CMAKE_SOURCE_DIR}/src/usb/class/hid
${CMAKE_SOURCE_DIR}/src/usb/class/hid/hww
${CMAKE_SOURCE_DIR}/src/usb/class/hid/u2f
${CMAKE_SOURCE_DIR}/external/lvgl
)
set(INCLUDES ${INCLUDES} PARENT_SCOPE)

set(LVGL_DEFINITIONS
LV_KCONFIG_IGNORE
LV_LVGL_H_INCLUDE_SIMPLE
LV_CONF_PATH="${CMAKE_SOURCE_DIR}/src/rust/bitbox-lvgl-sys/lv_conf.h"
LV_CONF_INCLUDE_SIMPLE
)

#-----------------------------------------------------------------------------
# Build embedded firmware

Expand Down Expand Up @@ -386,6 +394,7 @@ foreach(type ${RUST_LIBS})
_UNIT_TEST_
PRODUCT_BITBOX_MULTI=1
APP_U2F=1
${LVGL_DEFINITIONS}
)
# For tests all C-files are built into the rust lib.
target_include_directories(${type}_rust_c INTERFACE
Expand Down Expand Up @@ -420,6 +429,7 @@ if(CMAKE_CROSSCOMPILING)
target_link_libraries(${elf} PRIVATE c asf4-drivers-min samd51a-ds -Wl,-u,exception_table)
target_include_directories(${elf} PRIVATE ${INCLUDES})
target_compile_definitions(${elf} PRIVATE BOOTLOADER "APP_U2F=0")
target_compile_definitions(${elf} PRIVATE ${LVGL_DEFINITIONS})
# needed to find version.h
target_include_directories(${elf} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
# needed to find bootloader_version.h
Expand Down Expand Up @@ -505,6 +515,7 @@ if(CMAKE_CROSSCOMPILING)
asf4-drivers
-Wl,-u,exception_table)
target_include_directories(${elf} PRIVATE ${INCLUDES})
target_compile_definitions(${elf} PRIVATE ${LVGL_DEFINITIONS})

# needed to find version.h
target_include_directories(${elf} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
14 changes: 7 additions & 7 deletions src/bootloader/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ void bootloader_render_ble_confirm_screen(bool confirmed)
image_cross(SCREEN_WIDTH / 16, 0, IMAGE_DEFAULT_CROSS_HEIGHT);
image_checkmark(SCREEN_WIDTH * 15 / 16 - check_width, 0, IMAGE_DEFAULT_CHECKMARK_HEIGHT);
}
UG_FontSelect(&font_monogram_5X9);
UG_FontSelect(&font_monogram_16);
UG_PutString(45, SCREEN_HEIGHT / 2 - 9, code_str);
UG_FontSelect(&font_font_a_9X9);
UG_FontSelect(&font_arial_9);
UG_SendBuffer();
}
#endif
Expand Down Expand Up @@ -398,8 +398,8 @@ static void _render_hash(const char* title, const uint8_t* hash)
// If you change this, check the timer_buf size below.
const uint8_t seconds = 10; // how many seconds to show screen
const UG_S16 title_margin = 7; // Margin between title and hash
const UG_FONT* f_mono = &font_monogram_5X9; // monospaced font
const UG_FONT* f_regular = &font_font_a_9X9; // regular font
const UG_FONT* f_mono = &font_monogram_16; // monospaced font
const UG_FONT* f_regular = &font_arial_9; // regular font

// Convert hash to ascii hex
char hash_hex[2 * SHA256_DIGEST_LENGTH + 1];
Expand Down Expand Up @@ -428,10 +428,10 @@ static void _render_hash(const char* title, const uint8_t* hash)
snprintf(timer_buf, sizeof(timer_buf), "%ds", seconds - i);
UG_MeasureString(&timer_str_width, NULL, timer_buf);
UG_PutString(
SCREEN_WIDTH - timer_str_width, SCREEN_HEIGHT - f_regular->char_height, timer_buf);
SCREEN_WIDTH - timer_str_width, SCREEN_HEIGHT - f_regular->line_height, timer_buf);

UG_FontSelect(f_mono);
UG_PutString(0, title_margin + f_regular->char_height, hash_multiline);
UG_PutString(0, title_margin + f_regular->line_height, hash_multiline);

UG_FontSelect(f_regular);

Expand Down Expand Up @@ -1062,7 +1062,7 @@ void bootloader_jump(void)
screen_rotate();
}

UG_FontSelect(&font_font_a_9X9);
UG_FontSelect(&font_arial_9);

if (shared_data.fields.auto_enter != sectrue_u8) {
#ifdef BOOTLOADER_DEVDEVICE
Expand Down
4 changes: 2 additions & 2 deletions src/da14531/da14531_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <rust/rust.h>
#include <ui/components/confirm.h>
#include <ui/components/ui_images.h>
#include <ui/fonts/monogram_5X9.h>
#include <ui/fonts/monogram_16.h>
#include <utils_assert.h>

const uint8_t* da14531_handler_current_product = NULL;
Expand Down Expand Up @@ -155,7 +155,7 @@ static void _ctrl_handler(const struct da14531_ctrl_frame* frame, struct RustByt
const confirm_params_t confirm_params = {
.title = "Pairing code",
.body = pairing_code,
.font = &font_monogram_5X9,
.font = &font_monogram_16,
};
_ble_pairing_component = confirm_create(
&confirm_params, _ble_pairing_callback, (void*)&_ble_pairing_callback_data);
Expand Down
12 changes: 9 additions & 3 deletions src/rust/bitbox-hal/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use core::time::Duration;

pub struct UserAbort;

#[derive(Copy, Clone, Default)]
#[derive(Copy, Clone, Default, Eq, PartialEq)]
pub enum Font {
#[default]
Default,
Password11X12,
Monogram5X9,
Password12,
Monogram16,
}

#[derive(Default)]
Expand Down Expand Up @@ -77,6 +77,12 @@ pub trait Ui {
/// Returns `Ok(())` if the user accepts, `Err(UserAbort)` if the user rejects.
async fn confirm(&mut self, params: &ConfirmParams<'_>) -> Result<(), UserAbort>;

/// Returns true if `font` can render `c`.
///
/// Control characters such as newlines are workflow-specific layout markers and are not
/// considered font glyphs here.
fn has_glyph(&self, font: Font, c: char) -> bool;

/// Returns `Ok(())` if the user accepts the swap, `Err(UserAbort)` if the user rejects it.
async fn confirm_swap(&mut self, title: &str, from: &str, to: &str) -> Result<(), UserAbort>;

Expand Down
16 changes: 15 additions & 1 deletion src/rust/bitbox02-rust/src/hal/testing/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::hal::Ui;
use crate::hal::ui::{
CanCancel, ConfirmParams, Empty, EnterStringParams, Progress, TrinaryChoice, UserAbort,
CanCancel, ConfirmParams, Empty, EnterStringParams, Font, Progress, TrinaryChoice, UserAbort,
};

use alloc::boxed::Box;
Expand Down Expand Up @@ -54,6 +54,7 @@ pub enum Screen {
}

type EnterStringCb<'a> = Box<dyn FnMut(&EnterStringParams<'_>) -> Result<String, UserAbort> + 'a>;
type HasGlyphCb<'a> = Box<dyn Fn(Font, char) -> bool + 'a>;
type MenuCb<'a> = Box<dyn FnMut(&[&str], Option<&str>) -> Result<u8, UserAbort> + 'a>;
type TrinaryChoiceCb<'a> =
Box<dyn FnMut(&str, Option<&str>, Option<&str>, Option<&str>) -> TrinaryChoice + 'a>;
Expand All @@ -65,6 +66,7 @@ pub struct TestingUi<'a> {
pub screens: Vec<Screen>,
pub confirm_display_sizes: Vec<usize>,
_enter_string: Option<EnterStringCb<'a>>,
_has_glyph: Option<HasGlyphCb<'a>>,
_menu: Option<MenuCb<'a>>,
_trinary_choice: Option<TrinaryChoiceCb<'a>>,
_quiz_choices: VecDeque<u8>,
Expand Down Expand Up @@ -121,6 +123,13 @@ impl Ui for TestingUi<'_> {
Ok(())
}

fn has_glyph(&self, font: Font, c: char) -> bool {
if let Some(has_glyph) = self._has_glyph.as_ref() {
return has_glyph(font, c);
}
matches!(c, ' '..='~' | 'µ' | 'ä' | 'ö' | 'ü' | 'Ä' | 'Ö' | 'Ü')
}

async fn confirm_swap(&mut self, title: &str, from: &str, to: &str) -> Result<(), UserAbort> {
self.screens.push(Screen::Swap {
title: title.into(),
Expand Down Expand Up @@ -276,6 +285,7 @@ impl<'a> TestingUi<'a> {
confirm_display_sizes: vec![],
_abort_nth: None,
_enter_string: None,
_has_glyph: None,
_menu: None,
_trinary_choice: None,
_quiz_choices: VecDeque::new(),
Expand Down Expand Up @@ -303,6 +313,10 @@ impl<'a> TestingUi<'a> {
self._enter_string = None;
}

pub fn set_has_glyph(&mut self, cb: Box<dyn Fn(Font, char) -> bool + 'a>) {
self._has_glyph = Some(cb);
}

pub fn set_menu(&mut self, cb: MenuCb<'a>) {
self._menu = Some(cb);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rust/bitbox02-rust/src/workflow/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn confirm(hal: &mut impl crate::hal::Hal, hash: &[u8; 32]) -> Result<
let params = ConfirmParams {
title: "Pairing code",
body: &format_hash(hash),
font: Font::Monogram5X9,
font: Font::Monogram16,
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion src/rust/bitbox02-rust/src/workflow/unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn confirm_mnemonic_passphrase(
let params = ConfirmParams {
title: "Confirm",
body: passphrase,
font: crate::hal::ui::Font::Password11X12,
font: crate::hal::ui::Font::Password12,
scrollable: true,
longtouch: true,
..Default::default()
Expand Down
Loading
Loading