From cc839a26711069399ec86cdb63b2d246fa3395d2 Mon Sep 17 00:00:00 2001 From: Rani Hod Date: Mon, 31 Jul 2006 19:13:21 +0000 Subject: [PATCH] Applied FS#5734 by Michael Sevakis (X5 LCD contrast bugfix and some #define fixup). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10388 a1c6a512-1295-4272-9138-f99709370657 --- apps/settings.c | 10 +++++----- apps/settings.h | 15 +++++++++++---- apps/settings_menu.c | 6 +++--- firmware/export/config-iaudiox5.h | 5 +++++ firmware/powermgmt.c | 2 ++ firmware/target/coldfire/iaudio/x5/lcd-x5.c | 15 +++++++++------ 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/apps/settings.c b/apps/settings.c index b6d84d53f7..673b8fe246 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -240,8 +240,8 @@ static const struct bit_entry rtc_bits[] = {32 | SIGNED, S_O(resume_seed), -1, NULL, NULL }, {3, S_O(repeat_mode), REPEAT_ALL, "repeat", "off,all,one,shuffle,ab" }, /* LCD */ -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) - {6, S_O(contrast), 40, "contrast", NULL }, +#ifdef HAVE_LCD_CONTRAST + {6, S_O(contrast), DEFAULT_CONTRAST_SETTING, "contrast", NULL }, #endif #ifdef CONFIG_BACKLIGHT {5, S_O(backlight_timeout), 5, "backlight timeout", backlight_times_conf }, @@ -1017,7 +1017,7 @@ void settings_apply(void) audio_set_buffer_margin(global_settings.buffer_margin); -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST lcd_set_contrast(global_settings.contrast); #endif lcd_scroll_speed(global_settings.scroll_speed); @@ -1263,7 +1263,7 @@ void settings_load(int which) RTC_BLOCK_SIZE*8); } -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST if ( global_settings.contrast < MIN_CONTRAST_SETTING ) global_settings.contrast = lcd_default_contrast(); #endif @@ -1728,7 +1728,7 @@ void settings_reset(void) { global_settings.mdb_enable = sound_default(SOUND_MDB_ENABLE); global_settings.superbass = sound_default(SOUND_SUPERBASS); #endif -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST global_settings.contrast = lcd_default_contrast(); #endif #ifdef HAVE_LCD_REMOTE diff --git a/apps/settings.h b/apps/settings.h index d32b58ac85..983e58911d 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -200,6 +200,13 @@ extern unsigned char vp_dummy[VIRT_SIZE]; /* get the string ID from a virtual pointer, -1 if not virtual */ #define P2ID(p) ((p>=VIRT_PTR && p<=VIRT_PTR+VIRT_SIZE) ? p-VIRT_PTR : -1) +/* !defined(HAVE_LCD_COLOR) implies HAVE_LCD_CONTRAST with default 40. + Explicitly define HAVE_LCD_CONTRAST in config file for newer ports for + simplicity. */ +#if !defined(HAVE_LCD_COLOR) +#define HAVE_LCD_CONTRAST +#define DEFAULT_CONTRAST_SETTING 40 +#endif struct user_settings { @@ -274,7 +281,7 @@ struct user_settings /* device settings */ -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST int contrast; /* lcd contrast */ #endif bool invert; /* invert display */ @@ -571,10 +578,10 @@ extern long lasttime; extern const char rec_base_directory[]; /* system defines */ - #ifdef IAUDIO_X5 -#define MIN_CONTRAST_SETTING 0 -#define MAX_CONTRAST_SETTING 29 +#define MIN_CONTRAST_SETTING 1 +#define MAX_CONTRAST_SETTING 30 +#define DEFAULT_CONTRAST_SETTING 19 #elif defined HAVE_LCD_CHARCELLS #define MIN_CONTRAST_SETTING 5 #define MAX_CONTRAST_SETTING 31 diff --git a/apps/settings_menu.c b/apps/settings_menu.c index f088c3be3d..20235f5a72 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -266,7 +266,7 @@ static bool remote_caption_backlight(void) } #endif /* HAVE_REMOTE_LCD */ -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST static bool contrast(void) { return set_int( str(LANG_CONTRAST), "", UNIT_INT, @@ -274,7 +274,7 @@ static bool contrast(void) lcd_set_contrast, 1, MIN_CONTRAST_SETTING, MAX_CONTRAST_SETTING, NULL ); } -#endif /* HAVE_LCD_COLOR */ +#endif /* HAVE_LCD_CONTRAST */ #ifdef HAVE_LCD_BITMAP #ifndef HAVE_LCD_COLOR @@ -1781,7 +1781,7 @@ static bool lcd_settings_menu(void) { ID2P(LANG_BRIGHTNESS), brightness }, #endif #endif /* CONFIG_BACKLIGHT */ -#if !defined(HAVE_LCD_COLOR) || defined(IAUDIO_X5) +#ifdef HAVE_LCD_CONTRAST { ID2P(LANG_CONTRAST), contrast }, #endif #ifdef HAVE_LCD_BITMAP diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index 21fa636f0c..ae48eb6dbe 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h @@ -22,6 +22,7 @@ #define LCD_HEIGHT 128 #define LCD_DEPTH 16 /* pseudo 262.144 colors */ #define LCD_PIXELFORMAT RGB565 /* rgb565 */ +#define HAVE_LCD_CONTRAST /* remote LCD */ #define LCD_REMOTE_WIDTH 128 @@ -40,6 +41,10 @@ #define CONFIG_LCD LCD_X5 +#define MIN_CONTRAST_SETTING 1 +#define MAX_CONTRAST_SETTING 30 +#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ + /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled !?!? */ #define HAVE_BACKLIGHT_BRIGHTNESS diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index ee01fd862d..4bccd4e211 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -1045,7 +1045,9 @@ void shutdown_hw(void) lcd_update(); sleep(HZ/16); #endif +#ifndef IAUDIO_X5 lcd_set_contrast(0); +#endif #ifdef HAVE_REMOTE_LCD remote_backlight_off(); lcd_remote_set_contrast(0); diff --git a/firmware/target/coldfire/iaudio/x5/lcd-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-x5.c index 7c155eac8f..c06521ef54 100755 --- a/firmware/target/coldfire/iaudio/x5/lcd-x5.c +++ b/firmware/target/coldfire/iaudio/x5/lcd-x5.c @@ -139,17 +139,20 @@ inline void lcd_write_data(const unsigned short* p_bytes, int count) int lcd_default_contrast(void) { - return 16; + return DEFAULT_CONTRAST_SETTING; } void lcd_set_contrast(int val) { - if (val >= 15) // val must'nt be 15 or 31 - ++val; - if (val > 30) - return; + /* Clamp val in range 0-14, 16-30 */ + if (val < 1) + val = 0; + else if (val <= 15) + --val; + else if (val > 30) + val = 30; - lcd_write_reg(0x0e, 0x201e + (val << 8)); + lcd_write_reg(0x0e, 0x2018 + (val << 8)); } void lcd_set_invert_display(bool yesno)