diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2006-10-05 10:58:51 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2006-10-05 10:58:51 +0000 |
commit | d4945dc0d07b23eced900075e8748ccc7fb3e424 (patch) | |
tree | 4d67d49b4c036a841fb1ffe2e5f3a267bb9309d0 /firmware/target/arm/ipod/button-mini1g.c | |
parent | 1d69db7355dc7e3cbabc3c1c949e5d6ba3863405 (diff) | |
download | rockbox-d4945dc0d07b23eced900075e8748ccc7fb3e424.tar.gz rockbox-d4945dc0d07b23eced900075e8748ccc7fb3e424.zip |
Move all iPod targets into the target tree. FS#5890
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11129 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/ipod/button-mini1g.c')
-rw-r--r-- | firmware/target/arm/ipod/button-mini1g.c | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/firmware/target/arm/ipod/button-mini1g.c b/firmware/target/arm/ipod/button-mini1g.c new file mode 100644 index 0000000000..07885bc159 --- /dev/null +++ b/firmware/target/arm/ipod/button-mini1g.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in December 2005 | ||
14 | * Original file: linux/arch/armnommu/mach-ipod/keyboard.c | ||
15 | * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) | ||
16 | * | ||
17 | * | ||
18 | * All files in this archive are subject to the GNU General Public License. | ||
19 | * See the file COPYING in the source tree root for full license agreement. | ||
20 | * | ||
21 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
22 | * KIND, either express or implied. | ||
23 | * | ||
24 | ****************************************************************************/ | ||
25 | |||
26 | /* | ||
27 | * Rockbox button functions | ||
28 | */ | ||
29 | |||
30 | #include <stdlib.h> | ||
31 | #include "config.h" | ||
32 | #include "cpu.h" | ||
33 | #include "system.h" | ||
34 | #include "button.h" | ||
35 | #include "kernel.h" | ||
36 | #include "backlight.h" | ||
37 | #include "adc.h" | ||
38 | #include "serial.h" | ||
39 | #include "power.h" | ||
40 | #include "system.h" | ||
41 | #include "powermgmt.h" | ||
42 | |||
43 | /* Variable to use for setting button status in interrupt handler */ | ||
44 | int int_btn = BUTTON_NONE; | ||
45 | #ifdef HAVE_WHEEL_POSITION | ||
46 | static int wheel_position = -1; | ||
47 | static bool send_events = true; | ||
48 | #endif | ||
49 | |||
50 | /* iPod 3G and mini 1G, mini 2G uses iPod 4G code */ | ||
51 | void handle_scroll_wheel(int new_scroll, int was_hold, int reverse) | ||
52 | { | ||
53 | int wheel_keycode = BUTTON_NONE; | ||
54 | static int prev_scroll = -1; | ||
55 | static int direction = 0; | ||
56 | static int count = 0; | ||
57 | static int scroll_state[4][4] = { | ||
58 | {0, 1, -1, 0}, | ||
59 | {-1, 0, 0, 1}, | ||
60 | {1, 0, 0, -1}, | ||
61 | {0, -1, 1, 0} | ||
62 | }; | ||
63 | |||
64 | if ( prev_scroll == -1 ) { | ||
65 | prev_scroll = new_scroll; | ||
66 | } | ||
67 | else if (direction != scroll_state[prev_scroll][new_scroll]) { | ||
68 | direction = scroll_state[prev_scroll][new_scroll]; | ||
69 | count = 0; | ||
70 | } | ||
71 | else if (!was_hold) { | ||
72 | backlight_on(); | ||
73 | if (++count == 6) { /* reduce sensitivity */ | ||
74 | count = 0; | ||
75 | switch (direction) { | ||
76 | case 1: | ||
77 | if (reverse) { | ||
78 | /* 'r' keypress */ | ||
79 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
80 | } | ||
81 | else { | ||
82 | /* 'l' keypress */ | ||
83 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
84 | } | ||
85 | break; | ||
86 | case -1: | ||
87 | if (reverse) { | ||
88 | /* 'l' keypress */ | ||
89 | wheel_keycode = BUTTON_SCROLL_BACK; | ||
90 | } | ||
91 | else { | ||
92 | /* 'r' keypress */ | ||
93 | wheel_keycode = BUTTON_SCROLL_FWD; | ||
94 | } | ||
95 | break; | ||
96 | default: | ||
97 | /* only happens if we get out of sync */ | ||
98 | break; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | if (wheel_keycode != BUTTON_NONE && queue_empty(&button_queue)) | ||
103 | queue_post(&button_queue, wheel_keycode, NULL); | ||
104 | prev_scroll = new_scroll; | ||
105 | } | ||
106 | |||
107 | /* mini 1 only, mini 2G uses iPod 4G code */ | ||
108 | static int ipod_mini_button_read(void) | ||
109 | { | ||
110 | unsigned char source, wheel_source, state, wheel_state; | ||
111 | static bool was_hold = false; | ||
112 | int btn = BUTTON_NONE; | ||
113 | |||
114 | /* The ipodlinux source had a udelay(250) here, but testing has shown that | ||
115 | it is not needed - tested on mini 1g. */ | ||
116 | /* udelay(250);*/ | ||
117 | |||
118 | /* get source(s) of interupt */ | ||
119 | source = GPIOA_INT_STAT & 0x3f; | ||
120 | wheel_source = GPIOB_INT_STAT & 0x30; | ||
121 | |||
122 | if (source == 0 && wheel_source == 0) { | ||
123 | return BUTTON_NONE; /* not for us */ | ||
124 | } | ||
125 | |||
126 | /* get current keypad & wheel status */ | ||
127 | state = GPIOA_INPUT_VAL & 0x3f; | ||
128 | wheel_state = GPIOB_INPUT_VAL & 0x30; | ||
129 | |||
130 | /* toggle interrupt level */ | ||
131 | GPIOA_INT_LEV = ~state; | ||
132 | GPIOB_INT_LEV = ~wheel_state; | ||
133 | |||
134 | /* hold switch causes all outputs to go low */ | ||
135 | /* we shouldn't interpret these as key presses */ | ||
136 | if ((state & 0x20)) { | ||
137 | if (!(state & 0x1)) | ||
138 | btn |= BUTTON_SELECT; | ||
139 | if (!(state & 0x2)) | ||
140 | btn |= BUTTON_MENU; | ||
141 | if (!(state & 0x4)) | ||
142 | btn |= BUTTON_PLAY; | ||
143 | if (!(state & 0x8)) | ||
144 | btn |= BUTTON_RIGHT; | ||
145 | if (!(state & 0x10)) | ||
146 | btn |= BUTTON_LEFT; | ||
147 | |||
148 | if (wheel_source & 0x30) { | ||
149 | handle_scroll_wheel((wheel_state & 0x30) >> 4, was_hold, 1); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | was_hold = button_hold(); | ||
154 | |||
155 | /* ack any active interrupts */ | ||
156 | if (source) | ||
157 | GPIOA_INT_CLR = source; | ||
158 | if (wheel_source) | ||
159 | GPIOB_INT_CLR = wheel_source; | ||
160 | |||
161 | return btn; | ||
162 | } | ||
163 | |||
164 | void ipod_mini_button_int(void) | ||
165 | { | ||
166 | CPU_HI_INT_CLR = GPIO_MASK; | ||
167 | int_btn = ipod_mini_button_read(); | ||
168 | //CPU_INT_EN = 0x40000000; | ||
169 | CPU_HI_INT_EN = GPIO_MASK; | ||
170 | } | ||
171 | |||
172 | void button_init_device(void) | ||
173 | { | ||
174 | /* iPod Mini G1 */ | ||
175 | /* buttons - enable as input */ | ||
176 | GPIOA_ENABLE |= 0x3f; | ||
177 | GPIOA_OUTPUT_EN &= ~0x3f; | ||
178 | /* scroll wheel- enable as input */ | ||
179 | GPIOB_ENABLE |= 0x30; /* port b 4,5 */ | ||
180 | GPIOB_OUTPUT_EN &= ~0x30; /* port b 4,5 */ | ||
181 | /* buttons - set interrupt levels */ | ||
182 | GPIOA_INT_LEV = ~(GPIOA_INPUT_VAL & 0x3f); | ||
183 | GPIOA_INT_CLR = GPIOA_INT_STAT & 0x3f; | ||
184 | /* scroll wheel - set interrupt levels */ | ||
185 | GPIOB_INT_LEV = ~(GPIOB_INPUT_VAL & 0x30); | ||
186 | GPIOB_INT_CLR = GPIOB_INT_STAT & 0x30; | ||
187 | /* enable interrupts */ | ||
188 | GPIOA_INT_EN = 0x3f; | ||
189 | GPIOB_INT_EN = 0x30; | ||
190 | /* unmask interrupt */ | ||
191 | CPU_INT_EN = 0x40000000; | ||
192 | CPU_HI_INT_EN = GPIO_MASK; | ||
193 | } | ||
194 | |||
195 | /* | ||
196 | * Get button pressed from hardware | ||
197 | */ | ||
198 | int button_read_device(void) | ||
199 | { | ||
200 | static bool hold_button = false; | ||
201 | bool hold_button_old; | ||
202 | |||
203 | /* normal buttons */ | ||
204 | hold_button_old = hold_button; | ||
205 | hold_button = button_hold(); | ||
206 | |||
207 | if (hold_button != hold_button_old) | ||
208 | backlight_hold_changed(hold_button); | ||
209 | |||
210 | /* The int_btn variable is set in the button interrupt handler */ | ||
211 | return int_btn; | ||
212 | } | ||
213 | |||
214 | bool button_hold(void) | ||
215 | { | ||
216 | return (GPIOA_INPUT_VAL & 0x20)?false:true; | ||
217 | } | ||