From c4a0d45d36cf093425146c93c25c8f97df87a854 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sat, 28 Oct 2006 23:10:45 +0000 Subject: Cleanup of new button reading code. Moved functions for enabling of scanning and the decision to scan or not to button_read_device. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11377 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/coldfire/iaudio/x5/adc-target.h | 2 -- firmware/target/coldfire/iaudio/x5/adc-x5.c | 26 -------------- firmware/target/coldfire/iaudio/x5/button-target.h | 2 ++ firmware/target/coldfire/iaudio/x5/button-x5.c | 40 ++++++++++++++-------- firmware/target/coldfire/iaudio/x5/pcf50606-x5.c | 6 ++-- 5 files changed, 30 insertions(+), 46 deletions(-) (limited to 'firmware/target/coldfire') diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h index 51e853625f..4081562fe5 100644 --- a/firmware/target/coldfire/iaudio/x5/adc-target.h +++ b/firmware/target/coldfire/iaudio/x5/adc-target.h @@ -28,7 +28,5 @@ /* Force a scan now */ unsigned short adc_scan(int channel); -void adc_enable_button_scan(bool enable); -bool adc_get_button_scan_enabled(void); #endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c index c923951e31..72aec7d547 100755 --- a/firmware/target/coldfire/iaudio/x5/adc-x5.c +++ b/firmware/target/coldfire/iaudio/x5/adc-x5.c @@ -33,37 +33,11 @@ static const int adcc2_parms[] = [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ }; -/* have buttons scan by default */ -static volatile bool button_scan_on = true; - -void adc_enable_button_scan(bool enable) -{ - button_scan_on = enable; -} - -bool adc_get_button_scan_enabled(void) -{ - return button_scan_on; -} - unsigned short adc_scan(int channel) { int level; unsigned char data; - if (channel == ADC_BUTTONS) - { - /* no button scan if nothing pushed */ - if (!button_scan_on) - return adcdata[channel] = 0xff; - } - else if (channel == ADC_REMOTE) - { - /* no remote scan if not plugged */ - if (GPIO_READ & 0x01000000) - return adcdata[channel] = 0xff; - } - level = set_irq_level(HIGHEST_IRQ_LEVEL); pcf50606_write(0x2f, adcc2_parms[channel]); diff --git a/firmware/target/coldfire/iaudio/x5/button-target.h b/firmware/target/coldfire/iaudio/x5/button-target.h index ab6e770ed3..af1088dfed 100755 --- a/firmware/target/coldfire/iaudio/x5/button-target.h +++ b/firmware/target/coldfire/iaudio/x5/button-target.h @@ -29,6 +29,8 @@ bool button_hold(void); bool remote_button_hold(void); void button_init_device(void); int button_read_device(void); +void button_enable_scan(bool enable); +bool button_scan_enabled(void); /* iaudio X5 specific button codes */ diff --git a/firmware/target/coldfire/iaudio/x5/button-x5.c b/firmware/target/coldfire/iaudio/x5/button-x5.c index 5874e01a64..7cb86ff930 100755 --- a/firmware/target/coldfire/iaudio/x5/button-x5.c +++ b/firmware/target/coldfire/iaudio/x5/button-x5.c @@ -16,16 +16,17 @@ * KIND, either express or implied. * ****************************************************************************/ - -#include #include "config.h" -#include "cpu.h" #include "system.h" #include "button.h" -#include "kernel.h" #include "backlight.h" #include "adc.h" -#include "system.h" +#include "lcd-remote-target.h" + +/* have buttons scan by default */ +static bool button_scan_on = true; +static bool hold_button = false; +static bool remote_hold_button = false; void button_init_device(void) { @@ -34,24 +35,32 @@ void button_init_device(void) GPIO_ENABLE &= ~0x0e000000; } +void button_enable_scan(bool enable) +{ + button_scan_on = enable; +} + +bool button_scan_enabled(void) +{ + return button_scan_on; +} + bool button_hold(void) { - return (GPIO_READ & 0x08000000)?false:true; + return (GPIO_READ & 0x08000000) == 0; } bool remote_button_hold(void) { - return adc_scan(ADC_REMOTE) < 0x17; + return remote_hold_button; } int button_read_device(void) { - int data; - int btn = BUTTON_NONE; - static bool hold_button = false; - static bool remote_hold_button = false; + int btn = BUTTON_NONE; bool hold_button_old; bool remote_hold_button_old; + int data; /* normal buttons */ hold_button_old = hold_button; @@ -63,9 +72,10 @@ int button_read_device(void) backlight_hold_changed(hold_button); #endif - if (!hold_button) + if (button_scan_on && !hold_button) { data = adc_scan(ADC_BUTTONS); + if (data < 0xf0) { if(data < 0x7c) @@ -91,9 +101,9 @@ int button_read_device(void) } /* remote buttons */ - remote_hold_button_old = remote_hold_button; + data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff; - data = adc_scan(ADC_REMOTE); + remote_hold_button_old = remote_hold_button; remote_hold_button = data < 0x17; #ifndef BOOTLOADER @@ -101,7 +111,7 @@ int button_read_device(void) remote_backlight_hold_changed(remote_hold_button); #endif - if(!remote_hold_button) + if (!remote_hold_button) { if (data < 0xee) { diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c index 8b3655c107..3443d1e567 100644 --- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c +++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c @@ -20,7 +20,7 @@ #include "system.h" #include "kernel.h" #include "pcf50606.h" -#include "adc.h" +#include "button-target.h" #include "powermgmt.h" /* These voltages were determined by measuring the output of the PCF50606 @@ -130,7 +130,7 @@ void GPI0(void) /* ACDINS/ACDREM */ /* Check if adc_scan should actually scan main buttons or not - bias towards "yes" out of paranoia. */ - adc_enable_button_scan((data[2] & 0x02) != 0 || - (pcf50606_read(0x33) & 0x01) != 0); + button_enable_scan((data[2] & 0x02) != 0 || + (pcf50606_read(0x33) & 0x01) != 0); } } -- cgit v1.2.3