Modified to work with two displays

Dependents:   touch2 default CANary_9341_test CANary_merge

Fork of Touch_tft by Peter Drescher

Revision:
16:bee053b17977
Parent:
15:f2165aa0daa6
--- a/TOUCH_TFTx2.h	Mon May 12 03:19:02 2014 +0000
+++ b/TOUCH_TFTx2.h	Sun May 18 12:45:30 2014 +0000
@@ -1,6 +1,7 @@
 /* mbed library for touchscreen connected to 4 mbed pins
- * derive from SPI_TFT lib 
+ * derive from SPI_TFT lib
  * Copyright (c) 2011 Peter Drescher - DC2PD
+ * Updated by YoongHM to use SPI_TFTx2 or SPI_TFTx2_ILI9341
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -11,11 +12,19 @@
  * THE SOFTWARE.
  */
 
-#ifndef MBED_TOUCH_H
-#define MBED_TOUCH_H
+#ifndef MBED_TOUCH_TFTx2_H
+#define MBED_TOUCH_TFTx2_H
+
+// Include this before other header files
+#include "precompile.h"
 
 #include "mbed.h"
+
+#if USE_ILI9341 == 1
 #include "SPI_TFTx2_ILI9341.h"
+#else
+#include "SPI_TFTx2.h"
+#endif
 
 struct point{
        unsigned short x;
@@ -23,8 +32,14 @@
        };
 
 
-class TOUCH_TFTx2 : public  SPI_TFTx2{
+#if USE_ILI9341 == 1
+class TOUCH_TFTx2 : public  SPI_TFTx2_ILI9341 {
+#else
+class TOUCH_TFTx2 : public  SPI_TFTx2 {
+#endif
 public:
+
+#if USE_ILI9341 == 1
     /** create a TFT with touch object connected to the pins:
      *
      * @param pin xp resistiv touch x+
@@ -33,24 +48,42 @@
      * @param pin ym resistiv touch y-
      * @param mosi,miso,sclk SPI connection to TFT
      * @param cs pin connected to CS of display
-     * @param reset pin connected to RESET of display 
+     * @param reset pin connected to RESET of display
      * @param dc pin connected to WR of display
      * based on my SPI_TFT lib
      */
-    TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi, PinName miso, PinName sclk, PinName cs0, PinName cs1, PinName reset, PinName dc,const char* name ="TFT");
+    TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi, 
+                PinName miso, PinName sclk, PinName cs0, PinName cs1, 
+                PinName reset, PinName dc, const char* name ="TFT");
+#else
+    /** create a TFT with touch object connected to the pins:
+     *
+     * @param pin xp resistiv touch x+
+     * @param pin xm resistiv touch x-
+     * @param pin yp resistiv touch y+
+     * @param pin ym resistiv touch y-
+     * @param mosi,miso,sclk SPI connection to TFT
+     * @param cs pin connected to CS of display
+     * @param reset pin connected to RESET of display
+     * based on my SPI_TFT lib
+     */
+    TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi,
+                PinName miso, PinName sclk, PinName cs0, PinName cs1, 
+                PinName reset, const char* name ="TFT");
+#endif
 
     unsigned short x0_off,y0_off;
     unsigned short x0_pp,y0_pp;
     unsigned short x1_off,y1_off;
     unsigned short x1_pp,y1_pp;
     unsigned short x_mid;
-    
+
     /** calibrate the touch display
      *
      * User is asked to touch on two points on the screen
-     */   
+     */
     void calibrate(void);
-    
+
     /** read x and y analog samples
      *
      * @returns point(x,y)
@@ -62,7 +95,7 @@
     */
 
     point get_touch(void);
-    
+
     /** calculate coord on screen
      *
      * @param a_point point(analog x, analog y)
@@ -70,17 +103,17 @@
      *
      */
     point to_pixel(point a_point);
-    
+
     /** test if screen is touched
-     * 
+     *
      * @param point analog x,y
      * @returns true is touched
      *
-     */   
-    bool is_touched(void);    
+     */
+    bool is_touched(void);
 
-    void wfi(void);    
-    
+    void wfi(void);
+
 protected:
     DigitalInOut _xp;
     DigitalInOut _xm;
@@ -94,4 +127,4 @@
     unsigned short x_a,y_a;
     };
 
-#endif
\ No newline at end of file
+#endif /* MBED_TOUCH_TFTx2_H */
\ No newline at end of file