hdd6330: enable full touchpad support - code cleanup, all buttons should work now...
[kugel-rb.git] / firmware / target / arm / philips / hdd6330 / button-hdd6330.c
blob1d15b11a1ef1184f8ba890db8c03ca43e7b9404c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Mark Arigo
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "system.h"
23 #include "button.h"
24 #include "backlight.h"
25 #include "powermgmt.h"
26 #include "synaptics-mep.h"
28 /*#define LOGF_ENABLE*/
29 #include "logf.h"
31 static int int_btn = BUTTON_NONE;
32 static int old_pos = -1;
34 static int scroll_repeat = BUTTON_NONE;
35 static int repeat = 0;
38 * Generate a click sound from the player (not in headphones yet)
39 * TODO: integrate this with the "key click" option
41 void button_click(void)
43 GPO32_ENABLE |= 0x2000;
44 GPO32_VAL |= 0x2000;
45 udelay(1000);
46 GPO32_VAL &= ~0x2000;
49 #ifndef BOOTLOADER
50 void button_init_device(void)
52 /* The touchpad is powered on and initialized in power-hdd1630.c
53 since it needs to be ready for both buttons and button lights. */
57 * Button interrupt handler
59 void button_int(void)
61 char data[4];
62 int val;
64 int_btn = BUTTON_NONE;
66 val = touchpad_read_device(data, 4);
68 if (data[0] == MEP_BUTTON_HEADER)
70 /* Buttons packet */
71 if (data[1] & 0x1)
72 int_btn |= BUTTON_LEFT;
73 if (data[1] & 0x2)
74 int_btn |= BUTTON_MENU;
75 if (data[1] & 0x4)
76 int_btn |= BUTTON_RIGHT;
77 if (data[1] & 0x8)
78 int_btn |= BUTTON_VIEW;
80 else if ((data[0] == MEP_ABSOLUTE_HEADER))
82 if (data[1] & MEP_FINGER)
84 /* Absolute packet - the finger is on the horizontal strip.
85 Position ranges from 1-4095, with 1 at the bottom. */
86 val = ((data[1] >> 4) << 8) | data[2]; /* position */
88 /* The HDD63x0 actually has 2 scrollbars. One vertical and one horizontal
89 (where the prev, play, and next buttons are). Because of that, we need to know
90 which sensor is reporting data. */
91 if ((data[3] >> 6) == 1) /* index = 1 */
93 if ((val > 0) && (val <= 1365))
94 int_btn |= BUTTON_PREV;
95 else if ((val > 1365) && (val <= 2730))
96 int_btn |= BUTTON_PLAY;
97 else if ((val > 2730) && (val <= 4095))
98 int_btn |= BUTTON_NEXT;
99 } else
101 int scr_pos = val >> 8; /* split the scrollstrip into 16 regions */
102 if ((old_pos<scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_UP;
103 if ((old_pos>scr_pos)&&(old_pos!=-1)) int_btn = BUTTON_DOWN;
105 old_pos = scr_pos;
107 /* repeat button */
108 repeat = 0;
109 if (int_btn != BUTTON_NONE)
111 if (int_btn != scroll_repeat)
112 scroll_repeat = int_btn;
113 else repeat = BUTTON_REPEAT;
117 else
119 old_pos = -1;
120 scroll_repeat = BUTTON_NONE;
124 #else
125 void button_init_device(void){}
126 #endif /* bootloader */
128 bool button_hold(void)
130 return !(GPIOJ_INPUT_VAL & 0x8);
134 * Get button pressed from hardware
136 int button_read_device(void)
138 static int btn_old = BUTTON_NONE;
139 int btn = int_btn;
141 /* Hold */
142 if(button_hold())
143 return BUTTON_NONE;
145 /* Device buttons */
146 if (!(GPIOA_INPUT_VAL & 0x02)) btn |= BUTTON_VOL_UP;
147 if (!(GPIOA_INPUT_VAL & 0x04)) btn |= BUTTON_VOL_DOWN;
148 if (!(GPIOD_INPUT_VAL & 0x40)) btn |= BUTTON_POWER;
150 /* Scrollstrip direct button post - much better response */
151 if ((btn == BUTTON_UP) || (btn == BUTTON_DOWN))
153 queue_post(&button_queue,btn|repeat,0);
154 backlight_on();
155 buttonlight_on();
156 reset_poweroff_timer();
158 int_btn = BUTTON_NONE;
159 repeat = BUTTON_NONE;
160 btn = BUTTON_NONE;
163 if ((btn != btn_old) && (btn != BUTTON_NONE))
164 button_click();
166 btn_old = btn;
168 return btn;
171 bool headphones_inserted(void)
173 return (GPIOE_INPUT_VAL & 0x80) ? true : false;