Nils Wallménius | ad5c4b6 | 2008-05-08 16:47:24 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Will Robertson |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * 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énius | ad5c4b6 | 2008-05-08 16:47:24 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 22 | #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 | |
| 31 | static volatile bool lcd_on = true; |
| 32 | volatile bool lcd_poweroff = false; |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 33 | static unsigned lcd_yuv_options = 0; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 34 | /* |
Michael Sevakis | 595d065 | 2008-04-15 13:06:29 +0000 | [diff] [blame] | 35 | ** This is imported from lcd-16bit.c |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 36 | */ |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 37 | extern struct viewport* current_vp; |
| 38 | |
Michael Sevakis | 595d065 | 2008-04-15 13:06:29 +0000 | [diff] [blame] | 39 | /* 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. */ |
| 42 | extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, |
| 43 | int width, int height); |
| 44 | |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 45 | #if 0 |
| 46 | bool lcd_enabled() |
| 47 | { |
| 48 | return lcd_on; |
| 49 | } |
| 50 | #endif |
| 51 | |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 52 | /* LCD init */ |
| 53 | void lcd_init_device(void) |
| 54 | { |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /* Update a fraction of the display. */ |
| 58 | void lcd_update_rect(int x, int y, int width, int height) |
| 59 | { |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 60 | fb_data *dst, *src; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 61 | |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 62 | if (!lcd_on) |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 63 | return; |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 64 | |
| 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 89 | } |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 90 | else |
| 91 | { |
| 92 | /* Full width - copy as one line */ |
| 93 | lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); |
| 94 | } |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void lcd_enable(bool state) |
| 98 | { |
| 99 | (void)state; |
| 100 | } |
| 101 | |
| 102 | bool 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. */ |
| 109 | void lcd_update(void) |
| 110 | { |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 111 | 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void 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 Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 122 | int w, px; |
| 123 | fb_data *dst; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 124 | |
Michael Sevakis | 595d065 | 2008-04-15 13:06:29 +0000 | [diff] [blame] | 125 | if (x + width > current_vp->width) |
| 126 | width = current_vp->width - x; /* Clip right */ |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 127 | if (x < 0) |
| 128 | width += x, x = 0; /* Clip left */ |
| 129 | if (width <= 0) |
| 130 | return; /* nothing left to do */ |
| 131 | |
Michael Sevakis | 595d065 | 2008-04-15 13:06:29 +0000 | [diff] [blame] | 132 | if (y + height > current_vp->height) |
| 133 | height = current_vp->height - y; /* Clip bottom */ |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 134 | if (y < 0) |
| 135 | height += y, y = 0; /* Clip top */ |
| 136 | if (height <= 0) |
| 137 | return; /* nothing left to do */ |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 138 | |
| 139 | src += stride * src_y + src_x; /* move starting point */ |
Michael Sevakis | 595d065 | 2008-04-15 13:06:29 +0000 | [diff] [blame] | 140 | dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x]; |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 141 | |
| 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 Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void lcd_yuv_set_options(unsigned options) |
| 170 | { |
| 171 | lcd_yuv_options = options; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ |
| 175 | extern void lcd_write_yuv420_lines(fb_data *dst, |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 176 | unsigned char const * const src[3], |
| 177 | int width, |
| 178 | int stride); |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 179 | extern 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 185 | /* 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 Arnold | 68a2168 | 2008-03-24 00:35:53 +0000 | [diff] [blame] | 188 | void lcd_blit_yuv(unsigned char * const src[3], |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 189 | 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 194 | 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 Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 204 | y = LCD_WIDTH - 1 - y; |
| 205 | fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y; |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 206 | |
| 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 Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 212 | if (lcd_yuv_options & LCD_YUV_DITHER) |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 213 | { |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 214 | 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 224 | } |
Michael Sevakis | 1f021af | 2008-02-05 04:43:19 +0000 | [diff] [blame] | 225 | 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 Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void lcd_set_contrast(int val) { |
| 240 | (void) val; |
| 241 | // TODO: |
| 242 | } |
| 243 | |
| 244 | void lcd_set_invert_display(bool yesno) { |
| 245 | (void) yesno; |
| 246 | // TODO: |
| 247 | } |
| 248 | |
Will Robertson | 590501c | 2007-09-21 15:51:53 +0000 | [diff] [blame] | 249 | void lcd_set_flip(bool yesno) { |
| 250 | (void) yesno; |
| 251 | // TODO: |
| 252 | } |
| 253 | |