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 void get_scrollwheel(void)
43 #if defined(HAVE_SCROLLWHEEL) && !defined(BOOTLOADER)
44 /* scroll wheel handling */
46 #define GPIOA_PIN76_offset ((1<<(6+2)) | (1<<(7+2)))
47 #define GPIOA_PIN76 (*(volatile unsigned char*)(GPIOA_BASE+GPIOA_PIN76_offset))
48 scrollwheel(GPIOA_PIN76
>> 6);
54 * Get button pressed from hardware
58 int button_read_device(void)
62 static bool hold_button_old
= false;
63 static long power_counter
= 0;
66 /* if we remove this delay, we see screen corruption (the higher the CPU
67 * frequency the higher the corruption) */
68 for(delay
= 1000; delay
; delay
--)
76 for(delay
= 500; delay
; delay
--)
79 gpiod6
= GPIOD_PIN(6);
82 for(delay
= 240; delay
; delay
--)
85 if (GPIOC_PIN(1) & 1<<1)
87 if (GPIOC_PIN(2) & 1<<2)
89 if (GPIOC_PIN(3) & 1<<3)
91 if (GPIOC_PIN(4) & 1<<4)
93 if (GPIOC_PIN(5) & 1<<5)
95 if (GPIOB_PIN(1) & 1<<1)
98 { /* power/hold is on the same pin. we know it's hold if the bit isn't
100 if (GPIOD_PIN(6) & 1<<6)
113 #ifdef HAS_BUTTON_HOLD
116 if (hold_button
!= hold_button_old
)
118 hold_button_old
= hold_button
;
119 backlight_hold_changed(hold_button
);
122 (void)hold_button_old
;
129 /* read power, but not if hold button was just released, since
130 * you basically always hit power due to the slider mechanism after releasing
133 else if (power_counter
> 0)
136 btn
&= ~BUTTON_POWER
;
142 #ifdef HAS_BUTTON_HOLD
143 bool button_hold(void)