summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-04-16 13:37:50 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-04-16 13:37:50 +0000
commitfeef1ed07690c5b027e441d1ffdc381d8e71038c (patch)
tree7edac39fcef9a755c72d9cecd16ae2e029bcdb8f
parentefca1cd39a29afa32a00748e432513c9eec066aa (diff)
downloadrockbox-feef1ed07690c5b027e441d1ffdc381d8e71038c.tar.gz
rockbox-feef1ed07690c5b027e441d1ffdc381d8e71038c.zip
Gary's code for reading the Recorder's keyboard. This can't yet be used in
the simulator as we need to tweak how it reads raw input when we simulate this. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@101 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/button.c151
-rw-r--r--firmware/button.h47
2 files changed, 198 insertions, 0 deletions
diff --git a/firmware/button.c b/firmware/button.c
new file mode 100644
index 0000000000..2bea49879c
--- /dev/null
+++ b/firmware/button.c
@@ -0,0 +1,151 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19/*
20 * Archos Jukebox Recorder button functions
21 */
22
23#include "config.h"
24
25#ifdef HAVE_RECORDER_KEYPAD
26
27#include "types.h"
28#include "sh7034.h"
29#include "button.h"
30
31/* AJBR buttons are connected to the CPU as follows:
32 *
33 * ON and OFF are connected to separate port B input pins.
34 *
35 * F1, F2, F3, and UP are connected to the AN4 analog input, each through
36 * a separate voltage divider. The voltage on AN4 depends on which button
37 * (or none, or a combination) is pressed.
38 *
39 * DOWN, PLAY, LEFT, and RIGHT are likewise connected to AN5. */
40
41/* Button voltage levels on AN4 and AN5 */
42#define LEVEL1 50
43#define LEVEL2 125
44#define LEVEL3 175
45#define LEVEL4 225
46
47/* Number of calls to get_button for a button to stop bouncing
48 * and to be considered held down.
49 * Should really use a hardware timer for this.
50 */
51#define BOUNCE_COUNT 200
52#define HOLD_COUNT 10000
53
54static int last; /* Last button pressed */
55static int count; /* Number of calls button has been down */
56
57
58/*
59 *Initialize buttons
60 */
61void button_init()
62{
63#ifndef SIMULATOR
64 /* Set PB4 and PB8 as input pins */
65 PBCR1 &= 0xfffc; /* PB8MD = 00 */
66 PBCR2 &= 0xfcff; /* PB4MD = 00 */
67 PBIOR &= ~(PBDR_BTN_ON|PBDR_BTN_OFF); /* Inputs */
68
69 /* Set A/D to scan AN4 and AN5.
70 * This needs to be changed to scan other analog pins
71 * for battery level, etc. */
72 ADCSR = 0;
73 ADCR = 0;
74 ADCSR = ADCSR_ADST | ADCSR_SCAN | 0x5;
75#endif
76 last = BUTTON_NONE;
77 count = 0;
78}
79
80/*
81 * Get button pressed from hardware
82 */
83static int get_raw_button (void)
84{
85 /* Check port B pins for ON and OFF */
86 int data = PBDR;
87 if ((data & PBDR_BTN_ON) == 0)
88 return BUTTON_ON;
89 else if ((data & PBDR_BTN_OFF) == 0)
90 return BUTTON_OFF;
91
92 /* Check AN4 pin for F1-3 and UP */
93 data = ADDRAH;
94 if (data >= LEVEL4)
95 return BUTTON_F3;
96 else if (data >= LEVEL3)
97 return BUTTON_UP;
98 else if (data >= LEVEL2)
99 return BUTTON_F2;
100 else if (data >= LEVEL1)
101 return BUTTON_F1;
102
103 /* Check AN5 pin for DOWN, PLAY, LEFT, RIGHT */
104 data = ADDRBH;
105 if (data >= LEVEL4)
106 return BUTTON_DOWN;
107 else if (data >= LEVEL3)
108 return BUTTON_PLAY;
109 else if (data >= LEVEL2)
110 return BUTTON_LEFT;
111 else if (data >= LEVEL1)
112 return BUTTON_RIGHT;
113
114 return BUTTON_NONE;
115}
116
117/*
118 * Get the currently pressed button.
119 * Returns one of BUTTON_xxx codes, with possibly a modifier bit set.
120 * No modifier bits are set when the button is first pressed.
121 * BUTTON_HELD bit is while the button is being held.
122 * BUTTON_REL bit is set when button has been released.
123 */
124int button_get(void)
125{
126 int btn = get_raw_button();
127 int ret;
128
129 /* Last button pressed is still down */
130 if (btn != BUTTON_NONE && btn == last) {
131 count++;
132 if (count == BOUNCE_COUNT)
133 return btn;
134 else if (count >= HOLD_COUNT)
135 return btn | BUTTON_HELD;
136 else
137 return BUTTON_NONE;
138 }
139
140 /* Last button pressed now released */
141 if (btn == BUTTON_NONE && last != BUTTON_NONE)
142 ret = last | BUTTON_REL;
143 else
144 ret = BUTTON_NONE;
145
146 last = btn;
147 count = 0;
148 return ret;
149}
150
151#endif /* HAVE_RECORDER_KEYPAD */
diff --git a/firmware/button.h b/firmware/button.h
new file mode 100644
index 0000000000..93ac4b8eac
--- /dev/null
+++ b/firmware/button.h
@@ -0,0 +1,47 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
21
22#ifdef HAVE_RECORDER_KEYPAD
23/*
24 * Archos Jukebox Recorder button functions
25 */
26
27/* Button codes */
28#define BUTTON_NONE 0x0000
29#define BUTTON_ON 0x0001
30#define BUTTON_OFF 0x0002
31#define BUTTON_PLAY 0x0004
32#define BUTTON_UP 0x0010
33#define BUTTON_DOWN 0x0020
34#define BUTTON_LEFT 0x0040
35#define BUTTON_RIGHT 0x0080
36#define BUTTON_F1 0x0100
37#define BUTTON_F2 0x0200
38#define BUTTON_F3 0x0400
39
40/* Button modifiers */
41#define BUTTON_HELD 0x4000
42#define BUTTON_REL 0x8000
43
44void button_init (void);
45int get_button (void);
46
47#endif