Skip to content

Commit f97beeb

Browse files
committed
H7_video: wip: port to lvgl9
Rotation is not functional at the moment (a commented dummy implementation can be found in lvgl_displayFlushing)
1 parent 68fbece commit f97beeb

File tree

6 files changed

+552
-319
lines changed

6 files changed

+552
-319
lines changed

libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Arduino_GigaDisplayTouch TouchDetector;
1717
/* Button click event callback */
1818
static void btn_event_cb(lv_event_t * e) {
1919
static uint32_t cnt = 1;
20-
lv_obj_t * btn = lv_event_get_target(e);
20+
lv_obj_t * btn = (lv_obj_t *)lv_event_get_target(e);
2121
lv_obj_t * label = lv_obj_get_child(btn, 0);
2222
lv_label_set_text_fmt(label, "%"LV_PRIu32, cnt);
2323
cnt++;
@@ -76,7 +76,7 @@ void setup() {
7676
lv_style_init(&style_radio);
7777
lv_style_set_radius(&style_radio, LV_RADIUS_CIRCLE);
7878
lv_style_init(&style_radio_chk);
79-
lv_style_set_bg_img_src(&style_radio_chk, NULL);
79+
lv_style_set_bg_image_src(&style_radio_chk, NULL);
8080

8181
cb = lv_checkbox_create(obj);
8282
lv_checkbox_set_text(cb, "Lemon");

libraries/Arduino_H7_Video/examples/LVGLDemo/img_arduinologo.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,9 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_IMG_ARDUI
637637
};
638638

639639
const lv_img_dsc_t img_arduinologo = {
640-
.header.cf = LV_IMG_CF_TRUE_COLOR,
641-
.header.always_zero = 0,
642-
.header.reserved = 0,
640+
.header.cf = LV_COLOR_FORMAT_RGB565,
643641
.header.w = 200,
644642
.header.h = 150,
645-
.data_size = 30000 * LV_COLOR_SIZE / 8,
643+
.data_size = 30000 * LV_COLOR_DEPTH / 8,
646644
.data = img_arduinologo_map,
647645
};

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+42-21
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ extern "C" {
3737

3838
/* Private function prototypes -----------------------------------------------*/
3939
#if __has_include ("lvgl.h")
40-
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
40+
#include "mbed.h"
41+
void lvgl_displayFlushing(lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
42+
static void inc_thd() {
43+
while (1) {
44+
lv_tick_inc(16);
45+
delay(16);
46+
}
47+
}
48+
static rtos::Thread lvgl_inc_thd;
4149
#endif
4250

4351
/* Functions -----------------------------------------------------------------*/
@@ -85,30 +93,27 @@ int Arduino_H7_Video::begin() {
8593
lv_init();
8694

8795
/* Create a draw buffer */
88-
static lv_disp_draw_buf_t draw_buf;
89-
static lv_color_t * buf1;
90-
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
96+
static lv_color_t * buf1 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
9197
if (buf1 == NULL) {
9298
return 2; /* Insuff memory err */
9399
}
94-
lv_disp_draw_buf_init(&draw_buf, buf1, NULL, width() * height() / 10); /* Initialize the display buffer. */
100+
static lv_color_t * buf2 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
101+
if (buf2 == NULL) {
102+
return 2; /* Insuff memory err */
103+
}
95104

96-
/* Initialize display features for LVGL library */
97-
static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
98-
lv_disp_drv_init(&disp_drv); /* Basic initialization */
99-
disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
100-
disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
105+
lv_display_t *display;
101106
if(_rotated) {
102-
disp_drv.hor_res = height(); /* Set the horizontal resolution of the display */
103-
disp_drv.ver_res = width(); /* Set the vertical resolution of the display */
104-
disp_drv.rotated = LV_DISP_ROT_270;
107+
display = lv_display_create(height(), width());
108+
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_270);
109+
//display->sw_rotate = 1;
105110
} else {
106-
disp_drv.hor_res = width(); /* Set the horizontal resolution of the display */
107-
disp_drv.ver_res = height(); /* Set the vertical resolution of the display */
108-
disp_drv.rotated = LV_DISP_ROT_NONE;
111+
display = lv_display_create(width(), height());
109112
}
110-
disp_drv.sw_rotate = 1;
111-
lv_disp_drv_register(&disp_drv); /* Finally register the driver */
113+
lv_display_set_buffers(display, buf1, NULL, width() * height() / 10, LV_DISPLAY_RENDER_MODE_PARTIAL); /*Initialize the display buffer.*/
114+
lv_display_set_flush_cb(display, lvgl_displayFlushing);
115+
116+
lvgl_inc_thd.start(inc_thd);
112117
#endif
113118

114119
/* Configure SDRAM */
@@ -189,13 +194,29 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
189194
#endif
190195

191196
#if __has_include("lvgl.h")
192-
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
197+
static uint8_t* dst = nullptr;
198+
void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
193199
uint32_t width = lv_area_get_width(area);
194200
uint32_t height = lv_area_get_height(area);
195201
uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize() * area->y1)) * sizeof(uint16_t);
196202

197-
dsi_lcdDrawImage((void *) color_p, (void *)(dsi_getActiveFrameBuffer() + offsetPos), width, height, DMA2D_INPUT_RGB565);
198-
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
203+
// 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;
215+
}
216+
*/
217+
218+
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), width, height, DMA2D_INPUT_RGB565);
219+
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
199220
}
200221
#endif
201222

libraries/Arduino_H7_Video/src/dsi.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,17 @@ uint32_t dsi_getFramebufferEnd(void) {
323323
return (FB_BASE_ADDRESS + 2 * (lcd_x_size * lcd_y_size * BYTES_PER_PIXEL));
324324
}
325325

326-
void dsi_drawCurrentFrameBuffer(void) {
326+
void dsi_drawCurrentFrameBuffer(bool reload) {
327327
int fb = pend_buffer++ % 2;
328328

329329
/* Enable current LTDC layer */
330330
__HAL_LTDC_LAYER_ENABLE(&(ltdc), fb);
331331
/* Disable active LTDC layer */
332332
__HAL_LTDC_LAYER_DISABLE(&(ltdc), !fb);
333333

334+
if (!reload) {
335+
return;
336+
}
334337
/* LTDC reload request within next vertical blanking */
335338
reloadLTDC_status = 0;
336339
HAL_LTDC_Reload(&ltdc, LTDC_SRCR_VBR);

libraries/Arduino_H7_Video/src/dsi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void dsi_lcdClear(uint32_t color);
3636
void dsi_lcdDrawImage(void *pSrc, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
3737
void dsi_lcdFillArea(void *pDst, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
3838
void dsi_configueCLUT(uint32_t* clut);
39-
void dsi_drawCurrentFrameBuffer(void);
39+
void dsi_drawCurrentFrameBuffer(bool reload = true);
4040
uint32_t dsi_getCurrentFrameBuffer(void);
4141
uint32_t dsi_getActiveFrameBuffer(void);
4242
uint32_t dsi_getFramebufferEnd(void);

0 commit comments

Comments
 (0)