2016-03-27 14:10:31 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) Pavol Rusnak, SatoshiLabs
|
|
|
|
*
|
2016-05-28 05:37:32 -07:00
|
|
|
* Licensed under TREZOR License
|
|
|
|
* see LICENSE file for details
|
2016-03-27 14:10:31 -07:00
|
|
|
*/
|
|
|
|
|
2016-04-28 12:43:22 -07:00
|
|
|
#include <stdlib.h>
|
2017-03-17 06:14:00 -07:00
|
|
|
#ifndef TREZOR_NOUI
|
2016-10-03 10:56:45 -07:00
|
|
|
#include <SDL2/SDL.h>
|
2017-03-17 06:14:00 -07:00
|
|
|
#include <SDL2/SDL_image.h>
|
2016-03-27 14:10:31 -07:00
|
|
|
|
2016-05-02 08:16:55 -07:00
|
|
|
#define DISPLAY_BORDER 16
|
2016-04-30 06:35:23 -07:00
|
|
|
|
2017-10-02 07:48:24 -07:00
|
|
|
static SDL_Renderer *RENDERER;
|
|
|
|
static SDL_Surface *BUFFER;
|
|
|
|
static SDL_Texture *TEXTURE;
|
|
|
|
static int DATAODD;
|
|
|
|
static int POSX, POSY, SX, SY, EX, EY;
|
2016-03-27 14:10:31 -07:00
|
|
|
|
2016-05-11 12:05:08 -07:00
|
|
|
void DATA(uint8_t x) {
|
2017-10-02 07:22:27 -07:00
|
|
|
if (!RENDERER) {
|
|
|
|
display_init();
|
|
|
|
}
|
2016-03-27 14:10:31 -07:00
|
|
|
if (POSX <= EX && POSY <= EY) {
|
2016-10-05 15:02:46 -07:00
|
|
|
((uint8_t *)BUFFER->pixels)[POSX * 2 + POSY * BUFFER->pitch + (DATAODD ^ 1)] = x;
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
|
|
|
DATAODD = !DATAODD;
|
|
|
|
if (DATAODD == 0) {
|
|
|
|
POSX++;
|
|
|
|
if (POSX > EX) {
|
|
|
|
POSX = SX;
|
|
|
|
POSY++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-17 06:14:00 -07:00
|
|
|
#else
|
|
|
|
#define DATA(X) (void)(X);
|
|
|
|
#endif
|
2016-03-27 14:10:31 -07:00
|
|
|
|
2017-10-20 06:25:24 -07:00
|
|
|
void display_init(void)
|
2016-03-27 14:10:31 -07:00
|
|
|
{
|
2017-03-17 06:14:00 -07:00
|
|
|
#ifndef TREZOR_NOUI
|
2016-03-27 14:10:31 -07:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
2017-12-07 03:44:38 -08:00
|
|
|
printf("%s\n", SDL_GetError());
|
|
|
|
ensure(secfalse, "SDL_Init error");
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
2017-12-07 06:31:23 -08:00
|
|
|
atexit(SDL_Quit);
|
2016-09-24 07:53:43 -07:00
|
|
|
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);
|
2016-03-27 14:10:31 -07:00
|
|
|
if (!win) {
|
2017-12-07 03:44:38 -08:00
|
|
|
printf("%s\n", SDL_GetError());
|
|
|
|
ensure(secfalse, "SDL_CreateWindow error");
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
2017-03-16 11:14:12 -07:00
|
|
|
RENDERER = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
|
2016-03-27 14:10:31 -07:00
|
|
|
if (!RENDERER) {
|
2017-12-07 03:44:38 -08:00
|
|
|
printf("%s\n", SDL_GetError());
|
2016-03-27 14:10:31 -07:00
|
|
|
SDL_DestroyWindow(win);
|
2017-12-07 03:44:38 -08:00
|
|
|
ensure(secfalse, "SDL_CreateRenderer error");
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
2017-03-17 07:27:11 -07:00
|
|
|
SDL_SetRenderDrawColor(RENDERER, DISPLAY_BACKLIGHT, DISPLAY_BACKLIGHT, DISPLAY_BACKLIGHT, 255);
|
2016-03-27 14:10:31 -07:00
|
|
|
SDL_RenderClear(RENDERER);
|
2017-10-02 07:47:45 -07:00
|
|
|
BUFFER = SDL_CreateRGBSurface(0, MAX_DISPLAY_RESX, MAX_DISPLAY_RESY, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
|
2016-09-24 07:53:43 -07:00
|
|
|
TEXTURE = SDL_CreateTexture(RENDERER, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, DISPLAY_RESX, DISPLAY_RESY);
|
2016-05-17 07:24:51 -07:00
|
|
|
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE);
|
|
|
|
SDL_SetTextureAlphaMod(TEXTURE, 0);
|
2017-10-02 07:29:21 -07:00
|
|
|
|
|
|
|
DISPLAY_BACKLIGHT = 0;
|
|
|
|
DISPLAY_ORIENTATION = 0;
|
2017-03-17 06:14:00 -07:00
|
|
|
#endif
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
|
|
|
|
2017-11-10 11:26:54 -08:00
|
|
|
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
2016-05-11 12:05:08 -07:00
|
|
|
{
|
2017-03-17 06:14:00 -07:00
|
|
|
#ifndef TREZOR_NOUI
|
2017-10-02 07:22:27 -07:00
|
|
|
if (!RENDERER) {
|
|
|
|
display_init();
|
|
|
|
}
|
2016-10-13 08:09:46 -07:00
|
|
|
SX = x0; SY = y0;
|
|
|
|
EX = x1; EY = y1;
|
2016-03-27 14:10:31 -07:00
|
|
|
POSX = SX; POSY = SY;
|
|
|
|
DATAODD = 0;
|
2017-03-17 06:14:00 -07:00
|
|
|
#endif
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
|
|
|
|
2016-10-03 02:52:19 -07:00
|
|
|
void display_refresh(void)
|
2016-03-27 14:10:31 -07:00
|
|
|
{
|
2017-03-17 06:14:00 -07:00
|
|
|
#ifndef TREZOR_NOUI
|
2017-10-02 07:22:27 -07:00
|
|
|
if (!RENDERER) {
|
|
|
|
display_init();
|
|
|
|
}
|
2016-03-29 06:31:41 -07:00
|
|
|
SDL_RenderClear(RENDERER);
|
2016-10-05 15:02:46 -07:00
|
|
|
SDL_UpdateTexture(TEXTURE, NULL, BUFFER->pixels, BUFFER->pitch);
|
2016-09-24 07:53:43 -07:00
|
|
|
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, DISPLAY_RESX, DISPLAY_RESY};
|
2017-03-17 07:27:11 -07:00
|
|
|
SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, DISPLAY_ORIENTATION, NULL, 0);
|
2016-03-27 14:10:31 -07:00
|
|
|
SDL_RenderPresent(RENDERER);
|
2017-03-17 06:14:00 -07:00
|
|
|
#endif
|
2016-03-27 14:10:31 -07:00
|
|
|
}
|
2016-03-29 06:31:41 -07:00
|
|
|
|
2017-03-08 08:36:11 -08:00
|
|
|
static void display_set_orientation(int degrees)
|
2016-03-29 06:31:41 -07:00
|
|
|
{
|
2016-04-03 06:26:49 -07:00
|
|
|
}
|
2016-10-05 15:02:46 -07:00
|
|
|
|
2017-03-08 08:36:11 -08:00
|
|
|
static void display_set_backlight(int val)
|
2016-10-05 15:02:46 -07:00
|
|
|
{
|
2017-03-17 06:14:00 -07:00
|
|
|
#ifndef TREZOR_NOUI
|
2017-10-02 07:22:27 -07:00
|
|
|
if (!RENDERER) {
|
|
|
|
display_init();
|
|
|
|
}
|
2017-03-08 08:36:11 -08:00
|
|
|
SDL_SetRenderDrawColor(RENDERER, val, val, val, 255);
|
2017-03-17 06:14:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void display_save(const char *filename)
|
|
|
|
{
|
|
|
|
#ifndef TREZOR_NOUI
|
2017-10-02 07:22:27 -07:00
|
|
|
if (!RENDERER) {
|
|
|
|
display_init();
|
|
|
|
}
|
2017-03-17 06:14:00 -07:00
|
|
|
IMG_SavePNG(BUFFER, filename);
|
|
|
|
#endif
|
2016-10-05 15:02:46 -07:00
|
|
|
}
|