说明
-
RT-Thread : 5.2.0
-
LVGL 9.5
-
BSP : qemu-vexpress-a9
-
更新 LVGL 9.5 版本后, 原来的 LVGL8.3 版本的 LCD 显示驱动
lv_port_disp.c需要重新适配。 -
qemu qemu-vexpress-a9 LCD 驱动默认是: RGB565 (16位)的
lv_port_disp.c 适配
- 内容如下,在 LVGL 9.5 版本上验证通过
c
#include <lvgl.h>
#include <drv_clcd.h>
static rt_device_t lcd_device = RT_NULL;
static struct rt_device_graphic_info info;
static lv_display_t *disp_drv; /*Descriptor of a display driver*/
/*Flush the content of the internal buffer the specific area on the display
*You can use DMA or any hardware acceleration to do this operation in the background but
*'lv_disp_flush_ready()' has to be called when finished.*/
static void lcd_fb_flush(lv_display_t * disp, const lv_area_t * area, uint8_t *px_map)
{
uint32_t x;
uint32_t y;
uint32_t location = 0;
uint16_t *fb_buf;
/* 16 bit per pixel */
lv_color16_t *fbp16 = (lv_color16_t *)info.framebuffer;
for (y = area->y1; y <area->y2 + 1; y++)
{
for (x = area->x1; x <area->x2 + 1; x++)
{
fb_buf = (uint16_t *)px_map;
location = x + y * info.width;
fbp16[location].red = (*fb_buf >> 11) & 0x1F;
fbp16[location].green = (*fb_buf >> 5) & 0x3F;
fbp16[location].blue = *fb_buf & 0x1F;
px_map+=2;
}
}
lv_display_flush_ready(disp_drv);
}
void lv_port_disp_init(void)
{
rt_err_t result;
lv_color_t *fbuf1, *fbuf2;
uint32_t fbuf_size;
lcd_device = rt_device_find("lcd");
if (lcd_device == 0)
{
rt_kprintf("error!\n");
return;
}
result = rt_device_open(lcd_device, 0);
if (result != RT_EOK)
{
rt_kprintf("error!\n");
return;
}
/* get framebuffer address */
result = rt_device_control(lcd_device, RTGRAPHIC_CTRL_GET_INFO, &info);
if (result != RT_EOK)
{
rt_kprintf("error!\n");
/* get device information failed */
return;
}
RT_ASSERT(info.bits_per_pixel == 8 || info.bits_per_pixel == 16 ||
info.bits_per_pixel == 24 || info.bits_per_pixel == 32);
fbuf_size = info.width * info.height * sizeof(lv_color16_t);
fbuf1 = rt_malloc(fbuf_size);
if (fbuf1 == RT_NULL)
{
rt_kprintf("Error: alloc disp buf fail\n");
return;
}
fbuf2 = rt_malloc(fbuf_size);
if (fbuf2 == RT_NULL)
{
rt_kprintf("Error: alloc disp buf fail\n");
rt_free(fbuf1);
return;
}
disp_drv = lv_display_create(info.width, info.height);
{
if (disp_drv == RT_NULL)
{
rt_kprintf("%s : Error: lv_display_create failed\n", __func__);
return;
}
}
lv_display_set_buffers(disp_drv, fbuf1, fbuf2, fbuf_size, LV_DISPLAY_RENDER_MODE_PARTIAL);
/* This callback will display the rendered image */
lv_display_set_flush_cb(disp_drv, lcd_fb_flush);
}
显示效果
