wireless-tag-com / ZX2D10GE01R-V4848

The Unlicense
72 stars 18 forks source link

LVGL 9.0 upgrade with screen.c #4

Open puddletowntom opened 7 months ago

puddletowntom commented 7 months ago

I would like to use the screen.c code with the latest version of LVGL. It seems like it is only a small change to make for compatibility, however I am not fully sure if i am doing it correctly. There is a tutorial on porting the display to 9.0 here.

https://docs.lvgl.io/master/porting/display.html

Its seems that the only functions that need to be changed are around the display initialisation. What i have done so far is change the two functions to the following,

static void __qsmd_rgb_disp_flush(lv_display_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
    int offsetx1 = area->x1;
    int offsetx2 = area->x2;
    int offsety1 = area->y1;
    int offsety2 = area->y2;

    esp_lcd_panel_draw_bitmap(g_panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_p);
    lv_disp_flush_ready(disp_drv);
}

void qmsd_rgb_init(esp_lcd_rgb_panel_config_t *panel_config)
{
    lv_display_t *myDisp;
    int32_t hor_res = panel_config->timings.h_res;
    int32_t ver_res = panel_config->timings.v_res;
    int buffer_size;

    void *buf1 = NULL;
    void *buf2 = NULL;

    lv_init();

    ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(panel_config, &g_panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_reset(g_panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_init(g_panel_handle));

    buffer_size = panel_config->timings.h_res * panel_config->timings.v_res;
    esp_lcd_rgb_panel_get_frame_buffer(g_panel_handle, 2, &buf1, &buf2);

    myDisp = lv_display_create(hor_res, ver_res);
    lv_display_set_flush_cb(myDisp, __qsmd_rgb_disp_flush);
    lv_display_set_buffers(myDisp, buf1, buf2, buffer_size, LV_DISPLAY_RENDER_MODE_PARTIAL); //LV_DISPLAY_RENDER_MODE_DIRECT or LV_DISPLAY_RENDER_MODE_FULL
    lv_display_set_draw_buffers(myDisp, buf1, buf2);
}

This originally looked like the following,

static void __qsmd_rgb_disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
    int offsetx1 = area->x1;
    int offsetx2 = area->x2;
    int offsety1 = area->y1;
    int offsety2 = area->y2;

    esp_lcd_panel_draw_bitmap(g_panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_p);
    lv_disp_flush_ready(disp_drv);
}

void qmsd_rgb_init(esp_lcd_rgb_panel_config_t *panel_config)
{
    static lv_disp_drv_t disp_drv;
    int buffer_size;
    void *buf1 = NULL;
    void *buf2 = NULL;
    static lv_disp_draw_buf_t draw_buf;

    lv_init();

    ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(panel_config, &g_panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_reset(g_panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_init(g_panel_handle));

    buffer_size = 480 * 40;
    buf1 = heap_caps_malloc(buffer_size * 2, MALLOC_CAP_DMA);
    lv_disp_draw_buf_init(&draw_buf, buf1, buf2, buffer_size);

    lv_disp_drv_init(&disp_drv);         
    disp_drv.flush_cb = __qsmd_rgb_disp_flush;
    disp_drv.draw_buf = &draw_buf;
    disp_drv.hor_res = panel_config->timings.h_res;
    disp_drv.ver_res = panel_config->timings.v_res;
    lv_disp_drv_register(&disp_drv);
}

This will compile with LVGL 9.0 if you just remove the encoder functions qsmd_encoder_init() and qmsd_encoder_read()

So far I am just getting a blank screen. It would be nice to get this ported in because I was having compatibility issues when using rlottie with LVGL v8.3.3. If anyone knows how to fix this maybe we can do a pull request and get it into the main code?