Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Rockbox driver for iPod LCDs |
| 11 | * |
| 12 | * Based on code from the ipodlinux project - http://ipodlinux.org/ |
| 13 | * Adapted for Rockbox in November 2005 |
| 14 | * |
| 15 | * Original file: linux/arch/armnommu/mach-ipod/fb.c |
| 16 | * |
| 17 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) |
| 18 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 19 | * This program is free software; you can redistribute it and/or |
| 20 | * modify it under the terms of the GNU General Public License |
| 21 | * as published by the Free Software Foundation; either version 2 |
| 22 | * of the License, or (at your option) any later version. |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 23 | * |
| 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 25 | * KIND, either express or implied. |
| 26 | * |
| 27 | ****************************************************************************/ |
| 28 | #include "config.h" |
| 29 | #include "cpu.h" |
| 30 | #include "lcd.h" |
| 31 | #include "kernel.h" |
| 32 | #include "system.h" |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 33 | #include "hwcompat.h" |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 34 | |
Jens Arnold | 92abed7 | 2007-08-08 07:57:34 +0000 | [diff] [blame] | 35 | /* LCD command codes for HD66753 */ |
| 36 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 37 | #define R_START_OSC 0x00 |
| 38 | #define R_DRV_OUTPUT_CONTROL 0x01 |
| 39 | #define R_DRV_WAVEFORM_CONTROL 0x02 |
| 40 | #define R_POWER_CONTROL 0x03 |
| 41 | #define R_CONTRAST_CONTROL 0x04 |
| 42 | #define R_ENTRY_MODE 0x05 |
| 43 | #define R_ROTATION 0x06 |
| 44 | #define R_DISPLAY_CONTROL 0x07 |
| 45 | #define R_CURSOR_CONTROL 0x08 |
| 46 | #define R_HORIZONTAL_CURSOR_POS 0x0b |
| 47 | #define R_VERTICAL_CURSOR_POS 0x0c |
| 48 | #define R_1ST_SCR_DRV_POS 0x0d |
| 49 | #define R_2ND_SCR_DRV_POS 0x0e |
| 50 | #define R_RAM_WRITE_MASK 0x10 |
| 51 | #define R_RAM_ADDR_SET 0x11 |
| 52 | #define R_RAM_DATA 0x12 |
| 53 | |
Jens Arnold | 021c086 | 2007-07-27 12:05:54 +0000 | [diff] [blame] | 54 | #ifdef HAVE_BACKLIGHT_INVERSION |
| 55 | /* The backlight makes the LCD appear negative on the 1st/2nd gen */ |
| 56 | static bool lcd_inverted = false; |
| 57 | static bool lcd_backlit = false; |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 58 | #if NUM_CORES > 1 |
| 59 | /* invert_display() and the lcd_blit_* functions need to be corelocked */ |
| 60 | static struct corelock cl IBSS_ATTR; |
| 61 | #endif |
Jens Arnold | 41534a9 | 2007-07-27 12:40:36 +0000 | [diff] [blame] | 62 | static void invert_display(void); |
Jens Arnold | 021c086 | 2007-07-27 12:05:54 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 65 | #if defined(IPOD_1G2G) || defined(IPOD_3G) |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 66 | #define POWER_REG_H 0x1120 /* 1/7 Bias, 5x step-up @ clk/8 */ |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 67 | #else |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 68 | #define POWER_REG_H 0x1200 /* 1/7 Bias, 6x step-up @ clk/32 */ |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 71 | #define CONTRAST_REG_H 0x400 |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 72 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 73 | /* needed for flip */ |
| 74 | static int addr_offset; |
| 75 | #if defined(IPOD_MINI) || defined(IPOD_MINI2G) |
| 76 | static int pix_offset; |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 77 | void lcd_write_data_shifted(const fb_data* p_bytes, int count); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 78 | #endif |
| 79 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 80 | /* wait for LCD with timeout */ |
| 81 | static inline void lcd_wait_write(void) |
| 82 | { |
Jens Arnold | 8aeed2d | 2007-10-12 00:28:57 +0000 | [diff] [blame] | 83 | while (LCD1_CONTROL & LCD1_BUSY_MASK); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 86 | /* send LCD command */ |
| 87 | static void lcd_prepare_cmd(unsigned cmd) |
| 88 | { |
| 89 | lcd_wait_write(); |
| 90 | #ifdef IPOD_MINI2G |
Jens Arnold | 1f0d06f | 2007-10-07 16:44:55 +0000 | [diff] [blame] | 91 | LCD1_CMD = cmd | 0x740000; |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 92 | #else |
Jens Arnold | 1f0d06f | 2007-10-07 16:44:55 +0000 | [diff] [blame] | 93 | LCD1_CMD = 0; |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 94 | lcd_wait_write(); |
Jens Arnold | 1f0d06f | 2007-10-07 16:44:55 +0000 | [diff] [blame] | 95 | LCD1_CMD = cmd; |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 96 | #endif |
| 97 | } |
| 98 | |
| 99 | /* send LCD command and data */ |
| 100 | static void lcd_cmd_and_data(unsigned cmd, unsigned data) |
| 101 | { |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 102 | lcd_wait_write(); |
| 103 | #ifdef IPOD_MINI2G |
| 104 | LCD1_CMD = cmd | 0x740000; |
| 105 | lcd_wait_write(); |
| 106 | LCD1_CMD = data | 0x760000; |
| 107 | #else |
| 108 | LCD1_CMD = 0; |
| 109 | lcd_wait_write(); |
| 110 | LCD1_CMD = cmd; |
| 111 | lcd_wait_write(); |
| 112 | LCD1_DATA = data >> 8; |
| 113 | lcd_wait_write(); |
| 114 | LCD1_DATA = data & 0xff; |
| 115 | #endif |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* LCD init */ |
| 119 | void lcd_init_device(void) |
| 120 | { |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 121 | #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) |
| 122 | corelock_init(&cl); |
| 123 | #endif |
Jens Arnold | 6ef2db2 | 2007-11-18 12:49:24 +0000 | [diff] [blame] | 124 | #ifdef IPOD_MINI2G /* serial LCD hookup */ |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 125 | lcd_wait_write(); |
Jens Arnold | 6ef2db2 | 2007-11-18 12:49:24 +0000 | [diff] [blame] | 126 | LCD1_CONTROL = 0x01730084; /* fastest setting */ |
| 127 | #elif defined(IPOD_1G2G) || defined(IPOD_3G) |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 128 | LCD1_CONTROL = (LCD1_CONTROL & 0x0002) | 0x0084; |
| 129 | /* fastest setting, keep backlight bit */ |
Jens Arnold | 6ef2db2 | 2007-11-18 12:49:24 +0000 | [diff] [blame] | 130 | #else |
| 131 | LCD1_CONTROL = 0x0084; /* fastest setting */ |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 132 | #endif |
| 133 | |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 134 | lcd_cmd_and_data(R_DRV_WAVEFORM_CONTROL, 0x48); |
| 135 | /* C waveform, no EOR, 9 lines inversion */ |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 136 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc); |
Jens Arnold | ab46e46 | 2008-05-17 09:55:23 +0000 | [diff] [blame] | 137 | lcd_cmd_and_data(R_DISPLAY_CONTROL, 0x0019); |
Jens Arnold | 41534a9 | 2007-07-27 12:40:36 +0000 | [diff] [blame] | 138 | #ifdef HAVE_BACKLIGHT_INVERSION |
| 139 | invert_display(); |
Jens Arnold | 41534a9 | 2007-07-27 12:40:36 +0000 | [diff] [blame] | 140 | #endif |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 141 | lcd_set_flip(false); |
| 142 | lcd_cmd_and_data(R_ENTRY_MODE, 0x0000); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /*** hardware configuration ***/ |
| 146 | |
| 147 | int lcd_default_contrast(void) |
| 148 | { |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 149 | #if defined(IPOD_1G2G) |
| 150 | return 45; |
| 151 | #elif defined(IPOD_3G) |
| 152 | return 55; |
| 153 | #elif defined(IPOD_MINI) || defined(IPOD_MINI2G) |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 154 | return 42; |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 155 | #elif defined(IPOD_4G) |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 156 | return 35; |
| 157 | #endif |
| 158 | } |
| 159 | |
| 160 | /* Rockbox stores the contrast as 0..63 - we add 64 to it */ |
| 161 | void lcd_set_contrast(int val) |
| 162 | { |
| 163 | if (val < 0) val = 0; |
| 164 | else if (val > 63) val = 63; |
| 165 | |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 166 | lcd_cmd_and_data(R_CONTRAST_CONTROL, CONTRAST_REG_H | (val + 64)); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Jens Arnold | 021c086 | 2007-07-27 12:05:54 +0000 | [diff] [blame] | 169 | #ifdef HAVE_BACKLIGHT_INVERSION |
| 170 | static void invert_display(void) |
| 171 | { |
Jens Arnold | 8399749 | 2008-04-04 17:33:39 +0000 | [diff] [blame] | 172 | static bool last_invert = false; |
| 173 | bool new_invert = lcd_inverted ^ lcd_backlit; |
| 174 | |
| 175 | if (new_invert != last_invert) |
| 176 | { |
| 177 | int oldlevel = disable_irq_save(); |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 178 | #if NUM_CORES > 1 |
| 179 | corelock_lock(&cl); |
Jens Arnold | ab46e46 | 2008-05-17 09:55:23 +0000 | [diff] [blame] | 180 | lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019); |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 181 | corelock_unlock(&cl); |
| 182 | #else |
Jens Arnold | ab46e46 | 2008-05-17 09:55:23 +0000 | [diff] [blame] | 183 | lcd_cmd_and_data(R_DISPLAY_CONTROL, new_invert? 0x0027 : 0x0019); |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 184 | #endif |
Jens Arnold | 8399749 | 2008-04-04 17:33:39 +0000 | [diff] [blame] | 185 | restore_irq(oldlevel); |
| 186 | last_invert = new_invert; |
| 187 | } |
Jens Arnold | 021c086 | 2007-07-27 12:05:54 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void lcd_set_invert_display(bool yesno) |
| 191 | { |
| 192 | lcd_inverted = yesno; |
| 193 | invert_display(); |
| 194 | } |
| 195 | |
| 196 | void lcd_set_backlight_inversion(bool yesno) |
| 197 | { |
| 198 | lcd_backlit = yesno; |
| 199 | invert_display(); |
| 200 | } |
| 201 | #else |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 202 | void lcd_set_invert_display(bool yesno) |
| 203 | { |
Jens Arnold | ab46e46 | 2008-05-17 09:55:23 +0000 | [diff] [blame] | 204 | lcd_cmd_and_data(R_DISPLAY_CONTROL, yesno ? 0x0027 : 0x0019); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 205 | } |
Jens Arnold | 021c086 | 2007-07-27 12:05:54 +0000 | [diff] [blame] | 206 | #endif |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 207 | |
| 208 | /* turn the display upside down (call lcd_update() afterwards) */ |
| 209 | void lcd_set_flip(bool yesno) |
| 210 | { |
| 211 | #if defined(IPOD_MINI) || defined(IPOD_MINI2G) |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 212 | if (yesno) |
| 213 | { /* 168x112, inverse COM order */ |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 214 | lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x020d); |
| 215 | lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8316); /* 22..131 */ |
| 216 | addr_offset = (22 << 5) | (20 - 4); |
| 217 | pix_offset = -2; |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 218 | } |
| 219 | else |
| 220 | { /* 168x112, inverse SEG order */ |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 221 | lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x010d); |
| 222 | lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x6d00); /* 0..109 */ |
| 223 | addr_offset = 20; |
| 224 | pix_offset = 0; |
| 225 | } |
| 226 | #else |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 227 | if (yesno) |
| 228 | { /* 168x128, inverse SEG & COM order */ |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 229 | lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x030f); |
| 230 | lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x8304); /* 4..131 */ |
| 231 | addr_offset = (4 << 5) | (20 - 1); |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 232 | } |
| 233 | else |
| 234 | { /* 168x128 */ |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 235 | lcd_cmd_and_data(R_DRV_OUTPUT_CONTROL, 0x000f); |
| 236 | lcd_cmd_and_data(R_1ST_SCR_DRV_POS, 0x7f00); /* 0..127 */ |
| 237 | addr_offset = 20; |
| 238 | } |
| 239 | #endif |
| 240 | } |
| 241 | |
Jens Arnold | 97bdfce | 2007-08-10 08:09:53 +0000 | [diff] [blame] | 242 | void lcd_enable(bool on) |
| 243 | { |
| 244 | if (on) |
| 245 | { |
| 246 | lcd_cmd_and_data(R_START_OSC, 1); /* start oscillation */ |
| 247 | sleep(HZ/10); /* wait 10ms */ |
| 248 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H); /*clear standby mode */ |
| 249 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0xc); |
| 250 | /* enable opamp & booster */ |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H); |
| 255 | /* switch off opamp & booster */ |
| 256 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x1); |
| 257 | /* enter standby mode */ |
| 258 | } |
| 259 | } |
| 260 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 261 | /*** update functions ***/ |
| 262 | |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 263 | /* Helper function. */ |
| 264 | void lcd_mono_data(const unsigned char *data, int count); |
| 265 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 266 | /* Performance function that works with an external buffer |
| 267 | note that x, bwidtht and stride are in 8-pixel units! */ |
Jens Arnold | 68a2168 | 2008-03-24 00:35:53 +0000 | [diff] [blame] | 268 | void lcd_blit_mono(const unsigned char *data, int bx, int y, int bwidth, |
| 269 | int height, int stride) |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 270 | { |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 271 | #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) |
| 272 | corelock_lock(&cl); |
| 273 | #endif |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 274 | while (height--) |
| 275 | { |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 276 | lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx); |
| 277 | lcd_prepare_cmd(R_RAM_DATA); |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 278 | lcd_mono_data(data, bwidth); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 279 | data += stride; |
| 280 | } |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 281 | #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) |
| 282 | corelock_unlock(&cl); |
| 283 | #endif |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 286 | /* Helper function for lcd_grey_phase_blit(). */ |
| 287 | void lcd_grey_data(unsigned char *values, unsigned char *phases, int count); |
| 288 | |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 289 | /* Performance function that works with an external buffer |
| 290 | note that bx and bwidth are in 8-pixel units! */ |
Jens Arnold | 68a2168 | 2008-03-24 00:35:53 +0000 | [diff] [blame] | 291 | void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, |
Jens Arnold | 6a56c14 | 2008-01-09 23:48:26 +0000 | [diff] [blame] | 292 | int bx, int y, int bwidth, int height, int stride) |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 293 | { |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 294 | #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) |
| 295 | corelock_lock(&cl); |
| 296 | #endif |
| 297 | while (height--) |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 298 | { |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 299 | lcd_cmd_and_data(R_RAM_ADDR_SET, (y++ << 5) + addr_offset - bx); |
| 300 | lcd_prepare_cmd(R_RAM_DATA); |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 301 | lcd_grey_data(values, phases, bwidth); |
Jens Arnold | 6a56c14 | 2008-01-09 23:48:26 +0000 | [diff] [blame] | 302 | values += stride; |
| 303 | phases += stride; |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 304 | } |
Jens Arnold | 32bd0f8 | 2008-04-04 22:13:53 +0000 | [diff] [blame] | 305 | #if (NUM_CORES > 1) && defined(HAVE_BACKLIGHT_INVERSION) |
| 306 | corelock_unlock(&cl); |
| 307 | #endif |
Jens Arnold | feb5b15 | 2008-01-04 23:42:38 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 310 | void lcd_update_rect(int x, int y, int width, int height) |
| 311 | { |
| 312 | int xmax, ymax; |
| 313 | |
| 314 | if (x + width > LCD_WIDTH) |
| 315 | width = LCD_WIDTH - x; |
| 316 | if (width <= 0) |
| 317 | return; |
| 318 | |
| 319 | ymax = y + height - 1; |
| 320 | if (ymax >= LCD_HEIGHT) |
| 321 | ymax = LCD_HEIGHT - 1; |
| 322 | |
| 323 | #if defined(IPOD_MINI) || defined(IPOD_MINI2G) |
| 324 | x += pix_offset; |
| 325 | #endif |
| 326 | /* writing is done in 16-bit units (8 pixels) */ |
| 327 | xmax = (x + width - 1) >> 3; |
| 328 | x >>= 3; |
| 329 | width = xmax - x + 1; |
| 330 | |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 331 | for (; y <= ymax; y++) |
| 332 | { |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 333 | lcd_cmd_and_data(R_RAM_ADDR_SET, (y << 5) + addr_offset - x); |
| 334 | lcd_prepare_cmd(R_RAM_DATA); |
| 335 | |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 336 | #if defined(IPOD_MINI) || defined(IPOD_MINI2G) |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 337 | if (pix_offset == -2) |
| 338 | lcd_write_data_shifted(&lcd_framebuffer[y][2*x], width); |
| 339 | else |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 340 | #endif |
Jens Arnold | 41cd44c | 2008-01-12 00:59:18 +0000 | [diff] [blame] | 341 | lcd_write_data(&lcd_framebuffer[y][2*x], width); |
Jens Arnold | 2906c36 | 2007-02-25 13:11:02 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | /* Update the display. */ |
| 346 | void lcd_update(void) |
| 347 | { |
| 348 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); |
| 349 | } |
Nicolas Pennequin | f548336 | 2007-09-29 20:56:07 +0000 | [diff] [blame] | 350 | |
| 351 | #ifdef HAVE_LCD_SHUTDOWN |
| 352 | /* LCD powerdown */ |
| 353 | void lcd_shutdown(void) |
| 354 | { |
Jens Arnold | b073f0c | 2008-04-02 19:01:16 +0000 | [diff] [blame] | 355 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x00); /* Turn off op amp power */ |
| 356 | lcd_cmd_and_data(R_POWER_CONTROL, POWER_REG_H | 0x02); /* Put LCD driver in standby */ |
Nicolas Pennequin | f548336 | 2007-09-29 20:56:07 +0000 | [diff] [blame] | 357 | } |
| 358 | #endif |