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)
61 static bool hold_button_old
= false;
62 static long power_counter
= 0;
66 /* if we don't wait for the fifo to empty, we'll see screen corruption
67 * (the higher the CPU frequency the higher the corruption) */
68 while ((DBOP_STAT
& (1<<10)) == 0);
77 gpiod6
= GPIOD_PIN(6);
82 if (GPIOC_PIN(1) & 1<<1)
84 if (GPIOC_PIN(2) & 1<<2)
86 if (GPIOC_PIN(3) & 1<<3)
88 if (GPIOC_PIN(4) & 1<<4)
90 if (GPIOC_PIN(5) & 1<<5)
92 if (GPIOB_PIN(1) & 1<<1)
95 { /* power/hold is on the same pin. we know it's hold if the bit isn't
97 if (GPIOD_PIN(6) & 1<<6)
110 #ifdef HAS_BUTTON_HOLD
113 if (hold_button
!= hold_button_old
)
115 hold_button_old
= hold_button
;
116 backlight_hold_changed(hold_button
);
119 (void)hold_button_old
;
126 /* read power, but not if hold button was just released, since
127 * you basically always hit power due to the slider mechanism after releasing
130 else if (power_counter
> 0)
133 btn
&= ~BUTTON_POWER
;
139 #ifdef HAS_BUTTON_HOLD
140 bool button_hold(void)