From 0d733d8e223720d232c99afb610d5cd0bb6c96a6 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Fri, 14 Oct 2022 12:43:37 +0200 Subject: [PATCH] feat(core): change display type for model R [no changelog] --- core/SConscript.boardloader | 4 +- core/SConscript.bootloader | 3 +- core/SConscript.bootloader_ci | 3 +- core/SConscript.firmware | 7 ++- core/SConscript.prodtest | 3 +- core/SConscript.reflash | 3 +- core/SConscript.unix | 5 +- core/embed/bootloader/bootui.c | 44 +++++++++++++++ core/embed/bootloader/main.c | 2 + core/embed/extmod/modtrezorui/buffers.h | 4 +- core/embed/extmod/modtrezorui/display.h | 2 +- core/embed/extmod/modtrezorui/display_defs.h | 52 ------------------ .../extmod/modtrezorui/display_interface.h | 33 ++---------- core/embed/firmware/main.c | 9 ++-- core/embed/prodtest/main.c | 1 + core/embed/rust/build.rs | 14 +++++ core/embed/rust/trezorhal.h | 1 + core/embed/trezorhal/boards/trezor_1.h | 33 ++++++++++++ core/embed/trezorhal/boards/trezor_r_v3.h | 13 +++++ core/embed/trezorhal/boards/trezor_r_v4.h | 33 ++++++++++++ core/embed/trezorhal/boards/trezor_t.h | 6 +++ core/embed/trezorhal/button.c | 19 +------ .../displays/st7789v.c} | 7 ++- core/embed/trezorhal/displays/st7789v.h | 25 +++++++++ .../displays/ug-2828tswig01.c} | 4 +- .../embed/trezorhal/displays/ug-2828tswig01.h | 10 ++++ .../displays/vg-2864ksweg01.c} | 53 ++++++++++--------- .../embed/trezorhal/displays/vg-2864ksweg01.h | 13 +++++ core/embed/unix/board-unix.h | 6 +++ .../modtrezorui => unix}/display-unix.c | 2 +- core/embed/unix/display-unix.h | 33 ++++++++++++ core/site_scons/tools.py | 26 ++++++++- 32 files changed, 328 insertions(+), 145 deletions(-) delete mode 100644 core/embed/extmod/modtrezorui/display_defs.h create mode 100644 core/embed/trezorhal/boards/trezor_1.h create mode 100644 core/embed/trezorhal/boards/trezor_r_v3.h create mode 100644 core/embed/trezorhal/boards/trezor_r_v4.h create mode 100644 core/embed/trezorhal/boards/trezor_t.h rename core/embed/{extmod/modtrezorui/display-stm32_T.c => trezorhal/displays/st7789v.c} (99%) create mode 100644 core/embed/trezorhal/displays/st7789v.h rename core/embed/{extmod/modtrezorui/display-stm32_R.c => trezorhal/displays/ug-2828tswig01.c} (99%) create mode 100644 core/embed/trezorhal/displays/ug-2828tswig01.h rename core/embed/{extmod/modtrezorui/display-stm32_1.c => trezorhal/displays/vg-2864ksweg01.c} (87%) create mode 100644 core/embed/trezorhal/displays/vg-2864ksweg01.h create mode 100644 core/embed/unix/board-unix.h rename core/embed/{extmod/modtrezorui => unix}/display-unix.c (99%) create mode 100644 core/embed/unix/display-unix.h diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader index d85201f784..de31c8c711 100644 --- a/core/SConscript.boardloader +++ b/core/SConscript.boardloader @@ -1,6 +1,7 @@ # pylint: disable=E0602 import os +import tools TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T') @@ -51,7 +52,6 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/colors.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', ] @@ -101,6 +101,8 @@ SOURCE_TREZORHAL = [ env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Replace( AS='arm-none-eabi-as', AR='arm-none-eabi-ar', diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader index 1216c669b7..c9829affd7 100644 --- a/core/SConscript.bootloader +++ b/core/SConscript.bootloader @@ -69,7 +69,6 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/buffers.c', 'embed/extmod/modtrezorui/colors.c', 'embed/extmod/modtrezorui/display.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', 'vendor/micropython/lib/uzlib/adler32.c', @@ -155,6 +154,8 @@ tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Replace( AS='arm-none-eabi-as', AR='arm-none-eabi-ar', diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci index d2a5366f62..f7b99791d9 100644 --- a/core/SConscript.bootloader_ci +++ b/core/SConscript.bootloader_ci @@ -66,7 +66,6 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/colors.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', 'vendor/micropython/lib/uzlib/adler32.c', @@ -138,6 +137,8 @@ tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Replace( AS='arm-none-eabi-as', AR='arm-none-eabi-ar', diff --git a/core/SConscript.firmware b/core/SConscript.firmware index d336f3951d..92b1d67622 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -175,7 +175,6 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/buffers.c', 'embed/extmod/modtrezorui/colors.c', 'embed/extmod/modtrezorui/display.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', 'embed/extmod/modtrezorui/modtrezorui.c', @@ -434,6 +433,8 @@ SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_MICROPYTHON_SPEED env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s -DPYOPT=%s -DBITCOIN_ONLY=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'), PYOPT, BITCOIN_ONLY)) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Tool('micropython') env.Replace( @@ -449,7 +450,7 @@ env.Replace( OBJCOPY='arm-none-eabi-objcopy', ) env.Replace( - TREZOR_MODEL=TREZOR_MODEL, ) + TREZOR_MODEL=TREZOR_MODEL,) if TREZOR_MODEL in ('T', 'R'): CPU_ASFLAGS = '-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16' @@ -731,6 +732,8 @@ def cargo_build(): '-Z build-std-features=panic_immediate_abort', ] + env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL + return f'cd embed/rust; cargo build {profile} ' + ' '.join(cargo_opts) rust = env.Command( diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest index 5d1effbbdd..ba19d4dd19 100644 --- a/core/SConscript.prodtest +++ b/core/SConscript.prodtest @@ -41,7 +41,6 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/colors.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', 'embed/extmod/modtrezorui/qr-code-generator/qrcodegen.c', @@ -107,6 +106,8 @@ tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Replace( AS='arm-none-eabi-as', AR='arm-none-eabi-ar', diff --git a/core/SConscript.reflash b/core/SConscript.reflash index 2b55646486..e10b523115 100644 --- a/core/SConscript.reflash +++ b/core/SConscript.reflash @@ -36,7 +36,6 @@ CPPPATH_MOD += [ SOURCE_MOD += [ 'embed/extmod/modtrezorui/display.c', 'embed/extmod/modtrezorui/colors.c', - f'embed/extmod/modtrezorui/display-stm32_{TREZOR_MODEL}.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/font_bitmap.c', 'vendor/micropython/lib/uzlib/adler32.c', @@ -100,6 +99,8 @@ tools.add_font('MONO', FONT_MONO, CPPDEFINES_MOD, SOURCE_MOD) env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0'))) +tools.configure_board(TREZOR_MODEL, env, CPPDEFINES_MOD, SOURCE_TREZORHAL) + env.Replace( AS='arm-none-eabi-as', AR='arm-none-eabi-ar', diff --git a/core/SConscript.unix b/core/SConscript.unix index c91523fb0f..03f23ba0cd 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -171,7 +171,6 @@ SOURCE_MOD += [ 'embed/extmod/modtrezorui/buffers.c', 'embed/extmod/modtrezorui/colors.c', 'embed/extmod/modtrezorui/display.c', - 'embed/extmod/modtrezorui/display-unix.c', 'embed/extmod/modtrezorui/fonts/fonts.c', 'embed/extmod/modtrezorui/fonts/font_bitmap.c', 'embed/extmod/modtrezorui/modtrezorui.c', @@ -333,6 +332,7 @@ SOURCE_MICROPYTHON = [ SOURCE_UNIX = [ 'embed/unix/common.c', + 'embed/unix/display-unix.c', 'embed/unix/flash.c', 'embed/unix/main.c', 'embed/unix/main_main.c', @@ -445,6 +445,7 @@ env.Replace( CPPDEFINES=[ 'TREZOR_EMULATOR', 'TREZOR_MODEL_'+TREZOR_MODEL, + 'TREZOR_BOARD=\\"board-unix.h\\"', ('MP_CONFIGFILE', '\\"embed/unix/mpconfigport.h\\"'), ] + CPPDEFINES_MOD, ASPPFLAGS='$CFLAGS $CCFLAGS', ) @@ -676,6 +677,8 @@ def cargo_build(): if DMA2D: features.append('dma2d') + env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL + return f'cd embed/rust; cargo build --profile {RUST_PROFILE} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}" --target {TARGET}' rust = env.Command( diff --git a/core/embed/bootloader/bootui.c b/core/embed/bootloader/bootui.c index fac7e13d1c..8c6618b935 100644 --- a/core/embed/bootloader/bootui.c +++ b/core/embed/bootloader/bootui.c @@ -119,6 +119,9 @@ void ui_screen_boot(const vendor_header *const vhdr, display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5 - 25, ver_str, -1, FONT_NORMAL, COLOR_BL_BG, boot_background); } + + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_boot_wait(int wait_seconds) { @@ -127,6 +130,8 @@ void ui_screen_boot_wait(int wait_seconds) { display_bar(0, DISPLAY_RESY - 5 - 20, DISPLAY_RESX, 5 + 20, boot_background); display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5, wait_str, -1, FONT_NORMAL, COLOR_BL_BG, boot_background); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_boot_click(void) { @@ -134,6 +139,8 @@ void ui_screen_boot_click(void) { display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5, "click to continue ...", -1, FONT_NORMAL, COLOR_BL_BG, boot_background); + PIXELDATA_DIRTY(); + display_refresh(); } // welcome UI @@ -141,6 +148,8 @@ void ui_screen_boot_click(void) { void ui_screen_welcome_first(void) { display_icon(0, 0, 240, 240, toi_icon_logo + 12, sizeof(toi_icon_logo) - 12, COLOR_WELCOME_FG, COLOR_WELCOME_BG); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_welcome_second(void) { @@ -148,6 +157,8 @@ void ui_screen_welcome_second(void) { display_icon((DISPLAY_RESX - 200) / 2, (DISPLAY_RESY - 60) / 2, 200, 60, toi_icon_safeplace + 12, sizeof(toi_icon_safeplace) - 12, COLOR_WELCOME_FG, COLOR_WELCOME_BG); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_welcome_third(void) { @@ -157,6 +168,8 @@ void ui_screen_welcome_third(void) { COLOR_WELCOME_FG, COLOR_WELCOME_BG); display_text_center(120, 220, "Go to trezor.io/start", -1, FONT_NORMAL, COLOR_WELCOME_FG, COLOR_WELCOME_BG); + PIXELDATA_DIRTY(); + display_refresh(); } // info UI @@ -176,6 +189,8 @@ static int display_vendor_string(const char *text, int textlen, COLOR_BL_BG); return 145; } + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_firmware_info(const vendor_header *const vhdr, @@ -196,6 +211,8 @@ void ui_screen_firmware_info(const vendor_header *const vhdr, } display_text_center(120, 220, "Go to trezor.io/start", -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_firmware_fingerprint(const image_header *const hdr) { @@ -219,6 +236,8 @@ void ui_screen_firmware_fingerprint(const image_header *const hdr) { display_icon(9 + (222 - 19) / 2, 184 + (50 - 16) / 2, 20, 16, toi_icon_confirm + 12, sizeof(toi_icon_confirm) - 12, COLOR_BL_BG, COLOR_BL_DONE); + PIXELDATA_DIRTY(); + display_refresh(); } // install UI @@ -237,6 +256,8 @@ void ui_screen_install_confirm_upgrade(const vendor_header *const vhdr, const char *ver_str = format_ver("to version %d.%d.%d?", hdr->version); display_text(55, next_y, ver_str, -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); ui_confirm_cancel_buttons(); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_install_confirm_newvendor_or_downgrade_wipe( @@ -258,6 +279,8 @@ void ui_screen_install_confirm_newvendor_or_downgrade_wipe( display_text_center(120, 170, "Seed will be erased!", -1, FONT_NORMAL, COLOR_BL_FAIL, COLOR_BL_BG); ui_confirm_cancel_buttons(); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_install_start(void) { @@ -267,16 +290,24 @@ void ui_screen_install_start(void) { display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24, "Installing firmware", -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_install_progress_erase(int pos, int len) { display_loader(250 * pos / len, false, -20, COLOR_BL_PROCESS, COLOR_BL_BG, toi_icon_install, sizeof(toi_icon_install), COLOR_BL_FG); + + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_install_progress_upload(int pos) { display_loader(pos, false, -20, COLOR_BL_PROCESS, COLOR_BL_BG, toi_icon_install, sizeof(toi_icon_install), COLOR_BL_FG); + + PIXELDATA_DIRTY(); + display_refresh(); } // wipe UI @@ -296,6 +327,8 @@ void ui_screen_wipe_confirm(void) { display_text_center(120, 170, "Seed will be erased!", -1, FONT_NORMAL, COLOR_BL_FAIL, COLOR_BL_BG); ui_confirm_cancel_buttons(); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_wipe(void) { @@ -304,11 +337,16 @@ void ui_screen_wipe(void) { sizeof(toi_icon_wipe), COLOR_BL_FG); display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24, "Wiping device", -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); + PIXELDATA_DIRTY(); + display_refresh(); } void ui_screen_wipe_progress(int pos, int len) { display_loader(1000 * pos / len, false, -20, COLOR_BL_PROCESS, COLOR_BL_BG, toi_icon_wipe, sizeof(toi_icon_wipe), COLOR_BL_FG); + + PIXELDATA_DIRTY(); + display_refresh(); } // done UI @@ -333,6 +371,9 @@ void ui_screen_done(int restart_seconds, secbool full_redraw) { } display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24, str, -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); + + PIXELDATA_DIRTY(); + display_refresh(); } // error UI @@ -344,6 +385,9 @@ void ui_screen_fail(void) { display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 24, "Failed! Please, reconnect.", -1, FONT_NORMAL, COLOR_BL_FG, COLOR_BL_BG); + + PIXELDATA_DIRTY(); + display_refresh(); } // general functions diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index 9fca724d3a..0e8e6701f0 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -255,6 +255,8 @@ int main(void) { dma2d_init(); #endif + display_reinit(); + #if defined TREZOR_MODEL_T set_core_clock(CLOCK_180_MHZ); display_set_little_endian(); diff --git a/core/embed/extmod/modtrezorui/buffers.h b/core/embed/extmod/modtrezorui/buffers.h index 5acd07df12..89f284d837 100644 --- a/core/embed/extmod/modtrezorui/buffers.h +++ b/core/embed/extmod/modtrezorui/buffers.h @@ -23,7 +23,7 @@ #include #include "common.h" -#include "display_defs.h" +#include TREZOR_BOARD #define BUFFER_PIXELS DISPLAY_RESX @@ -56,4 +56,4 @@ line_buffer_16bpp_t* buffers_get_line_buffer_16bpp(uint16_t idx, bool clear); line_buffer_4bpp_t* buffers_get_line_buffer_4bpp(uint16_t idx, bool clear); buffer_text_t* buffers_get_text_buffer(uint16_t idx, bool clear); -#endif //_BUFFERS_H +#endif // _BUFFERS_H diff --git a/core/embed/extmod/modtrezorui/display.h b/core/embed/extmod/modtrezorui/display.h index cc2a1f55cb..4c946cf879 100644 --- a/core/embed/extmod/modtrezorui/display.h +++ b/core/embed/extmod/modtrezorui/display.h @@ -26,7 +26,7 @@ #include "buffers.h" #include "colors.h" -#include "display_defs.h" +#include TREZOR_BOARD #include "display_interface.h" #include "fonts/fonts.h" diff --git a/core/embed/extmod/modtrezorui/display_defs.h b/core/embed/extmod/modtrezorui/display_defs.h deleted file mode 100644 index dadb339bc3..0000000000 --- a/core/embed/extmod/modtrezorui/display_defs.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef _DISPLAY_DEFS_H -#define _DISPLAY_DEFS_H - -#if defined TREZOR_MODEL_T - -// ILI9341V, GC9307 and ST7789V drivers support 240px x 320px display resolution -#define MAX_DISPLAY_RESX 240 -#define MAX_DISPLAY_RESY 320 -#define DISPLAY_RESX 240 -#define DISPLAY_RESY 240 -#define TREZOR_FONT_BPP 4 - -#elif defined TREZOR_MODEL_1 - -#define MAX_DISPLAY_RESX 128 -#define MAX_DISPLAY_RESY 64 -#define DISPLAY_RESX 128 -#define DISPLAY_RESY 64 -#define TREZOR_FONT_BPP 1 - -#elif defined TREZOR_MODEL_R - -#define MAX_DISPLAY_RESX 128 -#define MAX_DISPLAY_RESY 128 -#define DISPLAY_RESX 128 -#define DISPLAY_RESY 128 -#define TREZOR_FONT_BPP 1 - -#else -#error Unknown Trezor model -#endif - -#endif //_DISPLAY_DEFS_H diff --git a/core/embed/extmod/modtrezorui/display_interface.h b/core/embed/extmod/modtrezorui/display_interface.h index bd0a804df4..4b166fdc8d 100644 --- a/core/embed/extmod/modtrezorui/display_interface.h +++ b/core/embed/extmod/modtrezorui/display_interface.h @@ -22,36 +22,15 @@ #include #include "common.h" +#include TREZOR_BOARD -#if !defined TREZOR_EMULATOR -#include STM32_HAL_H -#endif - -#if (defined TREZOR_MODEL_T) && !(defined TREZOR_EMULATOR) - -extern __IO uint8_t *const DISPLAY_CMD_ADDRESS; -extern __IO uint8_t *const DISPLAY_DATA_ADDRESS; - -#define CMD(X) (*DISPLAY_CMD_ADDRESS = (X)) -#define DATA(X) (*DISPLAY_DATA_ADDRESS = (X)) -#define PIXELDATA(X) \ - DATA((X)&0xFF); \ - DATA((X) >> 8) - -#else +#ifndef PIXELDATA #define PIXELDATA(c) display_pixeldata(c) #endif -#ifdef TREZOR_EMULATOR -extern uint8_t *const DISPLAY_DATA_ADDRESS; -#endif - void display_pixeldata(uint16_t c); -#if (defined TREZOR_MODEL_1) && !(defined TREZOR_EMULATOR) -void PIXELDATA_DIRTY(); -#else -// noop +#ifndef PIXELDATA_DIRTY #define PIXELDATA_DIRTY() #endif @@ -63,13 +42,9 @@ int display_get_orientation(void); int display_backlight(int val); void display_init(void); +void display_reinit(void); void display_refresh(void); const char *display_save(const char *prefix); void display_clear_save(void); -#ifdef TREZOR_MODEL_T -void display_set_little_endian(void); -void display_set_big_endian(void); -#endif - #endif //_DISPLAY_INTERFACE_H diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index eab237a582..c694fc85cf 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -109,26 +109,25 @@ int main(void) { SCB->SHCSR |= (SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk); #endif + display_reinit(); + #if defined TREZOR_MODEL_1 - display_init(); - display_clear(); button_init(); #endif #if defined TREZOR_MODEL_R button_init(); - display_clear(); rgb_led_init(); #endif #if defined TREZOR_MODEL_T set_core_clock(CLOCK_180_MHZ); touch_init(); - display_set_little_endian(); sdcard_init(); - display_clear(); #endif + display_clear(); + #if !defined TREZOR_MODEL_1 // jump to unprivileged mode // http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/CHDBIBGJ.html diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index b4e5234262..c64746e711 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -378,6 +378,7 @@ int main(void) { sbu_init(); usb_init_all(); + display_reinit(); display_clear(); draw_border(1, 3); diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index 4e26dfcff6..0bba44c3d9 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -19,6 +19,19 @@ fn model() -> String { } } +fn board() -> String { + if !is_firmware() { + return String::from("board-unix.h"); + } + + match env::var("TREZOR_BOARD") { + Ok(board) => { + format!("boards/{}", board) + } + Err(_) => String::from("boards/trezor_t.h"), + } +} + /// Generates Rust module that exports QSTR constants used in firmware. #[cfg(feature = "micropython")] fn generate_qstr_bindings() { @@ -64,6 +77,7 @@ fn prepare_bindings() -> bindgen::Builder { "-I../../vendor/micropython/lib/uzlib", "-I../extmod/modtrezorui", // for display.h format!("-DTREZOR_MODEL_{}", model()).as_str(), + format!("-DTREZOR_BOARD=\"{}\"", board()).as_str(), ]); // Pass in correct include paths and defines. diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h index 0f474ae0a6..b097a3d77e 100644 --- a/core/embed/rust/trezorhal.h +++ b/core/embed/rust/trezorhal.h @@ -1,3 +1,4 @@ +#include TREZOR_BOARD #include "buffers.h" #include "common.h" #include "display.h" diff --git a/core/embed/trezorhal/boards/trezor_1.h b/core/embed/trezorhal/boards/trezor_1.h new file mode 100644 index 0000000000..56945255ee --- /dev/null +++ b/core/embed/trezorhal/boards/trezor_1.h @@ -0,0 +1,33 @@ +#ifndef _TREZOR_1_H +#define _TREZOR_1_H + +#include "displays/vg-2864ksweg01.h" + +#define BTN_LEFT_PIN GPIO_PIN_5 +#define BTN_LEFT_PORT GPIOC +#define BTN_LEFT_CLK_ENA __HAL_RCC_GPIOC_CLK_ENABLE +#define BTN_RIGHT_PIN GPIO_PIN_2 +#define BTN_RIGHT_PORT GPIOC +#define BTN_RIGHT_CLK_ENA __HAL_RCC_GPIOC_CLK_ENABLE + +#define OLED_DC_PORT GPIOB +#define OLED_DC_PIN GPIO_PIN_0 // PB0 | Data/Command +#define OLED_DC_CLK_ENA __HAL_RCC_GPIOB_CLK_ENABLE +#define OLED_CS_PORT GPIOA +#define OLED_CS_PIN GPIO_PIN_4 // PA4 | SPI Select +#define OLED_CS_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE +#define OLED_RST_PORT GPIOB +#define OLED_RST_PIN GPIO_PIN_1 // PB1 | Reset display +#define OLED_RST_CLK_ENA __HAL_RCC_GPIOB_CLK_ENABLE + +#define OLED_SPI SPI1 +#define OLED_SPI_AF GPIO_AF5_SPI1 +#define OLED_SPI_CLK_ENA __HAL_RCC_SPI1_CLK_ENABLE +#define OLED_SPI_SCK_PORT GPIOA +#define OLED_SPI_SCK_PIN GPIO_PIN_5 // PA5 | SPI SCK +#define OLED_SPI_SCK_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE +#define OLED_SPI_MOSI_PORT GPIOA +#define OLED_SPI_MOSI_PIN GPIO_PIN_7 // PA7 | SPI MOSI +#define OLED_SPI_MOSI_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE + +#endif //_TREZOR_1_H diff --git a/core/embed/trezorhal/boards/trezor_r_v3.h b/core/embed/trezorhal/boards/trezor_r_v3.h new file mode 100644 index 0000000000..acf524f1d6 --- /dev/null +++ b/core/embed/trezorhal/boards/trezor_r_v3.h @@ -0,0 +1,13 @@ +#ifndef _TREZOR_R_V3_H +#define _TREZOR_R_V3_H + +#include "displays/ug-2828tswig01.h" + +#define BTN_LEFT_PIN GPIO_PIN_0 +#define BTN_LEFT_PORT GPIOA +#define BTN_LEFT_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE +#define BTN_RIGHT_PIN GPIO_PIN_15 +#define BTN_RIGHT_PORT GPIOE +#define BTN_RIGHT_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE + +#endif //_TREZOR_R_V3_H diff --git a/core/embed/trezorhal/boards/trezor_r_v4.h b/core/embed/trezorhal/boards/trezor_r_v4.h new file mode 100644 index 0000000000..e7ba40ed97 --- /dev/null +++ b/core/embed/trezorhal/boards/trezor_r_v4.h @@ -0,0 +1,33 @@ +#ifndef _TREZOR_R_V4_H +#define _TREZOR_R_V4_H + +#include "displays/vg-2864ksweg01.h" + +#define BTN_LEFT_PIN GPIO_PIN_5 +#define BTN_LEFT_PORT GPIOC +#define BTN_LEFT_CLK_ENA __HAL_RCC_GPIOC_CLK_ENABLE +#define BTN_RIGHT_PIN GPIO_PIN_10 +#define BTN_RIGHT_PORT GPIOB +#define BTN_RIGHT_CLK_ENA __HAL_RCC_GPIOB_CLK_ENABLE + +#define OLED_DC_PORT GPIOD +#define OLED_DC_PIN GPIO_PIN_0 // PD0 | Data/Command +#define OLED_DC_CLK_ENA __HAL_RCC_GPIOD_CLK_ENABLE +#define OLED_CS_PORT GPIOE +#define OLED_CS_PIN GPIO_PIN_4 // PE4 | SPI Select +#define OLED_CS_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE +#define OLED_RST_PORT GPIOD +#define OLED_RST_PIN GPIO_PIN_1 // PD1 | Reset display +#define OLED_RST_CLK_ENA __HAL_RCC_GPIOD_CLK_ENABLE + +#define OLED_SPI SPI4 +#define OLED_SPI_AF GPIO_AF5_SPI4 +#define OLED_SPI_CLK_ENA __HAL_RCC_SPI4_CLK_ENABLE +#define OLED_SPI_SCK_PORT GPIOE +#define OLED_SPI_SCK_PIN GPIO_PIN_2 // PE2 | SPI SCK +#define OLED_SPI_SCK_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE +#define OLED_SPI_MOSI_PORT GPIOE +#define OLED_SPI_MOSI_PIN GPIO_PIN_6 // PE6 | SPI MOSI +#define OLED_SPI_MOSI_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE + +#endif //_TREZOR_R_V4_H diff --git a/core/embed/trezorhal/boards/trezor_t.h b/core/embed/trezorhal/boards/trezor_t.h new file mode 100644 index 0000000000..d5dccf2470 --- /dev/null +++ b/core/embed/trezorhal/boards/trezor_t.h @@ -0,0 +1,6 @@ +#ifndef _TREZOR_T_H +#define _TREZOR_T_H + +#include "displays/st7789v.h" + +#endif //_TREZOR_T_H diff --git a/core/embed/trezorhal/button.c b/core/embed/trezorhal/button.c index a5661b7df8..7555781d4e 100644 --- a/core/embed/trezorhal/button.c +++ b/core/embed/trezorhal/button.c @@ -1,23 +1,6 @@ #include STM32_HAL_H #include "button.h" - -#if defined TREZOR_MODEL_1 -#define BTN_LEFT_PIN GPIO_PIN_5 -#define BTN_LEFT_PORT GPIOC -#define BTN_LEFT_CLK_ENA __HAL_RCC_GPIOC_CLK_ENABLE -#define BTN_RIGHT_PIN GPIO_PIN_2 -#define BTN_RIGHT_PORT GPIOC -#define BTN_RIGHT_CLK_ENA __HAL_RCC_GPIOC_CLK_ENABLE -#elif defined TREZOR_MODEL_R -#define BTN_LEFT_PIN GPIO_PIN_0 -#define BTN_LEFT_PORT GPIOA -#define BTN_LEFT_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE -#define BTN_RIGHT_PIN GPIO_PIN_15 -#define BTN_RIGHT_PORT GPIOE -#define BTN_RIGHT_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE -#else -#error Unknown Trezor model -#endif +#include TREZOR_BOARD static char last_left = 0, last_right = 0; diff --git a/core/embed/extmod/modtrezorui/display-stm32_T.c b/core/embed/trezorhal/displays/st7789v.c similarity index 99% rename from core/embed/extmod/modtrezorui/display-stm32_T.c rename to core/embed/trezorhal/displays/st7789v.c index d6b5152778..371ab8e7f8 100644 --- a/core/embed/extmod/modtrezorui/display-stm32_T.c +++ b/core/embed/trezorhal/displays/st7789v.c @@ -18,7 +18,7 @@ */ #include -#include "display_defs.h" +#include TREZOR_BOARD #include "display_interface.h" #include "memzero.h" #include STM32_HAL_H @@ -601,6 +601,11 @@ void display_init(void) { display_set_little_endian(); } +void display_reinit(void) { + // important for model T as this is not set in boardloader + display_set_little_endian(); +} + void display_refresh(void) { uint32_t id = display_identify(); if (id && (id != DISPLAY_ID_GC9307)) { diff --git a/core/embed/trezorhal/displays/st7789v.h b/core/embed/trezorhal/displays/st7789v.h new file mode 100644 index 0000000000..57a15ee802 --- /dev/null +++ b/core/embed/trezorhal/displays/st7789v.h @@ -0,0 +1,25 @@ +#ifndef _ST7789V_H +#define _ST7789V_H + +#include STM32_HAL_H + +// ILI9341V, GC9307 and ST7789V drivers support 240px x 320px display resolution +#define MAX_DISPLAY_RESX 240 +#define MAX_DISPLAY_RESY 320 +#define DISPLAY_RESX 240 +#define DISPLAY_RESY 240 +#define TREZOR_FONT_BPP 4 + +extern __IO uint8_t *const DISPLAY_CMD_ADDRESS; +extern __IO uint8_t *const DISPLAY_DATA_ADDRESS; + +#define CMD(X) (*DISPLAY_CMD_ADDRESS = (X)) +#define DATA(X) (*DISPLAY_DATA_ADDRESS = (X)) +#define PIXELDATA(X) \ + DATA((X)&0xFF); \ + DATA((X) >> 8) + +void display_set_little_endian(void); +void display_set_big_endian(void); + +#endif //_ST7789V_H diff --git a/core/embed/extmod/modtrezorui/display-stm32_R.c b/core/embed/trezorhal/displays/ug-2828tswig01.c similarity index 99% rename from core/embed/extmod/modtrezorui/display-stm32_R.c rename to core/embed/trezorhal/displays/ug-2828tswig01.c index f1289ee92d..835b1ff354 100644 --- a/core/embed/extmod/modtrezorui/display-stm32_R.c +++ b/core/embed/trezorhal/displays/ug-2828tswig01.c @@ -18,7 +18,7 @@ */ #include -#include "display_defs.h" +#include TREZOR_BOARD #include "display_interface.h" #include "memzero.h" #include STM32_HAL_H @@ -356,6 +356,8 @@ void display_refresh(void) { } } +void display_reinit(void) {} + const char *display_save(const char *prefix) { return NULL; } void display_clear_save(void) {} diff --git a/core/embed/trezorhal/displays/ug-2828tswig01.h b/core/embed/trezorhal/displays/ug-2828tswig01.h new file mode 100644 index 0000000000..bdc5b432d4 --- /dev/null +++ b/core/embed/trezorhal/displays/ug-2828tswig01.h @@ -0,0 +1,10 @@ +#ifndef _UG_2828TSWIG01_H +#define _UG_2828TSWIG01_H + +#define MAX_DISPLAY_RESX 128 +#define MAX_DISPLAY_RESY 128 +#define DISPLAY_RESX 128 +#define DISPLAY_RESY 128 +#define TREZOR_FONT_BPP 1 + +#endif //_UG_2828TSWIG01_H diff --git a/core/embed/extmod/modtrezorui/display-stm32_1.c b/core/embed/trezorhal/displays/vg-2864ksweg01.c similarity index 87% rename from core/embed/extmod/modtrezorui/display-stm32_1.c rename to core/embed/trezorhal/displays/vg-2864ksweg01.c index 4777a9e4f0..15c74bbdb3 100644 --- a/core/embed/extmod/modtrezorui/display-stm32_1.c +++ b/core/embed/trezorhal/displays/vg-2864ksweg01.c @@ -19,7 +19,7 @@ #include #include -#include "display_defs.h" +#include TREZOR_BOARD #include "display_interface.h" #include STM32_HAL_H @@ -49,13 +49,6 @@ #define OLED_SEGREMAP 0xA0 #define OLED_CHARGEPUMP 0x8D -#define OLED_DC_PORT GPIOB -#define OLED_DC_PIN GPIO_PIN_0 // PB0 | Data/Command -#define OLED_CS_PORT GPIOA -#define OLED_CS_PIN GPIO_PIN_4 // PA4 | SPI Select -#define OLED_RST_PORT GPIOB -#define OLED_RST_PIN GPIO_PIN_1 // PB1 | Reset display - static int DISPLAY_BACKLIGHT = -1; static int DISPLAY_ORIENTATION = -1; static uint8_t OLED_BUFFER[OLED_BUFSIZE]; @@ -72,7 +65,7 @@ static struct { } pos; } PIXELWINDOW; -static bool pixeldata_dirty = true; +static bool pixeldata_dirty_flag = true; void display_pixeldata(uint16_t c) { if (PIXELWINDOW.pos.x <= PIXELWINDOW.end.x && @@ -99,7 +92,7 @@ void display_pixeldata(uint16_t c) { void display_reset_state() {} -void PIXELDATA_DIRTY() { pixeldata_dirty = true; } +void pixeldata_dirty(void) { pixeldata_dirty_flag = true; } void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { PIXELWINDOW.start.x = x0; @@ -140,9 +133,12 @@ static inline void spi_send(const uint8_t *data, int len) { } void display_init(void) { - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_SPI1_CLK_ENABLE(); + OLED_DC_CLK_ENA(); + OLED_CS_CLK_ENA(); + OLED_RST_CLK_ENA(); + OLED_SPI_SCK_CLK_ENA(); + OLED_SPI_MOSI_CLK_ENA(); + OLED_SPI_CLK_ENA(); GPIO_InitTypeDef GPIO_InitStructure; @@ -151,22 +147,27 @@ void display_init(void) { GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStructure.Alternate = 0; - GPIO_InitStructure.Pin = GPIO_PIN_4; - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); - HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_4; - HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_4, GPIO_PIN_RESET); - HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.Pin = OLED_CS_PIN; + HAL_GPIO_WritePin(OLED_CS_PORT, OLED_CS_PIN, GPIO_PIN_RESET); + HAL_GPIO_Init(OLED_CS_PORT, &GPIO_InitStructure); + GPIO_InitStructure.Pin = OLED_DC_PIN; + HAL_GPIO_WritePin(OLED_DC_PORT, OLED_DC_PIN, GPIO_PIN_RESET); + HAL_GPIO_Init(OLED_DC_PORT, &GPIO_InitStructure); + GPIO_InitStructure.Pin = OLED_RST_PIN; + HAL_GPIO_WritePin(OLED_RST_PORT, OLED_RST_PIN, GPIO_PIN_RESET); + HAL_GPIO_Init(OLED_RST_PORT, &GPIO_InitStructure); // enable SPI 1 for OLED display GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStructure.Alternate = GPIO_AF5_SPI1; - GPIO_InitStructure.Pin = GPIO_PIN_5 | GPIO_PIN_7; - HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.Alternate = OLED_SPI_AF; + GPIO_InitStructure.Pin = OLED_SPI_SCK_PIN; + HAL_GPIO_Init(OLED_SPI_SCK_PORT, &GPIO_InitStructure); + GPIO_InitStructure.Pin = OLED_SPI_MOSI_PIN; + HAL_GPIO_Init(OLED_SPI_MOSI_PORT, &GPIO_InitStructure); - spi_handle.Instance = SPI1; + spi_handle.Instance = OLED_SPI; spi_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; spi_handle.Init.Direction = SPI_DIRECTION_2LINES; spi_handle.Init.CLKPhase = SPI_PHASE_1EDGE; @@ -229,6 +230,8 @@ void display_init(void) { display_refresh(); } +void display_reinit(void) { display_init(); } + static inline uint8_t reverse_byte(uint8_t b) { b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; b = (b & 0xCC) >> 2 | (b & 0x33) << 2; @@ -249,10 +252,10 @@ void display_refresh(void) { OLED_SETHIGHCOLUMN | 0x00, OLED_SETSTARTLINE | 0x00}; - if (!pixeldata_dirty) { + if (!pixeldata_dirty_flag) { return; } - pixeldata_dirty = false; + pixeldata_dirty_flag = false; HAL_GPIO_WritePin(OLED_CS_PORT, OLED_CS_PIN, GPIO_PIN_RESET); // SPI select spi_send(s, 3); diff --git a/core/embed/trezorhal/displays/vg-2864ksweg01.h b/core/embed/trezorhal/displays/vg-2864ksweg01.h new file mode 100644 index 0000000000..8165b22288 --- /dev/null +++ b/core/embed/trezorhal/displays/vg-2864ksweg01.h @@ -0,0 +1,13 @@ +#ifndef _VG_2864KSWEG01_H +#define _VG_2864KSWEG01_H + +#define MAX_DISPLAY_RESX 128 +#define MAX_DISPLAY_RESY 64 +#define DISPLAY_RESX 128 +#define DISPLAY_RESY 64 +#define TREZOR_FONT_BPP 1 + +void pixeldata_dirty(void); +#define PIXELDATA_DIRTY() pixeldata_dirty(); + +#endif //_VG_2864KSWEG01_H diff --git a/core/embed/unix/board-unix.h b/core/embed/unix/board-unix.h new file mode 100644 index 0000000000..293e205513 --- /dev/null +++ b/core/embed/unix/board-unix.h @@ -0,0 +1,6 @@ +#ifndef _BOARD_UNIX_H +#define _BOARD_UNIX_H + +#include "display-unix.h" + +#endif //_BOARD_UNIX_H diff --git a/core/embed/extmod/modtrezorui/display-unix.c b/core/embed/unix/display-unix.c similarity index 99% rename from core/embed/extmod/modtrezorui/display-unix.c rename to core/embed/unix/display-unix.c index c3a336297d..c6669a205f 100644 --- a/core/embed/extmod/modtrezorui/display-unix.c +++ b/core/embed/unix/display-unix.c @@ -29,7 +29,7 @@ #include #include "common.h" -#include "display_defs.h" +#include "display-unix.h" #include "display_interface.h" #include "profile.h" diff --git a/core/embed/unix/display-unix.h b/core/embed/unix/display-unix.h new file mode 100644 index 0000000000..d6cf2cc6b7 --- /dev/null +++ b/core/embed/unix/display-unix.h @@ -0,0 +1,33 @@ +#ifndef _DISPLAY_UNIX_H +#define _DISPLAY_UNIX_H + +#include + +#ifdef TREZOR_MODEL_T +// ILI9341V, GC9307 and ST7789V drivers support 240px x 320px display resolution +#define MAX_DISPLAY_RESX 240 +#define MAX_DISPLAY_RESY 320 +#define DISPLAY_RESX 240 +#define DISPLAY_RESY 240 +#define TREZOR_FONT_BPP 4 +#endif + +#ifdef TREZOR_MODEL_R +#define MAX_DISPLAY_RESX 128 +#define MAX_DISPLAY_RESY 64 +#define DISPLAY_RESX 128 +#define DISPLAY_RESY 64 +#define TREZOR_FONT_BPP 1 +#endif + +#ifdef TREZOR_MODEL_1 +#define MAX_DISPLAY_RESX 128 +#define MAX_DISPLAY_RESY 64 +#define DISPLAY_RESX 128 +#define DISPLAY_RESY 64 +#define TREZOR_FONT_BPP 1 +#endif + +extern uint8_t *const DISPLAY_DATA_ADDRESS; + +#endif //_DISPLAY_UNIX_H diff --git a/core/site_scons/tools.py b/core/site_scons/tools.py index 3c2aeec6db..96dc5d2e52 100644 --- a/core/site_scons/tools.py +++ b/core/site_scons/tools.py @@ -1,11 +1,33 @@ - def add_font(font_name, font, defines, sources): if font is not None: defines += [ 'TREZOR_FONT_' + font_name + '_ENABLE=' + font, 'TREZOR_FONT_' + font_name + '_INCLUDE=\\"' + font.lower() + '.h\\"', - ] + ] sourcefile = 'embed/extmod/modtrezorui/fonts/' + font.lower() + '.c' if sourcefile not in sources: sources.append(sourcefile) + +def configure_board(model, env, defines, sources): + model_r_version = 4 + + if model in ('1',): + board = 'trezor_1.h' + display = 'vg-2864ksweg01.c' + elif model in ('T',): + board = 'trezor_t.h' + display = 'st7789v.c' + elif model in ('R',): + if model_r_version == 3: + board = 'trezor_r_v3.h' + display = "ug-2828tswig01.c" + else: + board = 'trezor_r_v4.h' + display = 'vg-2864ksweg01.c' + else: + raise Exception("Unknown model") + + defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ] + sources += [f'embed/trezorhal/displays/{display}', ] + env.get('ENV')['TREZOR_BOARD'] = board