Pages: 1 2 [3] 4   Go Down
Author Topic: High speed vector graphics engine. 3.2" TFT Lcd screen.  (Read 19559 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Edison Member
*
Karma: 37
Posts: 1009
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mael hello, can you share your optimised library please? smiley-kitty
« Last Edit: March 27, 2013, 12:24:37 am by guix » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is my bench sketch :

Code:
//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.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is Icon.h

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

* icon.h (9.33 KB - downloaded 114 times.)
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :

Code:
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  smiley-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. smiley

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

bye.
Maël.

* UTFT.zip (161.08 KB - downloaded 160 times.)
« Last Edit: March 27, 2013, 09:15:50 am by Mael » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi meal,

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



Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

your the best Mael,

t'es le meilleur smiley-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
« Last Edit: March 27, 2013, 03:23:48 pm by vincent13 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Salut Vincent,
Les forums internationaux sont souvent plus intéressant et riches, en plus ils nous font bosser notre anglais smiley-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 ? smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* before.jpg (614.69 KB, 2036x1151 - viewed 203 times.)

* after.jpg (587.31 KB, 1903x1016 - viewed 145 times.)

* bench.JPG (1213.54 KB, 2432x1585 - viewed 121 times.)
« Last Edit: March 28, 2013, 05:04:09 am by Rivinoo » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :
Code:
#define pulse_low_WR PORTG &= ~(1<<2); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); PORTG |= (1<<2)
by it :
Code:
#define pulse_low_WR PORTG &= ~(1<<2); delayMicroseconds(1); PORTG |= (1<<2)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:[table border=1]
Original UTFT:  Mael modification:
21218 us13207 us

Thank you!
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1848
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

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

Code:
__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.
« Last Edit: March 28, 2013, 11:19:05 am by MichaelMeissner » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

we are looking for pyro  smiley-sleep
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 It is nice to see all the work being put to this screen! Thanks!
Logged


Pages: 1 2 [3] 4   Go Up
Jump to: