Packard Bell Vibe 500: Improve/fix scrollstrip scrolling. The idea was taken from...
[kugel-rb.git] / firmware / target / arm / pbell / vibe500 / button-vibe500.c
blobb129cfea2d0bab9968b851d1327aa88f28651be3
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 "powermgmt.h"
27 #include "synaptics-mep.h"
29 static int int_btn = BUTTON_NONE;
30 static int old_pos = -1;
32 void button_init_device(void)
37 * Button interrupt handler
39 void button_int(void)
41 char data[4];
42 int val;
44 int_btn = BUTTON_NONE;
46 val = touchpad_read_device(data, 4);
48 if (data[0] == MEP_BUTTON_HEADER)
50 /* Buttons packet */
51 if (data[1] & 0x1)
52 int_btn |= BUTTON_MENU;
53 if (data[1] & 0x2)
54 int_btn |= BUTTON_PLAY;
55 if (data[1] & 0x4)
56 int_btn |= BUTTON_NEXT;
57 if (data[1] & 0x8)
58 int_btn |= BUTTON_PREV;
60 else if (data[0] == MEP_ABSOLUTE_HEADER)
62 if (data[1] & MEP_FINGER)
64 /* Absolute packet - the finger is on the vertical strip.
65 Position ranges from 1-4095, with 1 at the bottom. */
66 val = ((data[1] >> 4) << 8) | data[2]; /* position */
68 int scr_pos = val >> 8; /* split the scrollstrip into 16 regions */
69 if ((old_pos<scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_DOWN;
70 if ((old_pos>scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_UP;
71 old_pos = scr_pos;
73 else old_pos=-1;
77 int button_read_device(void)
79 int buttons = int_btn;
80 unsigned char state;
81 static bool hold_button = false;
82 bool hold_button_old;
84 hold_button_old = hold_button;
85 hold_button = button_hold();
87 #ifndef BOOTLOADER
88 if (hold_button != hold_button_old)
90 backlight_hold_changed(hold_button);
92 #endif
94 /* device buttons */
95 if (!hold_button)
97 /* Read Record, OK, C */
98 state = GPIOA_INPUT_VAL;
99 if ((state & 0x01)==0) buttons|=BUTTON_REC;
100 if ((state & 0x40)==0) buttons|=BUTTON_OK;
101 if ((state & 0x08)==0) buttons|=BUTTON_CANCEL;
103 /* Read POWER button */
104 if ((GPIOD_INPUT_VAL & 0x40)==0) buttons|=BUTTON_POWER;
106 /* Scrollstrip direct button post - much better response */
107 if ((buttons==BUTTON_UP) || (buttons==BUTTON_DOWN))
109 queue_post(&button_queue,buttons,0);
110 backlight_on();
111 buttonlight_on();
112 reset_poweroff_timer();
113 buttons = BUTTON_NONE;
114 int_btn = BUTTON_NONE;
117 else return BUTTON_NONE;
118 return buttons;
121 bool button_hold(void)
123 /* GPIOK 01000000B - HOLD when bit not set */
124 return (GPIOK_INPUT_VAL & 0x40)?false:true;