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-06-24 13:48:42 +00:00
|
|
|
|
|
|
|
#define BACKLIGHT_ON 1
|
|
|
|
#define BACKLIGHT_OFF 2
|
|
|
|
|
|
|
|
static void backlight_thread(void);
|
2002-07-01 21:16:07 +00:00
|
|
|
static char backlight_stack[0x400];
|
2002-06-24 13:48:42 +00:00
|
|
|
static struct event_queue backlight_queue;
|
|
|
|
|
|
|
|
static int backlight_timer;
|
2002-06-27 00:20:00 +00:00
|
|
|
static 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-06-27 00:20:00 +00:00
|
|
|
backlight_timer = HZ*backlight_timeout;
|
2002-06-24 13:48:42 +00:00
|
|
|
if(backlight_timer)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_RTC
|
|
|
|
rtc_write(0x13, 0x10);
|
|
|
|
#else
|
2002-06-25 11:15:33 +00:00
|
|
|
PADR |= 0x40;
|
2002-06-24 13:48:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
2002-06-29 23:01:10 +00:00
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
case BACKLIGHT_OFF:
|
|
|
|
#ifdef HAVE_RTC
|
|
|
|
rtc_write(0x13, 0x00);
|
|
|
|
#else
|
2002-06-25 11:15:33 +00:00
|
|
|
PADR &= ~0x40;
|
2002-06-24 13:48:42 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2002-06-29 23:01:10 +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-06-30 13:14:16 +00:00
|
|
|
/* Wait until the USB cable is extracted again */
|
|
|
|
usb_wait_for_disconnect(&backlight_queue);
|
2002-06-29 23:01:10 +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-06-27 00:20:00 +00:00
|
|
|
void backlight_time(int seconds)
|
|
|
|
{
|
|
|
|
backlight_timeout = seconds;
|
|
|
|
backlight_on();
|
|
|
|
}
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
void backlight_tick(void)
|
|
|
|
{
|
|
|
|
if(backlight_timer)
|
|
|
|
{
|
|
|
|
backlight_timer--;
|
|
|
|
if(backlight_timer == 0)
|
|
|
|
{
|
|
|
|
backlight_off();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void backlight_init(void)
|
|
|
|
{
|
2002-07-03 08:03:55 +00:00
|
|
|
#ifdef HAVE_RTC
|
2002-07-02 23:05:04 +00:00
|
|
|
rtc_write(0x0a, 0x40); /* Enable square wave */
|
2002-07-03 08:03:55 +00:00
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
queue_init(&backlight_queue);
|
|
|
|
create_thread(backlight_thread, backlight_stack, sizeof(backlight_stack));
|
|
|
|
backlight_on();
|
|
|
|
}
|