summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c')
-rw-r--r--firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c
new file mode 100644
index 0000000000..104c227378
--- /dev/null
+++ b/firmware/target/arm/as3525/sansa-clipzip/button-clipzip.c
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 François Dinel
11 * Copyright © 2008-2009 Rafaël Carré
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include "config.h"
24
25#include "button-target.h"
26#include "as3525v2.h"
27#include "kernel.h"
28#include "system-target.h"
29
30void button_init_device(void)
31{
32 /* GPIO A6, A7 and D6 are direct button inputs */
33 GPIOA_DIR &= ~(1 << 6);
34 GPIOA_DIR &= ~(1 << 7);
35 GPIOD_DIR &= ~(1 << 6);
36
37 /* GPIO C1, C2, C3, C4, C5 are used in a column/row key scan matrix */
38 GPIOC_DIR |= ((1 << 1) | (1 << 2));
39 GPIOC_DIR &= ~((1 << 3) | (1 << 4) | (1 << 5));
40}
41
42/* TODO:
43 Instead of using udelay to wait for buttons to settle, we could use a
44 simple state machine to alternate between key matrix rows (like we do on
45 the clip) and this way avoid burning cycles in the udelay.
46
47 TODO:
48 Figure out the real mappings from GPIOs to buttons.
49 The current mapping is just an educated guess.
50*/
51int button_read_device(void)
52{
53 int buttons = 0;
54
55 /* power */
56 if (GPIOD_PIN(6)) {
57 buttons |= BUTTON_POWER;
58 }
59
60 /* volume */
61 if (GPIOA_PIN(6)) {
62 buttons |= BUTTON_VOL_DOWN;
63 }
64 if (GPIOA_PIN(7)) {
65 buttons |= BUTTON_VOL_UP;
66 }
67
68 /* key matrix buttons, first row */
69 GPIOC_PIN(1) = (1 << 1);
70 GPIOC_PIN(2) = 0;
71 udelay(500);
72
73 if (GPIOC_PIN(3)) {
74 buttons |= BUTTON_LEFT;
75 }
76 if (GPIOC_PIN(4)) {
77 buttons |= BUTTON_SELECT;
78 }
79 if (GPIOC_PIN(5)) {
80 buttons |= BUTTON_RIGHT;
81 }
82
83 /* key matrix buttons, second row */
84 GPIOC_PIN(1) = 0;
85 GPIOC_PIN(2) = (1 << 2);
86 udelay(500);
87
88 if (GPIOC_PIN(3)) {
89 buttons |= BUTTON_UP;
90 }
91 if (GPIOC_PIN(4)) {
92 buttons |= BUTTON_HOME;
93 }
94 if (GPIOC_PIN(5)) {
95 buttons |= BUTTON_DOWN;
96 }
97
98 /* deselect scan rows */
99 GPIOC_PIN(2) = 0;
100
101 return buttons;
102}
103