blob: 2a5983e97a7ba850134edf670c824e91b0525b8f [file] [log] [blame]
Daniel Stenberg86bff1c2006-08-03 20:18:31 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Barry Wardell
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/* Custom written for the H10 based on analysis of the GPIO data */
21
22
23#include <stdlib.h>
24#include "config.h"
25#include "cpu.h"
26#include "system.h"
27#include "button.h"
28#include "kernel.h"
29#include "backlight.h"
30#include "adc.h"
31#include "system.h"
32
33
34void button_init_device(void)
35{
Hristo Kovachev12041362006-08-11 09:51:04 +000036 /* No hardware initialisation required as it is done by the bootloader */
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000037}
38
39bool button_hold(void)
40{
41 return (GPIOA_INPUT_VAL & 0x40)?false:true;
42}
43
44/*
45 * Get button pressed from hardware
46 */
47int button_read_device(void)
48{
49 int btn = BUTTON_NONE;
Hristo Kovachev12041362006-08-11 09:51:04 +000050 unsigned char state;
51 static bool hold_button = false;
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000052
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000053#if 0
54 /* light handling */
55 if (hold_button && !button_hold())
56 {
57 backlight_on();
58 }
59#endif
60
61 hold_button = button_hold();
Hristo Kovachev12041362006-08-11 09:51:04 +000062 if (!hold_button)
Hristo Kovachev9dc0e622006-08-11 08:35:27 +000063 {
Hristo Kovachev12041362006-08-11 09:51:04 +000064 /* Read normal buttons */
65 state = GPIOA_INPUT_VAL & 0xf8;
66 if ((state & 0x8) == 0) btn |= BUTTON_FF;
67 if ((state & 0x10) == 0) btn |= BUTTON_PLAY;
68 if ((state & 0x20) == 0) btn |= BUTTON_REW;
69 if ((state & 0x40) == 0) btn |= BUTTON_RIGHT;
70 if ((state & 0x80) == 0) btn |= BUTTON_LEFT;
71
72 /* Read power button */
73 if ((GPIOB_INPUT_VAL & 0x1) == 0) btn |= BUTTON_POWER;
74
75 /* Read scroller */
76 if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) )
77 {
78 /* Scroller is pressed */
79 }
80 }
81
Daniel Stenberg86bff1c2006-08-03 20:18:31 +000082 return btn;
83}