Skip to content

Commit 0da4e20

Browse files
committed
lvgl: fix lvgl8 build
1 parent 0f1918d commit 0da4e20

File tree

6 files changed

+1805
-973
lines changed

6 files changed

+1805
-973
lines changed

libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
7980
lv_style_set_bg_image_src(&style_radio_chk, NULL);
81+
#else
82+
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,22 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_IMG_ARDUI
636636
#endif
637637
};
638638

639+
#if (LVGL_VERSION_MAJOR == 9)
639640
const lv_img_dsc_t img_arduinologo = {
640641
.header.cf = LV_COLOR_FORMAT_RGB565,
641642
.header.w = 200,
642643
.header.h = 150,
643644
.data_size = 30000 * LV_COLOR_DEPTH / 8,
644645
.data = img_arduinologo_map,
645646
};
647+
#else
648+
const lv_img_dsc_t img_arduinologo = {
649+
.header.cf = LV_IMG_CF_TRUE_COLOR,
650+
.header.always_zero = 0,
651+
.header.reserved = 0,
652+
.header.w = 200,
653+
.header.h = 150,
654+
.data_size = 30000 * LV_COLOR_SIZE / 8,
655+
.data = img_arduinologo_map,
656+
};
657+
#endif

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
/* Private function prototypes -----------------------------------------------*/
3939
#if __has_include ("lvgl.h")
4040
#include "mbed.h"
41+
#if (LVGL_VERSION_MAJOR == 9)
4142
void lvgl_displayFlushing(lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
4243
static void inc_thd() {
4344
while (1) {
@@ -46,6 +47,9 @@ static void inc_thd() {
4647
}
4748
}
4849
static rtos::Thread lvgl_inc_thd;
50+
#else
51+
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
52+
#endif
4953
#endif
5054

5155
/* Functions -----------------------------------------------------------------*/
@@ -92,6 +96,8 @@ int Arduino_H7_Video::begin() {
9296
/* Initiliaze LVGL library */
9397
lv_init();
9498

99+
100+
#if (LVGL_VERSION_MAJOR == 9)
95101
/* Create a draw buffer */
96102
static lv_color_t * buf1 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
97103
if (buf1 == NULL) {
@@ -114,6 +120,36 @@ int Arduino_H7_Video::begin() {
114120
lv_display_set_flush_cb(display, lvgl_displayFlushing);
115121

116122
lvgl_inc_thd.start(inc_thd);
123+
124+
#else //LVGL_VERSION_MAJOR
125+
126+
/* Create a draw buffer */
127+
static lv_disp_draw_buf_t draw_buf;
128+
static lv_color_t * buf1;
129+
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
130+
if (buf1 == NULL) {
131+
return 2; /* Insuff memory err */
132+
}
133+
lv_disp_draw_buf_init(&draw_buf, buf1, NULL, width() * height() / 10); /* Initialize the display buffer. */
134+
135+
/* Initialize display features for LVGL library */
136+
static lv_disp_drv_t disp_drv; /* Descriptor of a display driver */
137+
lv_disp_drv_init(&disp_drv); /* Basic initialization */
138+
disp_drv.flush_cb = lvgl_displayFlushing; /* Set your driver function */
139+
disp_drv.draw_buf = &draw_buf; /* Assign the buffer to the display */
140+
if(_rotated) {
141+
disp_drv.hor_res = height(); /* Set the horizontal resolution of the display */
142+
disp_drv.ver_res = width(); /* Set the vertical resolution of the display */
143+
disp_drv.rotated = LV_DISP_ROT_270;
144+
} else {
145+
disp_drv.hor_res = width(); /* Set the horizontal resolution of the display */
146+
disp_drv.ver_res = height(); /* Set the vertical resolution of the display */
147+
disp_drv.rotated = LV_DISP_ROT_NONE;
148+
}
149+
disp_drv.sw_rotate = 1;
150+
lv_disp_drv_register(&disp_drv); /* Finally register the driver */
151+
152+
#endif
117153
#endif
118154

119155
/* Configure SDRAM */
@@ -194,6 +230,7 @@ void Arduino_H7_Video::set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
194230
#endif
195231

196232
#if __has_include("lvgl.h")
233+
#if (LVGL_VERSION_MAJOR == 9)
197234
static uint8_t* rotated_buf = nullptr;
198235
void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
199236
uint32_t w = lv_area_get_width(area);
@@ -228,6 +265,16 @@ void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned
228265
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), w, h, DMA2D_INPUT_RGB565);
229266
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
230267
}
268+
#else
269+
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
270+
uint32_t width = lv_area_get_width(area);
271+
uint32_t height = lv_area_get_height(area);
272+
uint32_t offsetPos = (area->x1 + (dsi_getDisplayXSize() * area->y1)) * sizeof(uint16_t);
273+
274+
dsi_lcdDrawImage((void *) color_p, (void *)(dsi_getActiveFrameBuffer() + offsetPos), width, height, DMA2D_INPUT_RGB565);
275+
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
276+
}
277+
#endif
231278
#endif
232279

233280
/**** END OF FILE ****/

0 commit comments

Comments
 (0)