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 ****************************************************************************/
27 #include "backlight.h"
28 #include "backlight-target.h"
29 #include "lcd-remote-target.h"
30 #include "uart-target.h"
33 #include "touchscreen.h"
35 static bool hold_button
= false;
37 static struct touch_calibration_point topleft
, bottomright
;
39 /* Jd's tests.. These will hopefully work for everyone so we dont have to
40 * create a calibration screen.
43 * (480,640) = 3880, 270
46 * (640,480) = 3880, 3900
49 static int touch_to_pixels(short *val_x
, short *val_y
)
53 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
61 x
= (x
-topleft
.val_x
)*(bottomright
.px_x
- topleft
.px_x
) / (bottomright
.val_x
- topleft
.val_x
) + topleft
.px_x
;
62 y
= (y
-topleft
.val_y
)*(bottomright
.px_y
- topleft
.px_y
) / (bottomright
.val_y
- topleft
.val_y
) + topleft
.px_y
;
66 else if (x
>=LCD_WIDTH
)
71 else if (y
>=LCD_HEIGHT
)
80 void button_init_device(void)
82 /* GIO is the power button, set as input */
85 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
89 bottomright
.val_x
= 3880;
90 bottomright
.val_y
= 270;
95 bottomright
.val_x
= 3900;
96 bottomright
.val_y
= 3880;
102 bottomright
.px_x
= LCD_WIDTH
;
103 bottomright
.px_y
= LCD_HEIGHT
;
106 inline bool button_hold(void)
111 /* Since this is a touchscreen, the expectation in higher levels is that the
112 * previous touch location is maintained when a release occurs. This is
113 * intended to mimic a mouse or other similar pointing device.
115 int button_read_device(int *data
)
117 static int old_data
= 0;
118 int button_read
= BUTTON_NONE
;
119 short touch_x
, touch_y
, touch_z1
, touch_z2
;
120 static bool hold_button_old
= false;
124 /* Handle touchscreen */
125 if (tsc2100_read_touch(&touch_x
, &touch_y
, &touch_z1
, &touch_z2
))
127 old_data
= *data
= touch_to_pixels(&touch_x
, &touch_y
);
128 button_read
|= touchscreen_to_pixels(touch_x
, touch_y
, data
);
131 tsc2100_set_mode(true, 0x01);
133 /* Handle power button */
134 if ((IO_GIO_BITSET0
&0x01) == 0) {
135 button_read
|= BUTTON_POWER
;
138 #if defined(HAVE_REMOTE_LCD)
139 /* Read data from the remote */
140 button_read
|= remote_read_device();
141 hold_button
=remote_button_hold();
144 /* Take care of hold notifications */
146 /* give BL notice if HB state chaged */
147 if (hold_button
!= hold_button_old
) {
148 backlight_hold_changed(hold_button
);
149 hold_button_old
=hold_button
;
155 button_read
= BUTTON_NONE
;