Skip to content

Initial: support LVGL9 #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libraries/Arduino_H7_Video/examples/LVGLDemo/LVGLDemo.ino
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ Arduino_GigaDisplayTouch TouchDetector;
/* Button click event callback */
static void btn_event_cb(lv_event_t * e) {
static uint32_t cnt = 1;
lv_obj_t * btn = lv_event_get_target(e);
lv_obj_t * btn = (lv_obj_t *)lv_event_get_target(e);
lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "%"LV_PRIu32, cnt);
cnt++;
@@ -76,7 +76,11 @@ void setup() {
lv_style_init(&style_radio);
lv_style_set_radius(&style_radio, LV_RADIUS_CIRCLE);
lv_style_init(&style_radio_chk);
#if (LVGL_VERSION_MAJOR == 9)
lv_style_set_bg_image_src(&style_radio_chk, NULL);
#else
lv_style_set_bg_img_src(&style_radio_chk, NULL);
#endif

cb = lv_checkbox_create(obj);
lv_checkbox_set_text(cb, "Lemon");
10 changes: 10 additions & 0 deletions libraries/Arduino_H7_Video/examples/LVGLDemo/img_arduinologo.c
Original file line number Diff line number Diff line change
@@ -636,6 +636,15 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_IMG_ARDUI
#endif
};

#if (LVGL_VERSION_MAJOR == 9)
const lv_img_dsc_t img_arduinologo = {
.header.cf = LV_COLOR_FORMAT_RGB565,
.header.w = 200,
.header.h = 150,
.data_size = 30000 * LV_COLOR_DEPTH / 8,
.data = img_arduinologo_map,
};
#else
const lv_img_dsc_t img_arduinologo = {
.header.cf = LV_IMG_CF_TRUE_COLOR,
.header.always_zero = 0,
@@ -645,3 +654,4 @@ const lv_img_dsc_t img_arduinologo = {
.data_size = 30000 * LV_COLOR_SIZE / 8,
.data = img_arduinologo_map,
};
#endif
80 changes: 79 additions & 1 deletion libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp
Original file line number Diff line number Diff line change
@@ -37,8 +37,20 @@ extern "C" {

/* Private function prototypes -----------------------------------------------*/
#if __has_include ("lvgl.h")
#include "mbed.h"
#if (LVGL_VERSION_MAJOR == 9)
void lvgl_displayFlushing(lv_display_t * display, const lv_area_t * area, unsigned char * px_map);
static void inc_thd() {
while (1) {
lv_tick_inc(16);
delay(16);
}
}
static rtos::Thread lvgl_inc_thd;
#else
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p);
#endif
#endif

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


#if (LVGL_VERSION_MAJOR == 9)
/* Create a draw buffer */
static lv_color_t * buf1 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
if (buf1 == NULL) {
return 2; /* Insuff memory err */
}
static lv_color_t * buf2 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
if (buf2 == NULL) {
return 2; /* Insuff memory err */
}

lv_display_t *display;
if(_rotated) {
display = lv_display_create(height(), width());
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_270);
//display->sw_rotate = 1;
} else {
display = lv_display_create(width(), height());
}
lv_display_set_buffers(display, buf1, NULL, width() * height() / 10, LV_DISPLAY_RENDER_MODE_PARTIAL); /*Initialize the display buffer.*/
lv_display_set_flush_cb(display, lvgl_displayFlushing);

lvgl_inc_thd.start(inc_thd);

#else //LVGL_VERSION_MAJOR

