hpm_display_common.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_DISPLAY_COMMON_H
  8. #define HPM_DISPLAY_COMMON_H
  9. #include "hpm_common.h"
  10. /**
  11. * @brief Display_common driver APIs
  12. * @defgroup Display_common_interface Display_common driver APIs
  13. * @ingroup io_interfaces
  14. * @{
  15. */
  16. /**
  17. * @brief display alphablend mode
  18. */
  19. typedef enum display_alphablend_mode {
  20. display_alphablend_mode_clear = 0,
  21. display_alphablend_mode_src = 1,
  22. display_alphablend_mode_dst = 2,
  23. display_alphablend_mode_src_over = 3,
  24. display_alphablend_mode_dst_over = 4,
  25. display_alphablend_mode_src_in = 5,
  26. display_alphablend_mode_dst_in = 6,
  27. display_alphablend_mode_src_out = 7,
  28. display_alphablend_mode_dst_out = 8,
  29. display_alphablend_mode_src_at_top = 9,
  30. display_alphablend_mode_dst_at_top = 10,
  31. display_alphablend_mode_xor = 11,
  32. display_alphablend_mode_plus = 12,
  33. display_alphablend_mode_modulate = 13,
  34. display_alphablend_mode_src_org = 14,
  35. display_alphablend_mode_dst_org = 15,
  36. } display_alphablend_mode_t;
  37. /**
  38. * @brief display pixel format
  39. */
  40. typedef enum display_pixel_format {
  41. display_pixel_format_argb8888,
  42. display_pixel_format_rgb565,
  43. display_pixel_format_rgb555,
  44. display_pixel_format_rgb444,
  45. display_pixel_format_gbr422,
  46. display_pixel_format_yuv422,
  47. display_pixel_format_ycbcr422,
  48. display_pixel_format_y8,
  49. display_pixel_format_raw8,
  50. } display_pixel_format_t;
  51. /**
  52. * @brief display data byte order
  53. */
  54. typedef enum display_byteorder {
  55. display_byteorder_a3a2a1a0 = 0,
  56. display_byteorder_a2a3a0a1 = 1,
  57. display_byteorder_a1a0a3a2 = 2,
  58. display_byteorder_a0a1a2a3 = 3,
  59. } display_byteorder_t;
  60. /**
  61. * @brief display yuv format
  62. */
  63. typedef enum display_yuv_format {
  64. display_yuv_mode_422_u1y1v1y2 = 0,
  65. display_yuv_mode_422_v1y1u1y2,
  66. display_yuv_mode_422_y1u1y2v1,
  67. display_yuv_mode_422_y1v1y2u1,
  68. } display_yuv_format_t;
  69. /**
  70. * @brief display data 32 bits argb
  71. */
  72. typedef union display_color_32b {
  73. uint32_t u;
  74. struct {
  75. uint8_t b;
  76. uint8_t g;
  77. uint8_t r;
  78. uint8_t alpha;
  79. };
  80. } display_color_32b_t;
  81. /**
  82. * @brief display data alpha value usage option
  83. */
  84. typedef enum display_alpha_op {
  85. display_alpha_op_invalid = 0,
  86. display_alpha_op_override = 1,
  87. display_alpha_op_scale = 2,
  88. } display_alpha_op_t;
  89. /**
  90. * @brief display data alphablend option
  91. */
  92. typedef struct dispaly_alphablend_option {
  93. uint8_t dst_alpha;
  94. uint8_t src_alpha;
  95. display_alpha_op_t dst_alpha_op;
  96. display_alpha_op_t src_alpha_op;
  97. display_alphablend_mode_t mode;
  98. } display_alphablend_option_t;
  99. /**
  100. * @brief display yuv to rgb format conversion coefficient
  101. */
  102. typedef struct dispaly_yuv2rgb_coef {
  103. uint16_t c0;
  104. uint16_t c1;
  105. uint16_t c2;
  106. uint16_t c3;
  107. uint16_t c4;
  108. uint16_t uv_offset;
  109. uint16_t y_offset;
  110. } display_yuv2rgb_coef_t;
  111. /**
  112. * @brief display yuv to rgb format conversion config
  113. */
  114. typedef struct display_yuv2rgb_config {
  115. bool enable;
  116. bool ycbcr_mode;
  117. display_yuv2rgb_coef_t yuv2rgb_coef;
  118. } display_yuv2rgb_config_t;
  119. /**
  120. * @brief display rgb to yuv format conversion config
  121. */
  122. typedef struct display_rgb2yuv_config {
  123. bool enable;
  124. bool ycbcr_mode;
  125. uint16_t c0;
  126. uint16_t c1;
  127. uint16_t c2;
  128. uint16_t c3;
  129. uint16_t c4;
  130. uint16_t c5;
  131. uint16_t c6;
  132. uint16_t c7;
  133. uint16_t c8;
  134. uint16_t uv_offset;
  135. uint16_t y_offset;
  136. } display_rgb2yuv_config_t;
  137. #ifdef __cplusplus
  138. extern "C" {
  139. #endif
  140. /**
  141. * @brief Display get pixel size in bit
  142. *
  143. * @param [in] format display_pixel_format_t
  144. *
  145. * @retval pixel size in bit
  146. */
  147. static inline
  148. uint8_t display_get_pixel_size_in_bit(display_pixel_format_t format)
  149. {
  150. switch (format) {
  151. case display_pixel_format_argb8888:
  152. return 32;
  153. case display_pixel_format_rgb565:
  154. return 16;
  155. case display_pixel_format_yuv422:
  156. return 16;
  157. case display_pixel_format_ycbcr422:
  158. return 16;
  159. case display_pixel_format_y8:
  160. return 8;
  161. case display_pixel_format_raw8:
  162. return 8;
  163. default:
  164. return 0;
  165. }
  166. }
  167. /**
  168. * @brief Check whether the pixel data is yuv format
  169. *
  170. * @param [in] format display_pixel_format_t
  171. *
  172. * @retval bool: true or false
  173. */
  174. static inline bool display_pixel_format_is_yuv_format(display_pixel_format_t format)
  175. {
  176. switch (format) {
  177. case display_pixel_format_yuv422:
  178. return true;
  179. case display_pixel_format_ycbcr422:
  180. return true;
  181. default:
  182. return false;
  183. }
  184. }
  185. /**
  186. * @brief Display get pixel size in byte
  187. *
  188. * @param [in] format display_pixel_format_t
  189. *
  190. * @retval pixel size in byte
  191. */
  192. static inline
  193. uint8_t display_get_pixel_size_in_byte(display_pixel_format_t format)
  194. {
  195. return display_get_pixel_size_in_bit(format) >> 3;
  196. }
  197. /**
  198. * @brief Display get pitch length in byte
  199. *
  200. * @param [in] format display_pixel_format_t
  201. * @param [in] width_in_pixel pixel width
  202. *
  203. * @retval pitch length in byte
  204. */
  205. static inline
  206. uint32_t display_get_pitch_length_in_byte(display_pixel_format_t format,
  207. uint32_t width_in_pixel)
  208. {
  209. return width_in_pixel * (display_get_pixel_size_in_bit(format) >> 3);
  210. }
  211. /**
  212. * @}
  213. *
  214. */
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* HPM_DISPLAY_COMMON_H */