Fork with support for ILI9341 controller
Dependents: CANary_9341 CANary
Fork of TOUCH_TFTx2 by
TOUCH_TFTx2.h@10:fd7ae99850a9, 2013-03-03 (annotated)
- Committer:
- TickTock
- Date:
- Sun Mar 03 15:49:34 2013 +0000
- Revision:
- 10:fd7ae99850a9
- Parent:
- 6:a91b668b058a
- Child:
- 12:b7fb9d3ae5ea
added setcal function to bypass calibration
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 | 3:3db7309b6146 | 18 | #include "SPI_TFTx2.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 |
dreschpe | 0:d78b00f167cb | 37 | * based on my SPI_TFT lib |
dreschpe | 0:d78b00f167cb | 38 | */ |
TickTock | 3:3db7309b6146 | 39 | 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"); |
dreschpe | 0:d78b00f167cb | 40 | |
dreschpe | 0:d78b00f167cb | 41 | /** calibrate the touch display |
dreschpe | 0:d78b00f167cb | 42 | * |
dreschpe | 1:1745fdf054b5 | 43 | * User is asked to touch on two points on the screen |
dreschpe | 0:d78b00f167cb | 44 | */ |
dreschpe | 0:d78b00f167cb | 45 | void calibrate(void); |
dreschpe | 0:d78b00f167cb | 46 | |
dreschpe | 0:d78b00f167cb | 47 | /** read x and y analog samples |
dreschpe | 0:d78b00f167cb | 48 | * |
dreschpe | 0:d78b00f167cb | 49 | * @returns point(x,y) |
dreschpe | 0:d78b00f167cb | 50 | */ |
TickTock | 10:fd7ae99850a9 | 51 | |
TickTock | 10:fd7ae99850a9 | 52 | void setcal(int _x0off, int _y0off, int _x0pp, int _y0pp, int _x1off, int _y1off, int _x1pp, int _y1pp, int _xmin); |
TickTock | 10:fd7ae99850a9 | 53 | /** set calibration values directly (bypass calibration) |
TickTock | 10:fd7ae99850a9 | 54 | * |
TickTock | 10:fd7ae99850a9 | 55 | */ |
TickTock | 10:fd7ae99850a9 | 56 | |
dreschpe | 0:d78b00f167cb | 57 | point get_touch(void); |
dreschpe | 0:d78b00f167cb | 58 | |
dreschpe | 0:d78b00f167cb | 59 | /** calculate coord on screen |
dreschpe | 0:d78b00f167cb | 60 | * |
dreschpe | 0:d78b00f167cb | 61 | * @param a_point point(analog x, analog y) |
dreschpe | 0:d78b00f167cb | 62 | * @returns point(pixel x, pixel y) |
dreschpe | 0:d78b00f167cb | 63 | * |
dreschpe | 0:d78b00f167cb | 64 | */ |
dreschpe | 0:d78b00f167cb | 65 | point to_pixel(point a_point); |
dreschpe | 0:d78b00f167cb | 66 | |
dreschpe | 0:d78b00f167cb | 67 | /** test if screen is touched |
dreschpe | 0:d78b00f167cb | 68 | * |
dreschpe | 0:d78b00f167cb | 69 | * @param point analog x,y |
dreschpe | 0:d78b00f167cb | 70 | * @returns true is touched |
dreschpe | 0:d78b00f167cb | 71 | * |
dreschpe | 0:d78b00f167cb | 72 | */ |
TickTock | 4:a3cd26c97b76 | 73 | bool is_touched(void); |
TickTock | 6:a91b668b058a | 74 | |
TickTock | 6:a91b668b058a | 75 | void wfi(void); |
dreschpe | 0:d78b00f167cb | 76 | |
dreschpe | 0:d78b00f167cb | 77 | protected: |
dreschpe | 0:d78b00f167cb | 78 | DigitalInOut _xp; |
dreschpe | 0:d78b00f167cb | 79 | DigitalInOut _xm; |
dreschpe | 0:d78b00f167cb | 80 | DigitalInOut _yp; |
dreschpe | 0:d78b00f167cb | 81 | DigitalInOut _ym; |
dreschpe | 0:d78b00f167cb | 82 | AnalogIn _ax; |
dreschpe | 0:d78b00f167cb | 83 | AnalogIn _ay; |
dreschpe | 0:d78b00f167cb | 84 | PinName xa; |
dreschpe | 0:d78b00f167cb | 85 | PinName ya; |
TickTock | 5:a9890c586a64 | 86 | |
dreschpe | 0:d78b00f167cb | 87 | unsigned short x_a,y_a; |
TickTock | 5:a9890c586a64 | 88 | unsigned short x0_off,y0_off; |
TickTock | 5:a9890c586a64 | 89 | unsigned short x0_pp,y0_pp; |
TickTock | 5:a9890c586a64 | 90 | unsigned short x1_off,y1_off; |
TickTock | 5:a9890c586a64 | 91 | unsigned short x1_pp,y1_pp; |
TickTock | 5:a9890c586a64 | 92 | unsigned short x_mid; |
dreschpe | 0:d78b00f167cb | 93 | }; |
dreschpe | 0:d78b00f167cb | 94 | |
dreschpe | 0:d78b00f167cb | 95 | #endif |