Index: firmware/export/config-c200.h =================================================================== --- firmware/export/config-c200.h (Revision 18663) +++ 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 18663) +++ 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/config-gigabeat-s.h =================================================================== --- firmware/export/config-gigabeat-s.h (Revision 18663) +++ firmware/export/config-gigabeat-s.h (Arbeitskopie) @@ -73,10 +73,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.c =================================================================== --- firmware/backlight.c (Revision 18663) +++ firmware/backlight.c (Arbeitskopie) @@ -114,6 +114,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 +400,38 @@ } #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_on(void) +{ +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); +#endif + if (backlight_fading_state == NOT_FADING) + { +#ifdef HAVE_LCD_ENABLE + lcd_enable(true); /* power on lcd, this takes some time */ +#endif + backlight_fade_counter = 0; + } + backlight_fading_state = FADING_UP; +} + +static void _backlight_off(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) { @@ -560,7 +595,20 @@ backlight_timer = 0; /* Disable the timeout */ _backlight_off(); 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 +662,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) { Index: firmware/target/arm/sandisk/backlight-c200_e200.c =================================================================== --- firmware/target/arm/sandisk/backlight-c200_e200.c (Revision 18663) +++ firmware/target/arm/sandisk/backlight-c200_e200.c (Arbeitskopie) @@ -27,17 +27,9 @@ #include "as3514.h" static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +static unsigned short current_brightness = DEFAULT_BRIGHTNESS_SETTING; +static void _backlight_set_brightness_helper(int brightness); -void _backlight_set_brightness(int brightness) -{ - backlight_brightness = brightness; - - if (brightness > 0) - _backlight_on(); - else - _backlight_off(); -} - void _backlight_on(void) { #ifdef HAVE_LCD_SLEEP @@ -46,12 +38,14 @@ #ifdef HAVE_LCD_ENABLE lcd_enable(true); /* power on lcd + visible display */ #endif - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, backlight_brightness); + current_brightness = backlight_brightness; + _backlight_set_brightness_helper(current_brightness); } void _backlight_off(void) { - pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, 0x0); + current_brightness = 0; + _backlight_set_brightness_helper(current_brightness); #ifdef HAVE_LCD_ENABLE lcd_enable(false); /* power off visible display */ #endif @@ -60,6 +54,17 @@ #endif } +void _backlight_set_brightness(int brightness) +{ + backlight_brightness = brightness; + current_brightness = brightness; + + if (brightness > 0) + _backlight_on(); + else + _backlight_off(); +} + void _buttonlight_on(void) { GPIO_SET_BITWISE(GPIOG_OUTPUT_VAL, 0x80); @@ -75,3 +80,34 @@ GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL, 0x10); /* The "menu" backlight */ #endif } + +static void _backlight_set_brightness_helper(int brightness) +{ + pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, brightness); +} + +/* returns true if fade is finished */ +bool _backlight_fade_up(void) +{ + if (current_brightness < backlight_brightness) + { + _backlight_set_brightness_helper(++current_brightness); + } + return current_brightness >= backlight_brightness; +} + +bool _backlight_fade_down(void) +{ + current_brightness -= 1; + if (current_brightness > 0) + { + _backlight_set_brightness_helper(current_brightness); + } + else + { + /* _backlight_off() sets brightness to 0 */ + _backlight_off(); + return true; + } + return false; +} Index: firmware/target/arm/sandisk/backlight-target.h =================================================================== --- firmware/target/arm/sandisk/backlight-target.h (Revision 18663) +++ firmware/target/arm/sandisk/backlight-target.h (Arbeitskopie) @@ -20,13 +20,22 @@ ****************************************************************************/ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#include "stdbool.h" #define _backlight_init() true + +#ifndef HAVE_BACKLIGHT_THREAD_FADING void _backlight_on(void); void _backlight_off(void); +#else +/* these both return true if the fade is finished */ +bool _backlight_fade_up(void); +bool _backlight_fade_down(void); +#endif void _backlight_set_brightness(int brightness); int __backlight_is_on(void); + void _buttonlight_on(void); void _buttonlight_off(void); #endif Index: firmware/target/arm/imx31/gigabeat-s/backlight-target.h =================================================================== --- firmware/target/arm/imx31/gigabeat-s/backlight-target.h (Revision 18663) +++ firmware/target/arm/imx31/gigabeat-s/backlight-target.h (Arbeitskopie) @@ -21,6 +21,8 @@ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#include "stdbool.h" + #ifdef BOOTLOADER #define BACKLIGHT_DRIVER_CLOSE /* Force the whole driver to be built */ @@ -28,8 +30,14 @@ #endif bool _backlight_init(void); +#ifndef HAVE_BACKLIGHT_THREAD_FADING void _backlight_on(void); void _backlight_off(void); +#else +/* these both return true if the fade is finished */ +bool _backlight_fade_up(void); +bool _backlight_fade_down(void); +#endif void _backlight_set_brightness(int brightness); #endif /* BACKLIGHT_TARGET_H */ Index: firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c =================================================================== --- firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c (Revision 18663) +++ firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c (Arbeitskopie) @@ -20,11 +20,16 @@ ****************************************************************************/ #include "config.h" #include "system.h" +#include "lcd.h" #include "backlight.h" #include "mc13783.h" #include "backlight-target.h" #ifdef HAVE_BACKLIGHT_BRIGHTNESS +static unsigned short backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; +static unsigned short current_brightness = DEFAULT_BRIGHTNESS_SETTING; +static bool backlight_is_on = false; +static void _backlight_set_brightness_helper(int brightness); /* Table that uses combinations of current level and pwm fraction to get * as many uniquely-visible brightness levels as possible. The lowest current * level for any average current is used even though many combinations give @@ -69,8 +74,11 @@ { mc13783_write(MC13783_LED_CONTROL0, MC13783_LEDEN | +/* disable hw backlight fading */ +#if 0 MC13783_LEDMDRAMPUP | MC13783_LEDMDRAMPDOWN | +#endif MC13783_BOOSTEN | MC13783_ABMODE_MONCH_LEDMD1234 | MC13783_ABREF_400MV); @@ -79,22 +87,80 @@ void _backlight_on(void) { +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); /* stop counter */ +#endif +#ifef HAVE_LCD_ENABLE + lcd_enable(true) +#endif /* LEDEN=1 */ mc13783_set(MC13783_LED_CONTROL0, MC13783_LEDEN); + backlight_is_on = true; } void _backlight_off(void) { /* LEDEN=0 */ mc13783_clear(MC13783_LED_CONTROL0, MC13783_LEDEN); + backlight_is_on = false; + current_brightness = 0; +#ifef HAVE_LCD_ENABLE + lcd_enable(true) +#endif +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(true); /* start countdown */ +#endif } +/* returns true if fade is finished */ +bool _backlight_fade_up(void) +{ + if (!backlight_is_on) + _backlight_on(); + if (current_brightness < backlight_brightness) + { + _backlight_set_brightness_helper(++current_brightness); + } + return (current_brightness >= backlight_brightness); +} + +bool _backlight_fade_down(void) +{ + if (current_brightness > 0) + { + _backlight_set_brightness_helper(--current_brightness); + } + if (current_brightness == 0) + { + _backlight_off(); + return true; + } + return false; +} + + #ifdef HAVE_BACKLIGHT_BRIGHTNESS /* Assumes that the backlight has been initialized */ + void _backlight_set_brightness(int brightness) { + current_brightness = brightness; + backlight_brightness = brightness; + + /* e200/c200 don't need this */ + _backlight_set_brightness_helper(brightness); + + if (brightness > 0) + _backlight_on(); + else + _backlight_off(); +} + +static void _backlight_set_brightness_helper(int brightness) +{ uint32_t data, md, pwm; + /* invalid brightness, restore default */ if ((unsigned)brightness >= ARRAYLEN(led_md_pwm_table)) brightness = DEFAULT_BRIGHTNESS_SETTING;