esp_lcd_panel_io.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdbool.h>
  8. #include "esp_err.h"
  9. #include "esp_lcd_types.h"
  10. #include "soc/soc_caps.h"
  11. #include "hal/lcd_types.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef void *esp_lcd_spi_bus_handle_t; /*!< Type of LCD SPI bus handle */
  16. typedef void *esp_lcd_i2c_bus_handle_t; /*!< Type of LCD I2C bus handle */
  17. typedef struct esp_lcd_i80_bus_t *esp_lcd_i80_bus_handle_t; /*!< Type of LCD intel 8080 bus handle */
  18. /**
  19. * @brief Transmit LCD command and corresponding parameters
  20. *
  21. * @note Commands sent by this function are short, so they are sent using polling transactions.
  22. * The function does not return before the command tranfer is completed.
  23. * If any queued transactions sent by `esp_lcd_panel_io_tx_color()` are still pending when this function is called,
  24. * this function will wait until they are finished and the queue is empty before sending the command(s).
  25. *
  26. * @param[in] io LCD panel IO handle, which is created by other factory API like `esp_lcd_new_panel_io_spi()`
  27. * @param[in] lcd_cmd The specific LCD command
  28. * @param[in] param Buffer that holds the command specific parameters, set to NULL if no parameter is needed for the command
  29. * @param[in] param_size Size of `param` in memory, in bytes, set to zero if no parameter is needed for the command
  30. * @return
  31. * - ESP_ERR_INVALID_ARG if parameter is invalid
  32. * - ESP_OK on success
  33. */
  34. esp_err_t esp_lcd_panel_io_tx_param(esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size);
  35. /**
  36. * @brief Transmit LCD RGB data
  37. *
  38. * @note This function will package the command and RGB data into a transaction, and push into a queue.
  39. * The real transmission is performed in the background (DMA+interrupt).
  40. * The caller should take care of the lifecycle of the `color` buffer.
  41. * Recycling of color buffer should be done in the callback `on_color_trans_done()`.
  42. *
  43. * @param[in] io LCD panel IO handle, which is created by factory API like `esp_lcd_new_panel_io_spi()`
  44. * @param[in] lcd_cmd The specific LCD command
  45. * @param[in] color Buffer that holds the RGB color data
  46. * @param[in] color_size Size of `color` in memory, in bytes
  47. * @return
  48. * - ESP_ERR_INVALID_ARG if parameter is invalid
  49. * - ESP_OK on success
  50. */
  51. esp_err_t esp_lcd_panel_io_tx_color(esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *color, size_t color_size);
  52. /**
  53. * @brief Destory LCD panel IO handle (deinitialize panel and free all corresponding resource)
  54. *
  55. * @param[in] io LCD panel IO handle, which is created by factory API like `esp_lcd_new_panel_io_spi()`
  56. * @return
  57. * - ESP_ERR_INVALID_ARG if parameter is invalid
  58. * - ESP_OK on success
  59. */
  60. esp_err_t esp_lcd_panel_io_del(esp_lcd_panel_io_handle_t io);
  61. /**
  62. * @brief Type of LCD panel IO event data
  63. */
  64. typedef struct {
  65. } esp_lcd_panel_io_event_data_t;
  66. /**
  67. * @brief Declare the prototype of the function that will be invoked when panel IO finishes transferring color data
  68. *
  69. * @param[in] panel_io LCD panel IO handle, which is created by factory API like `esp_lcd_new_panel_io_spi()`
  70. * @param[in] edata Panel IO event data, fed by driver
  71. * @param[in] user_ctx User data, passed from `esp_lcd_panel_io_xxx_config_t`
  72. * @return Whether a high priority task has been waken up by this function
  73. */
  74. typedef bool (*esp_lcd_panel_io_color_trans_done_cb_t)(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx);
  75. /**
  76. * @brief Panel IO configuration structure, for SPI interface
  77. */
  78. typedef struct {
  79. int cs_gpio_num; /*!< GPIO used for CS line */
  80. int dc_gpio_num; /*!< GPIO used to select the D/C line, set this to -1 if the D/C line not controlled by manually pulling high/low GPIO */
  81. int spi_mode; /*!< Traditional SPI mode (0~3) */
  82. unsigned int pclk_hz; /*!< Frequency of pixel clock */
  83. size_t trans_queue_depth; /*!< Size of internal transaction queue */
  84. esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data transfer has finished */
  85. void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
  86. int lcd_cmd_bits; /*!< Bit-width of LCD command */
  87. int lcd_param_bits; /*!< Bit-width of LCD parameter */
  88. struct {
  89. unsigned int dc_as_cmd_phase: 1; /*!< D/C line value is encoded into SPI transaction command phase */
  90. 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 */
  91. unsigned int octal_mode: 1; /*!< transmit with octal mode (8 data lines), this mode is used to simulate Intel 8080 timing */
  92. } flags;
  93. } esp_lcd_panel_io_spi_config_t;
  94. /**
  95. * @brief Create LCD panel IO handle, for SPI interface
  96. *
  97. * @param[in] bus SPI bus handle
  98. * @param[in] io_config IO configuration, for SPI interface
  99. * @param[out] ret_io Returned IO handle
  100. * @return
  101. * - ESP_ERR_INVALID_ARG if parameter is invalid
  102. * - ESP_ERR_NO_MEM if out of memory
  103. * - ESP_OK on success
  104. */
  105. esp_err_t esp_lcd_new_panel_io_spi(esp_lcd_spi_bus_handle_t bus, const esp_lcd_panel_io_spi_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
  106. typedef struct {
  107. uint32_t dev_addr; /*!< I2C device address */
  108. esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data transfer has finished */
  109. void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
  110. size_t control_phase_bytes; /*!< I2C LCD panel will encode control information (e.g. D/C seclection) into control phase, in several bytes */
  111. unsigned int dc_bit_offset; /*!< Offset of the D/C selection bit in control phase */
  112. int lcd_cmd_bits; /*!< Bit-width of LCD command */
  113. int lcd_param_bits; /*!< Bit-width of LCD parameter */
  114. struct {
  115. 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 */
  116. } flags;
  117. } esp_lcd_panel_io_i2c_config_t;
  118. /**
  119. * @brief Create LCD panel IO handle, for I2C interface
  120. *
  121. * @param[in] bus I2C bus handle
  122. * @param[in] io_config IO configuration, for I2C interface
  123. * @param[out] ret_io Returned IO handle
  124. * @return
  125. * - ESP_ERR_INVALID_ARG if parameter is invalid
  126. * - ESP_ERR_NO_MEM if out of memory
  127. * - ESP_OK on success
  128. */
  129. esp_err_t esp_lcd_new_panel_io_i2c(esp_lcd_i2c_bus_handle_t bus, const esp_lcd_panel_io_i2c_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
  130. #if SOC_LCD_I80_SUPPORTED
  131. /**
  132. * @brief LCD Intel 8080 bus configuration structure
  133. */
  134. typedef struct {
  135. int dc_gpio_num; /*!< GPIO used for D/C line */
  136. int wr_gpio_num; /*!< GPIO used for WR line */
  137. lcd_clock_source_t clk_src; /*!< Clock source for the I80 LCD peripheral */
  138. int data_gpio_nums[SOC_LCD_I80_BUS_WIDTH]; /*!< GPIOs used for data lines */
  139. size_t bus_width; /*!< Number of data lines, 8 or 16 */
  140. size_t max_transfer_bytes; /*!< Maximum transfer size, this determines the length of internal DMA link */
  141. } esp_lcd_i80_bus_config_t;
  142. /**
  143. * @brief Create Intel 8080 bus handle
  144. *
  145. * @param[in] bus_config Bus configuration
  146. * @param[out] ret_bus Returned bus handle
  147. * @return
  148. * - ESP_ERR_INVALID_ARG if parameter is invalid
  149. * - ESP_ERR_NO_MEM if out of memory
  150. * - ESP_ERR_NOT_FOUND if no free bus is available
  151. * - ESP_OK on success
  152. */
  153. esp_err_t esp_lcd_new_i80_bus(const esp_lcd_i80_bus_config_t *bus_config, esp_lcd_i80_bus_handle_t *ret_bus);
  154. /**
  155. * @brief Destory Intel 8080 bus handle
  156. *
  157. * @param[in] bus Intel 8080 bus handle, created by `esp_lcd_new_i80_bus()`
  158. * @return
  159. * - ESP_ERR_INVALID_ARG if parameter is invalid
  160. * - ESP_ERR_INVALID_STATE if there still be some device attached to the bus
  161. * - ESP_OK on success
  162. */
  163. esp_err_t esp_lcd_del_i80_bus(esp_lcd_i80_bus_handle_t bus);
  164. /**
  165. * @brief Panel IO configuration structure, for intel 8080 interface
  166. */
  167. typedef struct {
  168. int cs_gpio_num; /*!< GPIO used for CS line, set to -1 will declaim exclusively use of I80 bus */
  169. unsigned int pclk_hz; /*!< Frequency of pixel clock */
  170. size_t trans_queue_depth; /*!< Transaction queue size, larger queue, higher throughput */
  171. esp_lcd_panel_io_color_trans_done_cb_t on_color_trans_done; /*!< Callback invoked when color data was tranferred done */
  172. void *user_ctx; /*!< User private data, passed directly to on_color_trans_done's user_ctx */
  173. int lcd_cmd_bits; /*!< Bit-width of LCD command */
  174. int lcd_param_bits; /*!< Bit-width of LCD parameter */
  175. struct {
  176. unsigned int dc_idle_level: 1; /*!< Level of DC line in IDLE phase */
  177. unsigned int dc_cmd_level: 1; /*!< Level of DC line in CMD phase */
  178. unsigned int dc_dummy_level: 1; /*!< Level of DC line in DUMMY phase */
  179. unsigned int dc_data_level: 1; /*!< Level of DC line in DATA phase */
  180. } dc_levels; /*!< Each i80 device might have its own D/C control logic */
  181. struct {
  182. unsigned int cs_active_high: 1; /*!< If set, a high level of CS line will select the device, otherwise, CS line is low level active */
  183. unsigned int reverse_color_bits: 1; /*!< Reverse the data bits, D[N:0] -> D[0:N] */
  184. unsigned int swap_color_bytes: 1; /*!< Swap adjacent two color bytes */
  185. unsigned int pclk_active_neg: 1; /*!< The display will write data lines when there's a falling edge on WR signal (a.k.a the PCLK) */
  186. unsigned int pclk_idle_low: 1; /*!< The WR signal (a.k.a the PCLK) stays at low level in IDLE phase */
  187. } flags;
  188. } esp_lcd_panel_io_i80_config_t;
  189. /**
  190. * @brief Create LCD panel IO, for Intel 8080 interface
  191. *
  192. * @param[in] bus Intel 8080 bus handle, created by `esp_lcd_new_i80_bus()`
  193. * @param[in] io_config IO configuration, for i80 interface
  194. * @param[out] ret_io Returned panel IO handle
  195. * @return
  196. * - ESP_ERR_INVALID_ARG if parameter is invalid
  197. * - ESP_ERR_NOT_SUPPORTED if some configuration can't be satisfied, e.g. pixel clock out of the range
  198. * - ESP_ERR_NO_MEM if out of memory
  199. * - ESP_OK on success
  200. */
  201. esp_err_t esp_lcd_new_panel_io_i80(esp_lcd_i80_bus_handle_t bus, const esp_lcd_panel_io_i80_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
  202. #endif // SOC_LCD_I80_SUPPORTED
  203. #ifdef __cplusplus
  204. }
  205. #endif