diff options
author | Thomas Martitz <kugel@rockbox.org> | 2009-02-17 02:36:48 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2009-02-17 02:36:48 +0000 |
commit | be84fcffbd4bcc6e009a2a223b269b61098fdb93 (patch) | |
tree | d4668a7601118d92991ee3f8957dd5f2fd280b3c /firmware/target/arm/as3525/sansa-fuze/button-fuze.c | |
parent | 4b0ae103197be83586a0f082eb2d0ee57b579f30 (diff) | |
download | rockbox-be84fcffbd4bcc6e009a2a223b269b61098fdb93.tar.gz rockbox-be84fcffbd4bcc6e009a2a223b269b61098fdb93.zip |
Some Sansa Fuze work: Get Home button working (no keymap changes yet, so it's not very noticeable) and "fix" debug menu from not showing the dbop data (see FIXME), some cleanup in the fuze's button driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20027 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/as3525/sansa-fuze/button-fuze.c')
-rw-r--r-- | firmware/target/arm/as3525/sansa-fuze/button-fuze.c | 96 |
1 files changed, 45 insertions, 51 deletions
diff --git a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c index e52a1d37d8..0e50ec659a 100644 --- a/firmware/target/arm/as3525/sansa-fuze/button-fuze.c +++ b/firmware/target/arm/as3525/sansa-fuze/button-fuze.c | |||
@@ -42,8 +42,9 @@ static bool hold_button_old = false; | |||
42 | #else | 42 | #else |
43 | #define hold_button false | 43 | #define hold_button false |
44 | #endif /* !BOOTLOADER */ | 44 | #endif /* !BOOTLOADER */ |
45 | static int int_btn = BUTTON_NONE; | 45 | static short _dbop_din = BUTTON_NONE; |
46 | short _dbop_din = BUTTON_NONE; | 46 | |
47 | extern void lcd_button_support(void); | ||
47 | 48 | ||
48 | void button_init_device(void) | 49 | void button_init_device(void) |
49 | { | 50 | { |
@@ -53,12 +54,12 @@ void button_init_device(void) | |||
53 | 54 | ||
54 | /* clickwheel */ | 55 | /* clickwheel */ |
55 | #if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) | 56 | #if !defined(BOOTLOADER) && defined(HAVE_SCROLLWHEEL) |
56 | static void get_wheel(void) | 57 | static void clickwheel(void) |
57 | { | 58 | { |
58 | static unsigned int old_wheel_value = 0; | 59 | static unsigned int old_wheel_value = 0; |
59 | static unsigned int wheel_value = 0; | 60 | static unsigned int wheel_value = 0; |
60 | static unsigned int wheel_repeat = BUTTON_NONE; | 61 | static unsigned int wheel_repeat = BUTTON_NONE; |
61 | /* getting BUTTON_REPEAT works like this: We increment repeat by if the | 62 | /* getting BUTTON_REPEAT works like this: We increment repeat by 2 if the |
62 | * wheel was turned, and decrement it by 1 each tick, | 63 | * wheel was turned, and decrement it by 1 each tick, |
63 | * that means: if you change the wheel fast enough, repeat will be >1 and | 64 | * that means: if you change the wheel fast enough, repeat will be >1 and |
64 | * we send BUTTON_REPEAT | 65 | * we send BUTTON_REPEAT |
@@ -126,30 +127,15 @@ static void get_wheel(void) | |||
126 | } | 127 | } |
127 | #endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */ | 128 | #endif /* !defined(BOOTLOADER) && defined(SCROLLWHEEL) */ |
128 | 129 | ||
129 | #if !defined(BOOTLOADER) | ||
130 | /* get hold button state */ | ||
131 | static void get_hold(void) | ||
132 | { | ||
133 | hold_button = _dbop_din & (1<<12); | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | bool button_hold(void) | 130 | bool button_hold(void) |
138 | { | 131 | { |
139 | return hold_button; | 132 | return hold_button; |
140 | } | 133 | } |
141 | 134 | ||
142 | static void get_power(void) | 135 | static int button_dbop(void) |
143 | { | ||
144 | if (_dbop_din & (1<<8)) | ||
145 | int_btn |= BUTTON_POWER; | ||
146 | } | ||
147 | |||
148 | static void get_button_from_dbob(void) | ||
149 | { | 136 | { |
150 | int_btn &= ~(BUTTON_HOLD| | 137 | int ret = 0; |
151 | BUTTON_POWER); | 138 | lcd_button_support(); |
152 | |||
153 | /* Wait for fifo to empty */ | 139 | /* Wait for fifo to empty */ |
154 | while ((DBOP_STAT & (1<<10)) == 0); | 140 | while ((DBOP_STAT & (1<<10)) == 0); |
155 | 141 | ||
@@ -181,34 +167,43 @@ static void get_button_from_dbob(void) | |||
181 | DBOP_CTRL &= ~(1<<19); | 167 | DBOP_CTRL &= ~(1<<19); |
182 | 168 | ||
183 | #if !defined(BOOTLOADER) | 169 | #if !defined(BOOTLOADER) |
184 | get_hold(); | 170 | hold_button = _dbop_din & (1<<12); |
185 | #if defined(HAVE_SCROLLWHEEL) | 171 | if (hold_button) |
186 | get_wheel(); | 172 | return BUTTON_NONE; |
187 | #endif | 173 | #endif |
174 | /* read power */ | ||
175 | if (_dbop_din & (1<<8)) | ||
176 | ret |= BUTTON_POWER; | ||
177 | if(!(_dbop_din & (1<<15))) | ||
178 | ret |= BUTTON_HOME; | ||
179 | #if defined(HAVE_SCROLLWHEEL) | ||
180 | clickwheel(); | ||
188 | #endif | 181 | #endif |
189 | get_power(); | 182 | |
183 | return ret; | ||
184 | } | ||
185 | |||
186 | /* for the debug menu */ | ||
187 | short button_dbop_data(void) | ||
188 | { | ||
189 | return _dbop_din; | ||
190 | } | 190 | } |
191 | 191 | ||
192 | static void get_button_from_gpio(void) | 192 | static int button_gpio(void) |
193 | { | 193 | { |
194 | /* reset buttons we're going to read */ | 194 | int btn = BUTTON_NONE; |
195 | int_btn &= ~(BUTTON_LEFT| | ||
196 | BUTTON_RIGHT| | ||
197 | BUTTON_UP| | ||
198 | BUTTON_DOWN| | ||
199 | BUTTON_SELECT); | ||
200 | if(hold_button) | 195 | if(hold_button) |
201 | return; | 196 | return btn; |
202 | /* set afsel, so that we can read our buttons */ | 197 | /* set afsel, so that we can read our buttons */ |
203 | GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); | 198 | GPIOC_AFSEL &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); |
204 | /* set dir so we can read our buttons (but reset the C pins first) */ | 199 | /* set dir so we can read our buttons (but reset the C pins first) */ |
205 | GPIOB_DIR &= ~(1<<4); | 200 | GPIOB_DIR &= ~(1<<4); |
206 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); | 201 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); |
207 | GPIOC_PIN(2) |= (1<<2); | 202 | GPIOC_PIN(2) = (1<<2); |
208 | GPIOC_PIN(3) |= (1<<3); | 203 | GPIOC_PIN(3) = (1<<3); |
209 | GPIOC_PIN(4) |= (1<<4); | 204 | GPIOC_PIN(4) = (1<<4); |
210 | GPIOC_PIN(5) |= (1<<5); | 205 | GPIOC_PIN(5) = (1<<5); |
211 | GPIOC_PIN(6) |= (1<<6); | 206 | GPIOC_PIN(6) = (1<<6); |
212 | 207 | ||
213 | GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); | 208 | GPIOC_DIR &= ~(1<<2|1<<3|1<<4|1<<5|1<<6); |
214 | 209 | ||
@@ -218,31 +213,30 @@ static void get_button_from_gpio(void) | |||
218 | 213 | ||
219 | /* direct GPIO connections */ | 214 | /* direct GPIO connections */ |
220 | if (!GPIOC_PIN(3)) | 215 | if (!GPIOC_PIN(3)) |
221 | int_btn |= BUTTON_LEFT; | 216 | btn |= BUTTON_LEFT; |
222 | if (!GPIOC_PIN(2)) | 217 | if (!GPIOC_PIN(2)) |
223 | int_btn |= BUTTON_UP; | 218 | btn |= BUTTON_UP; |
224 | if (!GPIOC_PIN(6)) | 219 | if (!GPIOC_PIN(6)) |
225 | int_btn |= BUTTON_DOWN; | 220 | btn |= BUTTON_DOWN; |
226 | if (!GPIOC_PIN(5)) | 221 | if (!GPIOC_PIN(5)) |
227 | int_btn |= BUTTON_RIGHT; | 222 | btn |= BUTTON_RIGHT; |
228 | if (!GPIOC_PIN(4)) | 223 | if (!GPIOC_PIN(4)) |
229 | int_btn |= BUTTON_SELECT; | 224 | btn |= BUTTON_SELECT; |
230 | /* return to settings needed for lcd */ | 225 | /* return to settings needed for lcd */ |
231 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); | 226 | GPIOC_DIR |= (1<<2|1<<3|1<<4|1<<5|1<<6); |
232 | GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6); | 227 | GPIOC_AFSEL |= (1<<2|1<<3|1<<4|1<<5|1<<6); |
233 | } | ||
234 | 228 | ||
235 | static inline void get_buttons_from_hw(void) | 229 | return btn; |
236 | { | ||
237 | get_button_from_dbob(); | ||
238 | get_button_from_gpio(); | ||
239 | } | 230 | } |
231 | |||
240 | /* | 232 | /* |
241 | * Get button pressed from hardware | 233 | * Get button pressed from hardware |
242 | */ | 234 | */ |
243 | int button_read_device(void) | 235 | int button_read_device(void) |
244 | { | 236 | { |
245 | get_buttons_from_hw(); | 237 | int ret = BUTTON_NONE; |
238 | ret |= button_dbop(); | ||
239 | ret |= button_gpio(); | ||
246 | #ifndef BOOTLOADER | 240 | #ifndef BOOTLOADER |
247 | /* light handling */ | 241 | /* light handling */ |
248 | if (hold_button != hold_button_old) | 242 | if (hold_button != hold_button_old) |
@@ -252,5 +246,5 @@ int button_read_device(void) | |||
252 | } | 246 | } |
253 | #endif /* BOOTLOADER */ | 247 | #endif /* BOOTLOADER */ |
254 | 248 | ||
255 | return int_btn; /* set in button_int */ | 249 | return ret; |
256 | } | 250 | } |