High speed vector graphics engine. 3.2" TFT Lcd screen.

news?

blackmaster:
news?

Some news ????

I'm waiting for this "Library Mod" !! 8)

dead

pYro, you gave up, or.. ? :slight_smile:

vincent13:
hi mael,

already done on my side to clean all the unnecessary code in UTFT :smiley:

but still far of what this post promise .

Hi Vincent13,
I coded a workbench to compare my optimizations with the original version.
Here are my results :

start...
Initial version time - optimized version time - opération
724576 us     - 37248 us   : clrScr
200 us        - 24 us      : DrawPixel
2020 us       - 232 us     : DrawPixel x 10
4 us          - 4          : SetColor
4 us          - 4          : SetBackColor
19856 us      - 5804 us    : FillRoundRect 40x40
2652 us       - 636 us     : DrawRoundRect 40x40
4928 us       - 916 us     : drawLine 40x40
604 us        - 152 us     : draw Vertical Line 40
612 us        - 144 us     : draw Horizontal Line 40
27836 us      - 1480 us    : FillRect 40x40
8 us          - 8          : SetSmallFont
7764 us       - 2300 us    : Print 001
7640 us       - 2300 us    : Print Abc
7892 us       - 2580 us    : printNumI(123)
8 us          - 8          : SetBigFont
14912 us      - 4332 us    : Print 001
15048 us      - 4424 us    : printNumI(123)
11668 us      - 2412 us    : draw bitmap 32x32

Do you have better results ? (do you want my WorkBench sketch ?)

Quite impressive numbers here! Well done!

yep why not compare :wink:

give me access to your bench code using mp :sweat_smile:

Mael hello, can you share your optimised library please? :slight_smile:

This is my bench sketch :

//Bench.ino
//Maël - 01/03/2013
//Mesure le temps de différentes methodes des lib UTFT et UTouch et envoi les temps sur le port Serie (115200 bauds)

#include <UTFT.h>
#include <UTouch.h>

#include "icon.h"

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Tft, touchscreen for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41);  
UTouch myTouch(6,5,4,3,2);

extern unsigned int icon[0x400];

//pointeur de fonction simple
typedef void TFunction(void);

typedef struct  
{
  TFunction * process; //pointeur sur la methode à chronometrer
  String text;         //nom du test (apparaitra sur la console)
} TProcessInfo;

void InitTFT()
{
// Setup the LCD, touch screen
  myGLCD.InitLCD(LANDSCAPE);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW); //PREC_MEDIUM
  
  myGLCD.clrScr();
}

void MeasureDrawPixel(void)
{
  myGLCD.drawPixel(0,0);
}

void MeasureDraw10Pixels(void)
{
  for (int i = 0; i < 10; i++)
    myGLCD.drawPixel(i,i);
}

void MeasureSetColor()
{
  myGLCD.setColor(255, 255, 255);
}

void MeasureSetBackColor()
{
  myGLCD.setBackColor(64, 64, 64);
}

void MeasureFillRoundRect()
{
  myGLCD.fillRoundRect(10, 10, 50, 50);
}

void MeasureDrawRoundRect()
{
  myGLCD.drawRoundRect(110, 10, 150, 50);
}

void MeasureDrawLine()
{
  myGLCD.drawLine(210, 10, 250, 50);
}

void MeasureDrawVLine()
{
  myGLCD.drawLine(270, 10, 270, 50);
}

void MeasureDrawHLine()
{
  myGLCD.drawLine(230, 20, 270, 20);
}

void MeasureFillRect()
{
  myGLCD.fillRect(100, 100, 50, 150);
}

void MeasureSetSmallFont()
{
  myGLCD.setFont(SmallFont);
}

void MeasurePrintText()
{
  myGLCD.print("001", 1, 1);    
}

void MeasurePrintTextAbc()
{
  myGLCD.print("Abc", 1, 1);    
}

void MeasureSetBigFont()
{
  myGLCD.setFont(BigFont);
}

void MeasureclrScr()
{
  myGLCD.clrScr();
}

void MeasureBitmap()
{
 myGLCD.drawBitmap (200, 10, 32, 32, icon);
}

void MeasurePrintNum()
{
  int num = 123;
  myGLCD.printNumI(num, 200, 100);
}

void MeasureTouch_dataAvailable()
{
  boolean b = myTouch.dataAvailable();
}

void MeasureTouch_read()
{
  myTouch.read();
}

void MeasureTouch_getxy()
{
  int x=myTouch.getX();
  int y=myTouch.getY();
}

