summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-02 21:43:14 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-01-02 21:43:14 +0000
commit9f78d3809707cd38d49be1557c311c9a95aca2ef (patch)
tree98271cc5d492880353616f110477acfce3de69ae
parentcacc64a4feef33dfd2aef2a1092f110ac196382b (diff)
downloadrockbox-9f78d3809707cd38d49be1557c311c9a95aca2ef.tar.gz
rockbox-9f78d3809707cd38d49be1557c311c9a95aca2ef.zip
Submit FS#11843 v17. Integrate YUV-blitting of nano 2G to nano1G/color LCD driver. Additionally refactor RGB and YUV screen updates to use same code fragments and save some binsize. YUV speedup is +3-4%, RGB 1/4 screen +2%.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28944 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xfirmware/target/arm/ipod/lcd-as-color-nano.S377
-rw-r--r--firmware/target/arm/ipod/lcd-color_nano.c230
2 files changed, 334 insertions, 273 deletions
diff --git a/firmware/target/arm/ipod/lcd-as-color-nano.S b/firmware/target/arm/ipod/lcd-as-color-nano.S
index d4df4d496a..f6f9cc5be3 100755
--- a/firmware/target/arm/ipod/lcd-as-color-nano.S
+++ b/firmware/target/arm/ipod/lcd-as-color-nano.S
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id:$ 8 * $Id:$
9 * 9 *
10 * Copyright (C) 2010 by Andree Buschmann 10 * Copyright (C) 2010-2011 by Andree Buschmann
11 * 11 *
12 * Generic asm helper function used by YUV blitting. 12 * Generic asm helper function used by YUV blitting.
13 * 13 *
@@ -24,129 +24,264 @@
24#include "config.h" 24#include "config.h"
25#include "cpu.h" 25#include "cpu.h"
26 26
27 .section .icode, "ax", %progbits 27/****************************************************************************
28 * #define FORCE_FIFO_WAIT
29 *
30 * This is not needed in YUV blitting when the LCD IF is fast enough. In this
31 * case YUV-to-RGB conversion per pixel needs longer than the transfer of a
32 * pixel via the LCD IF.
33 ****************************************************************************/
34
35#include "config.h"
36
37/* Set FIFO wait for both iPod Color and iPod nano1G until we know for which
38 * devices we can switch this off. */
39#define FORCE_FIFO_WAIT
28 40
41 .section .icode, "ax", %progbits
42
29/**************************************************************************** 43/****************************************************************************
30* void lcd_yuv_write_inner_loop(unsigned char const * const ysrc, 44 * extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
31* unsigned char const * const usrc, 45 * const unsigned LCD_BASE,
32* unsigned char const * const vsrc, 46 * int width,
33* int width); 47 * int stride);
34* 48 *
35* YUV- > RGB565 conversion 49 * Conversion from Motion JPEG and MPEG Y'PbPr to RGB is:
36* |R| |1.000000 -0.000001 1.402000| |Y'| 50 * |R| |1.164 0.000 1.596| |Y' - 16|
37* |G| = |1.000000 -0.334136 -0.714136| |Pb| 51 * |G| = |1.164 -0.391 -0.813| |Pb - 128|
38* |B| |1.000000 1.772000 0.000000| |Pr| 52 * |B| |1.164 2.018 0.000| |Pr - 128|
39* Scaled, normalized, rounded and tweaked to yield RGB 565: 53 *
40* |R| |74 0 101| |Y' - 16| >> 9 54 * Scaled, normalized, rounded and tweaked to yield RGB 565:
41* |G| = |74 -24 -51| |Cb - 128| >> 8 55 * |R| |74 0 101| |Y' - 16| >> 9
42* |B| |74 128 0| |Cr - 128| >> 9 56 * |G| = |74 -24 -51| |Cb - 128| >> 8
43* 57 * |B| |74 128 0| |Cr - 128| >> 9
44*/ 58 *
59 * Converts two lines from YUV to RGB565 and writes to LCD at once. First loop
60 * loads Cb/Cr, calculates the chroma offset and saves them to buffer. Within
61 * the second loop these chroma offset are reloaded from buffer. Within each
62 * loop two pixels are calculated and written to LCD.
63 */
45 .align 2 64 .align 2
46 .global lcd_yuv_write_inner_loop 65 .global lcd_write_yuv420_lines
47 .type lcd_yuv_write_inner_loop, %function 66 .type lcd_write_yuv420_lines, %function
48 67lcd_write_yuv420_lines:
49lcd_yuv_write_inner_loop: 68 /* r0 = src = yuv_src */
50 @ r0 = ysrc 69 /* r1 = dst = LCD_BASE */
51 @ r1 = usrc 70 /* r2 = width */
52 @ r2 = vsrc 71 /* r3 = stride */
53 @ r3 = width 72 stmfd sp!, { r4-r10, lr } /* save non-scratch */
54 stmfd sp!, { r4-r11, lr } @ save regs 73 ldmia r0, { r9, r10, r12 } /* r9 = yuv_src[0] = Y'_p */
55 mov r4, #0x70000000 @ r4 = LCD2_BLOCK_CTRL - 0x20 74 /* r10 = yuv_src[1] = Cb_p */
56 add r4, r4, #0x8a00 @ 75 /* r12 = yuv_src[2] = Cr_p */
57 add r5, r4, #0x100 @ r5 = LCD2_BLOCK_DATA 76 add r3, r9, r3 /* r3 = &ysrc[stride] */
5810: @ loop 77 add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */
59 78 mov r4, r4, asl #2 /* use words for str/ldm possibility */
60 ldrb r7, [r1], #1 @ *usrc++ 79 add r4, r4, #19 /* plus room for 4 additional words, */
61 ldrb r8, [r2], #1 @ *vsrc++ 80 bic r4, r4, #3 /* rounded up to multiples of 4 byte */
62 81 sub sp, sp, r4 /* and allocate on stack */
63 sub r7, r7, #128 @ Cb -= 128 82 stmia sp, {r1-r4} /* LCD_BASE, width, &ysrc[stride], stack_alloc */
64 sub r8, r8, #128 @ Cr -= 128 83
65 84 mov r7, r2 /* r7 = loop count */
66 add r10, r8, r8, asl #2 @ Cr*101 85 add r8, sp, #16 /* chroma buffer */
67 add r10, r10, r8, asl #5 86 add lr, r1, #0x100 /* LCD data port = LCD2_BASE + 0x100 */
68 add r10, r10, r8, asl #6 87
69 88 /* 1st loop start */
70 add r11, r8, r8, asl #1 @ Cr*51 + Cb*24 8910: /* loop start */
71 add r11, r11, r11, asl #4 90
72 add r11, r11, r7, asl #3 91 ldrb r0, [r10], #1 /* r0 = *usrc++ = *Cb_p++ */
73 add r11, r11, r7, asl #4 92 ldrb r1, [r12], #1 /* r1 = *vsrc++ = *Cr_p++ */
74 93
75 add r12, r7, #2 @ r12 = bu = (Cb*128 + 256) >> 9 94 sub r0, r0, #128 /* r0 = Cb-128 */
76 mov r12, r12, asr #2 95 sub r1, r1, #128 /* r1 = Cr-128 */
77 add r10, r10, #256 @ r10 = rv = (Cr*101 + 256) >> 9 96
78 mov r10, r10, asr #9 97 add r2, r1, r1, asl #1 /* r2 = Cr*51 + Cb*24 */
79 rsb r11, r11, #128 @ r11 = guv = (-r11 + 128) >> 8 98 add r2, r2, r2, asl #4
80 mov r11, r11, asr #8 99 add r2, r2, r0, asl #3
81 100 add r2, r2, r0, asl #4
82@ pixel_1 101
83 ldrb r7, [r0], #1 @ *ysrc++ 102 add r4, r1, r1, asl #2 /* r1 = Cr*101 */
84 sub r7, r7, #16 @ Y = (Y' - 16) * 37 103 add r4, r4, r1, asl #5
85 add r8, r7, r7, asl #2 104 add r1, r4, r1, asl #6
86 add r7, r8, r7, asl #5 105
87 106 add r1, r1, #256 /* r1 = rv = (r1 + 256) >> 9 */
88 add r9, r10, r7, asr #8 @ R = (Y >> 8) + rv 107 mov r1, r1, asr #9
89 add r8, r11, r7, asr #7 @ G = (Y >> 7) + guv 108 rsb r2, r2, #128 /* r2 = guv = (-r2 + 128) >> 8 */
90 add r7, r12, r7, asr #8 @ B = (Y >> 8) + bu 109 mov r2, r2, asr #8
91 110 add r0, r0, #2 /* r0 = bu = (Cb*128 + 256) >> 9 */
92 cmp r9, #31 @ clamp R 111 mov r0, r0, asr #2
93 mvnhi r9, r9, asr #31 112 stmia r8!, {r0-r2} /* store r0, r1 and r2 to chroma buffer */
94 andhi r9, r9, #31 113
95 114 /* 1st loop, first pixel */
96 cmp r8, #63 @ clamp G 115 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
97 mvnhi r8, r8, asr #31 116 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
98 andhi r8, r8, #63 117 add r3, r5, r5, asl #2
99 118 add r5, r3, r5, asl #5
100 cmp r7, #31 @ clamp B 119
101 mvnhi r7, r7, asr #31 120 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
102 andhi r7, r7, #31 121 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
103 122 add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
104 orr r6, r7, r8, lsl #5 @ pack pixel 123
105 orr r6, r6, r9, lsl #11 124 orr r5, r6, r4 /* check if clamping is needed... */
106 125 orr r5, r5, r3, asr #1 /* ...at all */
107 mov r7, r6, lsl #8 @ swap bytes 126 cmp r5, #31
108 and r7, r7, #0xff00 127 bls 15f /* -> no clamp */
109 add r6, r7, r6, lsr #8 128 cmp r6, #31 /* clamp r */
110 129 mvnhi r6, r6, asr #31
111@ pixel_2 130 andhi r6, r6, #31
112 ldrb r7, [r0], #1 @ *ysrc++ 131 cmp r3, #63 /* clamp g */
113 sub r7, r7, #16 @ Y = (Y' - 16) * 37 132 mvnhi r3, r3, asr #31
114 add r8, r7, r7, asl #2 133 andhi r3, r3, #63
115 add r7, r8, r7, asl #5 134 cmp r4, #31 /* clamp b */
116 135 mvnhi r4, r4, asr #31
117 add r9, r10, r7, asr #8 @ R = (Y >> 8) + rv 136 andhi r4, r4, #31
118 add r8, r11, r7, asr #7 @ G = (Y >> 7) + guv 13715: /* no clamp */
119 add r7, r12, r7, asr #8 @ B = (Y >> 8) + bu 138
120 139 /* calculate pixel_1 and save to r4 for later pixel packing */
121 cmp r9, #31 @ clamp R 140 orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
122 mvnhi r9, r9, asr #31 141 orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */
123 andhi r9, r9, #31 142
124 143 /* 1st loop, second pixel */
125 cmp r8, #63 @ clamp G 144 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
126 mvnhi r8, r8, asr #31 145 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
127 andhi r8, r8, #63 146 add r3, r5, r5, asl #2
128 147 add r5, r3, r5, asl #5
129 cmp r7, #31 @ clamp B 148
130 mvnhi r7, r7, asr #31 149 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
131 andhi r7, r7, #31 150 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
132 151 add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */
133 orr r7, r7, r8, lsl #5 @ pack pixel 152
134 orr r7, r7, r9, lsl #11 153 orr r0, r6, r5 /* check if clamping is needed... */
135 154 orr r0, r0, r3, asr #1 /* ...at all */
136 orr r6, r6, r7, lsl #24 @ swap bytes and add pixels simultaneously 155 cmp r0, #31
137 mov r7, r7, lsr #8 156 bls 15f /* -> no clamp */
138 orr r6, r6, r7, lsl #16 157 cmp r6, #31 /* clamp r */
139#if 1 158 mvnhi r6, r6, asr #31
14011: @ while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_TXOK)); 159 andhi r6, r6, #31
141 ldr r11, [r4, #0x20] @ 160 cmp r3, #63 /* clamp g */
142 tst r11, #0x1000000 @ 161 mvnhi r3, r3, asr #31
143 beq 11b @ 162 andhi r3, r3, #63
163 cmp r5, #31 /* clamp b */
164 mvnhi r5, r5, asr #31
165 andhi r5, r5, #31
16615: /* no clamp */
167
168 /* calculate pixel_2 and pack with pixel_1 before writing */
169 orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
170 orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */
171#ifdef FORCE_FIFO_WAIT
172 /* wait for FIFO half full */
173.fifo_wait1:
174 ldr r3, [lr, #-0xE0] /* while !(LCD2_BLOCK_CTRL & 0x1000000); */
175 tst r3, #0x1000000
176 beq .fifo_wait1
144#endif 177#endif
145 str r6, [r5] @ send two pixels
146 178
147 subs r3, r3, #2 @ decrease width 179 mov r3, r4, lsl #8 /* swap pixel_1 */
148 bgt 10b @ loop 180 and r3, r3, #0xff00
181 add r4, r3, r4, lsr #8
182
183 orr r4, r4, r5, lsl #24 /* swap pixel_2 and pack with pixel_1 */
184 mov r5, r5, lsr #8
185 orr r4, r4, r5, lsl #16
186
187 str r4, [lr] /* write pixel_1 and pixel_2 */
188
189 subs r7, r7, #2 /* check for loop end */
190 bgt 10b /* back to beginning */
191 /* 1st loop end */
192
193 /* Reload several registers for pointer rewinding for next loop */
194 add r8, sp, #16 /* chroma buffer */
195 ldmia sp, { r1, r7, r9} /* r1 = LCD_BASE */
196 /* r7 = loop count */
197 /* r9 = &ysrc[stride] */
198
199 /* 2nd loop start */
20020: /* loop start */
201 /* restore r0 (bu), r1 (rv) and r2 (guv) from chroma buffer */
202 ldmia r8!, {r0-r2}
203
204 /* 2nd loop, first pixel */
205 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
206 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
207 add r3, r5, r5, asl #2
208 add r5, r3, r5, asl #5
209
210 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
211 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
212 add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
213
214 orr r5, r6, r4 /* check if clamping is needed... */
215 orr r5, r5, r3, asr #1 /* ...at all */
216 cmp r5, #31
217 bls 15f /* -> no clamp */
218 cmp r6, #31 /* clamp r */
219 mvnhi r6, r6, asr #31
220 andhi r6, r6, #31
221 cmp r3, #63 /* clamp g */
222 mvnhi r3, r3, asr #31
223 andhi r3, r3, #63
224 cmp r4, #31 /* clamp b */
225 mvnhi r4, r4, asr #31
226 andhi r4, r4, #31
22715: /* no clamp */
228 /* calculate pixel_1 and save to r4 for later pixel packing */
229 orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
230 orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */
231
232 /* 2nd loop, second pixel */
233 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
234 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
235 add r3, r5, r5, asl #2
236 add r5, r3, r5, asl #5
237
238 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
239 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
240 add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */
241
242 orr r0, r6, r5 /* check if clamping is needed... */
243 orr r0, r0, r3, asr #1 /* ...at all */
244 cmp r0, #31
245 bls 15f /* -> no clamp */
246 cmp r6, #31 /* clamp r */
247 mvnhi r6, r6, asr #31
248 andhi r6, r6, #31
249 cmp r3, #63 /* clamp g */
250 mvnhi r3, r3, asr #31
251 andhi r3, r3, #63
252 cmp r5, #31 /* clamp b */
253 mvnhi r5, r5, asr #31
254 andhi r5, r5, #31
25515: /* no clamp */
256
257 /* calculate pixel_2 and pack with pixel_1 before writing */
258 orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
259 orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */
260#ifdef FORCE_FIFO_WAIT
261 /* wait for FIFO half full */
262.fifo_wait2:
263 ldr r3, [lr, #-0xE0] /* while !(LCD2_BLOCK_CTRL & 0x1000000); */
264 tst r3, #0x1000000
265 beq .fifo_wait2
266#endif
267
268 mov r3, r4, lsl #8 /* swap pixel_1 */
269 and r3, r3, #0xff00
270 add r4, r3, r4, lsr #8
271
272 orr r4, r4, r5, lsl #24 /* swap pixel_2 and pack with pixel_1 */
273 mov r5, r5, lsr #8
274 orr r4, r4, r5, lsl #16
275
276 str r4, [lr] /* write pixel_1 and pixel_2 */
277
278 subs r7, r7, #2 /* check for loop end */
279 bgt 20b /* back to beginning */
280 /* 2nd loop end */
281
282 ldr r3, [sp, #12]
283 add sp, sp, r3 /* deallocate buffer */
284 ldmpc regs=r4-r10 /* restore registers */
149 285
150 ldmpc regs=r4-r11 @ restore regs 286 .ltorg
151 .ltorg @ dump constant pool 287 .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
152 .size lcd_yuv_write_inner_loop, .-lcd_yuv_write_inner_loop
diff --git a/firmware/target/arm/ipod/lcd-color_nano.c b/firmware/target/arm/ipod/lcd-color_nano.c
index e3b9ea8eb6..8cff7bda21 100644
--- a/firmware/target/arm/ipod/lcd-color_nano.c
+++ b/firmware/target/arm/ipod/lcd-color_nano.c
@@ -32,6 +32,9 @@
32#include "system.h" 32#include "system.h"
33#include "hwcompat.h" 33#include "hwcompat.h"
34 34
35/*** macros ***/
36#define SWAP_INT(X,Y) {int tmp=X; X=Y; Y=tmp;}
37
35/* LCD command codes for HD66789R */ 38/* LCD command codes for HD66789R */
36#define LCD_CNTL_RAM_ADDR_SET 0x21 39#define LCD_CNTL_RAM_ADDR_SET 0x21
37#define LCD_CNTL_WRITE_TO_GRAM 0x22 40#define LCD_CNTL_WRITE_TO_GRAM 0x22
@@ -120,25 +123,11 @@ void lcd_init_device(void)
120#endif 123#endif
121} 124}
122 125
123/*** update functions ***/ 126/* Helper function to set up drawing region and start drawing */
124extern void lcd_yuv_write_inner_loop(unsigned char const * const ysrc, 127static void lcd_setup_drawing_region(int x, int y, int width, int height)
125 unsigned char const * const usrc,
126 unsigned char const * const vsrc,
127 int width);
128
129#define CSUB_X 2
130#define CSUB_Y 2
131
132/* Performance function to blit a YUV bitmap directly to the LCD */
133void lcd_blit_yuv(unsigned char * const src[3],
134 int src_x, int src_y, int stride,
135 int x, int y, int width, int height)
136{ 128{
137 int h;
138 int y0, x0, y1, x1; 129 int y0, x0, y1, x1;
139 130
140 width = (width + 1) & ~1;
141
142 /* calculate the drawing region */ 131 /* calculate the drawing region */
143#if CONFIG_LCD == LCD_IPODNANO 132#if CONFIG_LCD == LCD_IPODNANO
144 y0 = x; /* start horiz */ 133 y0 = x; /* start horiz */
@@ -159,21 +148,8 @@ void lcd_blit_yuv(unsigned char * const src[3],
159 lcd_cmd_data(0x15, y1); /* end vert */ 148 lcd_cmd_data(0x15, y1); /* end vert */
160 lcd_cmd_data(0x16, x1); /* end horiz */ 149 lcd_cmd_data(0x16, x1); /* end horiz */
161 } else { 150 } else {
162 /* swap max horiz < start horiz */ 151 if (y1 < y0) SWAP_INT(y0,y1) /* swap max horiz < start horiz */
163 if (y1 < y0) { 152 if (x1 < x0) SWAP_INT(x0,x1) /* swap max vert < start vert */
164 int t;
165 t = y0;
166 y0 = y1;
167 y1 = t;
168 }
169
170 /* swap max vert < start vert */
171 if (x1 < x0) {
172 int t;
173 t = x0;
174 x0 = x1;
175 x1 = t;
176 }
177 153
178 /* max horiz << 8 | start horiz */ 154 /* max horiz << 8 | start horiz */
179 lcd_cmd_data(LCD_CNTL_HORIZ_RAM_ADDR_POS, (y1 << 8) | y0); 155 lcd_cmd_data(LCD_CNTL_HORIZ_RAM_ADDR_POS, (y1 << 8) | y0);
@@ -194,167 +170,117 @@ void lcd_blit_yuv(unsigned char * const src[3],
194 LCD2_PORT = LCD2_CMD_MASK; 170 LCD2_PORT = LCD2_CMD_MASK;
195 LCD2_PORT = (LCD2_CMD_MASK|LCD_CNTL_WRITE_TO_GRAM); 171 LCD2_PORT = (LCD2_CMD_MASK|LCD_CNTL_WRITE_TO_GRAM);
196 } 172 }
173}
197 174
198 const int stride_div_csub_x = stride/CSUB_X; 175/* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */
199 176extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
200 h=0; 177 const unsigned int lcd_baseadress,
201 while (1) 178 int width,
202 { 179 int stride);
203 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
204 const unsigned char *ysrc = src[0] + stride * src_y + src_x;
205
206 const int uvoffset = stride_div_csub_x * (src_y/CSUB_Y) +
207 (src_x/CSUB_X);
208 180
209 const unsigned char *usrc = src[1] + uvoffset; 181/* Performance function to blit a YUV bitmap directly to the LCD */
210 const unsigned char *vsrc = src[2] + uvoffset; 182void lcd_blit_yuv(unsigned char * const src[3],
183 int src_x, int src_y, int stride,
184 int x, int y, int width, int height)
185{
186 int z;
187 unsigned char const * yuv_src[3];
211 188
212 int pixels_to_write; 189 width = (width + 1) & ~1; /* ensure width is even */
190 height = (height + 1) & ~1; /* ensure height is even */
213 191
214 if (h==0) 192 lcd_setup_drawing_region(x, y, width, height);
215 {
216 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY));
217 LCD2_BLOCK_CONFIG = 0;
218 193
219 if (height == 0) break; 194 z = stride * src_y;
195 yuv_src[0] = src[0] + z + src_x;
196 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
197 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
220 198
221 pixels_to_write = (width * height) * 2; 199 while (height > 0) {
222 h = height; 200 int r, h, pixels_to_write;
223 201
224 /* calculate how much we can do in one go */ 202 pixels_to_write = (width * height) * 2;
225 if (pixels_to_write > 0x10000) 203 h = height;
226 {
227 h = (0x10000/2) / width;
228 pixels_to_write = (width * h) * 2;
229 }
230 204
231 height -= h; 205 /* calculate how much we can do in one go */
232 LCD2_BLOCK_CTRL = 0x10000080; 206 if (pixels_to_write > 0x10000) {
233 LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1); 207 h = ((0x10000/2) / width) & ~1; /* ensure h is even */
234 LCD2_BLOCK_CTRL = 0x34000000; 208 pixels_to_write = (width * h) * 2;
235 } 209 }
236 210
237 lcd_yuv_write_inner_loop(ysrc,usrc,vsrc,width); 211 LCD2_BLOCK_CTRL = 0x10000080;
238 212 LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1);
239 src_y++; 213 LCD2_BLOCK_CTRL = 0x34000000;
240 h--; 214
215 r = h>>1; /* lcd_write_yuv420_lines writes two lines at once */
216 do {
217 lcd_write_yuv420_lines(yuv_src, LCD2_BASE, width, stride);
218 yuv_src[0] += stride << 1;
219 yuv_src[1] += stride >> 1;
220 yuv_src[2] += stride >> 1;
221 } while (--r > 0);
222
223 /* transfer of pixels_to_write bytes finished */
224 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY));
225 LCD2_BLOCK_CONFIG = 0;
226
227 height -= h;
241 } 228 }
242
243 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY));
244 LCD2_BLOCK_CONFIG = 0;
245} 229}
246 230
231/* Helper function writes 'count' consecutive pixels from src to LCD IF */
232static void lcd_write_line(int count, unsigned long *src)
233{
234 do {
235 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_TXOK)); /* FIFO wait */
236 LCD2_BLOCK_DATA = *src++; /* output 2 pixels */
237 count -= 2;
238 } while (count > 0);
239}
247 240
248/* Update a fraction of the display. */ 241/* Update a fraction of the display. */
249void lcd_update_rect(int x, int y, int width, int height) 242void lcd_update_rect(int x, int y, int width, int height)
250{ 243{
251 int y0, x0, y1, x1;
252 int newx,newwidth;
253 unsigned long *addr; 244 unsigned long *addr;
254 245
255 /* Ensure x and width are both even - so we can read 32-bit aligned 246 /* Ensure both x and width are even to be able to read 32-bit aligned
256 data from lcd_framebuffer */ 247 * data from lcd_framebuffer */
257 newx=x&~1; 248 x = x & ~1; /* use the smaller even number */
258 newwidth=width&~1; 249 width = (width + 1) & ~1; /* use the bigger even number */
259 if (newx+newwidth < x+width) { newwidth+=2; }
260 x=newx; width=newwidth;
261 250
262 /* calculate the drawing region */ 251 lcd_setup_drawing_region(x, y, width, height);
263#if CONFIG_LCD == LCD_IPODNANO
264 y0 = x; /* start horiz */
265 x0 = y; /* start vert */
266 y1 = (x + width) - 1; /* max horiz */
267 x1 = (y + height) - 1; /* max vert */
268#elif CONFIG_LCD == LCD_IPODCOLOR
269 y0 = y; /* start vert */
270 x0 = (LCD_WIDTH - 1) - x; /* start horiz */
271 y1 = (y + height) - 1; /* end vert */
272 x1 = (x0 - width) + 1; /* end horiz */
273#endif
274 /* setup the drawing region */
275 if (lcd_type == 0) {
276 lcd_cmd_data(0x12, y0); /* start vert */
277 lcd_cmd_data(0x13, x0); /* start horiz */
278 lcd_cmd_data(0x15, y1); /* end vert */
279 lcd_cmd_data(0x16, x1); /* end horiz */
280 } else {
281 /* swap max horiz < start horiz */
282 if (y1 < y0) {
283 int t;
284 t = y0;
285 y0 = y1;
286 y1 = t;
287 }
288
289 /* swap max vert < start vert */
290 if (x1 < x0) {
291 int t;
292 t = x0;
293 x0 = x1;
294 x1 = t;
295 }
296
297 /* max horiz << 8 | start horiz */
298 lcd_cmd_data(LCD_CNTL_HORIZ_RAM_ADDR_POS, (y1 << 8) | y0);
299 /* max vert << 8 | start vert */
300 lcd_cmd_data(LCD_CNTL_VERT_RAM_ADDR_POS, (x1 << 8) | x0);
301
302 /* start vert = max vert */
303#if CONFIG_LCD == LCD_IPODCOLOR
304 x0 = x1;
305#endif
306
307 /* position cursor (set AD0-AD15) */
308 /* start vert << 8 | start horiz */
309 lcd_cmd_data(LCD_CNTL_RAM_ADDR_SET, ((x0 << 8) | y0));
310
311 /* start drawing */
312 lcd_wait_write();
313 LCD2_PORT = LCD2_CMD_MASK;
314 LCD2_PORT = (LCD2_CMD_MASK|LCD_CNTL_WRITE_TO_GRAM);
315 }
316 252
317 addr = (unsigned long*)&lcd_framebuffer[y][x]; 253 addr = (unsigned long*)&lcd_framebuffer[y][x];
318 254
319 while (height > 0) { 255 while (height > 0) {
320 int c, r; 256 int r, h, pixels_to_write;
321 int h, pixels_to_write;
322 257
323 pixels_to_write = (width * height) * 2; 258 pixels_to_write = (width * height) * 2;
324 h = height; 259 h = height;
325 260
326 /* calculate how much we can do in one go */ 261 /* calculate how much we can do in one go */
327 if (pixels_to_write > 0x10000) { 262 if (pixels_to_write > 0x10000) {
328 h = (0x10000/2) / width; 263 h = ((0x10000/2) / width) & ~1; /* ensure h is even */
329 pixels_to_write = (width * h) * 2; 264 pixels_to_write = (width * h) * 2;
330 } 265 }
331 266
332 LCD2_BLOCK_CTRL = 0x10000080; 267 LCD2_BLOCK_CTRL = 0x10000080;
333 LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1); 268 LCD2_BLOCK_CONFIG = 0xc0010000 | (pixels_to_write - 1);
334 LCD2_BLOCK_CTRL = 0x34000000; 269 LCD2_BLOCK_CTRL = 0x34000000;
335 270
336 if (LCD_WIDTH == width) { 271 if (LCD_WIDTH == width) {
337 /* for each row and column in a single loop */ 272 /* for each row and column in a single call */
338 for (r = 0; r < h*width; r += 2) { 273 lcd_write_line(h*width, addr);
339 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_TXOK)); 274 addr += LCD_WIDTH/2*h;
340
341 /* output 2 pixels */
342 LCD2_BLOCK_DATA = *addr++;
343 }
344 } else { 275 } else {
345 /* for each row */ 276 /* for each row */
346 for (r = 0; r < h; r++) { 277 for (r = 0; r < h; r++) {
347 /* for each column */ 278 lcd_write_line(width, addr);
348 for (c = 0; c < width; c += 2) { 279 addr += LCD_WIDTH/2;
349 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_TXOK));
350
351 /* output 2 pixels */
352 LCD2_BLOCK_DATA = *addr++;
353 }
354 addr += (LCD_WIDTH - width)/2;
355 } 280 }
356 } 281 }
357 282
283 /* transfer of pixels_to_write bytes finished */
358 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY)); 284 while (!(LCD2_BLOCK_CTRL & LCD2_BLOCK_READY));
359 LCD2_BLOCK_CONFIG = 0; 285 LCD2_BLOCK_CONFIG = 0;
360 286