Fork with support for ILI9341 controller
Dependents: CANary_9341 CANary
Fork of TOUCH_TFTx2 by
Revision 16:bee053b17977, committed 2014-05-18
- Comitter:
- TickTock
- Date:
- Sun May 18 12:45:30 2014 +0000
- Parent:
- 15:f2165aa0daa6
- Commit message:
- Works with both controllers using precompiler directive
Changed in this revision
--- a/TOUCH_TFTx2.cpp Mon May 12 03:19:02 2014 +0000 +++ b/TOUCH_TFTx2.cpp Sun May 18 12:45:30 2014 +0000 @@ -21,14 +21,27 @@ #define accuracy 1000 // noise filter #define numsamp 16 // number of averaging samples +#if USE_ILI9341== 1 TOUCH_TFTx2::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): + PinName mosi, PinName miso, PinName sclk, PinName cs0, + PinName cs1, PinName reset, PinName dc, + const char* name): _xp(xp),_xm(xm),_yp(yp),_ym(ym),_ax(xp),_ay(yp), - SPI_TFTx2(mosi,miso,sclk,cs0,cs1,reset,dc,name) { + SPI_TFTx2_ILI9341(mosi,miso,sclk,cs0,cs1,reset,dc,name) { xa = xp; ya = yp; - } +#else +TOUCH_TFTx2::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): + _xp(xp),_xm(xm),_yp(yp),_ym(ym),_ax(xp),_ay(yp), + SPI_TFTx2(mosi,miso,sclk,cs0,cs1,reset,name) { + xa = xp; + ya = yp; +} +#endif point TOUCH_TFTx2::get_touch() { unsigned short x1, x2=0, y1, y2=0, i=0, j=0, k;
--- 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/precompile.h Sun May 18 12:45:30 2014 +0000 @@ -0,0 +1,6 @@ +#ifndef PRECOMPILE_H +#define PRECOMPILE_H + +#define USE_ILI9341 0 + +#endif /* PRECOMPILE_H */