summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iaudio/m5/button-m5.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iaudio/m5/button-m5.c')
-rw-r--r--firmware/target/coldfire/iaudio/m5/button-m5.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iaudio/m5/button-m5.c b/firmware/target/coldfire/iaudio/m5/button-m5.c
new file mode 100644
index 0000000000..a5fdd79fde
--- /dev/null
+++ b/firmware/target/coldfire/iaudio/m5/button-m5.c
@@ -0,0 +1,151 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "system.h"
21#include "button.h"
22#include "backlight.h"
23#include "adc.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;
30
31void button_init_device(void)
32{
33 /* Power, Remote Play & Hold switch */
34 GPIO_FUNCTION |= 0x0e000000;
35 GPIO_ENABLE &= ~0x0e000000;
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
48bool button_hold(void)
49{
50 return (GPIO_READ & 0x08000000) == 0;
51}
52
53bool remote_button_hold(void)
54{
55 return remote_hold_button;
56}
57
58int button_read_device(void)
59{
60 int btn = BUTTON_NONE;
61 bool hold_button_old;
62 bool remote_hold_button_old;
63 int data;
64
65 /* normal buttons */
66 hold_button_old = hold_button;
67 hold_button = button_hold();
68
69#ifndef BOOTLOADER
70 /* give BL notice if HB state chaged */
71 if (hold_button != hold_button_old)
72 backlight_hold_changed(hold_button);
73#endif
74
75 if (button_scan_on && !hold_button)
76 {
77 data = adc_scan(ADC_BUTTONS);
78
79 if (data < 0xf0)
80 {
81 if(data < 0x7c)
82 if(data < 0x42)
83 btn = BUTTON_LEFT;
84 else
85 if(data < 0x62)
86 btn = BUTTON_RIGHT;
87 else
88 btn = BUTTON_SELECT;
89 else
90 if(data < 0xb6)
91 if(data < 0x98)
92 btn = BUTTON_PLAY;
93 else
94 btn = BUTTON_REC;
95 else
96 if(data < 0xd3)
97 btn = BUTTON_DOWN;
98 else
99 btn = BUTTON_UP;
100 }
101 }
102
103 /* remote buttons */
104 data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff;
105
106 remote_hold_button_old = remote_hold_button;
107 remote_hold_button = data < 0x17;
108
109#ifndef BOOTLOADER
110 if (remote_hold_button != remote_hold_button_old)
111 remote_backlight_hold_changed(remote_hold_button);
112#endif
113
114 if (!remote_hold_button)
115 {
116 if (data < 0xee)
117 {
118 if(data < 0x7a)
119 if(data < 0x41)
120 btn |= BUTTON_RC_FF;
121 else
122 if(data < 0x61)
123 btn |= BUTTON_RC_REW;
124 else
125 btn |= BUTTON_RC_MODE;
126 else
127 if(data < 0xb4)
128 if(data < 0x96)
129 btn |= BUTTON_RC_REC;
130 else
131 btn |= BUTTON_RC_MENU;
132 else
133 if(data < 0xd1)
134 btn |= BUTTON_RC_VOL_UP;
135 else
136 btn |= BUTTON_RC_VOL_DOWN;
137 }
138 }
139
140 data = GPIO_READ;
141
142 /* hold and power are mutually exclusive */
143 if (!(data & 0x04000000))
144 btn |= BUTTON_POWER;
145
146 /* remote play button should be dead if hold */
147 if (!remote_hold_button && !(data & 0x02000000))
148 btn |= BUTTON_RC_PLAY;
149
150 return btn;
151}