Skip to content

Commit

Permalink
Merge branch 'feat/add_cs_timing_parameters_in_spi_lcd' into 'master'
Browse files Browse the repository at this point in the history
feat(spi_lcd): add spi cs timing parameters

Closes IDFGH-12003

See merge request espressif/esp-idf!31836
  • Loading branch information
Kainarx committed Jul 3, 2024
2 parents 6cfd596 + 8d09908 commit af9d107
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/esp_lcd/include/esp_lcd_io_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ typedef struct {
void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
int lcd_cmd_bits; /*!< Bit-width of LCD command */
int lcd_param_bits; /*!< Bit-width of LCD parameter */
uint8_t cs_ena_pretrans; /*!< Amount of SPI bit-cycles the cs should be activated before the transmission (0-16) */
uint8_t cs_ena_posttrans; /*!< Amount of SPI bit-cycles the cs should stay active after the transmission (0-16) */
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 */
Expand Down
4 changes: 4 additions & 0 deletions components/esp_lcd/spi/esp_lcd_panel_io_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef struct {
size_t num_trans_inflight; // Number of transactions that are undergoing (the descriptor not recycled yet)
int lcd_cmd_bits; // Bit width of LCD command
int lcd_param_bits; // Bit width of LCD parameter
uint8_t cs_ena_pretrans; // Amount of SPI bit-cycles the cs should be activated before the transmission (0-16)
uint8_t cs_ena_posttrans; // Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
struct {
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
Expand Down Expand Up @@ -82,6 +84,8 @@ esp_err_t esp_lcd_new_panel_io_spi(esp_lcd_spi_bus_handle_t bus, const esp_lcd_p
.queue_size = io_config->trans_queue_depth,
.pre_cb = lcd_spi_pre_trans_cb, // pre-transaction callback, mainly control DC gpio level
.post_cb = lcd_spi_post_trans_color_cb, // post-transaction, where we invoke user registered "on_color_trans_done()"
.cs_ena_pretrans = io_config->cs_ena_pretrans,
.cs_ena_posttrans = io_config->cs_ena_posttrans,
};
ret = spi_bus_add_device((spi_host_device_t)bus, &devcfg, &spi_panel_io->spi_dev);
ESP_GOTO_ON_ERROR(ret, err, TAG, "adding spi device to bus failed");
Expand Down
2 changes: 2 additions & 0 deletions docs/en/api-reference/peripherals/lcd/spi_lcd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SPI Interfaced LCD
- :cpp:member:`esp_lcd_panel_io_spi_config_t::spi_mode` sets the SPI mode. The LCD driver uses this mode to communicate with the LCD. For the meaning of the SPI mode, please refer to the :doc:`SPI Master API doc </api-reference/peripherals/spi_master>`.
- :cpp:member:`esp_lcd_panel_io_spi_config_t::lcd_cmd_bits` and :cpp:member:`esp_lcd_panel_io_spi_config_t::lcd_param_bits` set the bit width of the command and parameter that recognized by the LCD controller chip. This is chip specific, you should refer to your LCD spec in advance.
- :cpp:member:`esp_lcd_panel_io_spi_config_t::trans_queue_depth` sets the depth of the SPI transaction queue. A bigger value means more transactions can be queued up, but it also consumes more memory.
- :cpp:member:`esp_lcd_panel_io_spi_config_t::cs_ena_pretrans` sets the amount of SPI bit-cycles which the cs should be activated before the transmission (0-16).
- :cpp:member:`esp_lcd_panel_io_spi_config_t::cs_ena_posttrans` sets the amount of SPI bit-cycles which the cs should stay active after the transmission (0-16).

.. code-block:: c
Expand Down
2 changes: 2 additions & 0 deletions docs/zh_CN/api-reference/peripherals/lcd/spi_lcd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SPI 接口的 LCD
- :cpp:member:`esp_lcd_panel_io_spi_config_t::spi_mode` 设置 SPI 模式。LCD 驱动程序使用此模式与 LCD 通信。有关 SPI 模式的详细信息,请参阅 :doc:`SPI 主机 API 文档 </api-reference/peripherals/spi_master>`。
- :cpp:member:`esp_lcd_panel_io_spi_config_t::lcd_cmd_bits` 和 :cpp:member:`esp_lcd_panel_io_spi_config_t::lcd_param_bits` 分别设置 LCD 控制器芯片可识别的命令及参数的位宽。不同芯片对位宽要求不同,请提前参阅 LCD 规格书。
- :cpp:member:`esp_lcd_panel_io_spi_config_t::trans_queue_depth` 设置 SPI 传输队列的深度。该值越大,可以排队的传输越多,但消耗的内存也越多。
- :cpp:member:`esp_lcd_panel_io_spi_config_t::cs_ena_pretrans` 设置 SPI 在传输之前应激活 CS 信号线的 SPI 位周期数 (0-16)。
- :cpp:member:`esp_lcd_panel_io_spi_config_t::cs_ena_posttrans` 设置 SPI 在传输之后保持激活 CS 信号线的 SPI 位周期数 (0-16)。

.. code-block:: c
Expand Down

0 comments on commit af9d107

Please sign in to comment.