blob: 69bf9225719fc23eb9fd57d69a6d071c8c6be668 [file] [log] [blame]
Michael Sevakis25413022008-03-31 04:53:03 +00001/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2007 by Greg White
11*
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
Michael Sevakis25413022008-03-31 04:53:03 +000016*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000021#include "config.h"
Michael Sevakisa65406e2008-03-31 01:29:50 +000022#include "system.h"
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000023#include "cpu.h"
Karl Kurbjunf863ba62007-06-04 14:07:26 +000024#include "string.h"
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000025#include "lcd.h"
26#include "kernel.h"
Greg White9d0faed2007-01-04 11:43:33 +000027#include "lcd-target.h"
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000028
Greg White69bb4362007-01-15 13:07:47 +000029#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000030
Michael Sevakis009cebe2008-05-14 19:29:25 +000031static bool lcd_on = true;
32static bool lcd_powered = true;
Michael Sevakis287d6222007-09-25 02:59:42 +000033static unsigned lcd_yuv_options = 0;
Greg White9d0faed2007-01-04 11:43:33 +000034/*
Dave Chapman945c8a22008-01-07 20:34:11 +000035** This is imported from lcd-16bit.c
Greg White9d0faed2007-01-04 11:43:33 +000036*/
Dave Chapman945c8a22008-01-07 20:34:11 +000037extern struct viewport* current_vp;
Greg White9d0faed2007-01-04 11:43:33 +000038
Michael Sevakis897c6432007-07-08 17:10:22 +000039/* Copies a rectangle from one framebuffer to another. Can be used in
40 single transfer mode with width = num pixels, and height = 1 which
41 allows a full-width rectangle to be copied more efficiently. */
42extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
43 int width, int height);
44
Michael Sevakis41b235d2008-05-14 20:26:20 +000045bool lcd_enabled(void)
Greg Whiteffb50d02007-01-11 10:24:21 +000046{
47 return lcd_on;
48}
Marcoen Hirschberg29536762006-12-29 02:49:12 +000049
Greg White355be502007-01-13 02:24:15 +000050unsigned int LCDBANK(unsigned int address)
51{
52 return ((address >> 22) & 0xff);
53}
54
55unsigned int LCDBASEU(unsigned int address)
56{
57 return (address & ((1 << 22)-1)) >> 1;
58}
59
60unsigned int LCDBASEL(unsigned int address)
61{
62 address += 320*240*2;
63 return (address & ((1 << 22)-1)) >> 1;
64}
65
Karl Kurbjun94bd1f72008-02-13 05:46:04 +000066inline void delay_cycles(volatile int delay)
67{
68 while(delay>0) delay--;
69}
70
Karl Kurbjun7a4d1602008-05-21 03:30:57 +000071static void LCD_CTRL_setup(void)
Karl Kurbjun94bd1f72008-02-13 05:46:04 +000072{
73 /* ENVID = 0, BPPMODE = 16 bpp, PNRMODE = TFT, MMODE = Each Frame, CLKVAL = 8 */
74 LCDCON1 = 0x878;
75
76 /* VCPW = 1, VFPD = 5, LINEVAL = 319, VBPD = 7 */
77 LCDCON2 = 0x74FC141;
78
79 /* HFPD = 9, HOZVAL = 239, HBPD = 7 */
80 LCDCON3 = 0x38EF09;
81
82 /* HSPW = 7 */
83 LCDCON4 = 7;
84
85 /* HWSWP = 1, INVVFRAM = 1, INVVLINE = 1, FRM565 = 1, All others = 0 */
86 LCDCON5 = 0xB01;
87
88 LCDSADDR1 = (LCDBANK((unsigned)FRAME) << 21) | (LCDBASEU((unsigned)FRAME));
89 LCDSADDR2 = LCDBASEL((unsigned)FRAME);
90 LCDSADDR3 = 0x000000F0;
91}
92
Karl Kurbjun7a4d1602008-05-21 03:30:57 +000093static void LCD_CTRL_clock(bool onoff)
Marcoen Hirschbergdd754882006-08-12 08:01:54 +000094{
Karl Kurbjun6e322c82008-05-14 00:26:28 +000095 if(onoff)
96 {
97 GPCCON &= ~0xFFF000FC;
98 GPDCON &= ~0xFFF0FFF0;
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +000099
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000100 GPCCON |= 0xAAA000A8;
101 GPCUP |= 0xFC0E;
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000102
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000103 GPDCON |= 0xAAA0AAA0;
104 GPDUP |= 0xFCFC;
105
106 s3c_regset(&CLKCON, 0x20); /* enable LCD clock */
107 LCDCON1 |=0x01;
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000108 }
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000109 else
110 {
111 GPCCON &= ~0xFFF000FC;
112 GPCUP &= ~0xFC0E;
Karl Kurbjun8a1fd8c2007-04-21 04:48:20 +0000113
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000114 GPDCON &= ~0xFFF0FFF0;
115 GPDUP &= ~0xFCFC;
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000116
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000117 LCDCON1 &= ~1; /* Must diable first or bus may freeze */
118 s3c_regclr(&CLKCON, 0x20); /* disable LCD clock */
119 }
120}
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000121
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000122static void reset_LCD(bool reset)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000123{
124 GPBCON&=~0xC000;
125 GPBCON|=0x4000;
126 if(reset)
127 GPBDAT|=0x80;
128 else
129 GPBDAT&=~0x80;
130}
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000131
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000132static void LCD_SPI_send(const unsigned char *array, int count)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000133{
134 while (count--)
135 {
136 while ((SPSTA0&0x01)==0){};
137 SPTDAT0=*array++;
138 }
139}
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000140
Karl Kurbjun35904562008-05-18 23:33:09 +0000141void LCD_SPI_setreg(unsigned char reg, unsigned char value)
142{
143 unsigned char regval[] =
144 {
145 0x00,reg,0x01,value
146 };
147 LCD_SPI_send(regval, sizeof(regval));
148}
149
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000150static void LCD_SPI_SS(bool select)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000151{
152 delay_cycles(0x4FFF);
Greg Whiteffb50d02007-01-11 10:24:21 +0000153
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000154 GPBCON&=~0x30000;
155 GPBCON|=0x10000;
Michael Sevakisa65406e2008-03-31 01:29:50 +0000156
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000157 if(select)
158 GPBDAT|=0x100;
159 else
160 GPBDAT&=~0x100;
161}
Karl Kurbjunf863ba62007-06-04 14:07:26 +0000162
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000163void LCD_SPI_start(void)
164{
165 s3c_regset(&CLKCON, 0x40000); /* enable SPI clock */
166 LCD_SPI_SS(false);
167 SPCON0=0x3E;
168 SPPRE0=24;
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000169
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000170 reset_LCD(true);
171 LCD_SPI_SS(true);
172}
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000173
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000174void LCD_SPI_stop(void)
175{
176 LCD_SPI_SS(false);
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000177
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000178 SPCON0 &= ~0x10;
179 s3c_regclr(&CLKCON, 0x40000); /* disable SPI clock */
180}
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000181
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000182static void LCD_SPI_powerdown(void)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000183{
Michael Sevakis009cebe2008-05-14 19:29:25 +0000184 lcd_powered = false;
185
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000186 LCD_SPI_start();
Karl Kurbjun35904562008-05-18 23:33:09 +0000187 LCD_SPI_setreg(0x04, 0x00);
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000188 LCD_SPI_stop();
189
190 reset_LCD(false); /* This makes a big difference on power */
191 LCD_CTRL_clock(false);
192}
193
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000194static void LCD_SPI_powerup(void)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000195{
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000196 LCD_CTRL_clock(true);
197
198 LCD_SPI_start();
Karl Kurbjun35904562008-05-18 23:33:09 +0000199 LCD_SPI_setreg(0x04, 0x01);
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000200 LCD_SPI_stop();
Michael Sevakis009cebe2008-05-14 19:29:25 +0000201
202 lcd_powered = true;
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000203}
204
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000205static void LCD_SPI_init(void)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000206{
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000207 /*
208 * SPI setup - Some of these registers are known; they are documented in
209 * the wiki. Many thanks to Alex Gerchanovsky for discovering this
210 * sequence.
Karl Kurbjunf863ba62007-06-04 14:07:26 +0000211 */
Karl Kurbjunf863ba62007-06-04 14:07:26 +0000212
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000213 LCD_CTRL_clock(true);
Karl Kurbjun94bd1f72008-02-13 05:46:04 +0000214
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000215 LCD_SPI_start();
Karl Kurbjun35904562008-05-18 23:33:09 +0000216 LCD_SPI_setreg(0x0F, 0x01);
217 LCD_SPI_setreg(0x09, 0x06);
218 LCD_SPI_setreg(0x16, 0xA6);
219 LCD_SPI_setreg(0x1E, 0x49);
220 LCD_SPI_setreg(0x1F, 0x26);
221 LCD_SPI_setreg(0x0B, 0x2F);
222 LCD_SPI_setreg(0x0C, 0x2B);
223 LCD_SPI_setreg(0x19, 0x5E);
224 LCD_SPI_setreg(0x1A, 0x15);
225 LCD_SPI_setreg(0x1B, 0x15);
226 LCD_SPI_setreg(0x1D, 0x01);
227 LCD_SPI_setreg(0x00, 0x03);
228 LCD_SPI_setreg(0x01, 0x10);
229 LCD_SPI_setreg(0x02, 0x0A);
230 LCD_SPI_setreg(0x06, 0x04); /* Set the orientation */
231 LCD_SPI_setreg(0x08, 0x2E);
232 LCD_SPI_setreg(0x24, 0x12);
233 LCD_SPI_setreg(0x25, 0x3F);
234 LCD_SPI_setreg(0x26, 0x0B);
235 LCD_SPI_setreg(0x27, 0x00);
236 LCD_SPI_setreg(0x28, 0x00);
237 LCD_SPI_setreg(0x29, 0xF6);
238 LCD_SPI_setreg(0x2A, 0x03);
239 LCD_SPI_setreg(0x2B, 0x0A);
240 LCD_SPI_setreg(0x04, 0x01); /* Turn the display on */
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000241 LCD_SPI_stop();
242}
243
244/* LCD init */
245void lcd_init_device(void)
246{
247 /* Set pins up */
248
249 GPHUP &= 0x600;
250
251 GPECON |= 0x0A800000;
252 GPEUP |= 0x3800;
253
254 GPBUP |= 0x181;
255
Karl Kurbjun35904562008-05-18 23:33:09 +0000256 s3c_regset(&CLKCON, 0x20); /* enable LCD clock */
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000257
258 LCD_CTRL_setup();
259 LCD_SPI_init();
260}
261
Michael Sevakis009cebe2008-05-14 19:29:25 +0000262void lcd_sleep(void)
263{
264 if (lcd_powered)
265 {
266 /* "not powered" implies "disabled" */
267 if (lcd_on)
268 lcd_enable(false);
269
270 LCD_SPI_powerdown();
271 }
272}
273
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000274void lcd_enable(bool state)
275{
Michael Sevakis009cebe2008-05-14 19:29:25 +0000276 if (state == lcd_on)
277 return;
278
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000279 if(state)
280 {
Michael Sevakis009cebe2008-05-14 19:29:25 +0000281 /* "enabled" implies "powered" */
282 if (!lcd_powered)
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000283 {
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000284 LCD_SPI_powerup();
Michael Sevakis009cebe2008-05-14 19:29:25 +0000285 /* Wait long enough for a frame to be written - yes, it
286 * takes awhile. */
287 sleep(HZ/5);
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000288 }
Michael Sevakis009cebe2008-05-14 19:29:25 +0000289
290 lcd_on = true;
291 lcd_update();
Michael Sevakisadf2e4c2008-05-28 10:17:16 +0000292 lcd_call_enable_hook();
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000293 }
294 else
295 {
Michael Sevakis009cebe2008-05-14 19:29:25 +0000296 lcd_on = false;
Karl Kurbjun6e322c82008-05-14 00:26:28 +0000297 }
Marcoen Hirschbergdd754882006-08-12 08:01:54 +0000298}
299
Karl Kurbjun35904562008-05-18 23:33:09 +0000300void lcd_set_flip(bool yesno) {
301 if (!lcd_on)
302 return;
303
Karl Kurbjun35904562008-05-18 23:33:09 +0000304 LCD_SPI_start();
305 if(yesno)
306 {
307 LCD_SPI_setreg(0x06, 0x02);
308 }
309 else
310 {
311 LCD_SPI_setreg(0x06, 0x04);
312 }
313 LCD_SPI_stop();
314}
315
Karl Kurbjun4c99f9a2008-05-21 03:50:48 +0000316int lcd_default_contrast(void)
317{
318 return DEFAULT_CONTRAST_SETTING;
319}
320
321void lcd_set_contrast(int val) {
322 if (!lcd_on)
323 return;
324
325 LCD_SPI_start();
326 LCD_SPI_setreg(0x0B, (unsigned char) val);
327 LCD_SPI_stop();
328}
329
Karl Kurbjun7a4d1602008-05-21 03:30:57 +0000330void lcd_set_invert_display(bool yesno) {
331 if (!lcd_on)
332 return;
333
334 LCD_SPI_start();
335 if(yesno)
336 {
337 LCD_SPI_setreg(0x27, 0x10);
338 }
339 else
340 {
341 LCD_SPI_setreg(0x27, 0x00);
342 }
343 LCD_SPI_stop();
344}
345
Marcoen Hirschbergdd754882006-08-12 08:01:54 +0000346/* Update a fraction of the display. */
347void lcd_update_rect(int x, int y, int width, int height)
348{
Michael Sevakis897c6432007-07-08 17:10:22 +0000349 fb_data *dst, *src;
Greg White9d0faed2007-01-04 11:43:33 +0000350
Michael Sevakis897c6432007-07-08 17:10:22 +0000351 if (!lcd_on)
Greg White9d0faed2007-01-04 11:43:33 +0000352 return;
Michael Sevakis897c6432007-07-08 17:10:22 +0000353
354 if (x + width > LCD_WIDTH)
355 width = LCD_WIDTH - x; /* Clip right */
356 if (x < 0)
357 width += x, x = 0; /* Clip left */
358 if (width <= 0)
359 return; /* nothing left to do */
360
361 if (y + height > LCD_HEIGHT)
362 height = LCD_HEIGHT - y; /* Clip bottom */
363 if (y < 0)
364 height += y, y = 0; /* Clip top */
365 if (height <= 0)
366 return; /* nothing left to do */
367
368 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
369 * and lcd_framebuffer */
370 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
371 src = &lcd_framebuffer[y][x];
372
373 /* Copy part of the Rockbox framebuffer to the second framebuffer */
374 if (width < LCD_WIDTH)
375 {
376 /* Not full width - do line-by-line */
377 lcd_copy_buffer_rect(dst, src, width, height);
Greg White9d0faed2007-01-04 11:43:33 +0000378 }
Michael Sevakis897c6432007-07-08 17:10:22 +0000379 else
380 {
381 /* Full width - copy as one line */
382 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
383 }
Greg White9d0faed2007-01-04 11:43:33 +0000384}
385
Marcoen Hirschbergdd754882006-08-12 08:01:54 +0000386/* Update the display.
387 This must be called after all other LCD functions that change the display. */
388void lcd_update(void)
389{
Michael Sevakis897c6432007-07-08 17:10:22 +0000390 if (!lcd_on)
391 return;
392
393 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
394 LCD_WIDTH*LCD_HEIGHT, 1);
Marcoen Hirschbergdd754882006-08-12 08:01:54 +0000395}
Dave Chapman7fe74272006-08-12 09:27:26 +0000396
Greg White69bb4362007-01-15 13:07:47 +0000397void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
398 int stride, int x, int y, int width,
399 int height)
400{
Michael Sevakis2e6723b2007-07-09 03:53:12 +0000401 int w, px;
402 fb_data *dst;
Greg White69bb4362007-01-15 13:07:47 +0000403
Dave Chapman4d58b0d2008-03-05 08:12:54 +0000404 if (x + width > current_vp->width)
405 width = current_vp->width - x; /* Clip right */
Michael Sevakis897c6432007-07-08 17:10:22 +0000406 if (x < 0)
407 width += x, x = 0; /* Clip left */
408 if (width <= 0)
409 return; /* nothing left to do */
410
Dave Chapman4d58b0d2008-03-05 08:12:54 +0000411 if (y + height > current_vp->height)
412 height = current_vp->height - y; /* Clip bottom */
Michael Sevakis897c6432007-07-08 17:10:22 +0000413 if (y < 0)
414 height += y, y = 0; /* Clip top */
415 if (height <= 0)
416 return; /* nothing left to do */
Greg White69bb4362007-01-15 13:07:47 +0000417
418 src += stride * src_y + src_x; /* move starting point */
Dave Chapman4d58b0d2008-03-05 08:12:54 +0000419 dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x];
Michael Sevakis2e6723b2007-07-09 03:53:12 +0000420
421 asm volatile (
422 ".rowstart: \r\n"
423 "mov %[w], %[width] \r\n" /* Load width for inner loop */
424 ".nextpixel: \r\n"
425 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
426 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
Michael Sevakisd2194912007-07-15 01:06:04 +0000427 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
428 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
429 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
Michael Sevakis2e6723b2007-07-09 03:53:12 +0000430 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
431 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
432 "bgt .nextpixel \r\n" /* More in this row? */
433 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
434 "add %[d], %[d], %[dstp], lsl #1 \r\n"
435 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
436 "bgt .rowstart \r\n" /* More rows? */
437 : [w]"=&r"(w), [h]"+&r"(height), [px]"=&r"(px),
438 [s]"+&r"(src), [d]"+&r"(dst)
439 : [width]"r"(width),
440 [sstp]"r"(stride - width),
441 [dstp]"r"(LCD_WIDTH - width),
Michael Sevakisd2194912007-07-15 01:06:04 +0000442 [transcolor]"r"(TRANSPARENT_COLOR),
443 [fgcolor]"r"(REPLACEWITHFG_COLOR),
Dave Chapman945c8a22008-01-07 20:34:11 +0000444 [fgpat]"r"(current_vp->fg_pattern)
Michael Sevakis2e6723b2007-07-09 03:53:12 +0000445 );
Greg White69bb4362007-01-15 13:07:47 +0000446}
447
Michael Sevakis287d6222007-09-25 02:59:42 +0000448void lcd_yuv_set_options(unsigned options)
449{
450 lcd_yuv_options = options;
451}
452
Michael Sevakis6f566072007-04-02 09:27:12 +0000453/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
454extern void lcd_write_yuv420_lines(fb_data *dst,
Michael Sevakis6f566072007-04-02 09:27:12 +0000455 unsigned char const * const src[3],
456 int width,
457 int stride);
Michael Sevakis287d6222007-09-25 02:59:42 +0000458extern void lcd_write_yuv420_lines_odither(fb_data *dst,
459 unsigned char const * const src[3],
460 int width,
461 int stride,
462 int x_screen, /* To align dither pattern */
463 int y_screen);
Dave Chapman7fe74272006-08-12 09:27:26 +0000464/* Performance function to blit a YUV bitmap directly to the LCD */
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000465/* For the Gigabeat - show it rotated */
466/* So the LCD_WIDTH is now the height */
Jens Arnold68a21682008-03-24 00:35:53 +0000467void lcd_blit_yuv(unsigned char * const src[3],
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000468 int src_x, int src_y, int stride,
469 int x, int y, int width, int height)
470{
Michael Sevakis6f566072007-04-02 09:27:12 +0000471 /* Caches for chroma data so it only need be recaculated every other
472 line */
Michael Sevakis6f566072007-04-02 09:27:12 +0000473 unsigned char const * yuv_src[3];
474 off_t z;
475
476 if (!lcd_on)
477 return;
478
479 /* Sorry, but width and height must be >= 2 or else */
480 width &= ~1;
481 height >>= 1;
482
Michael Sevakis287d6222007-09-25 02:59:42 +0000483 y = LCD_WIDTH - 1 - y;
484 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000485
Michael Sevakis6f566072007-04-02 09:27:12 +0000486 z = stride*src_y;
487 yuv_src[0] = src[0] + z + src_x;
488 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
489 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
490
Michael Sevakis287d6222007-09-25 02:59:42 +0000491 if (lcd_yuv_options & LCD_YUV_DITHER)
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000492 {
Michael Sevakis287d6222007-09-25 02:59:42 +0000493 do
494 {
495 lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x);
496 yuv_src[0] += stride << 1; /* Skip down two luma lines */
497 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
498 yuv_src[2] += stride >> 1;
499 dst -= 2;
500 y -= 2;
501 }
502 while (--height > 0);
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000503 }
Michael Sevakis287d6222007-09-25 02:59:42 +0000504 else
505 {
506 do
507 {
508 lcd_write_yuv420_lines(dst, yuv_src, width, stride);
509 yuv_src[0] += stride << 1; /* Skip down two luma lines */
510 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
511 yuv_src[2] += stride >> 1;
512 dst -= 2;
513 }
514 while (--height > 0);
515 }
Marcoen Hirschberg29536762006-12-29 02:49:12 +0000516}
517