summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire
diff options
context:
space:
mode:
authorRani Hod <raenye@gmail.com>2006-08-08 22:03:56 +0000
committerRani Hod <raenye@gmail.com>2006-08-08 22:03:56 +0000
commitc9f59e6f75bcfa25a563fedd77bfa77b3617f133 (patch)
treeceff51afb679acb2935ed18072384819abf4281e /firmware/target/coldfire
parentf8866a3a9c3a12b72e87ae96445eca1b52ed23fb (diff)
downloadrockbox-c9f59e6f75bcfa25a563fedd77bfa77b3617f133.tar.gz
rockbox-c9f59e6f75bcfa25a563fedd77bfa77b3617f133.zip
Accepted FS #5772 by Michael Sevakis
1. X5 lcd sleep 2. #define HAVE_LCD_ENABLE 3. add "backlight (on hold switch)" setting, adapted from FS #5735 Note that the while(1) yield ==> asm("halt") part is NOT commited here, I prefer it would be discussed separately. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10489 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/coldfire')
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/backlight-x5.c6
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/button-x5.c21
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/lcd-x5.c263
3 files changed, 198 insertions, 92 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/backlight-x5.c b/firmware/target/coldfire/iaudio/x5/backlight-x5.c
index 91c7224267..70a5d957b6 100755
--- a/firmware/target/coldfire/iaudio/x5/backlight-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/backlight-x5.c
@@ -21,10 +21,13 @@
21#include "system.h" 21#include "system.h"
22#include "backlight.h" 22#include "backlight.h"
23#include "pcf50606.h" 23#include "pcf50606.h"
24#include "lcd.h"
24 25
25void __backlight_on(void) 26void __backlight_on(void)
26{ 27{
27 int level = set_irq_level(HIGHEST_IRQ_LEVEL); 28 int level;
29 lcd_enable(true);
30 level = set_irq_level(HIGHEST_IRQ_LEVEL);
28 pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */ 31 pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */
29 set_irq_level(level); 32 set_irq_level(level);
30} 33}
@@ -34,6 +37,7 @@ void __backlight_off(void)
34 int level = set_irq_level(HIGHEST_IRQ_LEVEL); 37 int level = set_irq_level(HIGHEST_IRQ_LEVEL);
35 pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=000 */ 38 pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=000 */
36 set_irq_level(level); 39 set_irq_level(level);
40 lcd_enable(false);
37} 41}
38 42
39void __remote_backlight_on(void) 43void __remote_backlight_on(void)
diff --git a/firmware/target/coldfire/iaudio/x5/button-x5.c b/firmware/target/coldfire/iaudio/x5/button-x5.c
index 07bc7bf3f7..b44909a975 100755
--- a/firmware/target/coldfire/iaudio/x5/button-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/button-x5.c
@@ -50,18 +50,16 @@ int button_read_device(void)
50 int btn = BUTTON_NONE; 50 int btn = BUTTON_NONE;
51 static bool hold_button = false; 51 static bool hold_button = false;
52 static bool remote_hold_button = false; 52 static bool remote_hold_button = false;
53 bool hold_button_old;
53 54
54 /* backlight handling */ 55 /* normal buttons */
55 if (hold_button && !button_hold()) 56 hold_button_old = hold_button;
56 {
57 backlight_on();
58 }
59 /* TODO: add light handling for the remote */
60
61 hold_button = button_hold(); 57 hold_button = button_hold();
62 remote_hold_button = remote_button_hold();
63 58
64 /* normal buttons */ 59 /* give BL notice if HB state chaged */
60 if (hold_button != hold_button_old)
61 backlight_hold_changed(hold_button);
62
65 if (!hold_button) 63 if (!hold_button)
66 { 64 {
67 data = adc_scan(ADC_BUTTONS); 65 data = adc_scan(ADC_BUTTONS);
@@ -90,6 +88,11 @@ int button_read_device(void)
90 } 88 }
91 89
92 /* remote buttons */ 90 /* remote buttons */
91
92 /* TODO: add light handling for the remote */
93
94 remote_hold_button = remote_button_hold();
95
93 data = adc_scan(ADC_REMOTE); 96 data = adc_scan(ADC_REMOTE);
94 if(data < 0x17) 97 if(data < 0x17)
95 remote_hold_button = true; 98 remote_hold_button = true;
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-x5.c
index 2e3e785d73..f66b8801dc 100755
--- a/firmware/target/coldfire/iaudio/x5/lcd-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/lcd-x5.c
@@ -30,14 +30,20 @@
30#include "font.h" 30#include "font.h"
31#include "bidi.h" 31#include "bidi.h"
32 32
33/** Initialized in lcd_init_device() **/
34/* Is the power turned on? */
35static bool power_on;
33/* Is the display turned on? */ 36/* Is the display turned on? */
34static bool display_on = false; 37static bool display_on;
35 38/* Amount of vertical offset. Used for flip offset correction/detection. */
36/* Amount of vertical offset. Used for offset correction when flipped. */ 39static int y_offset;
37static int y_offset = 0;
38
39/* Amount of roll offset (0-127). */ 40/* Amount of roll offset (0-127). */
40static int roll_offset = 0; 41static int roll_offset;
42/* Reverse flag. Must be remembered when display is turned off. */
43static unsigned short disp_control_rev;
44
45/* Forward declarations */
46static void lcd_display_off(void);
41 47
42/* A15(0x8000) && CS1->CS, A1(0x0002)->RS */ 48/* A15(0x8000) && CS1->CS, A1(0x0002)->RS */
43#define LCD_CMD *(volatile unsigned short *)0xf0008000 49#define LCD_CMD *(volatile unsigned short *)0xf0008000
@@ -79,16 +85,16 @@ static int roll_offset = 0;
79#define R_GAMMA_AMP_ADJ_NEG 0x3b 85#define R_GAMMA_AMP_ADJ_NEG 0x3b
80 86
81/* called very frequently - inline! */ 87/* called very frequently - inline! */
82inline void lcd_write_reg(int reg, int val) 88static inline void lcd_write_reg(int reg, int val)
83{ 89{
84 LCD_CMD = 0x0000; /* MSB is ~always~ 0 */ 90 LCD_CMD = 0x0000; /* MSB is ~always~ 0 */
85 LCD_CMD = reg << 1; 91 LCD_CMD = reg << 1;
86 LCD_DATA = (val >> 8) << 1; 92 LCD_DATA = (val >> 8) << 1;
87 LCD_DATA = (val & 0xff) << 1; 93 LCD_DATA = val << 1;
88} 94}
89 95
90/* called very frequently - inline! */ 96/* called very frequently - inline! */
91inline void lcd_begin_write_gram(void) 97static inline void lcd_begin_write_gram(void)
92{ 98{
93 LCD_CMD = 0x0000; 99 LCD_CMD = 0x0000;
94 LCD_CMD = R_WRITE_DATA_2_GRAM << 1; 100 LCD_CMD = R_WRITE_DATA_2_GRAM << 1;
@@ -112,7 +118,7 @@ static inline void lcd_write_two(unsigned long px2)
112 LCD_DATA = px2sr + (px2sr & 0x1F8); 118 LCD_DATA = px2sr + (px2sr & 0x1F8);
113 LCD_DATA = px2 << 1; 119 LCD_DATA = px2 << 1;
114} 120}
115 121
116/*** hardware configuration ***/ 122/*** hardware configuration ***/
117 123
118int lcd_default_contrast(void) 124int lcd_default_contrast(void)
@@ -135,29 +141,43 @@ void lcd_set_contrast(int val)
135 141
136void lcd_set_invert_display(bool yesno) 142void lcd_set_invert_display(bool yesno)
137{ 143{
144 if (yesno == (disp_control_rev == 0x0000))
145 return;
146
147 disp_control_rev = yesno ? 0x0000 : 0x0004;
148
149 if (!display_on)
150 return;
151
138 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */ 152 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
139 lcd_write_reg(R_DISP_CONTROL, yesno ? 0x0033 : 0x0037); 153 lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
140} 154}
141 155
142/* turn the display upside down (call lcd_update() afterwards) */ 156/* turn the display upside down (call lcd_update() afterwards) */
143void lcd_set_flip(bool yesno) 157void lcd_set_flip(bool yesno)
144{ 158{
159 if (yesno == (y_offset != 0))
160 return;
161
145 y_offset = yesno ? 4 : 0; 162 y_offset = yesno ? 4 : 0;
146 /* SCN4-0=000x0 (G160) */ 163
164 if (!power_on)
165 return;
166
167 /* SCN4-0=000x0 (G1/G160) */
147 lcd_write_reg(R_GATE_SCAN_START_POS, yesno ? 0x0000 : 0x0002); 168 lcd_write_reg(R_GATE_SCAN_START_POS, yesno ? 0x0000 : 0x0002);
148 /* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/ 169 /* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
149 lcd_write_reg(R_DRV_OUTPUT_CONTROL, yesno ? 0x0013 : 0x0313); 170 lcd_write_reg(R_DRV_OUTPUT_CONTROL, yesno ? 0x0013 : 0x0313);
150 /* Vertical stripe */ 171 /* HEA7-0=0xxx, HSA7-0=0xxx */
151 /* HEA7-0=0xxx, HSA7-0=0xxx */ 172 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, yesno ? 0x8304 : 0x7f00);
152 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00 + (y_offset << 8) + y_offset);
153} 173}
154 174
155/* Rolls up the lcd display by the specified amount of lines. 175/* Rolls up the lcd display by the specified amount of lines.
156 * Lines that are rolled out over the top of the screen are 176 * Lines that are rolled out over the top of the screen are
157 * rolled in from the bottom again. This is a hardware 177 * rolled in from the bottom again. This is a hardware
158 * remapping only and all operations on the lcd are affected. 178 * remapping only and all operations on the lcd are affected.
159 * -> 179 * ->
160 * @param int lines - The number of lines that are rolled. 180 * @param int lines - The number of lines that are rolled.
161 * The value must be 0 <= pixels < LCD_HEIGHT. 181 * The value must be 0 <= pixels < LCD_HEIGHT.
162 * Call lcd_update() afterwards */ 182 * Call lcd_update() afterwards */
163void lcd_roll(int lines) 183void lcd_roll(int lines)
@@ -171,17 +191,11 @@ void lcd_roll(int lines)
171 roll_offset = lines; 191 roll_offset = lines;
172} 192}
173 193
174/* LCD init */ 194static void lcd_power_on(void)
175void lcd_init_device(void)
176{ 195{
177 /* LCD Reset */ 196 /* Be sure standby bit is clear. */
178 and_l(~0x00000010, &GPIO1_OUT); 197 /* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
179 or_l(0x00000010, &GPIO1_ENABLE); 198 lcd_write_reg(R_POWER_CONTROL1, 0x0000);
180 or_l(0x00000010, &GPIO1_FUNCTION);
181 sleep(HZ/100);
182 or_l(0x00000010, &GPIO1_OUT);
183
184 sleep(HZ/100);
185 199
186 /** Power ON Sequence **/ 200 /** Power ON Sequence **/
187 /* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */ 201 /* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
@@ -212,13 +226,13 @@ void lcd_init_device(void)
212 /* Instruction (4) for power setting; PON = "1" */ 226 /* Instruction (4) for power setting; PON = "1" */
213 /* VRL3-0=0100, PON=1, VRH3-0=0001 */ 227 /* VRL3-0=0100, PON=1, VRH3-0=0001 */
214 lcd_write_reg(R_POWER_CONTROL4, 0x0411); 228 lcd_write_reg(R_POWER_CONTROL4, 0x0411);
215 229
216 /* 40ms or more; time for step-up circuit 4 to stabilize */ 230 /* 40ms or more; time for step-up circuit 4 to stabilize */
217 sleep(HZ/25); 231 sleep(HZ/25);
218 232
219 /* Instructions for other mode settings (in register order). */ 233 /* Instructions for other mode settings (in register order). */
220 /* SM=0, GS=1, SS=1, NL4-0=10011 (G1-G160)*/ 234 /* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
221 lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x313); 235 lcd_write_reg(R_DRV_OUTPUT_CONTROL, y_offset ? 0x0013 : 0x0313);
222 /* FLD1-0=01 (1 field), B/C=1, EOR=1 (C-pat), NW5-0=000000 (1 row) */ 236 /* FLD1-0=01 (1 field), B/C=1, EOR=1 (C-pat), NW5-0=000000 (1 row) */
223 lcd_write_reg(R_DRV_AC_CONTROL, 0x0700); 237 lcd_write_reg(R_DRV_AC_CONTROL, 0x0700);
224 /* DIT=1, BGR=1, HWM=0, I/D1-0=11, AM=1, LG2-0=000 */ 238 /* DIT=1, BGR=1, HWM=0, I/D1-0=11, AM=1, LG2-0=000 */
@@ -227,16 +241,16 @@ void lcd_init_device(void)
227 lcd_write_reg(R_COMPARE_REG, 0x0000); 241 lcd_write_reg(R_COMPARE_REG, 0x0000);
228 /* NO1-0=01, SDT1-0=00, EQ1-0=00, DIV1-0=00, RTN3-00000 */ 242 /* NO1-0=01, SDT1-0=00, EQ1-0=00, DIV1-0=00, RTN3-00000 */
229 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x4000); 243 lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x4000);
230 /* SCN4-0=00010 (G160) */ 244 /* SCN4-0=000x0 (G1/G160) */
231 lcd_write_reg(R_GATE_SCAN_START_POS, 0x0002); 245 lcd_write_reg(R_GATE_SCAN_START_POS, y_offset ? 0x0000 : 0x0002);
232 /* VL7-0=0x00 */ 246 /* VL7-0=0x00 */
233 lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000); 247 lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000);
234 /* SE17-10(End)=0x9f (159), SS17-10(Start)=0x00 */ 248 /* SE17-10(End)=0x9f (159), SS17-10(Start)=0x00 */
235 lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00); 249 lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00);
236 /* SE27-20(End)=0x5c (92), SS27-20(Start)=0x00 */ 250 /* SE27-20(End)=0x5c (92), SS27-20(Start)=0x00 */
237 lcd_write_reg(R_2ND_SCR_DRV_POS, 0x5c00); 251 lcd_write_reg(R_2ND_SCR_DRV_POS, 0x5c00);
238 /* HEA7-0=0x7f, HSA7-0=0x00 */ 252 /* HEA7-0=0xxx, HSA7-0=0xxx */
239 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00); /* Vertical stripe */ 253 lcd_write_reg(R_HORIZ_RAM_ADDR_POS, y_offset ? 0x8304 : 0x7f00);
240 /* PKP12-10=0x0, PKP02-00=0x0 */ 254 /* PKP12-10=0x0, PKP02-00=0x0 */
241 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003); 255 lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003);
242 /* PKP32-30=0x4, PKP22-20=0x0 */ 256 /* PKP32-30=0x4, PKP22-20=0x0 */
@@ -261,32 +275,135 @@ void lcd_init_device(void)
261 /* 100ms or more; time for step-up circuits to stabilize */ 275 /* 100ms or more; time for step-up circuits to stabilize */
262 sleep(HZ/10); 276 sleep(HZ/10);
263 277
278 power_on = true;
279}
280
281static void lcd_power_off(void)
282{
283 /* Display must be off first */
284 if (display_on)
285 lcd_display_off();
286
287 power_on = false;
288
289 /** Power OFF sequence **/
290 /* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
291
292 /* Step-up1 halt setting bit */
293 /* BT2-0=110, DC2-0=001, AP2-0=011, SLP=0, STB=0 */
294 lcd_write_reg(R_POWER_CONTROL1, 0x062c);
295 /* Step-up3,4 halt setting bit */
296 /* VRL3-0=0100, PON=0, VRH3-0=0001 */
297 lcd_write_reg(R_POWER_CONTROL4, 0x0401);
298 /* VCOMG=0, VDV4-0=10011, VCM4-0=11000 */
299 lcd_write_reg(R_POWER_CONTROL5, 0x1318);
300
301 /* Wait 100ms or more */
302 sleep(HZ/10);
303
304 /* Step-up2,amp halt setting bit */
305 /* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
306 lcd_write_reg(R_POWER_CONTROL1, 0x0000);
307}
308
309static void lcd_display_on(void)
310{
311 /* Be sure power is on first */
312 if (!power_on)
313 lcd_power_on();
314
264 /** Display ON Sequence **/ 315 /** Display ON Sequence **/
265 /* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */ 316 /* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
266 317
267 /* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=1, D1-0=01 */ 318 /* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=01 */
268 lcd_write_reg(R_DISP_CONTROL, 0x0005); 319 lcd_write_reg(R_DISP_CONTROL, 0x0001);
269 320
270 sleep(HZ/25); /* Wait 2 frames or more */ 321 sleep(HZ/25); /* Wait 2 frames or more */
271 322
272 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=01 */ 323 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=01 */
273 lcd_write_reg(R_DISP_CONTROL, 0x0025); 324 lcd_write_reg(R_DISP_CONTROL, 0x0021 | disp_control_rev);
274 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=11 */ 325 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=11 */
275 lcd_write_reg(R_DISP_CONTROL, 0x0027); 326 lcd_write_reg(R_DISP_CONTROL, 0x0023 | disp_control_rev);
276 327
277 sleep(HZ/25); /* Wait 2 frames or more */ 328 sleep(HZ/25); /* Wait 2 frames or more */
278 329
279 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=1, D1-0=11 */ 330 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
280 lcd_write_reg(R_DISP_CONTROL, 0x0037); 331 lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
281 332
282 display_on = true; 333 display_on = true;
334}
335
336static void lcd_display_off(void)
337{
338 display_on = false;
339
340 /** Display OFF sequence **/
341 /* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
342
343 /* EQ1-0=00 already */
344
345 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=10 */
346 lcd_write_reg(R_DISP_CONTROL, 0x0032 | disp_control_rev);
347
348 sleep(HZ/25); /* Wait 2 frames or more */
349
350 /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=10 */
351 lcd_write_reg(R_DISP_CONTROL, 0x0022 | disp_control_rev);
352
353 sleep(HZ/25); /* Wait 2 frames or more */
354
355 /* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=00 */
356 lcd_write_reg(R_DISP_CONTROL, 0x0000);
357}
358
359/* LCD init */
360void lcd_init_device(void)
361{
362 /* Reset settings */
363 power_on = false;
364 display_on = false;
283 y_offset = 0; 365 y_offset = 0;
284 roll_offset = 0; 366 roll_offset = 0;
367 disp_control_rev = 0x0004;
368
369 /* LCD Reset */
370 and_l(~0x00000010, &GPIO1_OUT);
371 or_l(0x00000010, &GPIO1_ENABLE);
372 or_l(0x00000010, &GPIO1_FUNCTION);
373 sleep(HZ/100);
374 or_l(0x00000010, &GPIO1_OUT);
375
376 sleep(HZ/100);
377
378 lcd_display_on();
285} 379}
286 380
287void lcd_enable(bool on) 381void lcd_enable(bool on)
288{ 382{
289 display_on = on; 383 if (on == display_on)
384 return;
385
386 if (on)
387 {
388 lcd_display_on();
389 /* Probably out of sync and we don't wanna pepper the code with
390 lcd_update() calls for this. */
391 lcd_update();
392 }
393 else
394 {
395 lcd_display_off();
396 }
397}
398
399void lcd_sleep(void)
400{
401 if (power_on)
402 lcd_power_off();
403
404 /* Set standby mode */
405 /* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=1 */
406 lcd_write_reg(R_POWER_CONTROL1, 0x0001);
290} 407}
291 408
292/*** update functions ***/ 409/*** update functions ***/
@@ -303,7 +420,7 @@ void lcd_blit(const fb_data* data, int x, int by, int width,
303 (void)width; 420 (void)width;
304 (void)bheight; 421 (void)bheight;
305 (void)stride; 422 (void)stride;
306 /*if(display_on)*/ 423 /*if(display_on)*/
307} 424}
308 425
309 426
@@ -327,7 +444,7 @@ void lcd_update(void)
327 lcd_begin_write_gram(); 444 lcd_begin_write_gram();
328 445
329 ptr = (unsigned long *)lcd_framebuffer; 446 ptr = (unsigned long *)lcd_framebuffer;
330 ptr_end = ptr + (LCD_WIDTH*LCD_HEIGHT >> 1); 447 ptr_end = ptr + LCD_WIDTH*LCD_HEIGHT/2;
331 448
332 do 449 do
333 { 450 {
@@ -375,8 +492,6 @@ void lcd_update_rect(int x, int y, int width, int height)
375 if (y >= y_end) 492 if (y >= y_end)
376 return; /* nothing left to do */ 493 return; /* nothing left to do */
377 494
378 ptr = (unsigned long *)&lcd_framebuffer[y][x];
379
380 /* Set start position and window */ 495 /* Set start position and window */
381 lcd_write_reg(R_RAM_ADDR_SET, (x << 8) | 496 lcd_write_reg(R_RAM_ADDR_SET, (x << 8) |
382 (((y + roll_offset) & 127) + y_offset)); 497 (((y + roll_offset) & 127) + y_offset));
@@ -384,44 +499,28 @@ void lcd_update_rect(int x, int y, int width, int height)
384 499
385 lcd_begin_write_gram(); 500 lcd_begin_write_gram();
386 501
502 ptr = (unsigned long *)&lcd_framebuffer[y][x];
503
387 /* Aligning source reads to long boundaries helps 2% - 3% with IRAM 504 /* Aligning source reads to long boundaries helps 2% - 3% with IRAM
388 buffer. DK with DRAM. */ 505 buffer. DK with DRAM. */
506 odd_lead = x & 1;
389 507
390 /* special case widths 1 and 2. */ 508 if (odd_lead)
391 switch (width)
392 { 509 {
393 case 1: 510 duff = width - 1;
394 odd_lead = 1; /* odd_lead case writes pixels */ 511 odd_trail = duff & 1;
395 odd_trail = 0; 512 duff >>= 1;
396 duff = 0; /* Squelch compiler warning. */ 513 }
397 duff_end = ptr; 514 else
398 break; 515 {
399 case 2: /* Just read as long */ 516 duff = width >> 1;
400 odd_lead = 0; 517 odd_trail = width & 1;
401 odd_trail = 0; 518 }
402 duff = 1;
403 duff_end = ptr + 1;
404 break;
405 default:
406 odd_lead = x & 1;
407
408 if (odd_lead)
409 {
410 duff = width - 1;
411 odd_trail = duff & 1;
412 duff >>= 1;
413 }
414 else
415 {
416 duff = width >> 1;
417 odd_trail = width & 1;
418 }
419 519
420 duff_end = ptr + duff; 520 duff_end = ptr + duff;
421#ifndef BOOTLOADER 521#ifndef BOOTLOADER
422 duff &= 7; 522 duff &= 7;
423#endif 523#endif
424 } /* end switch */
425 524
426 stride = LCD_WIDTH - width + odd_trail; /* See odd_trail below */ 525 stride = LCD_WIDTH - width + odd_trail; /* See odd_trail below */
427 526
@@ -440,7 +539,7 @@ void lcd_update_rect(int x, int y, int width, int height)
440 do 539 do
441 lcd_write_two(*ptr); 540 lcd_write_two(*ptr);
442 while (++ptr < duff_end); 541 while (++ptr < duff_end);
443#else 542#else
444 switch (duff) 543 switch (duff)
445 { 544 {
446 do 545 do