2002-06-24 13:48:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 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 <stdlib.h>
|
|
|
|
#include "sh7034.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "rtc.h"
|
2002-06-29 23:01:10 +00:00
|
|
|
#include "usb.h"
|
2002-10-01 10:59:36 +00:00
|
|
|
#include "power.h"
|
2003-11-06 01:34:50 +00:00
|
|
|
#include "system.h"
|
2002-06-24 13:48:42 +00:00
|
|
|
|
2004-09-10 13:56:54 +00:00
|
|
|
const char backlight_timeout_value[19] =
|
|
|
|
{
|
|
|
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef HAVE_BACKLIGHT
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
#define BACKLIGHT_ON 1
|
|
|
|
#define BACKLIGHT_OFF 2
|
|
|
|
|
|
|
|
static void backlight_thread(void);
|
2002-07-15 22:19:49 +00:00
|
|
|
static char backlight_stack[DEFAULT_STACK_SIZE];
|
2004-08-03 05:58:46 +00:00
|
|
|
static const char backlight_thread_name[] = "backlight";
|
2002-06-24 13:48:42 +00:00
|
|
|
static struct event_queue backlight_queue;
|
|
|
|
|
2002-10-01 10:59:36 +00:00
|
|
|
static bool charger_was_inserted = 0;
|
|
|
|
static bool backlight_on_when_charging = 0;
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
static int backlight_timer;
|
2003-07-28 09:08:49 +00:00
|
|
|
static unsigned int backlight_timeout = 5;
|
2002-06-24 13:48:42 +00:00
|
|
|
|
|
|
|
void backlight_thread(void)
|
|
|
|
{
|
|
|
|
struct event ev;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
queue_wait(&backlight_queue, &ev);
|
|
|
|
switch(ev.id)
|
|
|
|
{
|
|
|
|
case BACKLIGHT_ON:
|
2002-10-01 10:59:36 +00:00
|
|
|
if( backlight_on_when_charging && charger_inserted() )
|
|
|
|
{
|
|
|
|
/* Forcing to zero keeps the lights on */
|
|
|
|
backlight_timer = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-04-23 09:17:34 +00:00
|
|
|
backlight_timer = HZ*backlight_timeout_value[backlight_timeout];
|
2002-10-01 10:59:36 +00:00
|
|
|
}
|
2002-10-01 11:06:22 +00:00
|
|
|
|
2002-08-15 13:56:06 +00:00
|
|
|
if(backlight_timer < 0)
|
|
|
|
{
|
2002-10-01 10:59:36 +00:00
|
|
|
backlight_timer = 0; /* timer value 0 will not get ticked */
|
2002-08-15 13:56:06 +00:00
|
|
|
#ifdef HAVE_RTC
|
|
|
|
/* Disable square wave */
|
|
|
|
rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
|
|
|
|
#else
|
2004-07-22 09:09:26 +00:00
|
|
|
and_b(~0x40, &PAIORH);
|
2002-08-15 13:56:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
2002-10-01 10:59:36 +00:00
|
|
|
/* else if(backlight_timer) */
|
|
|
|
else
|
2002-06-24 13:48:42 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_RTC
|
2002-07-26 14:30:48 +00:00
|
|
|
/* Enable square wave */
|
|
|
|
rtc_write(0x0a, rtc_read(0x0a) | 0x40);
|
2002-06-24 13:48:42 +00:00
|
|
|
#else
|
2003-11-07 12:15:24 +00:00
|
|
|
and_b(~0x40, &PADRH);
|
2004-07-22 09:09:26 +00:00
|
|
|
or_b(0x40, &PAIORH);
|
2002-06-24 13:48:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
2002-07-23 00:30:47 +00:00
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
case BACKLIGHT_OFF:
|
|
|
|
#ifdef HAVE_RTC
|
2002-07-26 14:30:48 +00:00
|
|
|
/* Disable square wave */
|
|
|
|
rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
|
2002-06-24 13:48:42 +00:00
|
|
|
#else
|
2004-07-22 09:09:26 +00:00
|
|
|
and_b(~0x40, &PAIORH);
|
2002-08-15 13:56:06 +00:00
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
break;
|
2002-07-23 00:30:47 +00:00
|
|
|
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
/* Tell the USB thread that we are safe */
|
|
|
|
DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
2002-08-23 09:36:49 +00:00
|
|
|
break;
|
2002-07-30 06:35:50 +00:00
|
|
|
|
|
|
|
case SYS_USB_DISCONNECTED:
|
|
|
|
usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
|
2002-07-23 00:30:47 +00:00
|
|
|
break;
|
2002-06-24 13:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void backlight_on(void)
|
|
|
|
{
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void backlight_off(void)
|
|
|
|
{
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
|
|
|
|
}
|
|
|
|
|
2002-12-14 22:01:27 +00:00
|
|
|
int backlight_get_timeout(void)
|
|
|
|
{
|
|
|
|
return backlight_timeout;
|
|
|
|
}
|
|
|
|
|
2004-01-30 23:27:44 +00:00
|
|
|
void backlight_set_timeout(int index)
|
2002-10-01 10:59:36 +00:00
|
|
|
{
|
2004-01-30 23:55:02 +00:00
|
|
|
if((unsigned)index >= sizeof(backlight_timeout_value))
|
2003-07-28 09:08:49 +00:00
|
|
|
/* if given a weird value, use 0 */
|
|
|
|
index=0;
|
|
|
|
backlight_timeout = index; /* index in the backlight_timeout_value table */
|
2002-10-01 10:59:36 +00:00
|
|
|
backlight_on();
|
|
|
|
}
|
|
|
|
|
2002-12-14 22:01:27 +00:00
|
|
|
bool backlight_get_on_when_charging(void)
|
|
|
|
{
|
|
|
|
return backlight_on_when_charging;
|
|
|
|
}
|
|
|
|
|
2002-10-01 10:59:36 +00:00
|
|
|
void backlight_set_on_when_charging(bool yesno)
|
2002-06-27 00:20:00 +00:00
|
|
|
{
|
2002-10-01 10:59:36 +00:00
|
|
|
backlight_on_when_charging = yesno;
|
2002-06-27 00:20:00 +00:00
|
|
|
backlight_on();
|
|
|
|
}
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
void backlight_tick(void)
|
|
|
|
{
|
2002-10-04 11:52:46 +00:00
|
|
|
bool charger_is_inserted = charger_inserted();
|
2002-10-01 11:06:22 +00:00
|
|
|
if( backlight_on_when_charging &&
|
|
|
|
(charger_was_inserted != charger_is_inserted) )
|
2002-10-01 10:59:36 +00:00
|
|
|
{
|
|
|
|
backlight_on();
|
|
|
|
}
|
|
|
|
charger_was_inserted = charger_is_inserted;
|
2002-10-04 11:52:46 +00:00
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
if(backlight_timer)
|
|
|
|
{
|
|
|
|
backlight_timer--;
|
|
|
|
if(backlight_timer == 0)
|
|
|
|
{
|
|
|
|
backlight_off();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void backlight_init(void)
|
|
|
|
{
|
|
|
|
queue_init(&backlight_queue);
|
2002-07-15 22:19:49 +00:00
|
|
|
create_thread(backlight_thread, backlight_stack,
|
2002-07-23 00:30:47 +00:00
|
|
|
sizeof(backlight_stack), backlight_thread_name);
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
backlight_on();
|
|
|
|
}
|
2004-09-10 13:56:54 +00:00
|
|
|
|
|
|
|
#else /* no backlight, empty dummy functions */
|
|
|
|
|
|
|
|
void backlight_init(void) {}
|
|
|
|
void backlight_on(void) {}
|
|
|
|
void backlight_off(void) {}
|
|
|
|
void backlight_tick(void) {}
|
|
|
|
int backlight_get_timeout(void) {return 0;}
|
|
|
|
void backlight_set_timeout(int index) {(void)index;}
|
|
|
|
bool backlight_get_on_when_charging(void) {return 0;}
|
|
|
|
void backlight_set_on_when_charging(bool yesno) {(void)yesno;}
|
|
|
|
|
|
|
|
#endif /* #ifdef HAVE_BACKLIGHT */
|
|
|
|
|