2006-08-12 08:01:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
2006-12-29 02:49:12 +00:00
|
|
|
#include "backlight-target.h"
|
2006-08-12 08:01:54 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#include "lcd.h"
|
2006-11-05 07:54:08 +00:00
|
|
|
#include "sc606-meg-fx.h"
|
2007-01-08 08:53:36 +00:00
|
|
|
#include "power.h"
|
|
|
|
|
2006-11-05 07:54:08 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
#define FLICKER_PERIOD 15
|
|
|
|
#define BUTTONLIGHT_MENU (SC606_LED_B1)
|
|
|
|
#define BUTTONLIGHT_ALL (SC606_LED_B1 | SC606_LED_B2 | SC606_LED_C1 | SC606_LED_C2)
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
static void led_control_service(void);
|
2007-01-04 09:32:49 +00:00
|
|
|
static unsigned short backlight_brightness;
|
|
|
|
static unsigned short backlight_current;
|
|
|
|
static unsigned short backlight_target;
|
|
|
|
static unsigned short time_til_fade;
|
|
|
|
static unsigned short fade_interval;
|
2007-01-11 10:24:21 +00:00
|
|
|
static unsigned short initial_tick_delay;
|
|
|
|
static unsigned char backlight_leds;
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
static enum backlight_states
|
|
|
|
{
|
|
|
|
BACKLIGHT_CONTROL_IDLE,
|
|
|
|
BACKLIGHT_CONTROL_OFF,
|
|
|
|
BACKLIGHT_CONTROL_ON,
|
|
|
|
BACKLIGHT_CONTROL_SET,
|
|
|
|
BACKLIGHT_CONTROL_FADE_OFF,
|
|
|
|
BACKLIGHT_CONTROL_FADE_ON,
|
|
|
|
BACKLIGHT_CONTROL_FADE_ON_FROM_OFF
|
|
|
|
} backlight_control;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum buttonlight_states
|
|
|
|
{
|
|
|
|
/* turn button lights off */
|
|
|
|
BUTTONLIGHT_MODE_OFF_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_OFF,
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* turns button lights on to setting */
|
2007-01-07 06:38:57 +00:00
|
|
|
BUTTONLIGHT_MODE_ON_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_ON,
|
|
|
|
|
|
|
|
/* turns button lights on to minimum */
|
|
|
|
BUTTONLIGHT_MODE_FAINT_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_FAINT,
|
|
|
|
|
|
|
|
/* allows button lights to flicker when triggered */
|
|
|
|
BUTTONLIGHT_MODE_FLICKER_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_FLICKER,
|
|
|
|
BUTTONLIGHT_MODE_FLICKERING,
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* button lights solid */
|
|
|
|
BUTTONLIGHT_MODE_SOLID_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_SOLID,
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* button light charing */
|
|
|
|
BUTTONLIGHT_MODE_CHARGING_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_CHARGING,
|
|
|
|
BUTTONLIGHT_MODE_CHARGING_WAIT,
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* internal use only */
|
|
|
|
BUTTONLIGHT_HELPER_SET,
|
|
|
|
BUTTONLIGHT_HELPER_SET_FINAL,
|
2007-01-08 08:53:36 +00:00
|
|
|
BUTTONLIGHT_MODE_STOP,
|
|
|
|
|
|
|
|
/* buttonlights follow the backlight settings */
|
|
|
|
BUTTONLIGHT_MODE_FOLLOW_ENTRY,
|
|
|
|
BUTTONLIGHT_MODE_FOLLOW,
|
2007-01-07 06:38:57 +00:00
|
|
|
};
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
static char buttonlight_leds;
|
2007-01-07 06:38:57 +00:00
|
|
|
static unsigned short buttonlight_setting;
|
|
|
|
static unsigned short buttonlight_current;
|
|
|
|
static unsigned char buttonlight_selected;
|
|
|
|
static enum buttonlight_states buttonlight_state;
|
|
|
|
static enum buttonlight_states buttonlight_saved_state;
|
|
|
|
static unsigned short buttonlight_flickering;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
|
|
|
static unsigned short buttonlight_trigger_now;
|
|
|
|
static unsigned short buttonlight_trigger_brightness;
|
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
static unsigned short charging_led_index;
|
|
|
|
static unsigned short buttonlight_charging_counter;
|
|
|
|
|
|
|
|
#define CHARGING_LED_COUNT 60
|
|
|
|
unsigned char charging_leds[] = { 0x00, 0x20, 0x38, 0x3C };
|
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
|
2007-01-12 20:26:23 +00:00
|
|
|
bool __backlight_init(void)
|
2006-12-29 02:49:12 +00:00
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
|
|
|
|
backlight_current = DEFAULT_BRIGHTNESS_SETTING;
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_OFF;
|
|
|
|
|
|
|
|
buttonlight_selected = 0x04;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-13 02:24:15 +00:00
|
|
|
/* delay 4 seconds before any fading */
|
|
|
|
initial_tick_delay = 400;
|
2007-01-07 06:38:57 +00:00
|
|
|
/* put the led control on the tick list */
|
|
|
|
tick_add_task(led_control_service);
|
2007-01-14 03:28:31 +00:00
|
|
|
|
2007-01-12 20:26:23 +00:00
|
|
|
return true;
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
void __backlight_on(void)
|
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
/* now go turn the backlight on */
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
void __backlight_off(void)
|
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Assumes that the backlight has been initialized */
|
2006-11-05 07:54:08 +00:00
|
|
|
void __backlight_set_brightness(int brightness)
|
2006-08-12 08:01:54 +00:00
|
|
|
{
|
2007-01-04 09:32:49 +00:00
|
|
|
/* stop the interrupt from messing us up */
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_brightness = brightness + 1;
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
/* only set the brightness if it is different from the current */
|
|
|
|
if (backlight_brightness != backlight_current)
|
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_SET;
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* only works if the buttonlight mode is set to triggered mode */
|
|
|
|
void __buttonlight_trigger(void)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_now = 1;
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* map the mode from the command into the state machine entries */
|
2007-01-11 10:24:21 +00:00
|
|
|
void __buttonlight_mode(enum buttonlight_mode mode,
|
2007-01-08 08:53:36 +00:00
|
|
|
enum buttonlight_selection selection,
|
|
|
|
unsigned short brightness)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
/* choose stop to setup mode */
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_STOP;
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* clip brightness */
|
|
|
|
if (brightness > MAX_BRIGHTNESS_SETTING)
|
|
|
|
{
|
|
|
|
brightness = MAX_BRIGHTNESS_SETTING;
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
brightness++;
|
|
|
|
|
|
|
|
/* Select which LEDs to use */
|
2007-01-07 06:38:57 +00:00
|
|
|
switch (selection)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
case BUTTONLIGHT_LED_ALL:
|
|
|
|
buttonlight_selected = BUTTONLIGHT_ALL;
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_LED_MENU:
|
|
|
|
buttonlight_selected = BUTTONLIGHT_MENU;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* which mode to use */
|
2007-01-07 06:38:57 +00:00
|
|
|
switch (mode)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
case BUTTONLIGHT_OFF:
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_OFF_ENTRY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONLIGHT_ON:
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_brightness = brightness;
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY;
|
|
|
|
break;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
|
|
|
/* faint is just a quick way to set ON to 1 */
|
2007-01-07 06:38:57 +00:00
|
|
|
case BUTTONLIGHT_FAINT:
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_brightness = 1;
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_ON_ENTRY;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
case BUTTONLIGHT_FLICKER:
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_brightness = brightness;
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_FLICKER_ENTRY;
|
|
|
|
break;
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_SIGNAL:
|
|
|
|
buttonlight_trigger_brightness = brightness;
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_SOLID_ENTRY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONLIGHT_FOLLOW:
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_FOLLOW_ENTRY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONLIGHT_CHARGING:
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_CHARGING_ENTRY;
|
|
|
|
break;
|
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
default:
|
|
|
|
return; /* unknown mode */
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/*
|
2007-01-07 06:38:57 +00:00
|
|
|
* The button lights have 'modes' of operation. Each mode must setup and
|
|
|
|
* execute its own operation - taking care that this is all done in an ISR.
|
2007-01-11 10:24:21 +00:00
|
|
|
*
|
2007-01-07 06:38:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/* led_control_service runs in interrupt context - be brief!
|
|
|
|
* This service is called once per interrupt timer tick - 100 times a second.
|
2007-01-07 06:38:57 +00:00
|
|
|
*
|
|
|
|
* There should be at most only one i2c operation per call - if more are need
|
|
|
|
* the calls should be spread across calls.
|
|
|
|
*
|
|
|
|
* Putting all led servicing in one thread means that we wont step on any
|
|
|
|
* i2c operations - they are all serialized here in the ISR tick. It also
|
|
|
|
* insures that we get called at equal timing for good visual effect.
|
|
|
|
*
|
|
|
|
* The buttonlight service runs only after all backlight services have finished.
|
|
|
|
* Fading the buttonlights is possible, but not recommended because of the
|
|
|
|
* additional calls needed during the ISR
|
|
|
|
*/
|
|
|
|
static void led_control_service(void)
|
|
|
|
{
|
2007-01-13 02:24:15 +00:00
|
|
|
if(initial_tick_delay) {
|
|
|
|
initial_tick_delay--;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
switch (backlight_control)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-01-11 10:24:21 +00:00
|
|
|
case BACKLIGHT_CONTROL_IDLE:
|
2007-01-07 06:38:57 +00:00
|
|
|
switch (buttonlight_state)
|
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_MODE_STOP: break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* Buttonlight mode: OFF */
|
2007-01-11 10:24:21 +00:00
|
|
|
case BUTTONLIGHT_MODE_OFF_ENTRY:
|
2007-01-07 06:38:57 +00:00
|
|
|
if (buttonlight_current)
|
|
|
|
{
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
2007-01-11 10:24:21 +00:00
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_OFF;
|
|
|
|
break;
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
case BUTTONLIGHT_MODE_OFF:
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* button mode: CHARGING - show charging sequence */
|
|
|
|
case BUTTONLIGHT_MODE_CHARGING_ENTRY:
|
|
|
|
/* start turned off */
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* temporary save for the next mode - then to do settings */
|
|
|
|
buttonlight_setting = DEFAULT_BRIGHTNESS_SETTING;
|
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_CHARGING_WAIT;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
2007-01-11 10:24:21 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_MODE_CHARGING:
|
|
|
|
if (--buttonlight_charging_counter == 0)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
/* change led */
|
|
|
|
if (charging_state())
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_leds = charging_leds[charging_led_index];
|
|
|
|
if (++charging_led_index >= sizeof(charging_leds))
|
|
|
|
{
|
|
|
|
charging_led_index = 0;
|
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_charging_counter = CHARGING_LED_COUNT;
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
else
|
2007-01-08 08:53:36 +00:00
|
|
|
{
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_CHARGING_ENTRY;
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* wait for the charget to be plugged in */
|
|
|
|
case BUTTONLIGHT_MODE_CHARGING_WAIT:
|
|
|
|
if (charging_state())
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
charging_led_index = 0;
|
|
|
|
buttonlight_charging_counter = CHARGING_LED_COUNT;
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_CHARGING;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Buttonlight mode: FOLLOW - try to stay current with backlight
|
2007-01-08 08:53:36 +00:00
|
|
|
* since this runs in the idle of the backlight it will not really
|
2007-01-11 10:24:21 +00:00
|
|
|
* follow in real time
|
2007-01-08 08:53:36 +00:00
|
|
|
*/
|
|
|
|
case BUTTONLIGHT_MODE_FOLLOW_ENTRY:
|
|
|
|
/* case 1 - backlight on, but buttonlight is off */
|
|
|
|
if (backlight_current)
|
|
|
|
{
|
|
|
|
/* Turn the buttonlights on */
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* temporary save for the next mode - then to do settings */
|
|
|
|
buttonlight_setting = backlight_current;
|
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_FOLLOW;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
2007-01-08 08:53:36 +00:00
|
|
|
/* case 2 - backlight off, but buttonlight is on */
|
2007-01-11 10:24:21 +00:00
|
|
|
else
|
2007-01-08 08:53:36 +00:00
|
|
|
{
|
|
|
|
buttonlight_current = 0;
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_FOLLOW;
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
break;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
case BUTTONLIGHT_MODE_FOLLOW:
|
2007-01-08 08:53:36 +00:00
|
|
|
if (buttonlight_current != backlight_current)
|
|
|
|
{
|
|
|
|
/* case 1 - backlight on, but buttonlight is off */
|
|
|
|
if (backlight_current)
|
|
|
|
{
|
|
|
|
if (0 == buttonlight_current)
|
|
|
|
{
|
|
|
|
/* Turn the buttonlights on */
|
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* temporary save for the next mode - then to do settings */
|
|
|
|
buttonlight_setting = backlight_current;
|
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_FOLLOW;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
/* case 2 - backlight off, but buttonlight is on */
|
2007-01-11 10:24:21 +00:00
|
|
|
else
|
2007-01-08 08:53:36 +00:00
|
|
|
{
|
|
|
|
buttonlight_current = 0;
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
break;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/* Buttonlight mode: ON - stays at the set brightness */
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_MODE_ON_ENTRY:
|
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
|
|
|
|
|
|
|
/* temporary save for the next mode - then to do settings */
|
|
|
|
buttonlight_setting = buttonlight_trigger_brightness;
|
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_ON;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
case BUTTONLIGHT_MODE_ON:
|
2007-01-08 08:53:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/* Buttonlight mode: FLICKER */
|
2007-01-07 06:38:57 +00:00
|
|
|
case BUTTONLIGHT_MODE_FLICKER_ENTRY:
|
|
|
|
/* already on? turn it off */
|
2007-01-11 10:24:21 +00:00
|
|
|
if (buttonlight_current)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
2007-01-11 10:24:21 +00:00
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/* set the brightness if not already set */
|
2007-01-08 08:53:36 +00:00
|
|
|
if (buttonlight_current != buttonlight_trigger_brightness)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
|
|
|
/* temporary save for the next mode - then to do settings */
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_setting = buttonlight_trigger_brightness;
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_FLICKER;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
|
|
|
}
|
2007-01-08 08:53:36 +00:00
|
|
|
else buttonlight_state = BUTTONLIGHT_MODE_FLICKER;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BUTTONLIGHT_MODE_FLICKER:
|
|
|
|
/* wait for the foreground to trigger flickering */
|
2007-01-08 08:53:36 +00:00
|
|
|
if (buttonlight_trigger_now)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
|
|
|
/* turn them on */
|
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
buttonlight_current = buttonlight_setting;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
|
|
|
|
|
|
|
/* reset the trigger and go flicker the LEDs */
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_now = 0;
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_flickering = FLICKER_PERIOD;
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_FLICKERING;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
case BUTTONLIGHT_MODE_FLICKERING:
|
|
|
|
/* flicker the LEDs for as long as we get triggered */
|
|
|
|
if (buttonlight_flickering)
|
|
|
|
{
|
|
|
|
/* turn the leds off if they are on */
|
|
|
|
if (buttonlight_current)
|
|
|
|
{
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonlight_flickering--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* is flickering triggered again? */
|
2007-01-08 08:53:36 +00:00
|
|
|
if (!buttonlight_trigger_now)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
|
|
|
/* completed a cycle - no new triggers - go back and wait */
|
|
|
|
buttonlight_state = BUTTONLIGHT_MODE_FLICKER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* reset flickering */
|
2007-01-08 08:53:36 +00:00
|
|
|
buttonlight_trigger_now = 0;
|
2007-01-07 06:38:57 +00:00
|
|
|
buttonlight_flickering = FLICKER_PERIOD;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* turn buttonlights on */
|
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
buttonlight_current = buttonlight_setting;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
/* Buttonlight mode: SIGNAL / SOLID */
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_MODE_SOLID_ENTRY:
|
|
|
|
/* already on? turn it off */
|
2007-01-11 10:24:21 +00:00
|
|
|
if (buttonlight_current)
|
2007-01-08 08:53:36 +00:00
|
|
|
{
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
2007-01-11 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the brightness if not already set */
|
2007-01-08 08:53:36 +00:00
|
|
|
/* temporary save for the next mode - then to do settings */
|
|
|
|
buttonlight_setting = buttonlight_trigger_brightness;
|
|
|
|
buttonlight_saved_state = BUTTONLIGHT_MODE_SOLID;
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BUTTONLIGHT_MODE_SOLID:
|
|
|
|
/* wait for the foreground to trigger */
|
|
|
|
if (buttonlight_trigger_now)
|
|
|
|
{
|
|
|
|
/* turn them on if not already on */
|
|
|
|
if (0 == buttonlight_current)
|
|
|
|
{
|
|
|
|
buttonlight_leds = buttonlight_selected;
|
|
|
|
buttonlight_current = buttonlight_setting;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds | buttonlight_leds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the trigger */
|
|
|
|
buttonlight_trigger_now = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buttonlight_current)
|
|
|
|
{
|
|
|
|
buttonlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, backlight_leds);
|
|
|
|
buttonlight_current = 0;
|
2007-01-11 10:24:21 +00:00
|
|
|
}
|
2007-01-08 08:53:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* set the brightness for the buttonlights - takes 2 passes */
|
|
|
|
case BUTTONLIGHT_HELPER_SET:
|
|
|
|
sc606_write(SC606_REG_B, buttonlight_setting-1);
|
|
|
|
buttonlight_state = BUTTONLIGHT_HELPER_SET_FINAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONLIGHT_HELPER_SET_FINAL:
|
|
|
|
sc606_write(SC606_REG_C, buttonlight_setting-1);
|
|
|
|
buttonlight_current = buttonlight_setting;
|
|
|
|
buttonlight_state = buttonlight_saved_state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BACKLIGHT_CONTROL_FADE_ON_FROM_OFF:
|
|
|
|
backlight_leds = 0x03;
|
|
|
|
sc606_write(SC606_REG_CONF, 0x03 | buttonlight_leds);
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE_ON;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BACKLIGHT_CONTROL_OFF:
|
|
|
|
backlight_current = 0;
|
|
|
|
backlight_leds = 0x00;
|
|
|
|
sc606_write(SC606_REG_CONF, buttonlight_leds);
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
case BACKLIGHT_CONTROL_ON:
|
|
|
|
backlight_leds = 0x03;
|
|
|
|
sc606_write(SC606_REG_CONF, 0x03 | buttonlight_leds);
|
|
|
|
backlight_current = backlight_brightness;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BACKLIGHT_CONTROL_SET:
|
|
|
|
/* The SC606 LED driver can set the brightness in 64 steps */
|
|
|
|
sc606_write(SC606_REG_A, backlight_brightness-1);
|
|
|
|
|
|
|
|
/* if we were turned off - turn the backlight on */
|
2007-01-11 10:24:21 +00:00
|
|
|
if (backlight_current)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
|
|
|
backlight_current = backlight_brightness;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
case BACKLIGHT_CONTROL_FADE_ON:
|
|
|
|
if (--time_til_fade) return;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* The SC606 LED driver can set the brightness in 64 steps */
|
|
|
|
sc606_write(SC606_REG_A, backlight_current++);
|
|
|
|
|
|
|
|
/* have we hit the target? */
|
|
|
|
if (backlight_current == backlight_target)
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_til_fade = fade_interval;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
case BACKLIGHT_CONTROL_FADE_OFF:
|
|
|
|
if (--time_til_fade) return;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
/* The SC606 LED driver can set the brightness in 64 steps */
|
|
|
|
sc606_write(SC606_REG_A, --backlight_current);
|
|
|
|
|
|
|
|
/* have we hit the target? */
|
|
|
|
if (backlight_current == backlight_target)
|
|
|
|
{
|
|
|
|
if (backlight_current)
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_til_fade = fade_interval;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 10:24:21 +00:00
|
|
|
if(backlight_current)
|
|
|
|
lcd_enable(true);
|
|
|
|
else
|
|
|
|
lcd_enable(false);
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void __backlight_dim(bool dim_now)
|
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
unsigned short target;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
/* dont let the interrupt tick happen */
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
target = (dim_now == true) ? 0 : backlight_brightness;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
/* only try and fade if the target is different */
|
|
|
|
if (backlight_current != target)
|
|
|
|
{
|
|
|
|
backlight_target = target;
|
2007-01-11 10:24:21 +00:00
|
|
|
|
|
|
|
if (backlight_current > backlight_target)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
time_til_fade = fade_interval = 4;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE_OFF;
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
time_til_fade = fade_interval = 1;
|
|
|
|
if (backlight_current)
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE_ON;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE_ON_FROM_OFF;
|
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-01-07 06:38:57 +00:00
|
|
|
|