1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-02 04:42:33 +00:00

embed/extmod/modtrezorui: refactor DATA into DATA and PIXELDATA in display

This commit is contained in:
Pavol Rusnak 2018-02-15 17:57:30 +01:00
parent f65c409416
commit e264090678
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 32 additions and 54 deletions

View File

@ -19,8 +19,9 @@
#define DISPLAY_MEMORY_BASE 0x60000000 #define DISPLAY_MEMORY_BASE 0x60000000
#define DISPLAY_MEMORY_PIN 16 #define DISPLAY_MEMORY_PIN 16
#define CMD(X) (*((__IO uint8_t *)((uint32_t)(DISPLAY_MEMORY_BASE))) = (X)) #define CMD(X) (*((__IO uint8_t *)((uint32_t)(DISPLAY_MEMORY_BASE))) = (X))
#define DATA(X) (*((__IO uint8_t *)((uint32_t)(DISPLAY_MEMORY_BASE | (1 << DISPLAY_MEMORY_PIN)))) = (X)) #define DATA(X) (*((__IO uint8_t *)((uint32_t)(DISPLAY_MEMORY_BASE | (1 << DISPLAY_MEMORY_PIN)))) = (X))
#define PIXELDATA(X) DATA((X) >> 8); DATA((X) & 0xFF)
#define LED_PWM_TIM_PERIOD (10000) #define LED_PWM_TIM_PERIOD (10000)

View File

@ -15,27 +15,23 @@
static SDL_Renderer *RENDERER; static SDL_Renderer *RENDERER;
static SDL_Surface *BUFFER; static SDL_Surface *BUFFER;
static SDL_Texture *TEXTURE; static SDL_Texture *TEXTURE;
static int DATAODD;
static int POSX, POSY, SX, SY, EX, EY; static int POSX, POSY, SX, SY, EX, EY;
void DATA(uint8_t x) { void PIXELDATA(uint16_t c) {
if (!RENDERER) { if (!RENDERER) {
display_init(); display_init();
} }
if (POSX <= EX && POSY <= EY) { if (POSX <= EX && POSY <= EY) {
((uint8_t *)BUFFER->pixels)[POSX * 2 + POSY * BUFFER->pitch + (DATAODD ^ 1)] = x; ((uint16_t *)BUFFER->pixels)[POSX + POSY * BUFFER->pitch / sizeof(uint16_t)] = c;
} }
DATAODD = !DATAODD; POSX++;
if (DATAODD == 0) { if (POSX > EX) {
POSX++; POSX = SX;
if (POSX > EX) { POSY++;
POSX = SX;
POSY++;
}
} }
} }
#else #else
#define DATA(X) (void)(X); #define PIXELDATA(X) (void)(X)
#endif #endif
void display_init(void) void display_init(void)
@ -78,7 +74,6 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
SX = x0; SY = y0; SX = x0; SY = y0;
EX = x1; EY = y1; EX = x1; EY = y1;
POSX = SX; POSY = SY; POSX = SX; POSY = SY;
DATAODD = 0;
#endif #endif
} }

View File

