diff options
Diffstat (limited to 'firmware/target/arm/tcc77x/m200/button-m200.c')
-rw-r--r-- | firmware/target/arm/tcc77x/m200/button-m200.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/firmware/target/arm/tcc77x/m200/button-m200.c b/firmware/target/arm/tcc77x/m200/button-m200.c new file mode 100644 index 0000000000..fec745ae99 --- /dev/null +++ b/firmware/target/arm/tcc77x/m200/button-m200.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Dave Chapman | ||
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 | #include "cpu.h" | ||
22 | #include "button.h" | ||
23 | #include "adc.h" | ||
24 | |||
25 | /* | ||
26 | |||
27 | Results of button testing (viewing ADC values whilst pressing buttons): | ||
28 | |||
29 | HOLD: GPIOB & 0x0200 (0=hold active, 0x0200 = hold inactive) | ||
30 | |||
31 | ADC[1]: (approx values) | ||
32 | |||
33 | Idle - 0x3ff | ||
34 | MENU - unknown | ||
35 | |||
36 | REPEAT/AB - 0x03? | ||
37 | LEFT - 0x07?-0x08? | ||
38 | SELECT - 0x0c? | ||
39 | RIGHT - 0x11? | ||
40 | |||
41 | PLAY/PAUSE - 0x17?-0x018? | ||
42 | VOL UP - 0x1e?-0x01f? | ||
43 | VOL DOWN - 0x26? | ||
44 | |||
45 | */ | ||
46 | |||
47 | void button_init_device(void) | ||
48 | { | ||
49 | /* Nothing to do */ | ||
50 | } | ||
51 | |||
52 | int button_read_device(void) | ||
53 | { | ||
54 | int btn = BUTTON_NONE; | ||
55 | int adc; | ||
56 | |||
57 | /* TODO - determine how to detect BUTTON_MENU - it doesn't appear to | ||
58 | be connected to a GPIO or to an ADC | ||
59 | */ | ||
60 | |||
61 | adc = adc_read(ADC_BUTTONS); | ||
62 | |||
63 | if (adc < 0x384) { | ||
64 | if (adc < 0x140) { | ||
65 | if (adc < 0x96) { | ||
66 | if (adc < 0x50) { | ||
67 | btn |= BUTTON_REPEATAB; /* 0x00..0x4f */ | ||
68 | } else { | ||
69 | btn |= BUTTON_LEFT; /* 0x50..0x95 */ | ||
70 | } | ||
71 | } else { | ||
72 | if (adc < 0xe0) { | ||
73 | btn |= BUTTON_SELECT; /* 0x96..0xdf */ | ||
74 | } else { | ||
75 | btn |= BUTTON_RIGHT; /* 0xe0..0x13f */ | ||
76 | } | ||
77 | } | ||
78 | } else { | ||
79 | if (adc < 0x208) { | ||
80 | if (adc < 0x1b0) { | ||
81 | btn |= BUTTON_PLAYPAUSE; /* 0x140..0x1af */ | ||
82 | } else { | ||
83 | btn |= BUTTON_VOLUP; /* 0x1b0..0x207 */ | ||
84 | } | ||
85 | } else { | ||
86 | btn |= BUTTON_VOLDOWN; /* 0x209..0x383 */ | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | return btn; | ||
92 | } | ||
93 | |||
94 | bool button_hold(void) | ||
95 | { | ||
96 | return (GPIOB & 0x200)?false:true; | ||
97 | } | ||