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) @@ -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/backlight-thread-fading.h =================================================================== --- firmware/export/backlight-thread-fading.h (Revision 0) +++ firmware/export/backlight-thread-fading.h (Revision 0) @@ -0,0 +1,58 @@ +/*************************************************************************** + * __________ __ ___. + * 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_ + +#define _BACKLIGHT_THREAD_FADING_ + +bool _backlight_fade_up(void); +bool _backlight_fade_down(void); +void _backlight_thread_fade_init(void); +#endif /* _BACKLIGHT_THREAD_FADING_ */ +/*************************************************************************** + * __________ __ ___. + * 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 + +bool _backlight_fade_up(void); +bool _backlight_fade_down(void); +void _backlight_thread_fade_init(void); +#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,10 +77,11 @@ #ifndef BOOTLOADER /* Not for bootloader */ -#define HAVE_LCD_ENABLE +//#define HAVE_LCD_ENABLE #define HAVE_BACKLIGHT_BRIGHTNESS +#define HAVE_BACKLIGHT_THREAD_FADING /* Main LCD backlight brightness range and defaults */ #define MIN_BRIGHTNESS_SETTING 0 #define MAX_BRIGHTNESS_SETTING 24 Index: firmware/backlight-thread-fading.c =================================================================== --- firmware/backlight-thread-fading.c (Revision 0) +++ firmware/backlight-thread-fading.c (Revision 0) @@ -0,0 +1,58 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 Thomas Martitz + * + * 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" + +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_off(); + return true; + } +} Index: firmware/backlight.c =================================================================== --- firmware/backlight.c (Revision 19102) +++ firmware/backlight.c (Arbeitskopie) @@ -33,7 +33,7 @@ #include "timer.h" #include "backlight.h" #include "lcd.h" - +#include "panic.h" #ifdef HAVE_REMOTE_LCD #include "lcd-remote.h" #endif @@ -46,6 +46,10 @@ #define BACKLIGHT_FULL_INIT #endif +#ifdef HAVE_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 +118,9 @@ #ifdef BACKLIGHT_DRIVER_CLOSE BACKLIGHT_QUIT, #endif +#if defined(HAVE_BACKLIGHT_THREAD_FADING) && !defined(SIMULATOR) + BACKLIGHT_FADE, +#endif }; static void backlight_thread(void); @@ -397,6 +404,39 @@ } #endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */ +#if defined(HAVE_BACKLIGHT_THREAD_FADING) && !defined(SIMULATOR) +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) + { + +#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 + /* Update state of backlight according to timeout setting */ static void backlight_update_state(void) { @@ -427,12 +467,20 @@ if (backlight_timeout < 0) { backlight_timer = 0; /* Disable the timeout */ +#ifdef HAVE_BACKLIGHT_THREAD_FADING + backlight_send_fade_down(); +#else _backlight_off(); +#endif } else { backlight_timer = backlight_timeout; +#ifdef HAVE_BACKLIGHT_THREAD_FADING + backlight_send_fade_up(); +#else _backlight_on(); +#endif } } @@ -558,9 +606,26 @@ case BACKLIGHT_OFF: backlight_timer = 0; /* Disable the timeout */ +#ifdef HAVE_BACKLIGHT_THREAD_FADING + backlight_send_fade_down(); +#else _backlight_off(); +#endif break; - +#if defined(HAVE_BACKLIGHT_THREAD_FADING) && !defined(SIMULATOR) + 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 /* defined(HAVE_BACKLIGHT_THREAD_FADING) && !defined(SIMULATOR) */ #ifdef HAVE_LCD_SLEEP case LCD_SLEEP: lcd_sleep(); @@ -614,7 +679,11 @@ } } #endif /* HAVE_LCD_SLEEP */ - +#if defined(HAVE_BACKLIGHT_THREAD_FADING) && !defined(SIMULATOR) + if (backlight_fading_state && (++backlight_fade_counter % + (HZ/25) == 0)) + queue_post(&backlight_queue, BACKLIGHT_FADE, 0); +#endif #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 HAVE_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,9 @@ #endif /* LCD_REMOTE_DEPTH */ #endif /* HAVE_REMOTE_LCD */ +#ifdef HAVE_BACKLIGHT_THREAD_FADING +backlight-thread-fading.c +#endif /* HAVE_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,28 @@ #include "ascodec.h" #include "as3514.h" -static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +#ifndef HAVE_BACKLIGHT_THREAD_FADING +static +#endif + unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; void _backlight_set_brightness(int brightness) { backlight_brightness = brightness; - if (brightness > 0) _backlight_on(); else _backlight_off(); } +#ifndef HAVE_BACKLIGHT_THREAD_FADING +static +#endif + inline void _backlight_set_brightness_fader(int brightness) +{ + ascodec_write(AS3514_DCDC15, brightness); +} + 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 HAVE_BACKLIGHT_THREAD_FADING +extern unsigned short backlight_brightness; +inline void _backlight_set_brightness_fader(int brightness); +#endif /* HAVE_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 HAVE_BACKLIGHT_THREAD_FADING +extern unsigned short backlight_brightness; +void _backlight_set_brightness_fader(int brightness); +#endif /* HAVE_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 HAVE_BACKLIGHT_THREAD_FADING +static +#endif + 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 */ +#ifdef HAVE_BACKLIGHT_THREAD_FADING MC13783_LEDMDRAMPUP | MC13783_LEDMDRAMPDOWN | +#endif MC13783_BOOSTEN | MC13783_ABMODE_MONCH_LEDMD1234 | MC13783_ABREF_400MV); @@ -81,18 +90,32 @@ { /* 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; } +void _backlight_set_brightness(int brightness) +{ + backlight_brightness = brightness; + _backlight_set_brightness_fader(brightness); +} + #ifdef HAVE_BACKLIGHT_BRIGHTNESS /* Assumes that the backlight has been initialized */ -void _backlight_set_brightness(int brightness) + +#ifndef HAVE_BACKLIGHT_THREAD_FADING +static inline +#endif + void _backlight_set_brightness_fader(int brightness) { + if (brightness && !_is_backlight_on) + _backlight_on(); uint32_t data, md, pwm; if ((unsigned)brightness >= ARRAYLEN(led_md_pwm_table)) @@ -110,5 +133,7 @@ data |= MC13783_LEDMDw(md) | MC13783_LEDMDDCw(pwm); mc13783_write(MC13783_LED_CONTROL2, data); + if (!brightness && _is_backlight_on) + _backlight_off(); } #endif /* HAVE_BACKLIGHT_BRIGHTNESS */