From 3d2e10bcbd13ec48decafe49f32afcc12c5e185a Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 10 Sep 2006 02:00:40 +0000 Subject: Added remote backlight on hold option to players with remote hold switch. Disabled IRQs while reading pcf50606 ADC. This seems to have stopped buttons becoming unresponsive when using remote. Maybe fixes other button glitches as well? git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10911 a1c6a512-1295-4272-9138-f99709370657 --- apps/settings.c | 11 +++++ apps/settings.h | 12 +++-- apps/settings_menu.c | 19 ++++++++ firmware/backlight.c | 57 ++++++++++++++++++++++-- firmware/drivers/adc.c | 2 + firmware/drivers/button.c | 10 +++-- firmware/export/backlight.h | 23 ++++++++-- firmware/target/coldfire/iaudio/x5/adc-x5.c | 2 + firmware/target/coldfire/iaudio/x5/button-x5.c | 16 ++++--- firmware/target/coldfire/iaudio/x5/pcf50606-x5.c | 2 +- 10 files changed, 131 insertions(+), 23 deletions(-) diff --git a/apps/settings.c b/apps/settings.c index 8dcad6bae4..d2b220f893 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -647,6 +647,14 @@ static const struct bit_entry hd_bits[] = {8|SIGNED, S_O(rec_agc_maxgain_line), 96, "agc maximum line gain", NULL}, {3, S_O(rec_agc_cliptime), 1, "agc cliptime", "0.2s,0.4s,0.6s,0.8,1s"}, #endif + +#ifdef HAVE_REMOTE_LCD +#ifdef HAS_REMOTE_BUTTON_HOLD + {2, S_O(remote_backlight_on_button_hold), 0, "remote backlight on button hold", + "normal,off,on" }, +#endif +#endif + /* If values are just added to the end, no need to bump the version. */ /* new stuff to be added at the end */ @@ -1108,7 +1116,10 @@ void settings_apply(void) #ifdef CONFIG_CHARGING remote_backlight_set_timeout_plugged(global_settings.remote_backlight_timeout_plugged); #endif +#ifdef HAS_REMOTE_BUTTON_HOLD + remote_backlight_set_on_button_hold(global_settings.remote_backlight_on_button_hold); #endif +#endif /* HAVE_REMOTE_LCD */ #ifdef CONFIG_BACKLIGHT backlight_set_timeout(global_settings.backlight_timeout); #ifdef CONFIG_CHARGING diff --git a/apps/settings.h b/apps/settings.h index b66e96b765..561dc59375 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -354,11 +354,15 @@ struct user_settings then according to timeout_values[] */ int remote_backlight_timeout_plugged; bool remote_caption_backlight; /* turn on backlight at end and start of track */ +#ifdef HAS_REMOTE_BUTTON_HOLD + int remote_backlight_on_button_hold; /* what to do with remote backlight when hold + switch is on */ +#endif #ifdef HAVE_REMOTE_LCD_TICKING bool remote_reduce_ticking; /* 0=normal operation, 1=EMI reduce on with cost more CPU. */ #endif -#endif +#endif /* HAVE_REMOTE_LCD */ bool next_folder; /* move to next folder */ bool runtimedb; /* runtime database active? */ @@ -446,10 +450,12 @@ struct user_settings bool remote_bl_filter_first_keypress; /* filter first remote keypress when remote dark? */ #endif #ifdef HAS_BUTTON_HOLD - int backlight_on_button_hold; + int backlight_on_button_hold; /* what to do with backlight when hold + switch is on */ #endif #ifdef HAVE_LCD_SLEEP - int lcd_sleep_after_backlight_off; + int lcd_sleep_after_backlight_off; /* when to put lcd to sleep after backlight + has turned off */ #endif #endif /* CONFIG_BACKLIGHT */ diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 5f84dc1d34..ab19c820be 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -315,6 +315,22 @@ static bool remote_caption_backlight(void) return set_bool((char *)str(LANG_CAPTION_BACKLIGHT), &global_settings.remote_caption_backlight); } + +#ifdef HAS_REMOTE_BUTTON_HOLD +static bool remote_backlight_on_button_hold(void) +{ + static const struct opt_items names[3] = { + { STR(LANG_BACKLIGHT_ON_BUTTON_HOLD_NORMAL) }, + { STR(LANG_OFF) }, + { STR(LANG_ON) }, + }; + return set_option(str(LANG_BACKLIGHT_ON_BUTTON_HOLD), + &global_settings.remote_backlight_on_button_hold, + INT, names, 3, + remote_backlight_set_on_button_hold); +} +#endif /* HAS_BUTTON_HOLD */ + #endif /* HAVE_REMOTE_LCD */ #ifdef HAVE_LCD_CONTRAST @@ -1886,6 +1902,9 @@ static bool lcd_remote_settings_menu(void) #ifdef CONFIG_CHARGING { ID2P(LANG_BACKLIGHT_ON_WHEN_CHARGING), remote_backlight_timer_plugged }, +#endif +#ifdef HAS_REMOTE_BUTTON_HOLD + { ID2P(LANG_BACKLIGHT_ON_BUTTON_HOLD), remote_backlight_on_button_hold }, #endif { ID2P(LANG_CAPTION_BACKLIGHT), remote_caption_backlight }, { ID2P(LANG_BACKLIGHT_FILTER_FIRST_KEYPRESS), set_remote_bl_filter_first_keypress }, diff --git a/firmware/backlight.c b/firmware/backlight.c index 6f7432c9e2..bf88cbe9bc 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -178,6 +178,9 @@ static int remote_backlight_timeout = 5*HZ; #ifdef CONFIG_CHARGING static int remote_backlight_timeout_plugged = 5*HZ; #endif +#ifdef HAS_REMOTE_BUTTON_HOLD +static int remote_backlight_on_button_hold = 0; +#endif #endif #ifdef HAVE_LCD_SLEEP @@ -461,6 +464,10 @@ static void remote_backlight_update_state(void) if (remote_backlight_timer < 0) { remote_backlight_timer = 0; /* Disable the timeout */ +#ifdef HAS_REMOTE_BUTTON_HOLD + if (remote_backlight_on_button_hold == 2 && remote_button_hold()) + return; /* Keep on if "On" */ +#endif __remote_backlight_off(); } else @@ -471,8 +478,18 @@ static void remote_backlight_update_state(void) backlight_update_state(); } else -#endif +#endif + { +#ifdef HAS_REMOTE_BUTTON_HOLD + if (remote_backlight_on_button_hold == 1 && remote_button_hold()) + { + /* Keep off if "Off". */ + remote_backlight_timer = 0; /* Disable the timeout */ + return; + } +#endif __remote_backlight_on(); + } } } #endif /* HAVE_REMOTE_LCD */ @@ -493,9 +510,15 @@ void backlight_thread(void) case REMOTE_BACKLIGHT_OFF: remote_backlight_timer = 0; /* Disable the timeout */ +#ifdef HAS_REMOTE_BUTTON_HOLD + if (remote_backlight_on_button_hold == 2 && + remote_button_hold()) + break; /* Keep on if "On" */ +#endif __remote_backlight_off(); break; -#endif +#endif /* HAVE_REMOTE_LCD */ + case BACKLIGHT_ON: backlight_update_state(); break; @@ -701,9 +724,7 @@ void backlight_hold_changed(bool hold_button) set to "Normal" */ /* Queue or freeze */ if (hold_button && backlight_on_button_hold == 1) - { backlight_off(); /* setting == Off */ - } else /* setting == On, Normal, no hold button, or anything else */ backlight_on(); } @@ -774,6 +795,34 @@ void remote_backlight_set_timeout_plugged(int index) } #endif /* CONFIG_CHARGING */ +#ifdef HAS_REMOTE_BUTTON_HOLD +/* Remote hold button change event handler. */ +void remote_backlight_hold_changed(bool rc_hold_button) +{ + /* Hold switch overrides all backlight behavior except when + set to "Normal" */ + /* Queue or freeze */ + if (rc_hold_button && remote_backlight_on_button_hold == 1) + remote_backlight_off(); /* setting == Off */ + else /* setting == On, Normal, no hold button, or anything else */ + remote_backlight_on(); + +} + +void remote_backlight_set_on_button_hold(int index) +{ + if ((unsigned)index >= 3) + /* if given a weird value, use default */ + index = 0; + + if (index == remote_backlight_on_button_hold) + return; + + remote_backlight_on_button_hold = index; + remote_backlight_hold_changed(remote_button_hold()); +} +#endif /* HAS_REMOTE_BUTTON_HOLD */ + /* return value in ticks; 0 means always on, <0 means always off */ int remote_backlight_get_current_timeout(void) { diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 1ebac066e7..d00f89958a 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c @@ -123,6 +123,7 @@ static int channelnum[] = unsigned short adc_scan(int channel) { + int level = set_irq_level(HIGHEST_IRQ_LEVEL); unsigned char data; pcf50606_write(0x2f, 0x80 | (channelnum[channel] << 1) | 1); @@ -130,6 +131,7 @@ unsigned short adc_scan(int channel) adcdata[channel] = data; + set_irq_level(level); return data; } #else diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index f31ab33c87..5e6f6b4827 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -845,6 +845,7 @@ static int button_read(void) static int prev_data = 0xff; static int last_valid = 0xff; bool hold_button_old; + bool remote_hold_button_old; /* normal buttons */ hold_button_old = hold_button; @@ -916,12 +917,13 @@ static int button_read(void) } /* remote buttons */ + remote_hold_button_old = remote_hold_button; remote_hold_button = remote_button_hold_only(); - if (remote_hold_button && !remote_button_hold_only()) - { - remote_backlight_on(); - } +#ifndef BOOTLOADER + if (remote_hold_button != remote_hold_button_old) + remote_backlight_hold_changed(remote_hold_button); +#endif if (!remote_hold_button) { diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 62f024816f..6875768f0c 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h @@ -25,27 +25,35 @@ bool is_backlight_on(void); void backlight_on(void); void backlight_off(void); void backlight_set_timeout(int index); + #ifdef CONFIG_BACKLIGHT void backlight_init(void); + #if defined(IAUDIO_X5) && !defined(SIMULATOR) #define X5_BACKLIGHT_SHUTDOWN void x5_backlight_shutdown(void); #endif + int backlight_get_current_timeout(void); + #ifdef HAVE_BACKLIGHT_PWM_FADING void backlight_set_fade_in(int index); void backlight_set_fade_out(int index); #endif + void backlight_set_timeout_plugged(int index); extern const signed char backlight_timeout_value[]; + #ifdef HAS_BUTTON_HOLD -void backlight_set_on_button_hold(int index); void backlight_hold_changed(bool hold_button); +void backlight_set_on_button_hold(int index); #endif + #ifdef HAVE_LCD_SLEEP void lcd_set_sleep_after_backlight_off(int index); extern const signed char lcd_sleep_timeout_value[]; #endif + #else /* ndef CONFIG_BACKLIGHT */ #define backlight_init() #endif /* CONFIG_BACKLIGHT */ @@ -56,15 +64,20 @@ void remote_backlight_off(void); void remote_backlight_set_timeout(int index); void remote_backlight_set_timeout_plugged(int index); bool is_remote_backlight_on(void); + +#ifdef HAS_REMOTE_BUTTON_HOLD +void remote_backlight_hold_changed(bool rc_hold_button); +void remote_backlight_set_on_button_hold(int index); #endif +#endif /* HAVE_REMOTE_LCD */ #ifdef SIMULATOR void sim_backlight(int value); void sim_remote_backlight(int value); #endif -#endif #ifdef HAVE_BACKLIGHT_BRIGHTNESS + #ifdef IAUDIO_X5 /* PFC50506 can output 0%-100% duty cycle but D305A expects %15-100%. */ #define MIN_BRIGHTNESS_SETTING 1 /* 15/16 (93.75%) */ @@ -74,7 +87,9 @@ void sim_remote_backlight(int value); #define MIN_BRIGHTNESS_SETTING 2 /* 2/16 (12.50%) */ #define MAX_BRIGHTNESS_SETTING 15 /* 15/16 (93.75%) */ #define DEFAULT_BRIGHTNESS_SETTING 9 /* 9/16 (56.25%) */ -#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ +#endif void backlight_set_brightness(int val); -#endif +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + +#endif /* BACKLIGHT_H */ diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c index e465f38494..fc45da8624 100755 --- a/firmware/target/coldfire/iaudio/x5/adc-x5.c +++ b/firmware/target/coldfire/iaudio/x5/adc-x5.c @@ -35,6 +35,7 @@ static int channelnum[] = unsigned short adc_scan(int channel) { + int level = set_irq_level(HIGHEST_IRQ_LEVEL); unsigned char data; pcf50606_write(0x2f, 0x80 | (channelnum[channel] << 1) | 1); @@ -42,6 +43,7 @@ unsigned short adc_scan(int channel) adcdata[channel] = data; + set_irq_level(level); return data; } diff --git a/firmware/target/coldfire/iaudio/x5/button-x5.c b/firmware/target/coldfire/iaudio/x5/button-x5.c index 287ee0e92b..84d1dbc7d8 100755 --- a/firmware/target/coldfire/iaudio/x5/button-x5.c +++ b/firmware/target/coldfire/iaudio/x5/button-x5.c @@ -41,7 +41,7 @@ bool button_hold(void) bool remote_button_hold(void) { - return false; /* TODO X5 */ + return adc_scan(ADC_REMOTE) < 0x17; } int button_read_device(void) @@ -51,6 +51,7 @@ int button_read_device(void) static bool hold_button = false; static bool remote_hold_button = false; bool hold_button_old; + bool remote_hold_button_old; /* normal buttons */ hold_button_old = hold_button; @@ -90,14 +91,15 @@ int button_read_device(void) } /* remote buttons */ - - /* TODO: add light handling for the remote */ - - remote_hold_button = remote_button_hold(); + remote_hold_button_old = remote_hold_button; data = adc_scan(ADC_REMOTE); - if(data < 0x17) - remote_hold_button = true; + remote_hold_button = data < 0x17; + +#ifndef BOOTLOADER + if (remote_hold_button != remote_hold_button_old) + remote_backlight_hold_changed(remote_hold_button); +#endif if(!remote_hold_button) { diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c index dde20d8b7c..032c30814a 100644 --- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c +++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c @@ -177,7 +177,7 @@ void pcf50606_init(void) and_l(~0x00000001, &GPIO_ENABLE); or_l(0x00000001, &GPIO_FUNCTION); or_l(0x00000100, &GPIO_INT_EN); /* GPI0 H-L */ - INTPRI5 |= 0x00000006; /* INT32 - Priority 6 */ + INTPRI5 |= (6 << 0); /* INT32 - Priority 6 */ pcf50606_write(0x39, 0x00); /* GPOOD0 = green led OFF */ pcf50606_write(0x3a, 0x00); /* GPOOD1 = red led OFF */ -- cgit v1.2.3