![](/media/cache/profiles/1507328878-06df007af8a6781c2780dd187c29374a-.jpeg.50x50_q85.jpg)
speedtest
Fork of Nucleo_UniGraphic_demo by
main.cpp@4:818956c30cae, 2015-02-23 (annotated)
- Committer:
- Geremia
- Date:
- Mon Feb 23 23:40:04 2015 +0000
- Revision:
- 4:818956c30cae
- Parent:
- 3:65af1a9fedda
- Child:
- 5:c69049e461b7
added 16bit bitmap test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 0:2ccd65a72ab8 | 1 | #include "stdio.h" |
Geremia | 0:2ccd65a72ab8 | 2 | #include "mbed.h" |
Geremia | 0:2ccd65a72ab8 | 3 | #include "string" |
Geremia | 0:2ccd65a72ab8 | 4 | #include "Arial12x12.h" |
Geremia | 0:2ccd65a72ab8 | 5 | #include "Arial24x23.h" |
Geremia | 0:2ccd65a72ab8 | 6 | //#include "Terminal6x8.h" |
Geremia | 0:2ccd65a72ab8 | 7 | #include "Arial43x48_numb.h" |
Geremia | 0:2ccd65a72ab8 | 8 | #include "pict.h" |
Geremia | 4:818956c30cae | 9 | #include "pavement_48x34.h" |
Geremia | 0:2ccd65a72ab8 | 10 | |
Geremia | 1:083257298075 | 11 | //#include "IST3020.h" |
Geremia | 0:2ccd65a72ab8 | 12 | //#include "UC1608.h" |
Geremia | 2:2b781c215ac0 | 13 | #include "ILI9341.h" |
Geremia | 2:2b781c215ac0 | 14 | //#include "ILI9486.h" |
Geremia | 2:2b781c215ac0 | 15 | //#include "TFT_MIPI.h" |
Geremia | 4:818956c30cae | 16 | //#include "SSD1306.h" |
Geremia | 0:2ccd65a72ab8 | 17 | |
Geremia | 0:2ccd65a72ab8 | 18 | Serial pc(USBTX, USBRX); |
Geremia | 0:2ccd65a72ab8 | 19 | |
Geremia | 4:818956c30cae | 20 | //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 |
Geremia | 4:818956c30cae | 21 | //UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 4:818956c30cae | 22 | ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 4:818956c30cae | 23 | //ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, A0, WR, RD for F401 |
Geremia | 4:818956c30cae | 24 | //ILI9486 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, A0, WR, RD for F401 |
Geremia | 4:818956c30cae | 25 | //TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, A0, WR, RD for F401 |
Geremia | 4:818956c30cae | 26 | //SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc |
Geremia | 0:2ccd65a72ab8 | 27 | |
Geremia | 0:2ccd65a72ab8 | 28 | Timer t; |
Geremia | 0:2ccd65a72ab8 | 29 | |
Geremia | 0:2ccd65a72ab8 | 30 | unsigned short backgroundcolor=Black; |
Geremia | 0:2ccd65a72ab8 | 31 | unsigned short foregroundcolor=White; |
Geremia | 0:2ccd65a72ab8 | 32 | |
Geremia | 0:2ccd65a72ab8 | 33 | char orient=1; |
Geremia | 0:2ccd65a72ab8 | 34 | int main() |
Geremia | 0:2ccd65a72ab8 | 35 | { |
Geremia | 4:818956c30cae | 36 | // myLCD.set_contrast(26);//for uc1608 |
Geremia | 4:818956c30cae | 37 | // myLCD.set_contrast(46);//for ist3020 |
Geremia | 4:818956c30cae | 38 | myLCD.set_orientation(orient); |
Geremia | 3:65af1a9fedda | 39 | int time, time2; |
Geremia | 0:2ccd65a72ab8 | 40 | pc.baud (115200); |
Geremia | 0:2ccd65a72ab8 | 41 | pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); |
Geremia | 0:2ccd65a72ab8 | 42 | t.start(); |
Geremia | 0:2ccd65a72ab8 | 43 | |
Geremia | 4:818956c30cae | 44 | // myLCD.claim(stdout); // send stdout to the LCD display |
Geremia | 4:818956c30cae | 45 | //myLCD.claim(stderr); // send stderr to the LCD display |
Geremia | 4:818956c30cae | 46 | myLCD.background(backgroundcolor); // set background to black |
Geremia | 4:818956c30cae | 47 | myLCD.foreground(foregroundcolor); // set chars to white |
Geremia | 4:818956c30cae | 48 | myLCD.cls(); // clear the screen |
Geremia | 4:818956c30cae | 49 | // myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 50 | myLCD.locate(0,30); |
Geremia | 4:818956c30cae | 51 | myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 4:818956c30cae | 52 | pc.printf("Display ID: %.8X\r\n", myLCD.tftID); |
Geremia | 0:2ccd65a72ab8 | 53 | // mem write/read test |
Geremia | 0:2ccd65a72ab8 | 54 | unsigned short readback; |
Geremia | 4:818956c30cae | 55 | unsigned short colorstep = (0x10000/myLCD.width()); |
Geremia | 4:818956c30cae | 56 | for(unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 1:083257298075 | 57 | { |
Geremia | 4:818956c30cae | 58 | myLCD.pixel(i,0,i*colorstep); // write line |
Geremia | 1:083257298075 | 59 | } |
Geremia | 1:083257298075 | 60 | bool readerror=false; |
Geremia | 4:818956c30cae | 61 | for(unsigned short i=0; i<myLCD.width(); i++) // verify line |
Geremia | 0:2ccd65a72ab8 | 62 | { |
Geremia | 4:818956c30cae | 63 | readback = myLCD.pixelread(i,0); |
Geremia | 1:083257298075 | 64 | if(readback!=i*colorstep) |
Geremia | 1:083257298075 | 65 | { |
Geremia | 1:083257298075 | 66 | readerror=true; |
Geremia | 1:083257298075 | 67 | pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); |
Geremia | 1:083257298075 | 68 | } |
Geremia | 0:2ccd65a72ab8 | 69 | } |
Geremia | 4:818956c30cae | 70 | myLCD.locate(0,10); |
Geremia | 4:818956c30cae | 71 | myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); |
Geremia | 1:083257298075 | 72 | wait(2); |
Geremia | 1:083257298075 | 73 | |
Geremia | 0:2ccd65a72ab8 | 74 | |
Geremia | 0:2ccd65a72ab8 | 75 | |
Geremia | 0:2ccd65a72ab8 | 76 | while(1) |
Geremia | 0:2ccd65a72ab8 | 77 | { |
Geremia | 4:818956c30cae | 78 | myLCD.set_orientation((orient++)%4); |
Geremia | 4:818956c30cae | 79 | // myLCD.set_orientation(2); |
Geremia | 4:818956c30cae | 80 | myLCD.cls(); |
Geremia | 4:818956c30cae | 81 | myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled |
Geremia | 4:818956c30cae | 82 | myLCD.locate(0,0); |
Geremia | 4:818956c30cae | 83 | myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly 00__"); |
Geremia | 4:818956c30cae | 84 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 85 | // myLCD.locate(0,0); |
Geremia | 4:818956c30cae | 86 | myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly 00__"); |
Geremia | 0:2ccd65a72ab8 | 87 | pc.printf(" Display Test \r\n"); |
Geremia | 0:2ccd65a72ab8 | 88 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 89 | t.reset(); |
Geremia | 4:818956c30cae | 90 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 91 | time=t.read_us(); |
Geremia | 4:818956c30cae | 92 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 93 | myLCD.printf("cls: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 94 | pc.printf("cls: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 95 | wait(3); |
Geremia | 4:818956c30cae | 96 | |
Geremia | 4:818956c30cae | 97 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 98 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 99 | // draw some graphics |
Geremia | 4:818956c30cae | 100 | //myLCD.cls(); |
Geremia | 4:818956c30cae | 101 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 4:818956c30cae | 102 | myLCD.locate(10,10); |
Geremia | 4:818956c30cae | 103 | myLCD.printf("Test"); |
Geremia | 0:2ccd65a72ab8 | 104 | |
Geremia | 4:818956c30cae | 105 | myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); |
Geremia | 4:818956c30cae | 106 | myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); |
Geremia | 4:818956c30cae | 107 | myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 108 | |
Geremia | 4:818956c30cae | 109 | myLCD.rect(10,30,50,40,foregroundcolor); |
Geremia | 4:818956c30cae | 110 | myLCD.fillrect(60,30,100,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 111 | |
Geremia | 4:818956c30cae | 112 | myLCD.circle(150,32,30,foregroundcolor); |
Geremia | 4:818956c30cae | 113 | myLCD.fillcircle(140,20,10,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 114 | |
Geremia | 0:2ccd65a72ab8 | 115 | double s; |
Geremia | 0:2ccd65a72ab8 | 116 | |
Geremia | 4:818956c30cae | 117 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 118 | { |
Geremia | 0:2ccd65a72ab8 | 119 | s =10 * sin((long double) i / 10 ); |
Geremia | 4:818956c30cae | 120 | myLCD.pixel(i,40 + (int)s ,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 121 | } |
Geremia | 0:2ccd65a72ab8 | 122 | |
Geremia | 0:2ccd65a72ab8 | 123 | |
Geremia | 0:2ccd65a72ab8 | 124 | time=t.read_us(); |
Geremia | 4:818956c30cae | 125 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 126 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 127 | myLCD.printf("plot: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 128 | pc.printf("plot: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 129 | wait(3); |
Geremia | 4:818956c30cae | 130 | myLCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 131 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 132 | Bitmap_s pic = { |
Geremia | 0:2ccd65a72ab8 | 133 | 64, // XSize |
Geremia | 0:2ccd65a72ab8 | 134 | 64, // YSize |
Geremia | 0:2ccd65a72ab8 | 135 | 8, // Bytes in Line |
Geremia | 0:2ccd65a72ab8 | 136 | burp, // Pointer to picture data |
Geremia | 0:2ccd65a72ab8 | 137 | }; |
Geremia | 4:818956c30cae | 138 | myLCD.Bitmap_BW(pic,myLCD.width()-64,0); |
Geremia | 0:2ccd65a72ab8 | 139 | time=t.read_us(); |
Geremia | 4:818956c30cae | 140 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 141 | myLCD.printf("bmp: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 142 | pc.printf("bmp: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 143 | wait(3); |
Geremia | 4:818956c30cae | 144 | myLCD.cls(); |
Geremia | 4:818956c30cae | 145 | myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled |
Geremia | 0:2ccd65a72ab8 | 146 | t.reset(); |
Geremia | 4:818956c30cae | 147 | myLCD.locate(0,0); |
Geremia | 4:818956c30cae | 148 | myLCD.printf("%d", 12345); |
Geremia | 0:2ccd65a72ab8 | 149 | time=t.read_us(); |
Geremia | 4:818956c30cae | 150 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 151 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 152 | myLCD.printf("Big Font speed: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 153 | pc.printf("Big Font speed: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 154 | wait(3); |
Geremia | 3:65af1a9fedda | 155 | // sparse pixels test |
Geremia | 4:818956c30cae | 156 | myLCD.cls(); |
Geremia | 4:818956c30cae | 157 | myLCD.FastWindow(true); |
Geremia | 3:65af1a9fedda | 158 | t.reset(); |
Geremia | 3:65af1a9fedda | 159 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 160 | { |
Geremia | 4:818956c30cae | 161 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 162 | } |
Geremia | 4:818956c30cae | 163 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 164 | time=t.read_us(); |
Geremia | 4:818956c30cae | 165 | myLCD.cls(); |
Geremia | 4:818956c30cae | 166 | myLCD.FastWindow(false); |
Geremia | 3:65af1a9fedda | 167 | t.reset(); |
Geremia | 3:65af1a9fedda | 168 | for(unsigned int i=0; i<20000; i++) |
Geremia | 3:65af1a9fedda | 169 | { |
Geremia | 4:818956c30cae | 170 | myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); |
Geremia | 3:65af1a9fedda | 171 | } |
Geremia | 4:818956c30cae | 172 | myLCD.copy_to_lcd(); |
Geremia | 3:65af1a9fedda | 173 | time2=t.read_us(); |
Geremia | 4:818956c30cae | 174 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 175 | myLCD.printf("std: %.3fms fastw: %.3fms", (float)time2/1000, (float)time/1000); |
Geremia | 4:818956c30cae | 176 | pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); |
Geremia | 3:65af1a9fedda | 177 | wait(3); |
Geremia | 2:2b781c215ac0 | 178 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 179 | myLCD.cls(); |
Geremia | 4:818956c30cae | 180 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 4:818956c30cae | 181 | myLCD.locate(10,10); |
Geremia | 4:818956c30cae | 182 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 183 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 184 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 185 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 186 | wait(1); |
Geremia | 4:818956c30cae | 187 | myLCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 188 | wait(1); |
Geremia | 4:818956c30cae | 189 | myLCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 190 | wait(1); |
Geremia | 4:818956c30cae | 191 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 192 | wait(1); |
Geremia | 4:818956c30cae | 193 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 194 | wait(1); |
Geremia | 4:818956c30cae | 195 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 196 | wait(1); |
Geremia | 4:818956c30cae | 197 | myLCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 198 | wait(1); |
Geremia | 4:818956c30cae | 199 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 200 | { |
Geremia | 4:818956c30cae | 201 | myLCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 202 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 203 | } |
Geremia | 2:2b781c215ac0 | 204 | wait(2); |
Geremia | 2:2b781c215ac0 | 205 | // color inversion |
Geremia | 2:2b781c215ac0 | 206 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 207 | { |
Geremia | 4:818956c30cae | 208 | myLCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 209 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 210 | } |
Geremia | 2:2b781c215ac0 | 211 | wait(2); |
Geremia | 4:818956c30cae | 212 | // bmp 16bit test |
Geremia | 4:818956c30cae | 213 | myLCD.cls(); |
Geremia | 4:818956c30cae | 214 | t.reset(); |
Geremia | 4:818956c30cae | 215 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 216 | { |
Geremia | 4:818956c30cae | 217 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 218 | } |
Geremia | 4:818956c30cae | 219 | time=t.read_us(); |
Geremia | 4:818956c30cae | 220 | myLCD.locate(2,55); |
Geremia | 4:818956c30cae | 221 | myLCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 4:818956c30cae | 222 | myLCD.printf("Bmp speed: %.3fms", (float)time/1000); |
Geremia | 4:818956c30cae | 223 | pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); |
Geremia | 4:818956c30cae | 224 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 225 | } |
Geremia | 0:2ccd65a72ab8 | 226 | } |