summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c')
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
index b157ae2d12..c30422fc79 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
@@ -38,6 +38,36 @@
38 /* but always the same one for the session? */ 38 /* but always the same one for the session? */
39static short last_x, last_y, last_z1, last_z2; /* for the touch screen */ 39static short last_x, last_y, last_z1, last_z2; /* for the touch screen */
40static int last_touch; 40static int last_touch;
41
42static struct touch_calibration_point topleft, bottomright;
43static bool using_calibration = false;
44void use_calibration(bool enable)
45{
46 using_calibration = enable;
47}
48
49void set_calibration_points(struct touch_calibration_point *tl,
50 struct touch_calibration_point *br)
51{
52 memcpy(&topleft, tl, sizeof(struct touch_calibration_point));
53 memcpy(&bottomright, br, sizeof(struct touch_calibration_point));
54}
55static int touch_to_pixels(short val_x, short val_y)
56{
57 short x,y;
58 int x1,x2;
59 if (!using_calibration)
60 return (val_x<<16)|val_y;
61 x1 = topleft.val_x; x2 = bottomright.val_x;
62 x = (val_x-x1)*(bottomright.px_x - topleft.px_x) / (x2 - x1) + topleft.px_x;
63 x1 = topleft.val_y; x2 = bottomright.val_y;
64 y = (val_y-x1)*(bottomright.px_y - topleft.px_y) / (x2 - x1) + topleft.px_y;
65 if (x < 0)
66 x = 0;
67 if (y < 0)
68 y = 0;
69 return (x<<16)|y;
70}
41void button_init_device(void) 71void button_init_device(void)
42{ 72{
43 last_touch = 0; 73 last_touch = 0;
@@ -128,6 +158,6 @@ void GIO14(void)
128{ 158{
129 tsc2100_read_values(&last_x, &last_y, 159 tsc2100_read_values(&last_x, &last_y,
130 &last_z1, &last_z2); 160 &last_z1, &last_z2);
131 last_touch = (last_x<<16)|last_y; 161 last_touch = touch_to_pixels(last_x, last_y);
132 IO_INTC_IRQ2 = (1<<3); 162 IO_INTC_IRQ2 = (1<<3);
133} 163}