1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +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);
DATA(display_command_parameter);
display_set_window(0, 0, DISPLAY_RESX - 1,
DISPLAY_RESY - 1); // reset the column and page extents
// 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.y = BY ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
@ -183,6 +183,263 @@ static void display_set_backlight(int val) {
TIM1->CCR1 = LED_PWM_TIM_PERIOD * val / 255;
}
static void send_init_seq_GC9307(void) {
// Inter Register Enable1
CMD(0xFE);
// Inter Register Enable2
CMD(0xEF);
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);
// Frame Rate
// CMD(0xE8); DATA(0x12); DATA(0x00);
// Power Control 2
CMD(0xC3);
DATA(0x27);
// Power Control 3
CMD(0xC4);
DATA(0x18);
// Power Control 4
CMD(0xC9);
DATA(0x1F);
CMD(0xC5);
DATA(0x0F);
CMD(0xC6);
DATA(0x00);
CMD(0xC7);
DATA(0x10);
CMD(0xC8);
DATA(0x01);
CMD(0xFF);
DATA(0x62);
CMD(0x99);
DATA(0x3E);
CMD(0x9D);
DATA(0x4B);
CMD(0x8E);
DATA(0x0F);
// SET_GAMMA1
CMD(0xF0);
DATA(0x8F);
DATA(0x1B);
DATA(0x05);
DATA(0x06);
DATA(0x07);
DATA(0x42);
// SET_GAMMA3
CMD(0xF2);
DATA(0x5C);
DATA(0x1F);
DATA(0x12);
DATA(0x10);
DATA(0x07);
DATA(0x43);
// SET_GAMMA2
CMD(0xF1);
DATA(0x59);
DATA(0xCF);
DATA(0xCF);
DATA(0x35);
DATA(0x37);
DATA(0x8F);
// SET_GAMMA4
CMD(0xF3);
DATA(0x58);
DATA(0xCF);
DATA(0xCF);
DATA(0x35);
DATA(0x37);
DATA(0x8F);
}
static void send_init_seq_ST7789V(void) {
// most recent manual:
// https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);
// CMD2EN: Commands in command table 2 can be executed when EXTC level is Low
CMD(0xDF);
DATA(0x5A);
DATA(0x69);
DATA(0x02);
DATA(0x01);
// LCMCTRL: LCM Control: XOR RGB setting
CMD(0xC0);
DATA(0x20);
// 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(0x20 | DISPLAY_ST7789V_INVERT_COLORS);
// the above config is the most important and definitely necessary
// PWCTRL1: Power Control 1
CMD(0xD0);
DATA(0xA4);
DATA(0xA1);
// gamma curve 1
// 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(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(0x33); DATA(0x53); DATA(0x0B); DATA(0x19); DATA(0x18); DATA(0x20);
// DATA(0x25);
}
static void send_init_seq_ILI9341V(void) {
// most recent manual: https://www.newhavendisplay.com/app_notes/ILI9341.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);
// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);
// Display Function Control: gate scan direction 319 -> 0
CMD(0xB6);
DATA(0x0A);
DATA(0xC2);
DATA(0x27);
DATA(0x00);
// Interface Control: XOR BGR as ST7789V does
CMD(0xF6);
DATA(0x09);
DATA(0x30);
DATA(0x00);
// the above config is the most important and definitely necessary
CMD(0xCF);
DATA(0x00);
DATA(0xC1);
DATA(0x30);
CMD(0xED);
DATA(0x64);
DATA(0x03);
DATA(0x12);
DATA(0x81);
CMD(0xE8);
DATA(0x85);
DATA(0x10);
DATA(0x7A);
CMD(0xF7);
DATA(0x20);
CMD(0xEA);
DATA(0x00);
DATA(0x00);
// power control VRH[5:0]
CMD(0xC0);
DATA(0x23);
// power control SAP[2:0] BT[3:0]
CMD(0xC1);
DATA(0x12);
// vcm control 1
CMD(0xC5);
DATA(0x60);
DATA(0x44);
// vcm control 2
CMD(0xC7);
DATA(0x8A);
// framerate
CMD(0xB1);
DATA(0x00);
DATA(0x18);
// 3 gamma func disable
CMD(0xF2);
DATA(0x00);
// gamma curve 1
CMD(0xE0);
DATA(0x0F);
DATA(0x2F);
DATA(0x2C);
DATA(0x0B);
DATA(0x0F);
DATA(0x09);
DATA(0x56);
DATA(0xD9);
DATA(0x4A);
DATA(0x0B);
DATA(0x14);
DATA(0x05);
DATA(0x0C);
DATA(0x06);
DATA(0x00);
// gamma curve 2
CMD(0xE1);
DATA(0x00);
DATA(0x10);
DATA(0x13);
DATA(0x04);
DATA(0x10);
DATA(0x06);
DATA(0x25);
DATA(0x26);
DATA(0x3B);
DATA(0x04);
DATA(0x0B);
DATA(0x0A);
DATA(0x33);
DATA(0x39);
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.
@ -198,186 +455,11 @@ void display_init_seq(void) {
// identify the controller we will communicate with
uint32_t id = display_identify();
if (id == DISPLAY_ID_GC9307) {
CMD(0xFE); // Inter Register Enable1
CMD(0xEF); // Inter Register Enable2
CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only
CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB
// 5-6-5 bits input)
// CMD(0xE8); DATA(0x12); DATA(0x00); // Frame Rate
CMD(0xC3);
DATA(0x27); // Power Control 2
CMD(0xC4);
DATA(0x18); // Power Control 3
CMD(0xC9);
DATA(0x1F); // Power Control 4
CMD(0xC5);
DATA(0x0F);
CMD(0xC6);
DATA(0x00);
CMD(0xC7);
DATA(0x10);
CMD(0xC8);
DATA(0x01);
CMD(0xFF);
DATA(0x62);
CMD(0x99);
DATA(0x3E);
CMD(0x9D);
DATA(0x4B);
CMD(0x8E);
DATA(0x0F);
// SET_GAMMA1
CMD(0xF0);
DATA(0x8F);
DATA(0x1B);
DATA(0x05);
DATA(0x06);
DATA(0x07);
DATA(0x42);
// SET_GAMMA3
CMD(0xF2);
DATA(0x5C);
DATA(0x1F);
DATA(0x12);
DATA(0x10);
DATA(0x07);
DATA(0x43);
// SET_GAMMA2
CMD(0xF1);
DATA(0x59);
DATA(0xCF);
DATA(0xCF);
DATA(0x35);
DATA(0x37);
DATA(0x8F);
// SET_GAMMA4
CMD(0xF3);
DATA(0x58);
DATA(0xCF);
DATA(0xCF);
DATA(0x35);
DATA(0x37);
DATA(0x8F);
send_init_seq_GC9307();
} else if (id == DISPLAY_ID_ST7789V) {
// most recent manual:
// https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only
CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB
// 5-6-5 bits input)
CMD(0xDF);
DATA(0x5A);
DATA(0x69);
DATA(0x02);
DATA(0x01); // CMD2EN: Commands in command table 2 can be executed when
// EXTC level is Low
CMD(0xC0);
DATA(0x20); // LCMCTRL: LCM Control: XOR RGB setting
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11); // GATECTRL: Gate Control; NL = 240 gate lines, first scan line
// is gate 80.; gate scan direction 319 -> 0
// INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On
CMD(0x20 | DISPLAY_ST7789V_INVERT_COLORS);
// the above config is the most important and definitely necessary
CMD(0xD0);
DATA(0xA4);
DATA(0xA1); // PWCTRL1: Power Control 1
// gamma curve 1
// 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(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(0x33); DATA(0x53); DATA(0x0B); DATA(0x19); DATA(0x18); DATA(0x20);
// DATA(0x25);
send_init_seq_ST7789V();
} else if (id == DISPLAY_ID_ILI9341V) {
// most recent manual: https://www.newhavendisplay.com/app_notes/ILI9341.pdf
CMD(0x35);
DATA(0x00); // TEON: Tearing Effect Line On; V-blanking only
CMD(0x3A);
DATA(0x55); // COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB
// 5-6-5 bits input)
CMD(0xB6);
DATA(0x0A);
DATA(0xC2);
DATA(0x27);
DATA(0x00); // Display Function Control: gate scan direction 319 -> 0
CMD(0xF6);
DATA(0x09);
DATA(0x30);
DATA(0x00); // Interface Control: XOR BGR as ST7789V does
// the above config is the most important and definitely necessary
CMD(0xCF);
DATA(0x00);
DATA(0xC1);
DATA(0x30);
CMD(0xED);
DATA(0x64);
DATA(0x03);
DATA(0x12);
DATA(0x81);
CMD(0xE8);
DATA(0x85);
DATA(0x10);
DATA(0x7A);
CMD(0xF7);
DATA(0x20);
CMD(0xEA);
DATA(0x00);
DATA(0x00);
CMD(0xC0);
DATA(0x23); // power control VRH[5:0]
CMD(0xC1);
DATA(0x12); // power control SAP[2:0] BT[3:0]
CMD(0xC5);
DATA(0x60);
DATA(0x44); // vcm control 1
CMD(0xC7);
DATA(0x8A); // vcm control 2
CMD(0xB1);
DATA(0x00);
DATA(0x18); // framerate
CMD(0xF2);
DATA(0x00); // 3 gamma func disable
// gamma curve 1
CMD(0xE0);
DATA(0x0F);
DATA(0x2F);
DATA(0x2C);
DATA(0x0B);
DATA(0x0F);
DATA(0x09);
DATA(0x56);
DATA(0xD9);
DATA(0x4A);
DATA(0x0B);
DATA(0x14);
DATA(0x05);
DATA(0x0C);
DATA(0x06);
DATA(0x00);
// gamma curve 2
CMD(0xE1);
DATA(0x00);
DATA(0x10);
DATA(0x13);
DATA(0x04);
DATA(0x10);
DATA(0x06);
DATA(0x25);
DATA(0x26);
DATA(0x3B);
DATA(0x04);
DATA(0x0B);
DATA(0x0A);
DATA(0x33);
DATA(0x39);
DATA(0x0F);
send_init_seq_ILI9341V();
}
display_clear();
@ -433,8 +515,8 @@ void display_init(void) {
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Alternate = 0;
GPIO_InitStructure.Pin = GPIO_PIN_14;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14,
GPIO_PIN_RESET); // default to keeping display in reset
// default to keeping display in reset
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
// LCD_FMARK/PD12 (tearing effect)
@ -449,16 +531,13 @@ void display_init(void) {
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF12_FMC;
// LCD_CS/PD7 LCD_RS/PD11 LCD_RD/PD4
// LCD_WR/PD5
// LCD_CS/PD7 LCD_RS/PD11 LCD_RD/PD4 LCD_WR/PD5
GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_11 | GPIO_PIN_4 | GPIO_PIN_5;
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
// LCD_D0/PD14 LCD_D1/PD15 LCD_D2/PD0
// LCD_D3/PD1
// LCD_D0/PD14 LCD_D1/PD15 LCD_D2/PD0 LCD_D3/PD1
GPIO_InitStructure.Pin = GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_0 | GPIO_PIN_1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
// LCD_D4/PE7 LCD_D5/PE8 LCD_D6/PE9
// LCD_D7/PE10
// 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);
@ -504,8 +583,8 @@ void display_init(void) {
void display_refresh(void) {
uint32_t id = display_identify();
if (id && (id != DISPLAY_ID_GC9307)) {
// synchronize with the panel synchronization signal in order to avoid
// visual tearing effects
// synchronize with the panel synchronization signal
// in order to avoid visual tearing effects
while (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) {
}
while (GPIO_PIN_SET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) {