More Gigabeat button light fixes. Settings now work properly, startup does not cause the button lights to flash when disabled. Buttonlights are now shutdown on power off.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13368 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2007-05-10 03:08:47 +00:00
parent cbf6a66aca
commit 1fc2d91a83
4 changed files with 72 additions and 49 deletions

View file

@ -109,6 +109,45 @@ static int backlight_on_button_hold = 0;
static int button_backlight_timer;
static int button_backlight_timeout = 5*HZ;
/* internal interface */
static void _button_backlight_on(void)
{
#ifndef SIMULATOR
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
__button_backlight_dim(false);
#else
__button_backlight_on();
#endif
#endif
}
void _button_backlight_off(void)
{
#ifndef SIMULATOR
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
if(button_backlight_timeout>0)
__button_backlight_dim(true);
else
#endif
__button_backlight_off();
#endif
}
/* Update state of buttonlight according to timeout setting */
static void buttonlight_update_state(void)
{
button_backlight_timer = button_backlight_timeout;
/* Buttonlight == OFF in the setting? */
if (button_backlight_timer < 0)
{
button_backlight_timer = 0; /* Disable the timeout */
_button_backlight_off();
}
else
_button_backlight_on();
}
/* external interface */
void button_backlight_on(void)
{
@ -127,33 +166,7 @@ void button_backlight_set_timeout(int index)
/* if given a weird value, use default */
index = 6;
button_backlight_timeout = HZ * backlight_timeout_value[index];
if (index == 0) /* off */
button_backlight_off();
else if (index == 1) /* on */
button_backlight_on();
button_backlight_timer = button_backlight_timeout;
}
/* internal interface */
static void _button_backlight_on(void)
{
if (button_backlight_timeout < 0)
return;
button_backlight_timer = button_backlight_timeout;
#ifndef SIMULATOR
__button_backlight_on();
#endif
}
static void _button_backlight_off(void)
{
if (button_backlight_timeout == 0)
return;
button_backlight_timer = 0;
#ifndef SIMULATOR
__button_backlight_off();
#endif
buttonlight_update_state();
}
#endif
@ -511,9 +524,10 @@ void backlight_thread(void)
#endif
#ifdef HAVE_BUTTON_LIGHT
case BUTTON_LIGHT_ON:
_button_backlight_on();
buttonlight_update_state();
break;
case BUTTON_LIGHT_OFF:
button_backlight_timer = 0;
_button_backlight_off();
break;
#endif
@ -796,7 +810,6 @@ void remote_backlight_hold_changed(bool rc_hold_button)
remote_backlight_off(); /* setting == Off */
else /* setting == On, Normal, no hold button, or anything else */
remote_backlight_on();
}
void remote_backlight_set_on_button_hold(int index)
@ -863,6 +876,8 @@ void buttonlight_set_brightness(int val)
val = MAX_BRIGHTNESS_SETTING;
__buttonlight_set_brightness(val);
if(button_backlight_timeout<0)
_button_backlight_off();
}
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */

View file

@ -69,6 +69,7 @@ unsigned char charging_leds[] = { 0x00, 0x20, 0x38, 0x3C };
bool __backlight_init(void)
{
buttonlight_brightness=DEFAULT_BRIGHTNESS_SETTING;
backlight_brightness=DEFAULT_BRIGHTNESS_SETTING;
backlight_control = BACKLIGHT_CONTROL_IDLE;
@ -152,9 +153,9 @@ static void led_control_service(void)
sc606regAval=DEFAULT_BRIGHTNESS_SETTING,
sc606regBval=DEFAULT_BRIGHTNESS_SETTING,
sc606regCval=DEFAULT_BRIGHTNESS_SETTING,
sc606regCONFval=3;
sc606regCONFval=0x03;
static bool sc606_changed=true;
static bool sc606_changed=false;
if(sc606_changed==false)
{
@ -174,9 +175,9 @@ static void led_control_service(void)
backlight_control = BACKLIGHT_CONTROL_IDLE;
break;
case BACKLIGHT_CONTROL_SET:
sc606regAval=backlight_brightness;
sc606_changed=true;
backlight_control = BACKLIGHT_CONTROL_ON;
sc606regAval=backlight_brightness;
backlight_control = BACKLIGHT_CONTROL_IDLE;
break;
case BACKLIGHT_CONTROL_FADE:
/* Was this mode set while the backlight is already on/off? */
@ -212,24 +213,25 @@ static void led_control_service(void)
case BUTTONLIGHT_CONTROL_OFF:
sc606_changed=true;
sc606regCONFval &= ~0x3C;
sc606regBval=sc606regCval=0;
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
break;
case BUTTONLIGHT_CONTROL_ON:
sc606_changed=true;
sc606regBval=sc606regCval=buttonlight_brightness;
sc606regCONFval |= 0x3C;
sc606regBval=sc606regCval=buttonlight_brightness;
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
break;
case BUTTONLIGHT_CONTROL_SET:
sc606regBval=sc606regCval=buttonlight_brightness;
sc606_changed=true;
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
sc606regBval=sc606regCval=buttonlight_brightness;
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
break;
case BUTTONLIGHT_CONTROL_FADE:
/* Was this mode set while the button light is already on/off? */
if(buttonlight_target==sc606regBval)
{
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
break;
}
sc606_changed=true;
@ -243,7 +245,7 @@ static void led_control_service(void)
else
{
sc606regCval=--sc606regBval;
if(buttonlight_target==sc606regBval)
if(sc606regBval==0)
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
}
@ -294,20 +296,25 @@ static void led_control_service(void)
void __button_backlight_on(void)
{
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
buttonlight_target = buttonlight_brightness;
if(buttonlight_brightness==0)
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
else
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
}
void __button_backlight_off(void)
{
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
}
void __button_backlight_dim(bool dim_now)
{
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
buttonlight_target = 0;
if(buttonlight_brightness==0)
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
buttonlight_target = (dim_now == true) ? 0 : buttonlight_brightness;
if(buttonlight_target==0 && buttonlight_brightness==0)
{
if(dim_now == false)
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
else
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
}
else
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
}
@ -330,7 +337,6 @@ void __backlight_dim(bool dim_now)
void __buttonlight_set_brightness(int brightness)
{
/* stop the interrupt from messing us up */
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
buttonlight_brightness = brightness;
buttonlight_control = BUTTONLIGHT_CONTROL_SET;

View file

@ -53,5 +53,6 @@ void __button_backlight_off(void);
/* true: backlight fades off - false: backlight fades on */
void __backlight_dim(bool dim);
void __button_backlight_dim(bool dim_now);
#endif

View file

@ -60,7 +60,8 @@ void power_off(void)
{
/* turn off backlight and wait for 1 second */
__backlight_off();
sleep(HZ/2);
__button_backlight_off();
sleep(HZ);
/* set SLEEP bit to on in CLKCON to turn off */
CLKCON |=(1<<3);
}