Skip to content

Commit

Permalink
Merge branch 'contrib/github_pr_12908_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
spi_lcd: add flag to control the DC level in cmd/param/data phase separately (GitHub PR) (v5.1)

See merge request espressif/esp-idf!28241
  • Loading branch information
suda-morris committed Jan 4, 2024
2 parents d2c1fcf + 3078210 commit a66693c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions components/esp_lcd/include/esp_lcd_panel_io.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -134,10 +134,12 @@ typedef struct {
int lcd_cmd_bits; /*!< Bit-width of LCD command */
int lcd_param_bits; /*!< Bit-width of LCD parameter */
struct {
unsigned int dc_low_on_data: 1; /*!< If this flag is enabled, DC line = 0 means transfer data, DC line = 1 means transfer command; vice versa */
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 sio_mode: 1; /*!< Read and write through a single data line (MOSI) */
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 */
} flags; /*!< Extra flags to fine-tune the SPI device */
Expand Down
20 changes: 12 additions & 8 deletions components/esp_lcd/src/esp_lcd_panel_io_spi.c
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -52,7 +52,9 @@ typedef struct {
int lcd_cmd_bits; // Bit width of LCD command
int lcd_param_bits; // Bit width of LCD parameter
struct {
unsigned int dc_data_level: 1; // Indicates the level of DC line when tranfering data
unsigned int dc_cmd_level: 1; // Indicates the level of DC line when transferring command
unsigned int dc_data_level: 1; // Indicates the level of DC line when transferring color data
unsigned int dc_param_level: 1; // Indicates the level of DC line when transferring parameters
unsigned int octal_mode: 1; // Indicates whether the transmitting is enabled with octal mode (8 data lines)
unsigned int quad_mode: 1; // Indicates whether the transmitting is enabled with quad mode (4 data lines)
} flags;
Expand Down Expand Up @@ -94,7 +96,9 @@ esp_err_t esp_lcd_new_panel_io_spi(esp_lcd_spi_bus_handle_t bus, const esp_lcd_p
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for D/C line failed");
}

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;
Expand Down Expand Up @@ -225,7 +229,7 @@ static esp_err_t panel_io_spi_tx_param(esp_lcd_panel_io_t *io, int lcd_cmd, cons

if (send_cmd) {
spi_lcd_prepare_cmd_buffer(spi_panel_io, &lcd_cmd);
lcd_trans->flags.dc_gpio_level = !spi_panel_io->flags.dc_data_level; // set D/C line to command mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_cmd_level; // set D/C level in command phase
lcd_trans->base.length = spi_panel_io->lcd_cmd_bits;
lcd_trans->base.tx_buffer = &lcd_cmd;
// command is short, using polling mode
Expand All @@ -235,7 +239,7 @@ static esp_err_t panel_io_spi_tx_param(esp_lcd_panel_io_t *io, int lcd_cmd, cons

if (param && param_size) {
spi_lcd_prepare_param_buffer(spi_panel_io, param, param_size);
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_data_level; // set D/C line to data mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_param_level; // set D/C level in param phase
lcd_trans->base.length = param_size * 8; // transaction length is in bits
lcd_trans->base.tx_buffer = param;
lcd_trans->base.flags &= ~SPI_TRANS_CS_KEEP_ACTIVE;
Expand Down Expand Up @@ -279,7 +283,7 @@ static esp_err_t panel_io_spi_rx_param(esp_lcd_panel_io_t *io, int lcd_cmd, void

if (send_cmd) {
spi_lcd_prepare_cmd_buffer(spi_panel_io, &lcd_cmd);
lcd_trans->flags.dc_gpio_level = !spi_panel_io->flags.dc_data_level; // set D/C line to command mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_cmd_level; // set D/C level in command phase
lcd_trans->base.length = spi_panel_io->lcd_cmd_bits;
lcd_trans->base.tx_buffer = &lcd_cmd;
// command is short, using polling mode
Expand All @@ -288,7 +292,7 @@ static esp_err_t panel_io_spi_rx_param(esp_lcd_panel_io_t *io, int lcd_cmd, void
}

if (param && param_size) {
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_data_level; // set D/C line to data mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_param_level; // set D/C level in param phase
lcd_trans->base.length = 0;
lcd_trans->base.tx_buffer = NULL;
lcd_trans->base.rxlength = param_size * 8; // Read length in bits
Expand Down Expand Up @@ -328,7 +332,7 @@ static esp_err_t panel_io_spi_tx_color(esp_lcd_panel_io_t *io, int lcd_cmd, cons

spi_lcd_prepare_cmd_buffer(spi_panel_io, &lcd_cmd);
lcd_trans->base.user = spi_panel_io;
lcd_trans->flags.dc_gpio_level = !spi_panel_io->flags.dc_data_level; // set D/C line to command mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_cmd_level; // set D/C level in command phase
lcd_trans->base.length = spi_panel_io->lcd_cmd_bits;
lcd_trans->base.tx_buffer = &lcd_cmd;
if(color && color_size) {
Expand Down Expand Up @@ -371,7 +375,7 @@ static esp_err_t panel_io_spi_tx_color(esp_lcd_panel_io_t *io, int lcd_cmd, cons
}

lcd_trans->base.user = spi_panel_io;
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_data_level; // set D/C line to data mode
lcd_trans->flags.dc_gpio_level = spi_panel_io->flags.dc_data_level; // set D/C level in data phase
lcd_trans->base.length = chunk_size * 8; // transaction length is in bits
lcd_trans->base.tx_buffer = color;
if (spi_panel_io->flags.octal_mode) {
Expand Down

0 comments on commit a66693c

Please sign in to comment.