root / hw / pl110_template.h @ 6295e564
History | View | Annotate | Download (6.8 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | bdd5003a | pbrook | * Arm PrimeCell PL110 Color LCD Controller
|
3 | bdd5003a | pbrook | *
|
4 | bdd5003a | pbrook | * Copyright (c) 2005 CodeSourcery, LLC.
|
5 | bdd5003a | pbrook | * Written by Paul Brook
|
6 | bdd5003a | pbrook | *
|
7 | bdd5003a | pbrook | * This code is licenced under the GNU LGPL
|
8 | bdd5003a | pbrook | *
|
9 | bdd5003a | pbrook | * Framebuffer format conversion routines.
|
10 | bdd5003a | pbrook | */
|
11 | bdd5003a | pbrook | |
12 | bdd5003a | pbrook | #ifndef ORDER
|
13 | bdd5003a | pbrook | |
14 | bdd5003a | pbrook | #if BITS == 8 |
15 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(to++) = from
|
16 | bdd5003a | pbrook | #elif BITS == 15 || BITS == 16 |
17 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2; |
18 | 5fafdf24 | ths | #elif BITS == 24 |
19 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) \
|
20 | bdd5003a | pbrook | *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16 |
21 | bdd5003a | pbrook | #elif BITS == 32 |
22 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4; |
23 | bdd5003a | pbrook | #else
|
24 | bdd5003a | pbrook | #error unknown bit depth
|
25 | bdd5003a | pbrook | #endif
|
26 | bdd5003a | pbrook | |
27 | e9c05b42 | balrog | #undef RGB
|
28 | e9c05b42 | balrog | #define BORDER bgr
|
29 | bdd5003a | pbrook | #define ORDER 0 |
30 | bdd5003a | pbrook | #include "pl110_template.h" |
31 | bdd5003a | pbrook | #define ORDER 1 |
32 | bdd5003a | pbrook | #include "pl110_template.h" |
33 | bdd5003a | pbrook | #define ORDER 2 |
34 | bdd5003a | pbrook | #include "pl110_template.h" |
35 | e9c05b42 | balrog | #undef BORDER
|
36 | e9c05b42 | balrog | #define RGB
|
37 | e9c05b42 | balrog | #define BORDER rgb
|
38 | e9c05b42 | balrog | #define ORDER 0 |
39 | e9c05b42 | balrog | #include "pl110_template.h" |
40 | e9c05b42 | balrog | #define ORDER 1 |
41 | e9c05b42 | balrog | #include "pl110_template.h" |
42 | e9c05b42 | balrog | #define ORDER 2 |
43 | e9c05b42 | balrog | #include "pl110_template.h" |
44 | e9c05b42 | balrog | #undef BORDER
|
45 | bdd5003a | pbrook | |
46 | e9c05b42 | balrog | static drawfn glue(pl110_draw_fn_,BITS)[36] = |
47 | bdd5003a | pbrook | { |
48 | e9c05b42 | balrog | glue(pl110_draw_line1_lblp_bgr,BITS), |
49 | e9c05b42 | balrog | glue(pl110_draw_line2_lblp_bgr,BITS), |
50 | e9c05b42 | balrog | glue(pl110_draw_line4_lblp_bgr,BITS), |
51 | e9c05b42 | balrog | glue(pl110_draw_line8_lblp_bgr,BITS), |
52 | e9c05b42 | balrog | glue(pl110_draw_line16_lblp_bgr,BITS), |
53 | e9c05b42 | balrog | glue(pl110_draw_line32_lblp_bgr,BITS), |
54 | e9c05b42 | balrog | |
55 | e9c05b42 | balrog | glue(pl110_draw_line1_bbbp_bgr,BITS), |
56 | e9c05b42 | balrog | glue(pl110_draw_line2_bbbp_bgr,BITS), |
57 | e9c05b42 | balrog | glue(pl110_draw_line4_bbbp_bgr,BITS), |
58 | e9c05b42 | balrog | glue(pl110_draw_line8_bbbp_bgr,BITS), |
59 | e9c05b42 | balrog | glue(pl110_draw_line16_bbbp_bgr,BITS), |
60 | e9c05b42 | balrog | glue(pl110_draw_line32_bbbp_bgr,BITS), |
61 | e9c05b42 | balrog | |
62 | e9c05b42 | balrog | glue(pl110_draw_line1_lbbp_bgr,BITS), |
63 | e9c05b42 | balrog | glue(pl110_draw_line2_lbbp_bgr,BITS), |
64 | e9c05b42 | balrog | glue(pl110_draw_line4_lbbp_bgr,BITS), |
65 | e9c05b42 | balrog | glue(pl110_draw_line8_lbbp_bgr,BITS), |
66 | e9c05b42 | balrog | glue(pl110_draw_line16_lbbp_bgr,BITS), |
67 | e9c05b42 | balrog | glue(pl110_draw_line32_lbbp_bgr,BITS), |
68 | e9c05b42 | balrog | |
69 | e9c05b42 | balrog | glue(pl110_draw_line1_lblp_rgb,BITS), |
70 | e9c05b42 | balrog | glue(pl110_draw_line2_lblp_rgb,BITS), |
71 | e9c05b42 | balrog | glue(pl110_draw_line4_lblp_rgb,BITS), |
72 | e9c05b42 | balrog | glue(pl110_draw_line8_lblp_rgb,BITS), |
73 | e9c05b42 | balrog | glue(pl110_draw_line16_lblp_rgb,BITS), |
74 | e9c05b42 | balrog | glue(pl110_draw_line32_lblp_rgb,BITS), |
75 | e9c05b42 | balrog | |
76 | e9c05b42 | balrog | glue(pl110_draw_line1_bbbp_rgb,BITS), |
77 | e9c05b42 | balrog | glue(pl110_draw_line2_bbbp_rgb,BITS), |
78 | e9c05b42 | balrog | glue(pl110_draw_line4_bbbp_rgb,BITS), |
79 | e9c05b42 | balrog | glue(pl110_draw_line8_bbbp_rgb,BITS), |
80 | e9c05b42 | balrog | glue(pl110_draw_line16_bbbp_rgb,BITS), |
81 | e9c05b42 | balrog | glue(pl110_draw_line32_bbbp_rgb,BITS), |
82 | e9c05b42 | balrog | |
83 | e9c05b42 | balrog | glue(pl110_draw_line1_lbbp_rgb,BITS), |
84 | e9c05b42 | balrog | glue(pl110_draw_line2_lbbp_rgb,BITS), |
85 | e9c05b42 | balrog | glue(pl110_draw_line4_lbbp_rgb,BITS), |
86 | e9c05b42 | balrog | glue(pl110_draw_line8_lbbp_rgb,BITS), |
87 | e9c05b42 | balrog | glue(pl110_draw_line16_lbbp_rgb,BITS), |
88 | e9c05b42 | balrog | glue(pl110_draw_line32_lbbp_rgb,BITS), |
89 | bdd5003a | pbrook | }; |
90 | bdd5003a | pbrook | |
91 | bdd5003a | pbrook | #undef BITS
|
92 | bdd5003a | pbrook | #undef COPY_PIXEL
|
93 | bdd5003a | pbrook | |
94 | bdd5003a | pbrook | #else
|
95 | bdd5003a | pbrook | |
96 | bdd5003a | pbrook | #if ORDER == 0 |
97 | e9c05b42 | balrog | #define NAME glue(glue(lblp_, BORDER), BITS)
|
98 | bdd5003a | pbrook | #ifdef WORDS_BIGENDIAN
|
99 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
100 | bdd5003a | pbrook | #endif
|
101 | bdd5003a | pbrook | #elif ORDER == 1 |
102 | e9c05b42 | balrog | #define NAME glue(glue(bbbp_, BORDER), BITS)
|
103 | bdd5003a | pbrook | #ifndef WORDS_BIGENDIAN
|
104 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
105 | bdd5003a | pbrook | #endif
|
106 | bdd5003a | pbrook | #else
|
107 | bdd5003a | pbrook | #define SWAP_PIXELS 1 |
108 | e9c05b42 | balrog | #define NAME glue(glue(lbbp_, BORDER), BITS)
|
109 | bdd5003a | pbrook | #ifdef WORDS_BIGENDIAN
|
110 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
111 | bdd5003a | pbrook | #endif
|
112 | bdd5003a | pbrook | #endif
|
113 | bdd5003a | pbrook | |
114 | bdd5003a | pbrook | #define FN_2(x, y) FN(x, y) FN(x+1, y) |
115 | 1f9519c9 | pbrook | #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y) |
116 | bdd5003a | pbrook | #define FN_8(y) FN_4(0, y) FN_4(4, y) |
117 | bdd5003a | pbrook | |
118 | bdd5003a | pbrook | static void glue(pl110_draw_line1_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
119 | bdd5003a | pbrook | { |
120 | bdd5003a | pbrook | uint32_t data; |
121 | bdd5003a | pbrook | while (width > 0) { |
122 | bdd5003a | pbrook | data = *(uint32_t *)src; |
123 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
124 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]); |
125 | bdd5003a | pbrook | #else
|
126 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]); |
127 | bdd5003a | pbrook | #endif
|
128 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
129 | bdd5003a | pbrook | FN_8(24)
|
130 | bdd5003a | pbrook | FN_8(16)
|
131 | bdd5003a | pbrook | FN_8(8)
|
132 | bdd5003a | pbrook | FN_8(0)
|
133 | bdd5003a | pbrook | #else
|
134 | bdd5003a | pbrook | FN_8(0)
|
135 | bdd5003a | pbrook | FN_8(8)
|
136 | bdd5003a | pbrook | FN_8(16)
|
137 | bdd5003a | pbrook | FN_8(24)
|
138 | bdd5003a | pbrook | #endif
|
139 | bdd5003a | pbrook | #undef FN
|
140 | bdd5003a | pbrook | width -= 32;
|
141 | bdd5003a | pbrook | src += 4;
|
142 | bdd5003a | pbrook | } |
143 | bdd5003a | pbrook | } |
144 | bdd5003a | pbrook | |
145 | bdd5003a | pbrook | static void glue(pl110_draw_line2_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
146 | bdd5003a | pbrook | { |
147 | bdd5003a | pbrook | uint32_t data; |
148 | bdd5003a | pbrook | while (width > 0) { |
149 | bdd5003a | pbrook | data = *(uint32_t *)src; |
150 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
151 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]); |
152 | bdd5003a | pbrook | #else
|
153 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]); |
154 | bdd5003a | pbrook | #endif
|
155 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
156 | bdd5003a | pbrook | FN_4(0, 24) |
157 | bdd5003a | pbrook | FN_4(0, 16) |
158 | bdd5003a | pbrook | FN_4(0, 8) |
159 | bdd5003a | pbrook | FN_4(0, 0) |
160 | bdd5003a | pbrook | #else
|
161 | bdd5003a | pbrook | FN_4(0, 0) |
162 | bdd5003a | pbrook | FN_4(0, 8) |
163 | bdd5003a | pbrook | FN_4(0, 16) |
164 | bdd5003a | pbrook | FN_4(0, 24) |
165 | bdd5003a | pbrook | #endif
|
166 | bdd5003a | pbrook | #undef FN
|
167 | bdd5003a | pbrook | width -= 16;
|
168 | bdd5003a | pbrook | src += 4;
|
169 | bdd5003a | pbrook | } |
170 | bdd5003a | pbrook | } |
171 | bdd5003a | pbrook | |
172 | bdd5003a | pbrook | static void glue(pl110_draw_line4_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
173 | bdd5003a | pbrook | { |
174 | bdd5003a | pbrook | uint32_t data; |
175 | bdd5003a | pbrook | while (width > 0) { |
176 | bdd5003a | pbrook | data = *(uint32_t *)src; |
177 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
178 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]); |
179 | bdd5003a | pbrook | #else
|
180 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]); |
181 | bdd5003a | pbrook | #endif
|
182 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
183 | bdd5003a | pbrook | FN_2(0, 24) |
184 | bdd5003a | pbrook | FN_2(0, 16) |
185 | bdd5003a | pbrook | FN_2(0, 8) |
186 | bdd5003a | pbrook | FN_2(0, 0) |
187 | bdd5003a | pbrook | #else
|
188 | bdd5003a | pbrook | FN_2(0, 0) |
189 | bdd5003a | pbrook | FN_2(0, 8) |
190 | bdd5003a | pbrook | FN_2(0, 16) |
191 | bdd5003a | pbrook | FN_2(0, 24) |
192 | bdd5003a | pbrook | #endif
|
193 | bdd5003a | pbrook | #undef FN
|
194 | bdd5003a | pbrook | width -= 8;
|
195 | bdd5003a | pbrook | src += 4;
|
196 | bdd5003a | pbrook | } |
197 | bdd5003a | pbrook | } |
198 | bdd5003a | pbrook | |
199 | bdd5003a | pbrook | static void glue(pl110_draw_line8_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
200 | bdd5003a | pbrook | { |
201 | bdd5003a | pbrook | uint32_t data; |
202 | bdd5003a | pbrook | while (width > 0) { |
203 | bdd5003a | pbrook | data = *(uint32_t *)src; |
204 | bdd5003a | pbrook | #define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]); |
205 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
206 | bdd5003a | pbrook | FN(24)
|
207 | bdd5003a | pbrook | FN(16)
|
208 | bdd5003a | pbrook | FN(8)
|
209 | bdd5003a | pbrook | FN(0)
|
210 | bdd5003a | pbrook | #else
|
211 | bdd5003a | pbrook | FN(0)
|
212 | bdd5003a | pbrook | FN(8)
|
213 | bdd5003a | pbrook | FN(16)
|
214 | bdd5003a | pbrook | FN(24)
|
215 | bdd5003a | pbrook | #endif
|
216 | bdd5003a | pbrook | #undef FN
|
217 | bdd5003a | pbrook | width -= 4;
|
218 | bdd5003a | pbrook | src += 4;
|
219 | bdd5003a | pbrook | } |
220 | bdd5003a | pbrook | } |
221 | bdd5003a | pbrook | |
222 | bdd5003a | pbrook | static void glue(pl110_draw_line16_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
223 | bdd5003a | pbrook | { |
224 | bdd5003a | pbrook | uint32_t data; |
225 | bdd5003a | pbrook | unsigned int r, g, b; |
226 | bdd5003a | pbrook | while (width > 0) { |
227 | bdd5003a | pbrook | data = *(uint32_t *)src; |
228 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
229 | bdd5003a | pbrook | data = bswap32(data); |
230 | bdd5003a | pbrook | #endif
|
231 | e9c05b42 | balrog | #ifdef RGB
|
232 | e9c05b42 | balrog | #define LSB r
|
233 | e9c05b42 | balrog | #define MSB b
|
234 | e9c05b42 | balrog | #else
|
235 | e9c05b42 | balrog | #define LSB b
|
236 | e9c05b42 | balrog | #define MSB r
|
237 | e9c05b42 | balrog | #endif
|
238 | bdd5003a | pbrook | #if 0
|
239 | e9c05b42 | balrog | LSB = data & 0x1f;
|
240 | bdd5003a | pbrook | data >>= 5;
|
241 | bdd5003a | pbrook | g = data & 0x3f;
|
242 | bdd5003a | pbrook | data >>= 6;
|
243 | e9c05b42 | balrog | MSB = data & 0x1f;
|
244 | bdd5003a | pbrook | data >>= 5;
|
245 | bdd5003a | pbrook | #else
|
246 | e9c05b42 | balrog | LSB = (data & 0x1f) << 3; |
247 | bdd5003a | pbrook | data >>= 5;
|
248 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
249 | bdd5003a | pbrook | data >>= 6;
|
250 | e9c05b42 | balrog | MSB = (data & 0x1f) << 3; |
251 | bdd5003a | pbrook | data >>= 5;
|
252 | bdd5003a | pbrook | #endif
|
253 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
254 | e9c05b42 | balrog | LSB = (data & 0x1f) << 3; |
255 | bdd5003a | pbrook | data >>= 5;
|
256 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
257 | bdd5003a | pbrook | data >>= 6;
|
258 | e9c05b42 | balrog | MSB = (data & 0x1f) << 3; |
259 | bdd5003a | pbrook | data >>= 5;
|
260 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
261 | e9c05b42 | balrog | #undef MSB
|
262 | e9c05b42 | balrog | #undef LSB
|
263 | bdd5003a | pbrook | width -= 2;
|
264 | bdd5003a | pbrook | src += 4;
|
265 | bdd5003a | pbrook | } |
266 | bdd5003a | pbrook | } |
267 | bdd5003a | pbrook | |
268 | bdd5003a | pbrook | static void glue(pl110_draw_line32_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width) |
269 | bdd5003a | pbrook | { |
270 | bdd5003a | pbrook | uint32_t data; |
271 | bdd5003a | pbrook | unsigned int r, g, b; |
272 | bdd5003a | pbrook | while (width > 0) { |
273 | bdd5003a | pbrook | data = *(uint32_t *)src; |
274 | e9c05b42 | balrog | #ifdef RGB
|
275 | e9c05b42 | balrog | #define LSB r
|
276 | e9c05b42 | balrog | #define MSB b
|
277 | e9c05b42 | balrog | #else
|
278 | e9c05b42 | balrog | #define LSB b
|
279 | e9c05b42 | balrog | #define MSB r
|
280 | e9c05b42 | balrog | #endif
|
281 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
282 | e9c05b42 | balrog | LSB = data & 0xff;
|
283 | bdd5003a | pbrook | g = (data >> 8) & 0xff; |
284 | e9c05b42 | balrog | MSB = (data >> 16) & 0xff; |
285 | bdd5003a | pbrook | #else
|
286 | e9c05b42 | balrog | LSB = (data >> 24) & 0xff; |
287 | bdd5003a | pbrook | g = (data >> 16) & 0xff; |
288 | e9c05b42 | balrog | MSB = (data >> 8) & 0xff; |
289 | bdd5003a | pbrook | #endif
|
290 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
291 | e9c05b42 | balrog | #undef MSB
|
292 | e9c05b42 | balrog | #undef LSB
|
293 | bdd5003a | pbrook | width--; |
294 | bdd5003a | pbrook | src += 4;
|
295 | bdd5003a | pbrook | } |
296 | bdd5003a | pbrook | } |
297 | bdd5003a | pbrook | |
298 | bdd5003a | pbrook | #undef SWAP_PIXELS
|
299 | bdd5003a | pbrook | #undef NAME
|
300 | bdd5003a | pbrook | #undef SWAP_WORDS
|
301 | bdd5003a | pbrook | #undef ORDER
|
302 | bdd5003a | pbrook | |
303 | bdd5003a | pbrook | #endif |