Lv_display_set_flush_cb() can't accept flush callback

What happened?

I was making project on LVGL v8.3.x, and now decided to migrate to v9.1.0. I’ve had a function for display flushing working on v8.3, then I followed the steps to migrate this function to v9.1.0, but found one problem - when I try to set the flush callback with lv_display_set_flush_cb(disp, my_disp_flush), it gives me an error:

error: invalid conversion from 'void (*)(lv_display_t*, const lv_area_t*, lv_color_t*)' {aka 'void (*)(_lv_display_t*, const lv_area_t*, lv_color_t*)'} to 'lv_display_flush_cb_t' {aka 'void (*)(_lv_display_t*, const lv_area_t*, unsigned char*)'} [-fpermissive]

But if I try to change callback type to lv_display_flush_cb_t, error stays + compiler ask to provide return value
Also I tried to copy example from this docs page (replaced put_px with my pixel drawing function), but it also didn’t work.

Logs:

src/main.cpp: In function 'void setup()':
src/main.cpp:107:33: error: invalid conversion from 'void (* (*)(lv_display_t*, const lv_area_t*, lv_color_t*))(lv_display_t*, const lv_area_t*, uint8_t*)' {aka 'void (* (*)(_lv_display_t*, const lv_area_t*, lv_color_t*))(_lv_display_t*, const lv_area_t*, unsigned char*)'} to 'lv_display_flush_cb_t' {aka 'void (*)(_lv_display_t*, const lv_area_t*, unsigned char*)'} [-fpermissive]
   lv_display_set_flush_cb(disp, my_disp_flush);
                                 ^~~~~~~~~~~~~
In file included from .pio/libdeps/esp32doit-devkit-v1/lvgl/src/core/lv_obj_tree.h:20,
                 from .pio/libdeps/esp32doit-devkit-v1/lvgl/src/core/lv_obj.h:26,
                 from .pio/libdeps/esp32doit-devkit-v1/lvgl/lvgl.h:41,
                 from src/main.cpp:7:
.pio/libdeps/esp32doit-devkit-v1/lvgl/src/core/../display/lv_display.h:262:73: note:   initializing argument 2 of 'void lv_display_set_flush_cb(lv_display_t*, lv_display_flush_cb_t)'
 void lv_display_set_flush_cb(lv_display_t * disp, lv_display_flush_cb_t flush_cb);

How to reproduce?

//...
#include <lvgl.h>

lv_display_t * disp = lv_display_create(320, 240);
static lv_color_t buf[320* 10];
void my_disp_flush(lv_display_t *disp, const lv_area_t *area, lv_color_t *color_p);

void setup(){
    lv_display_set_flush_cb(disp, my_disp_flush);        // here is the problem!
    lv_display_set_buffers(disp, buf, NULL, 320*10, LV_DISPLAY_RENDER_MODE_PARTIAL);
}
void loop(){
    //...
}

/* Display flushing (code from lvgl docs slightly modified) */
void my_flush_cb(lv_display_t * display, const lv_area_t * area, uint8_t * px_map)
{
    uint16_t * buf16 = (uint16_t *)px_map;
    int32_t x, y;
    for(y = area->y1; y <= area->y2; y++) {
        for(x = area->x1; x <= area->x2; x++) {
            tft.drawPixel(x, y, *buf16);    //custom function to draw pixels
            buf16++;
        }
    }
    lv_display_flush_ready(disp);
}

It’s just little oversight:
The prototype:

void my_disp_flush(lv_display_t *disp, const lv_area_t *area, lv_color_t *color_p);

The definition:

void my_flush_cb(lv_display_t * display, const lv_area_t * area, uint8_t * px_map)
{
 ...

See the last parameter.

1 Like