1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Rani Hod 2006-08-08 22:03:56 +00:00
parent f8866a3a9c
commit c9f59e6f75
17 changed files with 644 additions and 211 deletions

View file

@ -8805,6 +8805,62 @@
</dest> </dest>
<voice> <voice>
*: "(Vol- : Re-enable)" *: "(Vol- : Re-enable)"
<phrase>
id: LANG_BACKLIGHT_ON_BUTTON_HOLD_NORMAL
desc: in lcd settings
user:
<source>
*: "Normal"
</source>
<dest>
*: "Normal"
</dest>
<voice>
*: "Normal"
</voice>
</phrase>
<phrase>
id: LANG_BACKLIGHT_ON_BUTTON_HOLD
desc: in lcd settings
user:
<source>
*: "Backlight (On Hold Key)"
</source>
<dest>
*: "Backlight (On Hold Key)"
</dest>
<voice>
*: "Backlight on hold key"
</voice>
</phrase>
<phrase>
id: LANG_NEVER
desc: in lcd settings
user:
<source>
*: "Never"
</source>
<dest>
*: "Never"
</dest>
<voice>
*: "Never"
</voice>
</phrase>
<phrase>
id: LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF
desc: In display settings, time to switch LCD chip into power saving state
user:
<source>
*: "Sleep (After Backlight Off)"
</source>
<dest>
*: "Sleep (After Backlight Off)"
</dest>
<voice>
*: "Sleep after backlight off"
</voice>
</phrase>
</voice> </voice>
</phrase> </phrase>
<phrase> <phrase>

View file

@ -491,6 +491,9 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
{ {
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
screens[i].clear_display(); screens[i].clear_display();
#ifdef X5_BACKLIGHT_SHUTDOWN
x5_backlight_shutdown();
#endif
gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN));
if (!tagcache_prepare_shutdown()) if (!tagcache_prepare_shutdown())

View file

@ -24,11 +24,11 @@
#include "config.h" #include "config.h"
#include "kernel.h" #include "kernel.h"
#include "thread.h" #include "thread.h"
#include "button.h"
#include "settings.h" #include "settings.h"
#include "disk.h" #include "disk.h"
#include "panic.h" #include "panic.h"
#include "debug.h" #include "debug.h"
#include "button.h"
#include "usb.h" #include "usb.h"
#include "backlight.h" #include "backlight.h"
#include "lcd.h" #include "lcd.h"
@ -40,7 +40,6 @@
#include "ata.h" #include "ata.h"
#include "fat.h" #include "fat.h"
#include "power.h" #include "power.h"
#include "backlight.h"
#include "powermgmt.h" #include "powermgmt.h"
#include "status.h" #include "status.h"
#include "atoi.h" #include "atoi.h"
@ -244,7 +243,7 @@ static const struct bit_entry rtc_bits[] =
{6, S_O(contrast), DEFAULT_CONTRAST_SETTING, "contrast", NULL }, {6, S_O(contrast), DEFAULT_CONTRAST_SETTING, "contrast", NULL },
#endif #endif
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT
{5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf }, {5, S_O(backlight_timeout), 6, "backlight timeout", backlight_times_conf },
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
{5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged", {5, S_O(backlight_timeout_plugged), 11, "backlight timeout plugged",
backlight_times_conf }, backlight_times_conf },
@ -296,7 +295,7 @@ static const struct bit_entry rtc_bits[] =
{6, S_O(remote_contrast), 42, "remote contrast", NULL }, {6, S_O(remote_contrast), 42, "remote contrast", NULL },
{1, S_O(remote_invert), false, "remote invert", off_on }, {1, S_O(remote_invert), false, "remote invert", off_on },
{1, S_O(remote_flip_display), false, "remote flip display", off_on }, {1, S_O(remote_flip_display), false, "remote flip display", off_on },
{5, S_O(remote_backlight_timeout), 5, "remote backlight timeout", {5, S_O(remote_backlight_timeout), 6, "remote backlight timeout",
backlight_times_conf }, backlight_times_conf },
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
{5, S_O(remote_backlight_timeout_plugged), 11, {5, S_O(remote_backlight_timeout_plugged), 11,
@ -319,8 +318,7 @@ static const struct bit_entry rtc_bits[] =
{1, S_O(remote_bl_filter_first_keypress), false, {1, S_O(remote_bl_filter_first_keypress), false,
"backlight filters first remote keypress", off_on }, "backlight filters first remote keypress", off_on },
#endif #endif
#endif /* CONFIG_BACKLIGHT */
#endif
/* new stuff to be added here */ /* new stuff to be added here */
/* If values are just added to the end, no need to bump the version. */ /* 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[] =
{1, S_O(warnon_erase_dynplaylist), false, {1, S_O(warnon_erase_dynplaylist), false,
"warn when erasing dynamic playlist", off_on }, "warn when erasing dynamic playlist", off_on },
#ifdef CONFIG_BACKLIGHT
#ifdef HAS_BUTTON_HOLD
{2, S_O(backlight_on_button_hold), 0, "backlight on button hold",
"normal,off,on" },
#endif
#ifdef HAVE_LCD_SLEEP
{4, S_O(lcd_sleep_after_backlight_off), 3,
"lcd sleep after backlight off",
"always,never,5,10,15,20,30,45,60,90" },
#endif
#endif /* CONFIG_BACKLIGHT */
/* If values are just added to the end, no need to bump the version. */ /* If values are just added to the end, no need to bump the version. */
/* new stuff to be added at the end */ /* new stuff to be added at the end */
@ -1183,7 +1195,13 @@ void settings_apply(void)
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress); set_remote_backlight_filter_keypress(global_settings.remote_bl_filter_first_keypress);
#endif #endif
#ifdef HAS_BUTTON_HOLD
backlight_set_on_button_hold(global_settings.backlight_on_button_hold);
#endif #endif
#ifdef HAVE_LCD_SLEEP
lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off);
#endif
#endif /* CONFIG_BACKLIGHT */
} }

View file

@ -531,7 +531,13 @@ struct user_settings
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */ bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */
#endif #endif
#ifdef HAS_BUTTON_HOLD
int backlight_on_button_hold;
#endif #endif
#ifdef HAVE_LCD_SLEEP
int lcd_sleep_after_backlight_off;
#endif
#endif /* CONFIG_BACKLIGHT */
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */ unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */

View file

