1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Thomas Martitz
11 * Copyright (C) 2008 by Dominik Wenger
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 ****************************************************************************/
26 #include "button-target.h"
27 #include "backlight.h"
28 #include "dbop-as3525.h"
30 extern void scrollwheel(unsigned wheel_value
);
32 #if defined(SANSA_FUZE)
33 #define DBOP_BIT15_BUTTON BUTTON_HOME
37 #define DBOP_BIT15_BUTTON BUTTON_REC
41 static bool hold_button
= false;
43 static bool hold_button_old
= false;
46 void button_init_device(void)
49 GPIOA_PIN(1) = (1<<1);
52 bool button_hold(void)
57 unsigned short button_read_dbop(void)
59 unsigned dbop_din
= dbop_read_input();
60 #if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
61 /* scroll wheel handling */
62 scrollwheel((dbop_din
>> 13) & (1<<1|1<<0));
68 * Get button pressed from hardware
70 int button_read_device(void)
73 static unsigned power_counter
= 0;
75 unsigned short dbop_din
;
76 int btn
= BUTTON_NONE
;
78 dbop_din
= button_read_dbop();
80 /* hold button handling */
81 hold_button
= ((dbop_din
& (1<<12)) != 0);
84 if (hold_button
!= hold_button_old
)
86 hold_button_old
= hold_button
;
87 backlight_hold_changed(hold_button
);
89 #endif /* BOOTLOADER */
97 /* push button handling */
98 if ((dbop_din
& (1 << 2)) == 0)
100 if ((dbop_din
& (1 << 3)) == 0)
102 if ((dbop_din
& (1 << 4)) == 0)
103 btn
|= BUTTON_SELECT
;
104 if ((dbop_din
& (1 << 5)) == 0)
106 if ((dbop_din
& (1 << 6)) == 0)
108 if ((dbop_din
& (1 << 8)) != 0)
110 if ((dbop_din
& (1 << 15)) == 0)
111 btn
|= DBOP_BIT15_BUTTON
;
114 /* read power on bit 8, but not if hold button was just released, since
115 * you basically always hit power due to the slider mechanism after releasing
118 if (power_counter
> 0) {
120 btn
&= ~BUTTON_POWER
;