Modified to work with two displays

Dependents:   touch2 default CANary_9341_test CANary_merge

Fork of Touch_tft by Peter Drescher

Committer:
TickTock
Date:
Sun May 18 12:45:30 2014 +0000
Revision:
16:bee053b17977
Parent:
15:f2165aa0daa6
Works with both controllers using precompiler directive

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 1:1745fdf054b5 1 /* mbed library for touchscreen connected to 4 mbed pins
TickTock 16:bee053b17977 2 * derive from SPI_TFT lib
dreschpe 1:1745fdf054b5 3 * Copyright (c) 2011 Peter Drescher - DC2PD
TickTock 16:bee053b17977 4 * Updated by YoongHM to use SPI_TFTx2 or SPI_TFTx2_ILI9341
dreschpe 1:1745fdf054b5 5 *
dreschpe 1:1745fdf054b5 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 1:1745fdf054b5 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 1:1745fdf054b5 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 1:1745fdf054b5 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 1:1745fdf054b5 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 1:1745fdf054b5 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 1:1745fdf054b5 12 * THE SOFTWARE.
dreschpe 1:1745fdf054b5 13 */
dreschpe 1:1745fdf054b5 14
TickTock 16:bee053b17977 15 #ifndef MBED_TOUCH_TFTx2_H
TickTock 16:bee053b17977 16 #define MBED_TOUCH_TFTx2_H
TickTock 16:bee053b17977 17
TickTock 16:bee053b17977 18 // Include this before other header files
TickTock 16:bee053b17977 19 #include "precompile.h"
dreschpe 0:d78b00f167cb 20
dreschpe 0:d78b00f167cb 21 #include "mbed.h"
TickTock 16:bee053b17977 22
TickTock 16:bee053b17977 23 #if USE_ILI9341 == 1
TickTock 15:f2165aa0daa6 24 #include "SPI_TFTx2_ILI9341.h"
TickTock 16:bee053b17977 25 #else
TickTock 16:bee053b17977 26 #include "SPI_TFTx2.h"
TickTock 16:bee053b17977 27 #endif
dreschpe 0:d78b00f167cb 28
dreschpe 0:d78b00f167cb 29 struct point{
dreschpe 0:d78b00f167cb 30 unsigned short x;
dreschpe 0:d78b00f167cb 31 unsigned short y;
dreschpe 0:d78b00f167cb 32 };
dreschpe 0:d78b00f167cb 33
dreschpe 1:1745fdf054b5 34
TickTock 16:bee053b17977 35 #if USE_ILI9341 == 1
TickTock 16:bee053b17977 36 class TOUCH_TFTx2 : public SPI_TFTx2_ILI9341 {
TickTock 16:bee053b17977 37 #else
TickTock 16:bee053b17977 38 class TOUCH_TFTx2 : public SPI_TFTx2 {
TickTock 16:bee053b17977 39 #endif
dreschpe 0:d78b00f167cb 40 public:
TickTock 16:bee053b17977 41
TickTock 16:bee053b17977 42 #if USE_ILI9341 == 1
dreschpe 1:1745fdf054b5 43 /** create a TFT with touch object connected to the pins:
dreschpe 0:d78b00f167cb 44 *
dreschpe 0:d78b00f167cb 45 * @param pin xp resistiv touch x+
dreschpe 0:d78b00f167cb 46 * @param pin xm resistiv touch x-
dreschpe 0:d78b00f167cb 47 * @param pin yp resistiv touch y+
dreschpe 0:d78b00f167cb 48 * @param pin ym resistiv touch y-
dreschpe 0:d78b00f167cb 49 * @param mosi,miso,sclk SPI connection to TFT
dreschpe 0:d78b00f167cb 50 * @param cs pin connected to CS of display
TickTock 16:bee053b17977 51 * @param reset pin connected to RESET of display
TickTock 15:f2165aa0daa6 52 * @param dc pin connected to WR of display
dreschpe 0:d78b00f167cb 53 * based on my SPI_TFT lib
dreschpe 0:d78b00f167cb 54 */
TickTock 16:bee053b17977 55 TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi,
TickTock 16:bee053b17977 56 PinName miso, PinName sclk, PinName cs0, PinName cs1,
TickTock 16:bee053b17977 57 PinName reset, PinName dc, const char* name ="TFT");
TickTock 16:bee053b17977 58 #else
TickTock 16:bee053b17977 59 /** create a TFT with touch object connected to the pins:
TickTock 16:bee053b17977 60 *
TickTock 16:bee053b17977 61 * @param pin xp resistiv touch x+
TickTock 16:bee053b17977 62 * @param pin xm resistiv touch x-
TickTock 16:bee053b17977 63 * @param pin yp resistiv touch y+
TickTock 16:bee053b17977 64 * @param pin ym resistiv touch y-
TickTock 16:bee053b17977 65 * @param mosi,miso,sclk SPI connection to TFT
TickTock 16:bee053b17977 66 * @param cs pin connected to CS of display
TickTock 16:bee053b17977 67 * @param reset pin connected to RESET of display
TickTock 16:bee053b17977 68 * based on my SPI_TFT lib
TickTock 16:bee053b17977 69 */
TickTock 16:bee053b17977 70 TOUCH_TFTx2(PinName xp, PinName xm, PinName yp, PinName ym,PinName mosi,
TickTock 16:bee053b17977 71 PinName miso, PinName sclk, PinName cs0, PinName cs1,
TickTock 16:bee053b17977 72 PinName reset, const char* name ="TFT");
TickTock 16:bee053b17977 73 #endif
TickTock 12:b7fb9d3ae5ea 74
TickTock 12:b7fb9d3ae5ea 75 unsigned short x0_off,y0_off;
TickTock 12:b7fb9d3ae5ea 76 unsigned short x0_pp,y0_pp;
TickTock 12:b7fb9d3ae5ea 77 unsigned short x1_off,y1_off;
TickTock 12:b7fb9d3ae5ea 78 unsigned short x1_pp,y1_pp;
TickTock 12:b7fb9d3ae5ea 79 unsigned short x_mid;
TickTock 16:bee053b17977 80
dreschpe 0:d78b00f167cb 81 /** calibrate the touch display
dreschpe 0:d78b00f167cb 82 *
dreschpe 1:1745fdf054b5 83 * User is asked to touch on two points on the screen
TickTock 16:bee053b17977 84 */
dreschpe 0:d78b00f167cb 85 void calibrate(void);
TickTock 16:bee053b17977 86
dreschpe 0:d78b00f167cb 87 /** read x and y analog samples
dreschpe 0:d78b00f167cb 88 *
dreschpe 0:d78b00f167cb 89 * @returns point(x,y)
dreschpe 0:d78b00f167cb 90 */
TickTock 10:fd7ae99850a9 91
TickTock 10:fd7ae99850a9 92 void setcal(int _x0off, int _y0off, int _x0pp, int _y0pp, int _x1off, int _y1off, int _x1pp, int _y1pp, int _xmin);
TickTock 10:fd7ae99850a9 93 /** set calibration values directly (bypass calibration)
TickTock 10:fd7ae99850a9 94 *
TickTock 10:fd7ae99850a9 95 */
TickTock 10:fd7ae99850a9 96
dreschpe 0:d78b00f167cb 97 point get_touch(void);
TickTock 16:bee053b17977 98
dreschpe 0:d78b00f167cb 99 /** calculate coord on screen
dreschpe 0:d78b00f167cb 100 *
dreschpe 0:d78b00f167cb 101 * @param a_point point(analog x, analog y)
dreschpe 0:d78b00f167cb 102 * @returns point(pixel x, pixel y)
dreschpe 0:d78b00f167cb 103 *
dreschpe 0:d78b00f167cb 104 */
dreschpe 0:d78b00f167cb 105 point to_pixel(point a_point);
TickTock 16:bee053b17977 106
dreschpe 0:d78b00f167cb 107 /** test if screen is touched
TickTock 16:bee053b17977 108 *
dreschpe 0:d78b00f167cb 109 * @param point analog x,y
dreschpe 0:d78b00f167cb 110 * @returns true is touched
dreschpe 0:d78b00f167cb 111 *
TickTock 16:bee053b17977 112 */
TickTock 16:bee053b17977 113 bool is_touched(void);
TickTock 6:a91b668b058a 114
TickTock 16:bee053b17977 115 void wfi(void);
TickTock 16:bee053b17977 116
dreschpe 0:d78b00f167cb 117 protected:
dreschpe 0:d78b00f167cb 118 DigitalInOut _xp;
dreschpe 0:d78b00f167cb 119 DigitalInOut _xm;
dreschpe 0:d78b00f167cb 120 DigitalInOut _yp;
dreschpe 0:d78b00f167cb 121 DigitalInOut _ym;
dreschpe 0:d78b00f167cb 122 AnalogIn _ax;
dreschpe 0:d78b00f167cb 123 AnalogIn _ay;
dreschpe 0:d78b00f167cb 124 PinName xa;
dreschpe 0:d78b00f167cb 125 PinName ya;
TickTock 5:a9890c586a64 126
dreschpe 0:d78b00f167cb 127 unsigned short x_a,y_a;
dreschpe 0:d78b00f167cb 128 };
dreschpe 0:d78b00f167cb 129
TickTock 16:bee053b17977 130 #endif /* MBED_TOUCH_TFTx2_H */