FT6206 Library for Adafruit 2.8" TFT Touch Shield for Arduino w/Capacitive Touch
Dependents: ArchPro_TFT ATT_AWS_IoT_demo_v06 ArchPro_TFT TermProject
FT6206.h
00001 /* 00002 Copyright (c) 2015 Jack Berkhout 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 00022 This is a library for the Adafruit Capacitive Touch Screens 00023 ----> http://www.adafruit.com/products/1947 00024 This chipset uses I2C to communicate 00025 00026 Based on code by Limor Fried/Ladyada for Adafruit Industries. 00027 MIT license, all text above must be included in any redistribution. 00028 00029 On the shield, these jumpers were bridged: 00030 Int - #7 (default) 00031 SCK - 13 (default) 00032 SO - 12 (default) 00033 SI - 11 00034 SCL - SCL 00035 SDA - SDA 00036 00037 Usage: 00038 00039 #include "mbed.h" 00040 #include "SPI_TFT_ILI9341.h" 00041 #include "FT6206.h" 00042 #include "Arial12x12.h" 00043 00044 #define PIN_XP A3 00045 #define PIN_XM A1 00046 #define PIN_YP A2 00047 #define PIN_YM A0 00048 #define PIN_SCLK D13 00049 #define PIN_MISO D12 00050 #define PIN_MOSI D11 00051 #define PIN_CS_TFT D10 // chip select pin 00052 #define PIN_DC_TFT D9 // data/command select pin. 00053 #define PIN_RESET_TFT D8 00054 //#define PIN_BL_TFT D7 00055 #define PIN_CS_SD D4 00056 00057 #define PORTRAIT 0 00058 #define LANDSCAPE 1 00059 00060 #define PIN_SCL_FT6206 P0_28 00061 #define PIN_SDA_FT6206 P0_27 00062 #define PIN_INT_FT6206 D7 00063 00064 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "TFT"); // mosi, miso, sclk, cs, reset, dc 00065 FT6206 FT6206(PIN_SDA_FT6206, PIN_SCL_FT6206, PIN_INT_FT6206); // sda, scl, int 00066 00067 int main() 00068 { 00069 //Configure the display driver 00070 TFT.claim(stdout); 00071 TFT.background(Black); 00072 TFT.foreground(White); 00073 TFT.set_orientation(LANDSCAPE); 00074 TFT.cls(); 00075 00076 //Print a welcome message 00077 TFT.set_font((unsigned char*) Arial12x12); 00078 TFT.locate(0,0); 00079 TFT.printf("Hello mbed!\n"); 00080 00081 while(1) { 00082 int X1, Y1, X2, Y2; 00083 TS_Point p; 00084 if (FT6206.getTouchPoint(p)) { 00085 X1 = X2; 00086 Y1 = Y2; 00087 X2 = p.x; 00088 Y2 = p.y; 00089 TFT.locate(0,12); 00090 printf("Touch %3d %3d\n", p.x, p.y); 00091 if ((X1 > 0) && (Y1 > 0) && (X2 > 0) && (Y2 > 0)) { 00092 TFT.line(X1, Y1, X2, Y2, RGB(255,128,255)); 00093 } 00094 } 00095 } 00096 } 00097 */ 00098 00099 #ifndef FT6206_H 00100 #define FT6206_H 00101 00102 #include "mbed.h" 00103 00104 #define FT6206_I2C_FREQUENCY 400000 00105 00106 #define FT6206_ADDR 0x38 00107 #define FT6206_G_FT5201ID 0xA8 00108 #define FT6206_REG_NUMTOUCHES 0x02 00109 00110 #define FT6206_NUM_X 0x33 00111 #define FT6206_NUM_Y 0x34 00112 00113 #define FT6206_REG_MODE 0x00 00114 #define FT6206_REG_CALIBRATE 0x02 00115 #define FT6206_REG_WORKMODE 0x00 00116 #define FT6206_REG_FACTORYMODE 0x40 00117 #define FT6206_REG_THRESHHOLD 0x80 00118 #define FT6206_REG_POINTRATE 0x88 00119 #define FT6206_REG_FIRMVERS 0xA6 00120 #define FT6206_REG_CHIPID 0xA3 00121 #define FT6206_REG_VENDID 0xA8 00122 00123 // calibrated for Adafruit 2.8" ctp screen 00124 #define FT6206_DEFAULT_THRESSHOLD 0x80 00125 00126 #define ILI9341_TFTWIDTH 320 00127 #define ILI9341_TFTHEIGHT 240 00128 00129 class TS_Point { 00130 public: 00131 TS_Point(void); 00132 TS_Point(int16_t x, int16_t y, int16_t z); 00133 00134 bool operator==(TS_Point); 00135 bool operator!=(TS_Point); 00136 00137 int16_t x, y, z; 00138 }; 00139 00140 class FT6206 { 00141 public: 00142 //!Creates an instance of the class. 00143 /*! 00144 FT6206 display touchscreen at I2C using I2C port pins sda, scl, and interrupt pins. 00145 TMP102 00146 \param sda, scl, interrupt 00147 */ 00148 FT6206(PinName sda, PinName scl, PinName interrupt); 00149 00150 /*! 00151 Destroys instance. 00152 */ 00153 ~FT6206(); 00154 00155 bool init(uint8_t thresh = FT6206_DEFAULT_THRESSHOLD); 00156 00157 void writeRegister8(char reg, char val); 00158 char readRegister8(char reg); 00159 char dataReceived(void); 00160 00161 void readData(uint16_t *x, uint16_t *y); 00162 00163 bool touched(void); 00164 TS_Point getPoint(void); 00165 TS_Point clearPoint(void); 00166 00167 void checkDataReceived(void); 00168 00169 bool getDataReceived(void); 00170 00171 void waitScreenTapped(void); 00172 00173 bool getTouchPoint(TS_Point &p); 00174 00175 Ticker tick; 00176 00177 private: 00178 // DigitalIn m_interrupt; 00179 InterruptIn m_interrupt; 00180 00181 I2C m_i2c; 00182 int m_addr; 00183 char data[2]; 00184 00185 uint8_t touches; 00186 uint16_t touchX[2], touchY[2], touchID[2]; 00187 00188 bool DataReceived; 00189 00190 00191 }; 00192 00193 #endif 00194
Generated on Thu Jul 14 2022 07:18:42 by 1.7.2