diff options
-rw-r--r-- | firmware/SOURCES | 4 | ||||
-rw-r--r-- | firmware/target/arm/as3525/button-clip.c (renamed from firmware/target/arm/as3525/sansa-clipv2/button-clip.c) | 115 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sansa-clip/button-clip.c | 156 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c | 97 |
4 files changed, 84 insertions, 288 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index f5ee7873a2..1e41e75188 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -1418,7 +1418,7 @@ target/arm/as3525/tuner-as3525v2.c | |||
1418 | #ifndef SIMULATOR | 1418 | #ifndef SIMULATOR |
1419 | target/arm/as3525/lcd-ssd1303.c | 1419 | target/arm/as3525/lcd-ssd1303.c |
1420 | target/arm/as3525/sansa-clipv2/lcd-clipv2.c | 1420 | target/arm/as3525/sansa-clipv2/lcd-clipv2.c |
1421 | target/arm/as3525/sansa-clipv2/button-clip.c | 1421 | target/arm/as3525/button-clip.c |
1422 | target/arm/as3525/sansa-clipv2/backlight-clipv2.c | 1422 | target/arm/as3525/sansa-clipv2/backlight-clipv2.c |
1423 | #ifndef BOOTLOADER | 1423 | #ifndef BOOTLOADER |
1424 | target/arm/powermgmt-ascodec.c | 1424 | target/arm/powermgmt-ascodec.c |
@@ -1432,7 +1432,7 @@ target/arm/as3525/sansa-clipv2/lcd-as-clipv2.S | |||
1432 | #ifndef SIMULATOR | 1432 | #ifndef SIMULATOR |
1433 | target/arm/as3525/lcd-ssd1303.c | 1433 | target/arm/as3525/lcd-ssd1303.c |
1434 | target/arm/as3525/sansa-clip/lcd-clip.c | 1434 | target/arm/as3525/sansa-clip/lcd-clip.c |
1435 | target/arm/as3525/sansa-clip/button-clip.c | 1435 | target/arm/as3525/button-clip.c |
1436 | #ifndef BOOTLOADER | 1436 | #ifndef BOOTLOADER |
1437 | target/arm/powermgmt-ascodec.c | 1437 | target/arm/powermgmt-ascodec.c |
1438 | target/arm/as3525/sansa-clip/powermgmt-clip.c | 1438 | target/arm/as3525/sansa-clip/powermgmt-clip.c |
diff --git a/firmware/target/arm/as3525/sansa-clipv2/button-clip.c b/firmware/target/arm/as3525/button-clip.c index 1356bfbc55..b6679ca359 100644 --- a/firmware/target/arm/as3525/sansa-clipv2/button-clip.c +++ b/firmware/target/arm/as3525/button-clip.c | |||
@@ -27,14 +27,37 @@ | |||
27 | #include "backlight.h" | 27 | #include "backlight.h" |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #if defined(SANSA_CLIP) | ||
31 | # define OUT_PIN GPIOC_PIN | ||
32 | # define OUT_DIR GPIOC_DIR | ||
33 | # define OUT_INITIAL 0 | ||
34 | # define IN_PIN GPIOB_PIN | ||
35 | # define IN_DIR GPIOB_DIR | ||
36 | #elif defined(SANSA_CLIPV2) | ||
37 | # define OUT_PIN GPIOD_PIN | ||
38 | # define OUT_DIR GPIOD_DIR | ||
39 | # define OUT_INITIAL 1 | ||
40 | # define IN_PIN GPIOD_PIN | ||
41 | # define IN_DIR GPIOD_DIR | ||
42 | #endif | ||
43 | |||
44 | static const int rows[3] = { | ||
45 | #if defined(SANSA_CLIP) | ||
46 | 4, 5, 6 | ||
47 | #elif defined(SANSA_CLIPV2) | ||
48 | 5, 6, 4 | ||
49 | #endif | ||
50 | }; | ||
51 | |||
30 | void button_init_device(void) | 52 | void button_init_device(void) |
31 | { | 53 | { |
32 | GPIOA_DIR &= ~((1<<7) | (1<<3)); | 54 | GPIOA_DIR &= ~((1<<7) | (1<<3)); |
33 | GPIOD_DIR &= ~((1<<2) | (1<<1) | (1<<0)); | 55 | IN_DIR &= ~((1<<2) | (1<<1) | (1<<0)); |
34 | GPIOD_PIN(3) = 1<<3; | 56 | |
35 | GPIOD_PIN(4) = 1<<4; | 57 | for (int i = 0; i < 3; i++) { |
36 | GPIOD_PIN(5) = 1<<5; | 58 | OUT_PIN(rows[i]) = OUT_INITIAL << rows[i]; |
37 | GPIOD_DIR |= ((1<<5) | (1<<4) | (1<<3)); | 59 | OUT_DIR |= 1 << rows[i]; |
60 | } | ||
38 | 61 | ||
39 | /* get initial readings */ | 62 | /* get initial readings */ |
40 | button_read_device(); | 63 | button_read_device(); |
@@ -44,9 +67,8 @@ void button_init_device(void) | |||
44 | 67 | ||
45 | int button_read_device(void) | 68 | int button_read_device(void) |
46 | { | 69 | { |
47 | static int row = 0; | 70 | static int row, buttons; |
48 | static int buttons = 0; | 71 | static unsigned power_counter; |
49 | static unsigned power_counter = 0; | ||
50 | 72 | ||
51 | if(button_hold()) | 73 | if(button_hold()) |
52 | { | 74 | { |
@@ -66,84 +88,47 @@ int button_read_device(void) | |||
66 | else | 88 | else |
67 | buttons &= ~BUTTON_POWER; | 89 | buttons &= ~BUTTON_POWER; |
68 | 90 | ||
69 | /* This is a keypad using D3-D5 as columns and D0-D2 as rows */ | 91 | static const int matrix [3][3] = { |
70 | switch (row) { | 92 | { 0 /*unused*/, BUTTON_VOL_UP, BUTTON_UP }, |
71 | 93 | { BUTTON_LEFT, BUTTON_SELECT, BUTTON_RIGHT }, | |
72 | case 0: | 94 | { BUTTON_DOWN, BUTTON_VOL_DOWN, BUTTON_HOME }, |
73 | buttons &= ~(BUTTON_VOL_UP | BUTTON_UP); | 95 | }; |
74 | |||
75 | (void)GPIOD_PIN(0); /* D3D0 is unused */ | ||
76 | |||
77 | if (!GPIOD_PIN(1)) | ||
78 | buttons |= BUTTON_VOL_UP; | ||
79 | |||
80 | if (!GPIOD_PIN(2)) | ||
81 | buttons |= BUTTON_UP; | ||
82 | |||
83 | GPIOD_PIN(3) = 1<<3; | ||
84 | GPIOD_PIN(4) = 0x00; | ||
85 | row++; | ||
86 | break; | ||
87 | |||
88 | case 1: | ||
89 | buttons &= ~(BUTTON_LEFT | BUTTON_SELECT | BUTTON_RIGHT); | ||
90 | |||
91 | if (!GPIOD_PIN(0)) | ||
92 | buttons |= BUTTON_LEFT; | ||
93 | |||
94 | if (!GPIOD_PIN(1)) | ||
95 | buttons |= BUTTON_SELECT; | ||
96 | 96 | ||
97 | if (!GPIOD_PIN(2)) | 97 | for (int i = 0; i<3; i++) |
98 | buttons |= BUTTON_RIGHT; | 98 | if (IN_PIN(i)) |
99 | buttons |= matrix[row][i]; | ||
100 | else | ||
101 | buttons &= ~matrix[row][i]; | ||
99 | 102 | ||
100 | GPIOD_PIN(4) = 1<<4; | 103 | /* prepare next row */ |
101 | GPIOD_PIN(5) = 0x00; | 104 | OUT_PIN(rows[row]) = 0 << rows[row]; |
102 | row++; | 105 | row++; |
103 | break; | 106 | row %= 3; |
104 | 107 | OUT_PIN(rows[row]) = 1 << rows[row]; | |
105 | case 2: | ||
106 | buttons &= ~(BUTTON_DOWN | BUTTON_VOL_DOWN | BUTTON_HOME); | ||
107 | |||
108 | if (!GPIOD_PIN(0)) | ||
109 | buttons |= BUTTON_DOWN; | ||
110 | |||
111 | if (!GPIOD_PIN(1)) | ||
112 | buttons |= BUTTON_VOL_DOWN; | ||
113 | |||
114 | if (!GPIOD_PIN(2)) | ||
115 | buttons |= BUTTON_HOME; | ||
116 | |||
117 | GPIOD_PIN(5) = 1<<5; | ||
118 | GPIOD_PIN(3) = 0x00; | ||
119 | |||
120 | default: | ||
121 | row = 0; | ||
122 | break; | ||
123 | } | ||
124 | 108 | ||
125 | return buttons; | 109 | return buttons; |
126 | } | 110 | } |
127 | 111 | ||
128 | bool button_hold(void) | 112 | bool button_hold(void) |
129 | { | 113 | { |
130 | #ifndef BOOTLOADER | 114 | #ifdef SANSA_CLIPV2 |
131 | static bool hold_button_old = false; | ||
132 | #endif | ||
133 | |||
134 | GPIOA_DIR |= 1<<7; | 115 | GPIOA_DIR |= 1<<7; |
135 | GPIOA_PIN(7) = 1<<7; | 116 | GPIOA_PIN(7) = 1<<7; |
136 | 117 | ||
137 | int delay = 50; | 118 | int delay = 50; |
138 | while(delay--) | 119 | while(delay--) |
139 | asm("nop"); | 120 | asm("nop"); |
121 | #endif | ||
140 | 122 | ||
141 | bool hold_button = (GPIOA_PIN(3) != 0); | 123 | bool hold_button = (GPIOA_PIN(3) != 0); |
142 | 124 | ||
125 | #ifdef SANSA_CLIPV2 | ||
143 | GPIOA_PIN(7) = 0; | 126 | GPIOA_PIN(7) = 0; |
144 | GPIOA_DIR &= ~(1<<7); | 127 | GPIOA_DIR &= ~(1<<7); |
128 | #endif | ||
145 | 129 | ||
146 | #ifndef BOOTLOADER | 130 | #ifndef BOOTLOADER |
131 | static bool hold_button_old = false; | ||
147 | /* light handling */ | 132 | /* light handling */ |
148 | if (hold_button != hold_button_old) | 133 | if (hold_button != hold_button_old) |
149 | { | 134 | { |
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 | } | ||
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 | |||