Merge branch 'refactor/spi_lcd_detect_bus_mode_automatically' into 'master'

refactor(spi_lcd): detect the bus mode automatically

Closes IDF-11255 and IDFGH-15695

See merge request espressif/esp-idf!40308
This commit is contained in:
Chen Ji Chang
2025-07-14 11:45:15 +08:00
6 changed files with 14 additions and 7 deletions

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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).

View File

@@ -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.