Display shows garbage after partial redraw

Description

When trying to edit a label, the area on the screen where the label is located gets overwritten with garbage.

What MCU/Processor/Board and compiler are you using?

Custom NXP based board

What LVGL version are you using?

8.3

What have you tried so far?

I was able to get the lvgl library to work on my ili9341 screen. I’ve also created a gui using squareline studio and it is properly drawn on the lcd.

Now I need to change some labels on the screen during runtime. To do this I call the following function:

lv_label_set_text(ui_Label4, "hello");

The draw buffers that I’m currently using are both 0x400 bytes long. This is the maximum DMA SPI transfer length on the LPC54xx MCU’s. Therefore, full screen refreshs are split up in multiple flushes.

FUN FACT: When I manually change the color data in the display flush routine to 0xF000 (RGB565 RED), the label area is correctly redrawn with red pixels.

Thanks for your inputs :slight_smile:

Pictures

Just after starting, screen looks fine:

After modifying the label using the lv_label_set_text function it looks like this:

are you adding a 1 to the width and height in the flush function?

Yes, i’ve added the flush function below.

#define LCD_FB_BYTE_PER_PIXEL 2U

static void DEMO_FlushDisplay(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
    lv_coord_t x1 = area->x1;
    lv_coord_t y1 = area->y1;
    lv_coord_t x2 = area->x2;
    lv_coord_t y2 = area->y2;

    uint8_t data[4];
    const uint8_t *pdata = (const uint8_t *)color_p;
    size_t size = (x2 - x1 + 1) * (y2 - y1 + 1) * LCD_FB_BYTE_PER_PIXEL;

    DEMO_SPI_LCD_AssertSlaveSelect();

    /*Column addresses*/
    DEMO_SPI_LCD_WriteCmd(ILI9341_CMD_COLADDR);
    data[0] = (y1 >> 8) & 0xFF;
    data[1] = y1 & 0xFF;
    data[2] = (y2 >> 8) & 0xFF;
    data[3] = y2 & 0xFF;
    DEMO_SPI_LCD_Write(data, 4, LCD_DC_DATA);
    
    /*Page addresses*/
    DEMO_SPI_LCD_WriteCmd(ILI9341_CMD_PAGEADDR);
    data[0] = (x1 >> 8) & 0xFF;
    data[1] = x1 & 0xFF;
    data[2] = (x2 >> 8) & 0xFF;
    data[3] = x2 & 0xFF;
    DEMO_SPI_LCD_Write(data, 4, LCD_DC_DATA);

    /*Memory write*/
    DEMO_SPI_LCD_WriteCmd(ILI9341_CMD_GRAM);
    DEMO_SPI_LCD_WriteDMA(pdata, size, LCD_DC_DATA, DEMO_FlushDisplayComplete_CB);

    //Deassert happens in callback
}

if you are using lvgl8.x you have to set macro to swap the colors. If using 9.0 you have to set the color format to native reverse

The issue was somehow related to the pixel write order. After changing both the initialization and the flush routine to the official lvgl drivers, everything seems to work fine.

Find the official drivers here: GitHub - lvgl/lv_drivers: TFT and touch pad drivers for LVGL embedded GUI library