1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 14:58:09 +00:00

fix(core): update display initialization sequence on T3T1

[no changelog]
This commit is contained in:
tychovrahe 2024-08-26 13:15:48 +02:00 committed by TychoVrahe
parent c39ba83c8b
commit c7eabe3088
10 changed files with 438 additions and 16 deletions

View File

@ -35,7 +35,7 @@
#include "displays/panels/lx154a2422.h"
#include "displays/panels/tf15411a.h"
#else
#include "displays/panels/lx154a2422.h"
#include "displays/panels/lx154a2482.h"
#endif
// using const volatile instead of #define results in binaries that change
@ -243,7 +243,7 @@ int display_orientation(int degrees) {
lx154a2422_rotate(degrees, &DISPLAY_PADDING);
}
#else
lx154a2422_rotate(degrees, &DISPLAY_PADDING);
lx154a2482_rotate(degrees, &DISPLAY_PADDING);
#endif
panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
}
@ -294,7 +294,7 @@ void display_init_seq(void) {
_154a_init_seq();
}
#else
lx154a2422_init_seq();
lx154a2482_init_seq();
#endif
display_unsleep();
@ -474,9 +474,6 @@ void display_reinit(void) {
// important for model T as this is not set in boardloader
display_set_little_endian();
DISPLAY_ORIENTATION = 0;
panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
backlight_pwm_init(BACKLIGHT_RETAIN);
#ifdef TREZOR_MODEL_T
@ -487,8 +484,13 @@ void display_reinit(void) {
} else if (id == DISPLAY_ID_ST7789V) {
lx154a2411_gamma();
}
#else
lx154a2482_init_seq();
#endif
DISPLAY_ORIENTATION = 0;
panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
#ifdef FRAMEBUFFER
display_setup_te_interrupt();
#endif

View File

@ -68,7 +68,7 @@ void display_reinit(void) {
// Important for model T as this is not set in boardloader
display_panel_set_little_endian();
display_panel_init_gamma();
display_panel_reinit();
backlight_pwm_init(BACKLIGHT_RETAIN);
#ifdef XFRAMEBUFFER

View File

@ -31,7 +31,7 @@
#include "panels/lx154a2422.h"
#include "panels/tf15411a.h"
#else
#include "panels/lx154a2422.h"
#include "panels/lx154a2482.h"
#endif
// using const volatile instead of #define results in binaries that change
@ -212,14 +212,17 @@ void display_panel_init(void) {
_154a_init_seq();
}
#else
lx154a2422_init_seq();
lx154a2482_init_seq();
#endif
display_panel_unsleep();
}
void display_panel_init_gamma(void) {
void display_panel_reinit(void) {
// reinitialization is needed due to original sequence is unchangable in
// boardloader
#ifdef TREZOR_MODEL_T
// model TT has new gamma settings
uint32_t id = display_panel_identify();
if (id == DISPLAY_ID_ST7789V && display_panel_is_inverted()) {
// newest TT display - set proper gamma
@ -227,6 +230,9 @@ void display_panel_init_gamma(void) {
} else if (id == DISPLAY_ID_ST7789V) {
lx154a2411_gamma();
}
#else
// reduced touch-display interference in T3T1
lx154a2482_init_seq();
#endif
}
@ -239,6 +245,6 @@ void display_panel_rotate(int angle) {
lx154a2422_rotate(angle, &g_window_padding);
}
#else
lx154a2422_rotate(angle, &g_window_padding);
lx154a2482_rotate(angle, &g_window_padding);
#endif
}

View File

@ -44,7 +44,9 @@ uint32_t display_panel_identify(void);
bool display_panel_is_inverted();
void display_panel_init(void);
void display_panel_init_gamma(void);
// Due to inability to change display setting in boardlaoder,
// we need to reinitialize the display when bootloader or firmware runs
void display_panel_reinit(void);
void display_panel_set_little_endian(void);
void display_panel_set_big_endian(void);

View File

@ -0,0 +1,194 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "lx154a2482.h"
#include "../display_io.h"
void lx154a2482_gamma(void) {
// positive voltage correction
ISSUE_CMD_BYTE(0xE0);
ISSUE_DATA_BYTE(0xD0);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x10);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x26);
ISSUE_DATA_BYTE(0x36);
ISSUE_DATA_BYTE(0x34);
ISSUE_DATA_BYTE(0x4D);
ISSUE_DATA_BYTE(0x18);
ISSUE_DATA_BYTE(0x13);
ISSUE_DATA_BYTE(0x14);
ISSUE_DATA_BYTE(0x2F);
ISSUE_DATA_BYTE(0x34);
// negative voltage correction
ISSUE_CMD_BYTE(0xE1);
ISSUE_DATA_BYTE(0xD0);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x10);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x09);
ISSUE_DATA_BYTE(0x26);
ISSUE_DATA_BYTE(0x36);
ISSUE_DATA_BYTE(0x53);
ISSUE_DATA_BYTE(0x4C);
ISSUE_DATA_BYTE(0x18);
ISSUE_DATA_BYTE(0x14);
ISSUE_DATA_BYTE(0x14);
ISSUE_DATA_BYTE(0x2F);
ISSUE_DATA_BYTE(0x34);
}
void lx154a2482_init_seq(void) {
// TEON: Tearing Effect Line On; V-blanking only
ISSUE_CMD_BYTE(0x35);
ISSUE_DATA_BYTE(0x00);
// Memory Data Access Control (MADCTL)
ISSUE_CMD_BYTE(0x36);
ISSUE_DATA_BYTE(0x00);
// Interface Pixel Format
ISSUE_CMD_BYTE(0x3A);
ISSUE_DATA_BYTE(0x05);
// Column Address Set
ISSUE_CMD_BYTE(0x2A);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0xEF);
// Row Address Set
ISSUE_CMD_BYTE(0x2B);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0xEF);
// Porch Setting
ISSUE_CMD_BYTE(0xB2);
ISSUE_DATA_BYTE(0x0C);
ISSUE_DATA_BYTE(0x0C);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x33);
ISSUE_DATA_BYTE(0x33);
// VCOM Setting
ISSUE_CMD_BYTE(0xBB);
ISSUE_DATA_BYTE(0x1F);
// LCMCTRL: LCM Control: XOR RGB setting
ISSUE_CMD_BYTE(0xC0);
ISSUE_DATA_BYTE(0x20);
// VDV and VRH Command Enable
ISSUE_CMD_BYTE(0xC2);
ISSUE_DATA_BYTE(0x01);
// VRH Set
ISSUE_CMD_BYTE(0xC3);
ISSUE_DATA_BYTE(0x0F); // 4.3V
// VDV Setting
ISSUE_CMD_BYTE(0xC4);
ISSUE_DATA_BYTE(0x20);
// Frame Rate Control in Normal Mode
ISSUE_CMD_BYTE(0xC6);
ISSUE_DATA_BYTE(0xEF); // column inversion //0X0F Dot INV, 60Hz
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is gate 80.;
// gate scan direction 319 -> 0
ISSUE_CMD_BYTE(0xE4);
ISSUE_DATA_BYTE(0x1D);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x11);
// INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On
ISSUE_CMD_BYTE(0x21);
// the above config is the most important and definitely necessary
// PWCTRL1: Power Control 1
ISSUE_CMD_BYTE(0xD0);
ISSUE_DATA_BYTE(0xA4);
ISSUE_DATA_BYTE(0xA1);
lx154a2482_gamma();
}
void lx154a2482_rotate(int degrees, display_padding_t* padding) {
uint16_t shift = 0;
char BX = 0, BY = 0;
#define RGB (1 << 3)
#define ML (1 << 4) // vertical refresh order
#define MH (1 << 2) // horizontal refresh order
#define MV (1 << 5)
#define MX (1 << 6)
#define MY (1 << 7)
// MADCTL: Memory Data Access Control - reference:
// section 8.12 in the ST7789V manual
uint8_t display_command_parameter = 0;
switch (degrees) {
case 0:
display_command_parameter = 0;
BY = 0;
break;
case 90:
display_command_parameter = MV | MX | MH | ML;
BX = 1;
shift = 1;
break;
case 180:
display_command_parameter = MX | MY | MH | ML;
BY = 0;
shift = 1;
break;
case 270:
display_command_parameter = MV | MY;
BX = 1;
break;
}
ISSUE_CMD_BYTE(0x36);
ISSUE_DATA_BYTE(display_command_parameter);
if (shift) {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
ISSUE_CMD_BYTE(0xE4);
ISSUE_DATA_BYTE(0x1D);
ISSUE_DATA_BYTE(0x00);
ISSUE_DATA_BYTE(0x11);
} else {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
ISSUE_CMD_BYTE(0xE4);
ISSUE_DATA_BYTE(0x1D);
ISSUE_DATA_BYTE(0x0A);
ISSUE_DATA_BYTE(0x11);
}
padding->x = BX ? (320 - DISPLAY_RESY) : 0;
padding->y = BY ? (320 - DISPLAY_RESY) : 0;
}

