Skip to content

Commit ac7d14e

Browse files
Merge pull request #847 from facchinm/lvgl9
Initial: support LVGL9
2 parents 7c7d186 + 0e3dc0d commit ac7d14e

File tree

8 files changed

+1840
-766
lines changed

8 files changed

+1840
-766
lines changed

libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino

+5-1
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,11 @@ 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+
#if (LVGL_VERSION_MAJOR == 9)
80+
lv_style_set_bg_image_src(&style_radio_chk, NULL);
81+
#else
7982
lv_style_set_bg_img_src(&style_radio_chk, NULL);
83+
#endif
8084

8185
cb = lv_checkbox_create(obj);
8286
lv_checkbox_set_text(cb, "Lemon");

libraries/Arduino_H7_Video/examples/LVGLDemo/img_arduinologo.c

+10
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,15 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_IMG_ARDUI
636636
#endif
637637
};
638638

639+
#if (LVGL_VERSION_MAJOR == 9)
640+
const lv_img_dsc_t img_arduinologo = {
641+
.header.cf = LV_COLOR_FORMAT_RGB565,
642+
.header.w = 200,
643+
.header.h = 150,
644+
.data_size = 30000 * LV_COLOR_DEPTH / 8,
645+
.data = img_arduinologo_map,
646+
};
647+
#else
639648
const lv_img_dsc_t img_arduinologo = {
640649
.header.cf = LV_IMG_CF_TRUE_COLOR,
641650
.header.always_zero = 0,
@@ -645,3 +654,4 @@ const lv_img_dsc_t img_arduinologo = {
645654
.data_size = 30000 * LV_COLOR_SIZE / 8,
646655
.data = img_arduinologo_map,
647656
};
657+
#endif

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+79-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ extern "C" {
3737

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

4355
/* Functions -----------------------------------------------------------------*/
4456
Arduino_H7_Video::Arduino_H7_Video(int width, int height, H7DisplayShield &shield)
@@ -84,9 +96,36 @@ int Arduino_H7_Video::begin() {
8496
/* Initiliaze LVGL library */
8597
lv_init();
8698

99+
100+
#if (LVGL_VERSION_MAJOR == 9)
87101
/* Create a draw buffer */
102+
static lv_color_t * buf1 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
103+
if (buf1 == NULL) {
104+
return 2; /* Insuff memory err */
105+
}
106+
static lv_color_t * buf2 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
107+
if (buf2 == NULL) {
108+
return 2; /* Insuff memory err */
109+
}
110+
111+
lv_display_t *display;
112+
if(_rotated) {
113+
display = lv_display_create(height(), width());
114+
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_270);
115+
//display->sw_rotate = 1;
116+
} else {
117+
display = lv_display_create(width(), height());
118+
}
119+
lv_display_set_buffers(display, buf1, NULL, width() * height() / 10, LV_DISPLAY_RENDER_MODE_PARTIAL); /*Initialize the display buffer.*/
120+
lv_display_set_flush_cb(display, lvgl_displayFlushing);
121+
122+
lvgl_inc_thd.start(inc_thd);
123+
124+
#else //LVGL_VERSION_MAJOR
125+
126+
/* Create a draw buffer */
88127
static lv_disp_draw_buf_t draw_buf;
89-
static lv_color_t * buf1;
128+
static lv_color_t * buf1;
90129
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
91130
if (buf1 == NULL) {
92131
return 2; /* Insuff memory err */
@@ -109,6 +148,8 @@ int Arduino_H7_Video::begin() {
109148
}
110149
disp_drv.sw_rotate = 1;
111150
lv_disp_drv_register(&disp_drv); /* Finally register the driver */
151+
152+
#endif
112153
#endif
113154

114155
/* Configure SDRAM */
@@ -189,6 +230,42 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
189230
#endif
190231

191232
#if __has_include("lvgl.h")
233+
#if (LVGL_VERSION_MAJOR == 9)
234+
static uint8_t* rotated_buf = nullptr;
235+
void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
236+
uint32_t w = lv_area_get_width(area);
237+
uint32_t h = lv_area_get_height(area);
238+
lv_area_t* area_in_use = (lv_area_t *)area;
239+
240+
// TODO: find a smart way to tackle sw rotation
241+
lv_display_rotation_t rotation = lv_display_get_rotation(disp);
242+
lv_area_t rotated_area;
243+
if (rotation != LV_DISPLAY_ROTATION_0) {
244+
rotated_buf = (uint8_t*)realloc(rotated_buf, w * h * 4);
245+
lv_color_format_t cf = lv_display_get_color_format(disp);
246+
lv_draw_sw_rotate(px_map, rotated_buf,
247+
w, h, lv_draw_buf_width_to_stride(w, cf),
248+
lv_draw_buf_width_to_stride(h, cf),
249+
LV_DISPLAY_ROTATION_90, cf);
250+
rotated_area.x1 = lv_display_get_vertical_resolution(disp) - area->y2 - 1;
251+
rotated_area.y1 = area->x1;
252+
//rotated_area.y2 = dsi_getDisplayYSize() - area->x1 - 1;
253+
rotated_area.x2 = rotated_area.x1 + h - 1;
254+
rotated_area.y2 = rotated_area.y1 + w + 1;
255+
256+
area_in_use = &rotated_area;
257+
px_map = rotated_buf;
258+
auto temp = w;
259+
w = h;
260+
h = temp;
261+
}
262+
263+
uint32_t offsetPos = (area_in_use->x1 + (dsi_getDisplayXSize() * area_in_use->y1)) * sizeof(uint16_t);
264+
265+
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), w, h, DMA2D_INPUT_RGB565);
266+
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
267+
}
268+
#else
192269
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
193270
uint32_t width = lv_area_get_width(area);
194271
uint32_t height = lv_area_get_height(area);
@@ -198,5 +275,6 @@ void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color
198275
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
199276
}
200277
#endif
278+
#endif
201279

202280
/**** END OF FILE ****/

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)