Simple program for the RETRO to compare the performance of the DisplayN18 and LCD_ST7735 libraries.
This is a very simple program for the RETRO to compare the performance of some of the primitives of the DisplayN18 and LCD_ST7735 libraries
WARNING - WARNING - WARNING
If you're sensitive to ugly coding techniques, lack of best practice, ignorance of proper design patterns, abuse of object orientation or to total disregards of any coding guidelines, then don't - I repeat - DON'T look at this code...
P.S. Regardless the performance, I do think the N18 library has a much nicer font!
main.cpp
- Committer:
- maxint
- Date:
- 2015-01-16
- Revision:
- 1:e3193760dd98
- Parent:
- 0:59d6b70df5a4
- Child:
- 2:dcf8e6db342d
File content as of revision 1:e3193760dd98:
//////////////////////// // // Simple program for the RETRO to compare the performance of the DisplayN18 and LCD_ST7735 libraries // /////////////////////// #include "mbed.h" #include "DisplayN18.h" #include "Color565.h" #include "font_IBM.h" #include "LCD_ST7735.h" int testDisplayN18() { // test N18 library functions DisplayN18 disp; Timer tPerformance; // timer used for measuring performance char buf[256]; int iPerfMs=0; int iStartUs=0; tPerformance.start(); // start the timer // text iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"drawString..."); for(int i=1; i<100; i++) { disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, i, buf, DisplayN18::GREEN, DisplayN18::BLACK); } sprintf(buf,"drawString:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); // rectangles iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"drawRect..."); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK); for(int i=1; i<100; i++) { disp.drawRect(0, 0, i, i, DisplayN18::GREEN); } sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); // filled rectangles iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"fillRect..."); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK); for(int i=1; i<100; i+=2) { disp.fillRect(0, 0, i, i, DisplayN18::GREEN); } sprintf(buf,"fillRect:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); // circles iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"drawCircle..."); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK); for(int i=1; i<100; i++) { disp.drawCircle(i, i, i/2, DisplayN18::GREEN); } sprintf(buf,"drawCircle:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); // filled circles iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"fillCircle..."); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK); for(int i=1; i<100; i+=2) { disp.fillCircle(i, i, i/2, DisplayN18::GREEN); } sprintf(buf,"fillCircle:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); // lines iStartUs=tPerformance.read_us(); disp.clear(); sprintf(buf,"drawLine..."); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK); for(int i=1; i<100; i++) { disp.drawLine(0, 0, i, 100, DisplayN18::GREEN); } sprintf(buf,"drawLine:%u ", tPerformance.read_us()-iStartUs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); iPerfMs+=tPerformance.read_ms(); wait(0.5); disp.clear(); sprintf(buf,"Total:%u ms", iPerfMs); disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) * strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); wait(2); return(iPerfMs); } int testDisplayST7735() { // test ST7735 library functions LCD_ST7735 disp( P0_19, P0_20, P0_7, P0_21, P0_22, P1_15, P0_2, LCD_ST7735::RGB); Timer tPerformance; // timer used for measuring performance char buf[256]; int iPerfMs=0; int iStartUs=0; tPerformance.start(); // start the timer disp.setOrientation(LCD_ST7735::Rotate270, false); disp.setForegroundColor(Color565::White); disp.setBackgroundColor(Color565::Blue); disp.clearScreen(); // text iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"drawString..."); for(int i=1; i<100; i++) { //disp.drawString(font_ibm, disp.getWidth / 2 - (8 + 0) * strlen(buf) / 2, i, buf); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, i, buf); } sprintf(buf,"drawString:%u ", tPerformance.read_us()-iStartUs); //disp.drawString(font_ibm, disp.getWidth / 2 - (8 + 0) * strlen(buf) / 2, disp.getHeight-8, buf); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); // rectangles iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"drawRect..."); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf); for(int i=1; i<100; i++) { disp.drawRect(0, 0, i, i, Color565::Blue); } sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); // filled rectangles iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"drawRect..."); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf); for(int i=1; i<100; i+=2) { disp.fillRect(0, 0, i, i, Color565::Yellow, Color565::Blue); } sprintf(buf,"drawRect:%u ", tPerformance.read_us()-iStartUs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); // circles iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"drawCircle..."); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf); for(int i=1; i<100; i++) { disp.drawCircle(i, i, i/2, Color565::Blue); } sprintf(buf,"drawCircle:%u ", tPerformance.read_us()-iStartUs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); // filled circles iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"fillCircle..."); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf); for(int i=1; i<100; i+=2) { disp.fillCircle(i, i, i/2, Color565::Yellow, Color565::Blue); } sprintf(buf,"fillCircle:%u ", tPerformance.read_us()-iStartUs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); // lines iStartUs=tPerformance.read_us(); disp.clearScreen(); sprintf(buf,"drawLine..."); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 0, buf); for(int i=1; i<100; i++) { disp.drawLine(0, 0, i, 100, Color565::Blue); } sprintf(buf,"drawLine:%u ", tPerformance.read_us()-iStartUs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); iPerfMs+=tPerformance.read_ms(); wait(0.5); disp.clearScreen(); sprintf(buf,"Total:%u ms", iPerfMs); disp.drawString(font_ibm, 160 / 2 - (8 + 0) * strlen(buf) / 2, 128-8, buf); wait(2); return(iPerfMs); } main() { int iDisplayN18=testDisplayN18(); int iDisplayST7735=testDisplayST7735(); char buf[256]; DisplayN18 disp; disp.clear(); sprintf(buf,"Totals --->"); disp.drawString(0, 0, buf, DisplayN18::WHITE, DisplayN18::BLACK); sprintf(buf,"N18: %u ms", iDisplayN18); disp.drawString(0, DisplayN18::CHAR_HEIGHT, buf, DisplayN18::GREEN, DisplayN18::BLACK); sprintf(buf,"ST7735: %u ms", iDisplayST7735); disp.drawString(0, 2*DisplayN18::CHAR_HEIGHT, buf, DisplayN18::BLUE, DisplayN18::BLACK); DigitalOut led1(P0_9, false); DigitalOut led2(P0_8, true); while (true) { led1 = !led1; led2 = !led2; wait(.5); } }