1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

style(core): refactor style of display-stm32_T

This commit is contained in:
Pavol Rusnak 2021-06-19 19:33:12 +02:00
parent 6fef12128b
commit 18e103bb94
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -172,8 +172,8 @@ static void display_set_orientation(int degrees) {
} }
CMD(0x36); CMD(0x36);
DATA(display_command_parameter); DATA(display_command_parameter);
display_set_window(0, 0, DISPLAY_RESX - 1, // reset the column and page extents
DISPLAY_RESY - 1); // reset the column and page extents display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
} }
BUFFER_OFFSET.x = BX ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0; BUFFER_OFFSET.x = BX ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
BUFFER_OFFSET.y = BY ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0; BUFFER_OFFSET.y = BY ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
@ -183,51 +183,61 @@ static void display_set_backlight(int val) {
TIM1->CCR1 = LED_PWM_TIM_PERIOD * val / 255; TIM1->CCR1 = LED_PWM_TIM_PERIOD * val / 255;
} }
void display_init_seq(void) { static void send_init_seq_GC9307(void) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); // LCD_RST/PC14 // Inter Register Enable1
// wait 10 milliseconds. only needs to be low for 10 microseconds. CMD(0xFE);
// my dev display module ties display reset and touch panel reset together.
// keeping this low for max(display_reset_time, ctpm_reset_time) aids
// development and does not hurt.
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET); // LCD_RST/PC14
// max wait time for hardware reset is 120 milliseconds
// (experienced display flakiness using only 5ms wait before sending commands)
HAL_Delay(120);
// identify the controller we will communicate with // Inter Register Enable2
uint32_t id = display_identify(); CMD(0xEF);
if (id == DISPLAY_ID_GC9307) {
CMD(0xFE); // Inter Register Enable1 // TEON: Tearing Effect Line On; V-blanking only
CMD(0xEF); // Inter Register Enable2
CMD(0x35); CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A); CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB DATA(0x55);
// 5-6-5 bits input)
// CMD(0xE8); DATA(0x12); DATA(0x00); // Frame Rate // Frame Rate
// CMD(0xE8); DATA(0x12); DATA(0x00);
// Power Control 2
CMD(0xC3); CMD(0xC3);
DATA(0x27); // Power Control 2 DATA(0x27);
// Power Control 3
CMD(0xC4); CMD(0xC4);
DATA(0x18); // Power Control 3 DATA(0x18);
// Power Control 4
CMD(0xC9); CMD(0xC9);
DATA(0x1F); // Power Control 4 DATA(0x1F);
CMD(0xC5); CMD(0xC5);
DATA(0x0F); DATA(0x0F);
CMD(0xC6); CMD(0xC6);
DATA(0x00); DATA(0x00);
CMD(0xC7); CMD(0xC7);
DATA(0x10); DATA(0x10);
CMD(0xC8); CMD(0xC8);
DATA(0x01); DATA(0x01);
CMD(0xFF); CMD(0xFF);
DATA(0x62); DATA(0x62);
CMD(0x99); CMD(0x99);
DATA(0x3E); DATA(0x3E);
CMD(0x9D); CMD(0x9D);
DATA(0x4B); DATA(0x4B);
CMD(0x8E); CMD(0x8E);
DATA(0x0F); DATA(0x0F);
// SET_GAMMA1 // SET_GAMMA1
CMD(0xF0); CMD(0xF0);
DATA(0x8F); DATA(0x8F);
@ -236,6 +246,7 @@ void display_init_seq(void) {
DATA(0x06); DATA(0x06);
DATA(0x07); DATA(0x07);
DATA(0x42); DATA(0x42);
// SET_GAMMA3 // SET_GAMMA3
CMD(0xF2); CMD(0xF2);
DATA(0x5C); DATA(0x5C);
@ -244,6 +255,7 @@ void display_init_seq(void) {
DATA(0x10); DATA(0x10);
DATA(0x07); DATA(0x07);
DATA(0x43); DATA(0x43);
// SET_GAMMA2 // SET_GAMMA2
CMD(0xF1); CMD(0xF1);
DATA(0x59); DATA(0x59);
@ -252,6 +264,7 @@ void display_init_seq(void) {
DATA(0x35); DATA(0x35);
DATA(0x37); DATA(0x37);
DATA(0x8F); DATA(0x8F);
// SET_GAMMA4 // SET_GAMMA4
CMD(0xF3); CMD(0xF3);
DATA(0x58); DATA(0x58);
@ -260,90 +273,136 @@ void display_init_seq(void) {
DATA(0x35); DATA(0x35);
DATA(0x37); DATA(0x37);
DATA(0x8F); DATA(0x8F);
} else if (id == DISPLAY_ID_ST7789V) { }
static void send_init_seq_ST7789V(void) {
// most recent manual: // most recent manual:
// https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf // https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35); CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A); CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB DATA(0x55);
// 5-6-5 bits input)
// CMD2EN: Commands in command table 2 can be executed when EXTC level is Low
CMD(0xDF); CMD(0xDF);
DATA(0x5A); DATA(0x5A);
DATA(0x69); DATA(0x69);
DATA(0x02); DATA(0x02);
DATA(0x01); // CMD2EN: Commands in command table 2 can be executed when DATA(0x01);
// EXTC level is Low
// LCMCTRL: LCM Control: XOR RGB setting
CMD(0xC0); CMD(0xC0);
DATA(0x20); // LCMCTRL: LCM Control: XOR RGB setting DATA(0x20);
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is gate 80.;
// gate scan direction 319 -> 0
CMD(0xE4); CMD(0xE4);
DATA(0x1D); DATA(0x1D);
DATA(0x0A); DATA(0x0A);
DATA(0x11); // GATECTRL: Gate Control; NL = 240 gate lines, first scan line DATA(0x11);
// is gate 80.; gate scan direction 319 -> 0
// INVOFF (20h): Display Inversion Off // INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On // INVON (21h): Display Inversion On
CMD(0x20 | DISPLAY_ST7789V_INVERT_COLORS); CMD(0x20 | DISPLAY_ST7789V_INVERT_COLORS);
// the above config is the most important and definitely necessary // the above config is the most important and definitely necessary
// PWCTRL1: Power Control 1
CMD(0xD0); CMD(0xD0);
DATA(0xA4); DATA(0xA4);
DATA(0xA1); // PWCTRL1: Power Control 1 DATA(0xA1);
// gamma curve 1 // gamma curve 1
// CMD(0xE0); DATA(0x70); DATA(0x2C); DATA(0x2E); DATA(0x15); DATA(0x10); // CMD(0xE0); DATA(0x70); DATA(0x2C); DATA(0x2E); DATA(0x15); DATA(0x10);
// DATA(0x09); DATA(0x48); DATA(0x33); DATA(0x53); DATA(0x0B); DATA(0x19); // DATA(0x09); DATA(0x48); DATA(0x33); DATA(0x53); DATA(0x0B); DATA(0x19);
// DATA(0x18); DATA(0x20); DATA(0x25); gamma curve 2 CMD(0xE1); DATA(0x70); // DATA(0x18); DATA(0x20); DATA(0x25);
// gamma curve 2
// CMD(0xE1); DATA(0x70);
// DATA(0x2C); DATA(0x2E); DATA(0x15); DATA(0x10); DATA(0x09); DATA(0x48); // DATA(0x2C); DATA(0x2E); DATA(0x15); DATA(0x10); DATA(0x09); DATA(0x48);
// DATA(0x33); DATA(0x53); DATA(0x0B); DATA(0x19); DATA(0x18); DATA(0x20); // DATA(0x33); DATA(0x53); DATA(0x0B); DATA(0x19); DATA(0x18); DATA(0x20);
// DATA(0x25); // DATA(0x25);
} else if (id == DISPLAY_ID_ILI9341V) { }
static void send_init_seq_ILI9341V(void) {
// most recent manual: https://www.newhavendisplay.com/app_notes/ILI9341.pdf // most recent manual: https://www.newhavendisplay.com/app_notes/ILI9341.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35); CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A); CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB DATA(0x55);
// 5-6-5 bits input)
// Display Function Control: gate scan direction 319 -> 0
CMD(0xB6); CMD(0xB6);
DATA(0x0A); DATA(0x0A);
DATA(0xC2); DATA(0xC2);
DATA(0x27); DATA(0x27);
DATA(0x00); // Display Function Control: gate scan direction 319 -> 0 DATA(0x00);
// Interface Control: XOR BGR as ST7789V does
CMD(0xF6); CMD(0xF6);
DATA(0x09); DATA(0x09);
DATA(0x30); DATA(0x30);
DATA(0x00); // Interface Control: XOR BGR as ST7789V does DATA(0x00);
// the above config is the most important and definitely necessary // the above config is the most important and definitely necessary
CMD(0xCF); CMD(0xCF);
DATA(0x00); DATA(0x00);
DATA(0xC1); DATA(0xC1);
DATA(0x30); DATA(0x30);
CMD(0xED); CMD(0xED);
DATA(0x64); DATA(0x64);
DATA(0x03); DATA(0x03);
DATA(0x12); DATA(0x12);
DATA(0x81); DATA(0x81);
CMD(0xE8); CMD(0xE8);
DATA(0x85); DATA(0x85);
DATA(0x10); DATA(0x10);
DATA(0x7A); DATA(0x7A);
CMD(0xF7); CMD(0xF7);
DATA(0x20); DATA(0x20);
CMD(0xEA); CMD(0xEA);
DATA(0x00); DATA(0x00);
DATA(0x00); DATA(0x00);
// power control VRH[5:0]
CMD(0xC0); CMD(0xC0);
DATA(0x23); // power control VRH[5:0] DATA(0x23);
// power control SAP[2:0] BT[3:0]
CMD(0xC1); CMD(0xC1);
DATA(0x12); // power control SAP[2:0] BT[3:0] DATA(0x12);
// vcm control 1
CMD(0xC5); CMD(0xC5);
DATA(0x60); DATA(0x60);
DATA(0x44); // vcm control 1 DATA(0x44);
// vcm control 2
CMD(0xC7); CMD(0xC7);
DATA(0x8A); // vcm control 2 DATA(0x8A);
// framerate
CMD(0xB1); CMD(0xB1);
DATA(0x00); DATA(0x00);
DATA(0x18); // framerate DATA(0x18);
// 3 gamma func disable
CMD(0xF2); CMD(0xF2);
DATA(0x00); // 3 gamma func disable DATA(0x00);
// gamma curve 1 // gamma curve 1
CMD(0xE0); CMD(0xE0);
DATA(0x0F); DATA(0x0F);
@ -361,6 +420,7 @@ void display_init_seq(void) {
DATA(0x0C); DATA(0x0C);
DATA(0x06); DATA(0x06);
DATA(0x00); DATA(0x00);
// gamma curve 2 // gamma curve 2
CMD(0xE1); CMD(0xE1);
DATA(0x00); DATA(0x00);
@ -378,6 +438,28 @@ void display_init_seq(void) {
DATA(0x33); DATA(0x33);
DATA(0x39); DATA(0x39);
DATA(0x0F); DATA(0x0F);
}
void display_init_seq(void) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); // LCD_RST/PC14
// wait 10 milliseconds. only needs to be low for 10 microseconds.
// my dev display module ties display reset and touch panel reset together.
// keeping this low for max(display_reset_time, ctpm_reset_time) aids
// development and does not hurt.
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET); // LCD_RST/PC14
// max wait time for hardware reset is 120 milliseconds
// (experienced display flakiness using only 5ms wait before sending commands)
HAL_Delay(120);
// identify the controller we will communicate with
uint32_t id = display_identify();
if (id == DISPLAY_ID_GC9307) {
send_init_seq_GC9307();
} else if (id == DISPLAY_ID_ST7789V) {
send_init_seq_ST7789V();
} else if (id == DISPLAY_ID_ILI9341V) {
send_init_seq_ILI9341V();
} }
display_clear(); display_clear();
@ -433,8 +515,8 @@ void display_init(void) {
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Alternate = 0; GPIO_InitStructure.Alternate = 0;
GPIO_InitStructure.Pin = GPIO_PIN_14; GPIO_InitStructure.Pin = GPIO_PIN_14;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, // default to keeping display in reset
GPIO_PIN_RESET); // default to keeping display in reset HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
// LCD_FMARK/PD12 (tearing effect) // LCD_FMARK/PD12 (tearing effect)
@ -449,16 +531,13 @@ void display_init(void) {
GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF12_FMC; GPIO_InitStructure.Alternate = GPIO_AF12_FMC;
// LCD_CS/PD7 LCD_RS/PD11 LCD_RD/PD4 // LCD_CS/PD7 LCD_RS/PD11 LCD_RD/PD4 LCD_WR/PD5
// LCD_WR/PD5
GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_11 | GPIO_PIN_4 | GPIO_PIN_5; GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_11 | GPIO_PIN_4 | GPIO_PIN_5;
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure); HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
// LCD_D0/PD14 LCD_D1/PD15 LCD_D2/PD0 // LCD_D0/PD14 LCD_D1/PD15 LCD_D2/PD0 LCD_D3/PD1
// LCD_D3/PD1
GPIO_InitStructure.Pin = GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_0 | GPIO_PIN_1; GPIO_InitStructure.Pin = GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_0 | GPIO_PIN_1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure); HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
// LCD_D4/PE7 LCD_D5/PE8 LCD_D6/PE9 // LCD_D4/PE7 LCD_D5/PE8 LCD_D6/PE9 LCD_D7/PE10
// LCD_D7/PE10
GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
@ -504,8 +583,8 @@ void display_init(void) {
void display_refresh(void) { void display_refresh(void) {
uint32_t id = display_identify(); uint32_t id = display_identify();
if (id && (id != DISPLAY_ID_GC9307)) { if (id && (id != DISPLAY_ID_GC9307)) {
// synchronize with the panel synchronization signal in order to avoid // synchronize with the panel synchronization signal
// visual tearing effects // in order to avoid visual tearing effects
while (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) { while (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) {
} }
while (GPIO_PIN_SET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) { while (GPIO_PIN_SET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) {