summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2006-10-28 23:10:45 +0000
committerMichael Sevakis <jethead71@rockbox.org>2006-10-28 23:10:45 +0000
commitc4a0d45d36cf093425146c93c25c8f97df87a854 (patch)
treefaf8486c7e296c2272c3b2b277c097ad50ceb695 /firmware
parent56e75bee23b0458ebe5198912c024475c762c355 (diff)
downloadrockbox-c4a0d45d36cf093425146c93c25c8f97df87a854.tar.gz
rockbox-c4a0d45d36cf093425146c93c25c8f97df87a854.zip
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
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/coldfire/iaudio/x5/adc-target.h2
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/adc-x5.c26
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/button-target.h2
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/button-x5.c40
-rw-r--r--firmware/target/coldfire/iaudio/x5/pcf50606-x5.c6
5 files changed, 30 insertions, 46 deletions
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 @@
28 28
29/* Force a scan now */ 29/* Force a scan now */
30unsigned short adc_scan(int channel); 30unsigned short adc_scan(int channel);
31void adc_enable_button_scan(bool enable);
32bool adc_get_button_scan_enabled(void);
33 31
34#endif /* _ADC_TARGET_H_ */ 32#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[] =
33 [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ 33 [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */
34}; 34};
35 35
36/* have buttons scan by default */
37static volatile bool button_scan_on = true;
38
39void adc_enable_button_scan(bool enable)
40{
41 button_scan_on = enable;
42}
43
44bool adc_get_button_scan_enabled(void)
45{
46 return button_scan_on;
47}
48
49unsigned short adc_scan(int channel) 36unsigned short adc_scan(int channel)
50{ 37{
51 int level; 38 int level;
52 unsigned char data; 39 unsigned char data;
53 40
54 if (channel == ADC_BUTTONS)
55 {
56 /* no button scan if nothing pushed */
57 if (!button_scan_on)
58 return adcdata[channel] = 0xff;
59 }
60 else if (channel == ADC_REMOTE)
61 {
62 /* no remote scan if not plugged */
63 if (GPIO_READ & 0x01000000)
64 return adcdata[channel] = 0xff;
65 }
66
67 level = set_irq_level(HIGHEST_IRQ_LEVEL); 41 level = set_irq_level(HIGHEST_IRQ_LEVEL);
68 42
69 pcf50606_write(0x2f, adcc2_parms[channel]); 43 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);
29bool remote_button_hold(void); 29bool remote_button_hold(void);
30void button_init_device(void); 30void button_init_device(void);
31int button_read_device(void); 31int button_read_device(void);
32void button_enable_scan(bool enable);
33bool button_scan_enabled(void);
32 34
33/* iaudio X5 specific button codes */ 35/* iaudio X5 specific button codes */
34 36
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 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19
20#include <stdlib.h>
21#include "config.h" 19#include "config.h"
22#include "cpu.h"
23#include "system.h" 20#include "system.h"
24#include "button.h" 21#include "button.h"
25#include "kernel.h"
26#include "backlight.h" 22#include "backlight.h"
27#include "adc.h" 23#include "adc.h"
28#include "system.h" 24#include "lcd-remote-target.h"
25
26/* have buttons scan by default */
27static bool button_scan_on = true;
28static bool hold_button = false;
29static bool remote_hold_button = false;
29 30
30void button_init_device(void) 31void button_init_device(void)
31{ 32{
@@ -34,24 +35,32 @@ void button_init_device(void)
34 GPIO_ENABLE &= ~0x0e000000; 35 GPIO_ENABLE &= ~0x0e000000;
35} 36}
36 37
38void button_enable_scan(bool enable)
39{
40 button_scan_on = enable;
41}
42
43bool button_scan_enabled(void)
44{
45 return button_scan_on;
46}
47
37bool button_hold(void) 48bool button_hold(void)
38{ 49{
39 return (GPIO_READ & 0x08000000)?false:true; 50 return (GPIO_READ & 0x08000000) == 0;
40} 51}
41 52
42bool remote_button_hold(void) 53bool remote_button_hold(void)
43{ 54{
44 return adc_scan(ADC_REMOTE) < 0x17; 55 return remote_hold_button;
45} 56}
46 57
47int button_read_device(void) 58int button_read_device(void)
48{ 59{
49 int data; 60 int btn = BUTTON_NONE;
50 int btn = BUTTON_NONE;
51 static bool hold_button = false;
52 static bool remote_hold_button = false;
53 bool hold_button_old; 61 bool hold_button_old;
54 bool remote_hold_button_old; 62 bool remote_hold_button_old;
63 int data;
55 64
56 /* normal buttons */ 65 /* normal buttons */
57 hold_button_old = hold_button; 66 hold_button_old = hold_button;
@@ -63,9 +72,10 @@ int button_read_device(void)
63 backlight_hold_changed(hold_button); 72 backlight_hold_changed(hold_button);
64#endif 73#endif
65 74
66 if (!hold_button) 75 if (button_scan_on && !hold_button)
67 { 76 {
68 data = adc_scan(ADC_BUTTONS); 77 data = adc_scan(ADC_BUTTONS);
78
69 if (data < 0xf0) 79 if (data < 0xf0)
70 { 80 {
71 if(data < 0x7c) 81 if(data < 0x7c)
@@ -91,9 +101,9 @@ int button_read_device(void)
91 } 101 }
92 102
93 /* remote buttons */ 103 /* remote buttons */
94 remote_hold_button_old = remote_hold_button; 104 data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff;
95 105
96 data = adc_scan(ADC_REMOTE); 106 remote_hold_button_old = remote_hold_button;
97 remote_hold_button = data < 0x17; 107 remote_hold_button = data < 0x17;
98 108
99#ifndef BOOTLOADER 109#ifndef BOOTLOADER
@@ -101,7 +111,7 @@ int button_read_device(void)
101 remote_backlight_hold_changed(remote_hold_button); 111 remote_backlight_hold_changed(remote_hold_button);
102#endif 112#endif
103 113
104 if(!remote_hold_button) 114 if (!remote_hold_button)
105 { 115 {
106 if (data < 0xee) 116 if (data < 0xee)
107 { 117 {
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 @@
20#include "system.h" 20#include "system.h"
21#include "kernel.h" 21#include "kernel.h"
22#include "pcf50606.h" 22#include "pcf50606.h"
23#include "adc.h" 23#include "button-target.h"
24#include "powermgmt.h" 24#include "powermgmt.h"
25 25
26/* These voltages were determined by measuring the output of the PCF50606 26/* These voltages were determined by measuring the output of the PCF50606
@@ -130,7 +130,7 @@ void GPI0(void)
130 /* ACDINS/ACDREM */ 130 /* ACDINS/ACDREM */
131 /* Check if adc_scan should actually scan main buttons or not - 131 /* Check if adc_scan should actually scan main buttons or not -
132 bias towards "yes" out of paranoia. */ 132 bias towards "yes" out of paranoia. */
133 adc_enable_button_scan((data[2] & 0x02) != 0 || 133 button_enable_scan((data[2] & 0x02) != 0 ||
134 (pcf50606_read(0x33) & 0x01) != 0); 134 (pcf50606_read(0x33) & 0x01) != 0);
135 } 135 }
136} 136}