1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
44 int_btn
= BUTTON_NONE
;
46 val
= touchpad_read_device(data
, 4);
48 if (data
[0] == MEP_BUTTON_HEADER
)
52 int_btn
|= BUTTON_MENU
;
54 int_btn
|= BUTTON_PLAY
;
56 int_btn
|= BUTTON_NEXT
;
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
;
77 int button_read_device(void)
79 int buttons
= int_btn
;
81 static bool hold_button
= false;
84 hold_button_old
= hold_button
;
85 hold_button
= button_hold();
88 if (hold_button
!= hold_button_old
)
90 backlight_hold_changed(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);
112 reset_poweroff_timer();
113 buttons
= BUTTON_NONE
;
114 int_btn
= BUTTON_NONE
;
117 else return BUTTON_NONE
;
121 bool button_hold(void)
123 /* GPIOK 01000000B - HOLD when bit not set */
124 return (GPIOK_INPUT_VAL
& 0x40)?false:true;