summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/mrobe-500
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/tms320dm320/mrobe-500')
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
index 8d719eca81..0eb1c07e74 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
@@ -41,11 +41,7 @@ static short last_x, last_y, last_z1, last_z2; /* for the touch screen */
41static bool touch_available = false; 41static bool touch_available = false;
42 42
43static struct touch_calibration_point topleft, bottomright; 43static struct touch_calibration_point topleft, bottomright;
44static bool using_calibration = false; 44
45void use_calibration(bool enable)
46{
47 using_calibration = enable;
48}
49/* Jd's tests.. These will hopefully work for everyone so we dont have to 45/* Jd's tests.. These will hopefully work for everyone so we dont have to
50 * create a calibration screen. 46 * create a calibration screen.
51 * Portait: 47 * Portait:
@@ -55,12 +51,6 @@ void use_calibration(bool enable)
55 * (0,0) = 200, 270 51 * (0,0) = 200, 270
56 * (640,480) = 3880, 3900 52 * (640,480) = 3880, 3900
57*/ 53*/
58void set_calibration_points(struct touch_calibration_point *tl,
59 struct touch_calibration_point *br)
60{
61 memcpy(&topleft, tl, sizeof(struct touch_calibration_point));
62 memcpy(&bottomright, br, sizeof(struct touch_calibration_point));
63}
64 54
65static int touch_to_pixels(short val_x, short val_y) 55static int touch_to_pixels(short val_x, short val_y)
66{ 56{
@@ -74,16 +64,20 @@ static int touch_to_pixels(short val_x, short val_y)
74 y=val_x; 64 y=val_x;
75#endif 65#endif
76 66
77 if (!using_calibration)
78 return (val_x<<16)|val_y;
79
80 x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x; 67 x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x;
81 y = (y-topleft.val_y)*(bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y; 68 y = (y-topleft.val_y)*(bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y;
82 69
83 if (x < 0) 70 if (x < 0)
84 x = 0; 71 x = 0;
72 else if (x>=LCD_WIDTH)
73 x=LCD_WIDTH-1;
74
85 if (y < 0) 75 if (y < 0)
86 y = 0; 76 y = 0;
77 else if (y>=LCD_HEIGHT)
78 y=LCD_HEIGHT-1;
79
80
87 return (x<<16)|y; 81 return (x<<16)|y;
88} 82}
89 83
@@ -107,14 +101,12 @@ void button_init_device(void)
107 bottomright.val_y = 3880; 101 bottomright.val_y = 3880;
108#endif 102#endif
109 103
110 topleft.px_x = 0; 104 topleft.px_x = 0;
111 topleft.px_y = 0; 105 topleft.px_y = 0;
112 106
113 bottomright.px_x = LCD_WIDTH; 107 bottomright.px_x = LCD_WIDTH;
114 bottomright.px_y = LCD_HEIGHT; 108 bottomright.px_y = LCD_HEIGHT;
115 109
116 using_calibration = true;
117
118 /* Enable the touchscreen interrupt */ 110 /* Enable the touchscreen interrupt */
119 IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */ 111 IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
120#if 0 112#if 0
@@ -136,15 +128,18 @@ inline bool button_hold(void)
136static void remote_heartbeat(void) 128static void remote_heartbeat(void)
137{ 129{
138 char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; 130 char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
139 uart1_puts(data); 131 uart1_puts(data, 5);
140} 132}
141 133
142#define TOUCH_MARGIN 8 134#define TOUCH_MARGIN 8
135char r_buffer[5];
136int r_button = BUTTON_NONE;
143int button_read_device(int *data) 137int button_read_device(int *data)
144{ 138{
145 char buffer[5]; 139 int retval, calbuf;
146 int button = BUTTON_NONE, retval;
147 static int oldbutton = BUTTON_NONE; 140 static int oldbutton = BUTTON_NONE;
141
142 r_button=BUTTON_NONE;
148 *data = 0; 143 *data = 0;
149 144
150 if (touch_available) 145 if (touch_available)
@@ -170,7 +165,7 @@ int button_read_device(int *data)
170 last_x = x; 165 last_x = x;
171 last_y = y; 166 last_y = y;
172 *data = touch_to_pixels(x, y); 167 *data = touch_to_pixels(x, y);
173 button |= BUTTON_TOUCHPAD; 168 r_button |= BUTTON_TOUCHPAD;
174 } 169 }
175 last_touch = current_tick; 170 last_touch = current_tick;
176 touch_available = false; 171 touch_available = false;
@@ -178,23 +173,34 @@ int button_read_device(int *data)
178 remote_heartbeat(); 173 remote_heartbeat();
179 174
180 if ((IO_GIO_BITSET0&0x01) == 0) 175 if ((IO_GIO_BITSET0&0x01) == 0)
181 button |= BUTTON_POWER; 176 {
177 r_button |= BUTTON_POWER;
178 oldbutton=r_button;
179 }
182 180
183 retval=uart1_gets_queue(buffer, 5); 181 retval=uart1_gets_queue(r_buffer, 5);
184 do 182 do
185 { 183 {
184 for(calbuf=0;calbuf<4;calbuf++)
185 {
186 if((r_buffer[calbuf]&0xF0)==0xF0 && (r_buffer[calbuf+1]&0xF0)!=0xF0)
187 break;
188 }
189 calbuf++;
190 if(calbuf==5)
191 calbuf=0;
186 if(retval>=0) 192 if(retval>=0)
187 { 193 {
188 button |= buffer[1]; 194 r_button |= r_buffer[calbuf];
189 oldbutton=button; 195 oldbutton=r_button;
190 } 196 }
191 else 197 else
192 { 198 {
193 button=oldbutton; 199 r_button=oldbutton;
194 } 200 }
195 } while((retval=uart1_gets_queue(buffer, 5))>=5); 201 } while((retval=uart1_gets_queue(r_buffer, 5))>=5);
196 202
197 return button; 203 return r_button;
198} 204}
199 205
200/* Touchpad data available interupt */ 206/* Touchpad data available interupt */