Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.
Fork of UniGraphic by
Touch.h
00001 /****************************************************************** 00002 ***** ***** 00003 ***** Name: Touch.h ***** 00004 ***** Ver.: 1.0 ***** 00005 ***** Date: 04/01/2013 ***** 00006 ***** Auth: Frank Vannieuwkerke ***** 00007 ***** Erik Olieman ***** 00008 ***** Func: Touch driver for use with ADS7843 ***** 00009 ***** ***** 00010 ******************************************************************/ 00011 00012 #ifndef MBED_Touch_H 00013 #define MBED_Touch_H 00014 00015 #include "TFT.h" 00016 #include "mbed.h" 00017 00018 typedef struct 00019 { 00020 int x; 00021 int y; 00022 } Coordinate; 00023 00024 typedef struct 00025 { 00026 int An, 00027 Bn, 00028 Cn, 00029 Dn, 00030 En, 00031 Fn, 00032 Divider ; 00033 } Matrix; 00034 00035 class TouchScreenADS7843 { 00036 public: 00037 Coordinate display; 00038 Coordinate screen; 00039 00040 /* 00041 * Create a Touchscreen object connected to SPI and two pins. 00042 * 00043 * @param mosi,miso,sclk SPI 00044 * @param cs pin connected to CS of ADS7843 00045 * @param irq pin connected to IRQ of ADS7843 00046 * @param pointer to SPI_TFT constructor 00047 * 00048 */ 00049 TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq, TFT *_LCD); 00050 00051 /* 00052 * Draw a 2 by 2 dot on the LCD screen. 00053 * 00054 * @param x (horizontal position) 00055 * @param y (vertical position) 00056 * @param color (16 bit pixel color) 00057 * 00058 */ 00059 void TP_DrawPoint(unsigned int Xpos,unsigned int Ypos,unsigned int color); 00060 00061 /* 00062 * Obtain averaged data from ADS7846. 00063 * does 9 consecutive reads and only stores averaged data 00064 * when the 9 points are within the treshold limits. 00065 * 00066 * @param screenPTR (pointer to store data) 00067 * @returns 1 on success 00068 * @returns 0 on failure 00069 * 00070 * If called with screenPTR = NULL - 'screen' variable is used, otherwise (parameter) is used. 00071 * 00072 */ 00073 unsigned char Read_Ads7843(Coordinate * screenPtr = NULL); 00074 00075 /* 00076 * Calibrate the touch panel. 00077 * Three crosshairs are drawn and need to be touched in sequence. 00078 * A calibration matrix is set accordingly. 00079 * 00080 */ 00081 void TouchPanel_Calibrate(void); 00082 00083 /* 00084 * Obtain real x,y coordinates. 00085 * The x,y coordinates are calculated using the calibration matrix. 00086 * 00087 */ 00088 unsigned char getDisplayPoint(void); 00089 00090 /* 00091 * Read touchpanel screensample and matrix values. 00092 * 00093 * In your code, create 2 structures using Matrix and screenPtr 00094 * and call this function with these structures. 00095 * the calibration values are returned into these structures. 00096 * Example: 00097 * Matrix matrix; 00098 * Coordinate ScreenSample[3]; 00099 * GetCalibration(&matrix, &ScreenSample[0]); 00100 */ 00101 void GetCalibration(Matrix * matrixPtr, Coordinate * screenPtr); 00102 00103 /* 00104 * Set touchpanel calibration using screensample and matrix values. 00105 * 00106 * In your code, create 2 structures based on Matrix and screenPtr, 00107 * copy saved calibration values into these structures 00108 * and call this function with these structures. 00109 * Example: 00110 * Matrix matrix; 00111 * Coordinate ScreenSample[3]; 00112 * <pseudocode> load matrix with values from external storage (eg eeprom). 00113 * <pseudocode> load ScreenSample with values from external storage (eg eeprom). 00114 * SetCalibration(&matrix, &ScreenSample[0]); 00115 */ 00116 void SetCalibration(Matrix * matrixPtr, Coordinate * screenPtr); 00117 00118 TFT *LCD; 00119 SPI _tp_spi; 00120 DigitalOut _tp_cs; 00121 DigitalIn _tp_irq; 00122 00123 protected: 00124 00125 #define SPI_RD_DELAY 1 00126 #define CHX 0xd0 // 12 bit mode 00127 #define CHY 0x90 00128 00129 Coordinate DisplaySample[3]; 00130 Coordinate ScreenSample[3]; 00131 Matrix matrix; 00132 00133 /* 00134 * Obtain raw x,y data from ADS7846 00135 * 00136 * @param pointer to raw x and y coordinates (pointer to store data) 00137 * @returns x (horizontal position) 00138 * @returns y (vertical position) 00139 * 00140 */ 00141 void TP_GetAdXY(int *x,int *y); 00142 00143 /* 00144 * Obtain raw single channel data from ADS7846 (Called by TP_GetADXY) 00145 * 00146 * @param channel to be read (CHX or CHY) 00147 * @returns raw scaled down value (return value range must be between 0 and 1024) 00148 * 00149 */ 00150 int Read_XY(unsigned char XY); 00151 00152 /* 00153 * Draw a calibration crosshair on the LCD screen 00154 * 00155 * @param x (horizontal position) 00156 * @param y (vertical position) 00157 * 00158 */ 00159 void DrawCross(unsigned int Xpos,unsigned int Ypos); 00160 00161 /* 00162 * Set the calibration matrix 00163 * 00164 * @param displayPTR (pointer to display data) 00165 * @param screenPTR (pointer to screen data) 00166 * @param matrixPTR (pointer to calibration matrix) 00167 * 00168 * @returns 0 when matrix.divider != 0 00169 * @returns 1 when matrix.divider = 0 00170 * 00171 */ 00172 unsigned char setCalibrationMatrix( Coordinate * displayPtr,Coordinate * screenPtr,Matrix * matrixPtr); 00173 00174 }; 00175 #endif
Generated on Wed Jul 13 2022 21:19:22 by 1.7.2