Add initial Packard Bell Vibe 500 port, by Szymon Dziok
[kugel-rb.git] / firmware / target / arm / pbell / vibe500 / button-vibe500.c
blobc95e996ef86a3f66f32561bac7c40dca808d6357
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
10 * Copyright (C) 2009 Szymon Dziok
11 * Based on the Iriver H10 and the Philips HD1630 code
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #include "system.h"
24 #include "button.h"
25 #include "backlight.h"
26 #include "synaptics-mep.h"
28 static int int_btn = BUTTON_NONE;
29 static int old_pos = -1;
31 void button_init_device(void)
36 * Button interrupt handler
38 void button_int(void)
40 char data[4];
41 int val;
43 int_btn = BUTTON_NONE;
45 val = touchpad_read_device(data, 4);
47 if (val == MEP_BUTTON_HEADER)
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;
59 else if (val == MEP_ABSOLUTE_HEADER)
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 */
65 if (val > 0)
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;
72 else old_pos=-1;
76 int button_read_device(void)
78 int buttons = int_btn;
79 unsigned char state;
80 static bool hold_button = false;
81 bool hold_button_old;
83 hold_button_old = hold_button;
84 hold_button = button_hold();
86 #ifndef BOOTLOADER
87 if (hold_button != hold_button_old)
89 backlight_hold_changed(hold_button);
91 #endif
93 /* device buttons */
94 if (!hold_button)
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;
102 /* Read POWER button */
103 if ((GPIOD_INPUT_VAL & 0x40)==0) buttons|=BUTTON_POWER;
105 else return BUTTON_NONE;
106 return buttons;
109 bool button_hold(void)
111 /* GPIOK 01000000B - HOLD when bit not set */
112 return (GPIOK_INPUT_VAL & 0x40)?false:true;