hpm_panel.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef _HPM_PANEL_H
  8. #define _HPM_PANEL_H
  9. #include <stdint.h>
  10. #include <string.h>
  11. #include <stdbool.h>
  12. struct hpm_panel;
  13. typedef struct hpm_panel hpm_panel_t;
  14. typedef struct hpm_panel_timing {
  15. uint32_t pixel_clock_khz; /*!< pixel clocl,UINT: KHz */
  16. uint32_t hactive; /*!< Horizontal active video */
  17. uint32_t hfront_porch; /*!< Horizontal Front Porch */
  18. uint32_t hback_porch; /*!< Horizontal Back Porch */
  19. uint32_t hsync_len; /*!< Horizontal sync len */
  20. uint32_t vactive; /*!< Vertical active video */
  21. uint32_t vfront_porch; /*!< Vertical Front Porch */
  22. uint32_t vback_porch; /*!< Vertical Back Porch */
  23. uint32_t vsync_len; /*!< Vertical sync len */
  24. uint32_t hsync_pol :1; /*!< Horizontal Synchronization Signal Polarity, 0: High Active, 1: Low Active */
  25. uint32_t vsync_pol :1; /*!< Vertical Synchronization Signal Polarity, 0: High Active, 1: Low Active */
  26. uint32_t de_pol :1; /*!< Data Enable Signal Polarity, 0: High Active, 1: Low Active */
  27. uint32_t pixel_clk_pol :1; /*!< Pixel Clock Signal Polarity, 0: High Active, 1: Low Active */
  28. uint32_t pixel_data_pol :1;/*!< Pixel Data Signal Polarity, 0: High Active, 1: Low Active */
  29. } hpm_panel_timing_t;
  30. typedef enum hpm_panel_mipi_format {
  31. HPM_PANEL_MIPI_FORMAT_RGB888,
  32. HPM_PANEL_MIPI_FORMAT_RGB666,
  33. HPM_PANEL_MIPI_FORMAT_RGB666_PACKED,
  34. HPM_PANEL_MIPI_FORMAT_RGB565
  35. } hpm_panel_mipi_format;
  36. typedef struct hpm_panel_hw_interface {
  37. uint32_t lcdc_pixel_clk_khz;
  38. void (*set_reset_pin_level)(uint8_t level);
  39. void (*set_backlight)(uint16_t percent);
  40. void (*set_video_router)(void);
  41. union {
  42. struct {
  43. hpm_panel_mipi_format format;
  44. void *mipi_host_base;
  45. void *mipi_phy_base;
  46. } mipi;
  47. struct {
  48. uint32_t channel_di_index :8;
  49. uint32_t channel_index :8;
  50. void *lvb_base;
  51. } lvds;
  52. } video;
  53. } hpm_panel_hw_interface_t;
  54. typedef struct hpm_panel_funcs {
  55. void (*reset)(hpm_panel_t *panel);
  56. void (*init)(hpm_panel_t *panel);
  57. void (*power_on)(hpm_panel_t *panel);
  58. void (*power_off)(hpm_panel_t *panel);
  59. } hpm_panel_funcs_t;
  60. typedef enum hpm_panel_if_type {
  61. HPM_PANEL_IF_TYPE_RGB,
  62. HPM_PANEL_IF_TYPE_LVDS_SINGLE,
  63. HPM_PANEL_IF_TYPE_LVDS_SPLIT,
  64. HPM_PANEL_IF_TYPE_MIPI,
  65. } hpm_panel_if_type_t;
  66. typedef enum hpm_panel_state_power {
  67. HPM_PANEL_STATE_POWER_OFF,
  68. HPM_PANEL_STATE_POWER_ON
  69. } hpm_panel_power_state_t;
  70. typedef struct hpm_panel_state {
  71. uint8_t backlight_percent;
  72. uint8_t power_state;
  73. } hpm_panel_state_t;
  74. struct hpm_panel {
  75. const char *name;
  76. hpm_panel_if_type_t if_type;
  77. const hpm_panel_timing_t timing;
  78. hpm_panel_state_t state;
  79. hpm_panel_hw_interface_t hw_if;
  80. hpm_panel_funcs_t funcs;
  81. };
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /**
  86. * @brief Find default panel
  87. *
  88. * @return pointer of panel instance
  89. */
  90. hpm_panel_t *hpm_panel_find_device_default(void);
  91. /**
  92. * @brief Find panel for name
  93. *
  94. * @param [in] name of panel
  95. *
  96. * @return pointer of panel instance
  97. */
  98. hpm_panel_t *hpm_panel_find_device(const char *name);
  99. /**
  100. * @brief Get panel name
  101. *
  102. * @param panel pointer of panel instance
  103. *
  104. * @return panel name
  105. */
  106. const char *hpm_panel_get_name(hpm_panel_t *panel);
  107. /**
  108. * @brief Get panel timing
  109. *
  110. * @param panel pointer of panel instance
  111. *
  112. * @return pointer of timing
  113. */
  114. const hpm_panel_timing_t *hpm_panel_get_timing(hpm_panel_t *panel);
  115. /**
  116. * @brief Get panel interface type
  117. *
  118. * @param [in] panel pointer of panel instance
  119. *
  120. * @return panel interface type @ref hpm_panel_if_type_t
  121. */
  122. hpm_panel_if_type_t hpm_panel_get_if_type(hpm_panel_t *panel);
  123. /**
  124. * @brief Register platform level hardware interface
  125. *
  126. * @param [in] panel pointer of panel instance
  127. * @param [in] hw_if pointer of hardware interface
  128. */
  129. void hpm_panel_register_interface(hpm_panel_t *panel, hpm_panel_hw_interface_t *hw_if);
  130. /**
  131. * @brief Reset the panel
  132. *
  133. * @param [in] panel pointer of panel instance
  134. */
  135. void hpm_panel_reset(hpm_panel_t *panel);
  136. /**
  137. * @brief Initialize the panel
  138. *
  139. * @param [in] panel pointer of panel instance
  140. */
  141. void hpm_panel_init(hpm_panel_t *panel);
  142. /**
  143. * @brief Power on the panel
  144. *
  145. * @param [in] panel pointer of panel instance
  146. */
  147. void hpm_panel_power_on(hpm_panel_t *panel);
  148. /**
  149. * @brief Power off the panel
  150. *
  151. * @param [in] panel pointer of panel instance
  152. */
  153. void hpm_panel_power_off(hpm_panel_t *panel);
  154. /**
  155. * @brief Set backlight value
  156. *
  157. * @param [in] panel pointer of panel instance
  158. * @param [in] percent percent of backlight [0 - 100]
  159. */
  160. void hpm_panel_set_backlight(hpm_panel_t *panel, uint16_t percent);
  161. /**
  162. *
  163. * @brief Get backlight value
  164. *
  165. * @param [in] panel pointer of panel instance
  166. * @return percent of backlight [0 - 100]
  167. */
  168. uint8_t hpm_panel_get_backlight(hpm_panel_t *panel);
  169. /**
  170. * @brief Delay specified milliseconds
  171. *
  172. * @param [in] ms expected delay interval in milliseconds
  173. */
  174. void hpm_panel_delay_ms(uint32_t ms);
  175. /**
  176. * @brief Delay specified microseconds
  177. *
  178. * @param [in] us expected delay interval in microseconds
  179. */
  180. void hpm_panel_delay_us(uint32_t us);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif /* _HPM_PANEL_H */