mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 07:58:09 +00:00
embed/extmod/modtrezorui: refactor BUFFER_OFFSET and PIXELWINDOW structures
This commit is contained in:
parent
e264090678
commit
30396f9cf0
@ -43,15 +43,15 @@ static void display_unsleep(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t BUFFER_OFFSET_X = 0, BUFFER_OFFSET_Y = 0;
|
static struct {
|
||||||
|
uint16_t x, y;
|
||||||
|
} BUFFER_OFFSET;
|
||||||
|
|
||||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
||||||
{
|
{
|
||||||
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
#if DISPLAY_ILI9341V || DISPLAY_ST7789V
|
||||||
x0 += BUFFER_OFFSET_X;
|
x0 += BUFFER_OFFSET.x; x1 += BUFFER_OFFSET.x;
|
||||||
x1 += BUFFER_OFFSET_X;
|
y0 += BUFFER_OFFSET.y; y1 += BUFFER_OFFSET.y;
|
||||||
y0 += BUFFER_OFFSET_Y;
|
|
||||||
y1 += BUFFER_OFFSET_Y;
|
|
||||||
CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
|
CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
|
||||||
CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
|
CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
|
||||||
CMD(0x2C);
|
CMD(0x2C);
|
||||||
@ -66,8 +66,8 @@ void display_set_orientation(int degrees)
|
|||||||
#define MY (1 << 7)
|
#define MY (1 << 7)
|
||||||
// MADCTL: Memory Data Access Control
|
// MADCTL: Memory Data Access Control
|
||||||
// reference section 9.3 in the ILI9341 manual; 8.12 in the ST7789V manual
|
// reference section 9.3 in the ILI9341 manual; 8.12 in the ST7789V manual
|
||||||
BUFFER_OFFSET_X = 0;
|
BUFFER_OFFSET.x = 0;
|
||||||
BUFFER_OFFSET_Y = 0;
|
BUFFER_OFFSET.y = 0;
|
||||||
uint8_t display_command_parameter = 0;
|
uint8_t display_command_parameter = 0;
|
||||||
switch (degrees) {
|
switch (degrees) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -78,11 +78,11 @@ void display_set_orientation(int degrees)
|
|||||||
break;
|
break;
|
||||||
case 180:
|
case 180:
|
||||||
display_command_parameter = MX | MY;
|
display_command_parameter = MX | MY;
|
||||||
BUFFER_OFFSET_Y = MAX_DISPLAY_RESY - DISPLAY_RESY;
|
BUFFER_OFFSET.y = MAX_DISPLAY_RESY - DISPLAY_RESY;
|
||||||
break;
|
break;
|
||||||
case 270:
|
case 270:
|
||||||
display_command_parameter = MV | MY;
|
display_command_parameter = MV | MY;
|
||||||
BUFFER_OFFSET_X = MAX_DISPLAY_RESY - DISPLAY_RESX;
|
BUFFER_OFFSET.x = MAX_DISPLAY_RESY - DISPLAY_RESX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CMD(0x36); DATA(display_command_parameter);
|
CMD(0x36); DATA(display_command_parameter);
|
||||||
|
@ -15,19 +15,30 @@
|
|||||||
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 POSX, POSY, SX, SY, EX, EY;
|
|
||||||
|
static struct {
|
||||||
|
struct {
|
||||||
|
uint16_t x, y;
|
||||||
|
} start;
|
||||||
|
struct {
|
||||||
|
uint16_t x, y;
|
||||||
|
} end;
|
||||||
|
struct {
|
||||||
|
uint16_t x, y;
|
||||||
|
} pos;
|
||||||
|
} PIXELWINDOW;
|
||||||
|
|
||||||
void PIXELDATA(uint16_t c) {
|
void PIXELDATA(uint16_t c) {
|
||||||
if (!RENDERER) {
|
if (!RENDERER) {
|
||||||
display_init();
|
display_init();
|
||||||
}
|
}
|
||||||
if (POSX <= EX && POSY <= EY) {
|
if (PIXELWINDOW.pos.x <= PIXELWINDOW.end.x && PIXELWINDOW.pos.y <= PIXELWINDOW.end.y) {
|
||||||
((uint16_t *)BUFFER->pixels)[POSX + POSY * BUFFER->pitch / sizeof(uint16_t)] = c;
|
((uint16_t *)BUFFER->pixels)[PIXELWINDOW.pos.x + PIXELWINDOW.pos.y * BUFFER->pitch / sizeof(uint16_t)] = c;
|
||||||
}
|
}
|
||||||
POSX++;
|
PIXELWINDOW.pos.x++;
|
||||||
if (POSX > EX) {
|
if (PIXELWINDOW.pos.x > PIXELWINDOW.end.x) {
|
||||||
POSX = SX;
|
PIXELWINDOW.pos.x = PIXELWINDOW.start.x;
|
||||||
POSY++;
|
PIXELWINDOW.pos.y++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -71,9 +82,9 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
|
|||||||
if (!RENDERER) {
|
if (!RENDERER) {
|
||||||
display_init();
|
display_init();
|
||||||
}
|
}
|
||||||
SX = x0; SY = y0;
|
PIXELWINDOW.start.x = x0; PIXELWINDOW.start.y = y0;
|
||||||
EX = x1; EY = y1;
|
PIXELWINDOW.end.x = x1; PIXELWINDOW.end.y = y1;
|
||||||
POSX = SX; POSY = SY;
|
PIXELWINDOW.pos.x = x0; PIXELWINDOW.pos.y = y0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user