View File

@ -0,0 +1,29 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LX154A2422_H_
#define LX154A2422_H_
#include "../display_panel.h"
void lx154a2482_init_seq(void);
void lx154a2482_gamma(void);
void lx154a2482_rotate(int degrees, display_padding_t* padding);
#endif

View File

@ -0,0 +1,179 @@
#include "display.h"
#include "displays/st7789v.h"
#include "touch.h"
void lx154a2482_gamma(void) {
// positive voltage correction
CMD(0xE0);
DATA(0xD0);
DATA(0x0A);
DATA(0x10);
DATA(0x0A);
DATA(0x0A);
DATA(0x26);
DATA(0x36);
DATA(0x34);
DATA(0x4D);
DATA(0x18);
DATA(0x13);
DATA(0x14);
DATA(0x2F);
DATA(0x34);
// negative voltage correction
CMD(0xE1);
DATA(0xD0);
DATA(0x0A);
DATA(0x10);
DATA(0x0A);
DATA(0x09);
DATA(0x26);
DATA(0x36);
DATA(0x53);
DATA(0x4C);
DATA(0x18);
DATA(0x14);
DATA(0x14);
DATA(0x2F);
DATA(0x34);
}
void lx154a2482_init_seq(void) {
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);
// Memory Data Access Control (MADCTL)
CMD(0x36);
DATA(0x00);
// Interface Pixel Format
CMD(0x3A);
DATA(0x05);
// Column Address Set
CMD(0x2A);
DATA(0x00);
DATA(0x00);
DATA(0x00);
DATA(0xEF);
// Row Address Set
CMD(0x2B);
DATA(0x00);
DATA(0x00);
DATA(0x00);
DATA(0xEF);
// Porch Setting
CMD(0xB2);
DATA(0x0C);
DATA(0x0C);
DATA(0x00);
DATA(0x33);
DATA(0x33);
// VCOM Setting
CMD(0xBB);
DATA(0x1F);
// LCMCTRL: LCM Control: XOR RGB setting
CMD(0xC0);
DATA(0x20);
// VDV and VRH Command Enable
CMD(0xC2);
DATA(0x01);
// VRH Set
CMD(0xC3);
DATA(0x0F); // 4.3V
// VDV Setting
CMD(0xC4);
DATA(0x20);
// Frame Rate Control in Normal Mode
CMD(0xC6);
DATA(0xEF); // column inversion //0X0F Dot INV, 60Hz
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is gate 80.;
// gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11);
// INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On
CMD(0x21);
// the above config is the most important and definitely necessary
// PWCTRL1: Power Control 1
CMD(0xD0);
DATA(0xA4);
DATA(0xA1);
lx154a2482_gamma();
}
void lx154a2482_rotate(int degrees, display_padding_t* padding) {
uint16_t shift = 0;
char BX = 0, BY = 0;
#define RGB (1 << 3)
#define ML (1 << 4) // vertical refresh order
#define MH (1 << 2) // horizontal refresh order
#define MV (1 << 5)
#define MX (1 << 6)
#define MY (1 << 7)
// MADCTL: Memory Data Access Control - reference:
// section 8.12 in the ST7789V manual
uint8_t display_command_parameter = 0;
switch (degrees) {
case 0:
display_command_parameter = 0;
BY = 0;
break;
case 90:
display_command_parameter = MV | MX | MH | ML;
BX = 1;
shift = 1;
break;
case 180:
display_command_parameter = MX | MY | MH | ML;
BY = 0;
shift = 1;
break;
case 270:
display_command_parameter = MV | MY;
BX = 1;
break;
}
CMD(0x36);
DATA(display_command_parameter);
if (shift) {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x00);
DATA(0x11);
} else {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11);
}
// reset the column and page extents
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
padding->x = BX ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
padding->y = BY ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
}

