1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 08:08:51 +00:00

minor changes to display module

This commit is contained in:
Pavol Rusnak 2016-09-24 16:53:43 +02:00
parent ddaa1b1502
commit 0d3facf99e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 58 additions and 62 deletions

View File

@ -133,66 +133,64 @@ static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
int display_orientation(int degrees)
{
if (degrees != ORIENTATION) {
// memory access control
switch (degrees) {
case 0:
CMD(0x36);
// memory access control
switch (degrees) {
case 0:
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(0x08 | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
DATA(0x08 | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
#endif
#if DISPLAY_ST7789V
DATA(0x00 | (1<<5));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
DATA(0x00 | (1<<5));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
#endif
ORIENTATION = 0;
break;
case 90:
CMD(0x36);
ORIENTATION = 0;
break;
case 90:
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(0x08 | (1<<5) | (1<<6));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
DATA(0x08 | (1<<5) | (1<<6));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(0x00 | (1<<6));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
DATA(0x00 | (1<<6));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
#endif
ORIENTATION = 90;
break;
case 180:
CMD(0x36);
ORIENTATION = 90;
break;
case 180:
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(0x08);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
DATA(0x08);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(0x00 | (1<<5) | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
DATA(0x00 | (1<<5) | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
#endif
ORIENTATION = 180;
break;
case 270:
CMD(0x36);
ORIENTATION = 180;
break;
case 270:
CMD(0x36);
#if DISPLAY_ILI9341V
DATA(0x08 | (1<<5) | (1<<7));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
DATA(0x08 | (1<<5) | (1<<7));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
#endif
#if DISPLAY_ST7789V
DATA(0x00 | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
DATA(0x00 | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
#endif
ORIENTATION = 270;
break;
}
ORIENTATION = 270;
break;
}
return ORIENTATION;
}
@ -213,7 +211,6 @@ void display_init(void) {
CMD(0xC1); DATA(0x12); // power control SAP[2:0] BT[3:0]
CMD(0xC5); DATAS("\x60\x44", 2); // vcm control 1
CMD(0xC7); DATA(0x8A); // vcm control 2
display_orientation(0);
CMD(0x3A); DATA(0x55); // memory access control (16-bit 565)
CMD(0xB1); DATAS("\x00\x18", 2); // framerate
#endif
@ -232,12 +229,11 @@ void display_init(void) {
#endif
#if DISPLAY_ST7789V
CMD(0x20); // don't invert colors
// weird hack needed :-/
display_orientation(180);
display_orientation(0);
#endif
display_orientation(0);
display_backlight(0);
// clear buffer
display_bar(0, 0, 240, 240, 0x0000);
display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, 0x0000);
display_unsleep();
}
@ -258,7 +254,7 @@ void display_update(void) {
int display_backlight(int val)
{
if (BACKLIGHT != val && val >= 0 && val <= 255) {
if (val >= 0 && val <= 255) {
BACKLIGHT = val;
__HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * BACKLIGHT / 255);
}

View File

@ -45,7 +45,7 @@ uint32_t trezorui_poll_sdl_event(void)
case SDL_MOUSEBUTTONUP:
x = event.button.x - DISPLAY_BORDER;
y = event.button.y - DISPLAY_BORDER;
if (x < 0 || y < 0 || x >= RESX || y >= RESY) break;
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start
@ -80,7 +80,7 @@ void display_init(void)
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init Error: %s\n", SDL_GetError());
}
SDL_Window *win = SDL_CreateWindow("TREZOR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESX + 2 * DISPLAY_BORDER, RESY + 2 * DISPLAY_BORDER, SDL_WINDOW_SHOWN);
SDL_Window *win = SDL_CreateWindow("TREZOR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DISPLAY_RESX + 2 * DISPLAY_BORDER, DISPLAY_RESY + 2 * DISPLAY_BORDER, SDL_WINDOW_SHOWN);
if (!win) {
printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
@ -93,8 +93,8 @@ void display_init(void)
}
SDL_SetRenderDrawColor(RENDERER, BACKLIGHT, BACKLIGHT, BACKLIGHT, 255);
SDL_RenderClear(RENDERER);
SCREEN = SDL_CreateRGBSurface(0, RESX, RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
SCREEN = SDL_CreateRGBSurface(0, DISPLAY_RESX, DISPLAY_RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, DISPLAY_RESY);
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE);
SDL_SetTextureAlphaMod(TEXTURE, 0);
}
@ -111,7 +111,7 @@ void display_update(void)
{
SDL_RenderClear(RENDERER);
SDL_UpdateTexture(TEXTURE, NULL, SCREEN->pixels, SCREEN->pitch);
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, RESX, RESY};
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, DISPLAY_RESX, DISPLAY_RESY};
SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, ORIENTATION, NULL, 0);
SDL_RenderPresent(RENDERER);
}

View File

@ -258,7 +258,7 @@ void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const
if (icon) {
set_color_table(iconcolortable, iconfgcolor, bgcolor);
}
display_set_window(RESX / 2 - img_loader_size, RESY * 2 / 5 - img_loader_size, img_loader_size * 2, img_loader_size * 2);
display_set_window(DISPLAY_RESX / 2 - img_loader_size, DISPLAY_RESY * 2 / 5 - img_loader_size, img_loader_size * 2, img_loader_size * 2);
if (icon && memcmp(icon, "TOIg\x60\x00\x60\x00", 8) == 0 && iconlen == 12 + *(uint32_t *)(icon + 8)) {
uint8_t icondata[96 * 96 / 2];
sinf_inflate(icon + 12, iconlen - 12, inflate_callback_loader, icondata);

View File

@ -8,8 +8,8 @@
#ifndef __DISPLAY_H__
#define __DISPLAY_H__
#define RESX 240
#define RESY 240
#define DISPLAY_RESX 240
#define DISPLAY_RESY 240
void display_init(void);
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);

View File

@ -32,7 +32,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_bar(size_t n_args, const mp_obj_t *args) {
mp_int_t w = mp_obj_get_int(args[3]);
mp_int_t h = mp_obj_get_int(args[4]);
uint16_t c = mp_obj_get_int(args[5]);
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
}
if (n_args > 7) {
@ -83,7 +83,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_image(size_t n_args, const mp_obj_t *args)
mp_int_t w = *(uint16_t *)(data + 4);
mp_int_t h = *(uint16_t *)(data + 6);
mp_int_t datalen = *(uint32_t *)(data + 8);
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
}
if (datalen != image.len - 12) {
@ -111,7 +111,7 @@ STATIC mp_obj_t mod_TrezorUi_Display_icon(size_t n_args, const mp_obj_t *args) {
mp_int_t w = *(uint16_t *)(data + 4);
mp_int_t h = *(uint16_t *)(data + 6);
mp_int_t datalen = *(uint32_t *)(data + 8);
if ((x < 0) || (y < 0) || (x + w > RESX) || (y + h > RESY)) {
if ((x < 0) || (y < 0) || (x + w > DISPLAY_RESX) || (y + h > DISPLAY_RESY)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Out of bounds"));
}
if (datalen != icon.len - 12) {

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit 177a7bc48bca3cd9fb8de9103fce2e26ce996c1a
Subproject commit 3e0c59a46f455b94be5a2ef1684f6f45776f5180