KL25Z driving an ILI9320 LCD board with touch panel (HY28A-LCDB SPI)
Dependencies: SPI_TFT_ILI9320 mbed
Revision 1:76f92f6b3737, committed 2014-03-23
- Comitter:
- frankvnk
- Date:
- Sun Mar 23 19:45:33 2014 +0000
- Parent:
- 0:ff976ad09b2f
- Child:
- 2:e21bf3a79d1f
- Commit message:
- Added GetCalibration and SetCalibration
Changed in this revision
--- a/TouchADS7843/Touch.cpp Tue Mar 18 19:36:05 2014 +0000 +++ b/TouchADS7843/Touch.cpp Sun Mar 23 19:45:33 2014 +0000 @@ -260,3 +260,29 @@ LCD->cls(); } +void TouchScreenADS7843::GetCalibration(Matrix * matrixPtr, Coordinate * screenPtr) +{ + uint8_t i; + Matrix * mp1; + mp1 = &matrix; + *matrixPtr = *mp1; + for(i=0;i<3;i++) + { + screenPtr[i].x = ScreenSample[i].x; + screenPtr[i].y = ScreenSample[i].y; + } +} + +void TouchScreenADS7843::SetCalibration(Matrix * matrixPtr, Coordinate * screenPtr) +{ + uint8_t i; + Matrix * mp1; + mp1 = &matrix; + *mp1 = *matrixPtr; + for(i=0;i<3;i++) + { + ScreenSample[i].x = screenPtr[i].x; + ScreenSample[i].y = screenPtr[i].y; + } + setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix) ; +}
--- a/TouchADS7843/Touch.h Tue Mar 18 19:36:05 2014 +0000 +++ b/TouchADS7843/Touch.h Sun Mar 23 19:45:33 2014 +0000 @@ -38,7 +38,7 @@ Coordinate screen; /* - * Create a Touchscreen object connected to SPI and two pins + * Create a Touchscreen object connected to SPI and two pins. * * @param mosi,miso,sclk SPI * @param cs pin connected to CS of ADS7843 @@ -49,7 +49,7 @@ TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq, SPI_TFT *_LCD); /* - * Draw a 2 by 2 dot on the LCD screen + * Draw a 2 by 2 dot on the LCD screen. * * @param x (horizontal position) * @param y (vertical position) @@ -59,7 +59,7 @@ void TP_DrawPoint(unsigned int Xpos,unsigned int Ypos,unsigned int color); /* - * Obtain averaged data from ADS7846 + * Obtain averaged data from ADS7846. * does 9 consecutive reads and only stores averaged data * when the 9 points are within the treshold limits. * @@ -81,7 +81,7 @@ void TouchPanel_Calibrate(void); /* - * Obtain real x,y coordinates + * Obtain real x,y coordinates. * The x,y coordinates are calculated using the calibration matrix. * */ @@ -92,6 +92,34 @@ DigitalOut _tp_cs; DigitalIn _tp_irq; + /* + * Read touchpanel screensample and matrix values. + * + * In your code, create 2 structures using Matrix and screenPtr + * and call this function with these structures. + * the calibration values are returned into these structures. + * Example: + * Matrix matrix; + * Coordinate ScreenSample[3]; + * GetCalibration(&matrix, &ScreenSample[0]); + */ + void GetCalibration(Matrix * matrixPtr, Coordinate * screenPtr); + + /* + * Set touchpanel calibration using screensample and matrix values. + * + * In your code, create 2 structures based on Matrix and screenPtr, + * copy saved calibration values into these structures + * and call this function with these structures. + * Example: + * Matrix matrix; + * Coordinate ScreenSample[3]; + * <pseudocode> load matrix with values from external storage (eg eeprom). + * <pseudocode> load ScreenSample with values from external storage (eg eeprom). + * SetCalibration(&matrix, &ScreenSample[0]); + */ + void SetCalibration(Matrix * matrixPtr, Coordinate * screenPtr); + protected: #define SPI_RD_DELAY 1
--- a/main.cpp Tue Mar 18 19:36:05 2014 +0000 +++ b/main.cpp Sun Mar 23 19:45:33 2014 +0000 @@ -23,6 +23,9 @@ int main() { + Matrix matrix; + Coordinate ScreenSample[3]; + unsigned short LCD_id; TFT.claim(stdout); // send stdout to the TFT display // Disable stdout buffering, allows us to omit \n with printf. @@ -131,6 +134,40 @@ TP.TouchPanel_Calibrate(); TFT.set_font((unsigned char*) Arial12x12); TFT.set_orientation(0); + // Display calibration values + TP.GetCalibration(&matrix, &ScreenSample[0]); + TFT.cls(); + TFT.locate(0,20); + // read calibration results + printf("Read calibration results.\n"); + printf("matrix.An = %d\n", matrix.An); + printf("matrix.Bn = %d\n", matrix.Bn); + printf("matrix.Cn = %d\n", matrix.Cn); + printf("matrix.Dn = %d\n", matrix.Dn); + printf("matrix.En = %d\n", matrix.En); + printf("matrix.Fn = %d\n", matrix.Fn); + printf("matrix.Di = %d\n", matrix.Divider); + for (i=0;i<3;i++) + printf("sample x[%d] = %d\nsample y[%d] = %d\n", i, ScreenSample[i].x, i, ScreenSample[i].y); + // Write calibration results + printf("\nWrite calibration results...\n"); + TP.SetCalibration(&matrix, &ScreenSample[0]); + printf("Done.\nTouch panel to read again.\n"); + while(TP._tp_irq); + // read calibration results + TFT.cls(); + TFT.locate(0,20); + printf("Calibration results.\n\n"); + printf("matrix.An = %d\n", matrix.An); + printf("matrix.Bn = %d\n", matrix.Bn); + printf("matrix.Cn = %d\n", matrix.Cn); + printf("matrix.Dn = %d\n", matrix.Dn); + printf("matrix.En = %d\n", matrix.En); + printf("matrix.Fn = %d\n", matrix.Fn); + printf("matrix.Di = %d\n", matrix.Divider); + for (i=0;i<3;i++) + printf("sample x[%d] = %d\nsample y[%d] = %d\n", i, ScreenSample[i].x, i, ScreenSample[i].y); + TFT.locate(0,0); printf(" X:"); TFT.locate(70,0);