Problem with ST7769S and LVGL 9.5

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

Board: ESP32-S3-N16R8 TFT: 4" ST7769S Compiler: PlatformIO

Code to reproduce

#include “display.h”

#include <Arduino.h>

#include “lvgl.h”

#include <SPI.h>

#include “ui/ui.h”

// — BACKLIGHT —

int BL_CHANNEL = 1; // frei wählbar

int BL_FREQ = 5000; // 5 kHz ideal für Backlight

int BL_RES = 8; // 0–255

SPIClass spi(HSPI);

/* — LVGL Display Handle — */

static lv_display_t *disp;

// — Backlight —

void initBacklight()

{

ledcSetup(BL_CHANNEL, BL_FREQ, BL_RES);

ledcAttachPin(TFT_BL, BL_CHANNEL);



// Startwert: 100%

ledcWrite(BL_CHANNEL, 255);

}

void setBacklightValue(int percent)

{

// MIN/MAX Überwachung

if (percent < 10)

    percent = 10;

if (percent > 100)

    percent = 100;



// Prozent (10–100) → PWM (0–255)

int pwm = (percent \* 255) / 100;



ledcWrite(BL_CHANNEL, pwm);

}

/* — ST7769 Commands — */

static void send_cmd(uint8_t cmd)

{

digitalWrite(TFT_DC, LOW);

digitalWrite(TFT_CS, LOW);

spi.write(cmd);

digitalWrite(TFT_CS, HIGH);

}

static void send_data(const uint8_t *data, uint32_t len)

{

digitalWrite(TFT_DC, HIGH);

digitalWrite(TFT_CS, LOW);

spi.writeBytes(data, len);

digitalWrite(TFT_CS, HIGH);

}

/* — Flush Callback für LVGL — */

static void flush_cb(lv_display_t *d, const lv_area_t *area, uint8_t *px_map)

{

uint16_t x1 = area->x1;

uint16_t x2 = area->x2;

uint16_t y1 = area->y1;

uint16_t y2 = area->y2;



uint8_t buf\[4\];



/\* Column address \*/

send_cmd(0x2A);

buf\[0\] = x1 >> 8;

buf\[1\] = x1 & 0xFF;

buf\[2\] = x2 >> 8;

buf\[3\] = x2 & 0xFF;

send_data(buf, 4);



/\* Row address \*/

send_cmd(0x2B);

buf\[0\] = y1 >> 8;

buf\[1\] = y1 & 0xFF;

buf\[2\] = y2 >> 8;

buf\[3\] = y2 & 0xFF;

send_data(buf, 4);



/\* Memory write \*/

send_cmd(0x2C);



/\* Pixel-Daten senden \*/

send_data(px_map, (x2 - x1 + 1) \* (y2 - y1 + 1) \* 2);



lv_display_flush_ready(d);

}

/* — ST7769 Initialisierung — */

static void st7769_hw_init()

{

digitalWrite(TFT_RST, LOW);

delay(50);

digitalWrite(TFT_RST, HIGH);

delay(50);



/\* Memory Access Control (Rotation + Mirror + BGR) \*/

send_cmd(0x36);

uint8_t madctl = 0x2C | 0x08;

send_data(&madctl, 1);



/\* Pixel Format \*/

send_cmd(0x3A);

uint8_t pixfmt = 0x55; // 16-bit RGB565

send_data(&pixfmt, 1);



send_cmd(0x21); // Inversion ON

send_cmd(0x11); // Sleep Out

delay(120);

send_cmd(0x29); // Display ON

}

/* — LVGL Display erstellen — */

lv_display_t *st7769_init()

{

pinMode(TFT_CS, OUTPUT);

pinMode(TFT_DC, OUTPUT);

pinMode(TFT_RST, OUTPUT);



spi.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, TFT_CS);

spi.setFrequency(40000000); // 40 MHz stabil



st7769_hw_init();



disp = lv_display_create(screenWidth, screenHeight);

//lv_display_set_color_format(disp, LV_COLOR_FORMAT_RGB565_SWAPPED);



static lv_color_t screen_buffer\[screenWidth \* 80\];

lv_display_set_buffers(disp, screen_buffer, NULL, sizeof(screen_buffer), LV_DISPLAY_RENDER_MODE_PARTIAL);



lv_display_set_flush_cb(disp, flush_cb);



return disp;

}

void display_init()

{

lv_init();

st7769_init();

ui_init();

initBacklight();

setBacklightValue(90);

}

void display_loop()

{

lv_task_handler();

}

So i have wrong colors and i think no Screen-Updates (?) I have tried a lot of things, but now i have no idea and no solution found. It would be really nice if someone here has a solution and could help me out a lot with it. I’m grateful for any tip.

Here is the description of my TFT: https://www.lcdwiki.com/res/MSP4030_MSP4031/MSP4030_MSP4031_Specification_EN_V1.0.pdf

This is a Screenshot from SquareLine-Studio:

This is the output on my Screen:

Hello @Toddie, if your display driver is correct also take a look at the color configuration on lv_conf

If this is RGB565 display, CPU vs LCD endian mismatch looks like this.