Nathan Yonkee / Mbed OS STM32L432KC_ILI9341

Dependencies:   UniGraphic

Fork of STM32F103C8T6_ILI9341 by Nathan Yonkee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Arial12x12.h"
00003 #include "Arial24x23.h"
00004 #include "Arial43x48_numb.h"
00005 #include "pict.h"
00006 #include "pavement_48x34.h"
00007 #include "ILI9341.h"
00008 
00009 const unsigned short  FOREGROUND_COLORS[] = {White, Cyan, Red, Magenta, Yellow, Orange, GreenYellow};
00010 const unsigned short  BACKGROUND_COLORS[] = {Black, Navy, DarkGreen, DarkCyan, Maroon};
00011 
00012 Serial          pc(USBTX, USBRX);     // serial interface with PC
00013 ILI9341*        tft;                // ILI9341 driver
00014 Timer           t;
00015 unsigned short  backgroundColor;
00016 unsigned short  foregroundColor;
00017 unsigned short  colorIndex = 0;
00018 char            orient = 3;
00019 
00020 
00021 
00022 int main()
00023 {
00024     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
00025     tft->set_orientation(orient);
00026     int time, time2;
00027     pc.baud (115200);
00028     pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000);
00029     t.start();
00030 
00031     while(1) {
00032         foregroundColor = FOREGROUND_COLORS[colorIndex % 7];
00033         tft->foreground(foregroundColor);    // set chars to white
00034         backgroundColor = BACKGROUND_COLORS[colorIndex % 5];
00035         colorIndex++;
00036         tft->background(backgroundColor);    // set background to black
00037         tft->set_orientation((orient++)%4);
00038         tft->cls();                     // clear the screen
00039         tft->locate(0,30);
00040         tft->printf("Display ID: %.8X\r\n", tft->tftID);
00041         pc.printf("Display ID: %.8X\r\n", tft->tftID);
00042         // mem write/read test
00043         unsigned short readback;
00044         unsigned short colorstep = (0x10000/tft->width());
00045         for(unsigned short i=0; i<tft->width(); i++) {
00046             tft->pixel(i,0,i*colorstep); // write line
00047         }
00048         bool readerror=false;
00049         for(unsigned short i=0; i<tft->width(); i++) { // verify line
00050             readback = tft->pixelread(i,0);
00051             if(readback!=i*colorstep) {
00052                 readerror=true;
00053                 pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback);
00054             }
00055         }
00056         tft->locate(0,10);
00057         tft->printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS");
00058         wait(2);
00059 
00060         tft->cls();
00061         tft->set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled
00062         tft->locate(0,0);
00063         tft->printf("Display Test\r\nSome text just to see if auto carriage return works correctly");
00064         tft->set_font((unsigned char*) Terminal6x8);
00065         tft->printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly");
00066         pc.printf("  Display Test \r\n");
00067         wait(3);
00068         t.reset();
00069         tft->cls();
00070         time=t.read_us();
00071         tft->locate(2,55);
00072         tft->printf("cls: %.3fms", (float)time/1000);
00073         pc.printf("cls: %.3fms\r\n", (float)time/1000);
00074         wait(3);
00075 
00076         tft->cls();
00077         t.reset();
00078         // draw some graphics
00079         tft->set_font((unsigned char*) Arial24x23);
00080         tft->locate(10,10);
00081         tft->printf("Test");
00082 
00083         tft->line(0,0,tft->width()-1,0,foregroundColor);
00084         tft->line(0,0,0,tft->height()-1,foregroundColor);
00085         tft->line(0,0,tft->width()-1,tft->height()-1,foregroundColor);
00086 
00087         tft->rect(10,30,50,40,foregroundColor);
00088         tft->fillrect(60,30,100,40,foregroundColor);
00089 
00090         tft->circle(150,32,30,foregroundColor);
00091         tft->fillcircle(140,20,10,foregroundColor);
00092 
00093         double s;
00094 
00095         for (unsigned short i=0; i<tft->width(); i++) {
00096             s =10 * sin((long double) i / 10 );
00097             tft->pixel(i,40 + (int)s ,foregroundColor);
00098         }
00099 
00100 
00101         time=t.read_us();
00102         tft->locate(2,55);
00103         tft->set_font((unsigned char*) Terminal6x8);
00104         tft->printf("plot: %.3fms", (float)time/1000);
00105         pc.printf("plot: %.3fms\r\n", (float)time/1000);
00106         wait(3);
00107         tft->cls();
00108         t.reset();
00109         Bitmap_s pic = {
00110             64,     // XSize
00111             64,     // YSize
00112             8,      // Bytes in Line
00113             burp,   // Pointer to picture data
00114         };
00115         tft->Bitmap_BW(pic,tft->width()-64,0);
00116         time=t.read_us();
00117         tft->locate(2,55);
00118         tft->printf("bmp: %.3fms", (float)time/1000);
00119         pc.printf("bmp: %.3fms\r\n", (float)time/1000);
00120         wait(3);
00121         tft->cls();
00122         tft->set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled
00123         t.reset();
00124         tft->locate(0,0);
00125         tft->printf("%d", 12345);
00126         time=t.read_us();
00127         tft->locate(2,55);
00128         tft->set_font((unsigned char*) Terminal6x8);
00129         tft->printf("Big Font: %.3fms", (float)time/1000);
00130         pc.printf("Big Font: %.3fms\r\n", (float)time/1000);
00131         wait(3);
00132         // sparse pixels test
00133         tft->cls();
00134         tft->FastWindow(true);
00135         t.reset();
00136         for(unsigned int i=0; i<20000; i++) {
00137             tft->pixel((i+(i*89)%tft->width()), (i+(i*61)%tft->height()), White);
00138         }
00139         tft->copy_to_lcd();
00140         time=t.read_us();
00141         tft->cls();
00142         tft->FastWindow(false);
00143         t.reset();
00144         for(unsigned int i=0; i<20000; i++) {
00145             tft->pixel((i+(i*89)%tft->width()), (i+(i*61)%tft->height()), White);
00146         }
00147         tft->copy_to_lcd();
00148         time2=t.read_us();
00149         tft->locate(2,55);
00150         tft->printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000);
00151         pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000);
00152         wait(3);
00153         // scroll test, only for TFT
00154         tft->cls();
00155         tft->set_font((unsigned char*) Arial24x23);
00156         tft->locate(2,10);
00157         tft->printf("Scrolling");
00158         tft->rect(0,0,tft->width()-1,tft->height()-1,White);
00159         tft->rect(1,1,tft->width()-2,tft->height()-2,Blue);
00160         tft->setscrollarea(0,tft->sizeY());
00161         wait(1);
00162         tft->scroll(1); //up 1
00163         wait(1);
00164         tft->scroll(0); //center
00165         wait(1);
00166         tft->scroll(tft->sizeY()-1); //down 1
00167         wait(1);
00168         tft->scroll(tft->sizeY()); // same as 0, center
00169         wait(1);
00170         tft->scroll(tft->sizeY()>>1); // half screen
00171         wait(1);
00172         tft->scrollreset(); // center
00173         wait(1);
00174         for(unsigned short i=1; i<=tft->sizeY(); i++) {
00175             tft->scroll(i);
00176             wait_ms(2);
00177         }
00178         wait(2);
00179         // color inversion
00180         for(unsigned short i=0; i<=8; i++) {
00181             tft->invert(i&1);
00182             wait_ms(200);
00183         }
00184         wait(2);
00185         // bmp 16bit test
00186         tft->cls();
00187         t.reset();
00188         for(int y=0; y<tft->height(); y+=34) {
00189             for(int x=0; x<tft->width(); x+=48) tft->Bitmap(x,y,48,34,(unsigned char *)pavement_48x34);
00190         }
00191         time=t.read_us();
00192         tft->locate(2,55);
00193         tft->set_font((unsigned char*) Terminal6x8);
00194         tft->printf("Bmp speed: %.3fms", (float)time/1000);
00195         pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000);
00196         wait(2);
00197     }
00198 }
00199 
00200