esp_lcd_panel_io.h 12 KB

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