blob: f85eeca9121b4123cf9d19219e2f2dea1e1c3ca0 [file] [log] [blame]
Karl Kurbjun7b97fe22007-09-20 04:46:41 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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 "system.h"
23#include "button.h"
24#include "kernel.h"
25#include "backlight.h"
26#include "adc.h"
27#include "system.h"
28#include "backlight-target.h"
Jonathan Gordon300f64c2007-09-20 09:08:40 +000029#include "uart-target.h"
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000030
Jonathan Gordon376429d2007-09-20 08:42:06 +000031#define BUTTON_TIMEOUT 50
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000032void button_init_device(void)
33{
Jonathan Gordon376429d2007-09-20 08:42:06 +000034 /* GIO is the power button, set as input */
35 outw(inw(IO_GIO_DIR0)|0x01, IO_GIO_DIR0);
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000036}
37
38inline bool button_hold(void)
39{
40 return false;
41}
42
43int button_read_device(void)
44{
Jonathan Gordon376429d2007-09-20 08:42:06 +000045 char data[5], c;
46 int i = 0;
47 int btn = BUTTON_NONE, timeout = BUTTON_TIMEOUT;
48
49 if ((inw(IO_GIO_BITSET0)&0x01) == 0)
50 btn |= BUTTON_POWER;
51
52 uartHeartbeat();
53 while (timeout > 0)
54 {
55 c = uartPollch(BUTTON_TIMEOUT*100);
56 if (c > -1)
57 {
58 if (i && data[0] == 0xf4)
59 {
60 data[i++] = c;
61 }
62 else if (c == 0xf4)
63 {
64 data[0] = c;
65 i = 1;
66 }
67
68 if (i == 5)
69 {
70 if (data[1]& (1<<7))
71 btn |= BUTTON_RC_HEART;
72 if (data[1]& (1<<6))
73 btn |= BUTTON_RC_MODE;
74 if (data[1]& (1<<5))
75 btn |= BUTTON_RC_VOL_DOWN;
76 if (data[1]& (1<<4))
77 btn |= BUTTON_RC_VOL_UP;
78 if (data[1]& (1<<3))
79 btn |= BUTTON_RC_REW;
80 if (data[1]& (1<<2))
81 btn |= BUTTON_RC_FF;
82 if (data[1]& (1<<1))
83 btn |= BUTTON_RC_DOWN;
84 if (data[1]& (1<<0))
85 btn |= BUTTON_RC_PLAY;
86 break;
87 }
88 }
89 timeout--;
90 }
91 return btn;
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000092}