Stepan Smejkal / UTouch_vyrobek
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UTouch.h Source File

UTouch.h

Go to the documentation of this file.
00001 /** \file UTouch.h
00002  *  \brief mbed library for XPT2046 SPI Touchscreen Controller (TFT_320QVT module).
00003  *  \copyright GNU Public License, v2. or later
00004  *
00005  * A known display with this type of controller chip is the ITDB02-3.2S
00006  * from http://imall.iteadstudio.com
00007  *
00008  * This library is based on the Arduino/chipKIT UTFT library by Henning
00009  * Karlsen, http://www.rinkydinkelectronics.com/library.php?id=55
00010  *
00011  * Pressure sensivity added by Dmitry Shtatnov
00012  *
00013  * Copyright (C)2010-2015 Henning Karlsen. All right reserved.
00014  *
00015  * Copyright (C)2016 Dmitry Shtatnov. All right reserved.
00016  * http://modularsynth.ru/
00017  *
00018  * This library is free software; you can redistribute it and/or
00019  * modify it under the terms of the GNU Lesser General Public
00020  * License as published by the Free Software Foundation; either
00021  * version 2.1 of the License, or (at your option) any later version.
00022  *
00023  * This library is distributed in the hope that it will be useful,
00024  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00025  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026  * Lesser General Public License for more details.
00027  *
00028  * You should have received a copy of the GNU Lesser General Public
00029  * License along with this library; if not, write to:
00030  *
00031  * Free Software Foundation, Inc.
00032  * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
00033  *
00034  *********************************************************************/
00035 
00036 #include "mbed.h"
00037 
00038 #ifndef UTouch_h
00039 #define UTouch_h
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 /** Represents a Touchscreen instance.
00046  *
00047  * This is the utility class, through which the XPT2046 touchscreen can be manipulated
00048  * How to use:
00049  * \code
00050  * // If you are using TFT-320QVT TFT LCD module or similar, you also have to add
00051  * // SSD1289 library by Todor Todorov or modified version by Dmitry Shtatnov
00052  * 
00053  * #include "mbed.h"
00054  * #include "ssd1289.h"
00055  * #include "UTouch.h"
00056  * PortOut LCDPA(PortA,0xFF00);
00057  * PortOut LCDPC(PortC,0x00FF);
00058  * //                 CS,   REST, RS,   WR,   DATA,      BL, RD
00059  * SSD1289_LCD myGLCD(PB_3, PB_4, PB_0, PB_1, &LCDPA, &LCDPC, NC, PB_2);
00060  * 
00061  * UTouch  myTouch(PB_9, PB_8, PB_7, PB_6, PB_5);
00062  * 
00063  * int main() {
00064  *   myGLCD.Initialize();
00065  *   myGLCD.SetBackground(COLOR_WHITE);
00066  *   myGLCD.SetForeground(COLOR_BLACK);
00067  *   myGLCD.FillScreen(COLOR_WHITE);
00068  *   myTouch.InitTouch();
00069  *   myTouch.SetPrecision(PREC_HI);
00070  *   while(1==1)
00071  *   {
00072  *     if (myTouch.DataAvailable())
00073  *     {
00074  *       if(myTouch.Read())
00075  *       {
00076  *         x = myTouch.GetX();
00077  *         y = myTouch.GetY();
00078  *         myGLCD.DrawPixel(x, y, COLOR_BLACK);
00079  *       }
00080  *     }
00081  *   }
00082  * }
00083  *
00084  * \endcode
00085  * \version 0.1
00086  * \author Dmitry Shtatnov
00087  */
00088 
00089 
00090 #define UTOUCH_VERSION  124
00091 
00092 // *** Hardwarespecific defines ***
00093 #define swap(type, i, j) {type t = i; i = j; j = t;}
00094 
00095 #define LOW                 0
00096 #define HIGH                1
00097 
00098 #define PORTRAIT            0
00099 #define LANDSCAPE           1
00100 
00101 #define PREC_LOW            1
00102 #define PREC_MEDIUM         2
00103 #define PREC_HI             3
00104 #define PREC_EXTREME        4
00105 
00106 #define byte uint8_t
00107 #define word uint16_t
00108 class UTouch
00109 {
00110     public:
00111         int16_t TP_X ,TP_Y, TP_Z1, TP_Z2;
00112 
00113                 UTouch(PinName tclk, PinName tcs, PinName tdin, PinName dout, PinName irq);
00114 
00115         void    InitTouch(byte orientation = LANDSCAPE);
00116         bool    Read();
00117         bool    DataAvailable();
00118         int16_t GetX();
00119         int16_t GetY();
00120         void    SetPrecision(byte precision);
00121 
00122         void    CalibrateRead();
00123         int16_t GetPressure();
00124         void    SetTreshold(int16_t trshLow, int16_t trshHigh);
00125     
00126     protected:
00127         int16_t GetXraw();
00128         int16_t GetYraw();
00129         int16_t GetZ1raw();
00130         int16_t GetZ2raw();
00131         DigitalOut P_CLK, P_CS, P_DIN;
00132         DigitalIn P_DOUT;
00133         DigitalInOut P_IRQ;
00134         long    _default_orientation;
00135         byte    orient;
00136         byte    prec;
00137         byte    display_model;
00138         long    disp_x_size, disp_y_size, default_orientation;
00139         long    touch_x_left, touch_x_right, touch_y_top, touch_y_bottom;
00140 
00141         void    touch_WriteData(byte data);
00142         word    touch_ReadData();
00143         int16_t touch_tresholdLow;
00144         int16_t touch_tresholdHigh;
00145         int16_t touch_getrawdata(uint8_t code);
00146 };
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151 
00152 #endif