1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Karl Kurbjun
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 /* this file also handles the touch screen driver interface */
27 #include "backlight.h"
30 #include "backlight-target.h"
31 #include "uart-target.h"
35 #define BUTTON_TIMEOUT 50
37 #define BUTTON_START_BYTE 0xF0
38 #define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */
39 /* but always the same one for the session? */
40 static short last_x
, last_y
, last_z1
, last_z2
; /* for the touch screen */
41 static int last_touch
;
43 static struct touch_calibration_point topleft
, bottomright
;
44 static bool using_calibration
= false;
45 void use_calibration(bool enable
)
47 using_calibration
= enable
;
49 /* Jd's tests.. These will hopefully work for everyone so we dont have to
50 create a calibration screen. and
52 (480,320) = 0x0f19, 0x00fc
54 void set_calibration_points(struct touch_calibration_point
*tl
,
55 struct touch_calibration_point
*br
)
57 memcpy(&topleft
, tl
, sizeof(struct touch_calibration_point
));
58 memcpy(&bottomright
, br
, sizeof(struct touch_calibration_point
));
60 static int touch_to_pixels(short val_x
, short val_y
)
64 if (!using_calibration
)
65 return (val_x
<<16)|val_y
;
66 x1
= topleft
.val_x
; x2
= bottomright
.val_x
;
67 x
= (val_x
-x1
)*(bottomright
.px_x
- topleft
.px_x
) / (x2
- x1
) + topleft
.px_x
;
68 x1
= topleft
.val_y
; x2
= bottomright
.val_y
;
69 y
= (val_y
-x1
)*(bottomright
.px_y
- topleft
.px_y
) / (x2
- x1
) + topleft
.px_y
;
77 void button_init_device(void)
80 /* GIO is the power button, set as input */
82 topleft
.px_x
= 0; topleft
.px_y
= 0;
83 topleft
.val_x
= 0x00c0; topleft
.val_y
= 0xf40;
85 bottomright
.px_x
= LCD_WIDTH
; bottomright
.px_y
= LCD_HEIGHT
;
86 bottomright
.val_x
= 0x0f19; bottomright
.val_y
= 0x00fc;
87 using_calibration
= true;
89 /* Enable the touchscreen interrupt */
90 IO_INTC_EINT2
|= (1<<3); /* IRQ_GIO14 */
92 tsc2100_writereg(TSADC_PAGE
, TSADC_ADDRESS
,
94 (0x2<<TSADC_ADSCM_SHIFT
)| /* scan x,y,z1,z2 */
95 (0x1<<TSADC_RESOL_SHIFT
) /* 8 bit resolution */
97 /* doesnt work for some reason...
98 setting to 8bit would probably be better than the 12bit currently */
102 inline bool button_hold(void)
107 int button_get_last_touch(void)
109 int ret_val
= last_touch
;
114 static void remote_heartbeat(void)
116 char data
[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
120 int button_read_device(void)
124 int btn
= BUTTON_NONE
;
126 if ((IO_GIO_BITSET0
&0x01) == 0)
130 while (uart1_getch(&c
))
132 if (i
==0 && (c
== BUTTON_START_BYTE
|| c
== BUTTON_START_BYTE2
) )
142 btn
|= BUTTON_RC_HEART
;
144 btn
|= BUTTON_RC_MODE
;
146 btn
|= BUTTON_RC_VOL_DOWN
;
148 btn
|= BUTTON_RC_VOL_UP
;
150 btn
|= BUTTON_RC_REW
;
154 btn
|= BUTTON_RC_DOWN
;
156 btn
|= BUTTON_RC_PLAY
;
166 #define TOUCH_MARGIN 8
170 static int last_tick
= 0;
171 tsc2100_read_values(&x
, &y
,
173 if (TIME_BEFORE(last_tick
+HZ
/5, current_tick
))
175 if ((x
> last_x
+ TOUCH_MARGIN
) ||
176 (x
< last_x
- TOUCH_MARGIN
) ||
177 (y
> last_y
+ TOUCH_MARGIN
) ||
178 (y
< last_y
- TOUCH_MARGIN
))
182 queue_clear(&button_queue
);
183 queue_post(&button_queue
, BUTTON_TOUCHPAD
,
184 touch_to_pixels(x
, y
));
186 last_tick
= current_tick
;
188 IO_INTC_IRQ2
= (1<<3);