diff options
Diffstat (limited to 'firmware/target/coldfire/iriver/h300/button-h300.c')
-rw-r--r-- | firmware/target/coldfire/iriver/h300/button-h300.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/h300/button-h300.c b/firmware/target/coldfire/iriver/h300/button-h300.c new file mode 100644 index 0000000000..80210b6c19 --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/button-h300.c | |||
@@ -0,0 +1,246 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Jonathan Gordon | ||
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 | |||
20 | |||
21 | #include <stdlib.h> | ||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "button.h" | ||
26 | #include "kernel.h" | ||
27 | #include "backlight.h" | ||
28 | #include "adc.h" | ||
29 | #include "system.h" | ||
30 | #ifdef HAVE_REMOTE_LCD | ||
31 | #include "lcd-remote.h" | ||
32 | #endif | ||
33 | |||
34 | void button_init_device(void) | ||
35 | { | ||
36 | /* Set GPIO9 and GPIO15 as general purpose inputs */ | ||
37 | GPIO_ENABLE &= ~0x00008200; | ||
38 | GPIO_FUNCTION |= 0x00008200; | ||
39 | /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs */ | ||
40 | GPIO1_ENABLE &= ~0x00100060; | ||
41 | GPIO1_FUNCTION |= 0x00100062; | ||
42 | } | ||
43 | |||
44 | bool button_hold(void) | ||
45 | { | ||
46 | return (GPIO1_READ & 0x00000002)?true:false; | ||
47 | } | ||
48 | |||
49 | bool remote_button_hold_only(void) | ||
50 | { | ||
51 | if(remote_type() == REMOTETYPE_H300_NONLCD) | ||
52 | return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */ | ||
53 | else | ||
54 | return (GPIO1_READ & 0x00100000)?true:false; | ||
55 | } | ||
56 | |||
57 | /* returns true only if there is remote present */ | ||
58 | bool remote_button_hold(void) | ||
59 | { | ||
60 | /* H300's NON-LCD remote doesn't set the "remote present" bit */ | ||
61 | if(remote_type() == REMOTETYPE_H300_NONLCD) | ||
62 | return remote_button_hold_only(); | ||
63 | else | ||
64 | return ((GPIO_READ & 0x40000000) == 0)?remote_button_hold_only():false; | ||
65 | } | ||
66 | |||
67 | /* | ||
68 | * Get button pressed from hardware | ||
69 | */ | ||
70 | int button_read_device(void) | ||
71 | { | ||
72 | int btn = BUTTON_NONE; | ||
73 | int data; | ||
74 | static bool hold_button = false; | ||
75 | static bool remote_hold_button = false; | ||
76 | static int prev_data = 0xff; | ||
77 | static int last_valid = 0xff; | ||
78 | bool hold_button_old; | ||
79 | bool remote_hold_button_old; | ||
80 | |||
81 | /* normal buttons */ | ||
82 | hold_button_old = hold_button; | ||
83 | hold_button = button_hold(); | ||
84 | |||
85 | |||
86 | #ifndef BOOTLOADER | ||
87 | if (hold_button != hold_button_old) | ||
88 | backlight_hold_changed(hold_button); | ||
89 | #endif | ||
90 | |||
91 | if (!hold_button) | ||
92 | { | ||
93 | data = adc_scan(ADC_BUTTONS); | ||
94 | |||
95 | /* ADC debouncing: Only accept new reading if it's | ||
96 | * stable (+/-1). Use latest stable value otherwise. */ | ||
97 | if ((unsigned)(data - prev_data + 1) <= 2) | ||
98 | last_valid = data; | ||
99 | prev_data = data; | ||
100 | data = last_valid; | ||
101 | |||
102 | if (data < 0xba) | ||
103 | { | ||
104 | if (data < 0x54) | ||
105 | if (data < 0x30) | ||
106 | if (data < 0x10) | ||
107 | btn = BUTTON_SELECT; | ||
108 | else | ||
109 | btn = BUTTON_UP; | ||
110 | else | ||
111 | btn = BUTTON_LEFT; | ||
112 | else | ||
113 | if (data < 0x98) | ||
114 | if (data < 0x76) | ||
115 | btn = BUTTON_DOWN; | ||
116 | else | ||
117 | btn = BUTTON_RIGHT; | ||
118 | else | ||
119 | btn = BUTTON_OFF; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /* remote buttons */ | ||
124 | remote_hold_button_old = remote_hold_button; | ||
125 | remote_hold_button = remote_button_hold_only(); | ||
126 | |||
127 | #ifndef BOOTLOADER | ||
128 | if (remote_hold_button != remote_hold_button_old) | ||
129 | remote_backlight_hold_changed(remote_hold_button); | ||
130 | #endif | ||
131 | |||
132 | if (!remote_hold_button) | ||
133 | { | ||
134 | data = adc_scan(ADC_REMOTE); | ||
135 | switch (remote_type()) | ||
136 | { | ||
137 | case REMOTETYPE_H100_LCD: | ||
138 | if (data < 0xf5) | ||
139 | { | ||
140 | if (data < 0x73) | ||
141 | if (data < 0x3f) | ||
142 | if (data < 0x25) | ||
143 | if(data < 0x0c) | ||
144 | btn |= BUTTON_RC_STOP; | ||
145 | else | ||
146 | btn |= BUTTON_RC_VOL_DOWN; | ||
147 | else | ||
148 | btn |= BUTTON_RC_MODE; | ||
149 | else | ||
150 | if (data < 0x5a) | ||
151 | btn |= BUTTON_RC_VOL_UP; | ||
152 | else | ||
153 | btn |= BUTTON_RC_BITRATE; | ||
154 | else | ||
155 | if (data < 0xa8) | ||
156 | if (data < 0x8c) | ||
157 | btn |= BUTTON_RC_REC; | ||
158 | else | ||
159 | btn |= BUTTON_RC_SOURCE; | ||
160 | else | ||
161 | if (data < 0xdf) | ||
162 | if(data < 0xc5) | ||
163 | btn |= BUTTON_RC_FF; | ||
164 | else | ||
165 | btn |= BUTTON_RC_MENU; | ||
166 | else | ||
167 | btn |= BUTTON_RC_REW; | ||
168 | } | ||
169 | break; | ||
170 | case REMOTETYPE_H300_LCD: | ||
171 | if (data < 0xf5) | ||
172 | { | ||
173 | if (data < 0x73) | ||
174 | if (data < 0x42) | ||
175 | if (data < 0x27) | ||
176 | if(data < 0x0c) | ||
177 | btn |= BUTTON_RC_VOL_DOWN; | ||
178 | else | ||
179 | btn |= BUTTON_RC_FF; | ||
180 | else | ||
181 | btn |= BUTTON_RC_STOP; | ||
182 | else | ||
183 | if (data < 0x5b) | ||
184 | btn |= BUTTON_RC_MODE; | ||
185 | else | ||
186 | btn |= BUTTON_RC_REC; | ||
187 | else | ||
188 | if (data < 0xab) | ||
189 | if (data < 0x8e) | ||
190 | btn |= BUTTON_RC_ON; | ||
191 | else | ||
192 | btn |= BUTTON_RC_BITRATE; | ||
193 | else | ||
194 | if (data < 0xde) | ||
195 | if(data < 0xc5) | ||
196 | btn |= BUTTON_RC_SOURCE; | ||
197 | else | ||
198 | btn |= BUTTON_RC_VOL_UP; | ||
199 | else | ||
200 | btn |= BUTTON_RC_REW; | ||
201 | } | ||
202 | break; | ||
203 | case REMOTETYPE_H300_NONLCD: | ||
204 | if (data < 0xf1) | ||
205 | { | ||
206 | if (data < 0x7d) | ||
207 | if (data < 0x25) | ||
208 | btn |= BUTTON_RC_FF; | ||
209 | else | ||
210 | btn |= BUTTON_RC_REW; | ||
211 | else | ||
212 | if (data < 0xd5) | ||
213 | btn |= BUTTON_RC_VOL_DOWN; | ||
214 | else | ||
215 | btn |= BUTTON_RC_VOL_UP; | ||
216 | } | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | if (!hold_button) | ||
222 | { | ||
223 | data = GPIO_READ; | ||
224 | if ((data & 0x0200) == 0) | ||
225 | btn |= BUTTON_MODE; | ||
226 | if ((data & 0x8000) == 0) | ||
227 | btn |= BUTTON_REC; | ||
228 | } | ||
229 | |||
230 | data = GPIO1_READ; | ||
231 | if (!hold_button && ((data & 0x20) == 0)) | ||
232 | btn |= BUTTON_ON; | ||
233 | if (!remote_hold_button && ((data & 0x40) == 0)) | ||
234 | switch(remote_type()) | ||
235 | { | ||
236 | case REMOTETYPE_H100_LCD: | ||
237 | case REMOTETYPE_H300_NONLCD: | ||
238 | btn |= BUTTON_RC_ON; | ||
239 | break; | ||
240 | case REMOTETYPE_H300_LCD: | ||
241 | btn |= BUTTON_RC_MENU; | ||
242 | break; | ||
243 | } | ||
244 | |||
245 | return btn; | ||
246 | } | ||