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

modtrezorui: more cleanup

This commit is contained in:
Pavol Rusnak 2017-03-17 14:14:00 +01:00
parent a753bb05e2
commit 135294b5e8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
8 changed files with 59 additions and 43 deletions

View File

@ -48,6 +48,8 @@ clean_trezorhal: ## clean trezorhal build
clean_unix: ## clean unix build
$(MAKE) -f ../../../micropython/unix/Makefile -C vendor/micropython/unix clean $(UNIX_PORT_OPTS)
# workaround for relative paths containing ../.. in unix Makefile
rm -rf vendor/micropython/micropython
clean_cross: ## clean mpy-cross build
$(MAKE) -C vendor/micropython/mpy-cross clean $(CROSS_PORT_OPTS)

View File

@ -285,3 +285,7 @@ void display_refresh(void) {
while (GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) { }
while (GPIO_PIN_SET == HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_12)) { }
}
void display_save(const char *filename)
{
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#define CMD(X) (void)(X);
#define DATA(X) (void)(X);
void display_init(void)
{
}
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
}
void display_refresh(void)
{
}
static void display_set_orientation(int degrees)
{
}
static void display_set_backlight(int val)
{
}

View File

@ -6,7 +6,9 @@
*/
#include <stdlib.h>
#ifndef TREZOR_NOUI
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define DISPLAY_BORDER 16
@ -16,8 +18,6 @@ static SDL_Texture *TEXTURE = 0;
static int DATAODD = 0;
static int POSX, POSY, SX, SY, EX, EY = 0;
#define CMD(X) (void)(X);
void DATA(uint8_t x) {
if (POSX <= EX && POSY <= EY) {
((uint8_t *)BUFFER->pixels)[POSX * 2 + POSY * BUFFER->pitch + (DATAODD ^ 1)] = x;
@ -31,9 +31,13 @@ void DATA(uint8_t x) {
}
}
}
#else
#define DATA(X) (void)(X);
#endif
void display_init(void)
{
#ifndef TREZOR_NOUI
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("SDL_Init Error: %s\n", SDL_GetError());
}
@ -54,23 +58,28 @@ void display_init(void)
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, DISPLAY_RESY);
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE);
SDL_SetTextureAlphaMod(TEXTURE, 0);
#endif
}
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
#ifndef TREZOR_NOUI
SX = x0; SY = y0;
EX = x1; EY = y1;
POSX = SX; POSY = SY;
DATAODD = 0;
#endif
}
void display_refresh(void)
{
#ifndef TREZOR_NOUI
SDL_RenderClear(RENDERER);
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);
#endif
}
static void display_set_orientation(int degrees)
@ -79,5 +88,14 @@ static void display_set_orientation(int degrees)
static void display_set_backlight(int val)
{
#ifndef TREZOR_NOUI
SDL_SetRenderDrawColor(RENDERER, val, val, val, 255);
#endif
}
void display_save(const char *filename)
{
#ifndef TREZOR_NOUI
IMG_SavePNG(BUFFER, filename);
#endif
}

View File

@ -23,11 +23,7 @@ static int OFFSET[2] = {0, 0};
#if defined STM32_HAL_H
#include "display-stmhal.h"
#else
#ifndef TREZOR_NOUI
#include "display-unix-sdl.h"
#else
#include "display-unix-null.h"
#endif
#include "display-unix.h"
#endif
// common display functions

View File

@ -19,24 +19,34 @@
#define LOADER_ICON_SIZE 64
// provided by port
void display_init(void);
int display_orientation(int degrees);
int display_backlight(int val);
int *display_offset(int xy[2]);
void display_refresh(void);
void display_save(const char *filename);
// provided by common
void display_clear(void);
void display_refresh(void);
void display_bar(int x, int y, int w, int h, uint16_t c);
void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint8_t r);
void display_image(int x, int y, int w, int h, const void *data, int datalen);
void display_icon(int x, int y, int w, int h, const void *data, int datalen, uint16_t fgcolor, uint16_t bgcolor);
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
void display_print(const char *text, int textlen);
void display_text(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_center(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
void display_text_right(int x, int y, const char *text, int textlen, uint8_t font, uint16_t fgcolor, uint16_t bgcolor);
int display_text_width(const char *text, int textlen, uint8_t font);
void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale);
void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint32_t iconlen, uint16_t iconfgcolor);
int *display_offset(int xy[2]);
int display_orientation(int degrees);
int display_backlight(int val);
#endif

View File

@ -352,6 +352,20 @@ STATIC mp_obj_t mod_TrezorUi_Display_offset(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_offset_obj, 1, 2, mod_TrezorUi_Display_offset);
/// 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) },
@ -369,6 +383,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_offset), MP_ROM_PTR(&mod_TrezorUi_Display_offset_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) },

View File

@ -89,7 +89,7 @@ ifeq ($(MICROPY_PY_TREZORUI),1)
ifeq ($(TREZOR_NOUI),1)
CFLAGS_MOD += -DTREZOR_NOUI=1
else
LDFLAGS_MOD += -lSDL2
LDFLAGS_MOD += -lSDL2 -lSDL2_image
endif
endif