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 short touch_x
, touch_y
, touch_z1
, touch_z2
;
41 static long last_touch
= 0;
43 static struct touch_calibration_point topleft
, bottomright
;
45 /* Jd's tests.. These will hopefully work for everyone so we dont have to
46 * create a calibration screen.
49 * (480,640) = 3880, 270
52 * (640,480) = 3880, 3900
55 static int touch_to_pixels(short *val_x
, short *val_y
)
59 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
67 x
= (x
-topleft
.val_x
)*(bottomright
.px_x
- topleft
.px_x
) / (bottomright
.val_x
- topleft
.val_x
) + topleft
.px_x
;
68 y
= (y
-topleft
.val_y
)*(bottomright
.px_y
- topleft
.px_y
) / (bottomright
.val_y
- topleft
.val_y
) + topleft
.px_y
;
72 else if (x
>=LCD_WIDTH
)
77 else if (y
>=LCD_HEIGHT
)
86 void button_init_device(void)
88 touch_available
= false;
89 /* GIO is the power button, set as input */
92 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
96 bottomright
.val_x
= 3880;
97 bottomright
.val_y
= 270;
102 bottomright
.val_x
= 3900;
103 bottomright
.val_y
= 3880;
109 bottomright
.px_x
= LCD_WIDTH
;
110 bottomright
.px_y
= LCD_HEIGHT
;
113 inline bool button_hold(void)
118 /* This is called from the tsc2100 interupt handler in adc-mr500.c */
119 void touch_read_coord(void)
121 touch_available
= true;
122 tsc2100_read_touch(&touch_x
, &touch_y
, &touch_z1
, &touch_z2
);
125 int button_read_device(int *data
)
127 int button_read
= BUTTON_NONE
;
128 static bool hold_button_old
= false;
132 /* Handle touchscreen */
135 *data
= touch_to_pixels(&touch_x
, &touch_y
);
136 button_read
|= touchscreen_to_pixels(touch_x
, touch_y
, data
);
138 touch_available
= false;
139 last_touch
=current_tick
;
142 /* Handle power button */
143 if ((IO_GIO_BITSET0
&0x01) == 0)
145 button_read
|= BUTTON_POWER
;
148 /* Read data from the remote */
149 button_read
|= remote_read_device();
150 hold_button
=remote_button_hold();
152 /* Take care of hold notifications */
154 /* give BL notice if HB state chaged */
155 if (hold_button
!= hold_button_old
)
157 backlight_hold_changed(hold_button
);
158 hold_button_old
=hold_button
;
164 button_read
= BUTTON_NONE
;