1
0
Fork 0
forked from len0rd/rockbox

Backlight handling: * Added 'Caption Backlight' and 'Backlight On When Charging' for the iriver remote LCD. * Enabled the backlight code for the simulator, and prepared backlight simulation. It's only a stub atm, writing messages to the console window. * Added tick task handling to the simulators for this to work. * Code cleanup in backlight.c, less dead code.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8034 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2005-11-21 23:55:39 +00:00
parent e68680ac31
commit b51f7dfc9b
29 changed files with 416 additions and 231 deletions

View file

@ -1,9 +1,7 @@
#ifdef ROCKBOX_HAS_LOGF
logf.c
#endif
#ifndef SIMULATOR
backlight.c
#endif
buffer.c
common/atoi.c
common/ctype.c

View file

@ -28,6 +28,7 @@
#include "power.h"
#include "system.h"
#include "timer.h"
#include "backlight.h"
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
@ -51,17 +52,17 @@ static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)];
static const char backlight_thread_name[] = "backlight";
static struct event_queue backlight_queue;
static bool charger_was_inserted = 0;
static bool backlight_on_when_charging = 0;
static bool backlight_on_when_charging = false;
static int backlight_timer;
static unsigned int backlight_timeout = 5;
#ifdef HAVE_REMOTE_LCD
static bool remote_backlight_on_when_charging = false;
static int remote_backlight_timer;
static unsigned int remote_backlight_timeout = 5;
#endif
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
/* backlight fading */
#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */
#define BL_PWM_COUNT 100
@ -191,45 +192,13 @@ void backlight_set_fade_out(int index)
{
fade_out_count = backlight_fade_value[index];
}
#endif
static void __backlight_off(void)
{
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
if (fade_out_count > 0)
backlight_dim(0);
else
{
bl_dim_target = bl_dim_current = 0;
or_l(0x00020000, &GPIO1_OUT);
}
#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
and_l(~0x00020000, &GPIO1_OUT);
#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);
#endif
}
#endif /* (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) */
static void __backlight_on(void)
{
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
#ifdef SIMULATOR
sim_backlight(100);
#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
if (fade_in_count > 0)
backlight_dim(BL_PWM_COUNT);
else
@ -264,6 +233,66 @@ static void __backlight_on(void)
#endif
}
static void __backlight_off(void)
{
#ifdef SIMULATOR
sim_backlight(0);
#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
if (fade_out_count > 0)
backlight_dim(0);
else
{
bl_dim_target = bl_dim_current = 0;
or_l(0x00020000, &GPIO1_OUT);
}
#elif CONFIG_BACKLIGHT == BL_IRIVER_H300
and_l(~0x00020000, &GPIO1_OUT);
#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);
#endif
}
#ifdef HAVE_REMOTE_LCD
static void __remote_backlight_on(void)
{
#ifdef SIMULATOR
sim_remote_backlight(100);
#elif defined(IRIVER_H300_SERIES)
and_l(~0x00000002, &GPIO1_OUT);
#else
and_l(~0x00000800, &GPIO_OUT);
#endif
}
static void __remote_backlight_off(void)
{
#ifdef SIMULATOR
sim_remote_backlight(0);
#elif defined(IRIVER_H300_SERIES)
or_l(0x00000002, &GPIO1_OUT);
#else
or_l(0x00000800, &GPIO_OUT);
#endif
}
#endif /* HAVE_REMOTE_LCD */
void backlight_thread(void)
{
struct event ev;
@ -275,26 +304,34 @@ void backlight_thread(void)
{
#ifdef HAVE_REMOTE_LCD
case REMOTE_BACKLIGHT_ON:
remote_backlight_timer =
HZ*backlight_timeout_value[remote_backlight_timeout];
if( remote_backlight_on_when_charging && charger_inserted() )
{
/* Forcing to zero keeps the lights on */
remote_backlight_timer = 0;
}
else
{
remote_backlight_timer =
HZ*backlight_timeout_value[remote_backlight_timeout];
}
/* Backlight == OFF in the setting? */
if(remote_backlight_timer < 0)
{
remote_backlight_timer = 0; /* Disable the timeout */
lcd_remote_backlight_off();
__remote_backlight_off();
}
else
{
lcd_remote_backlight_on();
__remote_backlight_on();
}
break;
case REMOTE_BACKLIGHT_OFF:
lcd_remote_backlight_off();
__remote_backlight_off();
break;
#endif
#endif /* HAVE_REMOTE_LCD */
case BACKLIGHT_ON:
if( backlight_on_when_charging && charger_inserted() )
{
@ -321,7 +358,7 @@ void backlight_thread(void)
__backlight_off();
break;
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR)
case BACKLIGHT_UNBOOST_CPU:
cpu_boost(false);
break;
@ -340,74 +377,24 @@ void backlight_thread(void)
}
}
void backlight_on(void)
{
queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
}
void backlight_off(void)
{
queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
}
#ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void)
{
queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
}
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))
/* if given a weird value, use 0 */
index=0;
remote_backlight_timeout = index; /* index in the backlight_timeout_value table */
remote_backlight_on();
}
#endif
int backlight_get_timeout(void)
{
return backlight_timeout;
}
void backlight_set_timeout(int index)
{
if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */
index=0;
backlight_timeout = index; /* index in the backlight_timeout_value table */
backlight_on();
}
#ifdef HAVE_CHARGE_CTRL
bool backlight_get_on_when_charging(void)
{
return backlight_on_when_charging;
}
#endif
void backlight_set_on_when_charging(bool yesno)
{
backlight_on_when_charging = yesno;
backlight_on();
}
void backlight_tick(void)
static void backlight_tick(void)
{
#ifdef HAVE_CHARGING
static bool charger_was_inserted = false;
bool charger_is_inserted = charger_inserted();
if( backlight_on_when_charging &&
(charger_was_inserted != charger_is_inserted) )
if( charger_was_inserted != charger_is_inserted )
{
backlight_on();
if( backlight_on_when_charging )
backlight_on();
#ifdef HAVE_REMOTE_LCD
if( remote_backlight_on_when_charging )
remote_backlight_on();
#endif
}
charger_was_inserted = charger_is_inserted;
#endif /* HAVE_CHARGING */
if(backlight_timer)
{
backlight_timer--;
@ -433,8 +420,10 @@ void backlight_init(void)
queue_init(&backlight_queue);
create_thread(backlight_thread, backlight_stack,
sizeof(backlight_stack), backlight_thread_name);
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
tick_add_task(backlight_tick);
#ifdef SIMULATOR
/* do nothing */
#elif CONFIG_BACKLIGHT == BL_IRIVER_H100
or_l(0x00020000, &GPIO1_ENABLE);
or_l(0x00020000, &GPIO1_FUNCTION);
and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */
@ -454,22 +443,77 @@ void backlight_init(void)
#endif
}
void backlight_on(void)
{
queue_post(&backlight_queue, BACKLIGHT_ON, NULL);
}
void backlight_off(void)
{
queue_post(&backlight_queue, BACKLIGHT_OFF, NULL);
}
int backlight_get_timeout(void)
{
return backlight_timeout;
}
void backlight_set_timeout(int index)
{
if((unsigned)index >= sizeof(backlight_timeout_value))
/* if given a weird value, use 0 */
index=0;
backlight_timeout = index; /* index in the backlight_timeout_value table */
backlight_on();
}
#ifdef HAVE_CHARGING
bool backlight_get_on_when_charging(void)
{
return backlight_on_when_charging;
}
void backlight_set_on_when_charging(bool yesno)
{
backlight_on_when_charging = yesno;
backlight_on();
}
#endif
#ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void)
{
queue_post(&backlight_queue, REMOTE_BACKLIGHT_ON, NULL);
}
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))
/* if given a weird value, use 0 */
index=0;
remote_backlight_timeout = index; /* index in the backlight_timeout_value table */
remote_backlight_on();
}
#ifdef HAVE_CHARGING
void remote_backlight_set_on_when_charging(bool yesno)
{
remote_backlight_on_when_charging = yesno;
remote_backlight_on();
}
#endif
#endif /* HAVE_REMOTE_LCD */
#else /* no backlight, empty dummy functions */
void backlight_init(void)
{
#if defined(IRIVER_H300_SERIES) && defined(BOOTLOADER)
or_l(0x00020000, &GPIO1_OUT);
or_l(0x00020000, &GPIO1_ENABLE);
or_l(0x00020000, &GPIO1_FUNCTION);
#endif
}
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;}
void backlight_set_on_when_charging(bool yesno) {(void)yesno;}
#ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void) {}
void remote_backlight_off(void) {}