@ -196,6 +196,21 @@ static bool backlight_timer(void)
backlight_set_timeout ); backlight_set_timeout );
} }
#ifdef HAS_BUTTON_HOLD
static bool backlight_on_button_hold(void)
{
static const struct opt_items names[3] = {
{ STR(LANG_BACKLIGHT_ON_BUTTON_HOLD_NORMAL) },
{ STR(LANG_OFF) },
{ STR(LANG_ON) },
};
return set_option(str(LANG_BACKLIGHT_ON_BUTTON_HOLD),
&global_settings.backlight_on_button_hold,
INT, names, 3,
backlight_set_on_button_hold);
}
#endif /* HAS_BUTTON_HOLD */
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
static bool backlight_fade_in(void) static bool backlight_fade_in(void)
{ {
@ -227,6 +242,29 @@ static bool backlight_fade_out(void)
INT, names, 8, backlight_set_fade_out ); INT, names, 8, backlight_set_fade_out );
} }
#endif #endif
#ifdef HAVE_LCD_SLEEP
static bool lcd_sleep_after_backlight_off(void)
{
static const struct opt_items names[] = {
{ STR(LANG_ALWAYS) },
{ STR(LANG_NEVER) },
{ (unsigned char *)"5s", TALK_ID(5, UNIT_SEC) },
{ (unsigned char *)"10s", TALK_ID(10, UNIT_SEC) },
{ (unsigned char *)"15s", TALK_ID(15, UNIT_SEC) },
{ (unsigned char *)"20s", TALK_ID(20, UNIT_SEC) },
{ (unsigned char *)"30s", TALK_ID(30, UNIT_SEC) },
{ (unsigned char *)"45s", TALK_ID(45, UNIT_SEC) },
{ (unsigned char *)"60s", TALK_ID(60, UNIT_SEC) },
{ (unsigned char *)"90s", TALK_ID(90, UNIT_SEC) },
};
return set_option(str(LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF),
&global_settings.lcd_sleep_after_backlight_off,
INT, names, 10,
lcd_set_sleep_after_backlight_off );
}
#endif /* HAVE_LCD_SLEEP */
#endif /* CONFIG_BACKLIGHT */ #endif /* CONFIG_BACKLIGHT */
#ifdef HAVE_BACKLIGHT_BRIGHTNESS #ifdef HAVE_BACKLIGHT_BRIGHTNESS
@ -257,7 +295,7 @@ static bool remote_backlight_timer_plugged(void)
INT, backlight_timeouts, 19, INT, backlight_timeouts, 19,
remote_backlight_set_timeout_plugged ); remote_backlight_set_timeout_plugged );
} }
#endif #endif /* HAVE_REMOTE_LCD */
static bool remote_caption_backlight(void) static bool remote_caption_backlight(void)
{ {
@ -1770,6 +1808,9 @@ static bool lcd_settings_menu(void)
{ ID2P(LANG_BACKLIGHT), backlight_timer }, { ID2P(LANG_BACKLIGHT), backlight_timer },
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
{ ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged }, { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged },
#endif
#ifdef HAS_BUTTON_HOLD
{ ID2P(LANG_BACKLIGHT_ON_BUTTON_HOLD), backlight_on_button_hold },
#endif #endif
{ ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight },
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
@ -1777,6 +1818,9 @@ static bool lcd_settings_menu(void)
{ ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out }, { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out },
#endif #endif
{ ID2P(LANG_BACKLIGHT_FILTER_FIRST_KEYPRESS), set_bl_filter_first_keypress }, { ID2P(LANG_BACKLIGHT_FILTER_FIRST_KEYPRESS), set_bl_filter_first_keypress },
#ifdef HAVE_LCD_SLEEP
{ ID2P(LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF), lcd_sleep_after_backlight_off },
#endif
#ifdef HAVE_BACKLIGHT_BRIGHTNESS #ifdef HAVE_BACKLIGHT_BRIGHTNESS
{ ID2P(LANG_BRIGHTNESS), brightness }, { ID2P(LANG_BRIGHTNESS), brightness },
#endif #endif

View file

@ -27,15 +27,16 @@
#include "usb.h" #include "usb.h"
#include "power.h" #include "power.h"
#include "system.h" #include "system.h"
#include "button.h"
#include "timer.h" #include "timer.h"
#include "backlight.h" #include "backlight.h"
#ifdef HAVE_BACKLIGHT_BRIGHTNESS #ifdef HAVE_BACKLIGHT_BRIGHTNESS
#include "pcf50606.h" /* iRiver brightness */ #include "pcf50606.h" /* iRiver, iAudio X5 brightness */
#endif #endif
#if (CONFIG_BACKLIGHT == BL_IRIVER_H300) #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
#include "lcd.h" /* for lcd_enable() */ #include "lcd.h" /* for lcd_enable() and lcd_sleep() */
#endif #endif
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h" #include "lcd-remote.h"
@ -148,9 +149,17 @@ const signed char backlight_timeout_value[19] =
#define REMOTE_BACKLIGHT_ON 3 #define REMOTE_BACKLIGHT_ON 3
#define REMOTE_BACKLIGHT_OFF 4 #define REMOTE_BACKLIGHT_OFF 4
#define BACKLIGHT_UNBOOST_CPU 5 #define BACKLIGHT_UNBOOST_CPU 5
#ifdef HAVE_LCD_SLEEP
#define LCD_SLEEP 6
#endif
static void backlight_thread(void); static void backlight_thread(void);
static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)]; static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
#ifdef X5_BACKLIGHT_SHUTDOWN
#define BACKLIGHT_QUIT 256
/* Need to save this for x5 shutdown */
static int backlight_thread_id;
#endif
static const char backlight_thread_name[] = "backlight"; static const char backlight_thread_name[] = "backlight";
static struct event_queue backlight_queue; static struct event_queue backlight_queue;
@ -159,6 +168,9 @@ static int backlight_timeout = 5*HZ;
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
static int backlight_timeout_plugged = 5*HZ; static int backlight_timeout_plugged = 5*HZ;
#endif #endif
#ifdef HAS_BUTTON_HOLD
static int backlight_on_button_hold = 0;
#endif
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
static int remote_backlight_timer; static int remote_backlight_timer;
@ -168,6 +180,15 @@ static int remote_backlight_timeout_plugged = 5*HZ;
#endif #endif
#endif #endif
#ifdef HAVE_LCD_SLEEP
const signed char lcd_sleep_timeout_value[10] =
{
-1, 0, 5, 10, 15, 20, 30, 45, 60, 90
};
static int lcd_sleep_timer;
static int lcd_sleep_timeout = 10*HZ;
#endif
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
/* backlight fading */ /* backlight fading */
#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */ #define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */
@ -318,6 +339,9 @@ static void _backlight_on(void)
#else #else
__backlight_on(); __backlight_on();
#endif #endif
#ifdef HAVE_LCD_SLEEP
lcd_sleep_timer = 0; /* LCD should be awake already */
#endif
} }
static void _backlight_off(void) static void _backlight_off(void)
@ -333,6 +357,17 @@ static void _backlight_off(void)
#else #else
__backlight_off(); __backlight_off();
#endif #endif
#ifdef HAVE_LCD_SLEEP
/* Start LCD sleep countdown */
if (lcd_sleep_timeout < 0)
{
lcd_sleep_timer = 0; /* Setting == Always */
lcd_sleep();
}
else
lcd_sleep_timer = lcd_sleep_timeout;
#endif
} }
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
@ -366,8 +401,74 @@ static void __remote_backlight_off(void)
#endif #endif
} }
#endif /* TARGET_TREE */ #endif /* TARGET_TREE */
#endif /* HAVE_REMOTE_LCD */
#endif /* SIMULATOR */ #endif /* SIMULATOR */
#endif /* HAVE_REMOTE_LCD */
/* Update state of backlight according to timeout setting */
static void backlight_update_state(void)
{
#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
#endif
)
backlight_timer = backlight_timeout_plugged;
else
#endif
backlight_timer = backlight_timeout;
/* Backlight == OFF in the setting? */
if (backlight_timer < 0)
{
backlight_timer = 0; /* Disable the timeout */
#ifdef HAS_BUTTON_HOLD
if (backlight_on_button_hold == 2 && button_hold())
return; /* Keep on if "On" */
#endif
_backlight_off();
}
else
{
#ifdef HAS_BUTTON_HOLD
if (backlight_on_button_hold == 1 && button_hold())
{
/* Keep off if "Off". */
backlight_timer = 0; /* Disable the timeout */
return;
}
#endif
_backlight_on();
}
}
#ifdef HAVE_REMOTE_LCD
/* Update state of remote backlight according to timeout setting */
static void remote_backlight_update_state(void)
{
#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
#endif
)
remote_backlight_timer = remote_backlight_timeout_plugged;
else
#endif
remote_backlight_timer = remote_backlight_timeout;
/* Backlight == OFF in the setting? */
if (remote_backlight_timer < 0)
{
remote_backlight_timer = 0; /* Disable the timeout */
__remote_backlight_off();
}
else
{
__remote_backlight_on();
}
}
#endif /* HAVE_REMOTE_LCD */
void backlight_thread(void) void backlight_thread(void)
{ {
@ -380,61 +481,39 @@ void backlight_thread(void)
{ {
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
case REMOTE_BACKLIGHT_ON: case REMOTE_BACKLIGHT_ON:
#ifdef CONFIG_CHARGING remote_backlight_update_state();
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
#endif
)
remote_backlight_timer = remote_backlight_timeout_plugged;
else
#endif
remote_backlight_timer = remote_backlight_timeout;
/* Backlight == OFF in the setting? */
if (remote_backlight_timer < 0)
{
remote_backlight_timer = 0; /* Disable the timeout */
__remote_backlight_off();
}
else
{
__remote_backlight_on();
}
break; break;
case REMOTE_BACKLIGHT_OFF: case REMOTE_BACKLIGHT_OFF:
remote_backlight_timer = 0; /* Disable the timeout */
__remote_backlight_off(); __remote_backlight_off();
break; break;
#endif
#endif /* HAVE_REMOTE_LCD */
case BACKLIGHT_ON: case BACKLIGHT_ON:
#ifdef CONFIG_CHARGING backlight_update_state();
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
#endif
)
backlight_timer = backlight_timeout_plugged;
else
#endif
backlight_timer = backlight_timeout;
if (backlight_timer < 0) /* Backlight == OFF in the setting? */
{
backlight_timer = 0; /* Disable the timeout */
_backlight_off();
}
else
{
_backlight_on();
}
break; break;
case BACKLIGHT_OFF: case BACKLIGHT_OFF:
backlight_timer = 0; /* Disable the timeout */
#ifdef HAS_BUTTON_HOLD
if (backlight_on_button_hold == 2 && button_hold())
break; /* Keep on if "On" */
#endif
_backlight_off(); _backlight_off();
break; break;
#ifdef HAVE_LCD_SLEEP
case LCD_SLEEP:
lcd_sleep();
break;
#endif
#ifdef X5_BACKLIGHT_SHUTDOWN
case BACKLIGHT_QUIT:
remove_thread(backlight_thread_id);
break;
#endif
#if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \ #if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
&& !defined(SIMULATOR) && !defined(SIMULATOR)
case BACKLIGHT_UNBOOST_CPU: case BACKLIGHT_UNBOOST_CPU:
@ -451,8 +530,8 @@ void backlight_thread(void)
case SYS_USB_DISCONNECTED: case SYS_USB_DISCONNECTED:
usb_acknowledge(SYS_USB_DISCONNECTED_ACK); usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
break; break;
} } /* end switch */
} } /* end while */
} }
static void backlight_tick(void) static void backlight_tick(void)
@ -483,6 +562,18 @@ static void backlight_tick(void)
backlight_off(); backlight_off();
} }
} }
#ifdef HAVE_LCD_SLEEP
else if(lcd_sleep_timer)
{
lcd_sleep_timer--;
if(lcd_sleep_timer == 0)
{
/* Queue on bl thread or freeze! */
queue_post(&backlight_queue, LCD_SLEEP, NULL);
}
}
#endif /* HAVE_LCD_SLEEP */
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
if(remote_backlight_timer) if(remote_backlight_timer)
{ {
@ -492,12 +583,15 @@ static void backlight_tick(void)
remote_backlight_off(); remote_backlight_off();
} }
} }
#endif #endif /* HAVE_REMOVE_LCD */
} }
void backlight_init(void) void backlight_init(void)
{ {
queue_init(&backlight_queue); queue_init(&backlight_queue);
#ifdef X5_BACKLIGHT_SHUTDOWN
backlight_thread_id =
#endif
create_thread(backlight_thread, backlight_stack, create_thread(backlight_thread, backlight_stack,
sizeof(backlight_stack), backlight_thread_name); sizeof(backlight_stack), backlight_thread_name);
tick_add_task(backlight_tick); tick_add_task(backlight_tick);
@ -523,6 +617,19 @@ void backlight_init(void)
#endif #endif
} }
#ifdef X5_BACKLIGHT_SHUTDOWN
void x5_backlight_shutdown(void)
{
/* Turn on the screen and don't let anyone else mess with it. Called
from clean_shutdown in misc.c. */
queue_empty(&backlight_queue);
tick_remove_task(backlight_tick);
/* Next time the thread runs, if at all, it will just remove itself. */
queue_post(&backlight_queue, BACKLIGHT_QUIT, NULL);
__backlight_on();
}
#endif /* X5_BACKLIGHT_SHUTDOWN */
void backlight_on(void) void backlight_on(void)
{ {
queue_post(&backlight_queue, BACKLIGHT_ON, NULL); queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
@ -562,22 +669,72 @@ int backlight_get_current_timeout(void)
void backlight_set_timeout(int index) void backlight_set_timeout(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */ /* if given a weird value, use default */
index=0; index = 6;
backlight_timeout = HZ * backlight_timeout_value[index]; backlight_timeout = HZ * backlight_timeout_value[index];
backlight_on(); backlight_update_state();
} }
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
void backlight_set_timeout_plugged(int index) void backlight_set_timeout_plugged(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */ /* if given a weird value, use default */
index=0; index = 6;
backlight_timeout_plugged = HZ * backlight_timeout_value[index]; backlight_timeout_plugged = HZ * backlight_timeout_value[index];
backlight_on(); backlight_update_state();
} }
#endif #endif /* CONFIG_CHARGING */
#ifdef HAS_BUTTON_HOLD
/* Hold button change event handler. */
void backlight_hold_changed(bool hold_button)
{
/* Hold switch overrides all backlight behavior except when
set to "Normal" */
/* Queue or freeze */
if (hold_button && backlight_on_button_hold == 1)
{
backlight_off(); /* setting == Off */
}
else /* setting == On, Normal, no hold button, or anything else */
backlight_on();
}
void backlight_set_on_button_hold(int index)
{
if ((unsigned)index >= 3)
/* if given a weird value, use default */
index = 0;
if (index == backlight_on_button_hold)
return;
backlight_on_button_hold = index;
backlight_hold_changed(button_hold());
}
#endif /* HAS_BUTTON_HOLD */
#ifdef HAVE_LCD_SLEEP
void lcd_set_sleep_after_backlight_off(int index)
{
if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
/* if given a weird value, use default */
index = 3;
lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
/* Timer will be set when bl turns off or bl set to on. */
return;
/* Backlight is Off */
if (lcd_sleep_timeout < 0)
lcd_sleep_timer = 1; /* Always - sleep next tick */
else
lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
}
#endif /* HAVE_LCD_SLEEP */
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void) void remote_backlight_on(void)
@ -593,22 +750,22 @@ void remote_backlight_off(void)
void remote_backlight_set_timeout(int index) void remote_backlight_set_timeout(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */ /* if given a weird value, use default */
index=0; index=6;
remote_backlight_timeout = HZ * backlight_timeout_value[index]; remote_backlight_timeout = HZ * backlight_timeout_value[index];
remote_backlight_on(); remote_backlight_update_state();
} }
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
void remote_backlight_set_timeout_plugged(int index) void remote_backlight_set_timeout_plugged(int index)
{ {
if((unsigned)index >= sizeof(backlight_timeout_value)) if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */ /* if given a weird value, use default */
index=0; index=6;
remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index]; remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
remote_backlight_on(); remote_backlight_update_state();
} }
#endif #endif /* CONFIG_CHARGING */
/* return value in ticks; 0 means always on, <0 means always off */ /* return value in ticks; 0 means always on, <0 means always off */
int remote_backlight_get_current_timeout(void) int remote_backlight_get_current_timeout(void)
@ -639,7 +796,8 @@ bool is_remote_backlight_on(void)
#endif /* HAVE_REMOTE_LCD */ #endif /* HAVE_REMOTE_LCD */
#else /* no backlight, empty dummy functions */ #else /* !defined(CONFIG_BACKLIGHT) || defined(BOOTLOADER)
-- no backlight, empty dummy functions */
#if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT) #if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT)
void backlight_init(void) void backlight_init(void)
@ -662,8 +820,10 @@ void remote_backlight_off(void) {}
void remote_backlight_set_timeout(int index) {(void)index;} void remote_backlight_set_timeout(int index) {(void)index;}
bool is_remote_backlight_on(void) {return true;} bool is_remote_backlight_on(void) {return true;}
#endif #endif
#endif /* #ifdef CONFIG_BACKLIGHT */ #endif /* defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) */
/* TODO: Move low level code to target/ tree. Create
__backlight_set_brightness and call from here. */
#ifdef HAVE_BACKLIGHT_BRIGHTNESS #ifdef HAVE_BACKLIGHT_BRIGHTNESS
#if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5) #if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5)
void backlight_set_brightness(int val) void backlight_set_brightness(int val)
@ -692,5 +852,5 @@ void backlight_set_brightness(int val)
#endif #endif
} }
#endif #endif
#endif #endif /* HAVE_BACKLIGHT_BRIGHTNESS */

