Fork with support for ILI9341 controller
Dependents: CANary_9341 CANary
Fork of TOUCH_TFTx2 by
Revision 6:a91b668b058a, committed 2013-02-17
- Comitter:
- TickTock
- Date:
- Sun Feb 17 16:44:06 2013 +0000
- Parent:
- 5:a9890c586a64
- Child:
- 7:9cc43f20e365
- Commit message:
- Added colors and interrupt driven touch support;
Changed in this revision
TOUCH_TFTx2.cpp | Show annotated file Show diff for this revision Revisions of this file |
TOUCH_TFTx2.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TOUCH_TFTx2.cpp Thu Feb 14 00:26:54 2013 +0000 +++ b/TOUCH_TFTx2.cpp Sun Feb 17 16:44:06 2013 +0000 @@ -16,7 +16,7 @@ #include "TOUCH_TFTx2.h" #include "mbed.h" -#define threshold 0x1000 // threshold to detect pressed +#define threshold 0x8000 // threshold to detect pressed #define accuracy 300 // noise filter #define numsamp 16 // number of averaging samples @@ -122,6 +122,7 @@ //locate(1,100); //printf("d: %4d x: %5d",dx,p.x); //wait(0.25); + wfi(); //enable touchpad input return(p); }//*/ @@ -131,140 +132,154 @@ int ulx1 = 0, uly1 = 0, brx1 = 0, bry1 = 0; int pos_x, pos_y; point p; - - seldisp=1; // select right display - cls(); - line(0,3,6,3,White); - line(3,0,3,6,White); - - // get the center of the screen - pos_x = columns() / 2 - 3; - pos_x = pos_x * font[1]; - pos_y = (rows() / 2) - 1; - pos_y = pos_y * font[2]; + if(true){ //skip cal for me + x0_off = 5570; + y0_off = 34030; + x0_pp = 80; + y0_pp = 108; + x1_off = 33700; + y1_off = 5780; + x1_pp = 82; + y1_pp = 108; + x_mid = 32500; + } else { + seldisp=1; // select right display + cls(); + line(0,3,6,3,White); + line(3,0,3,6,White); - //calibrate right screen - locate(pos_x,pos_y); - printf("press cross"); - locate(pos_x,pos_y + font[2]); - printf("to calibrate"); - do { - wait(0.1); - } while (!is_touched()); //Wait for touch - for (i=0; i<5; i++) { + // get the center of the screen + pos_x = columns() / 2 - 3; + pos_x = pos_x * font[1]; + pos_y = (rows() / 2) - 1; + pos_y = pos_y * font[2]; + + //calibrate right screen + locate(pos_x,pos_y); + printf("press cross"); + locate(pos_x,pos_y + font[2]); + printf("to calibrate"); + do { + wait(0.1); + } while (!is_touched()); //Wait for touch + for (i=0; i<5; i++) { + do { + p = get_touch(); + } while (p.x==0 && p.y==0); + ulx1 += p.x; + uly1 += p.y; + } + ulx1 /= 5; + uly1 /= 5; + locate(pos_x,pos_y); + printf("OK "); + printf(" "); + do { + wait(0.1); + } while (is_touched()); //Wait for no touch + + cls(); + line(width() -1, height() - 4,width() - 7,height() -4,White); // paint cross + line(width() - 4,height() - 1,width() - 4,height() - 7,White); + locate(pos_x,pos_y); + printf("press cross"); + locate(pos_x,pos_y + font[2]); + printf("to calibrate"); + do { + wait(0.1); + } while (!is_touched()); //Wait for touch + for (i=0; i<5; i++) { + do { + p = get_touch(); + } while (p.x==0 && p.y==0); p = get_touch(); + brx1 += p.x; + bry1 += p.y; + } + brx1 /= 5; + bry1 /= 5; + + locate(pos_x, pos_y); + printf("OK "); + printf(" "); do { - p = get_touch(); - } while (p.x==0 && p.y==0); - ulx1 += p.x; - uly1 += p.y; - } - ulx1 /= 5; - uly1 /= 5; - locate(pos_x,pos_y); - printf("OK "); - printf(" "); - do { - wait(0.1); - } while (is_touched()); //Wait for no touch - - cls(); - line(width() -1, height() - 4,width() - 7,height() -4,White); // paint cross - line(width() - 4,height() - 1,width() - 4,height() - 7,White); - locate(pos_x,pos_y); - printf("press cross"); - locate(pos_x,pos_y + font[2]); - printf("to calibrate"); - do { - wait(0.1); - } while (!is_touched()); //Wait for touch - for (i=0; i<5; i++) { + wait(0.1); + } while (is_touched()); //Wait for no touch + + cls(); + seldisp=0; // select left display + cls(); + line(0,3,6,3,White); + line(3,0,3,6,White); + + // now calibrate left screen + locate(pos_x,pos_y); + printf("press cross"); + locate(pos_x,pos_y + font[2]); + printf("to calibrate"); + do { + wait(0.1); + } while (!is_touched()); //Wait for touch + for (i=0; i<5; i++) { + do { + p = get_touch(); + } while (p.x==0 && p.y==0); + ulx0 += p.x; + uly0 += p.y; + } + ulx0 /= 5; + uly0 /= 5; + locate(pos_x,pos_y); + printf("OK "); + printf(" "); do { - p = get_touch(); - } while (p.x==0 && p.y==0); p = get_touch(); - brx1 += p.x; - bry1 += p.y; + wait(0.1); + } while (is_touched()); //Wait for no touch + + cls(); + line(width() -1, height() - 4,width() - 7,height() -4,White); // paint cross + line(width() - 4,height() - 1,width() - 4,height() - 7,White); + locate(pos_x,pos_y); + printf("press cross"); + locate(pos_x,pos_y + font[2]); + printf("to calibrate"); + do { + wait(0.1); + } while (!is_touched()); //Wait for touch + for (i=0; i<5; i++) { + do { + p = get_touch(); + } while (p.x==0 && p.y==0); + brx0 += p.x; + bry0 += p.y; + } + brx0 /= 5; + bry0 /= 5; + + locate(pos_x, pos_y); + printf("OK "); + printf(" "); + do { + wait(0.1); + } while (is_touched()); //Wait for no touch + + cls(); + + x0_off = ulx0; + y0_off = uly0; + x0_pp = (brx0-ulx0) / (width() - 6); + y0_pp = (bry0-uly0) / (height() - 6); + + + x1_off = ulx1; + y1_off = uly1; + x1_pp = (brx1-ulx1) / (width() - 6); + y1_pp = (bry1-uly1) / (height() - 6); + x_mid = (brx0 + ulx1) / 2; + //debug + printf("x0_off:%d y0_off:%d x0_pp:%d y0_pp:%d\n",x0_off,y0_off,x0_pp,y0_pp); + printf("x1_off:%d y1_off:%d x1_pp:%d y1_pp:%d\n",x1_off,y1_off,x1_pp,y1_pp); + printf("x_mid:%d\n",x_mid); } - brx1 /= 5; - bry1 /= 5; - - locate(pos_x, pos_y); - printf("OK "); - printf(" "); - do { - wait(0.1); - } while (is_touched()); //Wait for no touch - - cls(); - seldisp=0; // select left display - cls(); - line(0,3,6,3,White); - line(3,0,3,6,White); - - // now calibrate left screen - locate(pos_x,pos_y); - printf("press cross"); - locate(pos_x,pos_y + font[2]); - printf("to calibrate"); - do { - wait(0.1); - } while (!is_touched()); //Wait for touch - for (i=0; i<5; i++) { - do { - p = get_touch(); - } while (p.x==0 && p.y==0); - ulx0 += p.x; - uly0 += p.y; - } - ulx0 /= 5; - uly0 /= 5; - locate(pos_x,pos_y); - printf("OK "); - printf(" "); - do { - wait(0.1); - } while (is_touched()); //Wait for no touch - - cls(); - line(width() -1, height() - 4,width() - 7,height() -4,White); // paint cross - line(width() - 4,height() - 1,width() - 4,height() - 7,White); - locate(pos_x,pos_y); - printf("press cross"); - locate(pos_x,pos_y + font[2]); - printf("to calibrate"); - do { - wait(0.1); - } while (!is_touched()); //Wait for touch - for (i=0; i<5; i++) { - do { - p = get_touch(); - } while (p.x==0 && p.y==0); - brx0 += p.x; - bry0 += p.y; - } - brx0 /= 5; - bry0 /= 5; - - locate(pos_x, pos_y); - printf("OK "); - printf(" "); - do { - wait(0.1); - } while (is_touched()); //Wait for no touch - - cls(); - - x0_off = ulx0; - y0_off = uly0; - x0_pp = (brx0-ulx0) / (width() - 6); - y0_pp = (bry0-uly0) / (height() - 6); - - - x1_off = ulx1; - y1_off = uly1; - x1_pp = (brx1-ulx1) / (width() - 6); - y1_pp = (bry1-uly1) / (height() - 6); - x_mid = (brx0 + ulx1) / 2; - } @@ -292,16 +307,27 @@ bool TOUCH_TFTx2::is_touched(void) { unsigned short y1; // read y voltage - _ym.input(); //y- has to be passive - _yp.input(); //y+ has to be passive - _ym.mode(PullUp); - _yp.mode(PullUp); - _xp.output(); - _xm.output(); - _xp = 0; //drive x+ low - _xm = 0; //drive x- low - AnalogIn Ay(ya); // we have to call the constructor to switch to analog mode + _xm.input(); //x- has to be passive + _xp.input(); //x+ has to be passive + _xm.mode(PullDown); + _xp.mode(PullDown); + _yp.output(); + _ym.output(); + _yp = 1; //drive y+ high + _ym = 1; //drive y- high + AnalogIn Ay(xa); // we have to call the constructor to switch to analog mode wait_us(10); y1 = Ay.read_u16(); // get y voltage - return (y1<threshold); + return (y1>threshold); } + +void TOUCH_TFTx2::wfi(void) { + _xm.input(); //x- has to be passive + _xp.input(); //x+ has to be passive + _xm.mode(PullDown); + _xp.mode(PullDown); + _yp.output(); + _ym.output(); + _yp = 1; //drive y+ high + _ym = 1; //drive y- high +}
--- a/TOUCH_TFTx2.h Thu Feb 14 00:26:54 2013 +0000 +++ b/TOUCH_TFTx2.h Sun Feb 17 16:44:06 2013 +0000 @@ -23,41 +23,6 @@ }; -/** touchscreen control class, based on SPI_TFT - * - * Example: - * @code - * - * #include "mbed.h" - * #include "SPI_TFTx2.h" - * #include "Arial12x12.h" - * #include "Arial28x28.h" - * #include "TOUCH_TFTx2.h" - * // the TFT is connected to SPI pin 5-7 - * // the touch is connected to 19,20,16,17 - * - * TOUCH_TFTx2 tt(p19,p20,p16,p17,p5, p6, p7, p8, p9, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset - * - * int main() { - * point p; - * - * tt.claim(stdout); // send stdout to the TFT display - * tt.background(Black); // set background to black - * tt.foreground(White); // set chars to white - * tt.cls(); // clear the screen - * tt.set_font((unsigned char*) Arial12x12); // select the font - * tt.set_orientation(1); - * - * tt.calibrate(); // calibrate the touch - * while (1) { - * p = tt.get_touch(); // read analog pos. - * if (tt.is_touched(p)) { // test if touched - * p = tt.to_pixel(p); // convert to pixel pos - * tt.fillcircle(p.x,p.y,3,Blue); // print a blue dot on the screen - * } - * } - * @endcode - */ class TOUCH_TFTx2 : public SPI_TFTx2{ public: /** create a TFT with touch object connected to the pins: @@ -100,6 +65,8 @@ * */ bool is_touched(void); + + void wfi(void); protected: DigitalInOut _xp;