HD200 - Fix GPIO setup in button_init_device()- this change fixes sound output broken...
[maemo-rb.git] / firmware / target / coldfire / mpio / hd200 / button-hd200.c
blobfba5c0b74edd1f611a5ec067c67029975d71f92b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
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 ****************************************************************************/
22 #include "config.h"
23 #include "cpu.h"
24 #include "system.h"
25 #include "button.h"
26 #include "backlight.h"
27 #include "adc.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 */
56 if (remote_detect())
57 return adc_scan(ADC_REMOTE)<50?true:false;
58 else
59 return false;
63 * Get button pressed from hardware
65 int button_read_device(void)
67 int btn = BUTTON_NONE;
68 int data = 0;
69 static bool hold_button = false;
70 bool remote_hold_button = false;
72 bool hold_button_old;
73 bool remote_present;
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();
83 #ifndef BOOTLOADER
84 /* Only main hold affects backlight */
85 if (hold_button != hold_button_old)
86 backlight_hold_changed(hold_button);
87 #endif
89 /* Skip if main hold is active */
90 if (!hold_button)
92 data = adc_scan(ADC_BUTTONS);
94 if (data < 2300) /* valid button */
96 if (data < 900) /* middle */
98 if (data < 500)
100 if (data > 200)
101 /* 200 - 500 */
102 btn = BUTTON_REC;
104 else /* 900 - 500 */
105 btn = BUTTON_VOL_DOWN;
107 else /* 2250 - 900 */
109 if (data < 1600)
111 /* 1600 - 900 */
112 if (data < 1200)
113 /* 1200 - 900 */
114 btn = BUTTON_VOL_UP;
115 else /* 1600 - 1200 */
116 btn = BUTTON_NEXT;
118 else /* 1600 - 2250 */
120 if (data < 1900)
121 /* 1900 - 1600 */
122 btn = BUTTON_PREV;
123 else /* 1900 - 2300 */
124 btn = BUTTON_SELECT;
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 */
139 if (data < 650)
141 if (data < 400)
143 if (data > 250)
144 /* 250 - 400 */
145 btn = BUTTON_RC_VOL_DOWN;
147 else /* 650 - 400 */
148 btn = BUTTON_RC_VOL_UP;
150 else /* 950 - 650 */
151 btn = BUTTON_RC_NEXT;
153 else /* 2050 - 950 */
155 if (data < 1900)
157 if (data < 1350)
158 /* 1350 - 900 */
159 btn = BUTTON_RC_PREV;
161 else /* 2050 - 1900 */
162 btn = BUTTON_RC_SELECT;
167 /* PLAY buttons (both remote and main) are
168 * GPIOs not ADC
170 data = GPIO1_READ;
172 /* GPIO56 active high main PLAY/PAUSE/ON */
173 if (!hold_button && ((data & (1<<24))))
174 btn |= BUTTON_PLAY;
176 /* GPIO41 active high remote PLAY/PAUSE/ON */
177 if (remote_present && !remote_hold_button && ((data & (1<<9))))
178 btn |= BUTTON_RC_PLAY;
180 return btn;