Fork with support for ILI9341 controller
Dependents: CANary_9341 CANary
Fork of TOUCH_TFTx2 by
TOUCH_TFTx2.h@15:f2165aa0daa6, 2014-05-12 (annotated)
- Committer:
- TickTock
- Date:
- Mon May 12 03:19:02 2014 +0000
- Revision:
- 15:f2165aa0daa6
- Parent:
- 12:b7fb9d3ae5ea
- Child:
- 16:bee053b17977
works with new display controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 1:1745fdf054b5 | 1 | /* mbed library for touchscreen connected to 4 mbed pins |
dreschpe | 1:1745fdf054b5 | 2 | * derive from SPI_TFT lib |
dreschpe | 1:1745fdf054b5 | 3 | * Copyright (c) 2011 Peter Drescher - DC2PD |
dreschpe | 1:1745fdf054b5 | 4 | * |
dreschpe | 1:1745fdf054b5 | 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dreschpe | 1:1745fdf054b5 | 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dreschpe | 1:1745fdf054b5 | 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dreschpe | 1:1745fdf054b5 | 8 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dreschpe | 1:1745fdf054b5 | 9 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dreschpe | 1:1745fdf054b5 | 10 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dreschpe | 1:1745fdf054b5 | 11 | * THE SOFTWARE. |
dreschpe | 1:1745fdf054b5 | 12 | */ |
dreschpe | 1:1745fdf054b5 | 13 | |
dreschpe | 0:d78b00f167cb | 14 | #ifndef MBED_TOUCH_H |
dreschpe | 0:d78b00f167cb | 15 | #define MBED_TOUCH_H |
dreschpe | 0:d78b00f167cb | 16 | |
dreschpe | 0:d78b00f167cb | 17 | #include "mbed.h" |
TickTock | 15:f2165aa0daa6 | 18 | #include "SPI_TFTx2_ILI9341.h" |
dreschpe | 0:d78b00f167cb | 19 | |
dreschpe | 0:d78b00f167cb | 20 | struct point{ |
dreschpe | 0:d78b00f167cb | 21 | unsigned short x; |
dreschpe | 0:d78b00f167cb | 22 | unsigned short y; |
dreschpe | 0:d78b00f167cb | 23 | }; |
dreschpe | 0:d78b00f167cb | 24 | |
dreschpe | 1:1745fdf054b5 | 25 | |
TickTock | 3:3db7309b6146 | 26 | class TOUCH_TFTx2 : public SPI_TFTx2{ |
dreschpe | 0:d78b00f167cb | 27 | public: |
dreschpe | 1:1745fdf054b5 | 28 | /** create a TFT with touch object connected to the pins: |
dreschpe | 0:d78b00f167cb | 29 | * |
dreschpe | 0:d78b00f167cb | 30 | * @param pin xp resistiv touch x+ |
dreschpe | 0:d78b00f167cb | 31 | * @param pin xm resistiv touch x- |
dreschpe | 0:d78b00f167cb | 32 | * @param pin yp resistiv touch y+ |
dreschpe | 0:d78b00f167cb | 33 | * @param pin ym resistiv touch y- |
dreschpe | 0:d78b00f167cb | 34 | * @param mosi,miso,sclk SPI connection to TFT |
dreschpe | 0:d78b00f167cb | 35 | * @param cs pin connected to CS of display |
dreschpe | 0:d78b00f167cb | 36 | * @param reset pin connected to RESET of display |
TickTock | 15:f2165aa0daa6 | 37 | * @param dc pin connected to WR of display |
dreschpe | 0:d78b00f167cb | 38 | * based on my SPI_TFT lib |
dreschpe | 0:d78b00f167cb | 39 | */ |
TickTock | 15:f2165aa0daa6 | 40 | 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"); |
TickTock | 12:b7fb9d3ae5ea | 41 | |
TickTock | 12:b7fb9d3ae5ea | 42 | unsigned short x0_off,y0_off; |
TickTock | 12:b7fb9d3ae5ea | 43 | unsigned short x0_pp,y0_pp; |
TickTock | 12:b7fb9d3ae5ea | 44 | unsigned short x1_off,y1_off; |
TickTock | 12:b7fb9d3ae5ea | 45 | unsigned short x1_pp,y1_pp; |
TickTock | 12:b7fb9d3ae5ea | 46 | unsigned short x_mid; |
dreschpe | 0:d78b00f167cb | 47 | |
dreschpe | 0:d78b00f167cb | 48 | /** calibrate the touch display |
dreschpe | 0:d78b00f167cb | 49 | * |
dreschpe | 1:1745fdf054b5 | 50 | * User is asked to touch on two points on the screen |
dreschpe | 0:d78b00f167cb | 51 | */ |
dreschpe | 0:d78b00f167cb | 52 | void calibrate(void); |
dreschpe | 0:d78b00f167cb | 53 | |
dreschpe | 0:d78b00f167cb | 54 | /** read x and y analog samples |
dreschpe | 0:d78b00f167cb | 55 | * |
dreschpe | 0:d78b00f167cb | 56 | * @returns point(x,y) |
dreschpe | 0:d78b00f167cb | 57 | */ |
TickTock | 10:fd7ae99850a9 | 58 | |
TickTock | 10:fd7ae99850a9 | 59 | void setcal(int _x0off, int _y0off, int _x0pp, int _y0pp, int _x1off, int _y1off, int _x1pp, int _y1pp, int _xmin); |
TickTock | 10:fd7ae99850a9 | 60 | /** set calibration values directly (bypass calibration) |
TickTock | 10:fd7ae99850a9 | 61 | * |
TickTock | 10:fd7ae99850a9 | 62 | */ |
TickTock | 10:fd7ae99850a9 | 63 | |
dreschpe | 0:d78b00f167cb | 64 | point get_touch(void); |
dreschpe | 0:d78b00f167cb | 65 | |
dreschpe | 0:d78b00f167cb | 66 | /** calculate coord on screen |
dreschpe | 0:d78b00f167cb | 67 | * |
dreschpe | 0:d78b00f167cb | 68 | * @param a_point point(analog x, analog y) |
dreschpe | 0:d78b00f167cb | 69 | * @returns point(pixel x, pixel y) |
dreschpe | 0:d78b00f167cb | 70 | * |
dreschpe | 0:d78b00f167cb | 71 | */ |
dreschpe | 0:d78b00f167cb | 72 | point to_pixel(point a_point); |
dreschpe | 0:d78b00f167cb | 73 | |
dreschpe | 0:d78b00f167cb | 74 | /** test if screen is touched |
dreschpe | 0:d78b00f167cb | 75 | * |
dreschpe | 0:d78b00f167cb | 76 | * @param point analog x,y |
dreschpe | 0:d78b00f167cb | 77 | * @returns true is touched |
dreschpe | 0:d78b00f167cb | 78 | * |
dreschpe | 0:d78b00f167cb | 79 | */ |
TickTock | 4:a3cd26c97b76 | 80 | bool is_touched(void); |
TickTock | 6:a91b668b058a | 81 | |
TickTock | 6:a91b668b058a | 82 | void wfi(void); |
dreschpe | 0:d78b00f167cb | 83 | |
dreschpe | 0:d78b00f167cb | 84 | protected: |
dreschpe | 0:d78b00f167cb | 85 | DigitalInOut _xp; |
dreschpe | 0:d78b00f167cb | 86 | DigitalInOut _xm; |
dreschpe | 0:d78b00f167cb | 87 | DigitalInOut _yp; |
dreschpe | 0:d78b00f167cb | 88 | DigitalInOut _ym; |
dreschpe | 0:d78b00f167cb | 89 | AnalogIn _ax; |
dreschpe | 0:d78b00f167cb | 90 | AnalogIn _ay; |
dreschpe | 0:d78b00f167cb | 91 | PinName xa; |
dreschpe | 0:d78b00f167cb | 92 | PinName ya; |
TickTock | 5:a9890c586a64 | 93 | |
dreschpe | 0:d78b00f167cb | 94 | unsigned short x_a,y_a; |
dreschpe | 0:d78b00f167cb | 95 | }; |
dreschpe | 0:d78b00f167cb | 96 | |
dreschpe | 0:d78b00f167cb | 97 | #endif |