1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

add possibility to save screen to png using ui.display.save() (unix port only)

This commit is contained in:
Pavol Rusnak 2016-10-06 00:02:46 +02:00
parent bd1774e764
commit 846846561c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
8 changed files with 106 additions and 76 deletions

View File

@ -13,28 +13,28 @@
```
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libsdl2-dev:i386
sudo apt-get install libsdl2-dev:i386 libsdl2-image-dev:i386
make build_unix
```
####Fedora
```
sudo yum install SDL2-devel.i686
sudo yum install SDL2-devel.i686 SDL2_image-devel.i686
make build_unix
```
####openSUSE
```
sudo zypper install libSDL2-devel-32bit
sudo zypper install libSDL2-devel-32bit libSDL2_image-devel-32bit
make build_unix
```
###OS X
```
brew install --universal sdl2
brew install --universal sdl2 sdl2_image
make build_unix
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -137,8 +137,75 @@ static void display_unsleep(void) {
#endif
}
void display_init(void) {
display_sram_init();
// hardware reset
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
HAL_Delay(5);
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x01); // software reset
HAL_Delay(20);
CMD(0x28); // display off
CMD(0xCF); DATAS("\x00\xC1\x30", 3);
CMD(0xED); DATAS("\x64\x03\x12\x81", 4);
CMD(0xE8); DATAS("\x85\x10\x7A", 3);
CMD(0xCB); DATAS("\x39\x2C\x00\x34\x02", 5);
CMD(0xF7); DATA(0x20);
CMD(0xEA); DATAS("\x00\x00", 2);
CMD(0xC0); DATA(0x23); // power control VRH[5:0]
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
CMD(0x3A); DATA(0x55); // memory access control (16-bit 565)
CMD(0xB1); DATAS("\x00\x18", 2); // framerate
#endif
#if DISPLAY_ILI9341V
CMD(0xB6); DATAS("\x0A\xA2", 2); // display function control
CMD(0xF6); DATAS("\x01\x30\x00", 3); // interface control
CMD(0xF2); DATA(0x00); // 3 gamma func disable
#endif
#if DISPLAY_ILI9341V
CMD(0x26); DATA(0x01); // gamma func enable
CMD(0xE0); DATAS("\x0F\x2F\x2C\x0B\x0F\x09\x56\xD9\x4A\x0B\x14\x05\x0C\x06\x00", 15); // gamma curve 1
CMD(0xE1); DATAS("\x00\x10\x13\x04\x10\x06\x25\x26\x3B\x04\x0B\x0A\x33\x39\x0F", 15); // gamma curve 2
#endif
#if DISPLAY_ST7789V
CMD(0x26); DATA(0x01); // gamma func enable
CMD(0xE0); DATAS("\x70\x2C\x2E\x15\x10\x09\x48\x33\x53\x0B\x19\x18\x20\x25", 14); // gamma curve 1
CMD(0xE1); DATAS("\x70\x2C\x2E\x15\x10\x09\x48\x33\x53\x0B\x19\x18\x20\x25", 14); // gamma curve 2
#endif
#if DISPLAY_ILI9341V
CMD(0x21); // invert colors
#endif
#if DISPLAY_ST7789V
CMD(0x20); // don't invert colors
#endif
display_orientation(0);
display_backlight(0);
// clear buffer
display_clear();
display_unsleep();
}
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
x += WINDOW_OFFSET_X;
y += WINDOW_OFFSET_Y;
uint16_t x1 = x + w - 1;
uint16_t y1 = y + h - 1;
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x2A); DATA(x >> 8); DATA(x & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y >> 8); DATA(y & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
CMD(0x2C);
#endif
}
void display_refresh(void) {
}
int display_orientation(int degrees)
{
// memory access control
@ -203,73 +270,6 @@ int display_orientation(int degrees)
return ORIENTATION;
}
void display_init(void) {
display_sram_init();
// hardware reset
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
HAL_Delay(5);
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x01); // software reset
HAL_Delay(20);
CMD(0x28); // display off
CMD(0xCF); DATAS("\x00\xC1\x30", 3);
CMD(0xED); DATAS("\x64\x03\x12\x81", 4);
CMD(0xE8); DATAS("\x85\x10\x7A", 3);
CMD(0xCB); DATAS("\x39\x2C\x00\x34\x02", 5);
CMD(0xF7); DATA(0x20);
CMD(0xEA); DATAS("\x00\x00", 2);
CMD(0xC0); DATA(0x23); // power control VRH[5:0]
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
CMD(0x3A); DATA(0x55); // memory access control (16-bit 565)
CMD(0xB1); DATAS("\x00\x18", 2); // framerate
#endif
#if DISPLAY_ILI9341V
CMD(0xB6); DATAS("\x0A\xA2", 2); // display function control
CMD(0xF6); DATAS("\x01\x30\x00", 3); // interface control
CMD(0xF2); DATA(0x00); // 3 gamma func disable
#endif
#if DISPLAY_ILI9341V
CMD(0x26); DATA(0x01); // gamma func enable
CMD(0xE0); DATAS("\x0F\x2F\x2C\x0B\x0F\x09\x56\xD9\x4A\x0B\x14\x05\x0C\x06\x00", 15); // gamma curve 1
CMD(0xE1); DATAS("\x00\x10\x13\x04\x10\x06\x25\x26\x3B\x04\x0B\x0A\x33\x39\x0F", 15); // gamma curve 2
#endif
#if DISPLAY_ST7789V
CMD(0x26); DATA(0x01); // gamma func enable
CMD(0xE0); DATAS("\x70\x2C\x2E\x15\x10\x09\x48\x33\x53\x0B\x19\x18\x20\x25", 14); // gamma curve 1
CMD(0xE1); DATAS("\x70\x2C\x2E\x15\x10\x09\x48\x33\x53\x0B\x19\x18\x20\x25", 14); // gamma curve 2
#endif
#if DISPLAY_ILI9341V
CMD(0x21); // invert colors
#endif
#if DISPLAY_ST7789V
CMD(0x20); // don't invert colors
#endif
display_orientation(0);
display_backlight(0);
// clear buffer
display_clear();
display_unsleep();
}
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
x += WINDOW_OFFSET_X;
y += WINDOW_OFFSET_Y;
uint16_t x1 = x + w - 1;
uint16_t y1 = y + h - 1;
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x2A); DATA(x >> 8); DATA(x & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y >> 8); DATA(y & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
CMD(0x2C);
#endif
}
void display_refresh(void) {
}
int display_backlight(int val)
{
if (val >= 0 && val <= 255) {
@ -278,3 +278,7 @@ int display_backlight(int val)
}
return BACKLIGHT;
}
void display_save(const char *filename)
{
}

View File

@ -34,3 +34,7 @@ int display_backlight(int val)
{
return BACKLIGHT;
}
void display_save(const char *filename)
{
}

View File

@ -7,11 +7,12 @@
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define DISPLAY_BORDER 16
static SDL_Renderer *RENDERER = 0;
static SDL_Surface *SCREEN = 0;
static SDL_Surface *BUFFER = 0;
static SDL_Texture *TEXTURE = 0;
static int DATAODD = 0;
static int POSX, POSY, SX, SY, EX, EY = 0;
@ -20,7 +21,7 @@ static int POSX, POSY, SX, SY, EX, EY = 0;
void DATA(uint8_t x) {
if (POSX <= EX && POSY <= EY) {
((uint8_t *)SCREEN->pixels)[POSX * 2 + POSY * SCREEN->pitch + (DATAODD ^ 1)] = x;
((uint8_t *)BUFFER->pixels)[POSX * 2 + POSY * BUFFER->pitch + (DATAODD ^ 1)] = x;
}
DATAODD = !DATAODD;
if (DATAODD == 0) {
@ -93,7 +94,7 @@ void display_init(void)
}
SDL_SetRenderDrawColor(RENDERER, BACKLIGHT, BACKLIGHT, BACKLIGHT, 255);
SDL_RenderClear(RENDERER);
SCREEN = SDL_CreateRGBSurface(0, DISPLAY_RESX, DISPLAY_RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
BUFFER = 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);
@ -110,7 +111,7 @@ void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
void display_refresh(void)
{
SDL_RenderClear(RENDERER);
SDL_UpdateTexture(TEXTURE, NULL, SCREEN->pixels, SCREEN->pitch);
SDL_UpdateTexture(TEXTURE, NULL, BUFFER->pixels, BUFFER->pitch);
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, DISPLAY_RESX, DISPLAY_RESY};
SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, ORIENTATION, NULL, 0);
SDL_RenderPresent(RENDERER);
@ -134,3 +135,8 @@ int display_backlight(int val)
}
return BACKLIGHT;
}
void display_save(const char *filename)
{
IMG_SavePNG(BUFFER, filename);
}

View File

@ -37,5 +37,6 @@ uint32_t display_text_width(const char *text, int textlen, uint8_t font);
void display_qrcode(uint8_t x, uint8_t y, const char *data, int datalen, int scale);
void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
void display_raw(uint8_t reg, const uint8_t *data, int datalen);
void display_save(const char *filename);
#endif

View File

@ -354,6 +354,20 @@ STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t d
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_raw_obj, mod_TrezorUi_Display_raw);
/// def trezor.ui.display.save(filename: string) -> None:
/// '''
/// Saves current display contents to file filename.
/// '''
STATIC mp_obj_t mod_TrezorUi_Display_save(mp_obj_t self, mp_obj_t filename) {
mp_buffer_info_t fn;
mp_get_buffer_raise(filename, &fn, MP_BUFFER_READ);
if (fn.len > 0) {
display_save(fn.buf);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_save_obj, mod_TrezorUi_Display_save);
STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&mod_TrezorUi_Display_clear_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&mod_TrezorUi_Display_refresh_obj) },
@ -371,6 +385,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUi_Display_orientation_obj) },
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUi_Display_backlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_raw), MP_ROM_PTR(&mod_TrezorUi_Display_raw_obj) },
{ MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&mod_TrezorUi_Display_save_obj) },
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_MONO) },
{ MP_ROM_QSTR(MP_QSTR_FONT_NORMAL), MP_OBJ_NEW_SMALL_INT(FONT_NORMAL) },
{ MP_ROM_QSTR(MP_QSTR_FONT_BOLD), MP_OBJ_NEW_SMALL_INT(FONT_BOLD) },

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit 4ab6e8c3b714d6393c67b359a305ae72f368fe7b
Subproject commit b041b5bf5d25e598ac792ab03896d534cbe73336