20 #define TS_TOLERANCE 40
23 u16 TS_Sensibility = 3100;
26 tTOUCHSCR_Info TOUCHSCR_Info = {0};
27 tPOINT TS_ScreenSample[3] = {0};
30 tTOUCHSCR_Cal TS_CalibrationSetup =
38 extern const tPOINT TS_RefSample[3];
59 NODEBUG2 u32 MedianFilter(
const u16* values )
61 u16 Sorted[ADC_NB_SAMPLES];
65 Sorted[0] = values[0];
67 for ( i = 1; i < ADC_NB_SAMPLES; i++ )
69 v = values[i * ADC_NB_CHANNELS];
73 if ( v > Sorted[j - 1] )
75 Sorted[j] = Sorted[j - 1];
80 return Sorted[( ADC_NB_SAMPLES + 1 ) >> 1];
107 TOUCHSCR_Info.Mode = mode;
125 NODEBUG
void TOUCHSCREEN_Drawing(
void )
127 static s32 old_x = 0;
128 static s32 old_y = 0;
129 static s32 old_Pressed = 0;
130 s32 xpos = 0, ypos = 0;
133 if ( TOUCHSCR_Info.TouchPress )
135 xpos = TOUCHSCR_Info.xPos;
136 ypos = TOUCHSCR_Info.yPos;
137 if ( xpos < 0 ) xpos = 0;
138 if ( ypos < 0 ) ypos = 0;
139 if ( xpos > ( Screen_Width - 1 ) ) xpos = ( Screen_Width - 1 );
140 if ( ypos > ( Screen_Height - 1 ) ) ypos = ( Screen_Height - 1 );
145 if ( ( ( xpos - old_x ) * ( xpos - old_x ) + ( ypos - old_y ) * ( ypos - old_y ) ) > ( TS_TOLERANCE * TS_TOLERANCE ) )
151 xpos = ( xpos + old_x ) / 2;
152 ypos = ( ypos + old_y ) / 2;
159 DRAW_Line_Circle( old_x, old_y, xpos, ypos,
RGB_BLACK );
164 old_Pressed = TOUCHSCR_Info.TouchPress;
187 NODEBUG
void TOUCHSCR_CalculateCalibration( tPOINT* Raw )
189 s32 Dx = Raw[0].X - Raw[2].X;
190 s32 Dy = Raw[0].Y - Raw[2].Y;
192 s32 Ex = Raw[1].X - Raw[2].X;
193 s32 Ey = Raw[1].Y - Raw[2].Y;
195 s32 Delta = Dx * Ey - Ex * Dy;
196 TS_CalibrationSetup.R = Delta;
199 s32 A = ( TS_RefSample[0].X - TS_RefSample[2].X ) * Ey
200 - ( TS_RefSample[1].X - TS_RefSample[2].X ) * Dy;
202 s32 B = ( TS_RefSample[1].X - TS_RefSample[2].X ) * Dx
203 - ( TS_RefSample[0].X - TS_RefSample[2].X ) * Ex;
206 s32 C = ( TS_RefSample[2].X * Delta ) - ( A * Raw[2].X ) - ( B * Raw[2].Y );
208 TS_CalibrationSetup.A = A;
209 TS_CalibrationSetup.B = B;
210 TS_CalibrationSetup.C = C;
213 s32 D = ( TS_RefSample[0].Y - TS_RefSample[2].Y ) * Ey
214 - ( TS_RefSample[1].Y - TS_RefSample[2].Y ) * Dy;
216 s32 E = ( TS_RefSample[1].Y - TS_RefSample[2].Y ) * Dx
217 - ( TS_RefSample[0].Y - TS_RefSample[2].Y ) * Ex;
219 s32 F = ( TS_RefSample[2].Y * Delta ) - ( D * Raw[2].X ) - ( E * Raw[2].Y );
221 TS_CalibrationSetup.D = D;
222 TS_CalibrationSetup.E = E;
223 TS_CalibrationSetup.F = F;
244 return ( TOUCHSCR_Info.xPos | ( TOUCHSCR_Info.yPos << 8 ) );
263 return TOUCHSCR_Info.xPos;
282 return TOUCHSCR_Info.yPos;
302 return ( TOUCHSCR_Info.xAbsPos | ( TOUCHSCR_Info.yAbsPos << 8 ) );
321 return ( TOUCHSCR_Info.TouchPress ) ;
340 return ( TOUCHSCR_Info.Mode ) ;
360 TS_Sensibility = sens;
362 TS_Sensibility = 4095;