Veikko Kero / Touch_tft

Dependents:   MIDI_Interface_ver_1

Fork of Touch_tft by Peter Drescher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers touch_tft.h Source File

touch_tft.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  *
00005  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00006  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00007  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00008  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00009  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00010  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00011  * THE SOFTWARE.
00012  */
00013 
00014 #ifndef MBED_TOUCH_H
00015 #define MBED_TOUCH_H
00016 
00017 #include "mbed.h"
00018 #include "SPI_TFT_ILI9341.h"
00019 
00020 struct point{
00021        unsigned short x;
00022        unsigned short y;
00023        };
00024        
00025 /** touchscreen control class, based on SPI_TFT
00026  *
00027  * Example:
00028  * @code
00029  * 
00030  * #include "mbed.h"
00031  * #include "SPI_TFT.h"
00032  * #include "Arial12x12.h"
00033  * #include "Arial28x28.h"
00034  * #include "touch_tft.h"
00035  * // the TFT is connected to SPI pin 5-7
00036  * // the touch is connected to 19,20,16,17
00037  *
00038  * touch_tft tt(p19,p20,p16,p17,p5, p6, p7, p8, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
00039  *
00040  * int main() {
00041  * point p;
00042  *
00043  *  tt.claim(stdout);        // send stdout to the TFT display
00044  *  tt.background(Black);    // set background to black
00045  *  tt.foreground(White);    // set chars to white
00046  *  tt.cls();                // clear the screen
00047  *  tt.set_font((unsigned char*) Arial12x12);  // select the font
00048  *  tt.set_orientation(1);
00049  *
00050  *  tt.calibrate();          // calibrate the touch
00051  * while (1) {
00052  *       p = tt.get_touch();   // read analog pos.
00053  *       if (tt.is_touched(p)) {  // test if touched
00054  *           p = tt.to_pixel(p);             // convert to pixel pos
00055  *           tt.fillcircle(p.x,p.y,3,Blue);  // print a blue dot on the screen
00056  *     }
00057  * }
00058  * @endcode
00059  */
00060 class touch_tft : public  SPI_TFT_ILI9341{
00061 public:
00062     /** create a TFT with touch object connected to the pins:
00063      *
00064      * @param pin xp resistiv touch x+
00065      * @param pin xm resistiv touch x-
00066      * @param pin yp resistiv touch y+
00067      * @param pin ym resistiv touch y-
00068      * @param mosi,miso,sclk SPI connection to TFT
00069      * @param cs pin connected to CS of display
00070      * @param reset pin connected to RESET of display 
00071      * based on my SPI_TFT lib
00072      */
00073     touch_tft(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT"); 
00074     
00075     /** calibrate the touch display
00076      *
00077      * User is asked to touch on two points on the screen
00078      */   
00079     void calibrate(void);
00080     
00081     /** read x and y analog samples
00082      *
00083      * @returns point(x,y)
00084      */
00085     point get_touch(void);
00086     
00087     /** calculate coord on screen
00088      *
00089      * @param a_point point(analog x, analog y)
00090      * @returns point(pixel x, pixel y)
00091      *
00092      */
00093     point to_pixel(point a_point);
00094     
00095     /** test if screen is touched
00096      * 
00097      * @param point analog x,y
00098      * @returns true is touched
00099      *
00100      */   
00101     bool is_touched(point a);    
00102     
00103 protected:
00104     DigitalInOut _xp;
00105     DigitalInOut _xm;
00106     DigitalInOut _yp;
00107     DigitalInOut _ym;
00108     AnalogIn     _ax;
00109     AnalogIn     _ay;
00110     PinName xa;
00111     PinName ya;
00112     
00113     
00114     unsigned short x_a,y_a;
00115     unsigned short x_off,y_off;
00116     unsigned short pp_tx,pp_ty;
00117     
00118     
00119            
00120     };
00121 
00122 #endif