blob: a37fe1302cf2586bb2fe9c46bc389e859d31818d [file] [log] [blame]
Dave Chapmanf2042982008-05-02 19:12:09 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Dave Chapman
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Dave Chapmanf2042982008-05-02 19:12:09 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "cpu.h"
24#include "button.h"
25#include "adc.h"
26
27/*
28
29Results of button testing (viewing ADC values whilst pressing buttons):
30
31HOLD: GPIOB & 0x0200 (0=hold active, 0x0200 = hold inactive)
32
33ADC[1]: (approx values)
34
35Idle - 0x3ff
36MENU - unknown
37
38REPEAT/AB - 0x03?
39LEFT - 0x07?-0x08?
40SELECT - 0x0c?
41RIGHT - 0x11?
42
43PLAY/PAUSE - 0x17?-0x018?
44VOL UP - 0x1e?-0x01f?
45VOL DOWN - 0x26?
46
47*/
48
49void button_init_device(void)
50{
51 /* Nothing to do */
52}
53
54int button_read_device(void)
55{
56 int btn = BUTTON_NONE;
57 int adc;
58
59 /* TODO - determine how to detect BUTTON_MENU - it doesn't appear to
60 be connected to a GPIO or to an ADC
61 */
62
63 adc = adc_read(ADC_BUTTONS);
64
65 if (adc < 0x384) {
66 if (adc < 0x140) {
67 if (adc < 0x96) {
68 if (adc < 0x50) {
69 btn |= BUTTON_REPEATAB; /* 0x00..0x4f */
70 } else {
71 btn |= BUTTON_LEFT; /* 0x50..0x95 */
72 }
73 } else {
74 if (adc < 0xe0) {
75 btn |= BUTTON_SELECT; /* 0x96..0xdf */
76 } else {
77 btn |= BUTTON_RIGHT; /* 0xe0..0x13f */
78 }
79 }
80 } else {
81 if (adc < 0x208) {
82 if (adc < 0x1b0) {
83 btn |= BUTTON_PLAYPAUSE; /* 0x140..0x1af */
84 } else {
85 btn |= BUTTON_VOLUP; /* 0x1b0..0x207 */
86 }
87 } else {
88 btn |= BUTTON_VOLDOWN; /* 0x209..0x383 */
89 }
90 }
91 }
92
93 return btn;
94}
95
96bool button_hold(void)
97{
98 return (GPIOB & 0x200)?false:true;
99}