From 08b75523cbde96dce83849a346c21c92bb4dac8d Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Wed, 2 Jul 2025 17:07:35 +0800 Subject: [PATCH 1/2] refactor(spi_lcd): detect the bus mode automatically --- components/esp_lcd/include/esp_lcd_io_spi.h | 4 ++-- components/esp_lcd/spi/esp_lcd_panel_io_spi.c | 11 +++++++++-- .../test_apps/spi_lcd/main/test_spi_lcd_panel.c | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/esp_lcd/include/esp_lcd_io_spi.h b/components/esp_lcd/include/esp_lcd_io_spi.h index 6781c6a428..e79563a341 100644 --- a/components/esp_lcd/include/esp_lcd_io_spi.h +++ b/components/esp_lcd/include/esp_lcd_io_spi.h @@ -35,8 +35,8 @@ typedef struct { unsigned int dc_high_on_cmd: 1; /*!< If enabled, DC level = 1 indicates command transfer */ unsigned int dc_low_on_data: 1; /*!< If enabled, DC level = 0 indicates color data transfer */ unsigned int dc_low_on_param: 1; /*!< If enabled, DC level = 0 indicates parameter transfer */ - unsigned int octal_mode: 1; /*!< transmit with octal mode (8 data lines), this mode is used to simulate Intel 8080 timing */ - unsigned int quad_mode: 1; /*!< transmit with quad mode (4 data lines), this mode is useful when transmitting LCD parameters (Only use one line for command) */ + unsigned int octal_mode: 1 __attribute__((deprecated("This bitfield is deprecated"))); /*!< Deprecated, driver will detect the bus mode automatically */ + unsigned int quad_mode: 1 __attribute__((deprecated("This bitfield is deprecated"))); /*!< Deprecated, driver will detect the bus mode automatically */ unsigned int sio_mode: 1; /*!< Read and write through a single data line (MOSI) */ unsigned int lsb_first: 1; /*!< transmit LSB bit first */ unsigned int cs_high_active: 1; /*!< CS line is high active */ diff --git a/components/esp_lcd/spi/esp_lcd_panel_io_spi.c b/components/esp_lcd/spi/esp_lcd_panel_io_spi.c index 13a84ca50f..e604ce365d 100644 --- a/components/esp_lcd/spi/esp_lcd_panel_io_spi.c +++ b/components/esp_lcd/spi/esp_lcd_panel_io_spi.c @@ -18,6 +18,7 @@ #include "driver/spi_master.h" #include "driver/gpio.h" #include "esp_private/gpio.h" +#include "esp_private/spi_common_internal.h" #include "hal/gpio_ll.h" #include "hal/gpio_hal.h" #include "esp_log.h" @@ -100,11 +101,17 @@ esp_err_t esp_lcd_new_panel_io_spi(esp_lcd_spi_bus_handle_t bus, const esp_lcd_p gpio_output_enable(io_config->dc_gpio_num); } + const spi_bus_attr_t* bus_attr = spi_bus_get_attr((spi_host_device_t)bus); + uint32_t flags = bus_attr->bus_cfg.flags; + if ((flags & SPICOMMON_BUSFLAG_QUAD) == SPICOMMON_BUSFLAG_QUAD) { + spi_panel_io->flags.quad_mode = 1; + } else if ((flags & SPICOMMON_BUSFLAG_OCTAL) == SPICOMMON_BUSFLAG_OCTAL) { + spi_panel_io->flags.octal_mode = 1; + } + spi_panel_io->flags.dc_cmd_level = io_config->flags.dc_high_on_cmd; spi_panel_io->flags.dc_data_level = !io_config->flags.dc_low_on_data; spi_panel_io->flags.dc_param_level = !io_config->flags.dc_low_on_param; - spi_panel_io->flags.octal_mode = io_config->flags.octal_mode; - spi_panel_io->flags.quad_mode = io_config->flags.quad_mode; spi_panel_io->on_color_trans_done = io_config->on_color_trans_done; spi_panel_io->user_ctx = io_config->user_ctx; spi_panel_io->lcd_cmd_bits = io_config->lcd_cmd_bits; diff --git a/components/esp_lcd/test_apps/spi_lcd/main/test_spi_lcd_panel.c b/components/esp_lcd/test_apps/spi_lcd/main/test_spi_lcd_panel.c index eb40f3dcf9..e975eac556 100644 --- a/components/esp_lcd/test_apps/spi_lcd/main/test_spi_lcd_panel.c +++ b/components/esp_lcd/test_apps/spi_lcd/main/test_spi_lcd_panel.c @@ -66,7 +66,6 @@ void test_spi_lcd_common_initialize(esp_lcd_panel_io_handle_t *io_handle, esp_lc }; #if SOC_SPI_SUPPORT_OCT if (oct_mode) { - io_config.flags.octal_mode = 1; io_config.spi_mode = 3; } #endif From 57cbcf388e874b58de8289a2a10b33f303c82848 Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Mon, 7 Jul 2025 12:02:08 +0800 Subject: [PATCH 2/2] docs(lcd): fix the wrong hyperlink in readme Closes https://github.com/espressif/esp-idf/issues/16389 --- docs/page_redirects.txt | 1 + examples/peripherals/lcd/i2c_oled/README.md | 2 +- examples/peripherals/lcd/spi_lcd_touch/README.md | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/page_redirects.txt b/docs/page_redirects.txt index 5445e53cea..8a27dfae76 100644 --- a/docs/page_redirects.txt +++ b/docs/page_redirects.txt @@ -31,6 +31,7 @@ api-reference/peripherals/adc_oneshot /api-reference/peripherals/adc/adc_one api-reference/peripherals/adc_continuous api-reference/peripherals/adc/adc_continuous api-reference/peripherals/adc_calibration api-reference/peripherals/adc/adc_calibration api-reference/peripherals/adc api-reference/peripherals/adc/index +api-reference/peripherals/lcd api-reference/peripherals/lcd/index get-started/idf-monitor api-guides/tools/idf-monitor diff --git a/examples/peripherals/lcd/i2c_oled/README.md b/examples/peripherals/lcd/i2c_oled/README.md index 8752f42c4d..09c1110508 100644 --- a/examples/peripherals/lcd/i2c_oled/README.md +++ b/examples/peripherals/lcd/i2c_oled/README.md @@ -3,7 +3,7 @@ # I2C OLED example -[esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) supports I2C interfaced OLED LCD, whose color depth is usually 1bpp. +[esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd/i2c_lcd.html) supports I2C interfaced OLED LCD, whose color depth is usually 1bpp. This example shows how to make use of the SSD1306 panel driver from `esp_lcd` component to facilitate the porting of LVGL library. In the end, example will display a scrolling text on the OLED screen. For more information about porting the LVGL library, you can also refer to another [lvgl porting example](../i80_controller/README.md). diff --git a/examples/peripherals/lcd/spi_lcd_touch/README.md b/examples/peripherals/lcd/spi_lcd_touch/README.md index b984c0e5e2..448c24e219 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/README.md +++ b/examples/peripherals/lcd/spi_lcd_touch/README.md @@ -3,7 +3,7 @@ # SPI LCD and Touch Panel Example -[esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) provides several panel drivers out-of box, e.g. ST7789, SSD1306, NT35510. However, there're a lot of other panels on the market, it's beyond `esp_lcd` component's responsibility to include them all. +[esp_lcd](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd/spi_lcd.html) provides several panel drivers out-of box, e.g. ST7789, SSD1306, NT35510. However, there're a lot of other panels on the market, it's beyond `esp_lcd` component's responsibility to include them all. `esp_lcd` allows user to add their own panel drivers in the project scope (i.e. panel driver can live outside of esp-idf), so that the upper layer code like LVGL porting code can be reused without any modifications, as long as user-implemented panel driver follows the interface defined in the `esp_lcd` component.