diff options
| author | Thom Johansen <thomj@rockbox.org> | 2006-03-19 17:42:58 +0000 |
|---|---|---|
| committer | Thom Johansen <thomj@rockbox.org> | 2006-03-19 17:42:58 +0000 |
| commit | 3c7278f405acd1dce7393cd589fbe002f51bad3b (patch) | |
| tree | 027b12d8f8c10af9d6bdd9f6dc31e3413c175a5c | |
| parent | ea4ccb5abab7f3a775b0c1fee1a50a8840b09d47 (diff) | |
| download | rockbox-3c7278f405acd1dce7393cd589fbe002f51bad3b.zip rockbox-3c7278f405acd1dce7393cd589fbe002f51bad3b.tar.gz rockbox-3c7278f405acd1dce7393cd589fbe002f51bad3b.tar.bz2 rockbox-3c7278f405acd1dce7393cd589fbe002f51bad3b.tar.xz | |
Reworked backlight fading by GPIO based PWM to work for other targets
than H1x0. iPod Nano and 5G backlight fading is enabled. To try for your
device, just define HAVE_BACKLIGHT_PWM_FADING in the relevant
config-xxxx.h file. NOTE: Will break your settings, so save a config
file first.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9121 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/settings.c | 6 | ||||
| -rw-r--r-- | apps/settings.h | 2 | ||||
| -rw-r--r-- | apps/settings_menu.c | 6 | ||||
| -rw-r--r-- | firmware/backlight.c | 197 | ||||
| -rw-r--r-- | firmware/export/backlight.h | 2 | ||||
| -rw-r--r-- | firmware/export/config-h100.h | 3 | ||||
| -rw-r--r-- | firmware/export/config-h120.h | 3 | ||||
| -rw-r--r-- | firmware/export/config-ipodnano.h | 3 | ||||
| -rw-r--r-- | firmware/export/config-ipodvideo.h | 3 |
9 files changed, 132 insertions, 93 deletions
diff --git a/apps/settings.c b/apps/settings.c index 6fedf66..7329b12 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -90,7 +90,7 @@ const char rec_base_directory[] = REC_BASE_DIR; #include "dsp.h" #endif -#define CONFIG_BLOCK_VERSION 37 +#define CONFIG_BLOCK_VERSION 38 #define CONFIG_BLOCK_SIZE 512 #define RTC_BLOCK_SIZE 44 @@ -436,7 +436,7 @@ static const struct bit_entry hd_bits[] = {4, S_O(rec_trigger_mode ), 0, "trigger mode", "off,once,repeat"}, #endif -#if CONFIG_BACKLIGHT == BL_IRIVER_H100 +#ifdef HAVE_BACKLIGHT_PWM_FADING /* backlight fading */ {2, S_O(backlight_fade_in), 1, "backlight fade in", "off,500ms,1s,2s"}, {3, S_O(backlight_fade_out), 3, "backlight fade out", @@ -997,7 +997,7 @@ void settings_apply(void) #ifdef HAVE_CHARGING backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); #endif -#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) backlight_set_fade_in(global_settings.backlight_fade_in); backlight_set_fade_out(global_settings.backlight_fade_out); #endif diff --git a/apps/settings.h b/apps/settings.h index 3d129ba..52e949e 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -271,7 +271,7 @@ struct user_settings 1=always, then according to timeout_values[] */ int backlight_timeout_plugged; -#if CONFIG_BACKLIGHT == BL_IRIVER_H100 +#ifdef HAVE_BACKLIGHT_PWM_FADING int backlight_fade_in; /* backlight fade in timing: 0..3 */ int backlight_fade_out; /* backlight fade in timing: 0..7 */ #endif diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 517c7f1..6e8d621 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -191,7 +191,7 @@ static bool backlight_timer(void) backlight_set_timeout ); } -#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) static bool backlight_fade_in(void) { static const struct opt_items names[] = { @@ -1087,7 +1087,7 @@ static bool custom_remote_wps_browse(void) return rockbox_browse(WPS_DIR, SHOW_RWPS); } #endif - + static bool custom_cfg_browse(void) { return rockbox_browse(ROCKBOX_DIR, SHOW_CFG); @@ -1614,7 +1614,7 @@ static bool lcd_settings_menu(void) { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), backlight_timer_plugged }, #endif { ID2P(LANG_CAPTION_BACKLIGHT), caption_backlight }, -#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) { ID2P(LANG_BACKLIGHT_FADE_IN), backlight_fade_in }, { ID2P(LANG_BACKLIGHT_FADE_OUT), backlight_fade_out }, #endif diff --git a/firmware/backlight.c b/firmware/backlight.c index 9d48f0d..9aace01 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -41,6 +41,88 @@ #include "lcd-remote.h" #endif +/* Basic low-level code that simply switches backlight on or off. Probably + * a nice candidate for inclusion in the target/ dir. */ +static inline void __backlight_on(void) +{ +#ifdef SIMULATOR + sim_backlight(100); +#elif CONFIG_BACKLIGHT == BL_IRIVER_H100 + and_l(~0x00020000, &GPIO1_OUT); +#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 + lcd_enable(true); + or_l(0x00020000, &GPIO1_OUT); +#elif CONFIG_BACKLIGHT == BL_RTC + /* Enable square wave */ + rtc_write(0x0a, rtc_read(0x0a) | 0x40); +#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ + and_b(~0x40, &PADRH); /* drive and set low */ + or_b(0x40, &PAIORH); +#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */ + or_b(0x40, &PADRH); /* drive it high */ +#elif CONFIG_BACKLIGHT == BL_GMINI + P1 |= 0x10; +#elif CONFIG_BACKLIGHT == BL_IPOD4G + /* brightness full */ + outl(0x80000000 | (0xff << 16), 0x7000a010); + + /* set port b bit 3 on */ + outl(((0x100 | 1) << 3), 0x6000d824); +#elif CONFIG_BACKLIGHT==BL_IPODMINI + /* set port B03 on */ + outl(((0x100 | 1) << 3), 0x6000d824); +#elif CONFIG_BACKLIGHT==BL_IPODNANO + /* set port B03 on */ + outl(((0x100 | 1) << 3), 0x6000d824); + + /* set port L07 on */ + outl(((0x100 | 1) << 7), 0x6000d12c); +#elif CONFIG_BACKLIGHT==BL_IPOD3G + lcd_enable(true); +#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX + GPIO3_SET = 1; +#endif +} + +static inline void __backlight_off(void) +{ +#ifdef SIMULATOR + sim_backlight(0); +#elif CONFIG_BACKLIGHT == BL_IRIVER_H100 + or_l(0x00020000, &GPIO1_OUT); +#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 + and_l(~0x00020000, &GPIO1_OUT); + lcd_enable(false); +#elif CONFIG_BACKLIGHT == BL_RTC + /* Disable square wave */ + rtc_write(0x0a, rtc_read(0x0a) & ~0x40); +#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ + and_b(~0x40, &PAIORH); /* let it float (up) */ +#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */ + and_b(~0x40, &PADRH); /* drive it low */ +#elif CONFIG_BACKLIGHT == BL_GMINI + P1 &= ~0x10; +#elif CONFIG_BACKLIGHT == BL_IPOD4G + /* fades backlight off on 4g */ + outl(inl(0x70000084) & ~0x2000000, 0x70000084); + outl(0x80000000, 0x7000a010); +#elif CONFIG_BACKLIGHT==BL_IPODNANO + /* set port B03 off */ + outl(((0x100 | 0) << 3), 0x6000d824); + + /* set port L07 off */ + outl(((0x100 | 0) << 7), 0x6000d12c); +#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX + GPIO3_CLR = 1; +#elif CONFIG_BACKLIGHT==BL_IPOD3G + lcd_enable(false); +#elif CONFIG_BACKLIGHT==BL_IPODMINI + /* set port B03 off */ + outl(((0x100 | 0) << 3), 0x6000d824); +#endif +} + + #if defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) const char backlight_timeout_value[19] = @@ -73,7 +155,7 @@ static int remote_backlight_timeout_plugged = 5*HZ; #endif #endif -#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) /* backlight fading */ #define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */ #define BL_PWM_COUNT 100 @@ -93,7 +175,7 @@ static void backlight_isr(void) int timer_period; bool idle = false; - timer_period = CPU_FREQ / 1000 * BL_PWM_INTERVAL / 1000; + timer_period = TIMER_FREQ / 1000 * BL_PWM_INTERVAL / 1000; switch (bl_dim_state) { /* New cycle */ @@ -103,7 +185,7 @@ static void backlight_isr(void) if (bl_dim_current > 0 && bl_dim_current < BL_PWM_COUNT) { - and_l(~0x00020000, &GPIO1_OUT); + __backlight_on(); bl_pwm_counter = bl_dim_current; timer_period = timer_period * bl_pwm_counter / BL_PWM_COUNT; bl_dim_state = DIM_STATE_MAIN; @@ -111,10 +193,9 @@ static void backlight_isr(void) else { if (bl_dim_current) - and_l(~0x00020000, &GPIO1_OUT); + __backlight_on(); else - or_l(0x00020000, &GPIO1_OUT); - + __backlight_off(); if (bl_dim_current == bl_dim_target) idle = true; } @@ -123,7 +204,7 @@ static void backlight_isr(void) /* Dim main screen */ case DIM_STATE_MAIN: - or_l(0x00020000, &GPIO1_OUT); + __backlight_off(); bl_dim_state = DIM_STATE_START; timer_period = timer_period * (BL_PWM_COUNT - bl_pwm_counter) / BL_PWM_COUNT; break ; @@ -143,7 +224,9 @@ static void backlight_isr(void) if (idle) { +#ifdef CPU_COLDFIRE queue_post(&backlight_queue, BACKLIGHT_UNBOOST_CPU, NULL); +#endif timer_unregister(); bl_timer_active = false; } @@ -155,19 +238,21 @@ static void backlight_switch(void) { if (bl_dim_target > (BL_PWM_COUNT/2)) { - and_l(~0x00020000, &GPIO1_OUT); + __backlight_on(); bl_dim_current = BL_PWM_COUNT; } else { - or_l(0x00020000, &GPIO1_OUT); + __backlight_off(); bl_dim_current = 0; } } static void backlight_release_timer(void) { +#ifdef CPU_COLDFIRE cpu_boost(false); +#endif timer_unregister(); bl_timer_active = false; backlight_switch(); @@ -186,8 +271,10 @@ static void backlight_dim(int value) if (timer_register(0, backlight_release_timer, 1, 0, backlight_isr)) { +#ifdef CPU_COLDFIRE /* Prevent cpu frequency changes while dimming. */ cpu_boost(true); +#endif bl_timer_active = true; } else @@ -203,96 +290,35 @@ void backlight_set_fade_out(int index) { fade_out_count = backlight_fade_value[index]; } -#endif /* (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) */ +#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */ -static void __backlight_on(void) +static void _backlight_on(void) { -#ifdef SIMULATOR - sim_backlight(100); -#elif CONFIG_BACKLIGHT == BL_IRIVER_H100 +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) if (fade_in_count > 0) backlight_dim(BL_PWM_COUNT); else { bl_dim_target = bl_dim_current = BL_PWM_COUNT; - and_l(~0x00020000, &GPIO1_OUT); + __backlight_on(); } -#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 - lcd_enable(true); - or_l(0x00020000, &GPIO1_OUT); -#elif CONFIG_BACKLIGHT == BL_RTC - /* Enable square wave */ - rtc_write(0x0a, rtc_read(0x0a) | 0x40); -#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ - and_b(~0x40, &PADRH); /* drive and set low */ - or_b(0x40, &PAIORH); -#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */ - or_b(0x40, &PADRH); /* drive it high */ -#elif CONFIG_BACKLIGHT == BL_GMINI - P1 |= 0x10; -#elif CONFIG_BACKLIGHT == BL_IPOD4G - /* brightness full */ - outl(0x80000000 | (0xff << 16), 0x7000a010); - - /* set port b bit 3 on */ - outl(((0x100 | 1) << 3), 0x6000d824); -#elif CONFIG_BACKLIGHT==BL_IPODMINI - /* set port B03 on */ - outl(((0x100 | 1) << 3), 0x6000d824); -#elif CONFIG_BACKLIGHT==BL_IPODNANO - /* set port B03 on */ - outl(((0x100 | 1) << 3), 0x6000d824); - - /* set port L07 on */ - outl(((0x100 | 1) << 7), 0x6000d12c); -#elif CONFIG_BACKLIGHT==BL_IPOD3G - lcd_enable(true); -#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX - GPIO3_SET = 1; +#else + __backlight_on(); #endif } -static void __backlight_off(void) +static void _backlight_off(void) { -#ifdef SIMULATOR - sim_backlight(0); -#elif CONFIG_BACKLIGHT == BL_IRIVER_H100 +#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) if (fade_out_count > 0) backlight_dim(0); else { bl_dim_target = bl_dim_current = 0; - or_l(0x00020000, &GPIO1_OUT); + __backlight_off(); } -#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 - and_l(~0x00020000, &GPIO1_OUT); - lcd_enable(false); -#elif CONFIG_BACKLIGHT == BL_RTC - /* Disable square wave */ - rtc_write(0x0a, rtc_read(0x0a) & ~0x40); -#elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ - and_b(~0x40, &PAIORH); /* let it float (up) */ -#elif CONFIG_BACKLIGHT == BL_PA14_HI /* Ondio */ - and_b(~0x40, &PADRH); /* drive it low */ -#elif CONFIG_BACKLIGHT == BL_GMINI - P1 &= ~0x10; -#elif CONFIG_BACKLIGHT == BL_IPOD4G - /* fades backlight off on 4g */ - outl(inl(0x70000084) & ~0x2000000, 0x70000084); - outl(0x80000000, 0x7000a010); -#elif CONFIG_BACKLIGHT==BL_IPODNANO - /* set port B03 off */ - outl(((0x100 | 0) << 3), 0x6000d824); - - /* set port L07 off */ - outl(((0x100 | 0) << 7), 0x6000d12c); -#elif CONFIG_BACKLIGHT==BL_IRIVER_IFP7XX - GPIO3_CLR = 1; -#elif CONFIG_BACKLIGHT==BL_IPOD3G - lcd_enable(false); -#elif CONFIG_BACKLIGHT==BL_IPODMINI - /* set port B03 off */ - outl(((0x100 | 0) << 3), 0x6000d824); +#else + __backlight_off(); #endif } @@ -374,19 +400,20 @@ void backlight_thread(void) if (backlight_timer < 0) /* Backlight == OFF in the setting? */ { backlight_timer = 0; /* Disable the timeout */ - __backlight_off(); + _backlight_off(); } else { - __backlight_on(); + _backlight_on(); } break; case BACKLIGHT_OFF: - __backlight_off(); + _backlight_off(); break; -#if (CONFIG_BACKLIGHT == BL_IRIVER_H100) && !defined(SIMULATOR) +#if defined(HAVE_BACKLIGHT_PWM_FADING) && defined(CPU_COLDFIRE) \ + && !defined(SIMULATOR) case BACKLIGHT_UNBOOST_CPU: cpu_boost(false); break; diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 05d395f..e182803 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h @@ -27,7 +27,7 @@ void backlight_set_timeout(int index); #ifdef CONFIG_BACKLIGHT void backlight_init(void); int backlight_get_current_timeout(void); -#if CONFIG_BACKLIGHT == BL_IRIVER_H100 +#ifdef HAVE_BACKLIGHT_PWM_FADING void backlight_set_fade_in(int index); void backlight_set_fade_out(int index); #endif diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h index bdbcce7..bc89689 100644 --- a/firmware/export/config-h100.h +++ b/firmware/export/config-h100.h @@ -40,6 +40,9 @@ /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */ +/* We can fade the backlight by using PWM */ +#define HAVE_BACKLIGHT_PWM_FADING + /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index aea6011..bbfa942 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h @@ -36,6 +36,9 @@ /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_IRIVER_H100 /* port controlled */ +/* We can fade the backlight by using PWM */ +#define HAVE_BACKLIGHT_PWM_FADING + /* Define this if you have a software controlled poweroff */ #define HAVE_SW_POWEROFF diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h index 6bcbffb..142fb272 100644 --- a/firmware/export/config-ipodnano.h +++ b/firmware/export/config-ipodnano.h @@ -48,6 +48,9 @@ /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */ +/* We can fade the backlight by using PWM */ +#define HAVE_BACKLIGHT_PWM_FADING + #ifndef SIMULATOR /* The Nano actually has a PP5021 - but it's register compatible with diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h index 6ea9fce..9536cc8 100644 --- a/firmware/export/config-ipodvideo.h +++ b/firmware/export/config-ipodvideo.h @@ -48,6 +48,9 @@ /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_IPODNANO /* port controlled */ +/* We can fade the backlight by using PWM */ +#define HAVE_BACKLIGHT_PWM_FADING + #ifndef SIMULATOR /* The Nano actually has a PP5021 - but it's register compatible with |