View file

@ -844,21 +844,15 @@ static int button_read(void)
static bool remote_hold_button = false; static bool remote_hold_button = false;
static int prev_data = 0xff; static int prev_data = 0xff;
static int last_valid = 0xff; static int last_valid = 0xff;
bool hold_button_old;
/* light handling */
if (hold_button && !button_hold())
{
backlight_on();
}
if (remote_hold_button && !remote_button_hold_only())
{
remote_backlight_on();
}
hold_button = button_hold();
remote_hold_button = remote_button_hold_only();
/* normal buttons */ /* normal buttons */
hold_button_old = hold_button;
hold_button = button_hold();
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
if (!hold_button) if (!hold_button)
{ {
data = adc_scan(ADC_BUTTONS); data = adc_scan(ADC_BUTTONS);
@ -920,6 +914,13 @@ static int button_read(void)
} }
/* remote buttons */ /* remote buttons */
remote_hold_button = remote_button_hold_only();
if (remote_hold_button && !remote_button_hold_only())
{
remote_backlight_on();
}
if (!remote_hold_button) if (!remote_hold_button)
{ {
data = adc_scan(ADC_REMOTE); data = adc_scan(ADC_REMOTE);
@ -1038,15 +1039,15 @@ static int button_read(void)
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
static bool hold_button = false; static bool hold_button = false;
bool hold_button_old;
/* light handling */
if (hold_button && !button_hold())
{
backlight_on();
}
hold_button = button_hold();
/* normal buttons */ /* normal buttons */
hold_button_old = hold_button;
hold_button = button_hold();
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
if (!button_hold()) if (!button_hold())
{ {
data = adc_read(ADC_BUTTONS); data = adc_read(ADC_BUTTONS);
@ -1217,28 +1218,30 @@ static int button_read(void)
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
static bool hold_button = false; static bool hold_button = false;
bool hold_button_old;
/* light handling */ /* normal buttons */
if (hold_button && !button_hold()) hold_button_old = hold_button;
{
backlight_on();
}
hold_button = button_hold(); hold_button = button_hold();
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
(void)data; (void)data;
/* The int_btn variable is set in the button interrupt handler */ /* The int_btn variable is set in the button interrupt handler */
btn = int_btn; btn = int_btn;
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) #elif (CONFIG_KEYPAD == IPOD_3G_PAD)
static bool hold_button = false; static bool hold_button = false;
bool hold_button_old;
/* light handling */ /* normal buttons */
if (hold_button && !button_hold()) hold_button_old = hold_button;
{
backlight_on();
}
hold_button = button_hold(); hold_button = button_hold();
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
(void)data; (void)data;
btn = ipod_3g_button_read(); btn = ipod_3g_button_read();

View file

@ -27,6 +27,10 @@ void backlight_off(void);
void backlight_set_timeout(int index); void backlight_set_timeout(int index);
#ifdef CONFIG_BACKLIGHT #ifdef CONFIG_BACKLIGHT
void backlight_init(void); void backlight_init(void);
#if defined(IAUDIO_X5) && !defined(SIMULATOR)
#define X5_BACKLIGHT_SHUTDOWN
void x5_backlight_shutdown(void);
#endif
int backlight_get_current_timeout(void); int backlight_get_current_timeout(void);
#ifdef HAVE_BACKLIGHT_PWM_FADING #ifdef HAVE_BACKLIGHT_PWM_FADING
void backlight_set_fade_in(int index); void backlight_set_fade_in(int index);
@ -34,9 +38,17 @@ void backlight_set_fade_out(int index);
#endif #endif
void backlight_set_timeout_plugged(int index); void backlight_set_timeout_plugged(int index);
extern const signed char backlight_timeout_value[]; extern const signed char backlight_timeout_value[];
#else #ifdef HAS_BUTTON_HOLD
#define backlight_init() void backlight_set_on_button_hold(int index);
void backlight_hold_changed(bool hold_button);
#endif #endif
#ifdef HAVE_LCD_SLEEP
void lcd_set_sleep_after_backlight_off(int index);
extern const signed char lcd_sleep_timeout_value[];
#endif
#else /* ndef CONFIG_BACKLIGHT */
#define backlight_init()
#endif /* CONFIG_BACKLIGHT */
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void); void remote_backlight_on(void);

View file

@ -70,6 +70,9 @@
#ifndef SIMULATOR #ifndef SIMULATOR
/* Define this if your LCD can be enabled/disabled */
#define HAVE_LCD_ENABLE
/* Define this if you have a Motorola SCF5249 */ /* Define this if you have a Motorola SCF5249 */
#define CONFIG_CPU MCF5249 #define CONFIG_CPU MCF5249
@ -126,4 +129,4 @@
/* define this if the unit can be powered or charged via USB */ /* define this if the unit can be powered or charged via USB */
#define HAVE_USB_POWER #define HAVE_USB_POWER
#endif #endif /* SIMULATOR */

View file

@ -23,7 +23,6 @@
#define LCD_HEIGHT 128 #define LCD_HEIGHT 128
#define LCD_DEPTH 16 /* pseudo 262.144 colors */ #define LCD_DEPTH 16 /* pseudo 262.144 colors */
#define LCD_PIXELFORMAT RGB565 /* rgb565 */ #define LCD_PIXELFORMAT RGB565 /* rgb565 */
#define HAVE_LCD_CONTRAST
/* remote LCD */ /* remote LCD */
#define LCD_REMOTE_WIDTH 128 #define LCD_REMOTE_WIDTH 128
@ -47,7 +46,7 @@
#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ #define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */
/* Define this for LCD backlight available */ /* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled !?!? */ #define CONFIG_BACKLIGHT BL_X5 /* PCF50606 I2C */
#define HAVE_BACKLIGHT_BRIGHTNESS #define HAVE_BACKLIGHT_BRIGHTNESS
/* Define this if you have a software controlled poweroff */ /* Define this if you have a software controlled poweroff */
@ -70,6 +69,16 @@
#ifndef SIMULATOR #ifndef SIMULATOR
/* Define this if your LCD can set contrast */
#define HAVE_LCD_CONTRAST
/* Define this if your LCD can be enabled/disabled */
#define HAVE_LCD_ENABLE
/* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE
should be defined as well. */
#define HAVE_LCD_SLEEP
/* Define this if you have a Motorola SCF5250 */ /* Define this if you have a Motorola SCF5250 */
#define CONFIG_CPU MCF5250 #define CONFIG_CPU MCF5250
@ -122,4 +131,4 @@
#define BOOTFILE_EXT "iaudio" #define BOOTFILE_EXT "iaudio"
#define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTFILE "rockbox." BOOTFILE_EXT
#endif #endif /* SIMULATOR */

View file

@ -54,6 +54,9 @@
#ifndef SIMULATOR #ifndef SIMULATOR
/* Define this if your LCD can be enabled/disabled */
#define HAVE_LCD_ENABLE
/* Define this if you have a PortalPlayer PP5002 */ /* Define this if you have a PortalPlayer PP5002 */
#define CONFIG_CPU PP5002 #define CONFIG_CPU PP5002
@ -103,4 +106,4 @@
#define BOOTFILE_EXT "ipod" #define BOOTFILE_EXT "ipod"
#define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTFILE "rockbox." BOOTFILE_EXT
#endif #endif /* SIMULATOR */

View file

@ -116,6 +116,7 @@
#define BL_IPODMINI 10 /* Apple iPod Mini */ #define BL_IPODMINI 10 /* Apple iPod Mini */
#define BL_GIGABEAT 11 /* Toshiba Gigabeat */ #define BL_GIGABEAT 11 /* Toshiba Gigabeat */
#define BL_IRIVER_H10 12 /* iriver H10 */ #define BL_IRIVER_H10 12 /* iriver H10 */
#define BL_X5 13 /* iAudio X5 PCF50606 I2C */
/* CONFIG_I2C */ /* CONFIG_I2C */
#define I2C_PLAYREC 0 /* Archos Player/Recorder style */ #define I2C_PLAYREC 0 /* Archos Player/Recorder style */

View file

@ -227,10 +227,17 @@ extern fb_data lcd_framebuffer[LCD_HEIGHT][LCD_WIDTH];
#define LCD_FBWIDTH LCD_WIDTH #define LCD_FBWIDTH LCD_WIDTH
#endif #endif
#if (CONFIG_BACKLIGHT==BL_IRIVER_H300) || (CONFIG_BACKLIGHT==BL_IPOD3G) /** Port-specific functions. Enable in port config file. **/
#ifdef HAVE_LCD_ENABLE
/* Enable/disable the main display. */
extern void lcd_enable(bool on); extern void lcd_enable(bool on);
#endif #endif
#ifdef HAVE_LCD_SLEEP
/* Put the LCD into a power saving state deeper than lcd_enable(false). */
extern void lcd_sleep(void);
#endif
/* Bitmap formats */ /* Bitmap formats */
enum enum
{ {

View file

@ -1032,10 +1032,12 @@ void shutdown_hw(void)
#elif defined(HAVE_WM8758) || defined(HAVE_WM8975) #elif defined(HAVE_WM8758) || defined(HAVE_WM8975)
wmcodec_close(); wmcodec_close();
#endif #endif
#ifndef IAUDIO_X5
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
backlight_set_fade_out(0); backlight_set_fade_out(0);
#endif #endif
backlight_off(); backlight_off();
#endif /* IAUDIO_X5 */
#if defined(IPOD_ARCH) && defined(HAVE_LCD_COLOR) #if defined(IPOD_ARCH) && defined(HAVE_LCD_COLOR)
/* Clear the screen and backdrop to /* Clear the screen and backdrop to
remove ghosting effect on shutdown */ remove ghosting effect on shutdown */

View file

@ -21,10 +21,13 @@
#include "system.h" #include "system.h"
#include "backlight.h" #include "backlight.h"
#include "pcf50606.h" #include "pcf50606.h"
#include "lcd.h"
void __backlight_on(void) void __backlight_on(void)
{ {
int level = set_irq_level(HIGHEST_IRQ_LEVEL); int level;
lcd_enable(true);
level = set_irq_level(HIGHEST_IRQ_LEVEL);
pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */ pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */
set_irq_level(level); set_irq_level(level);
} }
@ -34,6 +37,7 @@ void __backlight_off(void)
int level = set_irq_level(HIGHEST_IRQ_LEVEL); int level = set_irq_level(HIGHEST_IRQ_LEVEL);
pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=000 */ pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=000 */
set_irq_level(level); set_irq_level(level);
lcd_enable(false);
} }
void __remote_backlight_on(void) void __remote_backlight_on(void)

View file

@ -50,18 +50,16 @@ int button_read_device(void)
int btn = BUTTON_NONE; int btn = BUTTON_NONE;
static bool hold_button = false; static bool hold_button = false;
static bool remote_hold_button = false; static bool remote_hold_button = false;
bool hold_button_old;
/* backlight handling */
if (hold_button && !button_hold())
{
backlight_on();
}
/* TODO: add light handling for the remote */
hold_button = button_hold();
remote_hold_button = remote_button_hold();
/* normal buttons */ /* normal buttons */
hold_button_old = hold_button;
hold_button = button_hold();
/* give BL notice if HB state chaged */
if (hold_button != hold_button_old)
backlight_hold_changed(hold_button);
if (!hold_button) if (!hold_button)
{ {
data = adc_scan(ADC_BUTTONS); data = adc_scan(ADC_BUTTONS);
@ -90,6 +88,11 @@ int button_read_device(void)
} }
/* remote buttons */ /* remote buttons */
/* TODO: add light handling for the remote */
remote_hold_button = remote_button_hold();
data = adc_scan(ADC_REMOTE); data = adc_scan(ADC_REMOTE);
if(data < 0x17) if(data < 0x17)
remote_hold_button = true; remote_hold_button = true;

View file

@ -30,14 +30,20 @@
#include "font.h" #include "font.h"
#include "bidi.h" #include "bidi.h"
/** Initialized in lcd_init_device() **/
/* Is the power turned on? */
static bool power_on;
/* Is the display turned on? */ /* Is the display turned on? */
static bool display_on = false; static bool display_on;
/* Amount of vertical offset. Used for flip offset correction/detection. */
/* Amount of vertical offset. Used for offset correction when flipped. */ static int y_offset;
static int y_offset = 0;
/* Amount of roll offset (0-127). */ /* Amount of roll offset (0-127). */
static int roll_offset = 0; static int roll_offset;
/* Reverse flag. Must be remembered when display is turned off. */
static unsigned short disp_control_rev;
/* Forward declarations */
static void lcd_display_off(void);
/* A15(0x8000) && CS1->CS, A1(0x0002)->RS */ /* A15(0x8000) && CS1->CS, A1(0x0002)->RS */
#define LCD_CMD *(volatile unsigned short *)0xf0008000 #define LCD_CMD *(volatile unsigned short *)0xf0008000
@ -79,16 +85,16 @@ static int roll_offset = 0;
#define R_GAMMA_AMP_ADJ_NEG 0x3b #define R_GAMMA_AMP_ADJ_NEG 0x3b
/* called very frequently - inline! */ /* called very frequently - inline! */
inline void lcd_write_reg(int reg, int val) static inline void lcd_write_reg(int reg, int val)
{ {
LCD_CMD = 0x0000; /* MSB is ~always~ 0 */ LCD_CMD = 0x0000; /* MSB is ~always~ 0 */
LCD_CMD = reg << 1; LCD_CMD = reg << 1;
LCD_DATA = (val >> 8) << 1; LCD_DATA = (val >> 8) << 1;
LCD_DATA = (val & 0xff) << 1; LCD_DATA = val << 1;
} }
/* called very frequently - inline! */ /* called very frequently - inline! */
inline void lcd_begin_write_gram(void) static inline void lcd_begin_write_gram(void)
{ {
LCD_CMD = 0x0000; LCD_CMD = 0x0000;
LCD_CMD = R_WRITE_DATA_2_GRAM << 1; LCD_CMD = R_WRITE_DATA_2_GRAM << 1;
@ -135,21 +141,35 @@ void lcd_set_contrast(int val)
void lcd_set_invert_display(bool yesno) void lcd_set_invert_display(bool yesno)
{ {
if (yesno == (disp_control_rev == 0x0000))
return;
disp_control_rev = yesno ? 0x0000 : 0x0004;
if (!display_on)
return;
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */ /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, yesno ? 0x0033 : 0x0037); lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
} }
/* turn the display upside down (call lcd_update() afterwards) */ /* turn the display upside down (call lcd_update() afterwards) */
void lcd_set_flip(bool yesno) void lcd_set_flip(bool yesno)
{ {
if (yesno == (y_offset != 0))
return;
y_offset = yesno ? 4 : 0; y_offset = yesno ? 4 : 0;
/* SCN4-0=000x0 (G160) */
if (!power_on)
return;
/* SCN4-0=000x0 (G1/G160) */
lcd_write_reg(R_GATE_SCAN_START_POS, yesno ? 0x0000 : 0x0002); lcd_write_reg(R_GATE_SCAN_START_POS, yesno ? 0x0000 : 0x0002);
/* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/ /* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
lcd_write_reg(R_DRV_OUTPUT_CONTROL, yesno ? 0x0013 : 0x0313); lcd_write_reg(R_DRV_OUTPUT_CONTROL, yesno ? 0x0013 : 0x0313);
/* Vertical stripe */
/* HEA7-0=0xxx, HSA7-0=0xxx */ /* HEA7-0=0xxx, HSA7-0=0xxx */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00 + (y_offset << 8) + y_offset); lcd_write_reg(R_HORIZ_RAM_ADDR_POS, yesno ? 0x8304 : 0x7f00);
} }
/* Rolls up the lcd display by the specified amount of lines. /* Rolls up the lcd display by the specified amount of lines.
@ -171,17 +191,11 @@ void lcd_roll(int lines)
roll_offset = lines; roll_offset = lines;
} }
/* LCD init */ static void lcd_power_on(void)
void lcd_init_device(void)
{ {
/* LCD Reset */ /* Be sure standby bit is clear. */
and_l(~0x00000010, &GPIO1_OUT); /* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
or_l(0x00000010, &GPIO1_ENABLE); lcd_write_reg(R_POWER_CONTROL1, 0x0000);
or_l(0x00000010, &GPIO1_FUNCTION);
sleep(HZ/100);
or_l(0x00000010, &GPIO1_OUT);
sleep(HZ/100);
/** Power ON Sequence **/ /** Power ON Sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */ /* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
@ -217,8 +231,8 @@ void lcd_init_device(void)
sleep(HZ/25); sleep(HZ/25);
/* Instructions for other mode settings (in register order). */ /* Instructions for other mode settings (in register order). */
/* SM=0, GS=1, SS=1, NL4-0=10011 (G1-G160)*/ /* SM=0, GS=x, SS=x, NL4-0=10011 (G1-G160)*/
lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x313); lcd_write_reg(R_DRV_OUTPUT_CONTROL, y_offset ? 0x0013 : 0x0313);
/* FLD1-0=01 (1 field), B/C=1, EOR=1 (C-pat), NW5-0=000000 (1 row) */ /* FLD1-0=01 (1 field), B/C=1, EOR=1 (C-pat), NW5-0=000000 (1 row) */
lcd_write_reg(R_DRV_AC_CONTROL, 0x0700); lcd_write_reg(R_DRV_AC_CONTROL, 0x0700);
/* DIT=1, BGR=1, HWM=0, I/D1-0=11, AM=1, LG2-0=000 */ /* DIT=1, BGR=1, HWM=0, I/D1-0=11, AM=1, LG2-0=000 */
@ -227,16 +241,16 @@ void lcd_init_device(void)
lcd_write_reg(R_COMPARE_REG, 0x0000); lcd_write_reg(R_COMPARE_REG, 0x0000);
/* NO1-0=01, SDT1-0=00, EQ1-0=00, DIV1-0=00, RTN3-00000 */ /* NO1-0=01, SDT1-0=00, EQ1-0=00, DIV1-0=00, RTN3-00000 */
lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x4000); lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x4000);
/* SCN4-0=00010 (G160) */ /* SCN4-0=000x0 (G1/G160) */
lcd_write_reg(R_GATE_SCAN_START_POS, 0x0002); lcd_write_reg(R_GATE_SCAN_START_POS, y_offset ? 0x0000 : 0x0002);
/* VL7-0=0x00 */ /* VL7-0=0x00 */
lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000); lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000);
/* SE17-10(End)=0x9f (159), SS17-10(Start)=0x00 */ /* SE17-10(End)=0x9f (159), SS17-10(Start)=0x00 */
lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00); lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00);
/* SE27-20(End)=0x5c (92), SS27-20(Start)=0x00 */ /* SE27-20(End)=0x5c (92), SS27-20(Start)=0x00 */
lcd_write_reg(R_2ND_SCR_DRV_POS, 0x5c00); lcd_write_reg(R_2ND_SCR_DRV_POS, 0x5c00);
/* HEA7-0=0x7f, HSA7-0=0x00 */ /* HEA7-0=0xxx, HSA7-0=0xxx */
lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00); /* Vertical stripe */ lcd_write_reg(R_HORIZ_RAM_ADDR_POS, y_offset ? 0x8304 : 0x7f00);
/* PKP12-10=0x0, PKP02-00=0x0 */ /* PKP12-10=0x0, PKP02-00=0x0 */
lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003); lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0003);
/* PKP32-30=0x4, PKP22-20=0x0 */ /* PKP32-30=0x4, PKP22-20=0x0 */
@ -261,32 +275,135 @@ void lcd_init_device(void)
/* 100ms or more; time for step-up circuits to stabilize */ /* 100ms or more; time for step-up circuits to stabilize */
sleep(HZ/10); sleep(HZ/10);
power_on = true;
}
static void lcd_power_off(void)
{
/* Display must be off first */
if (display_on)
lcd_display_off();
power_on = false;
/** Power OFF sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 99 */
/* Step-up1 halt setting bit */
/* BT2-0=110, DC2-0=001, AP2-0=011, SLP=0, STB=0 */
lcd_write_reg(R_POWER_CONTROL1, 0x062c);
/* Step-up3,4 halt setting bit */
/* VRL3-0=0100, PON=0, VRH3-0=0001 */
lcd_write_reg(R_POWER_CONTROL4, 0x0401);
/* VCOMG=0, VDV4-0=10011, VCM4-0=11000 */
lcd_write_reg(R_POWER_CONTROL5, 0x1318);
/* Wait 100ms or more */
sleep(HZ/10);
/* Step-up2,amp halt setting bit */
/* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=0 */
lcd_write_reg(R_POWER_CONTROL1, 0x0000);
}
static void lcd_display_on(void)
{
/* Be sure power is on first */
if (!power_on)
lcd_power_on();
/** Display ON Sequence **/ /** Display ON Sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */ /* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=1, D1-0=01 */ /* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0005); lcd_write_reg(R_DISP_CONTROL, 0x0001);
sleep(HZ/25); /* Wait 2 frames or more */ sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=01 */ /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=01 */
lcd_write_reg(R_DISP_CONTROL, 0x0025); lcd_write_reg(R_DISP_CONTROL, 0x0021 | disp_control_rev);
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=1, D1-0=11 */ /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0027); lcd_write_reg(R_DISP_CONTROL, 0x0023 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */ sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=1, D1-0=11 */ /* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=11 */
lcd_write_reg(R_DISP_CONTROL, 0x0037); lcd_write_reg(R_DISP_CONTROL, 0x0033 | disp_control_rev);
display_on = true; display_on = true;
}
static void lcd_display_off(void)
{
display_on = false;
/** Display OFF sequence **/
/* Per datasheet Rev.1.10, Jun.21.2003, p. 97 */
/* EQ1-0=00 already */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=1, REV=x, D1-0=10 */
lcd_write_reg(R_DISP_CONTROL, 0x0032 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=1, DTE=0, REV=x, D1-0=10 */
lcd_write_reg(R_DISP_CONTROL, 0x0022 | disp_control_rev);
sleep(HZ/25); /* Wait 2 frames or more */
/* PT1-0=00, VLE2-1=00, SPT=0, GON=0, DTE=0, REV=0, D1-0=00 */
lcd_write_reg(R_DISP_CONTROL, 0x0000);
}
/* LCD init */
void lcd_init_device(void)
{
/* Reset settings */
power_on = false;
display_on = false;
y_offset = 0; y_offset = 0;
roll_offset = 0; roll_offset = 0;
disp_control_rev = 0x0004;
/* LCD Reset */
and_l(~0x00000010, &GPIO1_OUT);
or_l(0x00000010, &GPIO1_ENABLE);
or_l(0x00000010, &GPIO1_FUNCTION);
sleep(HZ/100);
or_l(0x00000010, &GPIO1_OUT);
sleep(HZ/100);
lcd_display_on();
} }
void lcd_enable(bool on) void lcd_enable(bool on)
{ {
display_on = on; if (on == display_on)
return;
if (on)
{
lcd_display_on();
/* Probably out of sync and we don't wanna pepper the code with
lcd_update() calls for this. */
lcd_update();
}
else
{
lcd_display_off();
}
}
void lcd_sleep(void)
{
if (power_on)
lcd_power_off();
/* Set standby mode */
/* BT2-0=000, DC2-0=000, AP2-0=000, SLP=0, STB=1 */
lcd_write_reg(R_POWER_CONTROL1, 0x0001);
} }
/*** update functions ***/ /*** update functions ***/
@ -327,7 +444,7 @@ void lcd_update(void)
lcd_begin_write_gram(); lcd_begin_write_gram();
ptr = (unsigned long *)lcd_framebuffer; ptr = (unsigned long *)lcd_framebuffer;
ptr_end = ptr + (LCD_WIDTH*LCD_HEIGHT >> 1); ptr_end = ptr + LCD_WIDTH*LCD_HEIGHT/2;
do do
{ {
@ -375,8 +492,6 @@ void lcd_update_rect(int x, int y, int width, int height)
if (y >= y_end) if (y >= y_end)
return; /* nothing left to do */ return; /* nothing left to do */
ptr = (unsigned long *)&lcd_framebuffer[y][x];
/* Set start position and window */ /* Set start position and window */
lcd_write_reg(R_RAM_ADDR_SET, (x << 8) | lcd_write_reg(R_RAM_ADDR_SET, (x << 8) |
(((y + roll_offset) & 127) + y_offset)); (((y + roll_offset) & 127) + y_offset));
@ -384,44 +499,28 @@ void lcd_update_rect(int x, int y, int width, int height)
lcd_begin_write_gram(); lcd_begin_write_gram();
ptr = (unsigned long *)&lcd_framebuffer[y][x];
/* Aligning source reads to long boundaries helps 2% - 3% with IRAM /* Aligning source reads to long boundaries helps 2% - 3% with IRAM
buffer. DK with DRAM. */ buffer. DK with DRAM. */
odd_lead = x & 1;
/* special case widths 1 and 2. */ if (odd_lead)
switch (width)
{ {
case 1: duff = width - 1;
odd_lead = 1; /* odd_lead case writes pixels */ odd_trail = duff & 1;
odd_trail = 0; duff >>= 1;
duff = 0; /* Squelch compiler warning. */ }
duff_end = ptr; else
break; {
case 2: /* Just read as long */ duff = width >> 1;
odd_lead = 0; odd_trail = width & 1;
odd_trail = 0; }
duff = 1;
duff_end = ptr + 1;
break;
default:
odd_lead = x & 1;
if (odd_lead) duff_end = ptr + duff;
{
duff = width - 1;
odd_trail = duff & 1;
duff >>= 1;
}
else
{
duff = width >> 1;
odd_trail = width & 1;
}
duff_end = ptr + duff;
#ifndef BOOTLOADER #ifndef BOOTLOADER
duff &= 7; duff &= 7;
#endif #endif
} /* end switch */
stride = LCD_WIDTH - width + odd_trail; /* See odd_trail below */ stride = LCD_WIDTH - width + odd_trail; /* See odd_trail below */