summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/lang/english.lang56
-rw-r--r--apps/misc.c3
-rw-r--r--apps/settings.c30
-rw-r--r--apps/settings.h6
-rw-r--r--apps/settings_menu.c46
-rw-r--r--firmware/backlight.c306
-rw-r--r--firmware/drivers/button.c59
-rw-r--r--firmware/export/backlight.h16
-rw-r--r--firmware/export/config-h300.h5
-rw-r--r--firmware/export/config-iaudiox5.h15
-rw-r--r--firmware/export/config-ipod3g.h5
-rw-r--r--firmware/export/config.h1
-rw-r--r--firmware/export/lcd.h9
-rw-r--r--firmware/powermgmt.c2
-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
17 files changed, 641 insertions, 208 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 61d16d22f7..a723c1cc0e 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -8805,6 +8805,62 @@
8805 </dest> 8805 </dest>
8806 <voice> 8806 <voice>
8807 *: "(Vol- : Re-enable)" 8807 *: "(Vol- : Re-enable)"
8808<phrase>
8809 id: LANG_BACKLIGHT_ON_BUTTON_HOLD_NORMAL
8810 desc: in lcd settings
8811 user:
8812 <source>
8813 *: "Normal"
8814 </source>
8815 <dest>
8816 *: "Normal"
8817 </dest>
8818 <voice>
8819 *: "Normal"
8820 </voice>
8821</phrase>
8822<phrase>
8823 id: LANG_BACKLIGHT_ON_BUTTON_HOLD
8824 desc: in lcd settings
8825 user:
8826 <source>
8827 *: "Backlight (On Hold Key)"
8828 </source>
8829 <dest>
8830 *: "Backlight (On Hold Key)"
8831 </dest>
8832 <voice>
8833 *: "Backlight on hold key"
8834 </voice>
8835</phrase>
8836<phrase>
8837 id: LANG_NEVER
8838 desc: in lcd settings
8839 user:
8840 <source>
8841 *: "Never"
8842 </source>
8843 <dest>
8844 *: "Never"
8845 </dest>
8846 <voice>
8847 *: "Never"
8848 </voice>
8849</phrase>
8850<phrase>
8851 id: LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF
8852 desc: In display settings, time to switch LCD chip into power saving state
8853 user:
8854 <source>
8855 *: "Sleep (After Backlight Off)"
8856 </source>
8857 <dest>
8858 *: "Sleep (After Backlight Off)"
8859 </dest>
8860 <voice>
8861 *: "Sleep after backlight off"
8862 </voice>
8863</phrase>
8808 </voice> 8864 </voice>
8809</phrase> 8865</phrase>
8810<phrase> 8866<phrase>
diff --git a/apps/misc.c b/apps/misc.c
index b0c315af98..ffacf7ed82 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -491,6 +491,9 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
491 { 491 {
492 FOR_NB_SCREENS(i) 492 FOR_NB_SCREENS(i)
493 screens[i].clear_display(); 493 screens[i].clear_display();
494#ifdef X5_BACKLIGHT_SHUTDOWN
495 x5_backlight_shutdown();
496#endif
494 gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); 497 gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN));
495 498
496 if (!tagcache_prepare_shutdown()) 499 if (!tagcache_prepare_shutdown())
diff --git a/apps/settings.c b/apps/settings.c
index 673b8fe246..3c036d8594 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -24,11 +24,11 @@
24#include "config.h" 24#include "config.h"
25#include "kernel.h" 25#include "kernel.h"
26#include "thread.h" 26#include "thread.h"
27#include "button.h"
27#include "settings.h" 28#include "settings.h"
28#include "disk.h" 29#include "disk.h"
29#include "panic.h" 30#include "panic.h"
30#include "debug.h" 31#include "debug.h"
31#include "button.h"
32#include "usb.h" 32#include "usb.h"
33#include "backlight.h" 33#include "backlight.h"
34#include "lcd.h" 34#include "lcd.h"
@@ -40,7 +40,6 @@
40#include "ata.h" 40#include "ata.h"
41#include "fat.h" 41#include "fat.h"
42#include "power.h" 42#include "power.h"
43#include "backlight.h"
44#include "powermgmt.h" 43#include "powermgmt.h"
45#include "status.h" 44#include "status.h"
46#include "atoi.h" 45#include "atoi.h"
@@ -244,7 +243,7 @@ static const struct bit_entry rtc_bits[] =
244 {6, S_O(contrast), DEFAULT_CONTRAST_SETTING, "contrast", NULL }, 243 {6, S_O(contrast), DEFAULT_CONTRAST_SETTING, "contrast", NULL },
245#endif 244#endif
246#ifdef CONFIG_BACKLIGHT 245#ifdef CONFIG_BACKLIGHT
247 {5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf }, 246 {5, S_O(backlight_timeout), 6, "backlight timeout", backlight_times_conf },
248#ifdef CONFIG_CHARGING 247#ifdef CONFIG_CHARGING
249 {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged", 248 {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged",
250 backlight_times_conf }, 249 backlight_times_conf },
@@ -296,7 +295,7 @@ static const struct bit_entry rtc_bits[] =
296 {6, S_O(remote_contrast), 42, "remote contrast", NULL }, 295 {6, S_O(remote_contrast), 42, "remote contrast", NULL },
297 {1, S_O(remote_invert), false, "remote invert", off_on }, 296 {1, S_O(remote_invert), false, "remote invert", off_on },
298 {1, S_O(remote_flip_display), false, "remote flip display", off_on }, 297 {1, S_O(remote_flip_display), false, "remote flip display", off_on },
299 {5, S_O(remote_backlight_timeout), 5, "remote backlight timeout", 298 {5, S_O(remote_backlight_timeout), 6, "remote backlight timeout",
300 backlight_times_conf }, 299 backlight_times_conf },
301#ifdef CONFIG_CHARGING 300#ifdef CONFIG_CHARGING
302 {5, S_O(remote_backlight_timeout_plugged), 11, 301 {5, S_O(remote_backlight_timeout_plugged), 11,
@@ -319,8 +318,7 @@ static const struct bit_entry rtc_bits[] =
319 {1, S_O(remote_bl_filter_first_keypress), false, 318 {1, S_O(remote_bl_filter_first_keypress), false,
320 "backlight filters first remote keypress", off_on }, 319 "backlight filters first remote keypress", off_on },
321#endif 320#endif
322 321#endif /* CONFIG_BACKLIGHT */
323#endif
324 322
325 /* new stuff to be added here */ 323 /* new stuff to be added here */
326 /* If values are just added to the end, no need to bump the version. */ 324 /* If values are just added to the end, no need to bump the version. */
@@ -574,6 +572,20 @@ static const struct bit_entry hd_bits[] =
574 {1, S_O(warnon_erase_dynplaylist), false, 572 {1, S_O(warnon_erase_dynplaylist), false,
575 "warn when erasing dynamic playlist", off_on }, 573 "warn when erasing dynamic playlist", off_on },
576 574
575#ifdef CONFIG_BACKLIGHT
576#ifdef HAS_BUTTON_HOLD
577 {2, S_O(backlight_on_button_hold), 0, "backlight on button hold",
578 "normal,off,on" },
579#endif
580
581#ifdef HAVE_LCD_SLEEP
582 {4, S_O(lcd_sleep_after_backlight_off), 3,
583 "lcd sleep after backlight off",
584 "always,never,5,10,15,20,30,45,60,90" },
585#endif
586#endif /* CONFIG_BACKLIGHT */
587
588
577 589
578 /* If values are just added to the end, no need to bump the version. */ 590 /* If values are just added to the end, no need to bump the version. */
579 /* new stuff to be added at the end */ 591 /* new stuff to be added at the end */
@@ -1183,7 +1195,13 @@ void settings_apply(void)
1183#ifdef HAVE_REMOTE_LCD 1195#ifdef HAVE_REMOTE_LCD
1184 set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress); 1196 set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress);
1185#endif 1197#endif
1198#ifdef HAS_BUTTON_HOLD
1199 backlight_set_on_button_hold(global_settings.backlight_on_button_hold);
1200#endif
1201#ifdef HAVE_LCD_SLEEP
1202 lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
1186#endif 1203#endif
1204#endif /* CONFIG_BACKLIGHT */
1187} 1205}
1188 1206
1189 1207
diff --git a/apps/settings.h b/apps/settings.h
index 4ab290914a..369e1ebd6b 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -531,7 +531,13 @@ struct user_settings
531#ifdef HAVE_REMOTE_LCD 531#ifdef HAVE_REMOTE_LCD
532 bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */ 532 bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */
533#endif 533#endif
534#ifdef HAS_BUTTON_HOLD
535 int backlight_on_button_hold;
534#endif 536#endif
537#ifdef HAVE_LCD_SLEEP
538 int lcd_sleep_after_backlight_off;
539#endif
540#endif /* CONFIG_BACKLIGHT */
535 541
536#ifdef HAVE_LCD_BITMAP 542#ifdef HAVE_LCD_BITMAP
537 unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */ 543 unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 20235f5a72..93c809d007 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -196,6 +196,21 @@ static bool backlight_timer(void)
196 backlight_set_timeout ); 196 backlight_set_timeout );
197} 197}
198 198
199#ifdef HAS_BUTTON_HOLD
200static bool backlight_on_button_hold(void)
201{
202 static const struct opt_items names[3] = {
203 { STR(LANG_BACKLIGHT_ON_BUTTON_HOLD_NORMAL) },
204 { STR(LANG_OFF) },
205 { STR(LANG_ON) },
206 };
207 return set_option(str(LANG_BACKLIGHT_ON_BUTTON_HOLD),
208 &global_settings.backlight_on_button_hold,
209 INT, names, 3,
210 backlight_set_on_button_hold);
211}
212#endif /* HAS_BUTTON_HOLD */
213
199#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 214#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
200static bool backlight_fade_in(void) 215static bool backlight_fade_in(void)
201{ 216{
@@ -227,6 +242,29 @@ static bool backlight_fade_out(void)
227 INT, names, 8, backlight_set_fade_out ); 242 INT, names, 8, backlight_set_fade_out );
228} 243}
229#endif 244#endif
245
246#ifdef HAVE_LCD_SLEEP
247static bool lcd_sleep_after_backlight_off(void)
248{
249 static const struct opt_items names[] = {
250 { STR(LANG_ALWAYS) },
251 { STR(LANG_NEVER) },
252 { (unsigned char *)"5s", TALK_ID(5, UNIT_SEC) },
253 { (unsigned char *)"10s", TALK_ID(10, UNIT_SEC) },
254 { (unsigned char *)"15s", TALK_ID(15, UNIT_SEC) },
255 { (unsigned char *)"20s", TALK_ID(20, UNIT_SEC) },
256 { (unsigned char *)"30s", TALK_ID(30, UNIT_SEC) },
257 { (unsigned char *)"45s", TALK_ID(45, UNIT_SEC) },
258 { (unsigned char *)"60s", TALK_ID(60, UNIT_SEC) },
259 { (unsigned char *)"90s", TALK_ID(90, UNIT_SEC) },
260 };
261
262 return set_option(str(LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF),
263 &global_settings.lcd_sleep_after_backlight_off,
264 INT, names, 10,
265 lcd_set_sleep_after_backlight_off );
266}
267#endif /* HAVE_LCD_SLEEP */
230#endif /* CONFIG_BACKLIGHT */ 268#endif /* CONFIG_BACKLIGHT */
231 269
232#ifdef HAVE_BACKLIGHT_BRIGHTNESS 270#ifdef HAVE_BACKLIGHT_BRIGHTNESS
@@ -257,7 +295,7 @@ static bool remote_backlight_timer_plugged(void)
257 INT, backlight_timeouts, 19, 295 INT, backlight_timeouts, 19,
258 remote_backlight_set_timeout_plugged ); 296 remote_backlight_set_timeout_plugged );
259} 297}
260#endif 298#endif /* HAVE_REMOTE_LCD */
261 299
262static bool remote_caption_backlight(void) 300static bool remote_caption_backlight(void)
263{ 301{
@@ -1771,12 +1809,18 @@ static bool lcd_settings_menu(void)
1771#ifdef CONFIG_CHARGING 1809#ifdef CONFIG_CHARGING
1772 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged }, 1810 { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged },
1773#endif 1811#endif
1812#ifdef HAS_BUTTON_HOLD
1813 { ID2P(LANG_BACKLIGHT_ON_BUTTON_HOLD), backlight_on_button_hold },
1814#endif
1774 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, 1815 { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
1775#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 1816#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
1776 { ID2P(LANG_BACKLIGHT_FADE_IN), backlight_fade_in }, 1817 { ID2P(LANG_BACKLIGHT_FADE_IN), backlight_fade_in },
1777 { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out }, 1818 { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out },
1778#endif 1819#endif
1779 { ID2P(LANG_BACKLIGHT_FILTER_FIRST_KEYPRESS), set_bl_filter_first_keypress }, 1820 { ID2P(LANG_BACKLIGHT_FILTER_FIRST_KEYPRESS), set_bl_filter_first_keypress },
1821#ifdef HAVE_LCD_SLEEP
1822 { ID2P(LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF), lcd_sleep_after_backlight_off },
1823#endif
1780#ifdef HAVE_BACKLIGHT_BRIGHTNESS 1824#ifdef HAVE_BACKLIGHT_BRIGHTNESS
1781 { ID2P(LANG_BRIGHTNESS), brightness }, 1825 { ID2P(LANG_BRIGHTNESS), brightness },
1782#endif 1826#endif
diff --git a/firmware/backlight.c b/firmware/backlight.c
index cd1fbaf1ba..f35e87a81d 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -27,15 +27,16 @@
27#include "usb.h" 27#include "usb.h"
28#include "power.h" 28#include "power.h"
29#include "system.h" 29#include "system.h"
30#include "button.h"
30#include "timer.h" 31#include "timer.h"
31#include "backlight.h" 32#include "backlight.h"
32 33
33#ifdef HAVE_BACKLIGHT_BRIGHTNESS 34#ifdef HAVE_BACKLIGHT_BRIGHTNESS
34#include "pcf50606.h" /* iRiver brightness */ 35#include "pcf50606.h" /* iRiver, iAudio X5 brightness */
35#endif 36#endif
36 37
37#if (CONFIG_BACKLIGHT == BL_IRIVER_H300) 38#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
38#include "lcd.h" /* for lcd_enable() */ 39#include "lcd.h" /* for lcd_enable() and lcd_sleep() */
39#endif 40#endif
40#ifdef HAVE_REMOTE_LCD 41#ifdef HAVE_REMOTE_LCD
41#include "lcd-remote.h" 42#include "lcd-remote.h"
@@ -61,11 +62,11 @@ static inline void __backlight_off(void)
61static inline void __backlight_on(void) 62static inline void __backlight_on(void)
62{ 63{
63#if CONFIG_BACKLIGHT == BL_IRIVER_H100 64#if CONFIG_BACKLIGHT == BL_IRIVER_H100
64 and_l(~0x00020000, &GPIO1_OUT); 65 and_l(~0x00020000, &GPIO1_OUT);
65#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 66#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
66 lcd_enable(true); 67 lcd_enable(true);
67 sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */ 68 sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */
68 or_l(0x00020000, &GPIO1_OUT); 69 or_l(0x00020000, &GPIO1_OUT);
69#elif CONFIG_BACKLIGHT == BL_RTC 70#elif CONFIG_BACKLIGHT == BL_RTC
70 /* Enable square wave */ 71 /* Enable square wave */
71 rtc_write(0x0a, rtc_read(0x0a) | 0x40); 72 rtc_write(0x0a, rtc_read(0x0a) | 0x40);
@@ -148,9 +149,17 @@ const signed char backlight_timeout_value[19] =
148#define REMOTE_BACKLIGHT_ON 3 149#define REMOTE_BACKLIGHT_ON 3
149#define REMOTE_BACKLIGHT_OFF 4 150#define REMOTE_BACKLIGHT_OFF 4
150#define BACKLIGHT_UNBOOST_CPU 5 151#define BACKLIGHT_UNBOOST_CPU 5
152#ifdef HAVE_LCD_SLEEP
153#define LCD_SLEEP 6
154#endif
151 155
152static void backlight_thread(void); 156static void backlight_thread(void);
153static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)]; 157static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
158#ifdef X5_BACKLIGHT_SHUTDOWN
159#define BACKLIGHT_QUIT 256
160/* Need to save this for x5 shutdown */
161static int backlight_thread_id;
162#endif
154static const char backlight_thread_name[] = "backlight"; 163static const char backlight_thread_name[] = "backlight";
155static struct event_queue backlight_queue; 164static struct event_queue backlight_queue;
156 165
@@ -159,6 +168,9 @@ static int backlight_timeout = 5*HZ;
159#ifdef CONFIG_CHARGING 168#ifdef CONFIG_CHARGING
160static int backlight_timeout_plugged = 5*HZ; 169static int backlight_timeout_plugged = 5*HZ;
161#endif 170#endif
171#ifdef HAS_BUTTON_HOLD
172static int backlight_on_button_hold = 0;
173#endif
162 174
163#ifdef HAVE_REMOTE_LCD 175#ifdef HAVE_REMOTE_LCD
164static int remote_backlight_timer; 176static int remote_backlight_timer;
@@ -168,6 +180,15 @@ static int remote_backlight_timeout_plugged = 5*HZ;
168#endif 180#endif
169#endif 181#endif
170 182
183#ifdef HAVE_LCD_SLEEP
184const signed char lcd_sleep_timeout_value[10] =
185{
186 -1, 0, 5, 10, 15, 20, 30, 45, 60, 90
187};
188static int lcd_sleep_timer;
189static int lcd_sleep_timeout = 10*HZ;
190#endif
191
171#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 192#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
172/* backlight fading */ 193/* backlight fading */
173#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */ 194#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */
@@ -318,6 +339,9 @@ static void _backlight_on(void)
318#else 339#else
319 __backlight_on(); 340 __backlight_on();
320#endif 341#endif
342#ifdef HAVE_LCD_SLEEP
343 lcd_sleep_timer = 0; /* LCD should be awake already */
344#endif
321} 345}
322 346
323static void _backlight_off(void) 347static void _backlight_off(void)
@@ -333,6 +357,17 @@ static void _backlight_off(void)
333#else 357#else
334 __backlight_off(); 358 __backlight_off();
335#endif 359#endif
360
361#ifdef HAVE_LCD_SLEEP
362 /* Start LCD sleep countdown */
363 if (lcd_sleep_timeout < 0)
364 {
365 lcd_sleep_timer = 0; /* Setting == Always */
366 lcd_sleep();
367 }
368 else
369 lcd_sleep_timer = lcd_sleep_timeout;
370#endif
336} 371}
337 372
338#ifdef HAVE_REMOTE_LCD 373#ifdef HAVE_REMOTE_LCD
@@ -366,13 +401,79 @@ static void __remote_backlight_off(void)
366#endif 401#endif
367} 402}
368#endif /* TARGET_TREE */ 403#endif /* TARGET_TREE */
369#endif /* HAVE_REMOTE_LCD */
370#endif /* SIMULATOR */ 404#endif /* SIMULATOR */
405#endif /* HAVE_REMOTE_LCD */
406
407/* Update state of backlight according to timeout setting */
408static void backlight_update_state(void)
409{
410#ifdef CONFIG_CHARGING
411 if (charger_inserted()
412#ifdef HAVE_USB_POWER
413 || usb_powered()
414#endif
415 )
416 backlight_timer = backlight_timeout_plugged;
417 else
418#endif
419 backlight_timer = backlight_timeout;
420
421 /* Backlight == OFF in the setting? */
422 if (backlight_timer < 0)
423 {
424 backlight_timer = 0; /* Disable the timeout */
425#ifdef HAS_BUTTON_HOLD
426 if (backlight_on_button_hold == 2 && button_hold())
427 return; /* Keep on if "On" */
428#endif
429 _backlight_off();
430 }
431 else
432 {
433#ifdef HAS_BUTTON_HOLD
434 if (backlight_on_button_hold == 1 && button_hold())
435 {
436 /* Keep off if "Off". */
437 backlight_timer = 0; /* Disable the timeout */
438 return;
439 }
440#endif
441 _backlight_on();
442 }
443}
444
445#ifdef HAVE_REMOTE_LCD
446/* Update state of remote backlight according to timeout setting */
447static void remote_backlight_update_state(void)
448{
449#ifdef CONFIG_CHARGING
450 if (charger_inserted()
451#ifdef HAVE_USB_POWER
452 || usb_powered()
453#endif
454 )
455 remote_backlight_timer = remote_backlight_timeout_plugged;
456 else
457#endif
458 remote_backlight_timer = remote_backlight_timeout;
459
460 /* Backlight == OFF in the setting? */
461 if (remote_backlight_timer < 0)
462 {
463 remote_backlight_timer = 0; /* Disable the timeout */
464 __remote_backlight_off();
465 }
466 else
467 {
468 __remote_backlight_on();
469 }
470}
471#endif /* HAVE_REMOTE_LCD */
371 472
372void backlight_thread(void) 473void backlight_thread(void)
373{ 474{
374 struct event ev; 475 struct event ev;
375 476
376 while(1) 477 while(1)
377 { 478 {
378 queue_wait(&backlight_queue, &ev); 479 queue_wait(&backlight_queue, &ev);
@@ -380,61 +481,39 @@ void backlight_thread(void)
380 { 481 {
381#ifdef HAVE_REMOTE_LCD 482#ifdef HAVE_REMOTE_LCD
382 case REMOTE_BACKLIGHT_ON: 483 case REMOTE_BACKLIGHT_ON:
383#ifdef CONFIG_CHARGING 484 remote_backlight_update_state();
384 if (charger_inserted()
385#ifdef HAVE_USB_POWER
386 || usb_powered()
387#endif
388 )
389 remote_backlight_timer = remote_backlight_timeout_plugged;
390 else
391#endif
392 remote_backlight_timer = remote_backlight_timeout;
393
394 /* Backlight == OFF in the setting? */
395 if (remote_backlight_timer < 0)
396 {
397 remote_backlight_timer = 0; /* Disable the timeout */
398 __remote_backlight_off();
399 }
400 else
401 {
402 __remote_backlight_on();
403 }
404 break; 485 break;
405 486
406 case REMOTE_BACKLIGHT_OFF: 487 case REMOTE_BACKLIGHT_OFF:
488 remote_backlight_timer = 0; /* Disable the timeout */
407 __remote_backlight_off(); 489 __remote_backlight_off();
408 break; 490 break;
409 491#endif
410#endif /* HAVE_REMOTE_LCD */
411 case BACKLIGHT_ON: 492 case BACKLIGHT_ON:
412#ifdef CONFIG_CHARGING 493 backlight_update_state();
413 if (charger_inserted()
414#ifdef HAVE_USB_POWER
415 || usb_powered()
416#endif
417 )
418 backlight_timer = backlight_timeout_plugged;
419 else
420#endif
421 backlight_timer = backlight_timeout;
422
423 if (backlight_timer < 0) /* Backlight == OFF in the setting? */
424 {
425 backlight_timer = 0; /* Disable the timeout */
426 _backlight_off();
427 }
428 else
429 {
430 _backlight_on();
431 }
432 break; 494 break;
433 495
434 case BACKLIGHT_OFF: 496 case BACKLIGHT_OFF:
497 backlight_timer = 0; /* Disable the timeout */
498#ifdef HAS_BUTTON_HOLD
499 if (backlight_on_button_hold == 2 && button_hold())
500 break; /* Keep on if "On" */
501#endif
435 _backlight_off(); 502 _backlight_off();
436 break; 503 break;
437 504
505#ifdef HAVE_LCD_SLEEP
506 case LCD_SLEEP:
507 lcd_sleep();
508 break;
509#endif
510
511#ifdef X5_BACKLIGHT_SHUTDOWN
512 case BACKLIGHT_QUIT:
513 remove_thread(backlight_thread_id);
514 break;
515#endif
516
438#if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \ 517#if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
439 && !defined(SIMULATOR) 518 && !defined(SIMULATOR)
440 case BACKLIGHT_UNBOOST_CPU: 519 case BACKLIGHT_UNBOOST_CPU:
@@ -451,8 +530,8 @@ void backlight_thread(void)
451 case SYS_USB_DISCONNECTED: 530 case SYS_USB_DISCONNECTED:
452 usb_acknowledge(SYS_USB_DISCONNECTED_ACK); 531 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
453 break; 532 break;
454 } 533 } /* end switch */
455 } 534 } /* end while */
456} 535}
457 536
458static void backlight_tick(void) 537static void backlight_tick(void)
@@ -483,6 +562,18 @@ static void backlight_tick(void)
483 backlight_off(); 562 backlight_off();
484 } 563 }
485 } 564 }
565#ifdef HAVE_LCD_SLEEP
566 else if(lcd_sleep_timer)
567 {
568 lcd_sleep_timer--;
569 if(lcd_sleep_timer == 0)
570 {
571 /* Queue on bl thread or freeze! */
572 queue_post(&backlight_queue, LCD_SLEEP, NULL);
573 }
574 }
575#endif /* HAVE_LCD_SLEEP */
576
486#ifdef HAVE_REMOTE_LCD 577#ifdef HAVE_REMOTE_LCD
487 if(remote_backlight_timer) 578 if(remote_backlight_timer)
488 { 579 {
@@ -492,12 +583,15 @@ static void backlight_tick(void)
492 remote_backlight_off(); 583 remote_backlight_off();
493 } 584 }
494 } 585 }
495#endif 586#endif /* HAVE_REMOVE_LCD */
496} 587}
497 588
498void backlight_init(void) 589void backlight_init(void)
499{ 590{
500 queue_init(&backlight_queue); 591 queue_init(&backlight_queue);
592#ifdef X5_BACKLIGHT_SHUTDOWN
593 backlight_thread_id =
594#endif
501 create_thread(backlight_thread, backlight_stack, 595 create_thread(backlight_thread, backlight_stack,
502 sizeof(backlight_stack), backlight_thread_name); 596 sizeof(backlight_stack), backlight_thread_name);
503 tick_add_task(backlight_tick); 597 tick_add_task(backlight_tick);
@@ -516,13 +610,26 @@ void backlight_init(void)
516 or_b(0x40, &PAIORH); /* ..and output */ 610 or_b(0x40, &PAIORH); /* ..and output */
517#elif CONFIG_BACKLIGHT == BL_GMINI 611#elif CONFIG_BACKLIGHT == BL_GMINI
518 P1CON |= 0x10; /* P1.4 C-MOS output mode */ 612 P1CON |= 0x10; /* P1.4 C-MOS output mode */
519#endif 613#endif
520 backlight_on(); 614 backlight_on();
521#ifdef HAVE_REMOTE_LCD 615#ifdef HAVE_REMOTE_LCD
522 remote_backlight_on(); 616 remote_backlight_on();
523#endif 617#endif
524} 618}
525 619
620#ifdef X5_BACKLIGHT_SHUTDOWN
621void x5_backlight_shutdown(void)
622{
623 /* Turn on the screen and don't let anyone else mess with it. Called
624 from clean_shutdown in misc.c. */
625 queue_empty(&backlight_queue);
626 tick_remove_task(backlight_tick);
627 /* Next time the thread runs, if at all, it will just remove itself. */
628 queue_post(&backlight_queue, BACKLIGHT_QUIT, NULL);
629 __backlight_on();
630}
631#endif /* X5_BACKLIGHT_SHUTDOWN */
632
526void backlight_on(void) 633void backlight_on(void)
527{ 634{
528 queue_post(&backlight_queue, BACKLIGHT_ON, NULL); 635 queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
@@ -562,22 +669,72 @@ int backlight_get_current_timeout(void)
562void backlight_set_timeout(int index) 669void backlight_set_timeout(int index)
563{ 670{
564 if((unsigned)index >= sizeof(backlight_timeout_value)) 671 if((unsigned)index >= sizeof(backlight_timeout_value))
565 /* if given a weird value, use 0 */ 672 /* if given a weird value, use default */
566 index=0; 673 index = 6;
567 backlight_timeout = HZ * backlight_timeout_value[index]; 674 backlight_timeout = HZ * backlight_timeout_value[index];
568 backlight_on(); 675 backlight_update_state();
569} 676}
570 677
571#ifdef CONFIG_CHARGING 678#ifdef CONFIG_CHARGING
572void backlight_set_timeout_plugged(int index) 679void backlight_set_timeout_plugged(int index)
573{ 680{
574 if((unsigned)index >= sizeof(backlight_timeout_value)) 681 if((unsigned)index >= sizeof(backlight_timeout_value))
575 /* if given a weird value, use 0 */ 682 /* if given a weird value, use default */
576 index=0; 683 index = 6;
577 backlight_timeout_plugged = HZ * backlight_timeout_value[index]; 684 backlight_timeout_plugged = HZ * backlight_timeout_value[index];
578 backlight_on(); 685 backlight_update_state();
579} 686}
580#endif 687#endif /* CONFIG_CHARGING */
688
689#ifdef HAS_BUTTON_HOLD
690/* Hold button change event handler. */
691void backlight_hold_changed(bool hold_button)
692{
693 /* Hold switch overrides all backlight behavior except when
694 set to "Normal" */
695 /* Queue or freeze */
696 if (hold_button && backlight_on_button_hold == 1)
697 {
698 backlight_off(); /* setting == Off */
699 }
700 else /* setting == On, Normal, no hold button, or anything else */
701 backlight_on();
702}
703
704void backlight_set_on_button_hold(int index)
705{
706 if ((unsigned)index >= 3)
707 /* if given a weird value, use default */
708 index = 0;
709
710 if (index == backlight_on_button_hold)
711 return;
712
713 backlight_on_button_hold = index;
714 backlight_hold_changed(button_hold());
715}
716#endif /* HAS_BUTTON_HOLD */
717
718#ifdef HAVE_LCD_SLEEP
719void lcd_set_sleep_after_backlight_off(int index)
720{
721 if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
722 /* if given a weird value, use default */
723 index = 3;
724
725 lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
726
727 if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
728 /* Timer will be set when bl turns off or bl set to on. */
729 return;
730
731 /* Backlight is Off */
732 if (lcd_sleep_timeout < 0)
733 lcd_sleep_timer = 1; /* Always - sleep next tick */
734 else
735 lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
736}
737#endif /* HAVE_LCD_SLEEP */
581 738
582#ifdef HAVE_REMOTE_LCD 739#ifdef HAVE_REMOTE_LCD
583void remote_backlight_on(void) 740void remote_backlight_on(void)
@@ -593,22 +750,22 @@ void remote_backlight_off(void)
593void remote_backlight_set_timeout(int index) 750void remote_backlight_set_timeout(int index)
594{ 751{
595 if((unsigned)index >= sizeof(backlight_timeout_value)) 752 if((unsigned)index >= sizeof(backlight_timeout_value))
596 /* if given a weird value, use 0 */ 753 /* if given a weird value, use default */
597 index=0; 754 index=6;
598 remote_backlight_timeout = HZ * backlight_timeout_value[index]; 755 remote_backlight_timeout = HZ * backlight_timeout_value[index];
599 remote_backlight_on(); 756 remote_backlight_update_state();
600} 757}
601 758
602#ifdef CONFIG_CHARGING 759#ifdef CONFIG_CHARGING
603void remote_backlight_set_timeout_plugged(int index) 760void remote_backlight_set_timeout_plugged(int index)
604{ 761{
605 if((unsigned)index >= sizeof(backlight_timeout_value)) 762 if((unsigned)index >= sizeof(backlight_timeout_value))
606 /* if given a weird value, use 0 */ 763 /* if given a weird value, use default */
607 index=0; 764 index=6;
608 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index]; 765 remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
609 remote_backlight_on(); 766 remote_backlight_update_state();
610} 767}
611#endif 768#endif /* CONFIG_CHARGING */
612 769
613/* return value in ticks; 0 means always on, <0 means always off */ 770/* return value in ticks; 0 means always on, <0 means always off */
614int remote_backlight_get_current_timeout(void) 771int remote_backlight_get_current_timeout(void)
@@ -639,7 +796,8 @@ bool is_remote_backlight_on(void)
639 796
640#endif /* HAVE_REMOTE_LCD */ 797#endif /* HAVE_REMOTE_LCD */
641 798
642#else /* no backlight, empty dummy functions */ 799#else /* !defined(CONFIG_BACKLIGHT) || defined(BOOTLOADER)
800 -- no backlight, empty dummy functions */
643 801
644#if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT) 802#if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT)
645void backlight_init(void) 803void backlight_init(void)
@@ -662,8 +820,10 @@ void remote_backlight_off(void) {}
662void remote_backlight_set_timeout(int index) {(void)index;} 820void remote_backlight_set_timeout(int index) {(void)index;}
663bool is_remote_backlight_on(void) {return true;} 821bool is_remote_backlight_on(void) {return true;}
664#endif 822#endif
665#endif /* #ifdef CONFIG_BACKLIGHT */ 823#endif /* defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) */
666 824
825/* TODO: Move low level code to target/ tree. Create
826 __backlight_set_brightness and call from here. */
667#ifdef HAVE_BACKLIGHT_BRIGHTNESS 827#ifdef HAVE_BACKLIGHT_BRIGHTNESS
668#if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5) 828#if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5)
669void backlight_set_brightness(int val) 829void backlight_set_brightness(int val)
@@ -692,5 +852,5 @@ void backlight_set_brightness(int val)
692#endif 852#endif
693} 853}
694#endif 854#endif
695#endif 855#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
696 856
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index d9f9ae2a6d..9ff0206a2b 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -844,21 +844,15 @@ static int button_read(void)
844 static bool remote_hold_button = false; 844 static bool remote_hold_button = false;
845 static int prev_data = 0xff; 845 static int prev_data = 0xff;
846 static int last_valid = 0xff; 846 static int last_valid = 0xff;
847 bool hold_button_old;
847 848
848 /* light handling */ 849 /* normal buttons */
849 if (hold_button && !button_hold()) 850 hold_button_old = hold_button;
850 {
851 backlight_on();
852 }
853 if (remote_hold_button && !remote_button_hold_only())
854 {
855 remote_backlight_on();
856 }
857
858 hold_button = button_hold(); 851 hold_button = button_hold();
859 remote_hold_button = remote_button_hold_only();
860 852
861 /* normal buttons */ 853 if (hold_button != hold_button_old)
854 backlight_hold_changed(hold_button);
855
862 if (!hold_button) 856 if (!hold_button)
863 { 857 {
864 data = adc_scan(ADC_BUTTONS); 858 data = adc_scan(ADC_BUTTONS);
@@ -920,6 +914,13 @@ static int button_read(void)
920 } 914 }
921 915
922 /* remote buttons */ 916 /* remote buttons */
917 remote_hold_button = remote_button_hold_only();
918
919 if (remote_hold_button && !remote_button_hold_only())
920 {
921 remote_backlight_on();
922 }
923
923 if (!remote_hold_button) 924 if (!remote_hold_button)
924 { 925 {
925 data = adc_scan(ADC_REMOTE); 926 data = adc_scan(ADC_REMOTE);
@@ -1038,15 +1039,15 @@ static int button_read(void)
1038 1039
1039#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD 1040#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1040 static bool hold_button = false; 1041 static bool hold_button = false;
1042 bool hold_button_old;
1041 1043
1042 /* light handling */ 1044 /* normal buttons */
1043 if (hold_button && !button_hold()) 1045 hold_button_old = hold_button;
1044 {
1045 backlight_on();
1046 }
1047 hold_button = button_hold(); 1046 hold_button = button_hold();
1048 1047
1049 /* normal buttons */ 1048 if (hold_button != hold_button_old)
1049 backlight_hold_changed(hold_button);
1050
1050 if (!button_hold()) 1051 if (!button_hold())
1051 { 1052 {
1052 data = adc_read(ADC_BUTTONS); 1053 data = adc_read(ADC_BUTTONS);
@@ -1217,28 +1218,30 @@ static int button_read(void)
1217 1218
1218#elif (CONFIG_KEYPAD == IPOD_4G_PAD) 1219#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
1219 static bool hold_button = false; 1220 static bool hold_button = false;
1221 bool hold_button_old;
1220 1222
1221 /* light handling */ 1223 /* normal buttons */
1222 if (hold_button && !button_hold()) 1224 hold_button_old = hold_button;
1223 {
1224 backlight_on();
1225 }
1226 hold_button = button_hold(); 1225 hold_button = button_hold();
1227 1226
1227 if (hold_button != hold_button_old)
1228 backlight_hold_changed(hold_button);
1229
1228 (void)data; 1230 (void)data;
1229 /* The int_btn variable is set in the button interrupt handler */ 1231 /* The int_btn variable is set in the button interrupt handler */
1230 btn = int_btn; 1232 btn = int_btn;
1231 1233
1232#elif (CONFIG_KEYPAD == IPOD_3G_PAD) 1234#elif (CONFIG_KEYPAD == IPOD_3G_PAD)
1233 static bool hold_button = false; 1235 static bool hold_button = false;
1236 bool hold_button_old;
1234 1237
1235 /* light handling */ 1238 /* normal buttons */
1236 if (hold_button && !button_hold()) 1239 hold_button_old = hold_button;
1237 {
1238 backlight_on();
1239 }
1240 hold_button = button_hold(); 1240 hold_button = button_hold();
1241 1241
1242 if (hold_button != hold_button_old)
1243 backlight_hold_changed(hold_button);
1244
1242 (void)data; 1245 (void)data;
1243 btn = ipod_3g_button_read(); 1246 btn = ipod_3g_button_read();
1244 1247
diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h
index 09960b7537..62f024816f 100644
--- a/firmware/export/backlight.h
+++ b/firmware/export/backlight.h
@@ -27,6 +27,10 @@ void backlight_off(void);
27void backlight_set_timeout(int index); 27void backlight_set_timeout(int index);
28#ifdef CONFIG_BACKLIGHT 28#ifdef CONFIG_BACKLIGHT
29void backlight_init(void); 29void backlight_init(void);
30#if defined(IAUDIO_X5) && !defined(SIMULATOR)
31#define X5_BACKLIGHT_SHUTDOWN
32void x5_backlight_shutdown(void);
33#endif
30int backlight_get_current_timeout(void); 34int backlight_get_current_timeout(void);
31#ifdef HAVE_BACKLIGHT_PWM_FADING 35#ifdef HAVE_BACKLIGHT_PWM_FADING
32void backlight_set_fade_in(int index); 36void backlight_set_fade_in(int index);
@@ -34,9 +38,17 @@ void backlight_set_fade_out(int index);
34#endif 38#endif
35void backlight_set_timeout_plugged(int index); 39void backlight_set_timeout_plugged(int index);
36extern const signed char backlight_timeout_value[]; 40extern const signed char backlight_timeout_value[];
37#else 41#ifdef HAS_BUTTON_HOLD
38#define backlight_init() 42void backlight_set_on_button_hold(int index);
43void backlight_hold_changed(bool hold_button);
39#endif 44#endif
45#ifdef HAVE_LCD_SLEEP
46void lcd_set_sleep_after_backlight_off(int index);
47extern const signed char lcd_sleep_timeout_value[];
48#endif
49#else /* ndef CONFIG_BACKLIGHT */
50#define backlight_init()
51#endif /* CONFIG_BACKLIGHT */
40 52
41#ifdef HAVE_REMOTE_LCD 53#ifdef HAVE_REMOTE_LCD
42void remote_backlight_on(void); 54void remote_backlight_on(void);
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index e98b60c9fc..6d5fbabbdf 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -70,6 +70,9 @@
70 70
71#ifndef SIMULATOR 71#ifndef SIMULATOR
72 72
73/* Define this if your LCD can be enabled/disabled */
74#define HAVE_LCD_ENABLE
75
73/* Define this if you have a Motorola SCF5249 */ 76/* Define this if you have a Motorola SCF5249 */
74#define CONFIG_CPU MCF5249 77#define CONFIG_CPU MCF5249
75 78
@@ -126,4 +129,4 @@
126/* define this if the unit can be powered or charged via USB */ 129/* define this if the unit can be powered or charged via USB */
127#define HAVE_USB_POWER 130#define HAVE_USB_POWER
128 131
129#endif 132#endif /* SIMULATOR */
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index a828ca1ec9..afb5074662 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -23,7 +23,6 @@
23#define LCD_HEIGHT 128 23#define LCD_HEIGHT 128
24#define LCD_DEPTH 16 /* pseudo 262.144 colors */ 24#define LCD_DEPTH 16 /* pseudo 262.144 colors */
25#define LCD_PIXELFORMAT RGB565 /* rgb565 */ 25#define LCD_PIXELFORMAT RGB565 /* rgb565 */
26#define HAVE_LCD_CONTRAST
27 26
28/* remote LCD */ 27/* remote LCD */
29#define LCD_REMOTE_WIDTH 128 28#define LCD_REMOTE_WIDTH 128
@@ -47,7 +46,7 @@
47#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ 46#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */
48 47
49/* Define this for LCD backlight available */ 48/* Define this for LCD backlight available */
50#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled !?!? */ 49#define CONFIG_BACKLIGHT BL_X5 /* PCF50606 I2C */
51#define HAVE_BACKLIGHT_BRIGHTNESS 50#define HAVE_BACKLIGHT_BRIGHTNESS
52 51
53/* Define this if you have a software controlled poweroff */ 52/* Define this if you have a software controlled poweroff */
@@ -70,6 +69,16 @@
70 69
71#ifndef SIMULATOR 70#ifndef SIMULATOR
72 71
72/* Define this if your LCD can set contrast */
73#define HAVE_LCD_CONTRAST
74
75/* Define this if your LCD can be enabled/disabled */
76#define HAVE_LCD_ENABLE
77
78/* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE
79 should be defined as well. */
80#define HAVE_LCD_SLEEP
81
73/* Define this if you have a Motorola SCF5250 */ 82/* Define this if you have a Motorola SCF5250 */
74#define CONFIG_CPU MCF5250 83#define CONFIG_CPU MCF5250
75 84
@@ -122,4 +131,4 @@
122#define BOOTFILE_EXT "iaudio" 131#define BOOTFILE_EXT "iaudio"
123#define BOOTFILE "rockbox." BOOTFILE_EXT 132#define BOOTFILE "rockbox." BOOTFILE_EXT
124 133
125#endif 134#endif /* SIMULATOR */
diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h
index d0d2d0664c..831ff40c1d 100644
--- a/firmware/export/config-ipod3g.h
+++ b/firmware/export/config-ipod3g.h
@@ -54,6 +54,9 @@
54 54
55#ifndef SIMULATOR 55#ifndef SIMULATOR
56 56
57/* Define this if your LCD can be enabled/disabled */
58#define HAVE_LCD_ENABLE
59
57/* Define this if you have a PortalPlayer PP5002 */ 60/* Define this if you have a PortalPlayer PP5002 */
58#define CONFIG_CPU PP5002 61#define CONFIG_CPU PP5002
59 62
@@ -103,4 +106,4 @@
103#define BOOTFILE_EXT "ipod" 106#define BOOTFILE_EXT "ipod"
104#define BOOTFILE "rockbox." BOOTFILE_EXT 107#define BOOTFILE "rockbox." BOOTFILE_EXT
105 108
106#endif 109#endif /* SIMULATOR */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 0dd1d25637..f00ac6498c 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -116,6 +116,7 @@
116#define BL_IPODMINI 10 /* Apple iPod Mini */ 116#define BL_IPODMINI 10 /* Apple iPod Mini */
117#define BL_GIGABEAT 11 /* Toshiba Gigabeat */ 117#define BL_GIGABEAT 11 /* Toshiba Gigabeat */
118#define BL_IRIVER_H10 12 /* iriver H10 */ 118#define BL_IRIVER_H10 12 /* iriver H10 */
119#define BL_X5 13 /* iAudio X5 PCF50606 I2C */
119 120
120/* CONFIG_I2C */ 121/* CONFIG_I2C */
121#define I2C_PLAYREC 0 /* Archos Player/Recorder style */ 122#define I2C_PLAYREC 0 /* Archos Player/Recorder style */
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index c3ad4f97d9..5c362c2b53 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -227,10 +227,17 @@ extern fb_data lcd_framebuffer[LCD_HEIGHT][LCD_WIDTH];
227#define LCD_FBWIDTH LCD_WIDTH 227#define LCD_FBWIDTH LCD_WIDTH
228#endif 228#endif
229 229
230#if (CONFIG_BACKLIGHT==BL_IRIVER_H300) || (CONFIG_BACKLIGHT==BL_IPOD3G) 230/** Port-specific functions. Enable in port config file. **/
231#ifdef HAVE_LCD_ENABLE
232/* Enable/disable the main display. */
231extern void lcd_enable(bool on); 233extern void lcd_enable(bool on);
232#endif 234#endif
233 235
236#ifdef HAVE_LCD_SLEEP
237/* Put the LCD into a power saving state deeper than lcd_enable(false). */
238extern void lcd_sleep(void);
239#endif
240
234/* Bitmap formats */ 241/* Bitmap formats */
235enum 242enum
236{ 243{
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index a8e641e1ed..1be361a01d 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -1032,10 +1032,12 @@ void shutdown_hw(void)
1032#elif defined(HAVE_WM8758) || defined(HAVE_WM8975) 1032#elif defined(HAVE_WM8758) || defined(HAVE_WM8975)
1033 wmcodec_close(); 1033 wmcodec_close();
1034#endif 1034#endif
1035#ifndef IAUDIO_X5
1035#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) 1036#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
1036 backlight_set_fade_out(0); 1037 backlight_set_fade_out(0);
1037#endif 1038#endif
1038 backlight_off(); 1039 backlight_off();
1040#endif /* IAUDIO_X5 */
1039#if defined(IPOD_ARCH) && defined(HAVE_LCD_COLOR) 1041#if defined(IPOD_ARCH) && defined(HAVE_LCD_COLOR)
1040 /* Clear the screen and backdrop to 1042 /* Clear the screen and backdrop to
1041 remove ghosting effect on shutdown */ 1043 remove ghosting effect on shutdown */
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