hpm_display_common.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_t;
  49. /**
  50. * @brief display data byte order
  51. */
  52. typedef enum display_byteorder {
  53. display_byteorder_a3a2a1a0 = 0,
  54. display_byteorder_a2a3a0a1 = 1,
  55. display_byteorder_a1a0a3a2 = 2,
  56. display_byteorder_a0a1a2a3 = 3,
  57. } display_byteorder_t;
  58. /**
  59. * @brief display yuv format
  60. */
  61. typedef enum display_yuv_format {
  62. display_yuv_mode_422_u1y1v1y2 = 0,
  63. display_yuv_mode_422_v1y1u1y2,
  64. display_yuv_mode_422_y1u1y2v1,
  65. display_yuv_mode_422_y1v1y2u1,
  66. } display_yuv_format_t;
  67. /**
  68. * @brief display data 32 bits argb
  69. */
  70. typedef union display_color_32b {
  71. uint32_t u;
  72. struct {
  73. uint8_t b;
  74. uint8_t g;
  75. uint8_t r;
  76. uint8_t alpha;
  77. };
  78. } display_color_32b_t;
  79. /**
  80. * @brief display data alpha value usage option
  81. */
  82. typedef enum display_alpha_op {
  83. display_alpha_op_invalid = 0,
  84. display_alpha_op_override = 1,
  85. display_alpha_op_scale = 2,
  86. } display_alpha_op_t;
  87. /**
  88. * @brief display data alphablend option
  89. */
  90. typedef struct dispaly_alphablend_option {
  91. uint8_t dst_alpha;
  92. uint8_t src_alpha;
  93. display_alpha_op_t dst_alpha_op;
  94. display_alpha_op_t src_alpha_op;
  95. display_alphablend_mode_t mode;
  96. } display_alphablend_option_t;
  97. /**
  98. * @brief display yuv to rgb format conversion coefficient
  99. */
  100. typedef struct dispaly_yuv2rgb_coef {
  101. uint16_t c0;
  102. uint16_t c1;
  103. uint16_t c2;
  104. uint16_t c3;
  105. uint16_t c4;
  106. uint16_t uv_offset;
  107. uint16_t y_offset;
  108. } display_yuv2rgb_coef_t;
  109. /**
  110. * @brief display yuv to rgb format conversion config
  111. */
  112. typedef struct display_yuv2rgb_config {
  113. bool enable;
  114. bool ycbcr_mode;
  115. display_yuv2rgb_coef_t yuv2rgb_coef;
  116. } display_yuv2rgb_config_t;
  117. /**
  118. * @brief display rgb to yuv format conversion config
  119. */
  120. typedef struct display_rgb2yuv_config {
  121. bool enable;
  122. bool ycbcr_mode;
  123. uint16_t c0;
  124. uint16_t c1;
  125. uint16_t c2;
  126. uint16_t c3;
  127. uint16_t c4;
  128. uint16_t c5;
  129. uint16_t c6;
  130. uint16_t c7;
  131. uint16_t c8;
  132. uint16_t uv_offset;
  133. uint16_t y_offset;
  134. } display_rgb2yuv_config_t;
  135. #ifdef __cplusplus
  136. extern "C" {
  137. #endif
  138. /**
  139. * @brief Display get pixel size in bit
  140. *
  141. * @param [in] format display_pixel_format_t
  142. *
  143. * @retval pixel size in bit
  144. */
  145. static inline
  146. uint8_t display_get_pixel_size_in_bit(display_pixel_format_t format)
  147. {
  148. switch(format) {
  149. case display_pixel_format_argb8888:
  150. return 32;
  151. case display_pixel_format_rgb565:
  152. return 16;
  153. case display_pixel_format_yuv422:
  154. return 16;
  155. case display_pixel_format_ycbcr422:
  156. return 16;
  157. default:
  158. return 0;
  159. }
  160. }
  161. /**
  162. * @brief Check whether the pixel data is yuv format
  163. *
  164. * @param [in] format display_pixel_format_t
  165. *
  166. * @retval bool: true or false
  167. */
  168. static inline bool display_pixel_format_is_yuv_format(display_pixel_format_t format)
  169. {
  170. switch(format) {
  171. case display_pixel_format_yuv422:
  172. return true;
  173. case display_pixel_format_ycbcr422:
  174. return true;
  175. default:
  176. return false;
  177. }
  178. }
  179. /**
  180. * @brief Display get pixel size in byte
  181. *
  182. * @param [in] format display_pixel_format_t
  183. *
  184. * @retval pixel size in byte
  185. */
  186. static inline
  187. uint8_t display_get_pixel_size_in_byte(display_pixel_format_t format)
  188. {
  189. return display_get_pixel_size_in_bit(format) >> 3;
  190. }
  191. /**
  192. * @brief Display get pitch length in byte
  193. *
  194. * @param [in] format display_pixel_format_t
  195. * @param [in] width_in_pixel pixel width
  196. *
  197. * @retval pitch length in byte
  198. */
  199. static inline
  200. uint32_t display_get_pitch_length_in_byte(display_pixel_format_t format,
  201. uint32_t width_in_pixel)
  202. {
  203. return width_in_pixel * (display_get_pixel_size_in_bit(format) >> 3);
  204. }
  205. /**
  206. * @}
  207. *
  208. */
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. #endif /* HPM_DISPLAY_COMMON_H */