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