Simple program for the RETRO to compare the performance of the DisplayN18 and LCD_ST7735 libraries.

Dependencies:   LCD_ST7735 mbed

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!

Revision:
0:59d6b70df5a4
Child:
1:e3193760dd98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jan 16 19:18:45 2015 +0000
@@ -0,0 +1,186 @@
+////////////////////////
+//
+// Simple program 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);
+
+    // 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);
+
+    // 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, i, 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);
+
+    // 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);
+
+    // 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, i, 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();
+    
+    DigitalOut led1(P0_9, false);
+
+    while (true) {
+        led1 = !led1;
+        wait(.5);
+    }
+
+}