sd-as3525v1: set up bank selection data outside of the loop
[kugel-rb.git] / firmware / target / arm / as3525 / button-e200v2-fuze.c
blob2cbdcf5130a98361dc1b069e08940ee3abb20c46
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
23 #include "config.h"
24 #include "system.h"
25 #include "button.h"
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
34 #endif
36 #ifdef SANSA_E200V2
37 #define DBOP_BIT15_BUTTON BUTTON_REC
38 #endif
40 /* Buttons */
41 static bool hold_button = false;
42 #ifndef BOOTLOADER
43 static bool hold_button_old = false;
44 #endif
46 void button_init_device(void)
48 GPIOA_DIR |= (1<<1);
49 GPIOA_PIN(1) = (1<<1);
52 bool button_hold(void)
54 return hold_button;
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));
63 #endif
64 return dbop_din;
68 * Get button pressed from hardware
70 int button_read_device(void)
72 #ifdef SANSA_FUZE
73 static unsigned power_counter = 0;
74 #endif
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);
82 #ifndef BOOTLOADER
83 /* light handling */
84 if (hold_button != hold_button_old)
86 hold_button_old = hold_button;
87 backlight_hold_changed(hold_button);
89 #endif /* BOOTLOADER */
90 if (hold_button) {
91 #ifdef SANSA_FUZE
92 power_counter = HZ;
93 #endif
94 return 0;
97 /* push button handling */
98 if ((dbop_din & (1 << 2)) == 0)
99 btn |= BUTTON_UP;
100 if ((dbop_din & (1 << 3)) == 0)
101 btn |= BUTTON_LEFT;
102 if ((dbop_din & (1 << 4)) == 0)
103 btn |= BUTTON_SELECT;
104 if ((dbop_din & (1 << 5)) == 0)
105 btn |= BUTTON_RIGHT;
106 if ((dbop_din & (1 << 6)) == 0)
107 btn |= BUTTON_DOWN;
108 if ((dbop_din & (1 << 8)) != 0)
109 btn |= BUTTON_POWER;
110 if ((dbop_din & (1 << 15)) == 0)
111 btn |= DBOP_BIT15_BUTTON;
113 #ifdef SANSA_FUZE
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
116 * (fuze only)
118 if (power_counter > 0) {
119 power_counter--;
120 btn &= ~BUTTON_POWER;
122 #endif
124 return btn;