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

显示效果

相关推荐
张世争7 小时前
RT-Thread qemu LVGL9.5 鼠标 indev 驱动更新 lv_port_indev.c
qemu·rt-thread·indev·lvgl9.5
张世争2 天前
RT-Thread bsp qemu-vexpress-a9 编译环境
qemu·rt-thread·编译
daqinzl21 天前
银河麒麟V10下使用QEMU安装Windows虚拟机
qemu·windows 10·银河麒麟v10
SXSBJS_XYT1 个月前
在资源有限的M0单片机上运行RTOS
单片机·rt-thread·rtos
ejinxian1 个月前
Linux 虚拟化技术 KVM/ESXI/Docker
linux·运维·docker·qemu·openvz
明早你自己说1 个月前
RT-Thread 在SD卡实现ulog+时间戳保存不同日志方法
stm32·rt-thread·ulog
skywalk81631 个月前
windows装wsl ubuntu24.04 ,里面装qemu ,然后装mac os (windows也可以直接qemu安装macos)(未实践)
windows·ubuntu·macos·qemu
学生董格2 个月前
[嵌入式embed]Keil5-STM32F103C8T6(江协科技)+移植RT-Thread v3.15模版
stm32·嵌入式硬件·rt-thread·keil5·江协科技
漫谈网络2 个月前
KVM创建的虚拟机,虚拟机的网卡是如何生成的
运维·服务器·网络·qemu·虚拟化·kvm