YUV Dither: r12 saving was removed but stacked parameter load offset wasn't changed...
[kugel-rb.git] / firmware / target / arm / iriver / h10 / button-h10.c
blob6710f39281054cac6458527784a18d79d1b4c1b8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 */
25 #include <stdlib.h>
26 #include "config.h"
27 #include "cpu.h"
28 #include "system.h"
29 #include "button.h"
30 #include "kernel.h"
31 #include "backlight.h"
32 #include "adc.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;
65 int data;
66 unsigned char state;
67 static bool hold_button = false;
68 static bool remote_hold_button = false;
69 bool hold_button_old;
70 bool remote_hold_button_old;
72 /* Hold */
73 hold_button_old = hold_button;
74 hold_button = button_hold();
76 #ifndef BOOTLOADER
77 /* light handling */
78 if (hold_button != hold_button_old)
80 backlight_hold_changed(hold_button);
82 #endif
84 /* device buttons */
85 if (!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;
98 /* Read scroller */
99 if ( GPIOD_INPUT_VAL & 0x20 )
101 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x40);
102 udelay(250);
103 data = adc_scan(ADC_SCROLLPAD);
104 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x40);
106 if(data < 0x224)
108 btn |= BUTTON_SCROLL_DOWN;
109 } else {
110 btn |= BUTTON_SCROLL_UP;
115 /* remote buttons */
116 remote_hold_button_old = remote_hold_button;
118 data = adc_scan(ADC_REMOTE);
119 remote_hold_button = data < 0x2B;
121 #ifndef BOOTLOADER
122 if (remote_hold_button != remote_hold_button_old)
123 backlight_hold_changed(remote_hold_button);
124 #endif
126 if(!remote_hold_button)
128 if (data < 0x3FF)
130 if(data < 0x204)
131 if(data < 0x155)
132 btn |= BUTTON_RC_FF;
133 else
134 btn |= BUTTON_RC_REW;
135 else
136 if(data < 0x2D0)
137 btn |= BUTTON_RC_VOL_DOWN;
138 else
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;
147 return btn;