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>
|
2004-10-07 08:38:51 +00:00
|
|
|
|
#include "cpu.h"
|
2002-06-24 13:48:42 +00:00
|
|
|
|
#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"
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#include "button.h"
|
2005-07-26 20:01:11 +00:00
|
|
|
|
#include "timer.h"
|
2005-11-21 23:55:39 +00:00
|
|
|
|
#include "backlight.h"
|
2002-06-24 13:48:42 +00:00
|
|
|
|
|
2005-12-22 10:43:36 +00:00
|
|
|
|
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#include "pcf50606.h" /* iRiver, iAudio X5 brightness */
|
2005-12-22 10:43:36 +00:00
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
|
|
|
|
|
#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
|
|
|
|
|
#include "lcd.h" /* for lcd_enable() and lcd_sleep() */
|
2005-12-20 23:15:27 +00:00
|
|
|
|
#endif
|
2005-04-15 13:51:19 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
#include "lcd-remote.h"
|
|
|
|
|
#endif
|
2006-03-22 15:17:17 +00:00
|
|
|
|
#if defined(TARGET_TREE) && !defined(SIMULATOR)
|
2006-03-22 14:17:45 +00:00
|
|
|
|
#include "backlight-target.h"
|
|
|
|
|
#endif
|
2005-04-15 13:51:19 +00:00
|
|
|
|
|
2006-03-22 14:33:07 +00:00
|
|
|
|
#ifdef SIMULATOR
|
2006-03-22 15:04:46 +00:00
|
|
|
|
static inline void __backlight_on(void)
|
2006-03-22 14:33:07 +00:00
|
|
|
|
{
|
|
|
|
|
sim_backlight(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void __backlight_off(void)
|
|
|
|
|
{
|
|
|
|
|
sim_backlight(0);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2006-03-19 17:42:58 +00:00
|
|
|
|
/* Basic low-level code that simply switches backlight on or off. Probably
|
|
|
|
|
* a nice candidate for inclusion in the target/ dir. */
|
2006-03-22 14:17:45 +00:00
|
|
|
|
#ifndef TARGET_TREE
|
2006-03-19 17:42:58 +00:00
|
|
|
|
static inline void __backlight_on(void)
|
|
|
|
|
{
|
2006-03-22 14:33:07 +00:00
|
|
|
|
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
|
2006-08-08 22:03:56 +00:00
|
|
|
|
and_l(~0x00020000, &GPIO1_OUT);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
|
|
|
|
|
lcd_enable(true);
|
2006-04-26 19:26:01 +00:00
|
|
|
|
sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */
|
2006-08-08 22:03:56 +00:00
|
|
|
|
or_l(0x00020000, &GPIO1_OUT);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_RTC
|
|
|
|
|
/* Enable square wave */
|
|
|
|
|
rtc_write(0x0a, rtc_read(0x0a) | 0x40);
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
|
|
|
|
|
and_b(~0x40, &PADRH); /* drive and set low */
|
|
|
|
|
or_b(0x40, &PAIORH);
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
|
|
|
|
|
or_b(0x40, &PADRH); /* drive it high */
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_GMINI
|
|
|
|
|
P1 |= 0x10;
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IPOD4G
|
|
|
|
|
/* brightness full */
|
|
|
|
|
outl(0x80000000 | (0xff << 16), 0x7000a010);
|
|
|
|
|
|
|
|
|
|
/* set port b bit 3 on */
|
|
|
|
|
outl(((0x100 | 1) << 3), 0x6000d824);
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPODMINI
|
|
|
|
|
/* set port B03 on */
|
|
|
|
|
outl(((0x100 | 1) << 3), 0x6000d824);
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPODNANO
|
|
|
|
|
/* set port B03 on */
|
|
|
|
|
outl(((0x100 | 1) << 3), 0x6000d824);
|
|
|
|
|
|
|
|
|
|
/* set port L07 on */
|
|
|
|
|
outl(((0x100 | 1) << 7), 0x6000d12c);
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPOD3G
|
2006-03-31 07:53:01 +00:00
|
|
|
|
outl(inl(0xc0001000) | 0x02, 0xc0001000);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX
|
|
|
|
|
GPIO3_SET = 1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void __backlight_off(void)
|
|
|
|
|
{
|
2006-03-22 14:33:07 +00:00
|
|
|
|
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
|
2006-03-19 17:42:58 +00:00
|
|
|
|
or_l(0x00020000, &GPIO1_OUT);
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
|
|
|
|
|
and_l(~0x00020000, &GPIO1_OUT);
|
|
|
|
|
lcd_enable(false);
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_RTC
|
|
|
|
|
/* Disable square wave */
|
|
|
|
|
rtc_write(0x0a, rtc_read(0x0a) & ~0x40);
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */
|
|
|
|
|
and_b(~0x40, &PAIORH); /* let it float (up) */
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */
|
|
|
|
|
and_b(~0x40, &PADRH); /* drive it low */
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_GMINI
|
|
|
|
|
P1 &= ~0x10;
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IPOD4G
|
|
|
|
|
/* fades backlight off on 4g */
|
|
|
|
|
outl(inl(0x70000084) & ~0x2000000, 0x70000084);
|
|
|
|
|
outl(0x80000000, 0x7000a010);
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPODNANO
|
|
|
|
|
/* set port B03 off */
|
|
|
|
|
outl(((0x100 | 0) << 3), 0x6000d824);
|
|
|
|
|
|
|
|
|
|
/* set port L07 off */
|
|
|
|
|
outl(((0x100 | 0) << 7), 0x6000d12c);
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX
|
|
|
|
|
GPIO3_CLR = 1;
|
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPOD3G
|
2006-03-31 07:53:01 +00:00
|
|
|
|
outl(inl(0xc0001000) & ~0x02, 0xc0001000);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT==BL_IPODMINI
|
|
|
|
|
/* set port B03 off */
|
|
|
|
|
outl(((0x100 | 0) << 3), 0x6000d824);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2006-03-22 14:17:45 +00:00
|
|
|
|
#endif
|
2006-03-22 14:33:07 +00:00
|
|
|
|
#endif /* SIMULATOR */
|
2006-03-19 17:42:58 +00:00
|
|
|
|
|
2005-07-04 22:42:44 +00:00
|
|
|
|
#if defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER)
|
2004-10-09 19:56:27 +00:00
|
|
|
|
|
2006-04-01 12:20:23 +00:00
|
|
|
|
const signed char backlight_timeout_value[19] =
|
2004-09-10 13:56:54 +00:00
|
|
|
|
{
|
|
|
|
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 45, 60, 90
|
|
|
|
|
};
|
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
|
#define BACKLIGHT_ON 1
|
|
|
|
|
#define BACKLIGHT_OFF 2
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#define REMOTE_BACKLIGHT_ON 3
|
|
|
|
|
#define REMOTE_BACKLIGHT_OFF 4
|
2005-08-11 21:47:52 +00:00
|
|
|
|
#define BACKLIGHT_UNBOOST_CPU 5
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
#define LCD_SLEEP 6
|
|
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
|
|
|
|
|
|
static void backlight_thread(void);
|
2005-02-06 02:43:26 +00:00
|
|
|
|
static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef X5_BACKLIGHT_SHUTDOWN
|
|
|
|
|
#define BACKLIGHT_QUIT 256
|
|
|
|
|
/* Need to save this for x5 shutdown */
|
|
|
|
|
static int backlight_thread_id;
|
|
|
|
|
#endif
|
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;
|
|
|
|
|
|
|
|
|
|
static int backlight_timer;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
static int backlight_timeout = 5*HZ;
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2005-11-23 20:12:33 +00:00
|
|
|
|
static int backlight_timeout_plugged = 5*HZ;
|
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
|
static int backlight_on_button_hold = 0;
|
|
|
|
|
#endif
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
static int remote_backlight_timer;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
static int remote_backlight_timeout = 5*HZ;
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2005-11-23 20:12:33 +00:00
|
|
|
|
static int remote_backlight_timeout_plugged = 5*HZ;
|
|
|
|
|
#endif
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
|
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
const signed char lcd_sleep_timeout_value[10] =
|
|
|
|
|
{
|
|
|
|
|
-1, 0, 5, 10, 15, 20, 30, 45, 60, 90
|
|
|
|
|
};
|
|
|
|
|
static int lcd_sleep_timer;
|
|
|
|
|
static int lcd_sleep_timeout = 10*HZ;
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
|
2005-06-20 17:03:09 +00:00
|
|
|
|
/* backlight fading */
|
|
|
|
|
#define BL_PWM_INTERVAL 5000 /* Cycle interval in <20>s */
|
2005-06-18 12:53:57 +00:00
|
|
|
|
#define BL_PWM_COUNT 100
|
2005-06-20 17:03:09 +00:00
|
|
|
|
static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 };
|
|
|
|
|
static int fade_in_count = 1;
|
|
|
|
|
static int fade_out_count = 4;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
|
|
|
|
|
static bool bl_timer_active = false;
|
|
|
|
|
static int bl_dim_current = BL_PWM_COUNT;
|
|
|
|
|
static int bl_dim_target = BL_PWM_COUNT;
|
|
|
|
|
static int bl_pwm_counter = 0;
|
|
|
|
|
static volatile int bl_cycle_counter = 0;
|
2005-06-20 17:03:09 +00:00
|
|
|
|
static enum {DIM_STATE_START, DIM_STATE_MAIN} bl_dim_state = DIM_STATE_START;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
static void backlight_isr(void)
|
2005-06-18 12:53:57 +00:00
|
|
|
|
{
|
|
|
|
|
int timer_period;
|
2005-06-19 10:12:11 +00:00
|
|
|
|
bool idle = false;
|
2005-07-26 20:01:11 +00:00
|
|
|
|
|
2006-03-19 17:42:58 +00:00
|
|
|
|
timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000;
|
2005-07-26 20:01:11 +00:00
|
|
|
|
switch (bl_dim_state)
|
|
|
|
|
{
|
2005-06-20 17:03:09 +00:00
|
|
|
|
/* New cycle */
|
|
|
|
|
case DIM_STATE_START:
|
2005-06-18 12:53:57 +00:00
|
|
|
|
bl_pwm_counter = 0;
|
|
|
|
|
bl_cycle_counter++;
|
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT)
|
2005-06-20 17:03:09 +00:00
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_on();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
bl_pwm_counter = bl_dim_current;
|
|
|
|
|
timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT;
|
|
|
|
|
bl_dim_state = DIM_STATE_MAIN;
|
2005-06-20 17:03:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-06-18 12:53:57 +00:00
|
|
|
|
if (bl_dim_current)
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_on();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
else
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_off();
|
2005-06-20 17:03:09 +00:00
|
|
|
|
if (bl_dim_current == bl_dim_target)
|
|
|
|
|
idle = true;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break ;
|
|
|
|
|
|
2005-06-20 17:03:09 +00:00
|
|
|
|
/* Dim main screen */
|
|
|
|
|
case DIM_STATE_MAIN:
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_off();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
bl_dim_state = DIM_STATE_START;
|
|
|
|
|
timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT;
|
|
|
|
|
break ;
|
|
|
|
|
}
|
2005-07-26 20:01:11 +00:00
|
|
|
|
|
2005-06-20 17:03:09 +00:00
|
|
|
|
if ((bl_dim_target > bl_dim_current) && (bl_cycle_counter >= fade_in_count))
|
|
|
|
|
{
|
|
|
|
|
bl_dim_current++;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
bl_cycle_counter = 0;
|
|
|
|
|
}
|
2005-06-20 17:03:09 +00:00
|
|
|
|
|
|
|
|
|
if ((bl_dim_target < bl_dim_current) && (bl_cycle_counter >= fade_out_count))
|
|
|
|
|
{
|
|
|
|
|
bl_dim_current--;
|
|
|
|
|
bl_cycle_counter = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (idle)
|
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#ifdef CPU_COLDFIRE
|
2005-08-11 21:47:52 +00:00
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_UNBOOST_CPU, NULL);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#endif
|
2005-07-26 20:01:11 +00:00
|
|
|
|
timer_unregister();
|
2005-06-20 17:03:09 +00:00
|
|
|
|
bl_timer_active = false;
|
|
|
|
|
}
|
2005-07-26 20:01:11 +00:00
|
|
|
|
else
|
|
|
|
|
timer_set_period(timer_period);
|
|
|
|
|
}
|
2005-06-20 17:03:09 +00:00
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
static void backlight_switch(void)
|
|
|
|
|
{
|
|
|
|
|
if (bl_dim_target > (BL_PWM_COUNT/2))
|
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_on();
|
2005-07-26 20:01:11 +00:00
|
|
|
|
bl_dim_current = BL_PWM_COUNT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_off();
|
2005-07-26 20:01:11 +00:00
|
|
|
|
bl_dim_current = 0;
|
|
|
|
|
}
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
static void backlight_release_timer(void)
|
2005-06-18 12:53:57 +00:00
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#ifdef CPU_COLDFIRE
|
2005-07-26 20:01:11 +00:00
|
|
|
|
cpu_boost(false);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#endif
|
2005-07-26 20:01:11 +00:00
|
|
|
|
timer_unregister();
|
|
|
|
|
bl_timer_active = false;
|
|
|
|
|
backlight_switch();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
static void backlight_dim(int value)
|
2005-06-18 12:53:57 +00:00
|
|
|
|
{
|
2005-08-11 21:22:54 +00:00
|
|
|
|
/* protect from extraneous calls with the same target value */
|
|
|
|
|
if (value == bl_dim_target)
|
|
|
|
|
return;
|
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
bl_dim_target = value;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
if (bl_timer_active)
|
|
|
|
|
return ;
|
2005-06-18 12:53:57 +00:00
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
|
if (timer_register(0, backlight_release_timer, 1, 0, backlight_isr))
|
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#ifdef CPU_COLDFIRE
|
2005-07-26 20:01:11 +00:00
|
|
|
|
/* Prevent cpu frequency changes while dimming. */
|
|
|
|
|
cpu_boost(true);
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#endif
|
2005-07-26 20:01:11 +00:00
|
|
|
|
bl_timer_active = true;
|
2005-06-20 17:03:09 +00:00
|
|
|
|
}
|
2005-07-26 20:01:11 +00:00
|
|
|
|
else
|
|
|
|
|
backlight_switch();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-20 17:03:09 +00:00
|
|
|
|
void backlight_set_fade_in(int index)
|
2005-06-18 12:53:57 +00:00
|
|
|
|
{
|
2005-06-20 17:03:09 +00:00
|
|
|
|
fade_in_count = backlight_fade_value[index];
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-20 17:03:09 +00:00
|
|
|
|
void backlight_set_fade_out(int index)
|
2005-06-18 12:53:57 +00:00
|
|
|
|
{
|
2005-06-20 17:03:09 +00:00
|
|
|
|
fade_out_count = backlight_fade_value[index];
|
2005-06-18 12:53:57 +00:00
|
|
|
|
}
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
2006-03-19 17:42:58 +00:00
|
|
|
|
static void _backlight_on(void)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
if (fade_in_count > 0)
|
|
|
|
|
backlight_dim(BL_PWM_COUNT);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bl_dim_target = bl_dim_current = BL_PWM_COUNT;
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_on();
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#else
|
|
|
|
|
__backlight_on();
|
2005-06-18 12:53:57 +00:00
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
lcd_sleep_timer = 0; /* LCD should be awake already */
|
|
|
|
|
#endif
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
2005-06-18 12:53:57 +00:00
|
|
|
|
|
2006-03-19 17:42:58 +00:00
|
|
|
|
static void _backlight_off(void)
|
2004-10-07 08:38:51 +00:00
|
|
|
|
{
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
|
2005-07-26 20:01:11 +00:00
|
|
|
|
if (fade_out_count > 0)
|
|
|
|
|
backlight_dim(0);
|
2005-06-20 17:03:09 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bl_dim_target = bl_dim_current = 0;
|
2006-03-19 17:42:58 +00:00
|
|
|
|
__backlight_off();
|
2005-06-20 17:03:09 +00:00
|
|
|
|
}
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#else
|
|
|
|
|
__backlight_off();
|
2004-10-07 08:38:51 +00:00
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
/* Start LCD sleep countdown */
|
|
|
|
|
if (lcd_sleep_timeout < 0)
|
|
|
|
|
{
|
|
|
|
|
lcd_sleep_timer = 0; /* Setting == Always */
|
|
|
|
|
lcd_sleep();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
lcd_sleep_timer = lcd_sleep_timeout;
|
|
|
|
|
#endif
|
2004-10-07 08:38:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2006-07-28 12:41:13 +00:00
|
|
|
|
#ifdef SIMULATOR
|
2005-11-21 23:55:39 +00:00
|
|
|
|
static void __remote_backlight_on(void)
|
2004-10-07 08:38:51 +00:00
|
|
|
|
{
|
2005-11-21 23:55:39 +00:00
|
|
|
|
sim_remote_backlight(100);
|
2006-07-28 12:41:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void __remote_backlight_off(void)
|
|
|
|
|
{
|
|
|
|
|
sim_remote_backlight(0);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#ifndef TARGET_TREE
|
|
|
|
|
static void __remote_backlight_on(void)
|
|
|
|
|
{
|
|
|
|
|
#if defined(IRIVER_H300_SERIES)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
and_l(~0x00000002, &GPIO1_OUT);
|
|
|
|
|
#else
|
|
|
|
|
and_l(~0x00000800, &GPIO_OUT);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2005-11-14 01:28:17 +00:00
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
static void __remote_backlight_off(void)
|
|
|
|
|
{
|
2006-07-28 12:41:13 +00:00
|
|
|
|
#if defined(IRIVER_H300_SERIES)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
or_l(0x00000002, &GPIO1_OUT);
|
|
|
|
|
#else
|
|
|
|
|
or_l(0x00000800, &GPIO_OUT);
|
2004-10-07 08:38:51 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2006-07-28 11:06:28 +00:00
|
|
|
|
#endif /* TARGET_TREE */
|
2006-07-28 12:41:13 +00:00
|
|
|
|
#endif /* SIMULATOR */
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* HAVE_REMOTE_LCD */
|
|
|
|
|
|
|
|
|
|
/* Update state of backlight according to timeout setting */
|
|
|
|
|
static void backlight_update_state(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef CONFIG_CHARGING
|
|
|
|
|
if (charger_inserted()
|
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
|
|| usb_powered()
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
backlight_timer = backlight_timeout_plugged;
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
backlight_timer = backlight_timeout;
|
|
|
|
|
|
|
|
|
|
/* Backlight == OFF in the setting? */
|
|
|
|
|
if (backlight_timer < 0)
|
|
|
|
|
{
|
|
|
|
|
backlight_timer = 0; /* Disable the timeout */
|
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
|
if (backlight_on_button_hold == 2 && button_hold())
|
|
|
|
|
return; /* Keep on if "On" */
|
|
|
|
|
#endif
|
|
|
|
|
_backlight_off();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
|
if (backlight_on_button_hold == 1 && button_hold())
|
|
|
|
|
{
|
|
|
|
|
/* Keep off if "Off". */
|
|
|
|
|
backlight_timer = 0; /* Disable the timeout */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
_backlight_on();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
/* Update state of remote backlight according to timeout setting */
|
|
|
|
|
static void remote_backlight_update_state(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef CONFIG_CHARGING
|
|
|
|
|
if (charger_inserted()
|
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
|
|| usb_powered()
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
remote_backlight_timer = remote_backlight_timeout_plugged;
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
remote_backlight_timer = remote_backlight_timeout;
|
|
|
|
|
|
|
|
|
|
/* Backlight == OFF in the setting? */
|
|
|
|
|
if (remote_backlight_timer < 0)
|
|
|
|
|
{
|
|
|
|
|
remote_backlight_timer = 0; /* Disable the timeout */
|
|
|
|
|
__remote_backlight_off();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-08-15 07:06:53 +00:00
|
|
|
|
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
|
|
|
|
|
if (remote_type() == REMOTETYPE_H300_NONLCD)
|
|
|
|
|
{
|
|
|
|
|
backlight_update_state();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
__remote_backlight_on();
|
2006-08-08 22:03:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_REMOTE_LCD */
|
2004-10-07 08:38:51 +00:00
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
|
void backlight_thread(void)
|
|
|
|
|
{
|
|
|
|
|
struct event ev;
|
2006-08-08 22:03:56 +00:00
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
queue_wait(&backlight_queue, &ev);
|
|
|
|
|
switch(ev.id)
|
|
|
|
|
{
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
case REMOTE_BACKLIGHT_ON:
|
2006-08-08 22:03:56 +00:00
|
|
|
|
remote_backlight_update_state();
|
2005-04-15 16:16:26 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case REMOTE_BACKLIGHT_OFF:
|
2006-08-08 22:03:56 +00:00
|
|
|
|
remote_backlight_timer = 0; /* Disable the timeout */
|
2005-11-21 23:55:39 +00:00
|
|
|
|
__remote_backlight_off();
|
2005-04-15 16:16:26 +00:00
|
|
|
|
break;
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
|
case BACKLIGHT_ON:
|
2006-08-08 22:03:56 +00:00
|
|
|
|
backlight_update_state();
|
2002-06-24 13:48:42 +00:00
|
|
|
|
break;
|
2006-08-08 22:03:56 +00:00
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
|
case BACKLIGHT_OFF:
|
2006-08-08 22:03:56 +00:00
|
|
|
|
backlight_timer = 0; /* Disable the timeout */
|
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
|
if (backlight_on_button_hold == 2 && button_hold())
|
|
|
|
|
break; /* Keep on if "On" */
|
|
|
|
|
#endif
|
2006-03-19 17:42:58 +00:00
|
|
|
|
_backlight_off();
|
2002-06-24 13:48:42 +00:00
|
|
|
|
break;
|
2005-08-11 21:47:52 +00:00
|
|
|
|
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
case LCD_SLEEP:
|
|
|
|
|
lcd_sleep();
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef X5_BACKLIGHT_SHUTDOWN
|
|
|
|
|
case BACKLIGHT_QUIT:
|
|
|
|
|
remove_thread(backlight_thread_id);
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-03-19 17:42:58 +00:00
|
|
|
|
#if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \
|
|
|
|
|
&& !defined(SIMULATOR)
|
2005-08-11 21:47:52 +00:00
|
|
|
|
case BACKLIGHT_UNBOOST_CPU:
|
|
|
|
|
cpu_boost(false);
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
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;
|
2006-08-08 22:03:56 +00:00
|
|
|
|
} /* end switch */
|
|
|
|
|
} /* end while */
|
2002-06-24 13:48:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
static void backlight_tick(void)
|
2002-06-24 13:48:42 +00:00
|
|
|
|
{
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2005-11-21 23:55:39 +00:00
|
|
|
|
static bool charger_was_inserted = false;
|
2006-03-19 01:01:03 +00:00
|
|
|
|
bool charger_is_inserted = charger_inserted()
|
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
|
|| usb_powered()
|
|
|
|
|
#endif
|
|
|
|
|
;
|
2002-06-24 13:48:42 +00:00
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
if( charger_was_inserted != charger_is_inserted )
|
|
|
|
|
{
|
2005-11-23 20:12:33 +00:00
|
|
|
|
backlight_on();
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2005-11-23 20:12:33 +00:00
|
|
|
|
remote_backlight_on();
|
2005-05-08 12:56:48 +00:00
|
|
|
|
#endif
|
2002-10-01 10:59:36 +00:00
|
|
|
|
}
|
|
|
|
|
charger_was_inserted = charger_is_inserted;
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#endif /* CONFIG_CHARGING */
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
2002-06-24 13:48:42 +00:00
|
|
|
|
if(backlight_timer)
|
|
|
|
|
{
|
|
|
|
|
backlight_timer--;
|
|
|
|
|
if(backlight_timer == 0)
|
|
|
|
|
{
|
|
|
|
|
backlight_off();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
else if(lcd_sleep_timer)
|
|
|
|
|
{
|
|
|
|
|
lcd_sleep_timer--;
|
|
|
|
|
if(lcd_sleep_timer == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Queue on bl thread or freeze! */
|
|
|
|
|
queue_post(&backlight_queue, LCD_SLEEP, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_LCD_SLEEP */
|
|
|
|
|
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
if(remote_backlight_timer)
|
|
|
|
|
{
|
|
|
|
|
remote_backlight_timer--;
|
|
|
|
|
if(remote_backlight_timer == 0)
|
|
|
|
|
{
|
|
|
|
|
remote_backlight_off();
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* HAVE_REMOVE_LCD */
|
2002-06-24 13:48:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void backlight_init(void)
|
|
|
|
|
{
|
|
|
|
|
queue_init(&backlight_queue);
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef X5_BACKLIGHT_SHUTDOWN
|
|
|
|
|
backlight_thread_id =
|
|
|
|
|
#endif
|
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);
|
2005-11-21 23:55:39 +00:00
|
|
|
|
tick_add_task(backlight_tick);
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
/* do nothing */
|
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
|
2005-07-02 12:18:10 +00:00
|
|
|
|
or_l(0x00020000, &GPIO1_ENABLE);
|
|
|
|
|
or_l(0x00020000, &GPIO1_FUNCTION);
|
2005-08-15 07:18:36 +00:00
|
|
|
|
and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
|
2005-11-14 22:12:50 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
|
|
|
|
|
or_l(0x00020000, &GPIO1_ENABLE);
|
|
|
|
|
or_l(0x00020000, &GPIO1_FUNCTION);
|
|
|
|
|
or_l(0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
|
2004-12-18 10:29:47 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_PA14_LO || CONFIG_BACKLIGHT == BL_PA14_HI
|
2004-11-20 00:15:40 +00:00
|
|
|
|
PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */
|
|
|
|
|
or_b(0x40, &PAIORH); /* ..and output */
|
2005-02-05 10:53:41 +00:00
|
|
|
|
#elif CONFIG_BACKLIGHT == BL_GMINI
|
|
|
|
|
P1CON |= 0x10; /* P1.4 C-MOS output mode */
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
|
backlight_on();
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
remote_backlight_on();
|
|
|
|
|
#endif
|
2002-06-24 13:48:42 +00:00
|
|
|
|
}
|
2004-09-10 13:56:54 +00:00
|
|
|
|
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#ifdef X5_BACKLIGHT_SHUTDOWN
|
|
|
|
|
void x5_backlight_shutdown(void)
|
|
|
|
|
{
|
|
|
|
|
/* Turn on the screen and don't let anyone else mess with it. Called
|
|
|
|
|
from clean_shutdown in misc.c. */
|
|
|
|
|
queue_empty(&backlight_queue);
|
|
|
|
|
tick_remove_task(backlight_tick);
|
|
|
|
|
/* Next time the thread runs, if at all, it will just remove itself. */
|
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_QUIT, NULL);
|
|
|
|
|
__backlight_on();
|
|
|
|
|
}
|
|
|
|
|
#endif /* X5_BACKLIGHT_SHUTDOWN */
|
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
void backlight_on(void)
|
|
|
|
|
{
|
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
|
|
|
|
|
}
|
2004-09-10 13:56:54 +00:00
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
void backlight_off(void)
|
2005-11-16 23:53:01 +00:00
|
|
|
|
{
|
2005-11-21 23:55:39 +00:00
|
|
|
|
queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-01 12:20:23 +00:00
|
|
|
|
/* returns true when the backlight is on OR when it's set to always off */
|
2006-03-24 13:47:24 +00:00
|
|
|
|
bool is_backlight_on(void)
|
|
|
|
|
{
|
2006-04-01 12:20:23 +00:00
|
|
|
|
if (backlight_timer || backlight_get_current_timeout() <= 0)
|
2006-03-24 13:47:24 +00:00
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-23 20:12:33 +00:00
|
|
|
|
/* return value in ticks; 0 means always on, <0 means always off */
|
|
|
|
|
int backlight_get_current_timeout(void)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
{
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2006-03-19 01:01:03 +00:00
|
|
|
|
if (charger_inserted()
|
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
|
|| usb_powered()
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
return backlight_timeout_plugged;
|
|
|
|
|
else
|
|
|
|
|
return backlight_timeout;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
#else
|
2005-11-21 23:55:39 +00:00
|
|
|
|
return backlight_timeout;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
#endif
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void backlight_set_timeout(int index)
|
|
|
|
|
{
|
|
|
|
|
if((unsigned)index >= sizeof(backlight_timeout_value))
|
2006-08-08 22:03:56 +00:00
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index = 6;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
backlight_timeout = HZ * backlight_timeout_value[index];
|
2006-08-08 22:03:56 +00:00
|
|
|
|
backlight_update_state();
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2005-11-23 20:12:33 +00:00
|
|
|
|
void backlight_set_timeout_plugged(int index)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
{
|
2005-11-23 20:12:33 +00:00
|
|
|
|
if((unsigned)index >= sizeof(backlight_timeout_value))
|
2006-08-08 22:03:56 +00:00
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index = 6;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
backlight_timeout_plugged = HZ * backlight_timeout_value[index];
|
2006-08-08 22:03:56 +00:00
|
|
|
|
backlight_update_state();
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* CONFIG_CHARGING */
|
|
|
|
|
|
|
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
|
/* Hold button change event handler. */
|
|
|
|
|
void backlight_hold_changed(bool hold_button)
|
|
|
|
|
{
|
|
|
|
|
/* Hold switch overrides all backlight behavior except when
|
|
|
|
|
set to "Normal" */
|
|
|
|
|
/* Queue or freeze */
|
|
|
|
|
if (hold_button && backlight_on_button_hold == 1)
|
|
|
|
|
{
|
|
|
|
|
backlight_off(); /* setting == Off */
|
|
|
|
|
}
|
|
|
|
|
else /* setting == On, Normal, no hold button, or anything else */
|
|
|
|
|
backlight_on();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void backlight_set_on_button_hold(int index)
|
|
|
|
|
{
|
|
|
|
|
if ((unsigned)index >= 3)
|
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
|
|
if (index == backlight_on_button_hold)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
backlight_on_button_hold = index;
|
|
|
|
|
backlight_hold_changed(button_hold());
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAS_BUTTON_HOLD */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_SLEEP
|
|
|
|
|
void lcd_set_sleep_after_backlight_off(int index)
|
|
|
|
|
{
|
|
|
|
|
if ((unsigned)index >= sizeof(lcd_sleep_timeout_value))
|
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index = 3;
|
|
|
|
|
|
|
|
|
|
lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index];
|
|
|
|
|
|
|
|
|
|
if (backlight_timer > 0 || backlight_get_current_timeout() == 0)
|
|
|
|
|
/* Timer will be set when bl turns off or bl set to on. */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Backlight is Off */
|
|
|
|
|
if (lcd_sleep_timeout < 0)
|
|
|
|
|
lcd_sleep_timer = 1; /* Always - sleep next tick */
|
|
|
|
|
else
|
|
|
|
|
lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_LCD_SLEEP */
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
void remote_backlight_on(void)
|
|
|
|
|
{
|
|
|
|
|
queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
|
2005-11-16 23:53:01 +00:00
|
|
|
|
}
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
|
|
|
|
void remote_backlight_off(void)
|
|
|
|
|
{
|
|
|
|
|
queue_post(&backlight_queue, REMOTE_BACKLIGHT_OFF, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void remote_backlight_set_timeout(int index)
|
|
|
|
|
{
|
|
|
|
|
if((unsigned)index >= sizeof(backlight_timeout_value))
|
2006-08-08 22:03:56 +00:00
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index=6;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
remote_backlight_timeout = HZ * backlight_timeout_value[index];
|
2006-08-08 22:03:56 +00:00
|
|
|
|
remote_backlight_update_state();
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2005-11-23 20:12:33 +00:00
|
|
|
|
void remote_backlight_set_timeout_plugged(int index)
|
2005-11-21 23:55:39 +00:00
|
|
|
|
{
|
2005-11-23 20:12:33 +00:00
|
|
|
|
if((unsigned)index >= sizeof(backlight_timeout_value))
|
2006-08-08 22:03:56 +00:00
|
|
|
|
/* if given a weird value, use default */
|
|
|
|
|
index=6;
|
2005-11-23 20:12:33 +00:00
|
|
|
|
remote_backlight_timeout_plugged = HZ * backlight_timeout_value[index];
|
2006-08-08 22:03:56 +00:00
|
|
|
|
remote_backlight_update_state();
|
2005-11-21 23:55:39 +00:00
|
|
|
|
}
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* CONFIG_CHARGING */
|
2006-03-25 19:16:45 +00:00
|
|
|
|
|
|
|
|
|
/* return value in ticks; 0 means always on, <0 means always off */
|
|
|
|
|
int remote_backlight_get_current_timeout(void)
|
|
|
|
|
{
|
2006-06-06 22:23:52 +00:00
|
|
|
|
#ifdef CONFIG_CHARGING
|
2006-03-25 19:16:45 +00:00
|
|
|
|
if (charger_inserted()
|
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
|
|| usb_powered()
|
|
|
|
|
#endif
|
|
|
|
|
)
|
|
|
|
|
return remote_backlight_timeout_plugged;
|
|
|
|
|
else
|
|
|
|
|
return remote_backlight_timeout;
|
|
|
|
|
#else
|
|
|
|
|
return remote_backlight_timeout;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-01 12:20:23 +00:00
|
|
|
|
/* returns true when the backlight is on OR when it's set to always off */
|
2006-03-25 19:16:45 +00:00
|
|
|
|
bool is_remote_backlight_on(void)
|
|
|
|
|
{
|
2006-04-01 12:20:23 +00:00
|
|
|
|
if (remote_backlight_timer != 0 ||
|
|
|
|
|
remote_backlight_get_current_timeout() <= 0)
|
2006-03-25 19:16:45 +00:00
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-21 23:55:39 +00:00
|
|
|
|
#endif /* HAVE_REMOTE_LCD */
|
|
|
|
|
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#else /* !defined(CONFIG_BACKLIGHT) || defined(BOOTLOADER)
|
|
|
|
|
-- no backlight, empty dummy functions */
|
2005-11-21 23:55:39 +00:00
|
|
|
|
|
2006-03-18 20:01:45 +00:00
|
|
|
|
#if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT)
|
2005-11-22 01:39:41 +00:00
|
|
|
|
void backlight_init(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef IRIVER_H300_SERIES
|
|
|
|
|
or_l(0x00020000, &GPIO1_OUT);
|
|
|
|
|
or_l(0x00020000, &GPIO1_ENABLE);
|
|
|
|
|
or_l(0x00020000, &GPIO1_FUNCTION);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-09-10 13:56:54 +00:00
|
|
|
|
void backlight_on(void) {}
|
|
|
|
|
void backlight_off(void) {}
|
|
|
|
|
void backlight_set_timeout(int index) {(void)index;}
|
2006-03-24 14:18:22 +00:00
|
|
|
|
bool is_backlight_on(void) {return true;}
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
|
void remote_backlight_on(void) {}
|
|
|
|
|
void remote_backlight_off(void) {}
|
2005-05-30 06:42:14 +00:00
|
|
|
|
void remote_backlight_set_timeout(int index) {(void)index;}
|
2006-03-25 19:16:45 +00:00
|
|
|
|
bool is_remote_backlight_on(void) {return true;}
|
2005-04-15 16:16:26 +00:00
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) */
|
2004-09-10 13:56:54 +00:00
|
|
|
|
|
2006-08-08 22:03:56 +00:00
|
|
|
|
/* TODO: Move low level code to target/ tree. Create
|
|
|
|
|
__backlight_set_brightness and call from here. */
|
2005-12-22 10:43:36 +00:00
|
|
|
|
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
|
2006-07-23 22:18:32 +00:00
|
|
|
|
#if defined(IRIVER_H300_SERIES) || defined(IAUDIO_X5)
|
2005-12-22 10:43:36 +00:00
|
|
|
|
void backlight_set_brightness(int val)
|
|
|
|
|
{
|
2006-07-23 22:39:06 +00:00
|
|
|
|
#ifndef SIMULATOR
|
2006-07-25 15:21:31 +00:00
|
|
|
|
/* set brightness by changing the PWM
|
|
|
|
|
* accepts 0..15 but note that 0 and 1 give a black display on H300!
|
|
|
|
|
* 0 is black on the X5.
|
|
|
|
|
*/
|
2006-05-27 09:27:22 +00:00
|
|
|
|
|
|
|
|
|
/* disable IRQs while bitbanging */
|
|
|
|
|
int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
|
|
|
|
|
|
2006-07-25 15:21:31 +00:00
|
|
|
|
/* Clamp setting to range */
|
2006-01-19 13:10:15 +00:00
|
|
|
|
if(val<MIN_BRIGHTNESS_SETTING)
|
|
|
|
|
val=MIN_BRIGHTNESS_SETTING;
|
2006-07-25 15:21:31 +00:00
|
|
|
|
else if(val>MAX_BRIGHTNESS_SETTING)
|
|
|
|
|
val=MAX_BRIGHTNESS_SETTING;
|
2006-01-19 13:10:15 +00:00
|
|
|
|
|
2006-07-25 15:21:31 +00:00
|
|
|
|
pcf50606_write(0x35, (val << 1) | 0x01); /* 512Hz, Enable PWM */
|
2006-01-19 13:10:15 +00:00
|
|
|
|
|
|
|
|
|
/* enable IRQs again */
|
|
|
|
|
set_irq_level(old_irq_level);
|
2006-07-23 22:39:06 +00:00
|
|
|
|
#else
|
2006-07-25 15:21:31 +00:00
|
|
|
|
val=0;
|
2005-12-22 10:43:36 +00:00
|
|
|
|
#endif
|
2006-07-23 22:39:06 +00:00
|
|
|
|
}
|
2006-01-19 13:10:15 +00:00
|
|
|
|
#endif
|
2006-08-08 22:03:56 +00:00
|
|
|
|
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
|
2005-12-22 10:43:36 +00:00
|
|
|
|
|