init

Dependencies:   UniGraphic

Fork of STM32F103C8T6_ILI9341 by Nathan Yonkee

Committer:
tulanthoar
Date:
Mon Nov 27 20:36:32 2017 +0000
Revision:
2:ce7ced8a93bc
Parent:
0:7136ca870582
Child:
3:6cddb29fc8d0
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:7136ca870582 1 #include "mbed.h"
hudakz 0:7136ca870582 2 #include "Arial12x12.h"
hudakz 0:7136ca870582 3 #include "Arial24x23.h"
hudakz 0:7136ca870582 4 #include "Arial43x48_numb.h"
hudakz 0:7136ca870582 5 #include "pict.h"
hudakz 0:7136ca870582 6 #include "pavement_48x34.h"
hudakz 0:7136ca870582 7 #include "ILI9341.h"
hudakz 0:7136ca870582 8
hudakz 0:7136ca870582 9 const unsigned short FOREGROUND_COLORS[] = {White, Cyan, Red, Magenta, Yellow, Orange, GreenYellow};
hudakz 0:7136ca870582 10 const unsigned short BACKGROUND_COLORS[] = {Black, Navy, DarkGreen, DarkCyan, Maroon};
hudakz 0:7136ca870582 11
tulanthoar 2:ce7ced8a93bc 12 Serial pc(USBTX, USBRX); // serial interface with PC
hudakz 0:7136ca870582 13 ILI9341* tft; // ILI9341 driver
hudakz 0:7136ca870582 14 Timer t;
hudakz 0:7136ca870582 15 unsigned short backgroundColor;
hudakz 0:7136ca870582 16 unsigned short foregroundColor;
hudakz 0:7136ca870582 17 unsigned short colorIndex = 0;
hudakz 0:7136ca870582 18 char orient = 3;
hudakz 0:7136ca870582 19
hudakz 0:7136ca870582 20
hudakz 0:7136ca870582 21
hudakz 0:7136ca870582 22 int main()
hudakz 0:7136ca870582 23 {
tulanthoar 2:ce7ced8a93bc 24 //tft = new ILI9341(SPI_8, 20000000, PB_5, PB_4, PB_3, PA_15, PA_12, PA_11, "tft"); // SPI type, SPI speed, mosi, miso, sclk, cs, reset, dc
tulanthoar 2:ce7ced8a93bc 25 tft = new ILI9341(SPI_8, 20000000, PA_7, PA_6, PA_1, PB_0, PB_7, PB_6, "tft"); // SPI type, SPI speed, mosi, miso, sclk, cs, reset, dc
hudakz 0:7136ca870582 26 tft->set_orientation(orient);
hudakz 0:7136ca870582 27 int time, time2;
hudakz 0:7136ca870582 28 pc.baud (115200);
hudakz 0:7136ca870582 29 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000);
hudakz 0:7136ca870582 30 t.start();
hudakz 0:7136ca870582 31
hudakz 0:7136ca870582 32 while(1) {
hudakz 0:7136ca870582 33 foregroundColor = FOREGROUND_COLORS[colorIndex % 7];
hudakz 0:7136ca870582 34 tft->foreground(foregroundColor); // set chars to white
hudakz 0:7136ca870582 35 backgroundColor = BACKGROUND_COLORS[colorIndex % 5];
hudakz 0:7136ca870582 36 colorIndex++;
hudakz 0:7136ca870582 37 tft->background(backgroundColor); // set background to black
hudakz 0:7136ca870582 38 tft->set_orientation((orient++)%4);
hudakz 0:7136ca870582 39 tft->cls(); // clear the screen
hudakz 0:7136ca870582 40 tft->locate(0,30);
hudakz 0:7136ca870582 41 tft->printf("Display ID: %.8X\r\n", tft->tftID);
hudakz 0:7136ca870582 42 pc.printf("Display ID: %.8X\r\n", tft->tftID);
hudakz 0:7136ca870582 43 // mem write/read test
hudakz 0:7136ca870582 44 unsigned short readback;
hudakz 0:7136ca870582 45 unsigned short colorstep = (0x10000/tft->width());
hudakz 0:7136ca870582 46 for(unsigned short i=0; i<tft->width(); i++) {
hudakz 0:7136ca870582 47 tft->pixel(i,0,i*colorstep); // write line
hudakz 0:7136ca870582 48 }
hudakz 0:7136ca870582 49 bool readerror=false;
hudakz 0:7136ca870582 50 for(unsigned short i=0; i<tft->width(); i++) { // verify line
hudakz 0:7136ca870582 51 readback = tft->pixelread(i,0);
hudakz 0:7136ca870582 52 if(readback!=i*colorstep) {
hudakz 0:7136ca870582 53 readerror=true;
hudakz 0:7136ca870582 54 pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback);
hudakz 0:7136ca870582 55 }
hudakz 0:7136ca870582 56 }
hudakz 0:7136ca870582 57 tft->locate(0,10);
hudakz 0:7136ca870582 58 tft->printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS");
hudakz 0:7136ca870582 59 wait(2);
hudakz 0:7136ca870582 60
hudakz 0:7136ca870582 61 tft->cls();
hudakz 0:7136ca870582 62 tft->set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled
hudakz 0:7136ca870582 63 tft->locate(0,0);
hudakz 0:7136ca870582 64 tft->printf("Display Test\r\nSome text just to see if auto carriage return works correctly");
hudakz 0:7136ca870582 65 tft->set_font((unsigned char*) Terminal6x8);
hudakz 0:7136ca870582 66 tft->printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly");
hudakz 0:7136ca870582 67 pc.printf(" Display Test \r\n");
hudakz 0:7136ca870582 68 wait(3);
hudakz 0:7136ca870582 69 t.reset();
hudakz 0:7136ca870582 70 tft->cls();
hudakz 0:7136ca870582 71 time=t.read_us();
hudakz 0:7136ca870582 72 tft->locate(2,55);
hudakz 0:7136ca870582 73 tft->printf("cls: %.3fms", (float)time/1000);
hudakz 0:7136ca870582 74 pc.printf("cls: %.3fms\r\n", (float)time/1000);
hudakz 0:7136ca870582 75 wait(3);
hudakz 0:7136ca870582 76
hudakz 0:7136ca870582 77 tft->cls();
hudakz 0:7136ca870582 78 t.reset();
hudakz 0:7136ca870582 79 // draw some graphics
hudakz 0:7136ca870582 80 tft->set_font((unsigned char*) Arial24x23);
hudakz 0:7136ca870582 81 tft->locate(10,10);
hudakz 0:7136ca870582 82 tft->printf("Test");
hudakz 0:7136ca870582 83
hudakz 0:7136ca870582 84 tft->line(0,0,tft->width()-1,0,foregroundColor);
hudakz 0:7136ca870582 85 tft->line(0,0,0,tft->height()-1,foregroundColor);
hudakz 0:7136ca870582 86 tft->line(0,0,tft->width()-1,tft->height()-1,foregroundColor);
hudakz 0:7136ca870582 87
hudakz 0:7136ca870582 88 tft->rect(10,30,50,40,foregroundColor);
hudakz 0:7136ca870582 89 tft->fillrect(60,30,100,40,foregroundColor);
hudakz 0:7136ca870582 90
hudakz 0:7136ca870582 91 tft->circle(150,32,30,foregroundColor);
hudakz 0:7136ca870582 92 tft->fillcircle(140,20,10,foregroundColor);
hudakz 0:7136ca870582 93
hudakz 0:7136ca870582 94 double s;
hudakz 0:7136ca870582 95
hudakz 0:7136ca870582 96 for (unsigned short i=0; i<tft->width(); i++) {
hudakz 0:7136ca870582 97 s =10 * sin((long double) i / 10 );
hudakz 0:7136ca870582 98 tft->pixel(i,40 + (int)s ,foregroundColor);
hudakz 0:7136ca870582 99 }
hudakz 0:7136ca870582 100
hudakz 0:7136ca870582 101
hudakz 0:7136ca870582 102 time=t.read_us();
hudakz 0:7136ca870582 103 tft->locate(2,55);
hudakz 0:7136ca870582 104 tft->set_font((unsigned char*) Terminal6x8);
hudakz 0:7136ca870582 105 tft->printf("plot: %.3fms", (float)time/1000);
hudakz 0:7136ca870582 106 pc.printf("plot: %.3fms\r\n", (float)time/1000);
hudakz 0:7136ca870582 107 wait(3);
hudakz 0:7136ca870582 108 tft->cls();
hudakz 0:7136ca870582 109 t.reset();
hudakz 0:7136ca870582 110 Bitmap_s pic = {
hudakz 0:7136ca870582 111 64, // XSize
hudakz 0:7136ca870582 112 64, // YSize
hudakz 0:7136ca870582 113 8, // Bytes in Line
hudakz 0:7136ca870582 114 burp, // Pointer to picture data
hudakz 0:7136ca870582 115 };
hudakz 0:7136ca870582 116 tft->Bitmap_BW(pic,tft->width()-64,0);
hudakz 0:7136ca870582 117 time=t.read_us();
hudakz 0:7136ca870582 118 tft->locate(2,55);
hudakz 0:7136ca870582 119 tft->printf("bmp: %.3fms", (float)time/1000);
hudakz 0:7136ca870582 120 pc.printf("bmp: %.3fms\r\n", (float)time/1000);
hudakz 0:7136ca870582 121 wait(3);
hudakz 0:7136ca870582 122 tft->cls();
hudakz 0:7136ca870582 123 tft->set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled
hudakz 0:7136ca870582 124 t.reset();
hudakz 0:7136ca870582 125 tft->locate(0,0);
hudakz 0:7136ca870582 126 tft->printf("%d", 12345);
hudakz 0:7136ca870582 127 time=t.read_us();
hudakz 0:7136ca870582 128 tft->locate(2,55);
hudakz 0:7136ca870582 129 tft->set_font((unsigned char*) Terminal6x8);
hudakz 0:7136ca870582 130 tft->printf("Big Font: %.3fms", (float)time/1000);
hudakz 0:7136ca870582 131 pc.printf("Big Font: %.3fms\r\n", (float)time/1000);
hudakz 0:7136ca870582 132 wait(3);
hudakz 0:7136ca870582 133 // sparse pixels test
hudakz 0:7136ca870582 134 tft->cls();
hudakz 0:7136ca870582 135 tft->FastWindow(true);
hudakz 0:7136ca870582 136 t.reset();
hudakz 0:7136ca870582 137 for(unsigned int i=0; i<20000; i++) {
hudakz 0:7136ca870582 138 tft->pixel((i+(i*89)%tft->width()), (i+(i*61)%tft->height()), White);
hudakz 0:7136ca870582 139 }
hudakz 0:7136ca870582 140 tft->copy_to_lcd();
hudakz 0:7136ca870582 141 time=t.read_us();
hudakz 0:7136ca870582 142 tft->cls();
hudakz 0:7136ca870582 143 tft->FastWindow(false);
hudakz 0:7136ca870582 144 t.reset();
hudakz 0:7136ca870582 145 for(unsigned int i=0; i<20000; i++) {
hudakz 0:7136ca870582 146 tft->pixel((i+(i*89)%tft->width()), (i+(i*61)%tft->height()), White);
hudakz 0:7136ca870582 147 }
hudakz 0:7136ca870582 148 tft->copy_to_lcd();
hudakz 0:7136ca870582 149 time2=t.read_us();
hudakz 0:7136ca870582 150 tft->locate(2,55);
hudakz 0:7136ca870582 151 tft->printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000);
hudakz 0:7136ca870582 152 pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000);
hudakz 0:7136ca870582 153 wait(3);
hudakz 0:7136ca870582 154 // scroll test, only for TFT
hudakz 0:7136ca870582 155 tft->cls();
hudakz 0:7136ca870582 156 tft->set_font((unsigned char*) Arial24x23);
hudakz 0:7136ca870582 157 tft->locate(2,10);
hudakz 0:7136ca870582 158 tft->printf("Scrolling");
hudakz 0:7136ca870582 159 tft->rect(0,0,tft->width()-1,tft->height()-1,White);
hudakz 0:7136ca870582 160 tft->rect(1,1,tft->width()-2,tft->height()-2,Blue);
hudakz 0:7136ca870582 161 tft->setscrollarea(0,tft->sizeY());
hudakz 0:7136ca870582 162 wait(1);
hudakz 0:7136ca870582 163 tft->scroll(1); //up 1
hudakz 0:7136ca870582 164 wait(1);
hudakz 0:7136ca870582 165 tft->scroll(0); //center
hudakz 0:7136ca870582 166 wait(1);
hudakz 0:7136ca870582 167 tft->scroll(tft->sizeY()-1); //down 1
hudakz 0:7136ca870582 168 wait(1);
hudakz 0:7136ca870582 169 tft->scroll(tft->sizeY()); // same as 0, center
hudakz 0:7136ca870582 170 wait(1);
hudakz 0:7136ca870582 171 tft->scroll(tft->sizeY()>>1); // half screen
hudakz 0:7136ca870582 172 wait(1);
hudakz 0:7136ca870582 173 tft->scrollreset(); // center
hudakz 0:7136ca870582 174 wait(1);
hudakz 0:7136ca870582 175 for(unsigned short i=1; i<=tft->sizeY(); i++) {
hudakz 0:7136ca870582 176 tft->scroll(i);
hudakz 0:7136ca870582 177 wait_ms(2);
hudakz 0:7136ca870582 178 }
hudakz 0:7136ca870582 179 wait(2);
hudakz 0:7136ca870582 180 // color inversion
hudakz 0:7136ca870582 181 for(unsigned short i=0; i<=8; i++) {
hudakz 0:7136ca870582 182 tft->invert(i&1);
hudakz 0:7136ca870582 183 wait_ms(200);
hudakz 0:7136ca870582 184 }
hudakz 0:7136ca870582 185 wait(2);
hudakz 0:7136ca870582 186 // bmp 16bit test
hudakz 0:7136ca870582 187 tft->cls();
hudakz 0:7136ca870582 188 t.reset();
hudakz 0:7136ca870582 189 for(int y=0; y<tft->height(); y+=34) {
hudakz 0:7136ca870582 190 for(int x=0; x<tft->width(); x+=48) tft->Bitmap(x,y,48,34,(unsigned char *)pavement_48x34);
hudakz 0:7136ca870582 191 }
hudakz 0:7136ca870582 192 time=t.read_us();
hudakz 0:7136ca870582 193 tft->locate(2,55);
hudakz 0:7136ca870582 194 tft->set_font((unsigned char*) Terminal6x8);
hudakz 0:7136ca870582 195 tft->printf("Bmp speed: %.3fms", (float)time/1000);
hudakz 0:7136ca870582 196 pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000);
hudakz 0:7136ca870582 197 wait(2);
hudakz 0:7136ca870582 198 }
hudakz 0:7136ca870582 199 }
hudakz 0:7136ca870582 200
hudakz 0:7136ca870582 201