1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 by Thomas Martitz
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 ****************************************************************************/
25 #include "backlight.h"
27 extern void scrollwheel(unsigned wheel_value
);
29 #ifdef HAS_BUTTON_HOLD
30 static bool hold_button
= false;
32 void button_init_device(void)
34 GPIOA_DIR
&= ~(1<<6|1<<7);
36 GPIOB_DIR
|= (1<<4)|(1<<0);
38 GPIOB_PIN(4) = 1<<4; /* activate the wheel */
41 unsigned read_GPIOA_67(void)
46 for(i
= 20; i
; i
--) nop
;
48 for(i
= 20; i
; i
--) nop
;
49 if (GPIOA_PIN(6) != 0)
51 for(i
= 20; i
; i
--) nop
;
52 if (GPIOA_PIN(7) != 0)
54 DBOP_CTRL
&= ~(1<<19);
55 for(i
= 20; i
; i
--) nop
;
59 void get_scrollwheel(void)
61 #if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
62 /* scroll wheel handling */
63 scrollwheel(read_GPIOA_67());
68 * Get button pressed from hardware
72 int button_read_device(void)
76 static bool hold_button_old
= false;
77 static long power_counter
= 0;
85 for(delay
= 500; delay
; delay
--)
88 gpiod6
= GPIOD_PIN(6);
91 for(delay
= 240; delay
; delay
--)
94 if (GPIOC_PIN(1) & 1<<1)
96 if (GPIOC_PIN(2) & 1<<2)
98 if (GPIOC_PIN(3) & 1<<3)
100 if (GPIOC_PIN(4) & 1<<4)
101 btn
|= BUTTON_SELECT
;
102 if (GPIOC_PIN(5) & 1<<5)
104 if (GPIOB_PIN(1) & 1<<1)
107 { /* power/hold is on the same pin. we know it's hold if the bit isn't
109 if (GPIOD_PIN(6) & 1<<6)
122 #ifdef HAS_BUTTON_HOLD
125 if (hold_button
!= hold_button_old
)
127 hold_button_old
= hold_button
;
128 backlight_hold_changed(hold_button
);
131 (void)hold_button_old
;
138 /* read power, but not if hold button was just released, since
139 * you basically always hit power due to the slider mechanism after releasing
142 else if (power_counter
> 0)
145 btn
&= ~BUTTON_POWER
;
151 #ifdef HAS_BUTTON_HOLD
152 bool button_hold(void)