hpm_display_common.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. typedef enum display_buf_format {
  138. display_buf_format_argb8888, /*!< memory layout in byte(low->high): b0[7:0], g0[7:0], r0[7:0], a0[7:0], b1[7:1], g1[7:1], r1[7:0], a1[7:0], ... */
  139. display_buf_format_bgra8888, /*!< memory layout in byte(low->high): a0[7:0], r0[7:0], g0[7:0], b0[7:0], a1[7:1], r1[7:1], g1[7:0], b1[7:0], ... */
  140. display_buf_format_rgb565, /*!< memory layout in byte(low->high): g0[2:0]:b0[4:0], r0[4:0]:g0[5:3], g1[2:0]:b1[4:0], r1[4:0]:g1[5:3], ... */
  141. display_buf_format_rgb565_swap, /*!< memory layout in byte(low->high): r0[4:0]:g0[5:3], g0[2:0]:b0[4:0], r2[4:0]:g2[5:3], g1[2:0]:b1[4:0], ... */
  142. display_buf_format_yuyv, /*!< memory layout in byte(low->high): y0, u0, y1, v0, y2, u2, y3, v2, ... */
  143. display_buf_format_uyvy, /*!< memory layout in byte(low->high): u0, y0, v0, y1, u2, y2, v2, y3, ... */
  144. display_buf_format_y8, /*!< memory layout in byte(low->high): y0, y1, y2, y3, y4, y5, ... */
  145. display_buf_format_max,
  146. } display_buf_format_t;
  147. typedef struct display_buf {
  148. void *buf; /*!< point pixel memory */
  149. uint16_t width; /*!< width in pixel */
  150. uint16_t height; /*!< height in pixel */
  151. uint32_t stride; /*!< stride each line, in byte */
  152. display_buf_format_t format;
  153. struct {
  154. display_alpha_op_t op;
  155. uint8_t val;
  156. } alpha;
  157. } display_buf_t;
  158. #ifdef __cplusplus
  159. extern "C" {
  160. #endif
  161. /**
  162. * @brief Display get pixel size in bit
  163. *
  164. * @param [in] format display_pixel_format_t
  165. *
  166. * @retval pixel size in bit
  167. */
  168. static inline
  169. uint8_t display_get_pixel_size_in_bit(display_pixel_format_t format)
  170. {
  171. switch (format) {
  172. case display_pixel_format_argb8888:
  173. return 32;
  174. case display_pixel_format_rgb565:
  175. return 16;
  176. case display_pixel_format_yuv422:
  177. return 16;
  178. case display_pixel_format_ycbcr422:
  179. return 16;
  180. case display_pixel_format_y8:
  181. return 8;
  182. case display_pixel_format_raw8:
  183. return 8;
  184. default:
  185. return 0;
  186. }
  187. }
  188. /**
  189. * @brief Check whether the pixel data is yuv format
  190. *
  191. * @param [in] format display_pixel_format_t
  192. *
  193. * @retval bool: true or false
  194. */
  195. static inline bool display_pixel_format_is_yuv_format(display_pixel_format_t format)
  196. {
  197. switch (format) {
  198. case display_pixel_format_yuv422:
  199. return true;
  200. case display_pixel_format_ycbcr422:
  201. return true;
  202. default:
  203. return false;
  204. }
  205. }
  206. /**
  207. * @brief Display get pixel size in byte
  208. *
  209. * @param [in] format display_pixel_format_t
  210. *
  211. * @retval pixel size in byte
  212. */
  213. static inline
  214. uint8_t display_get_pixel_size_in_byte(display_pixel_format_t format)
  215. {
  216. return display_get_pixel_size_in_bit(format) >> 3;
  217. }
  218. /**
  219. * @brief Display get pitch length in byte
  220. *
  221. * @param [in] format display_pixel_format_t
  222. * @param [in] width_in_pixel pixel width
  223. *
  224. * @retval pitch length in byte
  225. */
  226. static inline
  227. uint32_t display_get_pitch_length_in_byte(display_pixel_format_t format,
  228. uint32_t width_in_pixel)
  229. {
  230. return width_in_pixel * (display_get_pixel_size_in_bit(format) >> 3);
  231. }
  232. /**
  233. * @}
  234. *
  235. */
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* HPM_DISPLAY_COMMON_H */