1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
24 #include "backlight.h"
25 #include "powermgmt.h"
26 #include "synaptics-mep.h"
28 /*#define LOGF_ENABLE*/
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;
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
64 int_btn
= BUTTON_NONE
;
66 val
= touchpad_read_device(data
, 4);
68 if (data
[0] == MEP_BUTTON_HEADER
)
72 int_btn
|= BUTTON_LEFT
;
74 int_btn
|= BUTTON_MENU
;
76 int_btn
|= BUTTON_RIGHT
;
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
;
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
;
109 if (int_btn
!= BUTTON_NONE
)
111 if (int_btn
!= scroll_repeat
)
112 scroll_repeat
= int_btn
;
113 else repeat
= BUTTON_REPEAT
;
120 scroll_repeat
= BUTTON_NONE
;
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
;
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);
156 reset_poweroff_timer();
158 int_btn
= BUTTON_NONE
;
159 repeat
= BUTTON_NONE
;
163 if ((btn
!= btn_old
) && (btn
!= BUTTON_NONE
))
171 bool headphones_inserted(void)
173 return (GPIOE_INPUT_VAL
& 0x80) ? true : false;