Michael Sevakis | 2541302 | 2008-03-31 04:53:03 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Greg White |
| 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. |
Michael Sevakis | 2541302 | 2008-03-31 04:53:03 +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 | ****************************************************************************/ |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 21 | #include "config.h" |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 22 | #include "system.h" |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 23 | #include "cpu.h" |
Karl Kurbjun | f863ba6 | 2007-06-04 14:07:26 +0000 | [diff] [blame] | 24 | #include "string.h" |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 25 | #include "lcd.h" |
| 26 | #include "kernel.h" |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 27 | #include "lcd-target.h" |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 28 | |
Greg White | 69bb436 | 2007-01-15 13:07:47 +0000 | [diff] [blame] | 29 | #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)]) |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 30 | |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 31 | static bool lcd_on = true; |
| 32 | static bool lcd_powered = true; |
Michael Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 33 | static unsigned lcd_yuv_options = 0; |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 34 | /* |
Dave Chapman | 945c8a2 | 2008-01-07 20:34:11 +0000 | [diff] [blame] | 35 | ** This is imported from lcd-16bit.c |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 36 | */ |
Dave Chapman | 945c8a2 | 2008-01-07 20:34:11 +0000 | [diff] [blame] | 37 | extern struct viewport* current_vp; |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 38 | |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +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 | |
Michael Sevakis | 41b235d | 2008-05-14 20:26:20 +0000 | [diff] [blame] | 45 | bool lcd_enabled(void) |
Greg White | ffb50d0 | 2007-01-11 10:24:21 +0000 | [diff] [blame] | 46 | { |
| 47 | return lcd_on; |
| 48 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 49 | |
Greg White | 355be50 | 2007-01-13 02:24:15 +0000 | [diff] [blame] | 50 | unsigned int LCDBANK(unsigned int address) |
| 51 | { |
| 52 | return ((address >> 22) & 0xff); |
| 53 | } |
| 54 | |
| 55 | unsigned int LCDBASEU(unsigned int address) |
| 56 | { |
| 57 | return (address & ((1 << 22)-1)) >> 1; |
| 58 | } |
| 59 | |
| 60 | unsigned int LCDBASEL(unsigned int address) |
| 61 | { |
| 62 | address += 320*240*2; |
| 63 | return (address & ((1 << 22)-1)) >> 1; |
| 64 | } |
| 65 | |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 66 | inline void delay_cycles(volatile int delay) |
| 67 | { |
| 68 | while(delay>0) delay--; |
| 69 | } |
| 70 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 71 | static void LCD_CTRL_setup(void) |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 72 | { |
| 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 Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 93 | static void LCD_CTRL_clock(bool onoff) |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 94 | { |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 95 | if(onoff) |
| 96 | { |
| 97 | GPCCON &= ~0xFFF000FC; |
| 98 | GPDCON &= ~0xFFF0FFF0; |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 99 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 100 | GPCCON |= 0xAAA000A8; |
| 101 | GPCUP |= 0xFC0E; |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 102 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 103 | GPDCON |= 0xAAA0AAA0; |
| 104 | GPDUP |= 0xFCFC; |
| 105 | |
| 106 | s3c_regset(&CLKCON, 0x20); /* enable LCD clock */ |
| 107 | LCDCON1 |=0x01; |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 108 | } |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 109 | else |
| 110 | { |
| 111 | GPCCON &= ~0xFFF000FC; |
| 112 | GPCUP &= ~0xFC0E; |
Karl Kurbjun | 8a1fd8c | 2007-04-21 04:48:20 +0000 | [diff] [blame] | 113 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 114 | GPDCON &= ~0xFFF0FFF0; |
| 115 | GPDUP &= ~0xFCFC; |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 116 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 117 | LCDCON1 &= ~1; /* Must diable first or bus may freeze */ |
| 118 | s3c_regclr(&CLKCON, 0x20); /* disable LCD clock */ |
| 119 | } |
| 120 | } |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 121 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 122 | static void reset_LCD(bool reset) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 123 | { |
| 124 | GPBCON&=~0xC000; |
| 125 | GPBCON|=0x4000; |
| 126 | if(reset) |
| 127 | GPBDAT|=0x80; |
| 128 | else |
| 129 | GPBDAT&=~0x80; |
| 130 | } |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 131 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 132 | static void LCD_SPI_send(const unsigned char *array, int count) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 133 | { |
| 134 | while (count--) |
| 135 | { |
| 136 | while ((SPSTA0&0x01)==0){}; |
| 137 | SPTDAT0=*array++; |
| 138 | } |
| 139 | } |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 140 | |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 141 | void 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 Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 150 | static void LCD_SPI_SS(bool select) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 151 | { |
| 152 | delay_cycles(0x4FFF); |
Greg White | ffb50d0 | 2007-01-11 10:24:21 +0000 | [diff] [blame] | 153 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 154 | GPBCON&=~0x30000; |
| 155 | GPBCON|=0x10000; |
Michael Sevakis | a65406e | 2008-03-31 01:29:50 +0000 | [diff] [blame] | 156 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 157 | if(select) |
| 158 | GPBDAT|=0x100; |
| 159 | else |
| 160 | GPBDAT&=~0x100; |
| 161 | } |
Karl Kurbjun | f863ba6 | 2007-06-04 14:07:26 +0000 | [diff] [blame] | 162 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 163 | void 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 Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 169 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 170 | reset_LCD(true); |
| 171 | LCD_SPI_SS(true); |
| 172 | } |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 173 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 174 | void LCD_SPI_stop(void) |
| 175 | { |
| 176 | LCD_SPI_SS(false); |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 177 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 178 | SPCON0 &= ~0x10; |
| 179 | s3c_regclr(&CLKCON, 0x40000); /* disable SPI clock */ |
| 180 | } |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 181 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 182 | static void LCD_SPI_powerdown(void) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 183 | { |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 184 | lcd_powered = false; |
| 185 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 186 | LCD_SPI_start(); |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 187 | LCD_SPI_setreg(0x04, 0x00); |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 188 | LCD_SPI_stop(); |
| 189 | |
| 190 | reset_LCD(false); /* This makes a big difference on power */ |
| 191 | LCD_CTRL_clock(false); |
| 192 | } |
| 193 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 194 | static void LCD_SPI_powerup(void) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 195 | { |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 196 | LCD_CTRL_clock(true); |
| 197 | |
| 198 | LCD_SPI_start(); |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 199 | LCD_SPI_setreg(0x04, 0x01); |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 200 | LCD_SPI_stop(); |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 201 | |
| 202 | lcd_powered = true; |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 205 | static void LCD_SPI_init(void) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 206 | { |
Karl Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 207 | /* |
| 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 Kurbjun | f863ba6 | 2007-06-04 14:07:26 +0000 | [diff] [blame] | 211 | */ |
Karl Kurbjun | f863ba6 | 2007-06-04 14:07:26 +0000 | [diff] [blame] | 212 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 213 | LCD_CTRL_clock(true); |
Karl Kurbjun | 94bd1f7 | 2008-02-13 05:46:04 +0000 | [diff] [blame] | 214 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 215 | LCD_SPI_start(); |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 216 | 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 Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 241 | LCD_SPI_stop(); |
| 242 | } |
| 243 | |
| 244 | /* LCD init */ |
| 245 | void 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 Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 256 | s3c_regset(&CLKCON, 0x20); /* enable LCD clock */ |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 257 | |
| 258 | LCD_CTRL_setup(); |
| 259 | LCD_SPI_init(); |
| 260 | } |
| 261 | |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 262 | void 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 Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 274 | void lcd_enable(bool state) |
| 275 | { |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 276 | if (state == lcd_on) |
| 277 | return; |
| 278 | |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 279 | if(state) |
| 280 | { |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 281 | /* "enabled" implies "powered" */ |
| 282 | if (!lcd_powered) |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 283 | { |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 284 | LCD_SPI_powerup(); |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 285 | /* Wait long enough for a frame to be written - yes, it |
| 286 | * takes awhile. */ |
| 287 | sleep(HZ/5); |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 288 | } |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 289 | |
| 290 | lcd_on = true; |
| 291 | lcd_update(); |
Michael Sevakis | adf2e4c | 2008-05-28 10:17:16 +0000 | [diff] [blame] | 292 | lcd_call_enable_hook(); |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 293 | } |
| 294 | else |
| 295 | { |
Michael Sevakis | 009cebe | 2008-05-14 19:29:25 +0000 | [diff] [blame] | 296 | lcd_on = false; |
Karl Kurbjun | 6e322c8 | 2008-05-14 00:26:28 +0000 | [diff] [blame] | 297 | } |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 300 | void lcd_set_flip(bool yesno) { |
| 301 | if (!lcd_on) |
| 302 | return; |
| 303 | |
Karl Kurbjun | 3590456 | 2008-05-18 23:33:09 +0000 | [diff] [blame] | 304 | 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 Kurbjun | 4c99f9a | 2008-05-21 03:50:48 +0000 | [diff] [blame] | 316 | int lcd_default_contrast(void) |
| 317 | { |
| 318 | return DEFAULT_CONTRAST_SETTING; |
| 319 | } |
| 320 | |
| 321 | void 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 Kurbjun | 7a4d160 | 2008-05-21 03:30:57 +0000 | [diff] [blame] | 330 | void 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 Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 346 | /* Update a fraction of the display. */ |
| 347 | void lcd_update_rect(int x, int y, int width, int height) |
| 348 | { |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 349 | fb_data *dst, *src; |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 350 | |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 351 | if (!lcd_on) |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 352 | return; |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 353 | |
| 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 White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 378 | } |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 379 | else |
| 380 | { |
| 381 | /* Full width - copy as one line */ |
| 382 | lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); |
| 383 | } |
Greg White | 9d0faed | 2007-01-04 11:43:33 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 386 | /* Update the display. |
| 387 | This must be called after all other LCD functions that change the display. */ |
| 388 | void lcd_update(void) |
| 389 | { |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 390 | 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 Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 395 | } |
Dave Chapman | 7fe7427 | 2006-08-12 09:27:26 +0000 | [diff] [blame] | 396 | |
Greg White | 69bb436 | 2007-01-15 13:07:47 +0000 | [diff] [blame] | 397 | void 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 Sevakis | 2e6723b | 2007-07-09 03:53:12 +0000 | [diff] [blame] | 401 | int w, px; |
| 402 | fb_data *dst; |
Greg White | 69bb436 | 2007-01-15 13:07:47 +0000 | [diff] [blame] | 403 | |
Dave Chapman | 4d58b0d | 2008-03-05 08:12:54 +0000 | [diff] [blame] | 404 | if (x + width > current_vp->width) |
| 405 | width = current_vp->width - x; /* Clip right */ |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 406 | if (x < 0) |
| 407 | width += x, x = 0; /* Clip left */ |
| 408 | if (width <= 0) |
| 409 | return; /* nothing left to do */ |
| 410 | |
Dave Chapman | 4d58b0d | 2008-03-05 08:12:54 +0000 | [diff] [blame] | 411 | if (y + height > current_vp->height) |
| 412 | height = current_vp->height - y; /* Clip bottom */ |
Michael Sevakis | 897c643 | 2007-07-08 17:10:22 +0000 | [diff] [blame] | 413 | if (y < 0) |
| 414 | height += y, y = 0; /* Clip top */ |
| 415 | if (height <= 0) |
| 416 | return; /* nothing left to do */ |
Greg White | 69bb436 | 2007-01-15 13:07:47 +0000 | [diff] [blame] | 417 | |
| 418 | src += stride * src_y + src_x; /* move starting point */ |
Dave Chapman | 4d58b0d | 2008-03-05 08:12:54 +0000 | [diff] [blame] | 419 | dst = &lcd_framebuffer[current_vp->y+y][current_vp->x+x]; |
Michael Sevakis | 2e6723b | 2007-07-09 03:53:12 +0000 | [diff] [blame] | 420 | |
| 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 Sevakis | d219491 | 2007-07-15 01:06:04 +0000 | [diff] [blame] | 427 | "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 Sevakis | 2e6723b | 2007-07-09 03:53:12 +0000 | [diff] [blame] | 430 | "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 Sevakis | d219491 | 2007-07-15 01:06:04 +0000 | [diff] [blame] | 442 | [transcolor]"r"(TRANSPARENT_COLOR), |
| 443 | [fgcolor]"r"(REPLACEWITHFG_COLOR), |
Dave Chapman | 945c8a2 | 2008-01-07 20:34:11 +0000 | [diff] [blame] | 444 | [fgpat]"r"(current_vp->fg_pattern) |
Michael Sevakis | 2e6723b | 2007-07-09 03:53:12 +0000 | [diff] [blame] | 445 | ); |
Greg White | 69bb436 | 2007-01-15 13:07:47 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Michael Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 448 | void lcd_yuv_set_options(unsigned options) |
| 449 | { |
| 450 | lcd_yuv_options = options; |
| 451 | } |
| 452 | |
Michael Sevakis | 6f56607 | 2007-04-02 09:27:12 +0000 | [diff] [blame] | 453 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ |
| 454 | extern void lcd_write_yuv420_lines(fb_data *dst, |
Michael Sevakis | 6f56607 | 2007-04-02 09:27:12 +0000 | [diff] [blame] | 455 | unsigned char const * const src[3], |
| 456 | int width, |
| 457 | int stride); |
Michael Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 458 | extern 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 Chapman | 7fe7427 | 2006-08-12 09:27:26 +0000 | [diff] [blame] | 464 | /* Performance function to blit a YUV bitmap directly to the LCD */ |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 465 | /* For the Gigabeat - show it rotated */ |
| 466 | /* So the LCD_WIDTH is now the height */ |
Jens Arnold | 68a2168 | 2008-03-24 00:35:53 +0000 | [diff] [blame] | 467 | void lcd_blit_yuv(unsigned char * const src[3], |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 468 | int src_x, int src_y, int stride, |
| 469 | int x, int y, int width, int height) |
| 470 | { |
Michael Sevakis | 6f56607 | 2007-04-02 09:27:12 +0000 | [diff] [blame] | 471 | /* Caches for chroma data so it only need be recaculated every other |
| 472 | line */ |
Michael Sevakis | 6f56607 | 2007-04-02 09:27:12 +0000 | [diff] [blame] | 473 | 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 Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 483 | y = LCD_WIDTH - 1 - y; |
| 484 | fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + y; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 485 | |
Michael Sevakis | 6f56607 | 2007-04-02 09:27:12 +0000 | [diff] [blame] | 486 | 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 Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 491 | if (lcd_yuv_options & LCD_YUV_DITHER) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 492 | { |
Michael Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 493 | 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 Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 503 | } |
Michael Sevakis | 287d622 | 2007-09-25 02:59:42 +0000 | [diff] [blame] | 504 | 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 Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 516 | } |
| 517 | |