1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Marcin Bukat
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 ****************************************************************************/
26 #include "backlight.h"
29 static bool remote_detect(void)
31 /* When there is no remote adc readout
32 * is exactly 0. We add some margin
33 * for ADC readout instability
35 return adc_scan(ADC_REMOTE
)>10?true:false;
38 void button_init_device(void)
40 /* GPIO56 (main PLAY) general input
41 * GPIO41 (remote PLAY) is shared with Audio Serial Data
43 or_l((1<<24),&GPIO1_FUNCTION
);
44 and_l(~(1<<24),&GPIO1_ENABLE
);
47 bool button_hold(void)
49 /* GPIO36 active high */
50 return (GPIO1_READ
& (1<<4))?true:false;
53 bool remote_button_hold(void)
55 /* On my remote hold gives readout of 44 */
57 return adc_scan(ADC_REMOTE
)<50?true:false;
63 * Get button pressed from hardware
65 int button_read_device(void)
67 int btn
= BUTTON_NONE
;
69 static bool hold_button
= false;
70 bool remote_hold_button
= false;
75 /* check if we have remote connected */
76 remote_present
= remote_detect();
78 /* read hold buttons status */
79 hold_button_old
= hold_button
;
80 hold_button
= button_hold();
81 remote_hold_button
= remote_button_hold();
84 /* Only main hold affects backlight */
85 if (hold_button
!= hold_button_old
)
86 backlight_hold_changed(hold_button
);
89 /* Skip if main hold is active */
92 data
= adc_scan(ADC_BUTTONS
);
94 if (data
< 2300) /* valid button */
96 if (data
< 900) /* middle */
105 btn
= BUTTON_VOL_DOWN
;
107 else /* 2250 - 900 */
115 else /* 1600 - 1200 */
118 else /* 1600 - 2250 */
123 else /* 1900 - 2300 */
130 /* Skip if remote is not present or remote_hold is active */
131 if (remote_present
&& !remote_hold_button
)
133 data
= adc_scan(ADC_REMOTE
);
135 if (data
< 2050) /* valid button */
137 if (data
< 950) /* middle */
145 btn
= BUTTON_RC_VOL_DOWN
;
148 btn
= BUTTON_RC_VOL_UP
;
153 else /* 2050 - 950 */
161 else /* 2050 - 1900 */
162 btn
= BUTTON_RC_FUNC
;
167 /* PLAY buttons (both remote and main) are
172 /* GPIO56 active high main PLAY/PAUSE/ON */
173 if (!hold_button
&& ((data
& (1<<24))))
176 /* GPIO41 active high remote PLAY/PAUSE/ON */
177 if (remote_present
&& !remote_hold_button
&& ((data
& (1<<9))))
178 btn
|= BUTTON_RC_PLAY
;