LVGL --- 移植

提供给 LVGL 写 LCD 指定区域的函数

当 LVGL 渲染完,调用回调函数 example_lvgl_flush_cb 把数据写入 LCD

    // set the callback which can copy the rendered image to an area of the display
    lv_display_set_flush_cb(display, example_lvgl_flush_cb);

回调函数的函数类型如下

typedef void (*lv_display_flush_cb_t)(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map);

area 指定待显示数据的坐标,px_map 是待显示数据,disp 是创建 LVGL 显示返回的对象,所以可以把写 LCD 指定区域的函数记录在 disp 对象内

    // associate the mipi panel handle to the display
    lv_display_set_user_data(display, mipi_dpi_panel);

void lv_display_set_user_data(lv_display_t * disp, void * user_data)
{
    if(!disp) disp = lv_display_get_default();
    if(!disp) return;
    disp->user_data = user_data;
}

从而实现 LVGL 渲染完,调用回调函数,在回调函数内写 LCD 指定区域,回调函数例子如下

static void example_lvgl_flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map)
{
    esp_lcd_panel_handle_t panel_handle = lv_display_get_user_data(disp);
    int offsetx1 = area->x1;
    int offsetx2 = area->x2;
    int offsety1 = area->y1;
    int offsety2 = area->y2;
    // pass the draw buffer to the driver
    esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, px_map);
}

告知 LVGL 什么时候可以修改 LVGL 的待显示数据内存

分防撕裂和不防撕裂场景

不防撕裂,LVGL有自己的缓冲区,待显示数据拷贝到帧缓存后,调用lv_display_flush_ready(lv_disp_flush_ready) 告知 LVGL 可以再次对缓冲区进行修改。lv_display_flush_ready 对 disp->flushing 进行清零,为0表示拷贝完成,为1待拷贝。

防撕裂,LVGL 交替使用两个帧缓存的其中一个,不生效的帧缓存可以被LVGL修改,生效的帧缓存数据被输送到LCD,数据都输送到LCD后,生效的帧缓存不生效,同时调用lv_display_flush_ready

提供给 LVGL 从运行到当前流逝多少时间

使用定时器周期调用 lv_tick_inc()

或者

注册读时间回调函数,即调用 lv_tick_set_cb()。LVGL 库在 linux 环境下一般选这种,因为系统有提供时间的函数

周期调用 LVGL 自身定时器函数

lv_timer_handler()

为 LVGL 添加输入设备,如触屏

 

 
 
 

 

posted @ 2024-05-13 15:40  流水灯  阅读(481)  评论(0)    收藏  举报