Index: firmware/export/config-c200.h =================================================================== --- firmware/export/config-c200.h (Revision 19102) +++ firmware/export/config-c200.h (Arbeitskopie) @@ -32,6 +32,9 @@ /* define this if you have a light associated with the buttons */ #define HAVE_BUTTON_LIGHT +/* define this if the backlight thread is used for fade */ +#define HAVE_BACKLIGHT_THREAD_FADING + /* define this if you have access to the quickscreen */ #define HAVE_QUICKSCREEN Index: firmware/export/config-e200.h =================================================================== --- firmware/export/config-e200.h (Revision 19102) +++ firmware/export/config-e200.h (Arbeitskopie) @@ -129,6 +129,9 @@ /** Non-simulator section **/ #ifndef SIMULATOR +/* define this if the backlight thread is used for fade, not for sim */ +#define USE_BACKLIGHT_THREAD_FADING + /* Define this if you have a PortalPlayer PP5024 */ #define CONFIG_CPU PP5024 Index: firmware/export/backlight-thread-fading.h =================================================================== --- firmware/export/backlight-thread-fading.h (Revision 0) +++ firmware/export/backlight-thread-fading.h (Revision 0) @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id:$ + * + * Copyright (C) 2007 by Will Robertson + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef BACKLIGHT_THREAD_FADING_H + +#define BACKLIGHT_THREAD_FADING_H + +#ifdef USE_BACKLIGHT_THREAD_FADING +bool _backlight_fade_up(void); +bool _backlight_fade_down(void); +void _backlight_thread_fade_init(void); +#endif /* USE_BACKLIGHT_THREAD_FADING */ + +#endif /* _BACKLIGHT_THREAD_FADING_ */ Index: firmware/export/config-gigabeat-s.h =================================================================== --- firmware/export/config-gigabeat-s.h (Revision 19102) +++ firmware/export/config-gigabeat-s.h (Arbeitskopie) @@ -77,7 +77,7 @@ #ifndef BOOTLOADER /* Not for bootloader */ -#define HAVE_LCD_ENABLE +//#define HAVE_LCD_ENABLE #define HAVE_BACKLIGHT_BRIGHTNESS @@ -92,6 +92,9 @@ #ifndef SIMULATOR +/* define this if the backlight thread is used for fade, not for sim */ +#define USE_BACKLIGHT_THREAD_FADING + /* The LCD on a Gigabeat is 240x320 - it is portrait */ #define HAVE_PORTRAIT_LCD Index: firmware/backlight-thread-fading.c =================================================================== --- firmware/backlight-thread-fading.c (Revision 0) +++ firmware/backlight-thread-fading.c (Revision 0) @@ -0,0 +1,71 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Thomas Martitz + * Copyright (C) 2008 by Martin Ritter + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include "backlight-target.h" +#include "config.h" +#include "lcd.h" +#include "backlight.h" + +/* To adapt a target do: + * - export the backlight_brightness (which is the brightness you've set in the + * settings) from the backlight driver + * - create and export a function named _backlight_set_brightness_fader, + * which should do exactly the same as _backlight_set_brightness, EXCEPT + * changing the backlight_brightness var and make sure + * - make sure _backlight_set_brightness changes backlight_brightness + * - #define USE_BACKLIGHT_THREAD_FADING in config-.h + */ + + +static unsigned short current_brightness = DEFAULT_BRIGHTNESS_SETTING; + +void _backlight_thread_fade_init(void) +{ + current_brightness = backlight_brightness; +} + +/* returns true if fade is finished */ +bool _backlight_fade_up(void) +{ + if (current_brightness < backlight_brightness) + { + _backlight_set_brightness_fader(++current_brightness); + } + return (current_brightness >= backlight_brightness); +} + +/* returns true if fade is finished */ +bool _backlight_fade_down(void) +{ + if (current_brightness > 1) + { + _backlight_set_brightness_fader(--current_brightness); + return false; + } + else + { + /* backlight of at the end of the down fading */ + _backlight_off(); + return true; + } +} Index: firmware/backlight.c =================================================================== --- firmware/backlight.c (Revision 19102) +++ firmware/backlight.c (Arbeitskopie) @@ -8,7 +8,8 @@ * $Id$ * * Copyright (C) 2002 by Linus Nielsen Feltzing - * + * Additional work by Martin Ritter (2008) - backlight thread fading + * * 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 @@ -46,6 +47,10 @@ #define BACKLIGHT_FULL_INIT #endif +#ifdef USE_BACKLIGHT_THREAD_FADING +#include "backlight-thread-fading.h" +#endif + #ifdef SIMULATOR /* TODO: find a better way to do it but we need a kernel thread somewhere to handle this */ @@ -114,6 +119,9 @@ #ifdef BACKLIGHT_DRIVER_CLOSE BACKLIGHT_QUIT, #endif +#ifdef USE_BACKLIGHT_THREAD_FADING + BACKLIGHT_FADE, +#endif }; static void backlight_thread(void); @@ -397,6 +405,39 @@ } #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */ +#ifdef USE_BACKLIGHT_THREAD_FADING +static enum { + NOT_FADING = 0, + FADING_UP, + FADING_DOWN, +} backlight_fading_state = NOT_FADING; + +static unsigned int backlight_fade_counter = 0; + +static void backlight_send_fade_up(void) +{ + if (backlight_fading_state == NOT_FADING) + { + /* reactivate display before fading if necessary */ +#ifdef HAVE_LCD_ENABLE + lcd_enable(true); /* power on lcd, this takes some time */ +#endif +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); /* stop counter */ +#endif + backlight_fade_counter = 0; + } + backlight_fading_state = FADING_UP; +} + +static void backlight_send_fade_down(void) +{ + if (backlight_fading_state == NOT_FADING) + backlight_fade_counter = 0; + backlight_fading_state = FADING_DOWN; +} +#endif /* USE_BACKLIGHT_THREAD_FADING */ + /* Update state of backlight according to timeout setting */ static void backlight_update_state(void) { @@ -427,12 +468,20 @@ if (backlight_timeout < 0) { backlight_timer = 0; /* Disable the timeout */ +#ifdef USE_BACKLIGHT_THREAD_FADING + backlight_send_fade_down(); +#else _backlight_off(); +#endif } else { backlight_timer = backlight_timeout; +#ifdef USE_BACKLIGHT_THREAD_FADING + backlight_send_fade_up(); +#else _backlight_on(); +#endif } } @@ -558,9 +607,25 @@ case BACKLIGHT_OFF: backlight_timer = 0; /* Disable the timeout */ +#ifndef USE_BACKLIGHT_THREAD_FADING _backlight_off(); break; - +#else /* USE_BACKLIGHT_THREAD_FADING */ + backlight_send_fade_down(); + break; + case BACKLIGHT_FADE: + if (backlight_fading_state == FADING_UP) + { + if (_backlight_fade_up()) + backlight_fading_state = NOT_FADING; + } + else if (backlight_fading_state == FADING_DOWN) + { + if (_backlight_fade_down()) + backlight_fading_state = NOT_FADING; + } + break; +#endif /* !USE_BACKLIGHT_THREAD_FADING */ #ifdef HAVE_LCD_SLEEP case LCD_SLEEP: lcd_sleep(); @@ -614,7 +679,11 @@ } } #endif /* HAVE_LCD_SLEEP */ - +#ifdef USE_BACKLIGHT_THREAD_FADING + if (backlight_fading_state && (++backlight_fade_counter % + (HZ/20) == 0)) + queue_post(&backlight_queue, BACKLIGHT_FADE, 0); +#endif /* USE_BACKLIGHT_THREAD_FADING */ #ifdef HAVE_REMOTE_LCD if(remote_backlight_timer) { @@ -640,7 +709,6 @@ void backlight_init(void) { queue_init(&backlight_queue, true); - #ifndef SIMULATOR if (_backlight_init()) { @@ -832,6 +900,9 @@ val = MAX_BRIGHTNESS_SETTING; _backlight_set_brightness(val); +#ifdef USE_BACKLIGHT_THREAD_FADING + _backlight_thread_fade_init(); +#endif } #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (Revision 19102) +++ firmware/SOURCES (Arbeitskopie) @@ -96,6 +96,10 @@ #endif /* LCD_REMOTE_DEPTH */ #endif /* HAVE_REMOTE_LCD */ +#ifdef USE_BACKLIGHT_THREAD_FADING +backlight-thread-fading.c +#endif /* USE_BACKLIGHT_THREAD_FADING */ + /* Misc. */ drivers/led.c drivers/button.c Index: firmware/target/arm/sandisk/backlight-c200_e200.c =================================================================== --- firmware/target/arm/sandisk/backlight-c200_e200.c (Revision 19102) +++ firmware/target/arm/sandisk/backlight-c200_e200.c (Arbeitskopie) @@ -26,18 +26,26 @@ #include "ascodec.h" #include "as3514.h" -static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +#ifndef USE_BACKLIGHT_THREAD_FADING +static +#endif /* !USE_BACKLIGHT_THREAD_FADING */ + unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; void _backlight_set_brightness(int brightness) { backlight_brightness = brightness; - if (brightness > 0) _backlight_on(); else _backlight_off(); } +#ifdef USE_BACKLIGHT_THREAD_FADING + void _backlight_set_brightness_fader(int brightness) +{ + ascodec_write(AS3514_DCDC15, brightness); +} +#endif /* !USE_BACKLIGHT_THREAD_FADING */ void _backlight_on(void) { #ifdef HAVE_LCD_SLEEP Index: firmware/target/arm/sandisk/backlight-target.h =================================================================== --- firmware/target/arm/sandisk/backlight-target.h (Revision 19102) +++ firmware/target/arm/sandisk/backlight-target.h (Arbeitskopie) @@ -21,12 +21,17 @@ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#include "config.h" #define _backlight_init() true void _backlight_on(void); void _backlight_off(void); void _backlight_set_brightness(int brightness); -int __backlight_is_on(void); +#ifdef USE_BACKLIGHT_THREAD_FADING +extern unsigned short backlight_brightness; +inline void _backlight_set_brightness_fader(int brightness); +#endif /* USE_BACKLIGHT_THREAD_FADING */ + void _buttonlight_on(void); void _buttonlight_off(void); -#endif +#endif /* BACKLIGHT_TARGET_H */ Index: firmware/target/arm/imx31/gigabeat-s/backlight-target.h =================================================================== --- firmware/target/arm/imx31/gigabeat-s/backlight-target.h (Revision 19102) +++ firmware/target/arm/imx31/gigabeat-s/backlight-target.h (Arbeitskopie) @@ -21,15 +21,21 @@ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#include "stdbool.h" +#include "config.h" #ifdef BOOTLOADER + #define BACKLIGHT_DRIVER_CLOSE /* Force the whole driver to be built */ #define BACKLIGHT_FULL_INIT #endif - bool _backlight_init(void); void _backlight_on(void); void _backlight_off(void); void _backlight_set_brightness(int brightness); +#ifdef USE_BACKLIGHT_THREAD_FADING +extern unsigned short backlight_brightness; +void _backlight_set_brightness_fader(int brightness); +#endif /* USE_BACKLIGHT_THREAD_FADING */ #endif /* BACKLIGHT_TARGET_H */ Index: firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c =================================================================== --- firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c (Revision 19102) +++ firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c (Arbeitskopie) @@ -29,6 +29,12 @@ * as many uniquely-visible brightness levels as possible. The lowest current * level for any average current is used even though many combinations give * duplicate values. Current (I) values are in mA. */ + +#ifndef USE_BACKLIGHT_THREAD_FADING +static +#endif /* !USE_BACKLIGHT_THREAD_FADING */ + unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +static bool _is_backlight_on = false; static const struct { unsigned char md; @@ -69,8 +75,11 @@ { mc13783_write(MC13783_LED_CONTROL0, MC13783_LEDEN | +/* disable hw backlight fading, it apparently only fades up anyway */ +#ifndef USE_BACKLIGHT_THREAD_FADING MC13783_LEDMDRAMPUP | MC13783_LEDMDRAMPDOWN | +#endif /* !USE_BACKLIGHT_THREAD_FADING */ MC13783_BOOSTEN | MC13783_ABMODE_MONCH_LEDMD1234 | MC13783_ABREF_400MV); @@ -81,22 +90,30 @@ { /* LEDEN=1 */ mc13783_set(MC13783_LED_CONTROL0, MC13783_LEDEN); + _is_backlight_on = true; } void _backlight_off(void) { /* LEDEN=0 */ mc13783_clear(MC13783_LED_CONTROL0, MC13783_LEDEN); + _is_backlight_on = false; } #ifdef HAVE_BACKLIGHT_BRIGHTNESS /* Assumes that the backlight has been initialized */ -void _backlight_set_brightness(int brightness) + +#ifndef USE_BACKLIGHT_THREAD_FADING +static inline +#endif /* !USE_BACKLIGHT_THREAD_FADING */ + void _backlight_set_brightness_fader(int brightness) { + if (brightness > 0 && !_is_backlight_on) + _backlight_on(); uint32_t data, md, pwm; if ((unsigned)brightness >= ARRAYLEN(led_md_pwm_table)) - brightness = DEFAULT_BRIGHTNESS_SETTING; + brightness = MAX_BRIGHTNESS_SETTING; data = mc13783_read(MC13783_LED_CONTROL2); @@ -110,5 +127,14 @@ data |= MC13783_LEDMDw(md) | MC13783_LEDMDDCw(pwm); mc13783_write(MC13783_LED_CONTROL2, data); + if (brightness <= 0 && _is_backlight_on) + _backlight_off(); } + +void _backlight_set_brightness(int brightness) +{ + backlight_brightness = brightness; + _backlight_set_brightness_fader(brightness); +} + #endif /* HAVE_BACKLIGHT_BRIGHTNESS */