Skip to content

Commit

Permalink
feat(core): add T3W1 emulator build
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
TychoVrahe authored and cepetr committed Oct 9, 2024
1 parent a0c885d commit d71d9e9
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 7 deletions.
1 change: 0 additions & 1 deletion core/SConscript.bootloader_emu
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ CPPPATH_MOD += [

SOURCE_MOD += [
'embed/extmod/modtrezorcrypto/rand.c',
'embed/lib/buffers.c',
'embed/lib/colors.c',
'embed/lib/display_utils.c',
'embed/lib/error_handling.c',
Expand Down
1 change: 0 additions & 1 deletion core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ CPPPATH_MOD += [
]
SOURCE_MOD += [
'embed/extmod/modtrezorui/modtrezorui.c',
'embed/lib/buffers.c',
'embed/lib/colors.c',
'embed/lib/display_utils.c',
'embed/lib/error_handling.c',
Expand Down
26 changes: 26 additions & 0 deletions core/embed/models/T3W1/boards/t3w1-unix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef BOARDS_T3W1_UNIX_H
#define BOARDS_T3W1_UNIX_H

#define USE_TOUCH 1
#define USE_SBU 1
#define USE_RGB_COLORS 1
#define USE_BACKLIGHT 1
#define USE_OPTIGA 1

#define MAX_DISPLAY_RESX 380
#define MAX_DISPLAY_RESY 520
#define DISPLAY_RESX 380
#define DISPLAY_RESY 520
#define TREZOR_FONT_BPP 4

#define WINDOW_WIDTH 400
#define WINDOW_HEIGHT 600
#define TOUCH_OFFSET_X 80
#define TOUCH_OFFSET_Y 102

#define ORIENTATION_NS 1

// #define BACKGROUND_FILE "T3W1/background_T3W1.h"
// #define BACKGROUND_NAME background_T3W1_jpg

#endif // BOARDS_T3W1_UNIX_H
2 changes: 2 additions & 0 deletions core/embed/trezorhal/unix/display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ void display_init(display_content_mode_t mode) {
SDL_PumpEvents();
SDL_SetWindowSize(drv->window, WINDOW_WIDTH, WINDOW_HEIGHT);
#endif
#ifdef BACKGROUND_FILE
#include BACKGROUND_FILE
#define CONCAT_LEN_HELPER(name) name##_len
#define CONCAT_LEN(name) CONCAT_LEN_HELPER(name)
drv->background = IMG_LoadTexture_RW(
drv->renderer,
SDL_RWFromMem(BACKGROUND_NAME, CONCAT_LEN(BACKGROUND_NAME)), 0);
#endif
if (drv->background) {
SDL_SetTextureBlendMode(drv->background, SDL_BLENDMODE_NONE);
sdl_touch_offset_x = TOUCH_OFFSET_X;
Expand Down
8 changes: 4 additions & 4 deletions core/embed/trezorhal/unix/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
#define FLASH_FILE profile_flash_path()
#endif

#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
#if defined STM32F427xx || defined STM32F429xx
#define FLASH_SECTOR_COUNT 24
#elif defined TREZOR_MODEL_T3T1 || defined TREZOR_MODEL_T3B1
#elif defined STM32U585xx || defined STM32U5A9xx
#define FLASH_SECTOR_COUNT 256
#else
#error Unknown MCU
#endif

static uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
#if defined TREZOR_MODEL_T || defined TREZOR_MODEL_R
#if defined STM32F427xx || defined STM32F429xx
[0] = 0x08000000, // - 0x08003FFF | 16 KiB
[1] = 0x08004000, // - 0x08007FFF | 16 KiB
[2] = 0x08008000, // - 0x0800BFFF | 16 KiB
Expand All @@ -70,7 +70,7 @@ static uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
[22] = 0x081C0000, // - 0x081DFFFF | 128 KiB
[23] = 0x081E0000, // - 0x081FFFFF | 128 KiB
[24] = 0x08200000, // last element - not a valid sector
#elif defined TREZOR_MODEL_T3T1 || defined TREZOR_MODEL_T3B1
#elif defined STM32U585xx || defined STM32U5A9xx
[0] = 0x08000000, // - 0x08001FFF | 8 KiB
// rest is initialized in flash_init
#else
Expand Down
3 changes: 3 additions & 0 deletions core/embed/trezorhal/unix/optiga.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#elif defined(TREZOR_MODEL_T3B1)
#include "certs/T2B1.h"
#define DEVICE_CERT_CHAIN T2B1_der
#elif defined(TREZOR_MODEL_T3W1)
#include "certs/T2B1.h"
#define DEVICE_CERT_CHAIN T2B1_der
#else
#error "Cert chain for specified model is not available."
#endif
Expand Down
3 changes: 2 additions & 1 deletion core/site_scons/models/T3W1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Optional

from . import trezor_t3w1_d1
from . import emulator, trezor_t3w1_d1


def configure_board(
Expand All @@ -18,6 +18,7 @@ def configure_board(

# Mapping of revisions to their respective configurations
revision_map = {
"emulator": emulator,
"d1": trezor_t3w1_d1,
}

Expand Down
61 changes: 61 additions & 0 deletions core/site_scons/models/T3W1/emulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from __future__ import annotations

from .. import get_hw_model_as_number


def configure(
env: dict,
features_wanted: list[str],
defines: list[str | tuple[str, str]],
sources: list[str],
paths: list[str],
) -> list[str]:

features_available: list[str] = []
board = "T3W1/boards/t3w1-unix.h"
hw_model = get_hw_model_as_number("T3W1")
hw_revision = 0
mcu = "STM32F427xx"

defines += ["XFRAMEBUFFER", "DISPLAY_RGB585"]
features_available.append("xframebuffer")
features_available.append("display_rgb565")

defines += [mcu]
defines += [f'TREZOR_BOARD=\\"{board}\\"']
defines += [f"HW_MODEL={hw_model}"]
defines += [f"HW_REVISION={hw_revision}"]
defines += [f"MCU_TYPE={mcu}"]
# todo change to blockwise flash when implemented in unix
defines += ["FLASH_BIT_ACCESS=1"]
defines += ["FLASH_BLOCK_WORDS=1"]

if "dma2d" in features_wanted:
features_available.append("dma2d")
if "new_rendering" in features_wanted:
sources += [
"embed/trezorhal/unix/dma2d_bitblt.c",
]
else:
sources += ["embed/lib/dma2d_emul.c"]
defines += ["USE_DMA2D"]

if "sbu" in features_wanted:
sources += ["embed/trezorhal/unix/sbu.c"]

if "optiga_hal" in features_wanted:
sources += ["embed/trezorhal/unix/optiga_hal.c"]

if "optiga" in features_wanted:
sources += ["embed/trezorhal/unix/optiga.c"]
features_available.append("optiga")

if "input" in features_wanted:
sources += ["embed/trezorhal/unix/touch.c"]
features_available.append("touch")

features_available.append("backlight")

sources += ["embed/trezorhal/stm32f4/layout.c"]

return features_available

0 comments on commit d71d9e9

Please sign in to comment.