STS2 Adafruit TFT ok

Dependencies:   SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TS_Eyes by Motoo Tanaka

Committer:
Rhyme
Date:
Sat Dec 06 05:35:02 2014 +0000
Revision:
0:0b7a110bfceb
Child:
1:7cc0446656ae
First commit for publish;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:0b7a110bfceb 1 /** TS_Eye TSI sample program using Adafruit 2.8" TFT with Touch
Rhyme 0:0b7a110bfceb 2 *
Rhyme 0:0b7a110bfceb 3 * @note Just like the good old X11 eyes
Rhyme 0:0b7a110bfceb 4 * @note this program stares at the point where
Rhyme 0:0b7a110bfceb 5 * @note the TSI sensor of FRDM is being touched.
Rhyme 0:0b7a110bfceb 6 * @note By touching the right most side of the sensor
Rhyme 0:0b7a110bfceb 7 * @note program exits the staring loop and pretend to sleep.
Rhyme 0:0b7a110bfceb 8 * @note Then touching the TFT starts the staring loop again.
Rhyme 0:0b7a110bfceb 9 */
Rhyme 0:0b7a110bfceb 10
Rhyme 0:0b7a110bfceb 11 /*
Rhyme 0:0b7a110bfceb 12 * Note: This program is derived from the SeeeStudioTFTv2 program.
Rhyme 0:0b7a110bfceb 13 * Although both program share same ILI9341 TFT driver,
Rhyme 0:0b7a110bfceb 14 * the touch sensor was not same with the Display I purchased from Akizuki.
Rhyme 0:0b7a110bfceb 15 * http://akizukidenshi.com/catalog/g/gM-07747/
Rhyme 0:0b7a110bfceb 16 * The touch sensor on the display is STMPE610,
Rhyme 0:0b7a110bfceb 17 * so I hacked the minimum spi driver for it (polling mode only).
Rhyme 0:0b7a110bfceb 18 */
Rhyme 0:0b7a110bfceb 19
Rhyme 0:0b7a110bfceb 20 #include "mbed.h"
Rhyme 0:0b7a110bfceb 21 #include "TSISensor.h"
Rhyme 0:0b7a110bfceb 22 #include "SPI_TFT_ILI9341.h"
Rhyme 0:0b7a110bfceb 23 #include "SPI_STMPE610.h"
Rhyme 0:0b7a110bfceb 24 #include "Arial12x12.h"
Rhyme 0:0b7a110bfceb 25 #include "Arial24x23.h"
Rhyme 0:0b7a110bfceb 26 #include "Arial28x28.h"
Rhyme 0:0b7a110bfceb 27 #include "font_big.h"
Rhyme 0:0b7a110bfceb 28
Rhyme 0:0b7a110bfceb 29 #define PIN_MOSI PTD2
Rhyme 0:0b7a110bfceb 30 #define PIN_MISO PTD3
Rhyme 0:0b7a110bfceb 31 #define PIN_SCLK PTD1
Rhyme 0:0b7a110bfceb 32 #define PIN_CS_TFT PTD0
Rhyme 0:0b7a110bfceb 33 #define PIN_DC_TFT PTD5
Rhyme 0:0b7a110bfceb 34 #define PIN_BL_TFT PTC9
Rhyme 0:0b7a110bfceb 35 #define PIN_CS_SD PTA4
Rhyme 0:0b7a110bfceb 36 #define PIN_CS_TSC PTA13
Rhyme 0:0b7a110bfceb 37 #define PIN_TSC_INTR PTC9
Rhyme 0:0b7a110bfceb 38
Rhyme 0:0b7a110bfceb 39 TSISensor tsi;
Rhyme 0:0b7a110bfceb 40
Rhyme 0:0b7a110bfceb 41 SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
Rhyme 0:0b7a110bfceb 42 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:0b7a110bfceb 43
Rhyme 0:0b7a110bfceb 44 DigitalOut backlight(PTA12) ;
Rhyme 0:0b7a110bfceb 45
Rhyme 0:0b7a110bfceb 46 void initTFT(void)
Rhyme 0:0b7a110bfceb 47 {
Rhyme 0:0b7a110bfceb 48 //Configure the display driver
Rhyme 0:0b7a110bfceb 49 TFT.background(Black);
Rhyme 0:0b7a110bfceb 50 TFT.foreground(White);
Rhyme 0:0b7a110bfceb 51 wait(0.01) ;
Rhyme 0:0b7a110bfceb 52 TFT.cls();
Rhyme 0:0b7a110bfceb 53 }
Rhyme 0:0b7a110bfceb 54
Rhyme 0:0b7a110bfceb 55 void moveEye(void)
Rhyme 0:0b7a110bfceb 56 {
Rhyme 0:0b7a110bfceb 57 int dx, px ;
Rhyme 0:0b7a110bfceb 58 float delta = 0.0 ;
Rhyme 0:0b7a110bfceb 59 dx = 0 ;
Rhyme 0:0b7a110bfceb 60 px = 0 ;
Rhyme 0:0b7a110bfceb 61 backlight = 0 ;
Rhyme 0:0b7a110bfceb 62 TFT.background(Black);
Rhyme 0:0b7a110bfceb 63 wait(0.1) ;
Rhyme 0:0b7a110bfceb 64 TFT.foreground(White);
Rhyme 0:0b7a110bfceb 65 wait(0.1) ;
Rhyme 0:0b7a110bfceb 66 TFT.cls() ;
Rhyme 0:0b7a110bfceb 67 wait(0.1) ;
Rhyme 0:0b7a110bfceb 68
Rhyme 0:0b7a110bfceb 69 TFT.set_font((unsigned char*) Arial12x12);
Rhyme 0:0b7a110bfceb 70 TFT.foreground(Blue) ;
Rhyme 0:0b7a110bfceb 71 TFT.locate(60, 10) ;
Rhyme 0:0b7a110bfceb 72 TFT.printf("<< TS Eye >>") ;
Rhyme 0:0b7a110bfceb 73 TFT.locate(30, 280) ;
Rhyme 0:0b7a110bfceb 74 TFT.printf("Use FRDM touch slider") ;
Rhyme 0:0b7a110bfceb 75 TFT.locate(30, 300) ;
Rhyme 0:0b7a110bfceb 76 TFT.printf("Touch right edge to end") ;
Rhyme 0:0b7a110bfceb 77
Rhyme 0:0b7a110bfceb 78 TFT.fillcircle(120, 160, 100, Green) ;
Rhyme 0:0b7a110bfceb 79 TFT.fillcircle(60, 160, 50, Black) ;
Rhyme 0:0b7a110bfceb 80 TFT.fillcircle(60, 160, 45, White) ;
Rhyme 0:0b7a110bfceb 81 TFT.fillcircle(180, 160, 50, Black) ;
Rhyme 0:0b7a110bfceb 82 TFT.fillcircle(180, 160, 45, White) ;
Rhyme 0:0b7a110bfceb 83 TFT.fillcircle(60, 160, 5, Black) ;
Rhyme 0:0b7a110bfceb 84 TFT.fillcircle(180, 160, 5, Black) ;
Rhyme 0:0b7a110bfceb 85 backlight = 1 ;
Rhyme 0:0b7a110bfceb 86
Rhyme 0:0b7a110bfceb 87 while(dx < 38) {
Rhyme 0:0b7a110bfceb 88 delta = (80.0 * (tsi.readPercentage()-0.5)) ;
Rhyme 0:0b7a110bfceb 89 dx = (int)(delta + 0.5) ;
Rhyme 0:0b7a110bfceb 90 TFT.fillcircle(60+px, 160, 5, White) ;
Rhyme 0:0b7a110bfceb 91 TFT.fillcircle(180+px, 160, 5, White) ;
Rhyme 0:0b7a110bfceb 92 TFT.fillcircle(60+dx, 160, 5, Black) ;
Rhyme 0:0b7a110bfceb 93 TFT.fillcircle(180+dx, 160, 5, Black) ;
Rhyme 0:0b7a110bfceb 94 px = dx ;
Rhyme 0:0b7a110bfceb 95 wait(0.1) ;
Rhyme 0:0b7a110bfceb 96 }
Rhyme 0:0b7a110bfceb 97 TFT.fillcircle(60+px, 160, 5, White) ;
Rhyme 0:0b7a110bfceb 98 TFT.fillcircle(180+px, 160, 5, White) ;
Rhyme 0:0b7a110bfceb 99 TFT.line(15, 160, 105, 160, Black) ;
Rhyme 0:0b7a110bfceb 100 TFT.line(135, 160, 225, 160, Black) ;
Rhyme 0:0b7a110bfceb 101 TFT.locate(30, 280) ;
Rhyme 0:0b7a110bfceb 102 TFT.printf(" Sleeping ... zzz ") ;
Rhyme 0:0b7a110bfceb 103 TFT.locate(20, 300) ;
Rhyme 0:0b7a110bfceb 104 TFT.foreground(Yellow) ;
Rhyme 0:0b7a110bfceb 105 TFT.printf(" Touch TFT to wake up") ;
Rhyme 0:0b7a110bfceb 106 }
Rhyme 0:0b7a110bfceb 107
Rhyme 0:0b7a110bfceb 108 int main()
Rhyme 0:0b7a110bfceb 109 {
Rhyme 0:0b7a110bfceb 110 uint16_t x, y, z ;
Rhyme 0:0b7a110bfceb 111 bool awake = true ;
Rhyme 0:0b7a110bfceb 112
Rhyme 0:0b7a110bfceb 113 initTFT() ;
Rhyme 0:0b7a110bfceb 114
Rhyme 0:0b7a110bfceb 115 for(;;) {
Rhyme 0:0b7a110bfceb 116
Rhyme 0:0b7a110bfceb 117 if (awake) {
Rhyme 0:0b7a110bfceb 118 moveEye() ;
Rhyme 0:0b7a110bfceb 119 awake = false ;
Rhyme 0:0b7a110bfceb 120 }
Rhyme 0:0b7a110bfceb 121
Rhyme 0:0b7a110bfceb 122 if ( TSC.getRAWPoint(&x, &y, &z)) {
Rhyme 0:0b7a110bfceb 123 awake = true ;
Rhyme 0:0b7a110bfceb 124 }
Rhyme 0:0b7a110bfceb 125
Rhyme 0:0b7a110bfceb 126 }
Rhyme 0:0b7a110bfceb 127 }