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

显示效果

相关推荐
牛奶咖啡1314 天前
KVM虚拟化与企业应用实践——给远端主机创建虚拟机
云原生·qemu·kvm·给远端主机创建虚拟机·创建uefi模式的虚拟机·安装openeulersp2·vnc与虚拟机环境搭建
牛奶咖啡1315 天前
KVM虚拟化与企业应用实践——通过网络介质配合ks自动应答文件实现自动安装KVM虚拟机
云原生·qemu·kvm·系统网络引导与ks自动应答环境·远程资源+ks文件安装虚拟机·通过网络介质引导自动安装虚拟机·qemu的总线类型详解
冰山一脚201316 天前
kvm驱动学习笔记
qemu
IOT那些事儿16 天前
RT-Thread STM32F407自制BSP编译
bsp·rt-thread·hal·stm32f407zet6
小范馆17 天前
浦洋-1.69LCD_P169H002 屏幕模组
lcd
ggaofeng19 天前
如何通过uboot加载硬盘
linux·qemu·uboot
ScilogyHunter19 天前
QEMU完全指南
linux·qemu
冰山一脚20131 个月前
qemu的cpu加速器分析笔记
qemu
时光飞逝的日子1 个月前
嵌入式智能体开发指南:基于鸿蒙 ArkUI 与 RT-Thread 的设备自主决策系统实现
rt-thread·鸿蒙系统·自主决策·嵌入式智能体·设备协同·嵌入式 aiot
小灰灰搞电子1 个月前
rt-thread RTC设备使用详解
rt-thread·rtc