Remove some cruft not being used that interferes with building rockboy on Gigabeat S.
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / lcd-imx31.c
blobea8b10b5829003c05fea456701e6e3fc16d0bf16
1 #include "config.h"
2 #include "cpu.h"
3 #include "string.h"
4 #include "lcd.h"
5 #include "kernel.h"
6 #include "lcd-target.h"
8 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
10 static volatile bool lcd_on = true;
11 volatile bool lcd_poweroff = false;
12 static unsigned lcd_yuv_options = 0;
14 ** This is imported from lcd-16bit.c
16 extern struct viewport* current_vp;
18 /* Copies a rectangle from one framebuffer to another. Can be used in
19 single transfer mode with width = num pixels, and height = 1 which
20 allows a full-width rectangle to be copied more efficiently. */
21 extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
22 int width, int height);
24 #if 0
25 bool lcd_enabled()
27 return lcd_on;
29 #endif
31 /* LCD init */
32 void lcd_init_device(void)
36 /* Update a fraction of the display. */
37 void lcd_update_rect(int x, int y, int width, int height)
39 fb_data *dst, *src;
41 if (!lcd_on)
42 return;
44 if (x + width > LCD_WIDTH)
45 width = LCD_WIDTH - x; /* Clip right */
46 if (x < 0)
47 width += x, x = 0; /* Clip left */
48 if (width <= 0)
49 return; /* nothing left to do */
51 if (y + height > LCD_HEIGHT)
52 height = LCD_HEIGHT - y; /* Clip bottom */
53 if (y < 0)
54 height += y, y = 0; /* Clip top */
55 if (height <= 0)
56 return; /* nothing left to do */
58 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
59 * and lcd_framebuffer */
60 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
61 src = &lcd_framebuffer[y][x];
63 /* Copy part of the Rockbox framebuffer to the second framebuffer */
64 if (width < LCD_WIDTH)
66 /* Not full width - do line-by-line */
67 lcd_copy_buffer_rect(dst, src, width, height);
69 else
71 /* Full width - copy as one line */
72 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
76 void lcd_enable(bool state)
78 (void)state;
81 bool lcd_enabled(void)
83 return true;
86 /* Update the display.
87 This must be called after all other LCD functions that change the display. */
88 void lcd_update(void)
90 if (!lcd_on)
91 return;
93 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
94 LCD_WIDTH*LCD_HEIGHT, 1);
97 void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
98 int stride, int x, int y, int width,
99 int height)
101 int w, px;
102 fb_data *dst;
104 if (x + width > current_vp->width)
105 width = current_vp->width - x; /* Clip right */
106 if (x < 0)
107 width += x, x = 0; /* Clip left */
108 if (width <= 0)
109 return; /* nothing left to do */
111 if (y + height > current_vp->height)
112 height = current_vp->height - y; /* Clip bottom */
113 if (y < 0)
114 height += y, y = 0; /* Clip top */
115 if (height <= 0)
116 return; /* nothing left to do */
118 src += stride * src_y + src_x; /* move starting point */
119 dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x];
121 asm volatile (
122 ".rowstart: \r\n"
123 "mov %[w], %[width] \r\n" /* Load width for inner loop */
124 ".nextpixel: \r\n"
125 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
126 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
127 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
128 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
129 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
130 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
131 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
132 "bgt .nextpixel \r\n" /* More in this row? */
133 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
134 "add %[d], %[d], %[dstp], lsl #1 \r\n"
135 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
136 "bgt .rowstart \r\n" /* More rows? */
137 : [w]"=&r"(w), [h]"+&r"(height), [px]"=&r"(px),
138 [s]"+&r"(src), [d]"+&r"(dst)
139 : [width]"r"(width),
140 [sstp]"r"(stride - width),
141 [dstp]"r"(LCD_WIDTH - width),
142 [transcolor]"r"(TRANSPARENT_COLOR),
143 [fgcolor]"r"(REPLACEWITHFG_COLOR),
144 [fgpat]"r"(current_vp->fg_pattern)
148 void lcd_yuv_set_options(unsigned options)
150 lcd_yuv_options = options;
153 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
154 extern void lcd_write_yuv420_lines(fb_data *dst,
155 unsigned char const * const src[3],
156 int width,
157 int stride);
158 extern void lcd_write_yuv420_lines_odither(fb_data *dst,
159 unsigned char const * const src[3],
160 int width,
161 int stride,
162 int x_screen, /* To align dither pattern */
163 int y_screen);
164 /* Performance function to blit a YUV bitmap directly to the LCD */
165 /* For the Gigabeat - show it rotated */
166 /* So the LCD_WIDTH is now the height */
167 void lcd_blit_yuv(unsigned char * const src[3],
168 int src_x, int src_y, int stride,
169 int x, int y, int width, int height)
171 /* Caches for chroma data so it only need be recaculated every other
172 line */
173 unsigned char const * yuv_src[3];
174 off_t z;
176 if (!lcd_on)
177 return;
179 /* Sorry, but width and height must be >= 2 or else */
180 width &= ~1;
181 height >>= 1;
183 y = LCD_WIDTH - 1 - y;
184 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y;
186 z = stride*src_y;
187 yuv_src[0] = src[0] + z + src_x;
188 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
189 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
191 if (lcd_yuv_options & LCD_YUV_DITHER)
195 lcd_write_yuv420_lines_odither(dst, yuv_src, width, stride, y, x);
196 yuv_src[0] += stride << 1; /* Skip down two luma lines */
197 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
198 yuv_src[2] += stride >> 1;
199 dst -= 2;
200 y -= 2;
202 while (--height > 0);
204 else
208 lcd_write_yuv420_lines(dst, yuv_src, width, stride);
209 yuv_src[0] += stride << 1; /* Skip down two luma lines */
210 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
211 yuv_src[2] += stride >> 1;
212 dst -= 2;
214 while (--height > 0);
218 void lcd_set_contrast(int val) {
219 (void) val;
220 // TODO:
223 void lcd_set_invert_display(bool yesno) {
224 (void) yesno;
225 // TODO:
228 void lcd_set_flip(bool yesno) {
229 (void) yesno;
230 // TODO: