summaryrefslogtreecommitdiff
path: root/firmware/target/arm/pbell/vibe500/button-vibe500.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/pbell/vibe500/button-vibe500.c')
-rw-r--r--firmware/target/arm/pbell/vibe500/button-vibe500.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/firmware/target/arm/pbell/vibe500/button-vibe500.c b/firmware/target/arm/pbell/vibe500/button-vibe500.c
new file mode 100644
index 0000000000..c95e996ef8
--- /dev/null
+++ b/firmware/target/arm/pbell/vibe500/button-vibe500.c
@@ -0,0 +1,114 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2009 Szymon Dziok
11 * Based on the Iriver H10 and the Philips HD1630 code
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include "system.h"
24#include "button.h"
25#include "backlight.h"
26#include "synaptics-mep.h"
27
28static int int_btn = BUTTON_NONE;
29static int old_pos = -1;
30
31void button_init_device(void)
32{
33}
34
35/*
36 * Button interrupt handler
37 */
38void button_int(void)
39{
40 char data[4];
41 int val;
42
43 int_btn = BUTTON_NONE;
44
45 val = touchpad_read_device(data, 4);
46
47 if (val == MEP_BUTTON_HEADER)
48 {
49 /* Buttons packet */
50 if (data[1] & 0x1)
51 int_btn |= BUTTON_MENU;
52 if (data[1] & 0x2)
53 int_btn |= BUTTON_PLAY;
54 if (data[1] & 0x4)
55 int_btn |= BUTTON_NEXT;
56 if (data[1] & 0x8)
57 int_btn |= BUTTON_PREV;
58 }
59 else if (val == MEP_ABSOLUTE_HEADER)
60 {
61 /* Absolute packet - the finger is on the vertical strip.
62 Position ranges from 1-4095, with 1 at the bottom. */
63 val = ((data[1] >> 4) << 8) | data[2]; /* position */
64
65 if (val > 0)
66 {
67 int scr_pos = val >> 8; /* split the scrollstrip into 16 regions */
68 if ((old_pos<scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_DOWN;
69 if ((old_pos>scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_UP;
70 old_pos = scr_pos;
71 }
72 else old_pos=-1;
73 }
74}
75
76int button_read_device(void)
77{
78 int buttons = int_btn;
79 unsigned char state;
80 static bool hold_button = false;
81 bool hold_button_old;
82
83 hold_button_old = hold_button;
84 hold_button = button_hold();
85
86#ifndef BOOTLOADER
87 if (hold_button != hold_button_old)
88 {
89 backlight_hold_changed(hold_button);
90 }
91#endif
92
93 /* device buttons */
94 if (!hold_button)
95 {
96 /* Read Record, OK, C */
97 state = GPIOA_INPUT_VAL;
98 if ((state & 0x01)==0) buttons|=BUTTON_REC;
99 if ((state & 0x40)==0) buttons|=BUTTON_OK;
100 if ((state & 0x08)==0) buttons|=BUTTON_CANCEL;
101
102 /* Read POWER button */
103 if ((GPIOD_INPUT_VAL & 0x40)==0) buttons|=BUTTON_POWER;
104 }
105 else return BUTTON_NONE;
106 return buttons;
107}
108
109bool button_hold(void)
110{
111 /* GPIOK 01000000B - HOLD when bit not set */
112 return (GPIOK_INPUT_VAL & 0x40)?false:true;
113}
114