Skip to content

Commit 0f1918d

Browse files
committed
lvgl9: fix rotation for Giga display shield
1 parent f97beeb commit 0f1918d

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+28-18
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int Arduino_H7_Video::begin() {
105105
lv_display_t *display;
106106
if(_rotated) {
107107
display = lv_display_create(height(), width());
108-
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_270);
108+
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_90);
109109
//display->sw_rotate = 1;
110110
} else {
111111
display = lv_display_create(width(), height());
@@ -194,28 +194,38 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
194194
#endif
195195

196196
#if __has_include("lvgl.h")
197-
static uint8_t* dst = nullptr;
197+
static uint8_t* rotated_buf = nullptr;
198198
void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
199-
uint32_t width = lv_area_get_width(area);
200-
uint32_t height = lv_area_get_height(area);
201-
uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize() * area->y1)) * sizeof(uint16_t);
199+
uint32_t w = lv_area_get_width(area);
200+
uint32_t h = lv_area_get_height(area);
201+
lv_area_t* area_in_use = (lv_area_t *)area;
202202

203203
// TODO: find a smart way to tackle sw rotation
204-
/*
205-
if (lv_display_get_rotation(disp) != LV_DISPLAY_ROTATION_0) {
206-
if (dst != nullptr) {
207-
free(dst);
208-
}
209-
dst = (uint8_t*)malloc(width * height * 2);
210-
lv_draw_sw_rotate(px_map, dst, height, width,
211-
height * 2,
212-
width * 2,
213-
lv_display_get_rotation(disp), LV_COLOR_FORMAT_RGB565);
214-
px_map = dst;
204+
lv_display_rotation_t rotation = lv_display_get_rotation(disp);
205+
lv_area_t rotated_area;
206+
if (rotation != LV_DISPLAY_ROTATION_0) {
207+
rotated_buf = (uint8_t*)realloc(rotated_buf, w * h * 4);
208+
lv_color_format_t cf = lv_display_get_color_format(disp);
209+
lv_draw_sw_rotate(px_map, rotated_buf,
210+
w, h, lv_draw_buf_width_to_stride(w, cf),
211+
lv_draw_buf_width_to_stride(h, cf),
212+
LV_DISPLAY_ROTATION_270, cf);
213+
rotated_area.x1 = area->y1;
214+
rotated_area.y2 = lv_display_get_horizontal_resolution(disp) - area->x1 - 1;
215+
//rotated_area.y2 = dsi_getDisplayYSize() - area->x1 - 1;
216+
rotated_area.x2 = rotated_area.x1 + h - 1;
217+
rotated_area.y1 = rotated_area.y2 - w + 1;
218+
219+
area_in_use = &rotated_area;
220+
px_map = rotated_buf;
221+
auto temp = w;
222+
w = h;
223+
h = temp;
215224
}
216-
*/
217225

218-
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), width, height, DMA2D_INPUT_RGB565);
226+
uint32_t offsetPos = (area_in_use->x1 + (dsi_getDisplayXSize() * area_in_use->y1)) * sizeof(uint16_t);
227+
228+
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), w, h, DMA2D_INPUT_RGB565);
219229
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
220230
}
221231
#endif

0 commit comments

Comments
 (0)