From 5c21c4a96b783c2039c625ae45d3c51e0d02f2e8 Mon Sep 17 00:00:00 2001 From: mcudev <29890609+mcudev@users.noreply.github.com> Date: Thu, 7 Sep 2017 16:19:27 -0400 Subject: [PATCH] better support ILI9341 testing, make tearing effect synch optional, minor fixes --- Makefile | 14 ++++++-- SConscript.boardloader | 2 +- SConscript.bootloader | 2 +- SConscript.firmware | 2 +- embed/extmod/modtrezorui/display-stm32.h | 41 +++++++++++++----------- embed/extmod/modtrezorui/display.h | 4 +++ embed/trezorhal/common.c | 9 ++---- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 6c4445f7c..5791ced01 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,14 @@ UNIX_PORT_OPTS ?= TREZOR_X86=1 endif CROSS_PORT_OPTS ?= MICROPY_FORCE_32BIT=1 +ifeq ($(DISPLAY_ILI9341V), 1) +CFLAGS += -DDISPLAY_ILI9341V=1 +CFLAGS += -DDISPLAY_ST7789V=0 +endif + +ifeq ($(DISPLAY_VSYNC), 0) +CFLAGS += -DDISPLAY_VSYNC=0 +endif ## help commands: @@ -57,13 +65,13 @@ style: ## run code style check on application sources build: build_boardloader build_bootloader build_firmware build_unix build_cross ## build all build_boardloader: ## build boardloader - $(SCONS) build/boardloader/boardloader.bin + $(SCONS) CFLAGS="$(CFLAGS)" build/boardloader/boardloader.bin build_bootloader: ## build bootloader - $(SCONS) build/bootloader/bootloader.bin + $(SCONS) CFLAGS="$(CFLAGS)" build/bootloader/bootloader.bin build_firmware: res build_cross ## build firmware with frozen modules - $(SCONS) build/firmware/firmware.bin + $(SCONS) CFLAGS="$(CFLAGS)" build/firmware/firmware.bin build_unix: ## build unix port $(SCONS) build/unix/micropython $(UNIX_PORT_OPTS) diff --git a/SConscript.boardloader b/SConscript.boardloader index f8a0d2dbd..c69235d8c 100644 --- a/SConscript.boardloader +++ b/SConscript.boardloader @@ -84,7 +84,7 @@ SOURCE_TREZORHAL = [ 'embed/trezorhal/stm32_system.c', ] -env = Environment(ENV=os.environ) +env = Environment(ENV=os.environ, CFLAGS=ARGUMENTS.get('CFLAGS', '')) env.Replace( AS='arm-none-eabi-as', diff --git a/SConscript.bootloader b/SConscript.bootloader index 0dc5fd574..19f6338a1 100644 --- a/SConscript.bootloader +++ b/SConscript.bootloader @@ -102,7 +102,7 @@ SOURCE_TREZORHAL = [ 'embed/trezorhal/usbd_ioreq.c', ] -env = Environment(ENV=os.environ) +env = Environment(ENV=os.environ, CFLAGS=ARGUMENTS.get('CFLAGS', '')) env.Replace( AS='arm-none-eabi-as', diff --git a/SConscript.firmware b/SConscript.firmware index 9ca221357..68ef26a03 100644 --- a/SConscript.firmware +++ b/SConscript.firmware @@ -299,7 +299,7 @@ SOURCE_PY.extend(Glob('src/*/*/*/*.py')) SOURCE_PY.extend(Glob('src/*/*/*/*/*.py')) SOURCE_PY_DIR = 'src/' -env = Environment(ENV=os.environ) +env = Environment(ENV=os.environ, CFLAGS=ARGUMENTS.get('CFLAGS', '')) env.Tool('micropython') diff --git a/embed/extmod/modtrezorui/display-stm32.h b/embed/extmod/modtrezorui/display-stm32.h index 133b342ca..8b2a9adc0 100644 --- a/embed/extmod/modtrezorui/display-stm32.h +++ b/embed/extmod/modtrezorui/display-stm32.h @@ -7,8 +7,17 @@ #include STM32_HAL_H +#ifndef DISPLAY_ILI9341V #define DISPLAY_ILI9341V 0 +#endif + +#ifndef DISPLAY_ST7789V #define DISPLAY_ST7789V 1 +#endif + +#ifndef DISPLAY_VSYNC +#define DISPLAY_VSYNC 1 +#endif // FSMC Bank 1 - NOR/PSRAM 1 #define DISPLAY_FSMC_BASE 0x60000000 @@ -62,53 +71,45 @@ void display_set_orientation(int degrees) CMD(0x36); #if DISPLAY_ILI9341V DATA(BGR | MX | MY); - BUFFER_OFFSET_X = 0; - BUFFER_OFFSET_Y = 80; #endif #if DISPLAY_ST7789V - DATA(RGB | MX | MY ); - BUFFER_OFFSET_X = 0; - BUFFER_OFFSET_Y = 80; + DATA(RGB | MX | MY); #endif + BUFFER_OFFSET_X = 0; + BUFFER_OFFSET_Y = MAX_DISPLAY_RESY - DISPLAY_RESY; break; case 90: CMD(0x36); #if DISPLAY_ILI9341V - DATA(BGR | MV | MX); - BUFFER_OFFSET_X = 0; - BUFFER_OFFSET_Y = 0; + DATA(BGR | MV | MY); #endif #if DISPLAY_ST7789V - DATA(RGB | MV | MY ); - BUFFER_OFFSET_X = 80; - BUFFER_OFFSET_Y = 0; + DATA(RGB | MV | MY); #endif + BUFFER_OFFSET_X = MAX_DISPLAY_RESY - DISPLAY_RESX; + BUFFER_OFFSET_Y = 0; break; case 180: CMD(0x36); #if DISPLAY_ILI9341V DATA(BGR); - BUFFER_OFFSET_X = 0; - BUFFER_OFFSET_Y = 0; #endif #if DISPLAY_ST7789V DATA(RGB); +#endif BUFFER_OFFSET_X = 0; BUFFER_OFFSET_Y = 0; -#endif break; case 270: CMD(0x36); #if DISPLAY_ILI9341V - DATA(BGR | MV | MY); - BUFFER_OFFSET_X = 80; - BUFFER_OFFSET_Y = 0; + DATA(BGR | MV | MX); #endif #if DISPLAY_ST7789V DATA(RGB | MV | MX); +#endif BUFFER_OFFSET_X = 0; BUFFER_OFFSET_Y = 0; -#endif break; } } @@ -244,7 +245,7 @@ int display_init(void) { 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); - CMD(0x21); // invert colors + CMD(0x20); // don't invert colors #endif #if DISPLAY_ST7789V CMD(0x01); // software reset @@ -288,9 +289,11 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y } void display_refresh(void) { +#if DISPLAY_VSYNC // 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)) { } +#endif } void display_save(const char *filename) diff --git a/embed/extmod/modtrezorui/display.h b/embed/extmod/modtrezorui/display.h index f047844e0..1784eeb08 100644 --- a/embed/extmod/modtrezorui/display.h +++ b/embed/extmod/modtrezorui/display.h @@ -10,6 +10,10 @@ #include +// ILI9341V and ST7789V drivers both support 240px x 320px display resolution +#define MAX_DISPLAY_RESX 240 +#define MAX_DISPLAY_RESY 320 +// X and Y display resolution used #define DISPLAY_RESX 240 #define DISPLAY_RESY 240 diff --git a/embed/trezorhal/common.c b/embed/trezorhal/common.c index 820d927df..1e219d929 100644 --- a/embed/trezorhal/common.c +++ b/embed/trezorhal/common.c @@ -5,6 +5,8 @@ void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, int line, const char *func) { for (volatile uint32_t delay = 0; delay < 10000000; delay++) {} + display_orientation(0); + display_backlight(255); display_print_color(COLOR_WHITE, COLOR_RED128); display_printf("\nFATAL ERROR:\n%s\n", msg); if (file) { @@ -13,12 +15,7 @@ void __attribute__((noreturn)) __fatal_error(const char *msg, const char *file, if (func) { display_printf("Func: %s\n", func); } - for (;;) { - display_backlight(255); - HAL_Delay(950); - display_backlight(128); - HAL_Delay(50); - } + for (;;); } #ifndef NDEBUG