summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sansa-clipv2/button-clip.c')
-rw-r--r--firmware/target/arm/as3525/sansa-clipv2/button-clip.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/firmware/target/arm/as3525/sansa-clipv2/button-clip.c b/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
new file mode 100644
index 0000000000..4291665e3d
--- /dev/null
+++ b/firmware/target/arm/as3525/sansa-clipv2/button-clip.c
@@ -0,0 +1,108 @@
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#include "button-target.h"
23#include "as3525v2.h"
24#include "kernel.h"
25
26/* FIXME : use Clipv1 like driver (FS#10285) */
27
28void button_init_device(void)
29{
30 GPIOA_DIR &= ~((1<<7) | (1<<3));
31 GPIOD_DIR &= ~((1<<2) | (1<<1) | (1<<0));
32 GPIOD_PIN(3) = 1<<3;
33 GPIOD_PIN(4) = 1<<4;
34 GPIOD_PIN(5) = 1<<5;
35 GPIOD_DIR |= ((1<<5) | (1<<4) | (1<<3));
36}
37
38int button_read_device(void)
39{
40 int result = 0;
41 static unsigned power_counter = 0;
42
43 if(button_hold())
44 {
45 power_counter = HZ;
46 return 0;
47 }
48
49 /* direct GPIO connections */
50 /* read power, but not if hold button was just released, since
51 * you basically always hit power due to the slider mechanism after
52 * releasing hold (wait 1 sec) */
53 if (power_counter)
54 power_counter--;
55
56 if (GPIOA_PIN(7) && !power_counter)
57 result |= BUTTON_POWER;
58
59 /* This is a keypad using D3-D5 as columns and D0-D2 as rows */
60
61 GPIOD_PIN(3) = 0x00; /* activate D3 */
62 asm volatile ("nop\nnop\nnop\nnop\nnop\n"); /* wait a bit for reliable results */
63
64 /* D3D0 is unused */
65
66 if (!GPIOD_PIN(1))
67 result |= BUTTON_VOL_UP;
68
69 if (!GPIOD_PIN(2))
70 result |= BUTTON_UP;
71
72 GPIOD_PIN(3) = 1<<3;
73
74 GPIOD_PIN(4) = 0x00; /* activate D4 */
75 asm volatile ("nop\nnop\nnop\nnop\nnop\n");
76
77 if (!GPIOD_PIN(0))
78 result |= BUTTON_LEFT;
79
80 if (!GPIOD_PIN(1))
81 result |= BUTTON_SELECT;
82
83 if (!GPIOD_PIN(2))
84 result |= BUTTON_RIGHT;
85
86 GPIOD_PIN(4) = 1<<4;
87
88 GPIOD_PIN(5) = 0x00; /* activate D5 */
89 asm volatile ("nop\nnop\nnop\nnop\nnop\n");
90
91 if (!GPIOD_PIN(0))
92 result |= BUTTON_DOWN;
93
94 if (!GPIOD_PIN(1))
95 result |= BUTTON_VOL_DOWN;
96
97 if (!GPIOD_PIN(2))
98 result |= BUTTON_HOME;
99
100 GPIOD_PIN(5) = 1<<5;
101
102 return result;
103}
104
105bool button_hold(void)
106{
107 return (GPIOA_PIN(3) != 0);
108}