1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Barry Wardell
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 /* Custom written for the H10 based on analysis of the GPIO data */
31 #include "backlight.h"
35 void button_init_device(void)
37 /* Enable REW, FF, Play, Left, Right, Hold buttons */
38 GPIO_SET_BITWISE(GPIOA_ENABLE
, 0xfc);
40 /* Enable POWER button */
41 GPIO_SET_BITWISE(GPIOB_ENABLE
, 0x01);
43 /* We need to output to pin 6 of GPIOD when reading the scroll pad value */
44 GPIO_SET_BITWISE(GPIOD_ENABLE
, 0x40);
45 GPIO_SET_BITWISE(GPIOD_OUTPUT_EN
, 0x40);
46 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL
, 0x40);
49 bool button_hold(void)
51 return (GPIOA_INPUT_VAL
& 0x4)?false:true;
54 bool remote_button_hold(void)
56 return adc_scan(ADC_REMOTE
) < 0x2B;
60 * Get button pressed from hardware
62 int button_read_device(void)
64 int btn
= BUTTON_NONE
;
67 static bool hold_button
= false;
68 static bool remote_hold_button
= false;
70 bool remote_hold_button_old
;
73 hold_button_old
= hold_button
;
74 hold_button
= button_hold();
78 if (hold_button
!= hold_button_old
)
80 backlight_hold_changed(hold_button
);
87 /* Read normal buttons */
88 state
= GPIOA_INPUT_VAL
& 0xf8;
89 if ((state
& 0x8) == 0) btn
|= BUTTON_FF
;
90 if ((state
& 0x10) == 0) btn
|= BUTTON_PLAY
;
91 if ((state
& 0x20) == 0) btn
|= BUTTON_REW
;
92 if ((state
& 0x40) == 0) btn
|= BUTTON_RIGHT
;
93 if ((state
& 0x80) == 0) btn
|= BUTTON_LEFT
;
95 /* Read power button */
96 if (GPIOB_INPUT_VAL
& 0x1) btn
|= BUTTON_POWER
;
99 if ( GPIOD_INPUT_VAL
& 0x20 )
101 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL
, 0x40);
103 data
= adc_scan(ADC_SCROLLPAD
);
104 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL
, 0x40);
108 btn
|= BUTTON_SCROLL_DOWN
;
110 btn
|= BUTTON_SCROLL_UP
;
116 remote_hold_button_old
= remote_hold_button
;
118 data
= adc_scan(ADC_REMOTE
);
119 remote_hold_button
= data
< 0x2B;
122 if (remote_hold_button
!= remote_hold_button_old
)
123 backlight_hold_changed(remote_hold_button
);
126 if(!remote_hold_button
)
134 btn
|= BUTTON_RC_REW
;
137 btn
|= BUTTON_RC_VOL_DOWN
;
139 btn
|= BUTTON_RC_VOL_UP
;
143 /* remote play button should be dead if hold */
144 if (!remote_hold_button
&& !(GPIOA_INPUT_VAL
& 0x1))
145 btn
|= BUTTON_RC_PLAY
;