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 "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
43 int_btn
= BUTTON_NONE
;
45 val
= touchpad_read_device(data
, 4);
47 if (val
== MEP_BUTTON_HEADER
)
51 int_btn
|= BUTTON_MENU
;
53 int_btn
|= BUTTON_PLAY
;
55 int_btn
|= BUTTON_NEXT
;
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 */
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
;
76 int button_read_device(void)
78 int buttons
= int_btn
;
80 static bool hold_button
= false;
83 hold_button_old
= hold_button
;
84 hold_button
= button_hold();
87 if (hold_button
!= hold_button_old
)
89 backlight_hold_changed(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
;
109 bool button_hold(void)
111 /* GPIOK 01000000B - HOLD when bit not set */
112 return (GPIOK_INPUT_VAL
& 0x40)?false:true;