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"
|
|
|
|
|
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;
|
2007-05-08 06:45:38 +00:00
|
|
|
static unsigned short buttonlight_brightness;
|
2007-01-04 09:32:49 +00:00
|
|
|
static unsigned short backlight_target;
|
2007-05-07 19:34:34 +00:00
|
|
|
static unsigned short buttonlight_target;
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
static enum backlight_states
|
|
|
|
{
|
|
|
|
BACKLIGHT_CONTROL_IDLE,
|
|
|
|
BACKLIGHT_CONTROL_OFF,
|
|
|
|
BACKLIGHT_CONTROL_ON,
|
|
|
|
BACKLIGHT_CONTROL_SET,
|
2007-05-07 19:34:34 +00:00
|
|
|
BACKLIGHT_CONTROL_FADE
|
2007-01-07 06:38:57 +00:00
|
|
|
} backlight_control;
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
static enum sc606_states
|
|
|
|
{
|
|
|
|
SC606_CONTROL_IDLE,
|
|
|
|
SC606_CONTROL_A12,
|
|
|
|
SC606_CONTROL_B12,
|
|
|
|
SC606_CONTROL_C12,
|
|
|
|
SC606_CONTROL_CONF
|
|
|
|
} sc606_control;
|
2007-01-07 06:38:57 +00:00
|
|
|
|
|
|
|
enum buttonlight_states
|
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
BUTTONLIGHT_CONTROL_IDLE,
|
|
|
|
BUTTONLIGHT_CONTROL_OFF,
|
|
|
|
BUTTONLIGHT_CONTROL_ON,
|
2007-05-08 06:45:38 +00:00
|
|
|
BUTTONLIGHT_CONTROL_SET,
|
2007-05-07 19:34:34 +00:00
|
|
|
BUTTONLIGHT_CONTROL_FADE,
|
|
|
|
} buttonlight_control;
|
2007-01-08 08:53:36 +00:00
|
|
|
|
|
|
|
static unsigned short buttonlight_trigger_now;
|
|
|
|
|
|
|
|
#define CHARGING_LED_COUNT 60
|
|
|
|
unsigned char charging_leds[] = { 0x00, 0x20, 0x38, 0x3C };
|
|
|
|
|
2007-01-12 20:26:23 +00:00
|
|
|
bool __backlight_init(void)
|
2006-12-29 02:49:12 +00:00
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
backlight_brightness=DEFAULT_BRIGHTNESS_SETTING;
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
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
|
|
|
|
|
|
|
void __backlight_on(void)
|
|
|
|
{
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
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-05-07 19:34:34 +00:00
|
|
|
backlight_brightness = brightness;
|
|
|
|
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-08 08:53:36 +00:00
|
|
|
/* map the mode from the command into the state machine entries */
|
2007-05-07 19:34:34 +00:00
|
|
|
void __buttonlight_mode(enum buttonlight_mode mode)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-01-08 08:53:36 +00:00
|
|
|
/* choose stop to setup mode */
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
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:
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTONLIGHT_ON:
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
|
2007-01-08 08:53:36 +00:00
|
|
|
case BUTTONLIGHT_FOLLOW:
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
|
2007-01-08 08:53:36 +00:00
|
|
|
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
|
|
|
* 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
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
static void led_control_service(void)
|
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
static unsigned char
|
|
|
|
sc606regAval=DEFAULT_BRIGHTNESS_SETTING,
|
|
|
|
sc606regBval=DEFAULT_BRIGHTNESS_SETTING,
|
|
|
|
sc606regCval=DEFAULT_BRIGHTNESS_SETTING,
|
|
|
|
sc606regCONFval=3;
|
|
|
|
|
|
|
|
static bool sc606_changed=true;
|
2007-05-08 05:47:36 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
if(sc606_changed==false)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
switch (backlight_control)
|
2007-01-07 06:38:57 +00:00
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
case BACKLIGHT_CONTROL_IDLE:
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_OFF:
|
|
|
|
sc606_changed=true;
|
|
|
|
sc606regCONFval &= ~0x03;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_ON:
|
|
|
|
sc606_changed=true;
|
|
|
|
sc606regCONFval |= 0x03;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_SET:
|
|
|
|
sc606regAval=backlight_brightness;
|
|
|
|
sc606_changed=true;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_FADE:
|
2007-05-08 05:47:36 +00:00
|
|
|
/* Was this mode set while the backlight is already on/off? */
|
|
|
|
if(backlight_target==sc606regAval)
|
|
|
|
{
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606_changed=true;
|
|
|
|
sc606regCONFval |= 0x03;
|
2007-05-08 03:57:42 +00:00
|
|
|
if(backlight_target>sc606regAval)
|
|
|
|
{
|
|
|
|
sc606regAval++;
|
|
|
|
if(backlight_target==sc606regAval)
|
2007-05-07 19:34:34 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
2007-05-08 03:57:42 +00:00
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
else
|
2007-05-08 03:57:42 +00:00
|
|
|
{
|
|
|
|
sc606regAval--;
|
|
|
|
if(backlight_target==sc606regAval)
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (buttonlight_control)
|
|
|
|
{
|
|
|
|
case BUTTONLIGHT_CONTROL_IDLE:
|
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BUTTONLIGHT_CONTROL_OFF:
|
|
|
|
sc606_changed=true;
|
|
|
|
sc606regCONFval &= ~0x3C;
|
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BUTTONLIGHT_CONTROL_ON:
|
|
|
|
sc606_changed=true;
|
2007-05-08 06:45:38 +00:00
|
|
|
sc606regBval=sc606regCval=buttonlight_brightness;
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606regCONFval |= 0x3C;
|
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
2007-05-08 06:45:38 +00:00
|
|
|
case BUTTONLIGHT_CONTROL_SET:
|
|
|
|
sc606regBval=sc606regCval=buttonlight_brightness;
|
|
|
|
sc606_changed=true;
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case BUTTONLIGHT_CONTROL_FADE:
|
2007-05-08 05:47:36 +00:00
|
|
|
/* Was this mode set while the button light is already on/off? */
|
|
|
|
if(buttonlight_target==sc606regBval)
|
|
|
|
{
|
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606_changed=true;
|
|
|
|
sc606regCONFval |= 0x3C;
|
2007-05-08 03:57:42 +00:00
|
|
|
if(buttonlight_target>sc606regBval)
|
|
|
|
{
|
|
|
|
sc606regCval=++sc606regBval;
|
|
|
|
if(buttonlight_target==sc606regBval)
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
2007-05-08 03:57:42 +00:00
|
|
|
}
|
2007-01-11 10:24:21 +00:00
|
|
|
else
|
2007-05-08 03:57:42 +00:00
|
|
|
{
|
|
|
|
sc606regCval=--sc606regBval;
|
|
|
|
if(buttonlight_target==sc606regBval)
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
switch (sc606_control)
|
|
|
|
{
|
|
|
|
case SC606_CONTROL_IDLE:
|
|
|
|
if(sc606_changed)
|
|
|
|
sc606_control=SC606_CONTROL_A12;
|
2007-01-07 06:38:57 +00:00
|
|
|
else
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606_control=SC606_CONTROL_IDLE;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_A12:
|
|
|
|
sc606_write(SC606_REG_A , sc606regAval);
|
|
|
|
sc606_control=SC606_CONTROL_B12;
|
2007-01-08 08:53:36 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_B12:
|
|
|
|
sc606_write(SC606_REG_B , sc606regBval);
|
|
|
|
sc606_control=SC606_CONTROL_C12;
|
2007-01-08 08:53:36 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_C12:
|
|
|
|
sc606_write(SC606_REG_C , sc606regCval);
|
|
|
|
sc606_control=SC606_CONTROL_CONF;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_CONF:
|
|
|
|
sc606_write(SC606_REG_CONF , sc606regCONFval);
|
|
|
|
sc606_changed=false;
|
2007-05-08 03:57:42 +00:00
|
|
|
if(backlight_control != BACKLIGHT_CONTROL_IDLE && buttonlight_control != BUTTONLIGHT_CONTROL_IDLE)
|
|
|
|
sc606_control=SC606_CONTROL_A12;
|
|
|
|
else
|
|
|
|
sc606_control=SC606_CONTROL_IDLE;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
default:
|
|
|
|
sc606_control=SC606_CONTROL_A12;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
2007-05-08 05:47:36 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
if(sc606regCONFval&0x03)
|
2007-01-11 10:24:21 +00:00
|
|
|
lcd_enable(true);
|
|
|
|
else
|
|
|
|
lcd_enable(false);
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
void __button_backlight_on(void)
|
|
|
|
{
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2007-05-08 06:45:38 +00:00
|
|
|
buttonlight_target = buttonlight_brightness;
|
|
|
|
if(buttonlight_brightness==0)
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
|
|
|
else
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
|
2007-05-07 19:34:34 +00:00
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
void __button_backlight_off(void)
|
|
|
|
{
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
buttonlight_target = 0;
|
2007-05-08 06:45:38 +00:00
|
|
|
if(buttonlight_brightness==0)
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
|
|
|
else
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
|
2007-05-07 19:34:34 +00:00
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
|
|
|
void __backlight_dim(bool dim_now)
|
|
|
|
{
|
|
|
|
/* dont let the interrupt tick happen */
|
2007-01-07 06:38:57 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-05-07 19:34:34 +00:00
|
|
|
backlight_target = (dim_now == true) ? 0 : backlight_brightness;
|
2007-05-08 06:45:38 +00:00
|
|
|
if(backlight_target==0 && backlight_brightness==0)
|
|
|
|
{
|
|
|
|
if(dim_now == false)
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
|
|
|
else
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|