//Liste des méthodes à mesurer
#define LIST_COUNT 22
TProcessInfo ListOfMeasures[LIST_COUNT] = {
  { MeasureclrScr, "clrScr" },
  { MeasureDrawPixel, "DrawPixel" },
  { MeasureDraw10Pixels, "DrawPixel x 10" },
  { MeasureSetColor, "SetColor" },
  { MeasureSetBackColor, "SetBackColor" },
  { MeasureFillRoundRect, "FillRoundRect 40x40" },
  { MeasureDrawRoundRect, "DrawRoundRect 40x40" },
  { MeasureDrawLine, "drawLine 40x40" },
  { MeasureDrawVLine, "draw Vertical Line 40" },
  { MeasureDrawHLine, "draw Horizontal Line 40" },
  { MeasureFillRect, "FillRect 40x40" },
  { MeasureSetSmallFont, "SetSmallFont" },
  { MeasurePrintText, "Print 001" },
  { MeasurePrintTextAbc, "Print Abc" },
  { MeasurePrintNum, "printNumI(123)" },
  { MeasureSetBigFont, "SetBigFont" },
  { MeasurePrintText, "Print 001" },
  { MeasurePrintNum, "printNumI(123)" },
  { MeasureBitmap, "draw bitmap 32x32" },
  //Mesure des optimisations sur UTouch (en debogage)
  { MeasureTouch_dataAvailable, "Touch Screen DataAvailable"},
  { MeasureTouch_read, "Touch Screen Read"},
  { MeasureTouch_getxy, "Touch Screen getX, getY"}
  };

void Measure()
{
  Serial.println("start...");
  unsigned long ChronoAll = micros();
  for (int i = 0; i < LIST_COUNT; i++)
  {
    if ( ListOfMeasures[i].process != NULL)
    {
      unsigned long ChronoOne = micros();
      ListOfMeasures[i].process();
      ChronoOne = micros() - ChronoOne;
      Serial.print(ChronoOne, DEC);
      Serial.print(" us : ");
      Serial.println(ListOfMeasures[i].text);
    }
  }
  ChronoAll = micros() - ChronoAll;
  Serial.print("finish in ");
  Serial.print(ChronoAll, DEC);
  Serial.println(" us.");
}

void setup()
{
  Serial.begin(115200);
  Serial.println("ready.");
  InitTFT();
  
  Measure();
}

void loop()
{
}

Maël.

this is Icon.h

And I'm preparing a zip archive of my UTFT version.
Maël.

icon.h (9.33 KB)

Here is my UTFT version with optimizations speed of execution and ROM space used.

BE CAREFUL : It's work only with SSD1289 screen on Arduino Mega.
Screen : SainSmart 3.2" TFT LCD Display+Touch Panel+PCB adapter SD Slot for Arduino 2560,
Shield : SainSmart TFT LCD Adjustable Shield for Arduino Mega 2560 R3 1280 A082 Plug.

To optimize I examined the most frequently used functions.
For example:
drawPixel calls SetXY, SetXY makes a test on the target screen and calls LCD_Write_COM, it calls LCD_Write_COM and LCD_Write_DATA, they test the type of transfer and call LCD_Writ_Bus. LCD_Writ_Bus tests the type of target screen and then writes the data to the destination ports of the screen !!!
LCDxxx methods are called very often then it is they need to optimize.
I remove the tests "switch (mode)" or "if (display_transfer_mode! = 1)", which become useless if I still have the same screen.
I'm simplifying and removing cascades calls are expensive (passing parameters to the stack, context switching, etc.).

In the zip archive, I put a new example : Bench.ino (use this one to test), I removed some tools.

