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"
31 #ifdef HAS_BUTTON_HOLD
32 static bool hold_button
= false;
34 void button_init_device(void)
39 * Get button pressed from hardware
42 int button_read_device(void)
46 static bool hold_button_old
= false;
47 static long power_counter
= 0;
48 unsigned gpiod
= GPIOD_DATA
;
49 unsigned gpioa_dir
= GPIOA_DIR
;
51 for(delay
= 500; delay
; delay
--) nop
;
53 for(delay
=8;delay
;delay
--) nop
;
60 for(delay
= 500; delay
; delay
--)
62 gpiod6
= GPIOD_PIN(6);
64 for(delay
= 240; delay
; delay
--)
67 GPIOA_DIR
&= ~(1<<6|1<<7);
70 if (GPIOC_PIN(1) & 1<<1)
72 if (GPIOC_PIN(2) & 1<<2)
74 if (GPIOC_PIN(3) & 1<<3)
76 if (GPIOC_PIN(4) & 1<<4)
78 if (GPIOC_PIN(5) & 1<<5)
80 if (GPIOB_PIN(1) & 1<<1)
83 { /* power/hold is on the same pin. we know it's hold if the bit isn't
85 if (GPIOD_PIN(6) & 1<<6)
98 GPIOA_DIR
= gpioa_dir
;
101 #ifdef HAS_BUTTON_HOLD
103 if (hold_button
!= hold_button_old
)
105 hold_button_old
= hold_button
;
106 backlight_hold_changed(hold_button
);
113 /* read power, but not if hold button was just released, since
114 * you basically always hit power due to the slider mechanism after releasing
117 else if (power_counter
> 0)
120 btn
&= ~BUTTON_POWER
;
126 #ifdef HAS_BUTTON_HOLD
127 bool button_hold(void)