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 "synaptics-mep.h"
27 /*#define LOGF_ENABLE*/
30 static int int_btn
= BUTTON_NONE
;
33 static bool hold_button_old
= false;
35 void button_init_device(void)
37 /* The touchpad is powered on and initialized in power-sa9200.c
38 since it needs to be ready for both buttons and button lights. */
42 * Button interrupt handler
49 int_btn
= BUTTON_NONE
;
51 val
= touchpad_read_device(data
, 4);
53 if (val
== MEP_BUTTON_HEADER
)
56 if (data
[1] & 0x1) int_btn
|= BUTTON_RIGHT
;
57 if (data
[1] & 0x2) int_btn
|= BUTTON_NEXT
;
58 if (data
[1] & 0x4) int_btn
|= BUTTON_PREV
;
59 if (data
[1] & 0x8) int_btn
|= BUTTON_LEFT
;
60 if (data
[2] & 0x1) int_btn
|= BUTTON_MENU
;
62 else if (val
== MEP_ABSOLUTE_HEADER
)
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 if ((val
> 0) && (val
<= 1365))
69 int_btn
|= BUTTON_DOWN
;
70 else if ((val
> 1365) && (val
<= 2730))
71 int_btn
|= BUTTON_PLAY
;
72 else if ((val
> 2730) && (val
<= 4095))
77 void button_init_device(void)
80 #endif /* BOOTLOADER */
82 bool button_hold(void)
84 return !(GPIOL_INPUT_VAL
& 0x40);
88 * Get button pressed from hardware
90 int button_read_device(void)
93 bool hold
= !(GPIOL_INPUT_VAL
& 0x40);
96 /* Backlight hold handling */
97 if (hold
!= hold_button_old
)
99 hold_button_old
= hold
;
100 backlight_hold_changed(hold
);
107 if (!(GPIOB_INPUT_VAL
& 0x20)) btn
|= BUTTON_POWER
;
108 if (!(GPIOF_INPUT_VAL
& 0x10)) btn
|= BUTTON_VOL_UP
;
109 if (!(GPIOF_INPUT_VAL
& 0x04)) btn
|= BUTTON_VOL_DOWN
;
114 bool headphones_inserted(void)
116 return (GPIOB_INPUT_VAL
& 0x10) ? false : true;