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