Board library: fix 1 px offset in mirrored rotations

The panel's row mirror (MY) puts the image one line off, which left a
stray line at the edge when starting at 270 degrees. setRotation() now
sets a 1 px gap on the axis MY mirrors, and scr_lvgl_init() clears the
whole GRAM at rotation 0 so no random power-on pixels can show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-24 17:08:02 +02:00
1 parent c9fb70ad10
commit c22b98de76
2 files changed
+25 -3

No files matched your search

+23 -3
View File
@@ -283,27 +283,37 @@ void setRotation(uint8_t rot)
if (lcd == NULL)
return;
// The panel's row mirror (MY) is one line off, so the image needs a 1 px shift along the axis
// MY mirrors: logical Y without swap, logical X with swap.
switch (rot)
{
case 1: // 90° clockwise
lcd->swapXY(true);
lcd->mirrorX(true);
lcd->mirrorY(false);
lcd->setGapX(0);
lcd->setGapY(0);
break;
case 2: // 180°
lcd->swapXY(false);
lcd->mirrorX(true);
lcd->mirrorY(true);
lcd->setGapX(0);
lcd->setGapY(1);
break;
case 3: // 270° clockwise
lcd->swapXY(true);
lcd->mirrorX(false);
lcd->mirrorY(true);
lcd->setGapX(1);
lcd->setGapY(0);
break;
default:
lcd->swapXY(false);
lcd->mirrorX(false);
lcd->mirrorY(false);
lcd->setGapX(0);
lcd->setGapY(0);
break;
}
rotation = rot;
@@ -435,12 +445,22 @@ lv_display_t *scr_lvgl_init()
lcd->invertColor(true);
lcd->displayOn();
screen_switch(true);
backlight->setBrightness(100);
size_t buf_bytes = JC_DRAW_BUF_ROWS * SCREEN_RES_HOR * 2; // RGB565
disp_draw_buf = (uint8_t *)heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
disp_draw_buf2 = (uint8_t *)heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
// Clear the panel's whole GRAM (random after power-on) while still unrotated. In a mirrored
// rotation one physical line at the edge is never written by LVGL and would keep its garbage.
memset(disp_draw_buf, 0, buf_bytes);
for (int y = 0; y < SCREEN_RES_VER; y += JC_DRAW_BUF_ROWS)
{
int h = min(JC_DRAW_BUF_ROWS, SCREEN_RES_VER - y);
lcd->drawBitmapWaitUntilFinish(0, y, SCREEN_RES_HOR, h, disp_draw_buf, 100);
}
screen_switch(true);
backlight->setBrightness(100);
lv_init();
lv_tick_set_cb(lv_tick_millis);