From 009cebeab263085d142c413386f1fc7760792b6d Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 14 May 2008 19:29:25 +0000 Subject: Straigten-out lcd sleeping on Gigabeat F/X. Add a service function to backlight.c to handle lcd sleep timer. Make HAVE_LCD_SLEEP useable without a setting and use HAVE_LCD_SLEEP_SETTING when a setting is available in addition to HCD_HAVE_SLEEP. If a setting isn't used, the target must define the timeout to be used in the config. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17505 a1c6a512-1295-4272-9138-f99709370657 --- apps/menus/display_menu.c | 4 +- apps/settings.c | 2 +- apps/settings.h | 2 +- apps/settings_list.c | 4 +- firmware/backlight.c | 62 +++++++++++++++------- firmware/export/backlight.h | 8 ++- firmware/export/config-c200.h | 1 + firmware/export/config-e200.h | 1 + firmware/export/config-gigabeat.h | 7 +++ firmware/export/config-h10.h | 1 + firmware/export/config-iaudiox5.h | 1 + firmware/export/config-mrobe100.h | 1 + firmware/target/arm/iriver/h10/backlight-h10.c | 19 +++---- .../arm/s3c2440/gigabeat-fx/backlight-meg-fx.c | 16 +++--- .../target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c | 38 ++++++++++--- firmware/target/arm/sandisk/backlight-c200_e200.c | 21 +++----- 16 files changed, 118 insertions(+), 70 deletions(-) diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c index 57d2f72be5..5ba8c2ecb1 100644 --- a/apps/menus/display_menu.c +++ b/apps/menus/display_menu.c @@ -94,7 +94,7 @@ MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL); MENUITEM_SETTING(bl_filter_first_keypress, &global_settings.bl_filter_first_keypress, filterfirstkeypress_callback); -#ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING MENUITEM_SETTING(lcd_sleep_after_backlight_off, &global_settings.lcd_sleep_after_backlight_off, NULL); #endif @@ -130,7 +130,7 @@ MAKE_MENU(lcd_settings,ID2P(LANG_LCD_MENU), ,&backlight_fade_in, &backlight_fade_out # endif ,&bl_filter_first_keypress -# ifdef HAVE_LCD_SLEEP +# ifdef HAVE_LCD_SLEEP_SETTING ,&lcd_sleep_after_backlight_off # endif # ifdef HAVE_BACKLIGHT_BRIGHTNESS diff --git a/apps/settings.c b/apps/settings.c index 9fb1f12d0d..1a857eacd8 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -924,7 +924,7 @@ void settings_apply(bool read_disk) #ifdef HAS_BUTTON_HOLD backlight_set_on_button_hold(global_settings.backlight_on_button_hold); #endif -#ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING lcd_set_sleep_after_backlight_off(global_settings.lcd_sleep_after_backlight_off); #endif #endif /* HAVE_BACKLIGHT */ diff --git a/apps/settings.h b/apps/settings.h index 4ade11b11d..9a9169a74f 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -646,7 +646,7 @@ struct user_settings int backlight_on_button_hold; /* what to do with backlight when hold switch is on */ #endif -#ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING int lcd_sleep_after_backlight_off; /* when to put lcd to sleep after backlight has turned off */ #endif diff --git a/apps/settings_list.c b/apps/settings_list.c index 2ef90afc94..a08639996c 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1126,7 +1126,7 @@ const struct settings_list settings[] = { ID2P(LANG_NORMAL), ID2P(LANG_OFF), ID2P(LANG_ON)), #endif -#ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING STRINGCHOICE_SETTING(0, lcd_sleep_after_backlight_off, LANG_LCD_SLEEP_AFTER_BACKLIGHT_OFF, 3, "lcd sleep after backlight off", @@ -1137,7 +1137,7 @@ const struct settings_list settings[] = { TALK_ID(20, UNIT_SEC), TALK_ID(30, UNIT_SEC), TALK_ID(45, UNIT_SEC),TALK_ID(60, UNIT_SEC), TALK_ID(90, UNIT_SEC)), -#endif +#endif /* HAVE_LCD_SLEEP_SETTING */ #endif /* HAVE_BACKLIGHT */ OFFON_SETTING(0, hold_lr_for_scroll_in_list, -1, true, diff --git a/firmware/backlight.c b/firmware/backlight.c index 74cdee1205..edd78ec7ef 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -184,14 +184,41 @@ static int remote_backlight_on_button_hold = 0; #endif /* HAVE_REMOTE_LCD */ #ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING const signed char lcd_sleep_timeout_value[10] = { -1, 0, 5, 10, 15, 20, 30, 45, 60, 90 }; -int _lcd_sleep_timer; -int _lcd_sleep_timeout = 10*HZ; +static int lcd_sleep_timeout = 10*HZ; +#else +/* Target defines needed value */ +static const int lcd_sleep_timeout = LCD_SLEEP_TIMEOUT; #endif +static int lcd_sleep_timer = 0; + +void backlight_lcd_sleep_countdown(bool start) +{ + if (!start) + { + /* Cancel the LCD sleep countdown */ + lcd_sleep_timer = 0; + return; + } + + /* 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 /* HAVE_LCD_SLEEP */ + #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) /* backlight fading */ #define BL_PWM_INTERVAL 5 /* Cycle interval in ms */ @@ -328,8 +355,9 @@ static void _backlight_on(void) bl_dim_fraction = (BL_PWM_COUNT<<16); _backlight_on_normal(); } + #ifdef HAVE_LCD_SLEEP - _lcd_sleep_timer = 0; /* LCD should be awake already */ + backlight_lcd_sleep(false); #endif } @@ -344,15 +372,9 @@ static void _backlight_off(void) bl_dim_target = bl_dim_fraction = 0; _backlight_off_normal(); } + #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; + backlight_start_lcd_sleep_counter(false); #endif } @@ -580,10 +602,10 @@ static void backlight_tick(void) } } #ifdef HAVE_LCD_SLEEP - else if(_lcd_sleep_timer) + else if(lcd_sleep_timer) { - _lcd_sleep_timer--; - if(_lcd_sleep_timer == 0) + lcd_sleep_timer--; + if(lcd_sleep_timer == 0) { /* Queue on bl thread or freeze! */ queue_post(&backlight_queue, LCD_SLEEP, 0); @@ -716,26 +738,26 @@ void backlight_set_on_button_hold(int index) } #endif /* HAS_BUTTON_HOLD */ -#ifdef HAVE_LCD_SLEEP +#ifdef HAVE_LCD_SLEEP_SETTING 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]; + 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 */ + if (lcd_sleep_timeout < 0) + lcd_sleep_timer = 1; /* Always - sleep next tick */ else - _lcd_sleep_timer = _lcd_sleep_timeout; /* Never, other */ + lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */ } -#endif /* HAVE_LCD_SLEEP */ +#endif /* HAVE_LCD_SLEEP_SETTING */ #ifdef HAVE_REMOTE_LCD void remote_backlight_on(void) diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 895328d98e..b09c98e7d2 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h @@ -45,8 +45,10 @@ void backlight_set_on_button_hold(int index); #endif #ifdef HAVE_LCD_SLEEP +void backlight_lcd_sleep_countdown(bool start); +#ifdef HAVE_LCD_SLEEP_SETTING void lcd_set_sleep_after_backlight_off(int index); -extern const signed char lcd_sleep_timeout_value[]; +#endif #endif #else /* !HAVE_BACKLIGHT */ @@ -89,9 +91,5 @@ void buttonlight_set_timeout(int value); #ifdef HAVE_BUTTON_LIGHT extern int _buttonlight_timeout; #endif -#ifdef HAVE_LCD_SLEEP -extern int _lcd_sleep_timer; -extern int _lcd_sleep_timeout; -#endif #endif /* BACKLIGHT_H */ diff --git a/firmware/export/config-c200.h b/firmware/export/config-c200.h index 9f3e78f611..81b79373e4 100644 --- a/firmware/export/config-c200.h +++ b/firmware/export/config-c200.h @@ -53,6 +53,7 @@ /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE should be defined as well. */ /* TODO: #define HAVE_LCD_SLEEP */ +/* TODO: #define HAVE_LCD_SLEEP_SETTING <= optional */ /* define this if you can flip your LCD */ #define HAVE_LCD_FLIP diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h index 8d42dd2618..58b736e27c 100644 --- a/firmware/export/config-e200.h +++ b/firmware/export/config-e200.h @@ -53,6 +53,7 @@ /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE should be defined as well. */ #define HAVE_LCD_SLEEP +#define HAVE_LCD_SLEEP_SETTING /* define this if you can flip your LCD */ #define HAVE_LCD_FLIP diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h index a100a6a724..816796b706 100644 --- a/firmware/export/config-gigabeat.h +++ b/firmware/export/config-gigabeat.h @@ -41,6 +41,13 @@ /* Define this if your LCD can be enabled/disabled */ #define HAVE_LCD_ENABLE +/* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE + should be defined as well. */ +#define HAVE_LCD_SLEEP +/* We don't use a setting but a fixed delay after the backlight has + * turned off */ +#define LCD_SLEEP_TIMEOUT (5*HZ) + #define CONFIG_KEYPAD GIGABEAT_PAD /* Define this if you do software codec */ diff --git a/firmware/export/config-h10.h b/firmware/export/config-h10.h index f46eb76b5a..7e64494061 100644 --- a/firmware/export/config-h10.h +++ b/firmware/export/config-h10.h @@ -54,6 +54,7 @@ * should be defined as well. * We can currently put the lcd to sleep but it won't wake up properly */ #define HAVE_LCD_SLEEP +#define HAVE_LCD_SLEEP_SETTING /* define this if you can flip your LCD */ #define HAVE_LCD_FLIP diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index 370d4fcd9a..d0a107b28d 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h @@ -65,6 +65,7 @@ /* Define this if your LCD can be put to sleep. HAVE_LCD_ENABLE should be defined as well. */ #define HAVE_LCD_SLEEP +#define HAVE_LCD_SLEEP_SETTING #define CONFIG_KEYPAD IAUDIO_X5M5_PAD diff --git a/firmware/export/config-mrobe100.h b/firmware/export/config-mrobe100.h index dd8b170f9e..6aaa2b005a 100644 --- a/firmware/export/config-mrobe100.h +++ b/firmware/export/config-mrobe100.h @@ -126,6 +126,7 @@ * should be defined as well. * We can currently put the lcd to sleep but it won't wake up properly */ /*TODO: #define HAVE_LCD_SLEEP*/ +/*TODO: #define HAVE_LCD_SLEEP_SETTING <= optional */ /* We're able to shut off power to the HDD */ #define HAVE_ATA_POWER_OFF diff --git a/firmware/target/arm/iriver/h10/backlight-h10.c b/firmware/target/arm/iriver/h10/backlight-h10.c index 8033aebf71..5d211d26bf 100644 --- a/firmware/target/arm/iriver/h10/backlight-h10.c +++ b/firmware/target/arm/iriver/h10/backlight-h10.c @@ -25,8 +25,10 @@ void _backlight_on(void) { #ifdef HAVE_LCD_SLEEP - lcd_enable(true); - _lcd_sleep_timer = 0; + backlight_lcd_sleep_countdown(false); /* stop counter */ +#endif +#ifdef HAVE_LCD_ENABLE + lcd_enable(true); /* power on lcd + visible display */ #endif GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x20); } @@ -34,15 +36,10 @@ void _backlight_on(void) void _backlight_off(void) { GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x20); +#ifdef HAVE_LCD_ENABLE + lcd_enable(false); /* power off visible display */ +#endif #ifdef HAVE_LCD_SLEEP - lcd_enable(false); - /* Start LCD sleep countdown */ - if (_lcd_sleep_timeout < 0) - { - _lcd_sleep_timer = 0; /* Setting == Always */ - lcd_sleep(); - } - else - _lcd_sleep_timer = _lcd_sleep_timeout; + backlight_lcd_sleep_countdown(true); /* start countdown */ #endif } diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/backlight-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/backlight-meg-fx.c index 076c06b0d8..4fb66549cc 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/backlight-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/backlight-meg-fx.c @@ -314,11 +314,6 @@ static void led_control_service(void) sc606_control=SC606_CONTROL_IDLE; break; } - - if(sc606regCONFval&0x03) - lcd_enable(true); - else - lcd_enable(false); } #endif /* BOOTLOADER */ @@ -340,13 +335,22 @@ static void __backlight_dim(bool dim_now) void _backlight_on(void) { - lcd_enable(true); +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); /* stop counter */ +#endif +#ifdef HAVE_LCD_ENABLE + lcd_enable(true); /* power on lcd + visible display */ +#endif __backlight_dim(false); } void _backlight_off(void) { __backlight_dim(true); +#ifdef HAVE_LCD_SLEEP + /* Disable lcd after fade completes (when lcd_sleep timeout expires) */ + backlight_lcd_sleep_countdown(true); /* start countdown */ +#endif } static inline void __buttonlight_on(void) diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c index 37ac903418..5c268f42b8 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c @@ -26,7 +26,8 @@ #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)]) -static volatile bool lcd_on = true; +static bool lcd_on = true; +static bool lcd_powered = true; static unsigned lcd_yuv_options = 0; /* ** This is imported from lcd-16bit.c @@ -174,6 +175,8 @@ void LCD_SPI_powerdown(void) 0,0x04,1,0x00 }; + lcd_powered = false; + LCD_SPI_start(); LCD_SPI_send(powerdncmd, sizeof(powerdncmd)); @@ -198,6 +201,8 @@ void LCD_SPI_powerup(void) LCD_SPI_send(powerupcmd, sizeof(powerupcmd)); LCD_SPI_stop(); + + lcd_powered = true; } void LCD_SPI_init(void) @@ -266,23 +271,40 @@ void lcd_init_device(void) LCD_SPI_init(); } +void lcd_sleep(void) +{ + if (lcd_powered) + { + /* "not powered" implies "disabled" */ + if (lcd_on) + lcd_enable(false); + + LCD_SPI_powerdown(); + } +} + void lcd_enable(bool state) { + if (state == lcd_on) + return; + if(state) { - if(!lcd_on) + /* "enabled" implies "powered" */ + if (!lcd_powered) { - lcd_on = true; - lcd_update(); LCD_SPI_powerup(); + /* Wait long enough for a frame to be written - yes, it + * takes awhile. */ + sleep(HZ/5); } + + lcd_on = true; + lcd_update(); } else { - if(lcd_on) { - lcd_on = false; - LCD_SPI_powerdown(); - } + lcd_on = false; } } diff --git a/firmware/target/arm/sandisk/backlight-c200_e200.c b/firmware/target/arm/sandisk/backlight-c200_e200.c index 016751121e..aaec8cf007 100644 --- a/firmware/target/arm/sandisk/backlight-c200_e200.c +++ b/firmware/target/arm/sandisk/backlight-c200_e200.c @@ -38,11 +38,11 @@ void _backlight_set_brightness(int brightness) void _backlight_on(void) { -#ifdef HAVE_LCD_ENABLE - lcd_enable(true); /* power on lcd */ +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); /* stop counter */ #endif -#if defined(HAVE_LCD_SLEEP) && !defined(BOOTLOADER) - _lcd_sleep_timer = 0; /* LCD should be awake already */ +#ifdef HAVE_LCD_ENABLE + lcd_enable(true); /* power on lcd + visible display */ #endif pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, backlight_brightness); } @@ -51,17 +51,10 @@ void _backlight_off(void) { pp_i2c_send(AS3514_I2C_ADDR, AS3514_DCDC15, 0x0); #ifdef HAVE_LCD_ENABLE - lcd_enable(false); /* power off lcd */ + lcd_enable(false); /* power off visible display */ #endif -#if defined(HAVE_LCD_SLEEP) && !defined(BOOTLOADER) - /* Start LCD sleep countdown */ - if (_lcd_sleep_timeout < 0) - { - _lcd_sleep_timer = 0; /* Setting == Always */ - lcd_sleep(); - } - else - _lcd_sleep_timer = _lcd_sleep_timeout; +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(true); /* start countdown */ #endif } -- cgit v1.2.3