mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 02:58:57 +00:00
embed: add support for GC9307 display driver
This commit is contained in:
parent
f4252d755c
commit
e7a74ccfee
5
Makefile
5
Makefile
@ -21,6 +21,11 @@ CFLAGS += -DDISPLAY_ILI9341V=1
|
||||
CFLAGS += -DDISPLAY_ST7789V=0
|
||||
endif
|
||||
|
||||
ifeq ($(DISPLAY_GC9307), 1)
|
||||
CFLAGS += -DDISPLAY_GC9307=1
|
||||
CFLAGS += -DDISPLAY_ST7789V=0
|
||||
endif
|
||||
|
||||
PRODUCTION ?= 0
|
||||
|
||||
STLINK_VER ?= v2
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "common.h"
|
||||
#include "image.h"
|
||||
#include "flash.h"
|
||||
#include "display.h"
|
||||
#include "mini_printf.h"
|
||||
#include "rng.h"
|
||||
#include "secbool.h"
|
||||
@ -228,6 +229,8 @@ static void check_bootloader_version(void)
|
||||
int main(void)
|
||||
{
|
||||
main_start:
|
||||
display_clear();
|
||||
|
||||
#if PRODUCTION
|
||||
check_bootloader_version();
|
||||
#endif
|
||||
|
@ -23,6 +23,10 @@
|
||||
#define DISPLAY_ILI9341V 0
|
||||
#endif
|
||||
|
||||
#ifndef DISPLAY_GC9307
|
||||
#define DISPLAY_GC9307 0
|
||||
#endif
|
||||
|
||||
#ifndef DISPLAY_ST7789V
|
||||
#define DISPLAY_ST7789V 1
|
||||
#endif
|
||||
@ -38,23 +42,26 @@
|
||||
|
||||
#define LED_PWM_TIM_PERIOD (10000)
|
||||
|
||||
// ST7789V => 00 85 85 52
|
||||
// GC9307 => 00 00 93 07
|
||||
// ILI9341V => 00 00 00 00 (or unspecified)
|
||||
static uint32_t __attribute__((unused)) display_identify(void)
|
||||
{
|
||||
uint8_t c;
|
||||
volatile uint8_t c;
|
||||
uint32_t id = 0;
|
||||
|
||||
CMD(0x04); // RDDID: Read Display ID
|
||||
c = ADDR; id |= (c << 24);
|
||||
c = ADDR; id |= (c << 16);
|
||||
c = ADDR; id |= (c << 8);
|
||||
c = ADDR; id |= c;
|
||||
CMD(0x04); // RDDID: Read Display ID
|
||||
c = ADDR; // dummy data - discard
|
||||
c = ADDR; id |= (c << 16); // ID1 - manufacturer ID
|
||||
c = ADDR; id |= (c << 8); // ID2 - module/driver version ID
|
||||
c = ADDR; id |= c; // ID3 - module/drive ID
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) display_sleep(void)
|
||||
{
|
||||
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
||||
#if DISPLAY_ILI9341V || DISPLAY_GC9307 || DISPLAY_ST7789V
|
||||
CMD(0x28); // DISPOFF: Display Off
|
||||
CMD(0x10); // SLPIN: Sleep in
|
||||
HAL_Delay(5); // need to wait 5 milliseconds after "sleep in" before sending any new commands
|
||||
@ -63,7 +70,7 @@ static void __attribute__((unused)) display_sleep(void)
|
||||
|
||||
static void display_unsleep(void)
|
||||
{
|
||||
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
||||
#if DISPLAY_ILI9341V || DISPLAY_GC9307 || DISPLAY_ST7789V
|
||||
CMD(0x11); // SLPOUT: Sleep Out
|
||||
HAL_Delay(5); // need to wait 5 milliseconds after "sleep out" before sending any new commands
|
||||
CMD(0x29); // DISPON: Display On
|
||||
@ -78,7 +85,7 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
|
||||
{
|
||||
x0 += BUFFER_OFFSET.x; x1 += BUFFER_OFFSET.x;
|
||||
y0 += BUFFER_OFFSET.y; y1 += BUFFER_OFFSET.y;
|
||||
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
||||
#if DISPLAY_ILI9341V || DISPLAY_GC9307 || DISPLAY_ST7789V
|
||||
CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
|
||||
CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
|
||||
CMD(0x2C);
|
||||
@ -87,30 +94,46 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
|
||||
|
||||
void display_set_orientation(int degrees)
|
||||
{
|
||||
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
||||
#if DISPLAY_ILI9341V || DISPLAY_GC9307 || DISPLAY_ST7789V
|
||||
#define RGB (1 << 3)
|
||||
#define MV (1 << 5)
|
||||
#define MX (1 << 6)
|
||||
#define MY (1 << 7)
|
||||
// MADCTL: Memory Data Access Control
|
||||
// reference section 9.3 in the ILI9341 manual; 8.12 in the ST7789V manual
|
||||
// MADCTL: Memory Data Access Control - reference:
|
||||
// section 9.3 in the ILI9341 manual
|
||||
// section 6.2.18 in the GC9307 manual
|
||||
// section 8.12 in the ST7789V manual
|
||||
char BX = 0, BY = 0;
|
||||
uint8_t display_command_parameter = 0;
|
||||
switch (degrees) {
|
||||
case 0:
|
||||
display_command_parameter = 0;
|
||||
#if DISPLAY_GC9307
|
||||
BY = 1;
|
||||
#endif
|
||||
break;
|
||||
case 90:
|
||||
display_command_parameter = MV | MX;
|
||||
#if DISPLAY_GC9307
|
||||
BX = 1;
|
||||
#endif
|
||||
break;
|
||||
case 180:
|
||||
display_command_parameter = MX | MY;
|
||||
#if ! DISPLAY_GC9307
|
||||
BY = 1;
|
||||
#endif
|
||||
break;
|
||||
case 270:
|
||||
display_command_parameter = MV | MY;
|
||||
#if ! DISPLAY_GC9307
|
||||
BX = 1;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if DISPLAY_GC9307
|
||||
display_command_parameter ^= RGB | MY; // XOR RGB and MY settings
|
||||
#endif
|
||||
CMD(0x36); DATA(display_command_parameter);
|
||||
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1); // reset the column and page extents
|
||||
#endif
|
||||
@ -263,6 +286,33 @@ void display_init(void)
|
||||
// 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);
|
||||
#endif
|
||||
#if DISPLAY_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);
|
||||
|
||||
#endif
|
||||
#if DISPLAY_ST7789V
|
||||
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)
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// ILI9341V and ST7789V drivers both support 240px x 320px display resolution
|
||||
// ILI9341V, GC9307 and ST7789V drivers support 240px x 320px display resolution
|
||||
#define MAX_DISPLAY_RESX 240
|
||||
#define MAX_DISPLAY_RESY 320
|
||||
// X and Y display resolution used
|
||||
|
Loading…
Reference in New Issue
Block a user