Hello, your driver successfully drives my LCD screen, but I encountered some problems. The screen will be distorted when switching to landscape mode.The MCU I use is ESP32S3, and the lvgl version is 8.3.
#define EXAMPLE_PIN_NUM_SCLK 14
#define EXAMPLE_PIN_NUM_MOSI 15
#define EXAMPLE_PIN_NUM_MISO 13
#define EXAMPLE_PIN_NUM_LCD_DC 16
#define EXAMPLE_PIN_NUM_LCD_RST 17
#define EXAMPLE_PIN_NUM_LCD_CS 18
#define EXAMPLE_PIN_NUM_BK_LIGHT 2
#define EXAMPLE_PIN_NUM_TOUCH_CS 15
static const int DISPLAY_HORIZONTAL_PIXELS = 320;
static const int DISPLAY_VERTICAL_PIXELS = 480;
static const int DISPLAY_COMMAND_BITS = 8;
static const int DISPLAY_PARAMETER_BITS = 8;
static const unsigned int DISPLAY_REFRESH_HZ = 40000000;
static const int DISPLAY_SPI_QUEUE_LEN = 10;
static const int SPI_MAX_TRANSFER_SIZE = 32768;
static const size_t LV_BUFFER_SIZE = DISPLAY_HORIZONTAL_PIXELS * 25;
static esp_lcd_panel_io_handle_t lcd_io_handle = NULL;
static esp_lcd_panel_handle_t lcd_handle = NULL;
static lv_disp_draw_buf_t lv_disp_buf;
static lv_disp_drv_t lv_disp_drv;
static lv_disp_t *lv_display = NULL;
static const char *TAG = "disp";
static bool notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io,
esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
{
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
return false;
}
static void lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
}
void disp_init()
{
ESP_LOGI(TAG, "Initializing SPI bus (MOSI:%d, MISO:%d, CLK:%d)",
EXAMPLE_PIN_NUM_MOSI, EXAMPLE_PIN_NUM_MISO, EXAMPLE_PIN_NUM_SCLK);
spi_bus_config_t bus =
{
.mosi_io_num = EXAMPLE_PIN_NUM_MOSI,
.miso_io_num = EXAMPLE_PIN_NUM_MISO,
.sclk_io_num = EXAMPLE_PIN_NUM_SCLK,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.max_transfer_sz = SPI_MAX_TRANSFER_SIZE,
.flags = SPICOMMON_BUSFLAG_SCLK | SPICOMMON_BUSFLAG_MISO |
SPICOMMON_BUSFLAG_MOSI | SPICOMMON_BUSFLAG_MASTER,
.intr_flags = ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus, SPI_DMA_CH_AUTO));
const esp_lcd_panel_io_spi_config_t io_config =
{
.cs_gpio_num = EXAMPLE_PIN_NUM_LCD_CS,
.dc_gpio_num = EXAMPLE_PIN_NUM_LCD_DC,
.spi_mode = 0,
.pclk_hz = DISPLAY_REFRESH_HZ,
.trans_queue_depth = DISPLAY_SPI_QUEUE_LEN,
.on_color_trans_done = notify_lvgl_flush_ready,
.user_ctx = &lv_disp_drv,
.lcd_cmd_bits = DISPLAY_COMMAND_BITS,
.lcd_param_bits = DISPLAY_PARAMETER_BITS,
.flags =
{
.dc_low_on_data = 0,
.octal_mode = 0,
.sio_mode = 0,
.lsb_first = 0,
.cs_high_active = 0
}
};
const esp_lcd_panel_dev_config_t lcd_config =
{
.reset_gpio_num = EXAMPLE_PIN_NUM_LCD_RST,
.color_space = LCD_RGB_ELEMENT_ORDER_RGB,
.bits_per_pixel = 18,
.flags =
{
.reset_active_high = 0
},
.vendor_config = NULL
};
ESP_ERROR_CHECK(
esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &io_config, &lcd_io_handle));
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9488(lcd_io_handle, &lcd_config, LV_BUFFER_SIZE, &lcd_handle));
ESP_ERROR_CHECK(esp_lcd_panel_reset(lcd_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(lcd_handle));
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(lcd_handle, false));
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(lcd_handle, false));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(lcd_handle, false, false));
ESP_ERROR_CHECK(esp_lcd_panel_set_gap(lcd_handle, 0, 0));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(lcd_handle, true));
ESP_LOGI(TAG, "Initializing LVGL");
lv_init();
// ESP_LOGI(TAG, "Allocating %zu bytes for LVGL buffer", LV_BUFFER_SIZE * sizeof(lv_color_t));
// lv_buf_1 = (lv_color_t *)heap_caps_malloc(LV_BUFFER_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
// ESP_LOGI(TAG, "Creating LVLG display buffer");
// lv_disp_draw_buf_init(&lv_disp_buf, lv_buf_1, lv_buf_2, LV_BUFFER_SIZE);
// it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized
lv_color_t *buf1 = heap_caps_malloc(DISPLAY_HORIZONTAL_PIXELS * 20 * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf1);
lv_color_t *buf2 = heap_caps_malloc(DISPLAY_HORIZONTAL_PIXELS * 20 * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf2);
// initialize LVGL draw buffers
lv_disp_draw_buf_init(&lv_disp_buf, buf1, buf2, DISPLAY_HORIZONTAL_PIXELS * 10);
ESP_LOGI(TAG, "Initializing %dx%d display", DISPLAY_HORIZONTAL_PIXELS, DISPLAY_VERTICAL_PIXELS);
lv_disp_drv_init(&lv_disp_drv);
lv_disp_drv.hor_res = DISPLAY_HORIZONTAL_PIXELS;
lv_disp_drv.ver_res = DISPLAY_VERTICAL_PIXELS;
lv_disp_drv.flush_cb = lvgl_flush_cb;
lv_disp_drv.draw_buf = &lv_disp_buf;
lv_disp_drv.user_data = lcd_handle;
lv_disp_drv.rotated = LV_DISP_ROT_NONE;
lv_display = lv_disp_drv_register(&lv_disp_drv);
}
The above is my driver code, which is basically written according to your example。
![3D63B1D59FC81D214833042B5C65FE0D](https://private-user-images.githubusercontent.com/73769819/344439102-74f3549a-0fe6-454e-af78-362df752ec93.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NTIyNjEsIm5iZiI6MTcyNDQ1MTk2MSwicGF0aCI6Ii83Mzc2OTgxOS8zNDQ0MzkxMDItNzRmMzU0OWEtMGZlNi00NTRlLWFmNzgtMzYyZGY3NTJlYzkzLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDIyMjYwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI2MWUyMTg0YzhmNGM1MWQ4ZTUyYjhiYmNmZDkwNWMxMGNjMjE4YWZkMGU2NDNhYTU5NjdlOTY1NDc2ZDQ1NjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.xeCZ2w5g1JOHyZwZasvznpOa1AzO71L81nW7m8xx0cM)
![7CF707FBB18128864401E602D4F08FB3](https://private-user-images.githubusercontent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