2006-08-12 08:01:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-12 08:01:54 +00:00
|
|
|
*
|
|
|
|
* 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 BUTTONLIGHT_MENU (SC606_LED_B1)
|
2008-12-02 12:43:20 +00:00
|
|
|
#define BUTTONLIGHT_ALL (SC606_LED_B1 | SC606_LED_B2 | \
|
|
|
|
SC606_LED_C1 | SC606_LED_C2)
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2008-12-02 12:43:20 +00:00
|
|
|
/* Dummy value at index 0, 1-12 used. */
|
|
|
|
static const unsigned char log_brightness[13] =
|
|
|
|
{0,0,1,2,3,5,7,10,15,22,31,44,63};
|
2008-01-25 18:05:21 +00:00
|
|
|
|
2007-07-29 07:41:19 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-01-07 06:38:57 +00:00
|
|
|
static void led_control_service(void);
|
|
|
|
|
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-07-29 07:41:19 +00:00
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
|
|
|
static enum backlight_states
|
|
|
|
{
|
|
|
|
BACKLIGHT_CONTROL_IDLE,
|
|
|
|
BACKLIGHT_CONTROL_OFF,
|
|
|
|
BACKLIGHT_CONTROL_ON,
|
|
|
|
BACKLIGHT_CONTROL_SET,
|
|
|
|
BACKLIGHT_CONTROL_FADE
|
|
|
|
} backlight_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
|
|
|
|
2008-12-02 02:56:46 +00:00
|
|
|
static unsigned char _backlight_brightness;
|
2007-07-29 07:41:19 +00:00
|
|
|
static unsigned char buttonlight_brightness;
|
|
|
|
static unsigned char backlight_target;
|
|
|
|
static unsigned char buttonlight_target;
|
2007-01-14 03:28:31 +00:00
|
|
|
|
2007-07-29 07:41:19 +00:00
|
|
|
static unsigned short buttonlight_trigger_now;
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2007-01-04 09:32:49 +00:00
|
|
|
/* Assumes that the backlight has been initialized */
|
2007-11-12 18:49:53 +00:00
|
|
|
void _backlight_set_brightness(int brightness)
|
2006-08-12 08:01:54 +00:00
|
|
|
{
|
2008-12-02 02:56:46 +00:00
|
|
|
/* stop the interrupt from messing us up */
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2008-12-02 12:43:20 +00:00
|
|
|
_backlight_brightness = log_brightness[brightness];
|
2007-05-07 19:34:34 +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-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
|
|
|
/* 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.
|
|
|
|
*/
|
2007-07-29 07:41:19 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-01-07 06:38:57 +00:00
|
|
|
static void led_control_service(void)
|
|
|
|
{
|
2007-05-07 19:34:34 +00:00
|
|
|
static unsigned char
|
|
|
|
sc606regAval=DEFAULT_BRIGHTNESS_SETTING,
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606regBval=0,
|
|
|
|
sc606regCval=0,
|
2007-05-10 03:08:47 +00:00
|
|
|
sc606regCONFval=0x03;
|
2007-05-07 19:34:34 +00:00
|
|
|
|
2007-05-14 05:04:21 +00:00
|
|
|
static bool sc606_changed=false, sc606_CONF_changed=false;
|
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;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_CONF_changed=true;
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606regCONFval &= ~0x03;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606regAval=0;
|
2007-05-07 19:34:34 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_ON:
|
|
|
|
sc606_changed=true;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_CONF_changed=true;
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606regCONFval |= 0x03;
|
2008-12-02 02:56:46 +00:00
|
|
|
sc606regAval=_backlight_brightness;
|
2007-05-07 19:34:34 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BACKLIGHT_CONTROL_SET:
|
2007-05-14 05:04:21 +00:00
|
|
|
if(!(sc606regCONFval&0x03))
|
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606_changed=true;
|
2008-12-02 02:56:46 +00:00
|
|
|
sc606regAval = _backlight_brightness;
|
2007-05-10 03:08:47 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-05-07 19:34:34 +00:00
|
|
|
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;
|
2007-05-14 05:04:21 +00:00
|
|
|
if(!(sc606regCONFval&0x03))
|
|
|
|
{
|
|
|
|
sc606_CONF_changed=true;
|
|
|
|
sc606regCONFval |= 0x03;
|
|
|
|
}
|
2007-05-08 03:57:42 +00:00
|
|
|
if(backlight_target>sc606regAval)
|
|
|
|
{
|
|
|
|
sc606regAval++;
|
|
|
|
if(backlight_target==sc606regAval)
|
2007-05-14 05:04:21 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
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--;
|
2007-05-14 05:04:21 +00:00
|
|
|
if(sc606regAval==0)
|
2007-05-08 03:57:42 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
2007-05-14 05:04:21 +00:00
|
|
|
else if (backlight_target==sc606regAval)
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-05-08 03:57:42 +00:00
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-14 05:04:21 +00:00
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-05-07 19:34:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (buttonlight_control)
|
|
|
|
{
|
|
|
|
case BUTTONLIGHT_CONTROL_IDLE:
|
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BUTTONLIGHT_CONTROL_OFF:
|
|
|
|
sc606_changed=true;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_CONF_changed=true;
|
|
|
|
sc606regCONFval &= ~BUTTONLIGHT_ALL;
|
2007-05-10 03:08:47 +00:00
|
|
|
sc606regBval=sc606regCval=0;
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
|
|
|
case BUTTONLIGHT_CONTROL_ON:
|
|
|
|
sc606_changed=true;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_CONF_changed=true;
|
|
|
|
sc606regCONFval |= BUTTONLIGHT_ALL;
|
2007-05-10 03:08:47 +00:00
|
|
|
sc606regBval=sc606regCval=buttonlight_brightness;
|
2007-05-07 19:34:34 +00:00
|
|
|
buttonlight_control=BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
break;
|
2007-05-08 06:45:38 +00:00
|
|
|
case BUTTONLIGHT_CONTROL_SET:
|
2007-05-14 05:04:21 +00:00
|
|
|
if(!(sc606regCONFval&BUTTONLIGHT_ALL))
|
|
|
|
break;
|
2007-05-08 06:45:38 +00:00
|
|
|
sc606_changed=true;
|
2007-05-10 03:08:47 +00:00
|
|
|
sc606regBval=sc606regCval=buttonlight_brightness;
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2007-05-08 06:45:38 +00:00
|
|
|
break;
|
2007-05-07 19:34:34 +00:00
|
|
|
case BUTTONLIGHT_CONTROL_FADE:
|
2007-05-14 05:04:21 +00:00
|
|
|
/* Was this mode set while the button light is already on? */
|
2007-05-08 05:47:36 +00:00
|
|
|
if(buttonlight_target==sc606regBval)
|
|
|
|
{
|
2007-05-10 03:08:47 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2007-05-08 05:47:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-07 19:34:34 +00:00
|
|
|
sc606_changed=true;
|
2007-05-14 05:04:21 +00:00
|
|
|
if(!(sc606regCONFval&BUTTONLIGHT_ALL))
|
|
|
|
{
|
|
|
|
sc606_CONF_changed=true;
|
|
|
|
sc606regCONFval |= BUTTONLIGHT_ALL;
|
|
|
|
}
|
2007-05-08 03:57:42 +00:00
|
|
|
if(buttonlight_target>sc606regBval)
|
|
|
|
{
|
|
|
|
sc606regCval=++sc606regBval;
|
|
|
|
if(buttonlight_target==sc606regBval)
|
2007-05-14 05:04:21 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
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;
|
2007-05-10 03:08:47 +00:00
|
|
|
if(sc606regBval==0)
|
2007-05-08 03:57:42 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
2007-05-14 05:04:21 +00:00
|
|
|
else if (buttonlight_target==sc606regBval)
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2007-05-08 03:57:42 +00:00
|
|
|
}
|
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-14 05:04:21 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2007-05-07 19:34:34 +00:00
|
|
|
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-14 05:04:21 +00:00
|
|
|
|
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-14 05:04:21 +00:00
|
|
|
|
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-14 05:04:21 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_C12:
|
|
|
|
sc606_write(SC606_REG_C , sc606regCval);
|
2007-05-14 05:04:21 +00:00
|
|
|
if(sc606_CONF_changed!=true)
|
|
|
|
{
|
|
|
|
sc606_changed=false;
|
|
|
|
if(backlight_control != BACKLIGHT_CONTROL_IDLE ||
|
|
|
|
buttonlight_control != BUTTONLIGHT_CONTROL_IDLE)
|
|
|
|
{
|
|
|
|
sc606_control=SC606_CONTROL_A12;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc606_control=SC606_CONTROL_IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc606_control=SC606_CONTROL_CONF;
|
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-14 05:04:21 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
case SC606_CONTROL_CONF:
|
|
|
|
sc606_write(SC606_REG_CONF , sc606regCONFval);
|
|
|
|
sc606_changed=false;
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_CONF_changed=false;
|
|
|
|
if(backlight_control != BACKLIGHT_CONTROL_IDLE ||
|
|
|
|
buttonlight_control != BUTTONLIGHT_CONTROL_IDLE)
|
|
|
|
{
|
2007-05-08 03:57:42 +00:00
|
|
|
sc606_control=SC606_CONTROL_A12;
|
2007-05-14 05:04:21 +00:00
|
|
|
}
|
2007-05-08 03:57:42 +00:00
|
|
|
else
|
2007-05-14 05:04:21 +00:00
|
|
|
{
|
2007-05-08 03:57:42 +00:00
|
|
|
sc606_control=SC606_CONTROL_IDLE;
|
2007-05-14 05:04:21 +00:00
|
|
|
}
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-05-14 05:04:21 +00:00
|
|
|
|
2007-05-07 19:34:34 +00:00
|
|
|
default:
|
2007-05-14 05:04:21 +00:00
|
|
|
sc606_control=SC606_CONTROL_IDLE;
|
2007-01-07 06:38:57 +00:00
|
|
|
break;
|
2007-01-04 09:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-29 07:41:19 +00:00
|
|
|
#endif /* BOOTLOADER */
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
static void __backlight_dim(bool dim_now)
|
|
|
|
{
|
|
|
|
/* dont let the interrupt tick happen */
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_IDLE;
|
2009-05-21 14:15:24 +00:00
|
|
|
backlight_target = dim_now ? 0 : _backlight_brightness;
|
2008-12-02 02:56:46 +00:00
|
|
|
if(backlight_target==0 && _backlight_brightness==0)
|
2007-11-12 18:49:53 +00:00
|
|
|
{
|
|
|
|
if(dim_now == false)
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
|
|
|
else
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_OFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_FADE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _backlight_on(void)
|
|
|
|
{
|
2008-05-14 19:29:25 +00:00
|
|
|
#ifdef HAVE_LCD_ENABLE
|
|
|
|
lcd_enable(true); /* power on lcd + visible display */
|
|
|
|
#endif
|
2007-11-12 18:49:53 +00:00
|
|
|
__backlight_dim(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _backlight_off(void)
|
|
|
|
{
|
|
|
|
__backlight_dim(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __buttonlight_on(void)
|
2007-05-07 19:34:34 +00:00
|
|
|
{
|
2007-05-10 03:08:47 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
2007-05-07 19:34:34 +00:00
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
static inline void __buttonlight_off(void)
|
2007-05-10 03:08:47 +00:00
|
|
|
{
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
|
|
|
}
|
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
static void __buttonlight_dim(bool dim_now)
|
2007-05-07 19:34:34 +00:00
|
|
|
{
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2009-05-21 14:15:24 +00:00
|
|
|
buttonlight_target = dim_now ? 0 : buttonlight_brightness;
|
2007-05-10 03:08:47 +00:00
|
|
|
if(buttonlight_target==0 && buttonlight_brightness==0)
|
|
|
|
{
|
|
|
|
if(dim_now == false)
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_ON;
|
|
|
|
else
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_OFF;
|
|
|
|
}
|
2007-05-08 06:45:38 +00:00
|
|
|
else
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_FADE;
|
2007-05-07 19:34:34 +00:00
|
|
|
}
|
2007-01-04 09:32:49 +00:00
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
void _buttonlight_on(void)
|
2007-01-04 09:32:49 +00:00
|
|
|
{
|
2007-11-12 18:49:53 +00:00
|
|
|
__buttonlight_dim(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _buttonlight_off(void)
|
|
|
|
{
|
2007-11-12 19:19:38 +00:00
|
|
|
#ifndef BOOTLOADER
|
2009-04-25 18:15:50 +00:00
|
|
|
if(buttonlight_get_current_timeout() > 0)
|
2007-11-12 18:49:53 +00:00
|
|
|
__buttonlight_dim(true);
|
2007-05-08 06:45:38 +00:00
|
|
|
else
|
2007-11-12 19:19:38 +00:00
|
|
|
#endif
|
2007-11-12 18:49:53 +00:00
|
|
|
__buttonlight_off();
|
2007-05-08 06:45:38 +00:00
|
|
|
}
|
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
void _buttonlight_set_brightness(int brightness)
|
2007-05-08 06:45:38 +00:00
|
|
|
{
|
2008-01-25 18:05:21 +00:00
|
|
|
/* stop the interrupt from messing us up */
|
2007-05-08 06:45:38 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
2008-12-02 12:43:20 +00:00
|
|
|
buttonlight_brightness = log_brightness[brightness];
|
2007-05-08 06:45:38 +00:00
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_SET;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
2007-07-29 07:41:19 +00:00
|
|
|
|
2007-11-12 18:49:53 +00:00
|
|
|
bool _backlight_init(void)
|
2007-07-29 07:41:19 +00:00
|
|
|
{
|
2008-12-02 12:43:20 +00:00
|
|
|
unsigned char brightness = log_brightness[DEFAULT_BRIGHTNESS_SETTING];
|
|
|
|
buttonlight_brightness = brightness;
|
|
|
|
_backlight_brightness = brightness;
|
2007-07-29 07:41:19 +00:00
|
|
|
|
|
|
|
buttonlight_control = BUTTONLIGHT_CONTROL_IDLE;
|
|
|
|
backlight_control = BACKLIGHT_CONTROL_ON;
|
|
|
|
|
|
|
|
/* Set the backlight up in a known state */
|
|
|
|
sc606_init();
|
2008-12-02 12:43:20 +00:00
|
|
|
sc606_write(SC606_REG_A , brightness);
|
2007-07-29 07:41:19 +00:00
|
|
|
sc606_write(SC606_REG_B , 0);
|
|
|
|
sc606_write(SC606_REG_C , 0);
|
|
|
|
sc606_write(SC606_REG_CONF , 0x03);
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
/* put the led control on the tick list */
|
|
|
|
tick_add_task(led_control_service);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|