diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2011-12-13 23:12:21 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2011-12-13 23:12:21 +0000 |
commit | dfff88562e700ab1772c9bbb50c47bff00b9a002 (patch) | |
tree | c3479f8daff4b28c91823724257e3bfdf5263452 /firmware/target/arm/as3525/sansa-clip/button-clip.c | |
parent | 744adcba81f462f41c18557d28883c086c27edf7 (diff) | |
download | rockbox-dfff88562e700ab1772c9bbb50c47bff00b9a002.tar.gz rockbox-dfff88562e700ab1772c9bbb50c47bff00b9a002.zip |
Sansa Clip: simplify matrix key scan
Merge clipv1/clipv2 code since they use the same 3x3 matrix
clipzip keyscan buttons now work in bootloader
clipplus untouched (no matrix)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31235 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/as3525/sansa-clip/button-clip.c')
-rw-r--r-- | firmware/target/arm/as3525/sansa-clip/button-clip.c | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/firmware/target/arm/as3525/sansa-clip/button-clip.c b/firmware/target/arm/as3525/sansa-clip/button-clip.c deleted file mode 100644 index a64fddb564..0000000000 --- a/firmware/target/arm/as3525/sansa-clip/button-clip.c +++ /dev/null | |||
@@ -1,156 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 Bertrik Sikken | ||
11 | * Copyright (C) 2008 François Dinel | ||
12 | * Copyright (C) 2008 Rafaël Carré | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | #include "system.h" | ||
24 | #include "button-target.h" | ||
25 | #include "as3525.h" | ||
26 | #ifndef BOOTLOADER /* backlight on hold handling */ | ||
27 | #include "backlight.h" | ||
28 | #endif | ||
29 | |||
30 | /* The Sansa Clip uses a button matrix that is scanned by selecting one of | ||
31 | three rows and reading back the button states from the columns. | ||
32 | |||
33 | In this driver, the row is changed at each call (i.e. once per tick). | ||
34 | In one tick, column data from one row is read back and then the next row | ||
35 | is selected for the following tick. This mechanism ensures that there is | ||
36 | plenty time between selecting a row and reading the columns, avoiding the | ||
37 | need for explicit delays. | ||
38 | */ | ||
39 | |||
40 | |||
41 | void button_init_device(void) | ||
42 | { | ||
43 | GPIOA_DIR &= ~((1<<7) | (1<<3)); | ||
44 | GPIOB_DIR &= ~((1<<2) | (1<<1) | (1<<0)); | ||
45 | GPIOC_PIN(4) = 0; | ||
46 | GPIOC_PIN(5) = 0; | ||
47 | GPIOC_PIN(6) = 0; | ||
48 | GPIOC_DIR |= ((1<<6) | (1<<5) | (1<<4)); | ||
49 | |||
50 | /* get initial readings */ | ||
51 | button_read_device(); | ||
52 | button_read_device(); | ||
53 | button_read_device(); | ||
54 | } | ||
55 | |||
56 | int button_read_device(void) | ||
57 | { | ||
58 | static int row = 0; | ||
59 | static int buttons = 0; | ||
60 | static unsigned power_counter = 0; | ||
61 | |||
62 | if(button_hold()) | ||
63 | { | ||
64 | power_counter = HZ; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | /* direct GPIO connections */ | ||
69 | /* read power, but not if hold button was just released, since | ||
70 | * you basically always hit power due to the slider mechanism after | ||
71 | * releasing hold (wait 1 sec) */ | ||
72 | if (power_counter) | ||
73 | power_counter--; | ||
74 | |||
75 | if (GPIOA_PIN(7) && !power_counter) | ||
76 | buttons |= BUTTON_POWER; | ||
77 | else | ||
78 | buttons &= ~BUTTON_POWER; | ||
79 | |||
80 | /* This is a keypad using C4-C6 as columns and B0-B2 as rows */ | ||
81 | switch (row) { | ||
82 | |||
83 | case 0: | ||
84 | buttons &= ~(BUTTON_VOL_UP | BUTTON_UP); | ||
85 | |||
86 | (void)GPIOB_PIN(0); /* C4B0 is unused */ | ||
87 | |||
88 | if (GPIOB_PIN(1)) | ||
89 | buttons |= BUTTON_VOL_UP; | ||
90 | |||
91 | if (GPIOB_PIN(2)) | ||
92 | buttons |= BUTTON_UP; | ||
93 | |||
94 | GPIOC_PIN(4) = 0; | ||
95 | GPIOC_PIN(5) = (1<<5); | ||
96 | row++; | ||
97 | break; | ||
98 | |||
99 | case 1: | ||
100 | buttons &= ~(BUTTON_LEFT | BUTTON_SELECT | BUTTON_RIGHT); | ||
101 | |||
102 | if (GPIOB_PIN(0)) | ||
103 | buttons |= BUTTON_LEFT; | ||
104 | |||
105 | if (GPIOB_PIN(1)) | ||
106 | buttons |= BUTTON_SELECT; | ||
107 | |||
108 | if (GPIOB_PIN(2)) | ||
109 | buttons |= BUTTON_RIGHT; | ||
110 | |||
111 | GPIOC_PIN(5) = 0; | ||
112 | GPIOC_PIN(6) = (1<<6); | ||
113 | row++; | ||
114 | break; | ||
115 | |||
116 | case 2: | ||
117 | buttons &= ~(BUTTON_DOWN | BUTTON_VOL_DOWN | BUTTON_HOME); | ||
118 | |||
119 | if (GPIOB_PIN(0)) | ||
120 | buttons |= BUTTON_DOWN; | ||
121 | |||
122 | if (GPIOB_PIN(1)) | ||
123 | buttons |= BUTTON_VOL_DOWN; | ||
124 | |||
125 | if (GPIOB_PIN(2)) | ||
126 | buttons |= BUTTON_HOME; | ||
127 | |||
128 | GPIOC_PIN(6) = 0; | ||
129 | GPIOC_PIN(4) = (1<<4); | ||
130 | |||
131 | default: | ||
132 | row = 0; | ||
133 | break; | ||
134 | } | ||
135 | |||
136 | return buttons; | ||
137 | } | ||
138 | |||
139 | bool button_hold(void) | ||
140 | { | ||
141 | bool hold_button = (GPIOA_PIN(3) != 0); | ||
142 | |||
143 | #ifndef BOOTLOADER | ||
144 | /* backlight handling */ | ||
145 | |||
146 | static bool hold_button_old = false; | ||
147 | |||
148 | if (hold_button != hold_button_old) | ||
149 | { | ||
150 | hold_button_old = hold_button; | ||
151 | backlight_hold_changed(hold_button); | ||
152 | } | ||
153 | #endif /* BOOTLOADER */ | ||
154 | |||
155 | return hold_button; | ||
156 | } | ||