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

显示效果

相关推荐
enjoy嚣士2 天前
Windows10下安装arm64架构的centos
qemu·aarch64 linux·arm64 linux·arm64 centos
fox081513 天前
RTThread-Studio中,使用5.2.0版本默认配置生成工程,进行编译报警告的部分解决方法。
mcu·rt-thread·rtthread-studio
x-cmd16 天前
[x-cmd] QEMU 10.2.0 发布:虚拟机实时更新与性能飞跃的技术深度解读
安全·qemu·虚拟机·x-cmd
yao0003716 天前
基于QEMU+OpenSBI+edk2的riscv启动流程解析
qemu·riscv·uefi·bios·固件·opensbi
三雷科技18 天前
qemu-img 使用手册(含详细案例)
qemu
hwmxrhx18 天前
解析DTS时序参数:1920×1200屏幕配置详解
lcd·dts
混分巨兽龙某某1 个月前
基于STM32的嵌入式操作系统RT-Thread移植教学(HAL库版本)
stm32·嵌入式硬件·rt-thread·rtos
张世争1 个月前
RT-Thread 5.3 windows bsp simulator scons --target=vs 生成的工程编译失败问题
windows·rt-thread·simulator
张世争1 个月前
RT-Thread windows bsp simulator Visual Studio 2012 (v110) (未安装) 问题
rt-thread·visual studio·simulator
河码匠1 个月前
libvirt xml 配置文件说明
qemu·kvm·libvirt