View File

@ -0,0 +1,10 @@
#ifndef LX154A2422_H_
#define LX154A2422_H_
#include "displays/st7789v.h"
void lx154a2482_init_seq(void);
void lx154a2482_gamma(void);
void lx154a2482_rotate(int degrees, display_padding_t* padding);
#endif

View File

@ -54,12 +54,12 @@ def configure(
sources += ["embed/trezorhal/stm32u5/xdisplay/st-7789/display_io.c"]
sources += ["embed/trezorhal/stm32u5/xdisplay/st-7789/display_panel.c"]
sources += [
"embed/trezorhal/stm32u5/xdisplay/st-7789/panels/lx154a2422.c",
"embed/trezorhal/stm32u5/xdisplay/st-7789/panels/lx154a2482.c",
]
else:
sources += [f"embed/trezorhal/stm32u5/displays/{display}"]
sources += [
"embed/trezorhal/stm32u5/displays/panels/lx154a2422.c",
"embed/trezorhal/stm32u5/displays/panels/lx154a2482.c",
]
sources += ["embed/trezorhal/stm32u5/backlight_pwm.c"]

View File

@ -55,13 +55,13 @@ def configure(
sources += ["embed/trezorhal/stm32u5/xdisplay/st-7789/display_io.c"]
sources += ["embed/trezorhal/stm32u5/xdisplay/st-7789/display_panel.c"]
sources += [
"embed/trezorhal/stm32u5/xdisplay/st-7789/panels/lx154a2422.c",
"embed/trezorhal/stm32u5/xdisplay/st-7789/panels/lx154a2482.c",
]
else:
sources += [f"embed/trezorhal/stm32u5/displays/{display}"]
sources += [
"embed/trezorhal/stm32u5/displays/panels/lx154a2422.c",
"embed/trezorhal/stm32u5/displays/panels/lx154a2482.c",
]
sources += ["embed/trezorhal/stm32u5/backlight_pwm.c"]