summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-03-15 23:01:45 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-03-15 23:01:45 +0000
commitf74a6ed38a9c1228316b40363670edc97f90b695 (patch)
tree8ad4a7cfb7e547a4f1bfc8aa564b655272e673a4
parent9db98bb864c969cdbffd7081e49994ca31cc3084 (diff)
downloadrockbox-f74a6ed38a9c1228316b40363670edc97f90b695.tar.gz
rockbox-f74a6ed38a9c1228316b40363670edc97f90b695.zip
Sansa Clipv2: use similar button driver to Clipv1
Fixes some buttons not being read (hold is still buggy) FlySpray: FS#11111 Author: Pascal Below git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25209 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--docs/CREDITS1
-rw-r--r--firmware/target/arm/as3525/sansa-clipv2/button-clip.c103
2 files changed, 71 insertions, 33 deletions
diff --git a/docs/CREDITS b/docs/CREDITS
index 9845c454ec..0bf49acb18 100644
--- a/docs/CREDITS
+++ b/docs/CREDITS
@@ -532,6 +532,7 @@ Andrew Engelbrecht
532Kevin Schoedel 532Kevin Schoedel
533Jens Theeß 533Jens Theeß
534Alexey Nemtsev 534Alexey Nemtsev
535Pascal Below
535 536
536The libmad team 537The libmad team
537The wavpack team 538The wavpack team
diff --git a/firmware/target/arm/as3525/sansa-clipv2/button-clip.c b/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
index 4291665e3d..c14d67cb60 100644
--- a/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
+++ b/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
@@ -7,6 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2009 Bertrik Sikken
10 * Copyright (C) 2008 François Dinel 11 * Copyright (C) 2008 François Dinel
11 * Copyright © 2008-2009 Rafaël Carré 12 * Copyright © 2008-2009 Rafaël Carré
12 * 13 *
@@ -19,11 +20,12 @@
19 * KIND, either express or implied. 20 * KIND, either express or implied.
20 * 21 *
21 ****************************************************************************/ 22 ****************************************************************************/
23#include "system.h"
22#include "button-target.h" 24#include "button-target.h"
23#include "as3525v2.h" 25#include "as3525v2.h"
24#include "kernel.h" 26#ifndef BOOTLOADER
25 27#include "backlight.h"
26/* FIXME : use Clipv1 like driver (FS#10285) */ 28#endif
27 29
28void button_init_device(void) 30void button_init_device(void)
29{ 31{
@@ -33,11 +35,17 @@ void button_init_device(void)
33 GPIOD_PIN(4) = 1<<4; 35 GPIOD_PIN(4) = 1<<4;
34 GPIOD_PIN(5) = 1<<5; 36 GPIOD_PIN(5) = 1<<5;
35 GPIOD_DIR |= ((1<<5) | (1<<4) | (1<<3)); 37 GPIOD_DIR |= ((1<<5) | (1<<4) | (1<<3));
38
39 /* get initial readings */
40 button_read_device();
41 button_read_device();
42 button_read_device();
36} 43}
37 44
38int button_read_device(void) 45int button_read_device(void)
39{ 46{
40 int result = 0; 47 static int row = 0;
48 static int buttons = 0;
41 static unsigned power_counter = 0; 49 static unsigned power_counter = 0;
42 50
43 if(button_hold()) 51 if(button_hold())
@@ -54,55 +62,84 @@ int button_read_device(void)
54 power_counter--; 62 power_counter--;
55 63
56 if (GPIOA_PIN(7) && !power_counter) 64 if (GPIOA_PIN(7) && !power_counter)
57 result |= BUTTON_POWER; 65 buttons |= BUTTON_POWER;
66 else
67 buttons &= ~BUTTON_POWER;
58 68
59 /* This is a keypad using D3-D5 as columns and D0-D2 as rows */ 69 /* This is a keypad using D3-D5 as columns and D0-D2 as rows */
70 switch (row) {
60 71
61 GPIOD_PIN(3) = 0x00; /* activate D3 */ 72 case 0:
62 asm volatile ("nop\nnop\nnop\nnop\nnop\n"); /* wait a bit for reliable results */ 73 buttons &= ~(BUTTON_VOL_UP | BUTTON_UP);
63 74
64 /* D3D0 is unused */ 75 (void)GPIOD_PIN(0); /* D3D0 is unused */
65 76
66 if (!GPIOD_PIN(1)) 77 if (!GPIOD_PIN(1))
67 result |= BUTTON_VOL_UP; 78 buttons |= BUTTON_VOL_UP;
68 79
69 if (!GPIOD_PIN(2)) 80 if (!GPIOD_PIN(2))
70 result |= BUTTON_UP; 81 buttons |= BUTTON_UP;
71 82
72 GPIOD_PIN(3) = 1<<3; 83 GPIOD_PIN(3) = 1<<3;
84 GPIOD_PIN(4) = 0x00;
85 row++;
86 break;
73 87
74 GPIOD_PIN(4) = 0x00; /* activate D4 */ 88 case 1:
75 asm volatile ("nop\nnop\nnop\nnop\nnop\n"); 89 buttons &= ~(BUTTON_LEFT | BUTTON_SELECT | BUTTON_RIGHT);
76 90
77 if (!GPIOD_PIN(0)) 91 if (!GPIOD_PIN(0))
78 result |= BUTTON_LEFT; 92 buttons |= BUTTON_LEFT;
79 93
80 if (!GPIOD_PIN(1)) 94 if (!GPIOD_PIN(1))
81 result |= BUTTON_SELECT; 95 buttons |= BUTTON_SELECT;
82 96
83 if (!GPIOD_PIN(2)) 97 if (!GPIOD_PIN(2))
84 result |= BUTTON_RIGHT; 98 buttons |= BUTTON_RIGHT;
85 99
86 GPIOD_PIN(4) = 1<<4; 100 GPIOD_PIN(4) = 1<<4;
101 GPIOD_PIN(5) = 0x00;
102 row++;
103 break;
87 104
88 GPIOD_PIN(5) = 0x00; /* activate D5 */ 105 case 2:
89 asm volatile ("nop\nnop\nnop\nnop\nnop\n"); 106 buttons &= ~(BUTTON_DOWN | BUTTON_VOL_DOWN | BUTTON_HOME);
90 107
91 if (!GPIOD_PIN(0)) 108 if (!GPIOD_PIN(0))
92 result |= BUTTON_DOWN; 109 buttons |= BUTTON_DOWN;
93 110
94 if (!GPIOD_PIN(1)) 111 if (!GPIOD_PIN(1))
95 result |= BUTTON_VOL_DOWN; 112 buttons |= BUTTON_VOL_DOWN;
96 113
97 if (!GPIOD_PIN(2)) 114 if (!GPIOD_PIN(2))
98 result |= BUTTON_HOME; 115 buttons |= BUTTON_HOME;
99 116
100 GPIOD_PIN(5) = 1<<5; 117 GPIOD_PIN(5) = 1<<5;
118 GPIOD_PIN(3) = 0x00;
101 119
102 return result; 120 default:
121 row = 0;
122 break;
123 }
124
125 return buttons;
103} 126}
104 127
105bool button_hold(void) 128bool button_hold(void)
106{ 129{
107 return (GPIOA_PIN(3) != 0); 130#ifndef BOOTLOADER
131 static bool hold_button_old = false;
132#endif
133 bool hold_button = (GPIOA_PIN(3) != 0);
134
135#ifndef BOOTLOADER
136 /* light handling */
137 if (hold_button != hold_button_old)
138 {
139 hold_button_old = hold_button;
140 backlight_hold_changed(hold_button);
141 }
142#endif /* BOOTLOADER */
143
144 return hold_button;
108} 145}