.
UTouch.h@0:a275ef704eb8, 2016-01-11 (annotated)
- Committer:
- rpocc
- Date:
- Mon Jan 11 09:35:33 2016 +0000
- Revision:
- 0:a275ef704eb8
The first version of this mbed port
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rpocc | 0:a275ef704eb8 | 1 | /** \file UTouch.h |
rpocc | 0:a275ef704eb8 | 2 | * \brief mbed library for XPT2046 SPI Touchscreen Controller (TFT_320QVT module). |
rpocc | 0:a275ef704eb8 | 3 | * \copyright GNU Public License, v2. or later |
rpocc | 0:a275ef704eb8 | 4 | * |
rpocc | 0:a275ef704eb8 | 5 | * A known display with this type of controller chip is the ITDB02-3.2S |
rpocc | 0:a275ef704eb8 | 6 | * from http://imall.iteadstudio.com |
rpocc | 0:a275ef704eb8 | 7 | * |
rpocc | 0:a275ef704eb8 | 8 | * This library is based on the Arduino/chipKIT UTFT library by Henning |
rpocc | 0:a275ef704eb8 | 9 | * Karlsen, http://www.rinkydinkelectronics.com/library.php?id=55 |
rpocc | 0:a275ef704eb8 | 10 | * |
rpocc | 0:a275ef704eb8 | 11 | * Pressure sensivity added by Dmitry Shtatnov |
rpocc | 0:a275ef704eb8 | 12 | * |
rpocc | 0:a275ef704eb8 | 13 | * Copyright (C)2010-2015 Henning Karlsen. All right reserved. |
rpocc | 0:a275ef704eb8 | 14 | * |
rpocc | 0:a275ef704eb8 | 15 | * Copyright (C)2016 Dmitry Shtatnov. All right reserved. |
rpocc | 0:a275ef704eb8 | 16 | * http://modularsynth.ru/ |
rpocc | 0:a275ef704eb8 | 17 | * |
rpocc | 0:a275ef704eb8 | 18 | * This library is free software; you can redistribute it and/or |
rpocc | 0:a275ef704eb8 | 19 | * modify it under the terms of the GNU Lesser General Public |
rpocc | 0:a275ef704eb8 | 20 | * License as published by the Free Software Foundation; either |
rpocc | 0:a275ef704eb8 | 21 | * version 2.1 of the License, or (at your option) any later version. |
rpocc | 0:a275ef704eb8 | 22 | * |
rpocc | 0:a275ef704eb8 | 23 | * This library is distributed in the hope that it will be useful, |
rpocc | 0:a275ef704eb8 | 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
rpocc | 0:a275ef704eb8 | 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
rpocc | 0:a275ef704eb8 | 26 | * Lesser General Public License for more details. |
rpocc | 0:a275ef704eb8 | 27 | * |
rpocc | 0:a275ef704eb8 | 28 | * You should have received a copy of the GNU Lesser General Public |
rpocc | 0:a275ef704eb8 | 29 | * License along with this library; if not, write to: |
rpocc | 0:a275ef704eb8 | 30 | * |
rpocc | 0:a275ef704eb8 | 31 | * Free Software Foundation, Inc. |
rpocc | 0:a275ef704eb8 | 32 | * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA |
rpocc | 0:a275ef704eb8 | 33 | * |
rpocc | 0:a275ef704eb8 | 34 | *********************************************************************/ |
rpocc | 0:a275ef704eb8 | 35 | |
rpocc | 0:a275ef704eb8 | 36 | #include "mbed.h" |
rpocc | 0:a275ef704eb8 | 37 | |
rpocc | 0:a275ef704eb8 | 38 | #ifndef UTouch_h |
rpocc | 0:a275ef704eb8 | 39 | #define UTouch_h |
rpocc | 0:a275ef704eb8 | 40 | |
rpocc | 0:a275ef704eb8 | 41 | #ifdef __cplusplus |
rpocc | 0:a275ef704eb8 | 42 | extern "C" { |
rpocc | 0:a275ef704eb8 | 43 | #endif |
rpocc | 0:a275ef704eb8 | 44 | |
rpocc | 0:a275ef704eb8 | 45 | /** Represents a Touchscreen instance. |
rpocc | 0:a275ef704eb8 | 46 | * |
rpocc | 0:a275ef704eb8 | 47 | * This is the utility class, through which the XPT2046 touchscreen can be manipulated |
rpocc | 0:a275ef704eb8 | 48 | * How to use: |
rpocc | 0:a275ef704eb8 | 49 | * \code |
rpocc | 0:a275ef704eb8 | 50 | * // If you are using TFT-320QVT TFT LCD module or similar, you also have to add |
rpocc | 0:a275ef704eb8 | 51 | * // SSD1289 library by Todor Todorov or modified version by Dmitry Shtatnov |
rpocc | 0:a275ef704eb8 | 52 | * |
rpocc | 0:a275ef704eb8 | 53 | * #include "mbed.h" |
rpocc | 0:a275ef704eb8 | 54 | * #include "ssd1289.h" |
rpocc | 0:a275ef704eb8 | 55 | * #include "UTouch.h" |
rpocc | 0:a275ef704eb8 | 56 | * PortOut LCDPA(PortA,0xFF00); |
rpocc | 0:a275ef704eb8 | 57 | * PortOut LCDPC(PortC,0x00FF); |
rpocc | 0:a275ef704eb8 | 58 | * // CS, REST, RS, WR, DATA, BL, RD |
rpocc | 0:a275ef704eb8 | 59 | * SSD1289_LCD myGLCD(PB_3, PB_4, PB_0, PB_1, &LCDPA, &LCDPC, NC, PB_2); |
rpocc | 0:a275ef704eb8 | 60 | * |
rpocc | 0:a275ef704eb8 | 61 | * UTouch myTouch(PB_9, PB_8, PB_7, PB_6, PB_5); |
rpocc | 0:a275ef704eb8 | 62 | * |
rpocc | 0:a275ef704eb8 | 63 | * int main() { |
rpocc | 0:a275ef704eb8 | 64 | * myGLCD.Initialize(); |
rpocc | 0:a275ef704eb8 | 65 | * myGLCD.SetBackground(COLOR_WHITE); |
rpocc | 0:a275ef704eb8 | 66 | * myGLCD.SetForeground(COLOR_BLACK); |
rpocc | 0:a275ef704eb8 | 67 | * myGLCD.FillScreen(COLOR_WHITE); |
rpocc | 0:a275ef704eb8 | 68 | * myTouch.InitTouch(); |
rpocc | 0:a275ef704eb8 | 69 | * myTouch.SetPrecision(PREC_HI); |
rpocc | 0:a275ef704eb8 | 70 | * while(1==1) |
rpocc | 0:a275ef704eb8 | 71 | * { |
rpocc | 0:a275ef704eb8 | 72 | * if (myTouch.DataAvailable()) |
rpocc | 0:a275ef704eb8 | 73 | * { |
rpocc | 0:a275ef704eb8 | 74 | * if(myTouch.Read()) |
rpocc | 0:a275ef704eb8 | 75 | * { |
rpocc | 0:a275ef704eb8 | 76 | * x = myTouch.GetX(); |
rpocc | 0:a275ef704eb8 | 77 | * y = myTouch.GetY(); |
rpocc | 0:a275ef704eb8 | 78 | * myGLCD.DrawPixel(x, y, COLOR_BLACK); |
rpocc | 0:a275ef704eb8 | 79 | * } |
rpocc | 0:a275ef704eb8 | 80 | * } |
rpocc | 0:a275ef704eb8 | 81 | * } |
rpocc | 0:a275ef704eb8 | 82 | * } |
rpocc | 0:a275ef704eb8 | 83 | * |
rpocc | 0:a275ef704eb8 | 84 | * \endcode |
rpocc | 0:a275ef704eb8 | 85 | * \version 0.1 |
rpocc | 0:a275ef704eb8 | 86 | * \author Dmitry Shtatnov |
rpocc | 0:a275ef704eb8 | 87 | */ |
rpocc | 0:a275ef704eb8 | 88 | |
rpocc | 0:a275ef704eb8 | 89 | |
rpocc | 0:a275ef704eb8 | 90 | #define UTOUCH_VERSION 124 |
rpocc | 0:a275ef704eb8 | 91 | |
rpocc | 0:a275ef704eb8 | 92 | // *** Hardwarespecific defines *** |
rpocc | 0:a275ef704eb8 | 93 | #define swap(type, i, j) {type t = i; i = j; j = t;} |
rpocc | 0:a275ef704eb8 | 94 | |
rpocc | 0:a275ef704eb8 | 95 | #define LOW 0 |
rpocc | 0:a275ef704eb8 | 96 | #define HIGH 1 |
rpocc | 0:a275ef704eb8 | 97 | |
rpocc | 0:a275ef704eb8 | 98 | #define PORTRAIT 0 |
rpocc | 0:a275ef704eb8 | 99 | #define LANDSCAPE 1 |
rpocc | 0:a275ef704eb8 | 100 | |
rpocc | 0:a275ef704eb8 | 101 | #define PREC_LOW 1 |
rpocc | 0:a275ef704eb8 | 102 | #define PREC_MEDIUM 2 |
rpocc | 0:a275ef704eb8 | 103 | #define PREC_HI 3 |
rpocc | 0:a275ef704eb8 | 104 | #define PREC_EXTREME 4 |
rpocc | 0:a275ef704eb8 | 105 | |
rpocc | 0:a275ef704eb8 | 106 | #define byte uint8_t |
rpocc | 0:a275ef704eb8 | 107 | #define word uint16_t |
rpocc | 0:a275ef704eb8 | 108 | class UTouch |
rpocc | 0:a275ef704eb8 | 109 | { |
rpocc | 0:a275ef704eb8 | 110 | public: |
rpocc | 0:a275ef704eb8 | 111 | int16_t TP_X ,TP_Y, TP_Z1, TP_Z2; |
rpocc | 0:a275ef704eb8 | 112 | |
rpocc | 0:a275ef704eb8 | 113 | UTouch(PinName tclk, PinName tcs, PinName tdin, PinName dout, PinName irq); |
rpocc | 0:a275ef704eb8 | 114 | |
rpocc | 0:a275ef704eb8 | 115 | void InitTouch(byte orientation = LANDSCAPE); |
rpocc | 0:a275ef704eb8 | 116 | bool Read(); |
rpocc | 0:a275ef704eb8 | 117 | bool DataAvailable(); |
rpocc | 0:a275ef704eb8 | 118 | int16_t GetX(); |
rpocc | 0:a275ef704eb8 | 119 | int16_t GetY(); |
rpocc | 0:a275ef704eb8 | 120 | void SetPrecision(byte precision); |
rpocc | 0:a275ef704eb8 | 121 | |
rpocc | 0:a275ef704eb8 | 122 | void CalibrateRead(); |
rpocc | 0:a275ef704eb8 | 123 | int16_t GetPressure(); |
rpocc | 0:a275ef704eb8 | 124 | void SetTreshold(int16_t trshLow, int16_t trshHigh); |
rpocc | 0:a275ef704eb8 | 125 | |
rpocc | 0:a275ef704eb8 | 126 | protected: |
rpocc | 0:a275ef704eb8 | 127 | int16_t GetXraw(); |
rpocc | 0:a275ef704eb8 | 128 | int16_t GetYraw(); |
rpocc | 0:a275ef704eb8 | 129 | int16_t GetZ1raw(); |
rpocc | 0:a275ef704eb8 | 130 | int16_t GetZ2raw(); |
rpocc | 0:a275ef704eb8 | 131 | DigitalOut P_CLK, P_CS, P_DIN; |
rpocc | 0:a275ef704eb8 | 132 | DigitalIn P_DOUT; |
rpocc | 0:a275ef704eb8 | 133 | DigitalInOut P_IRQ; |
rpocc | 0:a275ef704eb8 | 134 | long _default_orientation; |
rpocc | 0:a275ef704eb8 | 135 | byte orient; |
rpocc | 0:a275ef704eb8 | 136 | byte prec; |
rpocc | 0:a275ef704eb8 | 137 | byte display_model; |
rpocc | 0:a275ef704eb8 | 138 | long disp_x_size, disp_y_size, default_orientation; |
rpocc | 0:a275ef704eb8 | 139 | long touch_x_left, touch_x_right, touch_y_top, touch_y_bottom; |
rpocc | 0:a275ef704eb8 | 140 | |
rpocc | 0:a275ef704eb8 | 141 | void touch_WriteData(byte data); |
rpocc | 0:a275ef704eb8 | 142 | word touch_ReadData(); |
rpocc | 0:a275ef704eb8 | 143 | int16_t touch_tresholdLow; |
rpocc | 0:a275ef704eb8 | 144 | int16_t touch_tresholdHigh; |
rpocc | 0:a275ef704eb8 | 145 | int16_t touch_getrawdata(uint8_t code); |
rpocc | 0:a275ef704eb8 | 146 | }; |
rpocc | 0:a275ef704eb8 | 147 | |
rpocc | 0:a275ef704eb8 | 148 | #ifdef __cplusplus |
rpocc | 0:a275ef704eb8 | 149 | } |
rpocc | 0:a275ef704eb8 | 150 | #endif |
rpocc | 0:a275ef704eb8 | 151 | |
rpocc | 0:a275ef704eb8 | 152 | #endif |