Currently, the Touch screen Correction Algorithm in Touch demo adopts a conversion method written by Carlos E. Vidales. The basic principle is to take the three points on the screen as the upper center, the middle right side, and the lower center, and then make correction. For details about the conversion principle, refer to the following link:
Original English:
Http://www.embedded.com/design/configurable-systems/4023968/How-To-Calibrate-Touch-Screens
Chinese version:
Http://www.eet-china.com/ART_8800302522_480101_TA_9c35bff5.HTM
The source code of the correction algorithm has been included in the routine. If I do not understand it thoroughly, I should at least learn how to use these functions first. The recommended operation steps for this correction algorithm are as follows:
1. Call setCalibrationMatrix () with a full set of values to set the display drive and provide raw access data. In this way, you do not need to construct special functions for data access. You only need to obtain the ordinate coordinates according to the same mechanism as the program.
2. Draw the first target in the coordinate (XD0, YD0.
3. Collect the data returned from the touch screen and store it in coordinates (X0, Y0 ).
4. Draw the second target in the coordinate (XD1, YD1.
5. Collect the data returned from the touch screen and store it in coordinates (X1, Y1 ).
6. Draw the third target in the coordinate (XD2, YD2.
7. Collect the data returned from the touch screen and store it in coordinates (X2, Y2 ).
8. Call the setCalibrationMatrix () function by using the reference display data and the generated touch screen data as variables.
Corresponding to the Code, it is:
1:
/* Initialize touch screen calibration factor matrix with approx. values */
SetCalibrationMatrix (POINT *) & lcdCalibPoints,/* Display coordinates */
(POINT *) & touchCalibPoints,/* Touch coordinates */
& CalibFactors);/* Calibration factor matrix */
2 ~ 8:
/* Calibrate touch screen */
Else if (buttons & bc_uif_pbs)
{
Memset (frameBuffer, BLACK, 2 * WIDTH * HEIGHT);/* Clear screen */
DrawCross (lcdCalibPoints [0]. x, lcdCalibPoints [0]. y, COLOR );
TFT_DrawString (30, 35, "Tap green marker ");
P [0] = getTouchTapSample10bit ();
Memset (frameBuffer, BLACK, 2 * WIDTH * HEIGHT);/* Clear screen */
DrawCross (lcdCalibPoints [1]. x, lcdCalibPoints [1]. y, COLOR );
TFT_DrawString (40,130, "Tap green marker ");
P [1] = getTouchTapSample10bit ();
Memset (frameBuffer, BLACK, 2 * WIDTH * HEIGHT);/* Clear screen */
DrawCross (lcdCalibPoints [2]. x, lcdCalibPoints [2]. y, COLOR );
TFT_DrawString (20,180, "Tap green marker ");
P [2] = getTouchTapSample10bit ();
SetCalibrationMatrix (POINT *) & lcdCalibPoints,/* Display coordinates */
& P [0],/* Touch coordinates */
& CalibFactors);/* Calibration factor matrix */
Memset (frameBuffer, BLACK, 2 * WIDTH * HEIGHT);/* Clear screen */
TFT_DrawString (10,100, "The touch screen is ");
TFT_DrawString (30,130, "now calibrated! ");
}
9. How to apply:
TouchSample = getTouchSample ();
| -------->
Static POINT getTouchSample (void)
{
POINT sample, normalizedSample;
Sample = getTouchSample10bit ();
GetDisplayPoint (& normalizedSample, & sample, & calibFactors );
Return normalizedSample;
}
The getTouchSample10bit () function is to retrieve the actual ADC value and then substitute it for getDisplayPoint () to obtain the corrected value.
In this way, you can retrieve the correct screen coordinates .. Pai_^