What do you want to achieve?
I get very poor display output on my display screen and the colors are wrong for buttons and label background.
What have you tried so far?
- Tried increasing buffer size from 320 * 10 to 320 * 40.
- Tried using two buffers instead of one in
lv_disp_draw_buf_init
function - Made sure my pins are configured correctly inside User_Setup.h of the TFT_eSPI library.
Code to reproduce
#include <Arduino.h>
#include <TFT_eSPI.h>
#include <lvgl.h>
// Display buffer
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[320 * 40];
TFT_eSPI tft = TFT_eSPI();
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
uint32_t w = area->x2 - area->x1 + 1;
uint32_t h = area->y2 - area->y1 + 1;
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushPixels((uint16_t *)color_p, w * h);
tft.endWrite();
lv_disp_flush_ready(disp);
}
void setup() {
Serial.begin(115200);
// Power control
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
pinMode(14, OUTPUT);
digitalWrite(14, HIGH);
// Backlight control
pinMode(38, OUTPUT);
digitalWrite(38, HIGH);
// TFT initialization
tft.begin();
tft.setRotation(1);
// LVGL initialization
lv_init();
lv_disp_draw_buf_init(&draw_buf, buf, NULL, 320 * 40);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = 320;
disp_drv.ver_res = 240;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
}
void loop() {
lv_timer_handler();
delay(5);
}
// Pin setup in User_Setup.h inside TFT_eSPI library:
#define USER_SETUP_INFO "User_Setup"
#define ST7789_DRIVER
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_MOSI 48
#define TFT_SCLK 8
#define TFT_CS 6
#define TFT_DC 7
#define TFT_RST -1
#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
#define SMOOTH_FONT
Screenshot and/or video
Environment
- MCU/MPU/Board: I am using T-HMI (Resistive Touch) with ESP32-S3 and a ST7789 driver display.
- LVGL version: 8.3.5