blob: 00049b3c8b4bca53d994db5eab99b44ef52f60e5 [file] [log] [blame]
Marc Guayb93667b2008-06-21 15:18:36 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Marc Guayb362b7f2008-06-21 16:07:59 +00008 * $Id$
Marc Guayb93667b2008-06-21 15:18:36 +00009 *
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.
Marc Guayb93667b2008-06-21 15:18:36 +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
27void button_init_device(void)
28{
29 GPIOA_DIR |= 0xC;
30}
31
32int button_read_device(void)
33{
34 int btn = BUTTON_NONE;
35
36 if (!button_hold()){
37 GPIOA |= 0x4;
38 GPIOA &= ~0x8;
39
40 int i=20; while (i--);
41
42 if (GPIOA & 0x10) btn |= BUTTON_PLAYPAUSE; /* up */
43 if (GPIOA & 0x20) btn |= BUTTON_RIGHT;
44 if (GPIOA & 0x40) btn |= BUTTON_LEFT;
45
46 GPIOA |= 0x8;
47 GPIOA &= ~0x4;
48
49 i=20; while (i--);
50
51 if (GPIOA & 0x10) btn |= BUTTON_VOLUP;
52 if (GPIOA & 0x20) btn |= BUTTON_VOLDOWN;
53 if (GPIOA & 0x40) btn |= BUTTON_REPEATAB; /* down */
54
55 if (GPIOA & 0x80) btn |= BUTTON_SELECT;
56 if (GPIOA & 0x100) btn |= BUTTON_MENU;
57 }
58 return btn;
59}
60
61bool button_hold(void)
62{
63 return (GPIOA & 0x2);
64}