/* Create a draw buffer */
static lv_disp_draw_buf_t draw_buf;
static lv_color_t * buf1;
static lv_color_t * buf1;
buf1 = (lv_color_t*)malloc((width() * height() / 10) * sizeof(lv_color_t)); /* Declare a buffer for 1/10 screen size */
if (buf1 == NULL) {
return 2; /* Insuff memory err */
@@ -109,6 +148,8 @@ int Arduino_H7_Video::begin() {
}
disp_drv.sw_rotate = 1;
lv_disp_drv_register(&disp_drv); /* Finally register the driver */

#endif
#endif

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

#if __has_include("lvgl.h")
#if (LVGL_VERSION_MAJOR == 9)
static uint8_t* rotated_buf = nullptr;
void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned char * px_map) {
uint32_t w = lv_area_get_width(area);
uint32_t h = lv_area_get_height(area);
lv_area_t* area_in_use = (lv_area_t *)area;

// TODO: find a smart way to tackle sw rotation
lv_display_rotation_t rotation = lv_display_get_rotation(disp);
lv_area_t rotated_area;
if (rotation != LV_DISPLAY_ROTATION_0) {
rotated_buf = (uint8_t*)realloc(rotated_buf, w * h * 4);
lv_color_format_t cf = lv_display_get_color_format(disp);
lv_draw_sw_rotate(px_map, rotated_buf,
w, h, lv_draw_buf_width_to_stride(w, cf),
lv_draw_buf_width_to_stride(h, cf),
LV_DISPLAY_ROTATION_90, cf);
rotated_area.x1 = lv_display_get_vertical_resolution(disp) - area->y2 - 1;
rotated_area.y1 = area->x1;
//rotated_area.y2 = dsi_getDisplayYSize() - area->x1 - 1;
rotated_area.x2 = rotated_area.x1 + h - 1;
rotated_area.y2 = rotated_area.y1 + w + 1;

area_in_use = &rotated_area;
px_map = rotated_buf;
auto temp = w;
w = h;
h = temp;
}

uint32_t offsetPos = (area_in_use->x1 + (dsi_getDisplayXSize() * area_in_use->y1)) * sizeof(uint16_t);

dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), w, h, DMA2D_INPUT_RGB565);
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
}
#else
void lvgl_displayFlushing(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
uint32_t width = lv_area_get_width(area);
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
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
}
#endif
#endif

/**** END OF FILE ****/
5 changes: 4 additions & 1 deletion libraries/Arduino_H7_Video/src/dsi.cpp
Original file line number Diff line number Diff line change
@@ -323,14 +323,17 @@ uint32_t dsi_getFramebufferEnd(void) {
return (FB_BASE_ADDRESS + 2 * (lcd_x_size * lcd_y_size * BYTES_PER_PIXEL));
}

void dsi_drawCurrentFrameBuffer(void) {
void dsi_drawCurrentFrameBuffer(bool reload) {
int fb = pend_buffer++ % 2;

/* Enable current LTDC layer */
__HAL_LTDC_LAYER_ENABLE(&(ltdc), fb);
/* Disable active LTDC layer */
__HAL_LTDC_LAYER_DISABLE(&(ltdc), !fb);

if (!reload) {
return;
}
/* LTDC reload request within next vertical blanking */
reloadLTDC_status = 0;
HAL_LTDC_Reload(&ltdc, LTDC_SRCR_VBR);
2 changes: 1 addition & 1 deletion libraries/Arduino_H7_Video/src/dsi.h
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ void dsi_lcdClear(uint32_t color);
void dsi_lcdDrawImage(void *pSrc, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
void dsi_lcdFillArea(void *pDst, uint32_t xSize, uint32_t ySize, uint32_t ColorMode);
void dsi_configueCLUT(uint32_t* clut);
void dsi_drawCurrentFrameBuffer(void);
void dsi_drawCurrentFrameBuffer(bool reload = true);
uint32_t dsi_getCurrentFrameBuffer(void);
uint32_t dsi_getActiveFrameBuffer(void);
uint32_t dsi_getFramebufferEnd(void);
768 changes: 6 additions & 762 deletions libraries/Arduino_H7_Video/src/lv_conf.h

Large diffs are not rendered by default.

762 changes: 762 additions & 0 deletions libraries/Arduino_H7_Video/src/lv_conf_8.h

Large diffs are not rendered by default.

973 changes: 973 additions & 0 deletions libraries/Arduino_H7_Video/src/lv_conf_9.h

Large diffs are not rendered by default.