diff options
Diffstat (limited to 'firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c')
-rw-r--r-- | firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c | 97 |
1 files changed, 32 insertions, 65 deletions
diff --git a/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c index 40b20cdce3..c22c5e24e9 100644 --- a/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c +++ b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c | |||
@@ -21,97 +21,64 @@ | |||
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | 22 | ||
23 | #include "config.h" | 23 | #include "config.h" |
24 | |||
25 | #include "button-target.h" | 24 | #include "button-target.h" |
26 | #include "as3525v2.h" | 25 | #include "as3525v2.h" |
26 | #include "system.h" | ||
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "system-target.h" | ||
29 | 28 | ||
30 | static int keyscan(void) | 29 | static int keyscan(void) |
31 | { | 30 | { |
32 | static int buttons = 0; | 31 | static int buttons, row; |
33 | static int row = 1; | 32 | static const int matrix[2][3] = { |
33 | { BUTTON_RIGHT, BUTTON_SELECT, BUTTON_UP }, | ||
34 | { BUTTON_HOME, BUTTON_DOWN, BUTTON_LEFT }, | ||
35 | }; | ||
36 | |||
37 | for (int i = 0; i < 3; i++) | ||
38 | if (GPIOC_PIN(3 + i)) | ||
39 | buttons |= matrix[row][i]; | ||
40 | else | ||
41 | buttons &= ~matrix[row][i]; | ||
34 | 42 | ||
35 | switch (row) { | 43 | /* prepare next row */ |
36 | 44 | GPIOC_PIN(1) = row << 1; | |
37 | case 1: | 45 | row ^= 1; |
38 | /* read row 1 */ | 46 | GPIOC_PIN(2) = row << 2; |
39 | buttons &= ~(BUTTON_RIGHT | BUTTON_SELECT | BUTTON_UP); | 47 | |
40 | if (GPIOC_PIN(3)) { | 48 | /* delay a bit if interrupts are disabled, to be sure next row will read */ |
41 | buttons |= BUTTON_RIGHT; | 49 | if (!irq_enabled()) |
42 | } | 50 | for (volatile int i = 0; i < 0x500; i++) ; |
43 | if (GPIOC_PIN(4)) { | ||
44 | buttons |= BUTTON_SELECT; | ||
45 | } | ||
46 | if (GPIOC_PIN(5)) { | ||
47 | buttons |= BUTTON_UP; | ||
48 | } | ||
49 | |||
50 | /* prepare row 2 */ | ||
51 | GPIOC_PIN(1) = 0; | ||
52 | GPIOC_PIN(2) = (1 << 2); | ||
53 | row = 2; | ||
54 | break; | ||
55 | |||
56 | case 2: | ||
57 | /* read row 2 */ | ||
58 | buttons &= ~(BUTTON_HOME | BUTTON_DOWN | BUTTON_LEFT); | ||
59 | if (GPIOC_PIN(3)) { | ||
60 | buttons |= BUTTON_HOME; | ||
61 | } | ||
62 | if (GPIOC_PIN(4)) { | ||
63 | buttons |= BUTTON_DOWN; | ||
64 | } | ||
65 | if (GPIOC_PIN(5)) { | ||
66 | buttons |= BUTTON_LEFT; | ||
67 | } | ||
68 | |||
69 | /* prepare row 1 */ | ||
70 | GPIOC_PIN(1) = (1 << 1); | ||
71 | GPIOC_PIN(2) = 0; | ||
72 | row = 1; | ||
73 | break; | ||
74 | 51 | ||
75 | default: | ||
76 | row = 1; | ||
77 | break; | ||
78 | } | ||
79 | |||
80 | return buttons; | 52 | return buttons; |
81 | } | 53 | } |
82 | 54 | ||
83 | void button_init_device(void) | 55 | void button_init_device(void) |
84 | { | 56 | { |
85 | /* GPIO A6, A7 and D6 are direct button inputs */ | 57 | /* GPIO A6, A7 and D6 are direct button inputs */ |
86 | GPIOA_DIR &= ~(1 << 6); | 58 | GPIOA_DIR &= ~(1 << 6 | 1<< 7); |
87 | GPIOA_DIR &= ~(1 << 7); | ||
88 | GPIOD_DIR &= ~(1 << 6); | 59 | GPIOD_DIR &= ~(1 << 6); |
89 | 60 | ||
90 | /* GPIO C1, C2, C3, C4, C5 are used in a column/row key scan matrix */ | 61 | /* GPIO C1, C2, C3, C4, C5 are used in a column/row key scan matrix */ |
91 | GPIOC_DIR |= ((1 << 1) | (1 << 2)); | 62 | GPIOC_DIR |= ((1 << 1) | (1 << 2)); |
92 | GPIOC_DIR &= ~((1 << 3) | (1 << 4) | (1 << 5)); | 63 | GPIOC_DIR &= ~((1 << 3) | (1 << 4) | (1 << 5)); |
64 | |||
65 | /* initial reading */ | ||
66 | button_read_device(); | ||
67 | sleep(1); | ||
68 | button_read_device(); | ||
69 | sleep(1); | ||
93 | } | 70 | } |
94 | 71 | ||
95 | int button_read_device(void) | 72 | int button_read_device(void) |
96 | { | 73 | { |
97 | int buttons = 0; | 74 | int buttons = 0; |
98 | 75 | ||
99 | /* power */ | 76 | if (GPIOD_PIN(6)) |
100 | if (GPIOD_PIN(6)) { | ||
101 | buttons |= BUTTON_POWER; | 77 | buttons |= BUTTON_POWER; |
102 | } | 78 | if (GPIOA_PIN(6)) |
103 | |||
104 | /* volume */ | ||
105 | if (GPIOA_PIN(6)) { | ||
106 | buttons |= BUTTON_VOL_DOWN; | 79 | buttons |= BUTTON_VOL_DOWN; |
107 | } | 80 | if (GPIOA_PIN(7)) |
108 | if (GPIOA_PIN(7)) { | ||
109 | buttons |= BUTTON_VOL_UP; | 81 | buttons |= BUTTON_VOL_UP; |
110 | } | ||
111 | |||
112 | /* keyscan buttons */ | ||
113 | buttons |= keyscan(); | ||
114 | 82 | ||
115 | return buttons; | 83 | return buttons | keyscan(); |
116 | } | 84 | } |
117 | |||