LIB for resistiv touchscreen connected to 4 mbed pins Use SPI_TFT lib
Fork of Touch_tft by
touch_tft.h@0:d78b00f167cb, 2011-07-14 (annotated)
- Committer:
- dreschpe
- Date:
- Thu Jul 14 21:02:43 2011 +0000
- Revision:
- 0:d78b00f167cb
- Child:
- 1:1745fdf054b5
0.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:d78b00f167cb | 1 | #ifndef MBED_TOUCH_H |
dreschpe | 0:d78b00f167cb | 2 | #define MBED_TOUCH_H |
dreschpe | 0:d78b00f167cb | 3 | |
dreschpe | 0:d78b00f167cb | 4 | #include "mbed.h" |
dreschpe | 0:d78b00f167cb | 5 | #include "SPI_TFT.h" |
dreschpe | 0:d78b00f167cb | 6 | |
dreschpe | 0:d78b00f167cb | 7 | struct point{ |
dreschpe | 0:d78b00f167cb | 8 | unsigned short x; |
dreschpe | 0:d78b00f167cb | 9 | unsigned short y; |
dreschpe | 0:d78b00f167cb | 10 | }; |
dreschpe | 0:d78b00f167cb | 11 | |
dreschpe | 0:d78b00f167cb | 12 | class touch_tft : public SPI_TFT{ |
dreschpe | 0:d78b00f167cb | 13 | public: |
dreschpe | 0:d78b00f167cb | 14 | /** create a TFT with touch object connected to the pins |
dreschpe | 0:d78b00f167cb | 15 | * |
dreschpe | 0:d78b00f167cb | 16 | * @param pin xp resistiv touch x+ |
dreschpe | 0:d78b00f167cb | 17 | * @param pin xm resistiv touch x- |
dreschpe | 0:d78b00f167cb | 18 | * @param pin yp resistiv touch y+ |
dreschpe | 0:d78b00f167cb | 19 | * @param pin ym resistiv touch y- |
dreschpe | 0:d78b00f167cb | 20 | * @param mosi,miso,sclk SPI connection to TFT |
dreschpe | 0:d78b00f167cb | 21 | * @param cs pin connected to CS of display |
dreschpe | 0:d78b00f167cb | 22 | * @param reset pin connected to RESET of display |
dreschpe | 0:d78b00f167cb | 23 | * based on my SPI_TFT lib |
dreschpe | 0:d78b00f167cb | 24 | */ |
dreschpe | 0:d78b00f167cb | 25 | touch_tft(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); |
dreschpe | 0:d78b00f167cb | 26 | |
dreschpe | 0:d78b00f167cb | 27 | /** calibrate the touch display |
dreschpe | 0:d78b00f167cb | 28 | * |
dreschpe | 0:d78b00f167cb | 29 | */ |
dreschpe | 0:d78b00f167cb | 30 | void calibrate(void); |
dreschpe | 0:d78b00f167cb | 31 | |
dreschpe | 0:d78b00f167cb | 32 | /** read x and y analog samples |
dreschpe | 0:d78b00f167cb | 33 | * |
dreschpe | 0:d78b00f167cb | 34 | * @returns point(x,y) |
dreschpe | 0:d78b00f167cb | 35 | */ |
dreschpe | 0:d78b00f167cb | 36 | point get_touch(void); |
dreschpe | 0:d78b00f167cb | 37 | |
dreschpe | 0:d78b00f167cb | 38 | /** calculate coord on screen |
dreschpe | 0:d78b00f167cb | 39 | * |
dreschpe | 0:d78b00f167cb | 40 | * @param a_point point(analog x, analog y) |
dreschpe | 0:d78b00f167cb | 41 | * @returns point(pixel x, pixel y) |
dreschpe | 0:d78b00f167cb | 42 | * |
dreschpe | 0:d78b00f167cb | 43 | */ |
dreschpe | 0:d78b00f167cb | 44 | point to_pixel(point a_point); |
dreschpe | 0:d78b00f167cb | 45 | |
dreschpe | 0:d78b00f167cb | 46 | /** test if screen is touched |
dreschpe | 0:d78b00f167cb | 47 | * |
dreschpe | 0:d78b00f167cb | 48 | * @param point analog x,y |
dreschpe | 0:d78b00f167cb | 49 | * @returns true is touched |
dreschpe | 0:d78b00f167cb | 50 | * |
dreschpe | 0:d78b00f167cb | 51 | */ |
dreschpe | 0:d78b00f167cb | 52 | bool is_touched(point a); |
dreschpe | 0:d78b00f167cb | 53 | |
dreschpe | 0:d78b00f167cb | 54 | protected: |
dreschpe | 0:d78b00f167cb | 55 | DigitalInOut _xp; |
dreschpe | 0:d78b00f167cb | 56 | DigitalInOut _xm; |
dreschpe | 0:d78b00f167cb | 57 | DigitalInOut _yp; |
dreschpe | 0:d78b00f167cb | 58 | DigitalInOut _ym; |
dreschpe | 0:d78b00f167cb | 59 | AnalogIn _ax; |
dreschpe | 0:d78b00f167cb | 60 | AnalogIn _ay; |
dreschpe | 0:d78b00f167cb | 61 | PinName xa; |
dreschpe | 0:d78b00f167cb | 62 | PinName ya; |
dreschpe | 0:d78b00f167cb | 63 | |
dreschpe | 0:d78b00f167cb | 64 | |
dreschpe | 0:d78b00f167cb | 65 | unsigned short x_a,y_a; |
dreschpe | 0:d78b00f167cb | 66 | unsigned short x_off,y_off; |
dreschpe | 0:d78b00f167cb | 67 | unsigned short pp_tx,pp_ty; |
dreschpe | 0:d78b00f167cb | 68 | |
dreschpe | 0:d78b00f167cb | 69 | |
dreschpe | 0:d78b00f167cb | 70 | |
dreschpe | 0:d78b00f167cb | 71 | }; |
dreschpe | 0:d78b00f167cb | 72 | |
dreschpe | 0:d78b00f167cb | 73 | #endif |