Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of UniGraphic_demo by
main.cpp
00001 // 00002 // UniGraphic demo on Nucleo-F401RE and UL024TF (Adafruit 2.2" parallel TFT shield compatible) 00003 // 00004 // 2016.3.13 00005 // 00006 // reference: https://developer.mbed.org/questions/6893/BusOut-instead-of-PortName/ 00007 // 00008 // 00009 // 00010 00011 #include "stdio.h" 00012 #include "mbed.h" 00013 #include "string" 00014 #include "Arial12x12.h" 00015 #include "Arial24x23.h" 00016 //#include "Terminal6x8.h" 00017 #include "Arial43x48_numb.h" 00018 #include "pict.h" 00019 #include "pavement_48x34.h" 00020 00021 //#include "IST3020.h" 00022 //#include "UC1608.h" 00023 //#include "ST7565.h" 00024 #include "ILI932x.h" 00025 //#include "ILI9341.h" 00026 //#include "ILI9486.h" 00027 //#include "TFT_MIPI.h" 00028 //#include "SSD1306.h" 00029 00030 Serial pc(USBTX, USBRX); 00031 00032 //IST3020 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 192, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302 00033 //UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc 00034 //ST7565 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 128, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD 00035 //ILI932x myLCD(PAR_8, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 8bit, Port, CS, reset, RS, WR, RD for F401 00036 //ILI932x myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset 00037 //ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc 00038 //ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00039 //ILI9486 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00040 //TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 00041 //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc 00042 //ILI9486 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple 00043 //ILI9341 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple 00044 00045 // using UL024TF on NucleoF401RE 00046 00047 PinName buspins[8]={D8,D9,D2,D3,D4,D5,D6,D7}; 00048 ILI932x myLCD(BUS_8, buspins, A3, A4, A2, A1, A0,"myLCD"); // Parallel Bus 8bit, buspins array, CS, reset, RS, WR, RD 00049 00050 00051 Timer t; 00052 00053 //unsigned short backgroundcolor=White; 00054 //unsigned short foregroundcolor=Black; 00055 unsigned short backgroundcolor=Black; 00056 unsigned short foregroundcolor=White; 00057 00058 char orient=1; 00059 int main() 00060 { 00061 // myLCD.set_contrast(26);//for uc1608 00062 // myLCD.set_contrast(46);//for ist3020 00063 myLCD.set_orientation(orient); 00064 int time, time2; 00065 pc.baud (115200); 00066 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); 00067 t.start(); 00068 // myLCD.set_font((unsigned char*) Terminal6x8); 00069 // myLCD.claim(stdout); // send stdout to the LCD display 00070 //myLCD.claim(stderr); // send stderr to the LCD display 00071 myLCD.background(backgroundcolor); // set background to black 00072 myLCD.foreground(foregroundcolor); // set chars to white 00073 00074 while(1) 00075 { 00076 myLCD.set_orientation((orient++)%4); 00077 // myLCD.set_orientation(2); 00078 myLCD.cls(); // clear the screen 00079 myLCD.locate(0,30); 00080 myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); 00081 pc.printf("Display ID: %.8X\r\n", myLCD.tftID); 00082 // mem write/read test 00083 unsigned short readback; 00084 unsigned short colorstep = (0x10000/myLCD.width()); 00085 for(unsigned short i=0; i<myLCD.width(); i++) 00086 { 00087 myLCD.pixel(i,0,i*colorstep); // write line 00088 } 00089 bool readerror=false; 00090 for(unsigned short i=0; i<myLCD.width(); i++) // verify line 00091 { 00092 readback = myLCD.pixelread(i,0); 00093 if(readback!=i*colorstep) 00094 { 00095 readerror=true; 00096 pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); 00097 } 00098 } 00099 myLCD.locate(0,10); 00100 myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); 00101 wait(2); 00102 00103 myLCD.cls(); 00104 myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled 00105 myLCD.locate(0,0); 00106 myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); 00107 myLCD.set_font((unsigned char*) Terminal6x8); 00108 // myLCD.locate(0,0); 00109 myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly"); 00110 pc.printf(" Display Test \r\n"); 00111 wait(3); 00112 t.reset(); 00113 myLCD.cls(); 00114 time=t.read_us(); 00115 myLCD.locate(2,55); 00116 myLCD.printf("cls: %.3fms", (float)time/1000); 00117 pc.printf("cls: %.3fms\r\n", (float)time/1000); 00118 wait(3); 00119 00120 myLCD.cls(); 00121 t.reset(); 00122 // draw some graphics 00123 //myLCD.cls(); 00124 myLCD.set_font((unsigned char*) Arial24x23); 00125 myLCD.locate(10,10); 00126 myLCD.printf("Test"); 00127 00128 myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); 00129 myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); 00130 myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); 00131 00132 myLCD.rect(10,30,50,40,foregroundcolor); 00133 myLCD.fillrect(60,30,100,40,foregroundcolor); 00134 00135 myLCD.circle(150,32,30,foregroundcolor); 00136 myLCD.fillcircle(140,20,10,foregroundcolor); 00137 00138 double s; 00139 00140 for (unsigned short i=0; i<myLCD.width(); i++) 00141 { 00142 s =10 * sin((long double) i / 10 ); 00143 myLCD.pixel(i,40 + (int)s ,foregroundcolor); 00144 } 00145 00146 00147 time=t.read_us(); 00148 myLCD.locate(2,55); 00149 myLCD.set_font((unsigned char*) Terminal6x8); 00150 myLCD.printf("plot: %.3fms", (float)time/1000); 00151 pc.printf("plot: %.3fms\r\n", (float)time/1000); 00152 wait(3); 00153 myLCD.cls(); 00154 t.reset(); 00155 Bitmap_s pic = { 00156 64, // XSize 00157 64, // YSize 00158 8, // Bytes in Line 00159 burp, // Pointer to picture data 00160 }; 00161 myLCD.Bitmap_BW(pic,myLCD.width()-64,0); 00162 time=t.read_us(); 00163 myLCD.locate(2,55); 00164 myLCD.printf("bmp: %.3fms", (float)time/1000); 00165 pc.printf("bmp: %.3fms\r\n", (float)time/1000); 00166 wait(3); 00167 myLCD.cls(); 00168 myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled 00169 t.reset(); 00170 myLCD.locate(0,0); 00171 myLCD.printf("%d", 12345); 00172 time=t.read_us(); 00173 myLCD.locate(2,55); 00174 myLCD.set_font((unsigned char*) Terminal6x8); 00175 myLCD.printf("Big Font: %.3fms", (float)time/1000); 00176 pc.printf("Big Font: %.3fms\r\n", (float)time/1000); 00177 wait(3); 00178 // sparse pixels test 00179 myLCD.cls(); 00180 myLCD.FastWindow(true); 00181 t.reset(); 00182 for(unsigned int i=0; i<20000; i++) 00183 { 00184 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); 00185 } 00186 myLCD.copy_to_lcd(); 00187 time=t.read_us(); 00188 myLCD.cls(); 00189 myLCD.FastWindow(false); 00190 t.reset(); 00191 for(unsigned int i=0; i<20000; i++) 00192 { 00193 myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); 00194 } 00195 myLCD.copy_to_lcd(); 00196 time2=t.read_us(); 00197 myLCD.locate(2,55); 00198 myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000); 00199 pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); 00200 wait(3); 00201 // scroll test, only for TFT 00202 myLCD.cls(); 00203 myLCD.set_font((unsigned char*) Arial24x23); 00204 myLCD.locate(2,10); 00205 myLCD.printf("Scrolling"); 00206 myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); 00207 myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); 00208 myLCD.setscrollarea(0,myLCD.sizeY()); 00209 wait(1); 00210 myLCD.scroll(1); //up 1 00211 wait(1); 00212 myLCD.scroll(0); //center 00213 wait(1); 00214 myLCD.scroll(myLCD.sizeY()-1); //down 1 00215 wait(1); 00216 myLCD.scroll(myLCD.sizeY()); // same as 0, center 00217 wait(1); 00218 myLCD.scroll(myLCD.sizeY()>>1); // half screen 00219 wait(1); 00220 myLCD.scrollreset(); // center 00221 wait(1); 00222 for(unsigned short i=1; i<=myLCD.sizeY(); i++) 00223 { 00224 myLCD.scroll(i); 00225 wait_ms(2); 00226 } 00227 wait(2); 00228 // color inversion 00229 for(unsigned short i=0; i<=8; i++) 00230 { 00231 myLCD.invert(i&1); 00232 wait_ms(200); 00233 } 00234 wait(2); 00235 // bmp 16bit test 00236 myLCD.cls(); 00237 t.reset(); 00238 for(int y=0; y<myLCD.height(); y+=34) 00239 { 00240 for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); 00241 } 00242 time=t.read_us(); 00243 myLCD.locate(2,55); 00244 myLCD.set_font((unsigned char*) Terminal6x8); 00245 myLCD.printf("Bmp speed: %.3fms", (float)time/1000); 00246 pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); 00247 wait(2); 00248 } 00249 }
Generated on Sat Jul 23 2022 11:15:12 by
1.7.2
