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 Feb 17 16:44:06 2013 +0000
Revision:
6:a91b668b058a
Parent:
5:a9890c586a64
Child:
10:fd7ae99850a9
Added colors and interrupt driven touch support;

Who changed what in which revision?

UserRevisionLine numberNew 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 */
dreschpe 0:d78b00f167cb 51 point get_touch(void);
dreschpe 0:d78b00f167cb 52
dreschpe 0:d78b00f167cb 53 /** calculate coord on screen
dreschpe 0:d78b00f167cb 54 *
dreschpe 0:d78b00f167cb 55 * @param a_point point(analog x, analog y)
dreschpe 0:d78b00f167cb 56 * @returns point(pixel x, pixel y)
dreschpe 0:d78b00f167cb 57 *
dreschpe 0:d78b00f167cb 58 */
dreschpe 0:d78b00f167cb 59 point to_pixel(point a_point);
dreschpe 0:d78b00f167cb 60
dreschpe 0:d78b00f167cb 61 /** test if screen is touched
dreschpe 0:d78b00f167cb 62 *
dreschpe 0:d78b00f167cb 63 * @param point analog x,y
dreschpe 0:d78b00f167cb 64 * @returns true is touched
dreschpe 0:d78b00f167cb 65 *
dreschpe 0:d78b00f167cb 66 */
TickTock 4:a3cd26c97b76 67 bool is_touched(void);
TickTock 6:a91b668b058a 68
TickTock 6:a91b668b058a 69 void wfi(void);
dreschpe 0:d78b00f167cb 70
dreschpe 0:d78b00f167cb 71 protected:
dreschpe 0:d78b00f167cb 72 DigitalInOut _xp;
dreschpe 0:d78b00f167cb 73 DigitalInOut _xm;
dreschpe 0:d78b00f167cb 74 DigitalInOut _yp;
dreschpe 0:d78b00f167cb 75 DigitalInOut _ym;
dreschpe 0:d78b00f167cb 76 AnalogIn _ax;
dreschpe 0:d78b00f167cb 77 AnalogIn _ay;
dreschpe 0:d78b00f167cb 78 PinName xa;
dreschpe 0:d78b00f167cb 79 PinName ya;
TickTock 5:a9890c586a64 80
dreschpe 0:d78b00f167cb 81 unsigned short x_a,y_a;
TickTock 5:a9890c586a64 82 unsigned short x0_off,y0_off;
TickTock 5:a9890c586a64 83 unsigned short x0_pp,y0_pp;
TickTock 5:a9890c586a64 84 unsigned short x1_off,y1_off;
TickTock 5:a9890c586a64 85 unsigned short x1_pp,y1_pp;
TickTock 5:a9890c586a64 86 unsigned short x_mid;
dreschpe 0:d78b00f167cb 87 };
dreschpe 0:d78b00f167cb 88
dreschpe 0:d78b00f167cb 89 #endif