esp_lcd_gc9503.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief ESP LCD: GC9503
  9. */
  10. #pragma once
  11. #include <stdint.h>
  12. #include <esp_lcd_panel_vendor.h>
  13. #include <esp_lcd_panel_rgb.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief LCD panel initialization commands.
  19. *
  20. */
  21. typedef struct {
  22. int cmd; /*<! The specific LCD command */
  23. const void *data; /*<! Buffer that holds the command specific data */
  24. size_t data_bytes; /*<! Size of `data` in memory, in bytes */
  25. unsigned int delay_ms; /*<! Delay in milliseconds after this command */
  26. } gc9503_lcd_init_cmd_t;
  27. /**
  28. * @brief LCD panel vendor configuration.
  29. *
  30. * @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
  31. *
  32. */
  33. typedef struct {
  34. const esp_lcd_rgb_panel_config_t *rgb_config; /*!< RGB panel configuration */
  35. const gc9503_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
  36. * The array should be declared as `static const` and positioned outside the function.
  37. * Please refer to `vendor_specific_init_default` in source file.
  38. */
  39. uint16_t init_cmds_size; /*<! Number of commands in above array */
  40. struct {
  41. unsigned int mirror_by_cmd: 1; /*<! The `mirror()` function will be implemented by LCD command if set to 1.
  42. * Otherwise, the function will be implemented by software.
  43. */
  44. unsigned int auto_del_panel_io: 1; /*<! Delete the panel IO instance automatically if set to 1. All `*_by_cmd` flags will be invalid.
  45. * If the panel IO pins are sharing other pins of the RGB interface to save GPIOs,
  46. * Please set it to 1 to release the panel IO and its pins (except CS signal).
  47. */
  48. } flags;
  49. } gc9503_vendor_config_t;
  50. /**
  51. * @brief Create LCD panel for model GC9503
  52. *
  53. * @note When `auto_del_panel_io` is set to 1, this function will first initialize the GC9503 with vendor specific initialization and then calls `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will only initialize RGB.
  54. * @note When `auto_del_panel_io` is set to 0, this function will only call `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will initialize both the GC9503 and RGB.
  55. * @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
  56. *
  57. * @param[in] io LCD panel IO handle
  58. * @param[in] panel_dev_config General panel device configuration (`vendor_config` and `rgb_config` are necessary)
  59. * @param[out] ret_panel Returned LCD panel handle
  60. * @return
  61. * - ESP_ERR_INVALID_ARG if parameter is invalid
  62. * - ESP_OK on success
  63. * - Otherwise on fail
  64. */
  65. esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
  66. esp_lcd_panel_handle_t *ret_panel);
  67. /**
  68. * @brief 3-wire SPI panel IO configuration structure
  69. *
  70. * @param[in] line_cfg SPI line configuration
  71. * @param[in] scl_active_edge SCL signal active edge, 0: rising edge, 1: falling edge
  72. *
  73. */
  74. #define GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_cfg, scl_active_edge) \
  75. { \
  76. .line_config = line_cfg, \
  77. .expect_clk_speed = PANEL_IO_3WIRE_SPI_CLK_MAX, \
  78. .spi_mode = scl_active_edge ? 1 : 0, \
  79. .lcd_cmd_bytes = 1, \
  80. .lcd_param_bytes = 1, \
  81. .flags = { \
  82. .use_dc_bit = 1, \
  83. .dc_zero_on_data = 0, \
  84. .lsb_first = 0, \
  85. .cs_high_active = 0, \
  86. .del_keep_cs_inactive = 1, \
  87. }, \
  88. }
  89. /**
  90. * @brief RGB timing structure
  91. *
  92. * @note refresh_rate = (pclk_hz * data_width) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
  93. * / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
  94. * / bits_per_pixel
  95. * .pclk_hz = 16 * 1000 * 1000, \
  96. .h_res = 384, \
  97. .v_res = 960, \
  98. .hsync_pulse_width = 24, \
  99. .hsync_back_porch = 20, \
  100. .hsync_front_porch = 40, \
  101. .vsync_pulse_width = 30, \
  102. .vsync_back_porch = 18, \
  103. .vsync_front_porch = 20, \
  104. .flags.pclk_active_neg = 0, \
  105. .hsync_pulse_width = 24, \
  106. .hsync_back_porch = 20, \
  107. .hsync_front_porch = 40, \
  108. .vsync_pulse_width = 30, \
  109. .vsync_back_porch = 18, \
  110. .vsync_front_porch = 20, \
  111. */
  112. #define GC9503_376_960_PANEL_60HZ_RGB_TIMING() \
  113. { \
  114. .pclk_hz = 16 * 1000 * 1000, \
  115. .h_res = 376, \
  116. .v_res = 960, \
  117. .hsync_pulse_width = 8, \
  118. .hsync_back_porch = 30, \
  119. .hsync_front_porch = 30, \
  120. .vsync_pulse_width = 8, \
  121. .vsync_back_porch = 16, \
  122. .vsync_front_porch = 16, \
  123. .flags = { \
  124. .hsync_idle_low = 0, \
  125. .vsync_idle_low = 0, \
  126. .de_idle_high = 0, \
  127. .pclk_active_neg = 0, \
  128. .pclk_idle_high = 0, \
  129. }, \
  130. }
  131. #ifdef __cplusplus
  132. }
  133. #endif