@ -72,7 +72,7 @@ void display_clear(void)
display_orientation(0); // set MADCTL first so that we can set the window correctly next display_orientation(0); // set MADCTL first so that we can set the window correctly next
display_set_window(0, 0, MAX_DISPLAY_RESX - 1, MAX_DISPLAY_RESY - 1); // address the complete frame memory display_set_window(0, 0, MAX_DISPLAY_RESX - 1, MAX_DISPLAY_RESY - 1); // address the complete frame memory
for (uint32_t i = 0; i < MAX_DISPLAY_RESX * MAX_DISPLAY_RESY; i++) { for (uint32_t i = 0; i < MAX_DISPLAY_RESX * MAX_DISPLAY_RESY; i++) {
DATA(0x00); DATA(0x00); // 2 bytes per pixel because we're using RGB 5-6-5 format PIXELDATA(0x0000); // 2 bytes per pixel because we're using RGB 5-6-5 format
} }
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1); // go back to restricted window display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1); // go back to restricted window
display_orientation(saved_orientation); // if valid, go back to the saved orientation display_orientation(saved_orientation); // if valid, go back to the saved orientation
@ -86,8 +86,7 @@ void display_bar(int x, int y, int w, int h, uint16_t c)
clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1); clamp_coords(x, y, w, h, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1); display_set_window(x0, y0, x1, y1);
for (int i = 0; i < (x1 - x0 + 1) * (y1 - y0 + 1); i++) { for (int i = 0; i < (x1 - x0 + 1) * (y1 - y0 + 1); i++) {
DATA(c >> 8); PIXELDATA(c);
DATA(c & 0xFF);
} }
} }
@ -132,26 +131,21 @@ void display_bar_radius(int x, int y, int w, int h, uint16_t c, uint16_t b, uint
int ry = j - y; int ry = j - y;
if (rx < CORNER_RADIUS / r && ry < CORNER_RADIUS / r) { if (rx < CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
uint8_t c = cornertable[rx * r + ry * r * CORNER_RADIUS]; uint8_t c = cornertable[rx * r + ry * r * CORNER_RADIUS];
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} else } else
if (rx < CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) { if (rx < CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[rx * r + (h - 1 - ry) * r * CORNER_RADIUS]; uint8_t c = cornertable[rx * r + (h - 1 - ry) * r * CORNER_RADIUS];
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} else } else
if (rx >= w - CORNER_RADIUS / r && ry < CORNER_RADIUS / r) { if (rx >= w - CORNER_RADIUS / r && ry < CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - rx) * r + ry * r * CORNER_RADIUS]; uint8_t c = cornertable[(w - 1 - rx) * r + ry * r * CORNER_RADIUS];
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} else } else
if (rx >= w - CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) { if (rx >= w - CORNER_RADIUS / r && ry >= h - CORNER_RADIUS / r) {
uint8_t c = cornertable[(w - 1 - rx) * r + (h - 1 - ry) * r * CORNER_RADIUS]; uint8_t c = cornertable[(w - 1 - rx) * r + (h - 1 - ry) * r * CORNER_RADIUS];
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} else { } else {
DATA(c >> 8); PIXELDATA(c);
DATA(c & 0xFF);
} }
} }
} }
@ -172,8 +166,7 @@ static void inflate_callback_image(uint8_t byte1, uint32_t pos, void *userdata)
const int px = (pos / 2) % w; const int px = (pos / 2) % w;
const int py = (pos / 2) / w; const int py = (pos / 2) / w;
if (px >= x0 && px <= x1 && py >= y0 && py <= y1) { if (px >= x0 && px <= x1 && py >= y0 && py <= y1) {
DATA(byte0); PIXELDATA((byte0 << 8) | byte1);
DATA(byte1);
} }
} }
@ -212,13 +205,11 @@ static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
int d = (px - w / 2) * (px - w / 2) + (py - w / 2) * (py - w / 2); int d = (px - w / 2) * (px - w / 2) + (py - w / 2) * (py - w / 2);
// inside border area // inside border area
if (d < AVATAR_BORDER_LOW) { if (d < AVATAR_BORDER_LOW) {
DATA(byte0); PIXELDATA((byte0 << 8) | byte1);
DATA(byte1);
} else } else
// outside border area // outside border area
if (d > AVATAR_BORDER_HIGH) { if (d > AVATAR_BORDER_HIGH) {
DATA(bgcolor >> 8); PIXELDATA(bgcolor);
DATA(bgcolor & 0xFF);
// border area // border area
} else { } else {
#if AVATAR_ANTIALIAS #if AVATAR_ANTIALIAS
@ -229,11 +220,9 @@ static void inflate_callback_avatar(uint8_t byte1, uint32_t pos, void *userdata)
} else { } else {
c = interpolate_color(fgcolor, (byte0 << 8) | byte1 , d); c = interpolate_color(fgcolor, (byte0 << 8) | byte1 , d);
} }
DATA(c >> 8); PIXELDATA(c);
DATA(c & 0xFF);
#else #else
DATA(fgcolor >> 8); PIXELDATA(fgcolor);
DATA(fgcolor & 0xFF);
#endif #endif
} }
} }
@ -261,10 +250,8 @@ static void inflate_callback_icon(uint8_t byte, uint32_t pos, void *userdata)
const int px = (pos * 2) % w; const int px = (pos * 2) % w;
const int py = (pos * 2) / w; const int py = (pos * 2) / w;
if (px >= x0 && px <= x1 && py >= y0 && py <= y1) { if (px >= x0 && px <= x1 && py >= y0 && py <= y1) {
DATA(colortable[byte >> 4] >> 8); PIXELDATA(colortable[byte >> 4]);
DATA(colortable[byte >> 4] & 0xFF); PIXELDATA(colortable[byte & 0x0F]);
DATA(colortable[byte & 0x0F] >> 8);
DATA(colortable[byte & 0x0F] & 0xFF);
} }
} }
@ -378,11 +365,9 @@ void display_print(const char *text, int textlen)
if (c < ' ') c = ' '; if (c < ' ') c = ' ';
const uint8_t *g = Font_Bitmap + (5 * (c - ' ')); const uint8_t *g = Font_Bitmap + (5 * (c - ' '));
if (k < 5 && (g[k] & (1 << j))) { if (k < 5 && (g[k] & (1 << j))) {
DATA(display_print_fgcolor >> 8); PIXELDATA(display_print_fgcolor);
DATA(display_print_fgcolor & 0xFF);
} else { } else {
DATA(display_print_bgcolor >> 8); PIXELDATA(display_print_bgcolor);
DATA(display_print_bgcolor & 0xFF);
} }
} }
display_refresh(); display_refresh();
@ -449,8 +434,7 @@ static void display_text_render(int x, int y, const char *text, int textlen, uin
#else #else
#error Unsupported FONT_BPP value #error Unsupported FONT_BPP value
#endif #endif
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} }
} }
} }
@ -524,14 +508,14 @@ void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale)
int ry = (j - y) / scale - 1; int ry = (j - y) / scale - 1;
// 1px border // 1px border
if (rx < 0 || ry < 0 || rx >= side || ry >= side) { if (rx < 0 || ry < 0 || rx >= side || ry >= side) {
DATA(0xFF); DATA(0xFF); PIXELDATA(0xFFFF);
continue; continue;
} }
int a = rx * side + ry; int a = rx * side + ry;
if (bitdata[a / 8] & (1 << (7 - a % 8))) { if (bitdata[a / 8] & (1 << (7 - a % 8))) {
DATA(0x00); DATA(0x00); PIXELDATA(0x0000);
} else { } else {
DATA(0xFF); DATA(0xFF); PIXELDATA(0xFFFF);
} }
} }
} }
@ -593,8 +577,7 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
} else { } else {
c = (icon[i / 2] & 0xF0) >> 4; c = (icon[i / 2] & 0xF0) >> 4;
} }
DATA(iconcolortable[c] >> 8); PIXELDATA(iconcolortable[c]);
DATA(iconcolortable[c] & 0xFF);
} else { } else {
uint8_t c; uint8_t c;
if (progress > a) { if (progress > a) {
@ -602,8 +585,7 @@ void display_loader(uint16_t progress, int yoffset, uint16_t fgcolor, uint16_t b
} else { } else {
c = img_loader[my][mx] & 0x000F; c = img_loader[my][mx] & 0x000F;
} }
DATA(colortable[c] >> 8); PIXELDATA(colortable[c]);
DATA(colortable[c] & 0xFF);
} }
} }
} }