slow - but working - IRQ based uart/button driver.
[Rockbox.git] / firmware / target / arm / olympus / mrobe-500 / button-mr500.c
blob1d0d2714a8d5430fb51e7763e53070267a993f68
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Karl Kurbjun
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 "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"
29 #include "uart-target.h"
31 #define BUTTON_TIMEOUT 50
33 #define BUTTON_START_BYTE 0xF0
34 #define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */
35 /* but always the same one for the session? */
37 void button_init_device(void)
39 /* GIO is the power button, set as input */
40 IO_GIO_DIR0 |= 0x01;
43 inline bool button_hold(void)
45 return false;
48 int button_read_device(void)
50 char data[5], c;
51 int i = 0;
52 int btn = BUTTON_NONE;
54 if ((IO_GIO_BITSET0&0x01) == 0)
55 btn |= BUTTON_POWER;
57 uart1_heartbeat();
58 while (uartAvailable())
60 if (uart1_getch(&c))
62 if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2))
64 data[i++] = c;
66 else if (c == BUTTON_START_BYTE ||
67 c == BUTTON_START_BYTE2)
69 data[0] = c;
70 i = 1;
73 if (i == 5)
75 if (data[1]& (1<<7))
76 btn |= BUTTON_RC_HEART;
77 if (data[1]& (1<<6))
78 btn |= BUTTON_RC_MODE;
79 if (data[1]& (1<<5))
80 btn |= BUTTON_RC_VOL_DOWN;
81 if (data[1]& (1<<4))
82 btn |= BUTTON_RC_VOL_UP;
83 if (data[1]& (1<<3))
84 btn |= BUTTON_RC_REW;
85 if (data[1]& (1<<2))
86 btn |= BUTTON_RC_FF;
87 if (data[1]& (1<<1))
88 btn |= BUTTON_RC_DOWN;
89 if (data[1]& (1<<0))
90 btn |= BUTTON_RC_PLAY;
91 break;
95 return btn;