View file

@ -181,8 +181,6 @@ static void button_tick(void)
lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
tick = 0;
}
backlight_tick();
}
long button_get(bool block)

View file

@ -122,24 +122,6 @@ static const char scroll_tick_table[16] = {
/*** driver routines ***/
#ifndef SIMULATOR
void lcd_remote_backlight_on(void)
{
#ifdef IRIVER_H300_SERIES
and_l(~0x00000002, &GPIO1_OUT);
#else
and_l(~0x00000800, &GPIO_OUT);
#endif
}
void lcd_remote_backlight_off(void)
{
#ifdef IRIVER_H300_SERIES
or_l(0x00000002, &GPIO1_OUT);
#else
or_l(0x00000800, &GPIO_OUT);
#endif
}
void lcd_remote_write_command(int cmd)
{
int i;

View file

@ -21,24 +21,32 @@
#include "config.h"
void backlight_init(void);
void backlight_on(void);
void backlight_off(void);
void backlight_tick(void);
int backlight_get_timeout(void);
void backlight_set_timeout(int index);
#ifdef CONFIG_BACKLIGHT
void backlight_init(void);
int backlight_get_timeout(void);
#if CONFIG_BACKLIGHT == BL_IRIVER_H100
void backlight_set_fade_in(int index);
void backlight_set_fade_out(int index);
#endif
bool backlight_get_on_when_charging(void);
void backlight_set_on_when_charging(bool yesno);
void remote_backlight_on(void);
void remote_backlight_off(void);
extern const char backlight_timeout_value[];
#else
#define backlight_init()
#endif
#ifdef HAVE_REMOTE_LCD
void remote_backlight_on(void);
void remote_backlight_off(void);
void remote_backlight_set_timeout(int index);
void remote_backlight_set_on_when_charging(bool yesno);
#endif
#ifdef SIMULATOR
void sim_backlight(int value);
void sim_remote_backlight(int value);
#endif
#endif

View file

@ -32,6 +32,9 @@
/* Define this for S/PDIF input available */
#define HAVE_SPDIF_IN
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
#ifndef SIMULATOR
/* Define this if you have a SH7034 */
@ -83,9 +86,6 @@
/* Software controlled LED */
#define CONFIG_LED LED_REAL
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
/* define this if the unit can be powered or charged via USB */
#define HAVE_USB_POWER

View file

@ -38,6 +38,9 @@
#define CONFIG_LCD LCD_S1D15E06
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
/* Define this if you have a software controlled poweroff */
#define HAVE_SW_POWEROFF
@ -77,9 +80,6 @@
/* The size of the flash ROM */
#define FLASH_SIZE 0x200000
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
/* Define this to the CPU frequency */
#define CPU_FREQ 11289600

View file

@ -31,6 +31,9 @@
#define CONFIG_LCD LCD_S1D15E06
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
/* Define this if you have a software controlled poweroff */
#define HAVE_SW_POWEROFF
@ -72,9 +75,6 @@
/* The size of the flash ROM */
#define FLASH_SIZE 0x200000
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */
/* Define this to the CPU frequency */
#define CPU_FREQ 11289600

View file

@ -36,6 +36,9 @@
/* Define this if you have an remote lcd */
#define HAVE_REMOTE_LCD
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H300 /* port controlled PWM */
/* Define this if you have a software controlled poweroff */
#define HAVE_SW_POWEROFF
@ -69,9 +72,6 @@
/* The size of the flash ROM */
#define FLASH_SIZE 0x400000
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IRIVER_H300 /* port controlled PWM */
/* Define this to the CPU frequency */
#define CPU_FREQ 11289600

View file

@ -38,6 +38,9 @@
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8975
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IPOD4G /* port controlled */
#ifndef SIMULATOR
/* Define this if you have a PortalPlayer PP5020 */
@ -60,9 +63,6 @@
/* The start address index for ROM builds */
#define ROM_START 0x00000000
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IPOD4G /* port controlled */
/* Define this to the CPU frequency */
#define CPU_FREQ 11289600

View file

@ -38,6 +38,9 @@
/* Define this if you have the WM8975 audio codec */
#define HAVE_WM8975
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */
#ifndef SIMULATOR
/* The Nano actually has a PP5021 - but it's register compatible with
@ -62,9 +65,6 @@
/* The start address index for ROM builds */
#define ROM_START 0x00000000
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */
/* Define this to the CPU frequency */
#define CPU_FREQ 11289600

View file

@ -20,6 +20,9 @@
/* Define this if you have a DAC3550A */
#define HAVE_DAC3550A
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_PA14_LO /* port PA14, low active */
#ifndef SIMULATOR
/* Define this if you have a SH7034 */
@ -70,9 +73,6 @@
/* Software controlled LED */
#define CONFIG_LED LED_REAL
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_PA14_LO /* port PA14, low active */
#define CONFIG_LCD LCD_SSD1801
#define BOOTFILE_EXT "mod"

View file

@ -26,6 +26,9 @@
/* Define this for S/PDIF input available */
#define HAVE_SPDIF_IN
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
#ifndef SIMULATOR
/* Define this if you have a SH7034 */
@ -74,9 +77,6 @@
/* Software controlled LED */
#define CONFIG_LED LED_REAL
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
/* Define this for S/PDIF output available */
#define HAVE_SPDIF_OUT

View file

@ -29,6 +29,9 @@
/* Define this for S/PDIF input available */
#define HAVE_SPDIF_IN
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
#ifndef SIMULATOR
/* Define this if you have a SH7034 */
@ -83,9 +86,6 @@
/* Software controlled LED */
#define CONFIG_LED LED_REAL
/* Define this for LCD backlight available */
#define CONFIG_BACKLIGHT BL_RTC /* on I2C controlled RTC port */
/* define this if the unit can be powered or charged via USB */
#define HAVE_USB_POWER

View file

@ -30,8 +30,6 @@
#define STYLE_INVERT 1
extern void lcd_remote_init(void);
extern void lcd_remote_backlight_on(void);
extern void lcd_remote_backlight_off(void);
extern int lcd_remote_default_contrast(void);
extern void lcd_remote_set_contrast(int val);
extern void lcd_remote_emireduce(bool state);

View file

@ -448,7 +448,7 @@ static int runcurrent(void)
current = CURRENT_USB;
}
#ifndef BOOTLOADER
#if defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER)
if ((backlight_get_timeout() == 1) /* LED always on */
#ifdef HAVE_CHARGE_CTRL
|| (charger_inserted() && backlight_get_on_when_charging())
@ -915,13 +915,11 @@ void shutdown_hw(void)
#elif HAVE_TLV320
tlv320_close();
#endif
#if CONFIG_KEYPAD == ONDIO_PAD
backlight_off();
sleep(1);
lcd_set_contrast(0);
#endif
#ifdef HAVE_REMOTE_LCD
lcd_remote_backlight_off();
remote_backlight_off();
lcd_remote_set_contrast(0);
#endif
power_off();
#endif /* #ifndef SIMULATOR */