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)
33 { /* activate the wheel */
36 for(i
= 20; i
; i
--) nop
;
40 unsigned read_GPIOA_67(void)
45 for(i
= 20; i
; i
--) nop
;
47 for(i
= 20; i
; i
--) nop
;
48 if (GPIOA_PIN(6) != 0)
50 for(i
= 20; i
; i
--) nop
;
51 if (GPIOA_PIN(7) != 0)
53 DBOP_CTRL
&= ~(1<<19);
54 for(i
= 20; i
; i
--) nop
;
58 void get_scrollwheel(void)
60 #if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
61 /* scroll wheel handling */
62 scrollwheel(read_GPIOA_67());
67 * Get button pressed from hardware
71 int button_read_device(void)
75 static bool hold_button_old
= false;
76 static long power_counter
= 0;
77 unsigned gpiod
= GPIOD_DATA
;
78 unsigned gpioa_dir
= GPIOA_DIR
;
81 for(delay
= 500; delay
; delay
--) nop
;
83 for(delay
=8;delay
;delay
--) nop
;
90 for(delay
= 500; delay
; delay
--)
92 gpiod6
= GPIOD_PIN(6);
94 for(delay
= 240; delay
; delay
--)
97 GPIOA_DIR
&= ~(1<<6|1<<7);
100 if (GPIOC_PIN(1) & 1<<1)
102 if (GPIOC_PIN(2) & 1<<2)
104 if (GPIOC_PIN(3) & 1<<3)
106 if (GPIOC_PIN(4) & 1<<4)
107 btn
|= BUTTON_SELECT
;
108 if (GPIOC_PIN(5) & 1<<5)
110 if (GPIOB_PIN(1) & 1<<1)
113 { /* power/hold is on the same pin. we know it's hold if the bit isn't
115 if (GPIOD_PIN(6) & 1<<6)
128 GPIOA_DIR
= gpioa_dir
;
131 #ifdef HAS_BUTTON_HOLD
134 if (hold_button
!= hold_button_old
)
136 hold_button_old
= hold_button
;
137 backlight_hold_changed(hold_button
);
140 (void)hold_button_old
;
147 /* read power, but not if hold button was just released, since
148 * you basically always hit power due to the slider mechanism after releasing
151 else if (power_counter
> 0)
154 btn
&= ~BUTTON_POWER
;
160 #ifdef HAS_BUTTON_HOLD
161 bool button_hold(void)