![](/media/cache/profiles/1507328878-06df007af8a6781c2780dd187c29374a-.jpeg.50x50_q85.jpg)
speedtest
Fork of Nucleo_UniGraphic_demo by
main.cpp@2:2b781c215ac0, 2015-02-17 (annotated)
- Committer:
- Geremia
- Date:
- Tue Feb 17 11:06:11 2015 +0000
- Revision:
- 2:2b781c215ac0
- Parent:
- 1:083257298075
- Child:
- 3:65af1a9fedda
added scroll test for tft
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 | 1:083257298075 | 18 | //IST3020 LCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"LCD"); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302 |
Geremia | 1:083257298075 | 19 | //UC1608 LCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"LCD"); // 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 | 0:2ccd65a72ab8 | 35 | int time; |
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 | 0:2ccd65a72ab8 | 76 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 77 | LCD.locate(0,0); |
Geremia | 0:2ccd65a72ab8 | 78 | LCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); |
Geremia | 0:2ccd65a72ab8 | 79 | pc.printf(" Display Test \r\n"); |
Geremia | 0:2ccd65a72ab8 | 80 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 81 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 82 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 83 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 84 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 85 | LCD.printf("cls: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 86 | pc.printf("cls: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 87 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 88 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 89 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 90 | // draw some graphics |
Geremia | 0:2ccd65a72ab8 | 91 | //LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 92 | LCD.set_font((unsigned char*) Arial24x23); |
Geremia | 0:2ccd65a72ab8 | 93 | LCD.locate(10,10); |
Geremia | 0:2ccd65a72ab8 | 94 | LCD.printf("Test"); |
Geremia | 0:2ccd65a72ab8 | 95 | |
Geremia | 0:2ccd65a72ab8 | 96 | LCD.line(0,0,LCD.width()-1,0,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 97 | LCD.line(0,0,0,LCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 98 | LCD.line(0,0,LCD.width()-1,LCD.height()-1,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 99 | |
Geremia | 0:2ccd65a72ab8 | 100 | LCD.rect(10,30,50,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 101 | LCD.fillrect(60,30,100,40,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 102 | |
Geremia | 0:2ccd65a72ab8 | 103 | LCD.circle(150,32,30,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 104 | LCD.fillcircle(140,20,10,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 105 | |
Geremia | 0:2ccd65a72ab8 | 106 | double s; |
Geremia | 0:2ccd65a72ab8 | 107 | |
Geremia | 0:2ccd65a72ab8 | 108 | for (unsigned short i=0; i<LCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 109 | { |
Geremia | 0:2ccd65a72ab8 | 110 | s =10 * sin((long double) i / 10 ); |
Geremia | 0:2ccd65a72ab8 | 111 | LCD.pixel(i,40 + (int)s ,foregroundcolor); |
Geremia | 0:2ccd65a72ab8 | 112 | } |
Geremia | 0:2ccd65a72ab8 | 113 | |
Geremia | 0:2ccd65a72ab8 | 114 | |
Geremia | 0:2ccd65a72ab8 | 115 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 116 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 117 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 118 | LCD.printf("plot: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 119 | pc.printf("plot: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 120 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 121 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 122 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 123 | Bitmap_s pic = { |
Geremia | 0:2ccd65a72ab8 | 124 | 64, // XSize |
Geremia | 0:2ccd65a72ab8 | 125 | 64, // YSize |
Geremia | 0:2ccd65a72ab8 | 126 | 8, // Bytes in Line |
Geremia | 0:2ccd65a72ab8 | 127 | burp, // Pointer to picture data |
Geremia | 0:2ccd65a72ab8 | 128 | }; |
Geremia | 0:2ccd65a72ab8 | 129 | LCD.Bitmap_BW(pic,LCD.width()-64,0); |
Geremia | 0:2ccd65a72ab8 | 130 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 131 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 132 | LCD.printf("bmp: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 133 | pc.printf("bmp: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 134 | wait(3); |
Geremia | 0:2ccd65a72ab8 | 135 | LCD.cls(); |
Geremia | 0:2ccd65a72ab8 | 136 | LCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled |
Geremia | 0:2ccd65a72ab8 | 137 | t.reset(); |
Geremia | 0:2ccd65a72ab8 | 138 | LCD.locate(0,0); |
Geremia | 0:2ccd65a72ab8 | 139 | LCD.printf("%d", 12345); |
Geremia | 0:2ccd65a72ab8 | 140 | time=t.read_us(); |
Geremia | 0:2ccd65a72ab8 | 141 | LCD.locate(2,55); |
Geremia | 0:2ccd65a72ab8 | 142 | LCD.set_font((unsigned char*) Terminal6x8); |
Geremia | 0:2ccd65a72ab8 | 143 | LCD.printf("Big Font speed: %.3fms", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 144 | pc.printf("Big Font speed: %.3fms\r\n", (float)time/1000); |
Geremia | 0:2ccd65a72ab8 | 145 | wait(3); |
Geremia | 2:2b781c215ac0 | 146 | // scroll test, only for TFT |
Geremia | 2:2b781c215ac0 | 147 | LCD.cls(); |
Geremia | 2:2b781c215ac0 | 148 | LCD.set_font((unsigned char*) Arial24x23); |
Geremia | 2:2b781c215ac0 | 149 | LCD.locate(10,10); |
Geremia | 2:2b781c215ac0 | 150 | LCD.printf("Scrolling"); |
Geremia | 2:2b781c215ac0 | 151 | LCD.rect(0,0,LCD.width()-1,LCD.height()-1,White); |
Geremia | 2:2b781c215ac0 | 152 | LCD.rect(1,1,LCD.width()-2,LCD.height()-2,Blue); |
Geremia | 2:2b781c215ac0 | 153 | LCD.setscrollarea(0,LCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 154 | wait(1); |
Geremia | 2:2b781c215ac0 | 155 | LCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 156 | wait(1); |
Geremia | 2:2b781c215ac0 | 157 | LCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 158 | wait(1); |
Geremia | 2:2b781c215ac0 | 159 | LCD.scroll(LCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 160 | wait(1); |
Geremia | 2:2b781c215ac0 | 161 | LCD.scroll(LCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 162 | wait(1); |
Geremia | 2:2b781c215ac0 | 163 | LCD.scroll(LCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 164 | wait(1); |
Geremia | 2:2b781c215ac0 | 165 | LCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 166 | wait(1); |
Geremia | 2:2b781c215ac0 | 167 | for(unsigned short i=1; i<=LCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 168 | { |
Geremia | 2:2b781c215ac0 | 169 | LCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 170 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 171 | } |
Geremia | 2:2b781c215ac0 | 172 | wait(2); |
Geremia | 2:2b781c215ac0 | 173 | // color inversion |
Geremia | 2:2b781c215ac0 | 174 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 175 | { |
Geremia | 2:2b781c215ac0 | 176 | LCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 177 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 178 | } |
Geremia | 2:2b781c215ac0 | 179 | wait(2); |
Geremia | 2:2b781c215ac0 | 180 | |
Geremia | 0:2ccd65a72ab8 | 181 | } |
Geremia | 0:2ccd65a72ab8 | 182 | } |