1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007, 2009 by Karl Kurbjun
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 /* this file also handles the touch screen driver interface */
29 #include "backlight.h"
30 #include "backlight-target.h"
31 #include "lcd-remote-target.h"
32 #include "uart-target.h"
35 #include "touchscreen.h"
37 static bool touch_available
= false;
38 static bool hold_button
= false;
40 static struct touch_calibration_point topleft
, bottomright
;
42 /* Jd's tests.. These will hopefully work for everyone so we dont have to
43 * create a calibration screen.
46 * (480,640) = 3880, 270
49 * (640,480) = 3880, 3900
52 static int touch_to_pixels(short val_x
, short val_y
)
56 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
64 x
= (x
-topleft
.val_x
)*(bottomright
.px_x
- topleft
.px_x
) / (bottomright
.val_x
- topleft
.val_x
) + topleft
.px_x
;
65 y
= (y
-topleft
.val_y
)*(bottomright
.px_y
- topleft
.px_y
) / (bottomright
.val_y
- topleft
.val_y
) + topleft
.px_y
;
69 else if (x
>=LCD_WIDTH
)
74 else if (y
>=LCD_HEIGHT
)
81 void button_init_device(void)
83 touch_available
= false;
84 /* GIO is the power button, set as input */
87 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
91 bottomright
.val_x
= 3880;
92 bottomright
.val_y
= 270;
97 bottomright
.val_x
= 3900;
98 bottomright
.val_y
= 3880;
104 bottomright
.px_x
= LCD_WIDTH
;
105 bottomright
.px_y
= LCD_HEIGHT
;
107 /* Enable the touchscreen interrupt */
108 IO_INTC_EINT2
|= (1<<3); /* IRQ_GIO14 */
110 tsc2100_writereg(TSADC_PAGE
, TSADC_ADDRESS
,
112 (0x2<<TSADC_ADSCM_SHIFT
)| /* scan x,y,z1,z2 */
113 (0x1<<TSADC_RESOL_SHIFT
) /* 8 bit resolution */
115 /* doesnt work for some reason...
116 setting to 8bit would probably be better than the 12bit currently */
120 inline bool button_hold(void)
125 int button_read_device(int *data
)
127 int button_read
= BUTTON_NONE
;
128 static int button_old
= BUTTON_NONE
;
129 static bool hold_button_old
= false;
130 static long last_touch
= 0;
134 /* Handle touchscreen */
138 short last_z1
, last_z2
;
140 tsc2100_read_values(&x
, &y
, &last_z1
, &last_z2
);
142 *data
= touch_to_pixels(x
, y
);
143 button_read
|= touchscreen_to_pixels((*data
&0xffff0000)>>16,
144 *data
&0x0000ffff, data
);
145 button_old
= button_read
;
147 touch_available
= false;
148 last_touch
=current_tick
;
152 /* Touch hasn't happened in a while, clear the bits */
153 if(last_touch
+3>current_tick
)
157 /* Handle power button */
158 if ((IO_GIO_BITSET0
&0x01) == 0)
160 button_read
|= BUTTON_POWER
;
161 button_old
= button_read
;
164 button_old
&=~BUTTON_POWER
;
166 /* Read data from the remote */
167 button_read
|= remote_read_device();
168 hold_button
=remote_button_hold();
170 /* Take care of hold notifications */
172 /* give BL notice if HB state chaged */
173 if (hold_button
!= hold_button_old
)
175 backlight_hold_changed(hold_button
);
176 hold_button_old
=hold_button
;
182 button_read
= BUTTON_NONE
;
183 button_old
= button_read
;
189 /* Touchscreen data available interupt */
190 void read_battery_inputs(void);
193 short tsadc
= tsc2100_readreg(TSADC_PAGE
, TSADC_ADDRESS
);
194 short adscm
= (tsadc
&TSADC_ADSCM_MASK
)>>TSADC_ADSCM_SHIFT
;
199 touch_available
= true;
202 read_battery_inputs();
205 IO_INTC_IRQ2
= (1<<3); /* IRQ_GIO14 == 35 */