blob: 14d83bf1384497d1be832bde03d413b41010b2f8 [file] [log] [blame]
Nils Wallméniusad5c4b62008-05-08 16:47:24 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Will Robertson
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.
Nils Wallméniusad5c4b62008-05-08 16:47:24 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Will Robertson590501c2007-09-21 15:51:53 +000022#include "config.h"
23#include "cpu.h"
24#include "string.h"
25#include "lcd.h"
26#include "kernel.h"
27#include "lcd-target.h"
28
29#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
30
31static volatile bool lcd_on = true;
32volatile bool lcd_poweroff = false;
Michael Sevakis1f021af2008-02-05 04:43:19 +000033static unsigned lcd_yuv_options = 0;
Will Robertson590501c2007-09-21 15:51:53 +000034/*
Michael Sevakis595d0652008-04-15 13:06:29 +000035** This is imported from lcd-16bit.c
Will Robertson590501c2007-09-21 15:51:53 +000036*/
Michael Sevakis1f021af2008-02-05 04:43:19 +000037extern struct viewport* current_vp;
38
Michael Sevakis595d0652008-04-15 13:06:29 +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
Will Robertson590501c2007-09-21 15:51:53 +000045#if 0
46bool lcd_enabled()
47{
48 return lcd_on;
49}
50#endif
51
Will Robertson590501c2007-09-21 15:51:53 +000052/* LCD init */
53void lcd_init_device(void)
54{
Will Robertson590501c2007-09-21 15:51:53 +000055}
56
57/* Update a fraction of the display. */
58void lcd_update_rect(int x, int y, int width, int height)
59{
Michael Sevakis1f021af2008-02-05 04:43:19 +000060 fb_data *dst, *src;
Will Robertson590501c2007-09-21 15:51:53 +000061
Michael Sevakis1f021af2008-02-05 04:43:19 +000062 if (!lcd_on)
Will Robertson590501c2007-09-21 15:51:53 +000063 return;
Michael Sevakis1f021af2008-02-05 04:43:19 +000064
65 if (x + width > LCD_WIDTH)
66 width = LCD_WIDTH - x; /* Clip right */
67 if (x < 0)
68 width += x, x = 0; /* Clip left */
69 if (width <= 0)
70 return; /* nothing left to do */
71
72 if (y + height > LCD_HEIGHT)
73 height = LCD_HEIGHT - y; /* Clip bottom */
74 if (y < 0)
75 height += y, y = 0; /* Clip top */
76 if (height <= 0)
77 return; /* nothing left to do */
78
79 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
80 * and lcd_framebuffer */
81 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
82 src = &lcd_framebuffer[y][x];
83
84 /* Copy part of the Rockbox framebuffer to the second framebuffer */
85 if (width < LCD_WIDTH)
86 {
87 /* Not full width - do line-by-line */
88 lcd_copy_buffer_rect(dst, src, width, height);
Will Robertson590501c2007-09-21 15:51:53 +000089 }
Michael Sevakis1f021af2008-02-05 04:43:19 +000090 else
91 {
92 /* Full width - copy as one line */
93 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
94 }
Will Robertson590501c2007-09-21 15:51:53 +000095}
96
97void lcd_enable(bool state)
98{
99 (void)state;
100}
101
102bool lcd_enabled(void)
103{
104 return true;
105}
106
107/* Update the display.
108 This must be called after all other LCD functions that change the display. */
109void lcd_update(void)
110{
Michael Sevakis1f021af2008-02-05 04:43:19 +0000111 if (!lcd_on)
112 return;
113
114 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
115 LCD_WIDTH*LCD_HEIGHT, 1);
Will Robertson590501c2007-09-21 15:51:53 +0000116}
117
118void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
119 int stride, int x, int y, int width,
120 int height)
121{
Michael Sevakis1f021af2008-02-05 04:43:19 +0000122 int w, px;
123 fb_data *dst;
Will Robertson590501c2007-09-21 15:51:53 +0000124
Michael Sevakis595d0652008-04-15 13:06:29 +0000125 if (x + width > current_vp->width)
126 width = current_vp->width - x; /* Clip right */
Michael Sevakis1f021af2008-02-05 04:43:19 +0000127 if (x < 0)
128 width += x, x = 0; /* Clip left */
129 if (width <= 0)
130 return; /* nothing left to do */
131
Michael Sevakis595d0652008-04-15 13:06:29 +0000132 if (y + height > current_vp->height)
133 height = current_vp->height - y; /* Clip bottom */
Michael Sevakis1f021af2008-02-05 04:43:19 +0000134 if (y < 0)
135 height += y, y = 0; /* Clip top */
136 if (height <= 0)
137 return; /* nothing left to do */
Will Robertson590501c2007-09-21 15:51:53 +0000138
139 src += stride * src_y + src_x; /* move starting point */
Michael Sevakis595d0652008-04-15 13:06:29 +0000140 dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x];
Michael Sevakis1f021af2008-02-05 04:43:19 +0000141
142 asm volatile (
143 ".rowstart: \r\n"
144 "mov %[w], %[width] \r\n" /* Load width for inner loop */
145 ".nextpixel: \r\n"
146 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
147 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
148 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
149 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
150 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
151 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
152 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
153 "bgt .nextpixel \r\n" /* More in this row? */
154 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
155 "add %[d], %[d], %[dstp], lsl #1 \r\n"
156 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
157 "bgt .rowstart \r\n" /* More rows? */
158 : [w]"=&r"(w), [h]"+&r"(height), [px]"=&r"(px),
159 [s]"+&r"(src), [d]"+&r"(dst)
160 : [width]"r"(width),
161 [sstp]"r"(stride - width),
162 [dstp]"r"(LCD_WIDTH - width),
163 [transcolor]"r"(TRANSPARENT_COLOR),
164 [fgcolor]"r"(REPLACEWITHFG_COLOR),
165 [fgpat]"r"(current_vp->fg_pattern)
166 );
Michael Sevakis1f021af2008-02-05 04:43:19 +0000167}
168
169void lcd_yuv_set_options(unsigned options)
170{
171 lcd_yuv_options = options;
Will Robertson590501c2007-09-21 15:51:53 +0000172}
173
174/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
175extern void lcd_write_yuv420_lines(fb_data *dst,
Will Robertson590501c2007-09-21 15:51:53 +0000176 unsigned char const * const src[3],
177 int width,
178 int stride);
Michael Sevakis1f021af2008-02-05 04:43:19 +0000179extern void lcd_write_yuv420_lines_odither(fb_data *dst,
180 unsigned char const * const src[3],
181 int width,
182 int stride,
183 int x_screen, /* To align dither pattern */
184 int y_screen);
Will Robertson590501c2007-09-21 15:51:53 +0000185/* Performance function to blit a YUV bitmap directly to the LCD */
186/* For the Gigabeat - show it rotated */
187/* So the LCD_WIDTH is now the height */
Jens Arnold68a21682008-03-24 00:35:53 +0000188void lcd_blit_yuv(unsigned char * const src[3],
Will Robertson590501c2007-09-21 15:51:53 +0000189 int src_x, int src_y, int stride,
190 int x, int y, int width, int height)
191{
192 /* Caches for chroma data so it only need be recaculated every other
193 line */
Will Robertson590501c2007-09-21 15:51:53 +0000194 unsigned char const * yuv_src[3];
195 off_t z;
196
197 if (!lcd_on)
198 return;
199
200 /* Sorry, but width and height must be >= 2 or else */
201 width &= ~1;
202 height >>= 1;
203
Michael Sevakis1f021af2008-02-05 04:43:19 +0000204 y = LCD_WIDTH - 1 - y;
205 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
Will Robertson590501c2007-09-21 15:51:53 +0000206
207 z = stride*src_y;
208 yuv_src[0] = src[0] + z + src_x;
209 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
210 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
211
Michael Sevakis1f021af2008-02-05 04:43:19 +0000212 if (lcd_yuv_options & LCD_YUV_DITHER)
Will Robertson590501c2007-09-21 15:51:53 +0000213 {
Michael Sevakis1f021af2008-02-05 04:43:19 +0000214 do
215 {
216 lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x);
217 yuv_src[0] += stride << 1; /* Skip down two luma lines */
218 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
219 yuv_src[2] += stride >> 1;
220 dst -= 2;
221 y -= 2;
222 }
223 while (--height > 0);
Will Robertson590501c2007-09-21 15:51:53 +0000224 }
Michael Sevakis1f021af2008-02-05 04:43:19 +0000225 else
226 {
227 do
228 {
229 lcd_write_yuv420_lines(dst, yuv_src, width, stride);
230 yuv_src[0] += stride << 1; /* Skip down two luma lines */
231 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
232 yuv_src[2] += stride >> 1;
233 dst -= 2;
234 }
235 while (--height > 0);
236 }
Will Robertson590501c2007-09-21 15:51:53 +0000237}
238
239void lcd_set_contrast(int val) {
240 (void) val;
241 // TODO:
242}
243
244void lcd_set_invert_display(bool yesno) {
245 (void) yesno;
246 // TODO:
247}
248
Will Robertson590501c2007-09-21 15:51:53 +0000249void lcd_set_flip(bool yesno) {
250 (void) yesno;
251 // TODO:
252}
253