diff options
Diffstat (limited to 'firmware/target/arm/ipod/video')
-rw-r--r-- | firmware/target/arm/ipod/video/lcd-as-video.S | 237 | ||||
-rw-r--r-- | firmware/target/arm/ipod/video/lcd-video.c | 47 |
2 files changed, 284 insertions, 0 deletions
diff --git a/firmware/target/arm/ipod/video/lcd-as-video.S b/firmware/target/arm/ipod/video/lcd-as-video.S index 1b982c75ce..47155b8c75 100644 --- a/firmware/target/arm/ipod/video/lcd-as-video.S +++ b/firmware/target/arm/ipod/video/lcd-as-video.S | |||
@@ -63,3 +63,240 @@ lcd_write_data: /* r1 = pixel count, must be even */ | |||
63 | strne r3, [lr] | 63 | strne r3, [lr] |
64 | 64 | ||
65 | ldmpc regs=r4 | 65 | ldmpc regs=r4 |
66 | |||
67 | /**************************************************************************** | ||
68 | * extern void lcd_write_yuv420_lines(unsigned char const * const src[3], | ||
69 | * unsigned bcmaddr | ||
70 | * int width, | ||
71 | * int stride); | ||
72 | * | ||
73 | * Conversion from Motion JPEG and MPEG Y'PbPr to RGB is: | ||
74 | * |R| |1.164 0.000 1.596| |Y' - 16| | ||
75 | * |G| = |1.164 -0.391 -0.813| |Pb - 128| | ||
76 | * |B| |1.164 2.018 0.000| |Pr - 128| | ||
77 | * | ||
78 | * Scaled, normalized, rounded and tweaked to yield RGB 565: | ||
79 | * |R| |74 0 101| |Y' - 16| >> 9 | ||
80 | * |G| = |74 -24 -51| |Cb - 128| >> 8 | ||
81 | * |B| |74 128 0| |Cr - 128| >> 9 | ||
82 | * | ||
83 | * Converts two lines from YUV to RGB565 and writes to BCM at once. First loop | ||
84 | * loads Cb/Cr, calculates the chroma offset and saves them to buffer. Within | ||
85 | * the second loop these chroma offset are reloaded from buffer. | ||
86 | * Within each loop two pixels are calculated and written to BCM. Before each | ||
87 | * loop the desired destination address is transmitted to BCM. | ||
88 | */ | ||
89 | .align 2 | ||
90 | .global lcd_write_yuv420_lines | ||
91 | .type lcd_write_yuv420_lines, %function | ||
92 | lcd_write_yuv420_lines: | ||
93 | /* r0 = src = yuv_src */ | ||
94 | /* r1 = dst = bcmaddr */ | ||
95 | /* r2 = width */ | ||
96 | /* r3 = stride */ | ||
97 | stmfd sp!, { r4-r10, lr } /* save non-scratch */ | ||
98 | ldmia r0, { r9, r10, r12 } /* r9 = yuv_src[0] = Y'_p */ | ||
99 | /* r10 = yuv_src[1] = Cb_p */ | ||
100 | /* r12 = yuv_src[2] = Cr_p */ | ||
101 | add r3, r9, r3 /* r3 = &ysrc[stride] */ | ||
102 | add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */ | ||
103 | mov r4, r4, asl #2 /* use words for str/ldm possibility */ | ||
104 | add r4, r4, #19 /* plus room for 4 additional words, */ | ||
105 | bic r4, r4, #3 /* rounded up to multiples of 4 byte */ | ||
106 | sub sp, sp, r4 /* and allocate on stack */ | ||
107 | stmia sp, {r1-r4} /* bcmaddr, width, &ysrc[stride], stack_alloc */ | ||
108 | |||
109 | mov r7, r2 /* r7 = loop count */ | ||
110 | add r8, sp, #16 /* chroma buffer */ | ||
111 | mov lr, #0x30000000 /* LCD data port */ | ||
112 | |||
113 | /* The following writes dest address to BCM and waits for write ready */ | ||
114 | orr r2, lr, #0x00010000 /* r2 = BCM_WR_ADDR32 */ | ||
115 | orr r6, lr, #0x00030000 /* r6 = BCM_CONTROL */ | ||
116 | str r1, [r2] /* BCM_WR_ADDR32 = bcmaddr */ | ||
117 | .busy_1: | ||
118 | ldrh r1, [r6] /* while (!(BCM_CONTROL & 0x2)) */ | ||
119 | tst r1, #0x2 | ||
120 | beq .busy_1 | ||
121 | |||
122 | /* 1st loop start */ | ||
123 | 10: /* loop start */ | ||
124 | |||
125 | ldrb r0, [r10], #1 /* r0 = *usrc++ = *Cb_p++ */ | ||
126 | ldrb r1, [r12], #1 /* r1 = *vsrc++ = *Cr_p++ */ | ||
127 | |||
128 | sub r0, r0, #128 /* r0 = Cb-128 */ | ||
129 | sub r1, r1, #128 /* r1 = Cr-128 */ | ||
130 | |||
131 | add r2, r1, r1, asl #1 /* r2 = Cr*51 + Cb*24 */ | ||
132 | add r2, r2, r2, asl #4 | ||
133 | add r2, r2, r0, asl #3 | ||
134 | add r2, r2, r0, asl #4 | ||
135 | |||
136 | add r4, r1, r1, asl #2 /* r1 = Cr*101 */ | ||
137 | add r4, r4, r1, asl #5 | ||
138 | add r1, r4, r1, asl #6 | ||
139 | |||
140 | add r1, r1, #256 /* r1 = rv = (r1 + 256) >> 9 */ | ||
141 | mov r1, r1, asr #9 | ||
142 | rsb r2, r2, #128 /* r2 = guv = (-r2 + 128) >> 8 */ | ||
143 | mov r2, r2, asr #8 | ||
144 | add r0, r0, #2 /* r0 = bu = (Cb*128 + 256) >> 9 */ | ||
145 | mov r0, r0, asr #2 | ||
146 | stmia r8!, {r0-r2} /* store r0, r1 and r2 to chroma buffer */ | ||
147 | |||
148 | /* 1st loop, first pixel */ | ||
149 | ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ | ||
150 | sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ | ||
151 | add r3, r5, r5, asl #2 | ||
152 | add r5, r3, r5, asl #5 | ||
153 | |||
154 | add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ | ||
155 | add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ | ||
156 | add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */ | ||
157 | |||
158 | orr r5, r6, r4 /* check if clamping is needed... */ | ||
159 | orr r5, r5, r3, asr #1 /* ...at all */ | ||
160 | cmp r5, #31 | ||
161 | bls 15f /* -> no clamp */ | ||
162 | cmp r6, #31 /* clamp r */ | ||
163 | mvnhi r6, r6, asr #31 | ||
164 | andhi r6, r6, #31 | ||
165 | cmp r3, #63 /* clamp g */ | ||
166 | mvnhi r3, r3, asr #31 | ||
167 | andhi r3, r3, #63 | ||
168 | cmp r4, #31 /* clamp b */ | ||
169 | mvnhi r4, r4, asr #31 | ||
170 | andhi r4, r4, #31 | ||
171 | 15: /* no clamp */ | ||
172 | |||
173 | /* calculate pixel_1 and save to r5 for later pixel packing */ | ||
174 | orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */ | ||
175 | orr r5, r4, r6, lsl #11 /* r5 = pixel_1 */ | ||
176 | |||
177 | /* 1st loop, second pixel */ | ||
178 | ldrb r4, [r9], #1 /* r4 = *ysrc++ = *Y'_p++ */ | ||
179 | sub r4, r4, #16 /* r4 = (Y'-16) * 74 */ | ||
180 | add r3, r4, r4, asl #2 | ||
181 | add r4, r3, r4, asl #5 | ||
182 | |||
183 | add r6, r1, r4, asr #8 /* r6 = r = (Y >> 9) + rv */ | ||
184 | add r3, r2, r4, asr #7 /* r3 = g = (Y >> 8) + guv */ | ||
185 | add r4, r0, r4, asr #8 /* r4 = b = (Y >> 9) + bu */ | ||
186 | |||
187 | orr r0, r6, r4 /* check if clamping is needed... */ | ||
188 | orr r0, r0, r3, asr #1 /* ...at all */ | ||
189 | cmp r0, #31 | ||
190 | bls 15f /* -> no clamp */ | ||
191 | cmp r6, #31 /* clamp r */ | ||
192 | mvnhi r6, r6, asr #31 | ||
193 | andhi r6, r6, #31 | ||
194 | cmp r3, #63 /* clamp g */ | ||
195 | mvnhi r3, r3, asr #31 | ||
196 | andhi r3, r3, #63 | ||
197 | cmp r4, #31 /* clamp b */ | ||
198 | mvnhi r4, r4, asr #31 | ||
199 | andhi r4, r4, #31 | ||
200 | 15: /* no clamp */ | ||
201 | |||
202 | /* calculate pixel_2 and pack with pixel_1 before writing */ | ||
203 | orr r4, r4, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ | ||
204 | orr r4, r4, r6, lsl #11 /* r4 = pixel_2 */ | ||
205 | orr r4, r5, r4, lsl #16 /* r4 = pixel_2<<16 | pixel_1 */ | ||
206 | str r4, [lr] /* write packed pixels */ | ||
207 | |||
208 | subs r7, r7, #2 /* check for loop end */ | ||
209 | bgt 10b /* back to beginning */ | ||
210 | /* 1st loop end */ | ||
211 | |||
212 | /* Reload several registers for pointer rewinding for next loop */ | ||
213 | add r8, sp, #16 /* chroma buffer */ | ||
214 | ldmia sp, { r1, r7, r9} /* r1 = bcmaddr */ | ||
215 | /* r7 = loop count */ | ||
216 | /* r9 = &ysrc[stride] */ | ||
217 | |||
218 | /* The following writes dest address to BCM and waits for write ready */ | ||
219 | orr r2, lr, #0x00010000 /* r2 = BCM_WR_ADDR32 */ | ||
220 | orr r6, lr, #0x00030000 /* r6 = BCM_CONTROL */ | ||
221 | add r1, r1, #640 /* dst += (LCD_WIDTH*2) */ | ||
222 | str r1, [r2] /* BCM_WR_ADDR32 = dst */ | ||
223 | .busy_2: | ||
224 | ldrh r1, [r6] /* while (!(BCM_CONTROL & 0x2)) */ | ||
225 | tst r1, #0x2 | ||
226 | beq .busy_2 | ||
227 | |||
228 | |||
229 | /* 2nd loop start */ | ||
230 | 20: /* loop start */ | ||
231 | /* restore r0 (bu), r1 (rv) and r2 (guv) from chroma buffer */ | ||
232 | ldmia r8!, {r0-r2} | ||
233 | |||
234 | /* 2nd loop, first pixel */ | ||
235 | ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */ | ||
236 | sub r5, r5, #16 /* r5 = (Y'-16) * 74 */ | ||
237 | add r3, r5, r5, asl #2 | ||
238 | add r5, r3, r5, asl #5 | ||
239 | |||
240 | add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */ | ||
241 | add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */ | ||
242 | add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */ | ||
243 | |||
244 | orr r5, r6, r4 /* check if clamping is needed... */ | ||
245 | orr r5, r5, r3, asr #1 /* ...at all */ | ||
246 | cmp r5, #31 | ||
247 | bls 15f /* -> no clamp */ | ||
248 | cmp r6, #31 /* clamp r */ | ||
249 | mvnhi r6, r6, asr #31 | ||
250 | andhi r6, r6, #31 | ||
251 | cmp r3, #63 /* clamp g */ | ||
252 | mvnhi r3, r3, asr #31 | ||
253 | andhi r3, r3, #63 | ||
254 | cmp r4, #31 /* clamp b */ | ||
255 | mvnhi r4, r4, asr #31 | ||
256 | andhi r4, r4, #31 | ||
257 | 15: /* no clamp */ | ||
258 | /* calculate pixel_1 and save to r5 for later pixel packing */ | ||
259 | orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */ | ||
260 | orr r5, r4, r6, lsl #11 /* r5 = pixel_1 */ | ||
261 | |||
262 | /* 2nd loop, second pixel */ | ||
263 | ldrb r4, [r9], #1 /* r4 = *ysrc++ = *Y'_p++ */ | ||
264 | sub r4, r4, #16 /* r4 = (Y'-16) * 74 */ | ||
265 | add r3, r4, r4, asl #2 | ||
266 | add r4, r3, r4, asl #5 | ||
267 | |||
268 | add r6, r1, r4, asr #8 /* r6 = r = (Y >> 9) + rv */ | ||
269 | add r3, r2, r4, asr #7 /* r3 = g = (Y >> 8) + guv */ | ||
270 | add r4, r0, r4, asr #8 /* r4 = b = (Y >> 9) + bu */ | ||
271 | |||
272 | orr r0, r6, r4 /* check if clamping is needed... */ | ||
273 | orr r0, r0, r3, asr #1 /* ...at all */ | ||
274 | cmp r0, #31 | ||
275 | bls 15f /* -> no clamp */ | ||
276 | cmp r6, #31 /* clamp r */ | ||
277 | mvnhi r6, r6, asr #31 | ||
278 | andhi r6, r6, #31 | ||
279 | cmp r3, #63 /* clamp g */ | ||
280 | mvnhi r3, r3, asr #31 | ||
281 | andhi r3, r3, #63 | ||
282 | cmp r4, #31 /* clamp b */ | ||
283 | mvnhi r4, r4, asr #31 | ||
284 | andhi r4, r4, #31 | ||
285 | 15: /* no clamp */ | ||
286 | |||
287 | /* calculate pixel_2 and pack with pixel_1 before writing */ | ||
288 | orr r4, r4, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */ | ||
289 | orr r4, r4, r6, lsl #11 /* r4 = pixel_2 */ | ||
290 | orr r4, r5, r4, lsl #16 /* r4 = pixel_2<<16 | pixel_1 */ | ||
291 | str r4, [lr] /* write packed pixels */ | ||
292 | |||
293 | subs r7, r7, #2 /* check for loop end */ | ||
294 | bgt 20b /* back to beginning */ | ||
295 | /* 2nd loop end */ | ||
296 | |||
297 | ldr r3, [sp, #12] | ||
298 | add sp, sp, r3 /* deallocate buffer */ | ||
299 | ldmpc regs=r4-r10 /* restore registers */ | ||
300 | |||
301 | .ltorg | ||
302 | .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines | ||
diff --git a/firmware/target/arm/ipod/video/lcd-video.c b/firmware/target/arm/ipod/video/lcd-video.c index 494bec8429..27d889aafa 100644 --- a/firmware/target/arm/ipod/video/lcd-video.c +++ b/firmware/target/arm/ipod/video/lcd-video.c | |||
@@ -439,6 +439,53 @@ void lcd_update(void) | |||
439 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | 439 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); |
440 | } | 440 | } |
441 | 441 | ||
442 | /* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */ | ||
443 | extern void lcd_write_yuv420_lines(unsigned char const * const src[3], | ||
444 | unsigned bcmaddr, | ||
445 | int width, | ||
446 | int stride); | ||
447 | |||
448 | /* Performance function to blit a YUV bitmap directly to the LCD */ | ||
449 | void lcd_blit_yuv(unsigned char * const src[3], | ||
450 | int src_x, int src_y, int stride, | ||
451 | int x, int y, int width, int height) | ||
452 | { | ||
453 | unsigned bcmaddr; | ||
454 | off_t z; | ||
455 | unsigned char const * yuv_src[3]; | ||
456 | |||
457 | #ifdef HAVE_LCD_SLEEP | ||
458 | if (!lcd_state.display_on) | ||
459 | return; | ||
460 | #endif | ||
461 | |||
462 | /* Sorry, but width and height must be >= 2 or else */ | ||
463 | width &= ~1; | ||
464 | |||
465 | z = stride * src_y; | ||
466 | yuv_src[0] = src[0] + z + src_x; | ||
467 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
468 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
469 | |||
470 | /* Prevent the tick from triggering BCM updates while we're writing. */ | ||
471 | lcd_block_tick(); | ||
472 | |||
473 | bcmaddr = BCMA_CMDPARAM + (LCD_WIDTH*2) * y + (x << 1); | ||
474 | height >>= 1; | ||
475 | |||
476 | do | ||
477 | { | ||
478 | lcd_write_yuv420_lines(yuv_src, bcmaddr, width, stride); | ||
479 | bcmaddr += (LCD_WIDTH*4); /* Skip up two lines */ | ||
480 | yuv_src[0] += stride << 1; | ||
481 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
482 | yuv_src[2] += stride >> 1; | ||
483 | } | ||
484 | while (--height > 0); | ||
485 | |||
486 | lcd_unblock_and_update(); | ||
487 | } | ||
488 | |||
442 | #ifdef HAVE_LCD_SLEEP | 489 | #ifdef HAVE_LCD_SLEEP |
443 | /* Executes a BCM command immediately and waits for it to complete. | 490 | /* Executes a BCM command immediately and waits for it to complete. |
444 | Other BCM commands (eg. LCD updates or lcd_tick) must not interfere. | 491 | Other BCM commands (eg. LCD updates or lcd_tick) must not interfere. |