esp_lcd_panel_rgb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 <stdint.h>
  8. #include <stdbool.h>
  9. #include "esp_err.h"
  10. #include "esp_lcd_types.h"
  11. #include "soc/soc_caps.h"
  12. #include "hal/lcd_types.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #if SOC_LCD_RGB_SUPPORTED
  17. /**
  18. * @brief LCD RGB timing structure
  19. * @verbatim
  20. * Total Width
  21. * <--------------------------------------------------->
  22. * HSYNC width HBP Active Width HFP
  23. * <---><--><--------------------------------------><--->
  24. * ____ ____|_______________________________________|____|
  25. * |___| | | |
  26. * | | |
  27. * __| | | |
  28. * /|\ /|\ | | | |
  29. * | VSYNC| | | | |
  30. * |Width\|/ |__ | | |
  31. * | /|\ | | | |
  32. * | VBP | | | | |
  33. * | \|/_____|_________|_______________________________________| |
  34. * | /|\ | | / / / / / / / / / / / / / / / / / / / | |
  35. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  36. * Total | | | |/ / / / / / / / / / / / / / / / / / / /| |
  37. * Height | | | |/ / / / / / / / / / / / / / / / / / / /| |
  38. * |Active| | |/ / / / / / / / / / / / / / / / / / / /| |
  39. * |Heigh | | |/ / / / / / Active Display Area / / / /| |
  40. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  41. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  42. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  43. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  44. * | | | |/ / / / / / / / / / / / / / / / / / / /| |
  45. * | \|/_____|_________|_______________________________________| |
  46. * | /|\ | |
  47. * | VFP | | |
  48. * \|/ \|/_____|______________________________________________________|
  49. * @endverbatim
  50. */
  51. typedef struct {
  52. uint32_t pclk_hz; /*!< Frequency of pixel clock */
  53. uint32_t h_res; /*!< Horizontal resolution, i.e. the number of pixels in a line */
  54. uint32_t v_res; /*!< Vertical resolution, i.e. the number of lines in the frame */
  55. uint32_t hsync_pulse_width; /*!< Horizontal sync width, unit: PCLK period */
  56. uint32_t hsync_back_porch; /*!< Horizontal back porch, number of PCLK between hsync and start of line active data */
  57. uint32_t hsync_front_porch; /*!< Horizontal front porch, number of PCLK between the end of active data and the next hsync */
  58. uint32_t vsync_pulse_width; /*!< Vertical sync width, unit: number of lines */
  59. uint32_t vsync_back_porch; /*!< Vertical back porch, number of invalid lines between vsync and start of frame */
  60. uint32_t vsync_front_porch; /*!< Vertical front porch, number of invalid lines between the end of frame and the next vsync */
  61. struct {
  62. uint32_t hsync_idle_low: 1; /*!< The hsync signal is low in IDLE state */
  63. uint32_t vsync_idle_low: 1; /*!< The vsync signal is low in IDLE state */
  64. uint32_t de_idle_high: 1; /*!< The de signal is high in IDLE state */
  65. uint32_t pclk_active_neg: 1; /*!< Whether the display data is clocked out on the falling edge of PCLK */
  66. uint32_t pclk_idle_high: 1; /*!< The PCLK stays at high level in IDLE phase */
  67. } flags; /*!< LCD RGB timing flags */
  68. } esp_lcd_rgb_timing_t;
  69. /**
  70. * @brief Type of RGB LCD panel event data
  71. */
  72. typedef struct {
  73. } esp_lcd_rgb_panel_event_data_t;
  74. /**
  75. * @brief RGB LCD VSYNC event callback prototype
  76. *
  77. * @param[in] panel LCD panel handle, returned from `esp_lcd_new_rgb_panel()`
  78. * @param[in] edata Panel event data, fed by driver
  79. * @param[in] user_ctx User data, passed from `esp_lcd_rgb_panel_register_event_callbacks()`
  80. * @return Whether a high priority task has been waken up by this function
  81. */
  82. typedef bool (*esp_lcd_rgb_panel_vsync_cb_t)(esp_lcd_panel_handle_t panel, const esp_lcd_rgb_panel_event_data_t *edata, void *user_ctx);
  83. /**
  84. * @brief Prototype for function to re-fill a bounce buffer, rather than copying from the frame buffer
  85. *
  86. * @param[in] bounce_buf Bounce buffer to write data into
  87. * @param[in] pos_px How many pixels already were sent to the display in this frame, in other words,
  88. * at what pixel the routine should start putting data into bounce_buf
  89. * @param[in] len_bytes Length, in bytes, of the bounce buffer. Routine should fill this length fully.
  90. * @param[in] user_ctx Opaque pointer that was passed from `esp_lcd_rgb_panel_register_event_callbacks()`
  91. * @return Whether a high priority task has been waken up by this function
  92. */
  93. typedef bool (*esp_lcd_rgb_panel_bounce_buf_fill_cb_t)(esp_lcd_panel_handle_t panel, void *bounce_buf, int pos_px, int len_bytes, void *user_ctx);
  94. /**
  95. * @brief Group of supported RGB LCD panel callbacks
  96. * @note The callbacks are all running under ISR environment
  97. * @note When CONFIG_LCD_RGB_ISR_IRAM_SAFE is enabled, the callback itself and functions called by it should be placed in IRAM.
  98. */
  99. typedef struct {
  100. esp_lcd_rgb_panel_vsync_cb_t on_vsync; /*!< VSYNC event callback */
  101. esp_lcd_rgb_panel_bounce_buf_fill_cb_t on_bounce_empty; /*!< Bounce buffer empty callback. */
  102. } esp_lcd_rgb_panel_event_callbacks_t;
  103. /**
  104. * @brief LCD RGB panel configuration structure
  105. */
  106. typedef struct {
  107. lcd_clock_source_t clk_src; /*!< Clock source for the RGB LCD peripheral */
  108. esp_lcd_rgb_timing_t timings; /*!< RGB timing parameters, including the screen resolution */
  109. size_t data_width; /*!< Number of data lines */
  110. size_t bits_per_pixel; /*!< Color depth, in bpp, specially, if set to zero, it will default to `data_width`.
  111. When using a Serial RGB interface, this value could be different from `data_width` */
  112. size_t bounce_buffer_size_px; /*!< If it's non-zero, the driver allocates two DRAM bounce buffers for DMA use.
  113. DMA fetching from DRAM bounce buffer is much faster than PSRAM frame buffer. */
  114. size_t sram_trans_align; /*!< Alignment of buffers (frame buffer or bounce buffer) that allocated in SRAM */
  115. size_t psram_trans_align; /*!< Alignment of buffers (frame buffer) that allocated in PSRAM */
  116. int hsync_gpio_num; /*!< GPIO used for HSYNC signal */
  117. int vsync_gpio_num; /*!< GPIO used for VSYNC signal */
  118. int de_gpio_num; /*!< GPIO used for DE signal, set to -1 if it's not used */
  119. int pclk_gpio_num; /*!< GPIO used for PCLK signal */
  120. int disp_gpio_num; /*!< GPIO used for display control signal, set to -1 if it's not used */
  121. int data_gpio_nums[SOC_LCD_RGB_DATA_WIDTH]; /*!< GPIOs used for data lines */
  122. struct {
  123. uint32_t disp_active_low: 1; /*!< If this flag is enabled, a low level of display control signal can turn the screen on; vice versa */
  124. uint32_t refresh_on_demand: 1; /*!< If this flag is enabled, the host only refresh the frame buffer when `esp_lcd_panel_draw_bitmap` is called.
  125. This is useful when the LCD screen has a GRAM and can refresh the LCD by itself. */
  126. uint32_t fb_in_psram: 1; /*!< If this flag is enabled, the frame buffer will be allocated from PSRAM, preferentially */
  127. uint32_t double_fb: 1; /*!< If this flag is enabled, the driver will allocate two screen sized frame buffer */
  128. uint32_t no_fb: 1; /*!< If this flag is enabled, the driver won't allocate frame buffer.
  129. Instead, user should fill in the bounce buffer manually in the `on_bounce_empty` callback */
  130. uint32_t bb_invalidate_cache: 1; /*!< If this flag is enabled, in bounce back mode we'll do a cache invalidate on the read data, freeing the cache.
  131. Can be dangerous if data is written from other core(s). */
  132. } flags; /*!< LCD RGB panel configuration flags */
  133. } esp_lcd_rgb_panel_config_t;
  134. /**
  135. * @brief Create RGB LCD panel
  136. *
  137. * @param[in] rgb_panel_config RGB panel configuration
  138. * @param[out] ret_panel Returned LCD panel handle
  139. * @return
  140. * - ESP_ERR_INVALID_ARG: Create RGB LCD panel failed because of invalid argument
  141. * - ESP_ERR_NO_MEM: Create RGB LCD panel failed because of out of memory
  142. * - ESP_ERR_NOT_FOUND: Create RGB LCD panel failed because some mandatory hardware resources are not found
  143. * - ESP_OK: Create RGB LCD panel successfully
  144. */
  145. esp_err_t esp_lcd_new_rgb_panel(const esp_lcd_rgb_panel_config_t *rgb_panel_config, esp_lcd_panel_handle_t *ret_panel);
  146. /**
  147. * @brief Register LCD RGB panel event callbacks
  148. *
  149. * @param[in] panel LCD panel handle, returned from `esp_lcd_new_rgb_panel()`
  150. * @param[in] callbacks Group of callback functions
  151. * @param[in] user_ctx User data, which will be passed to the callback functions directly
  152. * @return
  153. * - ESP_OK: Set event callbacks successfully
  154. * - ESP_ERR_INVALID_ARG: Set event callbacks failed because of invalid argument
  155. * - ESP_FAIL: Set event callbacks failed because of other error
  156. */
  157. esp_err_t esp_lcd_rgb_panel_register_event_callbacks(esp_lcd_panel_handle_t panel, const esp_lcd_rgb_panel_event_callbacks_t *callbacks, void *user_ctx);
  158. /**
  159. * @brief Set frequency of PCLK for RGB LCD panel
  160. *
  161. * @note The PCLK frequency is set in the `esp_lcd_rgb_timing_t` and gets configured during LCD panel initialization.
  162. * Usually you don't need to call this function to set the PCLK again, but in some cases, you might want to change the PCLK frequency.
  163. * e.g. slow down the PCLK frequency to reduce power consumption or to reduce the memory throughput during OTA.
  164. * @note This function doesn't cause the hardware to update the PCLK immediately but to record the new frequency and set a flag internally.
  165. * Only in the next VSYNC event handler, will the driver attempt to update the PCLK frequency.
  166. *
  167. * @param[in] panel LCD panel handle, returned from `esp_lcd_new_rgb_panel()`
  168. * @param[in] freq_hz Frequency of pixel clock, in Hz
  169. * @return
  170. * - ESP_ERR_INVALID_ARG: Set PCLK frequency failed because of invalid argument
  171. * - ESP_OK: Set PCLK frequency successfully
  172. */
  173. esp_err_t esp_lcd_rgb_panel_set_pclk(esp_lcd_panel_handle_t panel, uint32_t freq_hz);
  174. /**
  175. * @brief Get the address of the frame buffer(s) that allocated by the driver
  176. *
  177. * @param[in] panel LCD panel handle, returned from `esp_lcd_new_rgb_panel()`
  178. * @param[in] fb_num Number of frame buffer(s) to get. This value must be the same as the number of the following parameters.
  179. * @param[out] fb0 Returned address of the frame buffer 0
  180. * @param[out] ... List of other frame buffer addresses
  181. * @return
  182. * - ESP_ERR_INVALID_ARG: Get frame buffer address failed because of invalid argument
  183. * - ESP_OK: Get frame buffer address successfully
  184. */
  185. esp_err_t esp_lcd_rgb_panel_get_frame_buffer(esp_lcd_panel_handle_t panel, uint32_t fb_num, void **fb0, ...);
  186. /**
  187. * @brief Manually trigger once transmission of the frame buffer to the LCD panel
  188. *
  189. * @note This function should only be called when the RGB panel is working under the `refresh_on_demand` mode.
  190. *
  191. * @param[in] panel LCD panel handle, returned from `esp_lcd_new_rgb_panel()`
  192. * @return
  193. * - ESP_ERR_INVALID_ARG: Start a refresh failed because of invalid argument
  194. * - ESP_ERR_INVALID_STATE: Start a refresh failed because the LCD panel is not created with the `refresh_on_demand` flag enabled.
  195. * - ESP_OK: Start a refresh successfully
  196. */
  197. esp_err_t esp_lcd_rgb_panel_refresh(esp_lcd_panel_handle_t panel);
  198. #endif // SOC_LCD_RGB_SUPPORTED
  199. #ifdef __cplusplus
  200. }
  201. #endif