FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / tms320dm320 / mrobe-500 / button-mr500.c
blob7d9a43f902791e3de7db26f98599cb798db904b5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 #include "config.h"
23 #include "cpu.h"
24 #include "system.h"
25 #include "button.h"
26 #include "kernel.h"
27 #include "backlight.h"
28 #include "backlight-target.h"
29 #include "lcd-remote-target.h"
30 #include "uart-target.h"
31 #include "tsc2100.h"
32 #include "string.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.
41 * Portait:
42 * (0,0) = 200, 3900
43 * (480,640) = 3880, 270
44 * Landscape:
45 * (0,0) = 200, 270
46 * (640,480) = 3880, 3900
49 static int touch_to_pixels(short *val_x, short *val_y)
51 short x,y;
53 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
54 x=*val_x;
55 y=*val_y;
56 #else
57 x=*val_y;
58 y=*val_x;
59 #endif
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;
64 if (x < 0)
65 x = 0;
66 else if (x>=LCD_WIDTH)
67 x=LCD_WIDTH-1;
69 if (y < 0)
70 y = 0;
71 else if (y>=LCD_HEIGHT)
72 y=LCD_HEIGHT-1;
74 *val_x=x;
75 *val_y=y;
77 return (x<<16)|y;
80 void button_init_device(void)
82 /* GIO is the power button, set as input */
83 IO_GIO_DIR0 |= 0x01;
85 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
86 topleft.val_x = 200;
87 topleft.val_y = 3900;
89 bottomright.val_x = 3880;
90 bottomright.val_y = 270;
91 #else
92 topleft.val_x = 270;
93 topleft.val_y = 200;
95 bottomright.val_x = 3900;
96 bottomright.val_y = 3880;
97 #endif
99 topleft.px_x = 0;
100 topleft.px_y = 0;
102 bottomright.px_x = LCD_WIDTH;
103 bottomright.px_y = LCD_HEIGHT;
106 inline bool button_hold(void)
108 return hold_button;
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;
122 *data = old_data;
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();
142 #endif
144 /* Take care of hold notifications */
145 #ifndef BOOTLOADER
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;
151 #endif
153 if (hold_button)
155 button_read = BUTTON_NONE;
158 return button_read;