Button driver for Logik DAX, plus some changes to the debug info displayed in the...
[Rockbox.git] / firmware / target / arm / tcc77x / logikdax / button-logikdax.c
blob8e4279b699e898e3ffdab639300f98c72b1d2fb3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Dave Chapman
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #include "cpu.h"
22 #include "button.h"
23 #include "adc.h"
25 /*
27 Results of button testing:
29 HOLD: GPIOA & 0x0002 (0=pressed, 0x0002 = released)
30 POWER: GPIOA & 0x8000 (0=pressed, 0x8000 = released)
32 ADC[0]: (approx values)
34 RIGHT - 0x37
35 LEFT - 0x7f
36 JOYSTICK PRESS - 0xc7
37 UP - 0x11e
38 DOWN - 0x184
39 MODE - 0x1f0/0x1ff
40 PRESET - 0x268/0x269
41 REC - 0x2dd
43 Values of ADC[0] tested in OF disassembly: 0x50, 0x96, 0xdc, 0x208, 0x384
47 void button_init_device(void)
49 /* Nothing to do */
52 int button_read_device(void)
54 int btn = BUTTON_NONE;
55 int adc;
57 adc = adc_read(ADC_BUTTONS);
59 if (adc < 0x384) {
60 if (adc < 0x140) {
61 if (adc < 0x96) {
62 if (adc < 0x50) {
63 btn |= BUTTON_RIGHT; /* 0x00..0x4f */
64 } else {
65 btn |= BUTTON_LEFT; /* 0x50..0x95 */
67 } else {
68 if (adc < 0xe0) {
69 btn |= BUTTON_SELECT; /* 0x96..0xdf */
70 } else {
71 btn |= BUTTON_UP; /* 0xe0..0x13f */
74 } else {
75 if (adc < 0x208) {
76 if (adc < 0x1b0) {
77 btn |= BUTTON_DOWN; /* 0x140..0x1af */
78 } else {
79 btn |= BUTTON_MODE; /* 0x1b0..0x207 */
81 } else {
82 if (adc < 0x290) {
83 btn |= BUTTON_PRESET; /* 0x208..0x28f */
84 } else {
85 btn |= BUTTON_REC; /* 0x290..0x383 */
91 if (!(GPIOA & 0x2))
92 btn |= BUTTON_HOLD;
94 if (!(GPIOA & 0x8000))
95 btn |= BUTTON_POWERPLAY;
97 return btn;