Incorrect color received in flush callback

I am trying to write a driver for the ILI9488 which I have now working by itself but while setting up a simple example and adding debug logs, I see that:

  • The screen is first initialized to white (ok)
  • When I add my label, the color reported by the print statements is still white, so nothing is drawn

I hacked the function with a counter and I can see that if I hardcode a value, the display shows the correct output.

Flush:

static int c = 0;
void my_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
   c +=1;
   if (c >=33) {
     color_p->ch.red = 0;
   }
    for(y = area->y1; y <= area->y2; y++) {
        for(x = area->x1; x <= area->x2; x++) {
            tft.drawPixel(x, y, tft.color565(color_p->ch.red, color_p->ch.green, color_p->ch.blue));
        }
    }
    Serial.printf("Pixel color: r:%d, g:%d, b:%d\n", color_p->ch.red, color_p->ch.green, color_p->ch.blue);
    Serial.printf("count: %d", c);
    lv_disp_flush_ready(disp_drv);
}

The config is set to #define LV_COLOR_DEPTH 32

Draw function:

void paint(void)
{
  static lv_style_t my_red_style;
  lv_style_copy(&my_red_style, &lv_style_plain);
  my_red_style.body.main_color = LV_COLOR_RED;
  my_red_style.text.color = LV_COLOR_RED;

  lv_obj_t* label = lv_label_create(lv_scr_act(), NULL);
  lv_obj_set_style(label, &my_red_style); 
  lv_label_set_text(label, "Hello world!");  
  lv_obj_set_pos(label, 450, 305);
   
}

Print output:

Pixel color: r:255, g:255, b:255
count: 1Pixel color: r:255, g:255, b:255
count: 2Pixel color: r:255, g:255, b:255
count: 3Pixel color: r:255, g:255, b:255
count: 4Pixel color: r:255, g:255, b:255
count: 5Pixel color: r:255, g:255, b:255
count: 6Pixel color: r:255, g:255, b:255
count: 7Pixel color: r:255, g:255, b:255
count: 8Pixel color: r:255, g:255, b:255
count: 9Pixel color: r:255, g:255, b:255
count: 10Pixel color: r:255, g:255, b:255
count: 11Pixel color: r:255, g:255, b:255
count: 12Pixel color: r:255, g:255, b:255
count: 13Pixel color: r:255, g:255, b:255
count: 14Pixel color: r:255, g:255, b:255
count: 15Pixel color: r:255, g:255, b:255
count: 16Pixel color: r:255, g:255, b:255
count: 17Pixel color: r:255, g:255, b:255
count: 18Pixel color: r:255, g:255, b:255
count: 19Pixel color: r:255, g:255, b:255
count: 20Pixel color: r:255, g:255, b:255
count: 21Pixel color: r:255, g:255, b:255
count: 22Pixel color: r:255, g:255, b:255
count: 23Pixel color: r:255, g:255, b:255
count: 24Pixel color: r:255, g:255, b:255
count: 25Pixel color: r:255, g:255, b:255
count: 26Pixel color: r:255, g:255, b:255
count: 27Pixel color: r:255, g:255, b:255
count: 28Pixel color: r:255, g:255, b:255
count: 29Pixel color: r:255, g:255, b:255
count: 30Pixel color: r:255, g:255, b:255
count: 31Pixel color: r:255, g:255, b:255
count: 32Before setting the objects
INFO: File: .pio/libdeps/esp32dev/lvgl_ID6598/src/lv_objx/lv_label.c#161: label created
After setting the objects
Pixel color: r:0, g:255, b:255
count: 33Pixel color: r:0, g:255, b:255
count: 34Pixel color: r:0, g:255, b:255
count: 35

Thanks

color_p points to an array of pixels. You should be incrementing that pointer every time you draw a pixel. Have a look at the my_flush_cb function here.

1 Like

I spent so much time looking at the wrong place, thanks!