I also made a mode "x terminal" which sending display information to the serial port.
I wrote a program (in C #) that runs on the PC, he receives display information and draws on the PC screen: this is a simulator screen.
I left this feature in the code archive. It is off by a compiler directive (so this code is disabled).
Example :

void UTFT::drawPixel(int x, int y)
{
//don't worry about this code. this code is not compiled (Terminal_x not defined)
#ifdef TERMINAL_X
  //terminal x
  //0x81 [ID], [size], [datas]  
  uint8_t Trame[7];
  Trame[0] = 0x81; //ID de Terminal X
  Trame[1] = sizeof(Trame)-1; //taille de la sous-trame (à partir de cet endroit, on compte la size mais pas l'ID termX
  Trame[2] = TX_DRAWPIXEL; //ID ordre d'aff pixel
  Trame[3] = x >> 8; //MSB x1
  Trame[4] = x; //LSB x1
  Trame[5] = y >> 8;
  Trame[6] = y; 
  Serial.write(Trame, sizeof(Trame));
  //return;
#endif
...

If anyone is interested, I can share my C # program...
I preferred share code in the current state, because if I take the time to clean it before, it will never be perfect and finally I will send nothing :wink:

Finally, Perhaps the best is make a depot GIT.
I hope that pYro_65 will could give us his optimizations or ideas for a common version. :slight_smile:

(Sorry if I speak bad English, I took lessons :wink: )

bye.
Maël.

UTFT.zip (161 KB)

Hi meal,

french too :wink:
To run successfully, I need icon.h also :wink:

your the best Mael,

t'es le meilleur :wink:

ready.
start...
531340 us : clrScr
96 us : DrawPixel
884 us : DrawPixel x 10
4 us : SetColor
4 us : SetBackColor
8388 us : FillRoundRect 40x40
1128 us : DrawRoundRect 40x40
2776 us : drawLine 40x40
256 us : draw Vertical Line 40
256 us : draw Horizontal Line 40
11524 us : FillRect 40x40
8 us : SetSmallFont
4772 us : Print 001
4648 us : Print Abc
4900 us : printNumI(123)
8 us : SetBigFont
9592 us : Print 001
9724 us : printNumI(123)
6416 us : draw bitmap 32x32
28 us : Touch Screen DataAvailable
960 us : Touch Screen Read
116 us : Touch Screen getX, getY
finish in 611364 us

original lib scores :

ready.
start...
114588 us : clrScr
212 us : DrawPixel
2064 us : DrawPixel x 10
12 us : SetColor
8 us : SetBackColor
14408 us : FillRoundRect 40x40
2240 us : DrawRoundRect 40x40
4160 us : drawLine 40x40
468 us : draw Vertical Line 40
464 us : draw Horizontal Line 40
4364 us : FillRect 40x40
8 us : SetSmallFont
7396 us : Print 001
7212 us : Print Abc
7464 us : printNumI(123)
8 us : SetBigFont
13552 us : Print 001
13676 us : printNumI(123)
12040 us : draw bitmap 32x32
20 us : Touch Screen DataAvailable
968 us : Touch Screen Read
120 us : Touch Screen getX, getY
finish in 218352 us.

Salut Vincent,
Les forums internationaux sont souvent plus intéressant et riches, en plus ils nous font bosser notre anglais :wink:

I've the same result than you before I replace macros. Now I can't optimize more.
pYro_65 certainly has the best results.
pYro_65, what do you think about these times ? have you try the bench ? Are you here ? :slight_smile:

Hi Mael, I have Sainsmart kit (Arduino mega2560 + TFT Shield + 3.2" TFT Lcd screen). I replace original UTFT with yours optimized library, but it doesn't work fine.

Hi Rivinoo,

With the original lib, do you use this constructor "UTFT myGLCD(ITDB32S,38,39,40,41);" ?
Youre screen is really ITDB32S compatible ?

If it's, I think it's a timming problem.
Try this :
Edit HW_AVR_defines.h
change this line :

#define pulse_low_WR PORTG &= ~(1<<2); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); PORTG |= (1<<2)

by it :

#define pulse_low_WR PORTG &= ~(1<<2); delayMicroseconds(1); PORTG |= (1<<2)

Yes my screen is ITDB32S.
I change that line and now works very fine!

I try "UTFT_Demo_320x240" without delay(2000);

This is my result:Original UTFT: Mael modification:21218 us13207 us

Thank you!

And you can optimize :
Replace "delayMicroseconds(1);" by many "asm("nop\n\t");"
try until it's work. I need 3 nop, perhaps for you it's 4 or 5.

Mael:
And you can optimize :
Replace "delayMicroseconds(1);" by many "asm("nop\n\t");"
try until it's work. I need 3 nop, perhaps for you it's 4 or 5.

You don't need the trailing \n\t on the asm. While it is implied in the asm with no arguments, I always prefer to be explicit and use things like asm volatile ("nop"); to be clear that you don't want the compiler to optimize around the asm's. You can group multiple nops together:

__asm__ volatile ("nop\n\tnop\n\tnop\n\tnop");

Or, I tend to prefer to have instructions on separate lines:

__asm__ volatile ("nop\n\t"
                              "nop\n\t"
                              "nop\n\t"
                              "nop");

This uses the string token pasting feature that was first added in the C 1989 standard.