test for the SPI_TFT Lib

Dependencies:   SPI_TFT TFT_fonts mbed

Fork of TFT by Peter Drescher

Committer:
dreschpe
Date:
Sat Apr 07 14:28:58 2012 +0000
Revision:
1:b295f3228ea2
Parent:
0:f5b62bef3680
Child:
3:0d07cf37bc00
code with DMA

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 1:b295f3228ea2 1 // example to test the TFT Display
dreschpe 1:b295f3228ea2 2 // Thanks to the GraphicsDisplay and TextDisplay classes from
dreschpe 0:f5b62bef3680 3
dreschpe 0:f5b62bef3680 4 #include "stdio.h"
dreschpe 0:f5b62bef3680 5 #include "mbed.h"
dreschpe 0:f5b62bef3680 6 #include "SPI_TFT.h"
dreschpe 0:f5b62bef3680 7 #include "string"
dreschpe 0:f5b62bef3680 8 #include "Arial12x12.h"
dreschpe 0:f5b62bef3680 9 #include "Arial24x23.h"
dreschpe 0:f5b62bef3680 10 #include "Arial28x28.h"
dreschpe 0:f5b62bef3680 11 #include "font_big.h"
dreschpe 0:f5b62bef3680 12
dreschpe 0:f5b62bef3680 13 extern unsigned char p1[]; // the mbed logo
dreschpe 1:b295f3228ea2 14 DigitalOut xx(p6); // debug !!
dreschpe 1:b295f3228ea2 15 Serial pc(USBTX, USBRX); // tx, rx
dreschpe 1:b295f3228ea2 16 DigitalOut myled(LED1);
dreschpe 0:f5b62bef3680 17
dreschpe 1:b295f3228ea2 18 // the TFT is connected to SPI pin 11-14
dreschpe 0:f5b62bef3680 19 SPI_TFT TFT(p11, p12, p13, p14, p15,"TFT"); // mosi, miso, sclk, cs, reset
dreschpe 0:f5b62bef3680 20
dreschpe 1:b295f3228ea2 21 //LocalFileSystem local("local");
dreschpe 0:f5b62bef3680 22
dreschpe 0:f5b62bef3680 23 int main() {
dreschpe 1:b295f3228ea2 24
dreschpe 1:b295f3228ea2 25 //pc.printf("start main \n\r");
dreschpe 0:f5b62bef3680 26 int i;
dreschpe 1:b295f3228ea2 27 TFT.claim(stdout); // send stdout to the TFT display
dreschpe 0:f5b62bef3680 28 //TFT.claim(stderr); // send stderr to the TFT display
dreschpe 1:b295f3228ea2 29 TFT.set_orientation(0);
dreschpe 0:f5b62bef3680 30 TFT.background(Black); // set background to black
dreschpe 0:f5b62bef3680 31 TFT.foreground(White); // set chars to white
dreschpe 0:f5b62bef3680 32 TFT.cls(); // clear the screen
dreschpe 0:f5b62bef3680 33
dreschpe 1:b295f3228ea2 34 // first show the 4 directions
dreschpe 1:b295f3228ea2 35 // mbed logo
dreschpe 1:b295f3228ea2 36 //TFT.set_orientation(0);
dreschpe 1:b295f3228ea2 37 //TFT.background(Black);
dreschpe 1:b295f3228ea2 38 //TFT.cls();
dreschpe 1:b295f3228ea2 39
dreschpe 1:b295f3228ea2 40 //do{} while(1);
dreschpe 1:b295f3228ea2 41
dreschpe 0:f5b62bef3680 42 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:f5b62bef3680 43 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 44 printf(" Hello Mbed 0");
dreschpe 1:b295f3228ea2 45
dreschpe 1:b295f3228ea2 46 // do{} while(1);
dreschpe 1:b295f3228ea2 47
dreschpe 0:f5b62bef3680 48 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 49 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 50 printf(" Hello Mbed 1");
dreschpe 0:f5b62bef3680 51 TFT.set_orientation(2);
dreschpe 0:f5b62bef3680 52 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 53 printf(" Hello Mbed 2");
dreschpe 0:f5b62bef3680 54 TFT.set_orientation(3);
dreschpe 0:f5b62bef3680 55 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 56 printf(" Hello Mbed 3");
dreschpe 0:f5b62bef3680 57 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 58 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 59 TFT.locate(50,100);
dreschpe 0:f5b62bef3680 60 TFT.printf("TFT orientation");
dreschpe 1:b295f3228ea2 61
dreschpe 1:b295f3228ea2 62 wait(5); // wait two seconds
dreschpe 1:b295f3228ea2 63
dreschpe 1:b295f3228ea2 64 // draw some graphics
dreschpe 1:b295f3228ea2 65 TFT.cls();
dreschpe 0:f5b62bef3680 66 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 67 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 68 TFT.locate(100,100);
dreschpe 0:f5b62bef3680 69 TFT.printf("Graphic");
dreschpe 1:b295f3228ea2 70
dreschpe 1:b295f3228ea2 71 TFT.line(0,0,100,0,Green);
dreschpe 1:b295f3228ea2 72 TFT.line(0,0,0,200,Green);
dreschpe 0:f5b62bef3680 73 TFT.line(0,0,100,200,Green);
dreschpe 1:b295f3228ea2 74
dreschpe 0:f5b62bef3680 75 TFT.rect(100,50,150,100,Red);
dreschpe 0:f5b62bef3680 76 TFT.fillrect(180,25,220,70,Blue);
dreschpe 1:b295f3228ea2 77
dreschpe 0:f5b62bef3680 78 TFT.circle(80,150,33,White);
dreschpe 1:b295f3228ea2 79 TFT.fillcircle(160,190,20,Yellow);
dreschpe 1:b295f3228ea2 80
dreschpe 0:f5b62bef3680 81 wait(5); // wait two seconds
dreschpe 1:b295f3228ea2 82
dreschpe 0:f5b62bef3680 83 // bigger text
dreschpe 0:f5b62bef3680 84 TFT.foreground(White);
dreschpe 0:f5b62bef3680 85 TFT.background(Blue);
dreschpe 0:f5b62bef3680 86 TFT.cls();
dreschpe 0:f5b62bef3680 87 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 88 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 89 TFT.printf("Different Fonts :");
dreschpe 1:b295f3228ea2 90
dreschpe 0:f5b62bef3680 91 TFT.set_font((unsigned char*) Neu42x35);
dreschpe 0:f5b62bef3680 92 TFT.locate(0,30);
dreschpe 1:b295f3228ea2 93 TFT.printf("Hello Mbed 1");
dreschpe 0:f5b62bef3680 94 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 95 TFT.locate(20,80);
dreschpe 0:f5b62bef3680 96 TFT.printf("Hello Mbed 2");
dreschpe 0:f5b62bef3680 97 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:f5b62bef3680 98 TFT.locate(35,120);
dreschpe 0:f5b62bef3680 99 TFT.printf("Hello Mbed 3");
dreschpe 0:f5b62bef3680 100 wait(5);
dreschpe 1:b295f3228ea2 101
dreschpe 1:b295f3228ea2 102 // mbed logo
dreschpe 0:f5b62bef3680 103 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 104 TFT.background(Black);
dreschpe 0:f5b62bef3680 105 TFT.cls();
dreschpe 1:b295f3228ea2 106
dreschpe 1:b295f3228ea2 107 TFT.locate(10,10);
dreschpe 1:b295f3228ea2 108 TFT.printf("Graphic from Flash");
dreschpe 1:b295f3228ea2 109
dreschpe 0:f5b62bef3680 110 TFT.Bitmap(90,90,172,55,p1);
dreschpe 1:b295f3228ea2 111
dreschpe 1:b295f3228ea2 112 wait(5);
dreschpe 1:b295f3228ea2 113 TFT.cls();
dreschpe 1:b295f3228ea2 114 TFT.locate(10,10);
dreschpe 1:b295f3228ea2 115 TFT.printf("Graphic from File System");
dreschpe 1:b295f3228ea2 116 int err = TFT.BMP_16(20,50,"test.bmp");
dreschpe 1:b295f3228ea2 117 if (err != 1) TFT.printf(" - Err: %d",err);
dreschpe 0:f5b62bef3680 118 }
dreschpe 0:f5b62bef3680 119