Modified to work with two displays

Dependents:   touch2 default CANary_9341_test CANary_merge

Fork of Touch_tft by Peter Drescher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TOUCH_TFTx2.h Source File

TOUCH_TFTx2.h

00001 /* mbed library for touchscreen connected to 4 mbed pins
00002  * derive from SPI_TFT lib
00003  * Copyright (c) 2011 Peter Drescher - DC2PD
00004  * Updated by YoongHM to use SPI_TFTx2 or SPI_TFTx2_ILI9341
00005  *
00006  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00007  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00008  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00009  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00010  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00011  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00012  * THE SOFTWARE.
00013  */
00014 
00015 #ifndef MBED_TOUCH_TFTx2_H
00016 #define MBED_TOUCH_TFTx2_H
00017 
00018 // Include this before other header files
00019 #include "precompile.h"
00020 
00021 #include "mbed.h"
00022 
00023 #if USE_ILI9341 == 1
00024 #include "SPI_TFTx2_ILI9341.h"
00025 #else
00026 #include "SPI_TFTx2.h"
00027 #endif
00028 
00029 struct point{
00030        unsigned short x;
00031        unsigned short y;
00032        };
00033 
00034 
00035 #if USE_ILI9341 == 1
00036 class TOUCH_TFTx2 : public  SPI_TFTx2_ILI9341 {
00037 #else
00038 class TOUCH_TFTx2 : public  SPI_TFTx2 {
00039 #endif
00040 public:
00041 
00042 #if USE_ILI9341 == 1
00043     /** create a TFT with touch object connected to the pins:
00044      *
00045      * @param pin xp resistiv touch x+
00046      * @param pin xm resistiv touch x-
00047      * @param pin yp resistiv touch y+
00048      * @param pin ym resistiv touch y-
00049      * @param mosi,miso,sclk SPI connection to TFT
00050      * @param cs pin connected to CS of display
00051      * @param reset pin connected to RESET of display
00052      * @param dc pin connected to WR of display
00053      * based on my SPI_TFT lib
00054      */
00055     TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi, 
00056                 PinName miso, PinName sclk, PinName cs0, PinName cs1, 
00057                 PinName reset, PinName dc, const char* name ="TFT");
00058 #else
00059     /** create a TFT with touch object connected to the pins:
00060      *
00061      * @param pin xp resistiv touch x+
00062      * @param pin xm resistiv touch x-
00063      * @param pin yp resistiv touch y+
00064      * @param pin ym resistiv touch y-
00065      * @param mosi,miso,sclk SPI connection to TFT
00066      * @param cs pin connected to CS of display
00067      * @param reset pin connected to RESET of display
00068      * based on my SPI_TFT lib
00069      */
00070     TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi,
00071                 PinName miso, PinName sclk, PinName cs0, PinName cs1, 
00072                 PinName reset, const char* name ="TFT");
00073 #endif
00074 
00075     unsigned short x0_off,y0_off;
00076     unsigned short x0_pp,y0_pp;
00077     unsigned short x1_off,y1_off;
00078     unsigned short x1_pp,y1_pp;
00079     unsigned short x_mid;
00080 
00081     /** calibrate the touch display
00082      *
00083      * User is asked to touch on two points on the screen
00084      */
00085     void calibrate(void);
00086 
00087     /** read x and y analog samples
00088      *
00089      * @returns point(x,y)
00090      */
00091 
00092     void setcal(int _x0off, int _y0off, int _x0pp, int _y0pp, int _x1off, int _y1off, int _x1pp, int _y1pp, int _xmin);
00093     /** set calibration values directly (bypass calibration)
00094     *
00095     */
00096 
00097     point get_touch(void);
00098 
00099     /** calculate coord on screen
00100      *
00101      * @param a_point point(analog x, analog y)
00102      * @returns point(pixel x, pixel y)
00103      *
00104      */
00105     point to_pixel(point a_point);
00106 
00107     /** test if screen is touched
00108      *
00109      * @param point analog x,y
00110      * @returns true is touched
00111      *
00112      */
00113     bool is_touched(void);
00114 
00115     void wfi(void);
00116 
00117 protected:
00118     DigitalInOut _xp;
00119     DigitalInOut _xm;
00120     DigitalInOut _yp;
00121     DigitalInOut _ym;
00122     AnalogIn     _ax;
00123     AnalogIn     _ay;
00124     PinName xa;
00125     PinName ya;
00126 
00127     unsigned short x_a,y_a;
00128     };
00129 
00130 #endif /* MBED_TOUCH_TFTx2_H */