RT-Thread qemu LVGL9.5 显示驱动更新 lv_port_disp.c

说明

  • 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);
}

显示效果

相关推荐
xzl043 小时前
PL111 RGB LCD时序配置详解
rt-thread·pl111
xzl041 天前
LVGL 启动流程全解析:RT-Thread 下的界面渲染链路
rt-thread·lvgl
xzl041 天前
LVGL Coffee UI 接入实战:问题解决全记录
ui·rt-thread·lvgl
神一样的老师7 天前
【兆易创新GD32VW553开发板试用】 BSP 从 GitHub 下载与编译指南
单片机·github·rt-thread
xzl047 天前
【Menuconfig】RT-Thread配置菜单第一级
rt-thread
xzl048 天前
瑞萨 FSP 和 STM32 HAL 库的启动流程核心差异
stm32·单片机·嵌入式硬件·rt-thread
xzl048 天前
RT-Thread 5.2.2内核模块
开发语言·rt-thread
Shining05969 天前
QEMU 编译开发环境搭建
人工智能·语言模型·自然语言处理·云原生·qemu·vllm·华为昇腾
高铭杰12 天前
Postgresql热迁移pgbench持续读写零中断
postgresql·qemu·neon