diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index e20f57a17..b473f3caa 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -21,6 +21,8 @@ button = [] touch = [] clippy = [] jpeg = [] +disp_i8080_8bit_dw = [] # write pixels directly to peripheral +disp_i8080_16bit_dw = [] # write pixels directly to peripheral debug = ["ui_debug"] sbu = [] sd_card = [] diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index 69c0a5a20..060fa66b3 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -104,7 +104,15 @@ pub fn bar_radius_buffer(x: i16, y: i16, w: i16, h: i16, radius: u8, buffer: &mu } #[inline(always)] -#[cfg(all(feature = "model_tt", target_arch = "arm"))] +#[cfg(all(feature = "disp_i8080_16bit_dw", not(feature = "disp_i8080_8bit_dw")))] +pub fn pixeldata(c: u16) { + unsafe { + ffi::DISPLAY_DATA_ADDRESS.write_volatile(c); + } +} + +#[inline(always)] +#[cfg(feature = "disp_i8080_8bit_dw")] pub fn pixeldata(c: u16) { unsafe { ffi::DISPLAY_DATA_ADDRESS.write_volatile((c & 0xff) as u8); @@ -113,7 +121,7 @@ pub fn pixeldata(c: u16) { } #[inline(always)] -#[cfg(not(all(feature = "model_tt", target_arch = "arm")))] +#[cfg(not(any(feature = "disp_i8080_16bit_dw", feature = "disp_i8080_8bit_dw")))] pub fn pixeldata(c: u16) { unsafe { ffi::display_pixeldata(c); diff --git a/core/embed/trezorhal/boards/trezor_t.h b/core/embed/trezorhal/boards/trezor_t.h index 4e9973f50..5853cb988 100644 --- a/core/embed/trezorhal/boards/trezor_t.h +++ b/core/embed/trezorhal/boards/trezor_t.h @@ -5,6 +5,7 @@ #define USE_I2C 1 #define USE_TOUCH 1 #define USE_SBU 1 +#define USE_DISP_I8080_8BIT_DW 1 #include "displays/st7789v.h" diff --git a/core/embed/trezorhal/displays/st7789v.c b/core/embed/trezorhal/displays/st7789v.c index ae6f54000..f09919ccc 100644 --- a/core/embed/trezorhal/displays/st7789v.c +++ b/core/embed/trezorhal/displays/st7789v.c @@ -21,6 +21,7 @@ #include TREZOR_BOARD #include "display_interface.h" #include "memzero.h" +#include "st7789v.h" #include STM32_HAL_H // using const volatile instead of #define results in binaries that change @@ -32,13 +33,17 @@ const volatile uint8_t DISPLAY_ST7789V_INVERT_COLORS = 0; // FSMC/FMC Bank 1 - NOR/PSRAM 1 #define DISPLAY_MEMORY_BASE 0x60000000 #define DISPLAY_MEMORY_PIN 16 - -__IO uint8_t *const DISPLAY_CMD_ADDRESS = - (__IO uint8_t *const)((uint32_t)DISPLAY_MEMORY_BASE); -__IO uint8_t *const DISPLAY_DATA_ADDRESS = - (__IO uint8_t *const)((uint32_t)DISPLAY_MEMORY_BASE | - (1 << DISPLAY_MEMORY_PIN)); - +#ifdef USE_DISP_I8080_16BIT_DW +#define DISPLAY_ADDR_SHIFT 2 +#elif USE_DISP_I8080_8BIT_DW +#define DISPLAY_ADDR_SHIFT 1 +#endif + +__IO DISP_MEM_TYPE *const DISPLAY_CMD_ADDRESS = + (__IO DISP_MEM_TYPE *const)((uint32_t)DISPLAY_MEMORY_BASE); +__IO DISP_MEM_TYPE *const DISPLAY_DATA_ADDRESS = + (__IO DISP_MEM_TYPE *const)((uint32_t)DISPLAY_MEMORY_BASE | + (DISPLAY_ADDR_SHIFT << DISPLAY_MEMORY_PIN)); #define LED_PWM_TIM_PERIOD \ (255) // little less than 4kHz with PSC = (SystemCoreClock / 1000000) - 1) #define LED_PWM_SLOW_TIM_PERIOD \ @@ -526,7 +531,12 @@ void display_setup_fmc(void) { external_display_data_sram.Init.NSBank = FMC_NORSRAM_BANK1; external_display_data_sram.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; external_display_data_sram.Init.MemoryType = FMC_MEMORY_TYPE_SRAM; +#ifdef USE_DISP_I8080_16BIT_DW + external_display_data_sram.Init.MemoryDataWidth = + FMC_NORSRAM_MEM_BUS_WIDTH_16; +#elif USE_DISP_I8080_8BIT_DW external_display_data_sram.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_8; +#endif external_display_data_sram.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE; external_display_data_sram.Init.WaitSignalPolarity = @@ -559,6 +569,9 @@ void display_setup_fmc(void) { void display_init(void) { // init peripherals __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_TIM1_CLK_ENABLE(); __HAL_RCC_FMC_CLK_ENABLE(); @@ -631,6 +644,18 @@ void display_init(void) { // LCD_D4/PE7 LCD_D5/PE8 LCD_D6/PE9 LCD_D7/PE10 GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); +#ifdef USE_DISP_I8080_16BIT_DW + // LCD_D8/PE11 LCD_D9/PE12 LCD_D10/PE13 LCD_D11/PE14 + GPIO_InitStructure.Pin = + GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14; + HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); + // LCD_D12/PE15 + GPIO_InitStructure.Pin = GPIO_PIN_15; + HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); + // LCD_D13/PD8 LCD_D14/PD9 LCD_D15/PD10 + GPIO_InitStructure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; + HAL_GPIO_Init(GPIOD, &GPIO_InitStructure); +#endif display_setup_fmc(); diff --git a/core/embed/trezorhal/displays/st7789v.h b/core/embed/trezorhal/displays/st7789v.h index 4d23d300f..5d15c66b6 100644 --- a/core/embed/trezorhal/displays/st7789v.h +++ b/core/embed/trezorhal/displays/st7789v.h @@ -10,14 +10,27 @@ #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; +#ifdef USE_DISP_I8080_16BIT_DW +#define DISP_MEM_TYPE uint16_t +#elif USE_DISP_I8080_8BIT_DW +#define DISP_MEM_TYPE uint8_t +#else +#error "Unsupported display interface" +#endif + +extern __IO DISP_MEM_TYPE *const DISPLAY_CMD_ADDRESS; +extern __IO DISP_MEM_TYPE *const DISPLAY_DATA_ADDRESS; #define CMD(X) (*DISPLAY_CMD_ADDRESS = (X)) #define DATA(X) (*DISPLAY_DATA_ADDRESS = (X)) + +#ifdef USE_DISP_I8080_16BIT_DW +#define PIXELDATA(X) DATA(X) +#elif USE_DISP_I8080_8BIT_DW #define PIXELDATA(X) \ DATA((X)&0xFF); \ DATA((X) >> 8) +#endif void display_set_little_endian(void); void display_set_big_endian(void); diff --git a/core/site_scons/boards/trezor_t.py b/core/site_scons/boards/trezor_t.py index 54617f12d..99f7829ff 100644 --- a/core/site_scons/boards/trezor_t.py +++ b/core/site_scons/boards/trezor_t.py @@ -7,6 +7,7 @@ def configure(env, features_wanted, defines, sources): display = 'st7789v.c' hw_model = get_hw_model_as_number('T2T1') hw_revision = 0 + features_available.append("disp_i8080_8bit_dw") defines += [f'TREZOR_BOARD=\\"boards/{board}\\"', ] defines += [f'HW_MODEL={hw_model}', ]