Landtiger (LPC1768) graphics LCD demo.

Dependencies:   Tiger_LCD mbed

Dependents:   Tiger_LCD

See here for more info.

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Tue Nov 06 21:39:33 2012 +0000
Parent:
1:ea0f7b1c5daf
Child:
3:2dccfa0121de
Commit message:
cpp version and graphics test

Changed in this revision

GLCD.h Show annotated file Show diff for this revision Revisions of this file
GLCD_Config.h Show annotated file Show diff for this revision Revisions of this file
GLCD_LPC1700.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GLCD.h	Sun Nov 04 18:13:01 2012 +0000
+++ b/GLCD.h	Tue Nov 06 21:39:33 2012 +0000
@@ -39,13 +39,14 @@
 #define Yellow          0xFFE0      /* 255, 255, 0   */
 #define White           0xFFFF      /* 255, 255, 255 */
 
+// GLCD Controller IDs
+#define HX8347A_ID      0x0047
 #define HX8347D_ID      0x0047
-#define HX8347A_ID      0x0047
 #define ILI9320_ID      0x9320
 #define ILI9325_ID      0x9325
-//#define ILI9328_ID      0x9328
-#define testje 0x9328
-#define ILI9328_ID 0x9328
+#define ILI9325C_ID     0x9325
+#define ILI9325D_ID     0x9325
+#define ILI9328_ID      0x9328
 #define ILI9331_ID      0x9331
 #define LGDP4531_ID     0x4531
 #define LGDP4535_ID     0x4535
@@ -57,8 +58,8 @@
 #define SSD2119_ID      0x9919  
 #define ST7781_ID       0x7783
 
-// GLCD Controlled IDs
 
+#if(0)
 /* GLCD Exported functions   */   
 extern void GLCD_Init           (void);
 extern unsigned short GLCD_DriverCode ();
@@ -66,7 +67,7 @@
 extern void GLCD_PutPixel       (unsigned int x, unsigned int y);
 extern void GLCD_SetTextColor   (unsigned short color);
 extern void GLCD_SetBackColor   (unsigned short color);
-extern void GLCD_Clear          (unsigned short color);
+extern void GLCD_clearScreen    (unsigned short color);
 extern void GLCD_DrawChar       (unsigned int x, unsigned int y, unsigned short *c);
 extern void GLCD_DisplayChar    (unsigned int ln, unsigned int col, unsigned char  c);
 extern void GLCD_DisplayString  (unsigned int ln, unsigned int col, unsigned char *s);
@@ -78,5 +79,67 @@
 extern void GLCD_drawHLine      (int x, int y, int l);
 extern void GLCD_drawVLine      (int x, int y, int l);
 extern void GLCD_drawRect       (int x1, int y1, int x2, int y2);
+#endif
+
+
+class GLCD {
+  public:
+    GLCD(void);
+    void Init           (void);
+    void WindowMax      (void);
+    void Window         (int x1, int y1, int x2, int y2);    
+    void drawPixel      (unsigned int x, unsigned int y);
+    void drawPixel      (unsigned int x, unsigned int y, unsigned short color); 
+    void drawPixel      (unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b); 
+    
+    void setColor       (unsigned short color);
+    void setColor       (uint8_t r, uint8_t g, uint8_t b);     
+    void setBackColor   (unsigned short color);
+    void setBackColor   (uint8_t r, uint8_t g, uint8_t b);     
+
+    void clearScreen    (unsigned short color);
+
+    void DrawChar       (unsigned int x, unsigned int y, unsigned short *c);
+    void DisplayChar    (unsigned int ln, unsigned int col, unsigned char  c);
+    void DisplayString  (unsigned int ln, unsigned int col, unsigned char *s);
+    void ClearLn        (unsigned int ln);
+    void Bargraph       (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val);
+    void Bitmap         (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap);
+    void Bmp            (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp);
+
+    void drawHLine      (int x, int y, int l);
+    void drawVLine      (int x, int y, int l);
+    void drawRect       (int x1, int y1, int x2, int y2);
+    void drawLine       (int x1, int y1, int x2, int y2);
+    void drawRoundRect  (int x1, int y1, int x2, int y2);
+    void fillRect       (int x1, int y1, int x2, int y2);
+    void fillRoundRect  (int x1, int y1, int x2, int y2);
+    void drawCircle     (int x, int y, int radius);
+    void fillCircle     (int x, int y, int radius);
+        
+    void lcdOff();
+    void lcdOn();
+    void setContrast(char c);
+    
+    int getDisplayXSize();
+    int getDisplayYSize();
+    unsigned short getDriverCode ();
+
+    unsigned short _textColor, _backColor;
+
+  private:
+    static __inline unsigned char lcd_send (unsigned short data);
+    static __inline unsigned short lcd_read (void);
+    static __inline void wr_cmd (unsigned char c);
+    static __inline void wr_dat (unsigned short c);
+    static __inline unsigned short rd_dat (void);
+    static __inline void wr_dat_start (void);
+    static __inline void wr_dat_stop (void);
+    static __inline void wr_dat_only (unsigned short c);
+    static __inline void wr_reg (unsigned char reg, unsigned short val);
+    static __inline unsigned short rd_reg (unsigned short reg); 
+
+    unsigned short _driverCode;
+};
 
 #endif /* _GLCD_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GLCD_Config.h	Tue Nov 06 21:39:33 2012 +0000
@@ -0,0 +1,38 @@
+// UTFT Memory Saver
+// -----------------
+//
+// Since most people have only one or possibly two different display modules a lot
+// of memory has been wasted to keep support for many unneeded controller chips.
+// You now have the option to remove this unneeded code from the library with
+// this file.
+// By disabling the controllers you don't need you can reduce the memory footprint
+// of the library by several Kb.
+//
+// Uncomment the lines for the displaycontrollers that you don't use to save
+// some flash memory by not including the init code for that particular
+// controller.
+
+#define DISABLE_HX8340B_8 1
+#define DISABLE_HX8340B_S 1
+#define DISABLE_HX8347A   1
+#define DISABLE_HX8347D   1
+#define DISABLE_HX8352A   1
+#define DISABLE_ILI9320   1
+// This single define will disable both 8bit and 16bit mode for this controller#define DISABLE_ILI9325  
+#define DISABLE_ILI9325   1
+#define DISABLE_ILI9327   1
+#define DISABLE_ILI9331   1 
+#define DISABLE_LGDP4531  1
+#define DISABLE_LGDP4535  1
+#define DISABLE_PCF8833   1
+#define DISABLE_R61505U   1
+#define DISABLE_S1D19122  1
+#define DISABLE_S6D1121   1
+#define DISABLE_SPFD5408B 1
+//#define DISABLE_SSD1289           1
+#define DISABLE_SSD1298     1
+#define DISABLE_SSD1963_480 1
+#define DISABLE_SSD1963_800 1
+#define DISABLE_SSD2119     1 
+#define DISABLE_ST7735      1
+#define DISABLE_ST7781      1
--- a/GLCD_LPC1700.cpp	Sun Nov 04 18:13:01 2012 +0000
+++ b/GLCD_LPC1700.cpp	Tue Nov 06 21:39:33 2012 +0000
@@ -1,5 +1,5 @@
 /******************************************************************************/
-/* GLCD_LPC1700 low-level Graphic LCD (320x240 pixels) for LandTiger          */
+/* GLCD::LPC1700 low-level Graphic LCD (320x240 pixels) for LandTiger          */
 /*                                                                            */
 /******************************************************************************/
 /* This file is modified from the uVision/ARM development tools.              */
@@ -11,6 +11,7 @@
 
 #include "mbed.h"
 #include "GLCD.h"
+#include "GLCD_Config.h"
 #include "Font_24x16.h"
 
 /*********************** Hardware specific configuration **********************/
@@ -66,48 +67,57 @@
 /* Pin RD setting to 0 or 1                                                   */
 #define LCD_RD(x)   ((x) ? (LPC_GPIO0->FIOSET = PIN_RD) : (LPC_GPIO0->FIOCLR = PIN_RD));
 
-
-#define swap(type, i, j) {type t = i; i = j; j = t;}
-
  
 /*---------------------------- Global variables ------------------------------*/
 
 /******************************************************************************/
-static volatile unsigned short TextColor = Black, BackColor = White;
-static unsigned short driverCode;
+//static volatile unsigned short ____textColor = Black, _______backColor = White;
+//static unsigned short ___driverCode;
 
 /************************ Local auxiliary functions ***************************/
 
+#define swap(type, i, j) {type t = i; i = j; j = t;}
+
+// rrrrrggggggbbbbb
+#define RGB24toRGB16(r,g,b) ((r & 0xF8)<<8) | ((g & 0xFC)<<3) | ((b & 0xF8)>>3)
+
+
 /*******************************************************************************
 * Delay in while loop cycles                                                   *
 *   Parameter:    cnt:    number of while cycles to delay                      *
 *   Return:                                                                    *
 *******************************************************************************/
 
-static void delay (int cnt) {
+static __inline void delay (int cnt) {
 
   cnt <<= DELAY_2N;
   while (cnt--);
 }
 
-__asm void wait()
+static __inline __asm void wait()
 {
     nop
     BX lr
 }
 
-void wait_delay(int count)
+static __inline void wait_delay(int count)
 {
   while(count--);
 }
 
+
+GLCD::GLCD() {
+  Init();
+}
+
+
 /*******************************************************************************
 * Send 1 short to LCD                                                          *
 *   Parameter:    data:   data to be sent                                      *
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline unsigned char lcd_send (unsigned short data) {
+unsigned char GLCD::lcd_send (unsigned short data) {
 
   LPC_GPIO2->FIODIR |= 0x000000ff;  //P2.0...P2.7 Output
   LCD_DIR(1)                           //Interface A->B
@@ -126,7 +136,7 @@
 *   Return: short data from LCD                                                *
 *******************************************************************************/
 
-static __inline unsigned short lcd_read (void) {
+unsigned short GLCD::lcd_read (void) {
   unsigned short id;
   LPC_GPIO2->FIODIR &= 0xffffff00;                //P2.0...P2.7 Input
   LCD_DIR(0)                                         //Interface B->A
@@ -146,7 +156,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline void wr_cmd (unsigned char c) {
+void GLCD::wr_cmd (unsigned char c) {
 
   LCD_RS(0)
   LCD_RD(1)
@@ -163,7 +173,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline void wr_dat (unsigned short c) {
+void GLCD::wr_dat (unsigned short c) {
 
   LCD_RS(1)
   LCD_RD(1)
@@ -179,7 +189,7 @@
 *   Return:               read data                                            *
 *******************************************************************************/
 
-static __inline unsigned short rd_dat (void) {
+unsigned short GLCD::rd_dat (void) {
   unsigned short val = 0;
 
   LCD_RS(1)
@@ -196,7 +206,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline void wr_dat_start (void) {
+void GLCD::wr_dat_start (void) {
 
   LCD_CS(0)  
   LCD_RS(1)
@@ -209,7 +219,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline void wr_dat_stop (void) {
+void GLCD::wr_dat_stop (void) {
 
   LCD_CS(1)
 }
@@ -221,7 +231,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-static __inline void wr_dat_only (unsigned short c) {
+void GLCD::wr_dat_only (unsigned short c) {
 
   lcd_send(c);
   LCD_WR(0)
@@ -236,7 +246,7 @@
 *                 val:    value to write to register                           *
 *******************************************************************************/
 
-static __inline void wr_reg (unsigned char reg, unsigned short val) {
+void GLCD::wr_reg (unsigned char reg, unsigned short val) {
 
   LCD_CS(0)
   wr_cmd(reg);
@@ -251,7 +261,7 @@
 *   Return:               value read from register                             *
 *******************************************************************************/
 
-static unsigned short rd_reg (unsigned short reg) {
+unsigned short GLCD::rd_reg (unsigned short reg) {
   unsigned short val = 0;
 
   LCD_CS(0)
@@ -270,7 +280,7 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Init (void) { 
+void GLCD::Init (void) { 
 
   /* Configure the LCD Control pins                                           */
   LPC_GPIO0->FIODIR   |= 0x03f80000;
@@ -278,12 +288,13 @@
 
   delay(5);                             /* Delay 50 ms                        */
 
-  driverCode = rd_reg(0x00);
+  _driverCode = rd_reg(0x00);
 
-  switch (driverCode) {
+  switch (_driverCode) {
 
     case LGDP4531_ID:  {      //2.8" TFT LCD Module, DriverIC is LGDP4531
 
+#ifndef DISABLE_LGDP4531
       wr_reg(0x00,0x0001);
       wr_reg(0x10,0x0628);
       wr_reg(0x12,0x0006);
@@ -323,13 +334,14 @@
       delay(15);
       wr_reg(0xA0,0x0000);
       delay(20);
-      
+#endif      
       break;
     }
 
 case ILI9328_ID:
 case ILI9325_ID:    {  //2.8" TFT LCD Module, DriverIC is ILI9325
 
+#ifndef DISABLE_ILI9325
       wr_reg(0x00e7,0x0010);
       wr_reg(0x0000,0x0001);              //start internal osc
       wr_reg(0x0001,0x0100); 
@@ -396,11 +408,13 @@
       wr_reg(0x0007,0x0133);
       wr_reg(0x0020,0x0000);                                                            
       wr_reg(0x0021,0x0000);
-        
+#endif        
       break;
 }    
     
     case ILI9320_ID: {       //3.2" TFT LCD Module,DriverIC is ILI9320
+
+#ifndef DISABLE_ILI9320
       /* Start Initial Sequence --------------------------------------------------*/
       wr_reg(0xE5, 0x8000);                 /* Set the internal vcore voltage     */
       wr_reg(0x00, 0x0001);                 /* Start internal OSC                 */
@@ -468,11 +482,14 @@
       wr_reg(0x95, 0x0110);
       wr_reg(0x97, 0x0000);
       wr_reg(0x98, 0x0000);
+#endif
     
       break;
     }
 
     case ILI9331_ID: {
+
+#ifndef DISABLE_ILI9331
       wr_reg(0x00E7, 0x1014);
       wr_reg(0x0001, 0x0100); /* set SS and SM bit */
       wr_reg(0x0002, 0x0200); /* set 1 line inversion */
@@ -534,11 +551,13 @@
       wr_reg(0x0007,0x0061);
       delay(50); /* delay 50 ms */
       wr_reg(0x0007,0x0133); /* 262K color and display ON */
+#endif      
       break;
     }
 
     case SSD1289_ID: {     //3.2" TFT LCD Module,DriverIC is SSD1289
-  
+
+#ifndef DISABLE_SSD1289_ID
       wr_reg(0x0007,0x0233);    delay(5);        //0x0233    Set this first or init fails !
             
       wr_reg(0x0000,0x0001);    delay(5);  // osc en
@@ -600,12 +619,14 @@
       wr_reg(0x0025,0x8000);    delay(5);  // Frame freq 65 Hz
       wr_reg(0x004e,0);                    // Start x
       wr_reg(0x004f,0);                    // Start y     
-        
+#endif        
       break;
     }
 
 
   case SSD1298_ID: {
+
+#ifndef DISABLE_SSD1298_ID
       wr_reg(0x0028,0x0006);
       wr_reg(0x0000,0x0001);
       wr_reg(0x0003,0xaea4); /* power control 1---line frequency and VHG,VGL voltage */
@@ -654,10 +675,13 @@
       wr_reg(0x0026,0x7000);
       wr_reg(0x0020,0xb0eb);
       wr_reg(0x0027,0x007c);
+#endif
       break;
    }
 
 case SSD2119_ID: {
+
+#ifndef DISABLE_SSD2119_ID
       /* POWER ON & RESET DISPLAY OFF */
       wr_reg(0x28,0x0006);
       wr_reg(0x00,0x0001);
@@ -690,6 +714,7 @@
       wr_reg(0x3a,0x1200);
       wr_reg(0x3b,0x0800);
       wr_reg(0x07,0x0033);
+#endif      
       break;
     }
 
@@ -701,6 +726,7 @@
   case R61505U_ID1:
   case R61505U_ID2:  {
 
+#ifndef DISABLE_R61505U
       /* second release on 3/5  ,luminance is acceptable,water wave appear during camera preview */
        wr_reg(0x0007,0x0000);
        delay(50);  /* delay 50 ms */      
@@ -773,11 +799,13 @@
        wr_reg(0x0007,0x0061);
        delay(200);  /* delay 200 ms */      
        wr_reg(0x0007,0x0173);
+#endif
      break;
    } 
 
  case SPFD5408B_ID: {
-      
+
+#ifndef DISABLE_SPFD5408B
       wr_reg(0x0001,0x0100);     /* Driver Output Contral Register */ 
       wr_reg(0x0002,0x0700);      /* LCD Driving Waveform Contral */
       wr_reg(0x0003,0x1030);     /* Entry ModeÉèÖÃ */
@@ -821,10 +849,13 @@
       wr_reg(0x0093,0x0003);     /* Panel Interface control 3 */
       wr_reg(0x0095,0x0110);     /* Frame Cycle Control */
       wr_reg(0x0007,0x0173);
+#endif
      break;
    }   
 
    case LGDP4531_ID: {
+ 
+#ifndef DISABLE_LGDP4531
       /* Setup display */
       wr_reg(0x00,0x0001);
       wr_reg(0x10,0x0628);
@@ -864,10 +895,13 @@
       wr_reg(0x07,0x0133);
       delay(50);
       wr_reg(0xA0,0x0000);
+#endif
       break;
    }
 
    case LGDP4535_ID: {   
+
+#ifndef DISABLE_LGDP4535
       wr_reg(0x15, 0x0030);     /* Set the internal vcore voltage */                                              
       wr_reg(0x9A, 0x0010);     /* Start internal OSC */
       wr_reg(0x11, 0x0020);        /* set SS and SM bit */
@@ -907,10 +941,13 @@
       wr_reg(0x07, 0x0023);
       wr_reg(0x07, 0x0033);
       wr_reg(0x07, 0x0133);
+#endif
       break;
    }    
 
    case HX8347D_ID: {
+ 
+ #ifndef DISABLE_HX8347D
       /* Start Initial Sequence */
       wr_reg(0xEA,0x00);                          
       wr_reg(0xEB,0x20);                                                     
@@ -970,11 +1007,14 @@
       wr_reg(0x36,0x00);                                                    
       wr_reg(0x28,0x38);                                                 
       delay(50);
-      wr_reg(0x28,0x3C);                                                
+      wr_reg(0x28,0x3C); 
+#endif
       break;
    }
 
    case ST7781_ID: {
+ 
+#ifndef DISABLE_ST7781
       /* Start Initial Sequence */
       wr_reg(0x00FF,0x0001);
       wr_reg(0x00F3,0x0008);
@@ -1019,14 +1059,18 @@
       wr_reg(0x0090,0x0033);            
       wr_reg(0x002B,0x000B);      
       wr_reg(0x0007,0x0133);
+#endif
       break;
    }
 #endif     
 
   default: {
       /* special ID */
-      driverCode = rd_reg(0x67);
-      if (driverCode == HX8347A_ID) {
+      _driverCode = rd_reg(0x67);
+      
+      if (_driverCode == HX8347A_ID) {
+
+#ifndef DISABLE_HX8347A
         wr_reg(0x0042,0x0008);
         /* Gamma setting */
         wr_reg(0x0046,0x00B4);
@@ -1104,17 +1148,28 @@
         wr_reg(0x0057,0x0002);
         wr_reg(0x0055,0x0000);
         wr_reg(0x0057,0x0000);
+#endif        
      } // if
+
      break;
     } // default case
      
   } // end switch
 
-
+  _textColor = Black;
+  _backColor = White;    
 }
 
 
+int GLCD::getDisplayXSize()
+{
+  return HEIGHT;
+}
 
+int GLCD::getDisplayYSize()
+{
+  return WIDTH;
+}
 
 
 /*******************************************************************************
@@ -1122,9 +1177,9 @@
 *   Parameter:                                                                 *
 *   Return: short Controller ID                                                *
 *******************************************************************************/
-unsigned short GLCD_DriverCode () {
+unsigned short GLCD::getDriverCode () {
 
-  return (driverCode);
+  return (_driverCode);
 }
 
 
@@ -1134,9 +1189,9 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_WindowMax (void) {
+void GLCD::WindowMax (void) {
   
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
     wr_reg(0x44, 0);                      /* Horizontal GRAM Start Address      */
     wr_reg(0x44, 0 |((HEIGHT-1)<<8));     /* Horizontal GRAM End   Address (-1) */
@@ -1158,14 +1213,14 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Window (int x1, int y1, int x2, int y2) {
+void GLCD::Window (int x1, int y1, int x2, int y2) {
   
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
 //    wr_reg(0x44, x1);                     /* Horizontal GRAM Start Address */
 //    wr_reg(0x44, 0 | (x2<<8));            /* Horizontal GRAM End Address   */
 
-//Note x,y flipped  
+//Note x,y flipped for landscape  
     wr_reg(0x44, ((y2 & 0xFF) <<8) | (y1 & 0xFF)); /* Horizontal GRAM End Address | Start Address  */    
     wr_reg(0x45, x1);                     /* Vertical GRAM Start Address   */
     wr_reg(0x46, x2);                     /* Vertical GRAM End Address     */
@@ -1189,9 +1244,30 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_PutPixel (unsigned int x, unsigned int y) {
+void GLCD::drawPixel (unsigned int x, unsigned int y) {
   // Set Cursor
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
+  {
+      wr_reg(0x4e, y);
+//      wr_reg(0x4f, WIDTH-1-x);
+      wr_reg(0x4f, x);      
+  }
+  else
+  {
+      wr_reg(0x20, y);
+//      wr_reg(0x21, WIDTH-1-x);
+      wr_reg(0x21, x);      
+  }
+  LCD_CS(0)
+  wr_cmd(0x22);
+  wr_dat(_textColor);
+  LCD_CS(1)
+}
+
+void GLCD::drawPixel (unsigned int x, unsigned int y, unsigned short color) 
+{
+  // Set Cursor
+  if(_driverCode==SSD1289_ID)
   {
       wr_reg(0x4e, y);
       wr_reg(0x4f, WIDTH-1-x);
@@ -1203,32 +1279,76 @@
   }
   LCD_CS(0)
   wr_cmd(0x22);
-  wr_dat(TextColor);
+  wr_dat(color);
   LCD_CS(1)
 }
 
 
+void GLCD::drawPixel (unsigned int x, unsigned int y, uint8_t r, uint8_t g, uint8_t b) 
+{
+//  unsigned short color = ((r & 0xF8)<<8) | ((g & 0xFC)<<3) | ((b & 0xF8)>>3);    // rrrrrggggggbbbbb
+  unsigned short color = RGB24toRGB16(r,g,b);
+
+
+  // Set Cursor
+  if(_driverCode==SSD1289_ID)
+  {
+      wr_reg(0x4e, y);
+//      wr_reg(0x4f, WIDTH-1-x);
+      wr_reg(0x4f, x);      
+  }
+  else
+  {
+      wr_reg(0x20, y);
+//      wr_reg(0x21, WIDTH-1-x);
+      wr_reg(0x21, x);      
+  }
+  LCD_CS(0)
+  wr_cmd(0x22);
+  wr_dat(color);
+  LCD_CS(1)
+}
+
+
+
+
 /*******************************************************************************
 * Set foreground color                                                         *
 *   Parameter:      color:    foreground color                                 *
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_SetTextColor (unsigned short color) {
+void GLCD::setColor (unsigned short color) {
+
+  _textColor = color;
+}
 
-  TextColor = color;
+void GLCD::setColor (uint8_t r, uint8_t g, uint8_t b) {     
+  unsigned short color = RGB24toRGB16(r,g,b);
+  
+  _textColor = color;
 }
 
 
+
+
+
 /*******************************************************************************
 * Set background color                                                         *
 *   Parameter:      color:    background color                                 *
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_SetBackColor (unsigned short color) {
+void GLCD::setBackColor (unsigned short color) {
+
+  _backColor = color;
+}
 
-  BackColor = color;
+
+void GLCD::setBackColor (uint8_t r, uint8_t g, uint8_t b) {     
+  unsigned short color = RGB24toRGB16(r,g,b);
+  
+  _backColor = color;
 }
 
 
@@ -1238,13 +1358,13 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Clear (unsigned short color) {
+void GLCD::clearScreen (unsigned short color) {
   unsigned int   i;
 
-  GLCD_WindowMax();
+  WindowMax();
   
   // Set Cursor
-  if(driverCode==0x8989)
+  if (_driverCode==SSD1289_ID)
   {
       wr_reg(0x4e, 0);
       wr_reg(0x4f, 0);
@@ -1271,12 +1391,12 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_DrawChar (unsigned int x, unsigned int y, unsigned short *c) {
+void GLCD::DrawChar (unsigned int x, unsigned int y, unsigned short *c) {
   int idx = 0, i, j;
 
 //wh  x = WIDTH-x-CHAR_W;
 
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
 //wh    wr_reg(0x44, y);                      /* Horizontal GRAM Start Address      */
     wr_reg(0x44, y |((y+CHAR_H-1)<<8));   /* Horizontal GRAM End   Address (-1) */
@@ -1303,9 +1423,9 @@
 //wh    for (i = CHAR_W-1; i >= 0; i--) {
     for (i = 0; i < CHAR_W; i++) {    
       if((c[idx] & (1 << i)) == 0x00) {
-        wr_dat_only(BackColor);
+        wr_dat_only(_backColor);
       } else {
-        wr_dat_only(TextColor);
+        wr_dat_only(_textColor);
       }
     }
     c++;
@@ -1322,11 +1442,11 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char c) {
+void GLCD::DisplayChar (unsigned int ln, unsigned int col, unsigned char c) {
 
   c -= 32;
   // x = column, y = line
-  GLCD_DrawChar(col * CHAR_W, ln * CHAR_H, (unsigned short *)&Font_24x16[c * CHAR_H]);
+  DrawChar(col * CHAR_W, ln * CHAR_H, (unsigned short *)&Font_24x16[c * CHAR_H]);
 
 }
 
@@ -1339,11 +1459,11 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_DisplayString (unsigned int ln, unsigned int col, unsigned char *s) {
+void GLCD::DisplayString (unsigned int ln, unsigned int col, unsigned char *s) {
 
-  GLCD_WindowMax();
+  WindowMax();
   while (*s) {
-    GLCD_DisplayChar(ln, col++, *s++);
+    DisplayChar(ln, col++, *s++);
   }
 }
 
@@ -1354,10 +1474,10 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_ClearLn (unsigned int ln) {
+void GLCD::ClearLn (unsigned int ln) {
 
-  GLCD_WindowMax();
-  GLCD_DisplayString(ln, 0, (unsigned char*) "                    ");
+  WindowMax();
+  DisplayString(ln, 0, (unsigned char*) "                    ");
 }
 
 //SSD1289
@@ -1368,7 +1488,7 @@
 //}
 
 
-void GLCD_drawHLine(int x, int y, int l)
+void GLCD::drawHLine(int x, int y, int l)
 {
 //    char ch, cl;
     
@@ -1377,7 +1497,7 @@
 
 //    cbi(P_CS, B_CS);
 
-    GLCD_Window (x, y, x+l, y);
+    Window (x, y, x+l, y);
     
 //    for (int i=0; i<l+1; i++)
 //    {
@@ -1389,15 +1509,15 @@
  
     wr_dat_start();
     for (int i=0; i<l; i++)    
-      wr_dat_only(TextColor);
+      wr_dat_only(_textColor);
     wr_dat_stop();
    
 //    sbi(P_CS, B_CS);
 //    clrXY();
-    GLCD_WindowMax();
+    WindowMax();
 }
 
-void GLCD_drawVLine(int x, int y, int l)
+void GLCD::drawVLine(int x, int y, int l)
 {
 //    char ch, cl;
     
@@ -1405,29 +1525,29 @@
 //    cl=((fcolorg&28)<<3|fcolorb>>3);
 
 //    cbi(P_CS, B_CS);
-    GLCD_Window(x, y, x, y+l);
+    Window(x, y, x, y+l);
 //    for (int i=0; i<l; i++)
 //    {
-//        GLCD_wr_dat(ch, cl);
+//        GLCD::wr_dat(ch, cl);
 //    }
     LCD_CS(0)
     wr_cmd(0x22);
 
     wr_dat_start();
     for (int i=0; i<l; i++)    
-      wr_dat_only(TextColor);
+      wr_dat_only(_textColor);
     wr_dat_stop();
 
 
 //    sbi(P_CS, B_CS);
 //    clrXY();
-    GLCD_WindowMax();    
+    WindowMax();    
 }
 
 
-void GLCD_drawRect(int x1, int y1, int x2, int y2)
+void GLCD::drawRect(int x1, int y1, int x2, int y2)
 {
-    int tmp;
+    //int tmp;
 
     if (x1>x2)
     {
@@ -1438,12 +1558,269 @@
         swap(int, y1, y2);
     }
 
-    GLCD_drawHLine(x1, y1, x2-x1);
-    GLCD_drawHLine(x1, y2, x2-x1);
-    GLCD_drawVLine(x1, y1, y2-y1);
-    GLCD_drawVLine(x2, y1, y2-y1);
+    drawHLine(x1, y1, x2-x1);
+    drawHLine(x1, y2, x2-x1);
+    drawVLine(x1, y1, y2-y1);
+    drawVLine(x2, y1, y2-y1);
+}
+
+
+/// Replace by faster Bresenham int
+void GLCD::drawLine(int x1, int y1, int x2, int y2)
+{
+//  int tmp;
+  double delta, tx, ty;
+//  double m, b, dx, dy;
+//  char ch, cl;
+    
+  if (((x2-x1)<0))
+    {
+        swap(int, x1, x2);
+        swap(int, y1, y2);
+    }
+    if (((y2-y1)<0))
+    {
+        swap(int, x1, x2);
+        swap(int, y1, y2);
+    }
+
+    if (y1==y2)
+    {
+        if (x1>x2)
+        {
+            swap(int, x1, x2);
+        }
+        drawHLine(x1, y1, x2-x1);
+    }
+    else if (x1==x2)
+    {
+        if (y1>y2)
+        {
+            swap(int, y1, y2);
+        }
+        drawVLine(x1, y1, y2-y1);
+    }
+    else if (abs(x2-x1)>abs(y2-y1))
+    {
+        delta=(double(y2-y1)/double(x2-x1));
+        ty=double(y1);
+        if (x1>x2)
+        {
+            for (int i=x1; i>=x2; i--)
+            {
+                drawPixel(i, int(ty+0.5));
+                ty=ty-delta;
+            }
+        }
+        else
+        {
+            for (int i=x1; i<=x2; i++)
+            {
+                drawPixel(i, int(ty+0.5));                
+                ty=ty+delta;
+            }
+        }
+
+    }
+    else
+    {
+        delta=(float(x2-x1)/float(y2-y1));
+        tx=float(x1);
+        if (y1>y2)
+        {
+            for (int i=y2+1; i>y1; i--)
+            {
+                drawPixel(int(tx+0.5), i);
+                tx=tx+delta;
+            }
+        }
+        else
+        {
+            for (int i=y1; i<y2+1; i++)
+            {
+                drawPixel(int(tx+0.5), i);            
+                tx=tx+delta;
+            }
+        }
+    }
+
+    WindowMax();
+}
+
+void GLCD::drawRoundRect(int x1, int y1, int x2, int y2)
+{
+//    int tmp;
+
+    if (x1>x2)
+    {
+        swap(int, x1, x2);
+    }
+    if (y1>y2)
+    {
+        swap(int, y1, y2);
+    }
+    if ((x2-x1)>4 && (y2-y1)>4)
+    {
+        drawPixel(x1+1,y1+1);
+        drawPixel(x2-1,y1+1);
+        drawPixel(x1+1,y2-1);
+        drawPixel(x2-1,y2-1);
+        drawHLine(x1+2, y1, x2-x1-4);
+        drawHLine(x1+2, y2, x2-x1-4);
+        drawVLine(x1, y1+2, y2-y1-4);
+        drawVLine(x2, y1+2, y2-y1-4);
+    }
 }
 
+void GLCD::fillRect(int x1, int y1, int x2, int y2)
+{
+//    int tmp;
+
+    if (x1>x2)
+    {
+        swap(int, x1, x2);
+    }
+    if (y1>y2)
+    {
+        swap(int, y1, y2);
+    }
+
+//    if (orient==PORTRAIT)
+//    {
+//        for (int i=0; i<((y2-y1)/2)+1; i++)
+//        {
+//            drawHLine(x1, y1+i, x2-x1);
+//            drawHLine(x1, y2-i, x2-x1);
+//        }
+//    }
+//    else
+//    {
+        for (int i=0; i<((x2-x1)/2)+1; i++)
+        {
+            drawVLine(x1+i, y1, y2-y1);
+            drawVLine(x2-i, y1, y2-y1);
+        }
+//    }
+}
+
+void GLCD::fillRoundRect(int x1, int y1, int x2, int y2)
+{
+//    int tmp;
+
+    if (x1>x2)
+    {
+        swap(int, x1, x2);
+    }
+    if (y1>y2)
+    {
+        swap(int, y1, y2);
+    }
+
+    if ((x2-x1)>4 && (y2-y1)>4)
+    {
+        for (int i=0; i<((y2-y1)/2)+1; i++)
+        {
+            switch(i)
+            {
+            case 0:
+                drawHLine(x1+2, y1+i, x2-x1-4);
+                drawHLine(x1+2, y2-i, x2-x1-4);
+                break;
+            case 1:
+                drawHLine(x1+1, y1+i, x2-x1-2);
+                drawHLine(x1+1, y2-i, x2-x1-2);
+                break;
+            default:
+                drawHLine(x1, y1+i, x2-x1);
+                drawHLine(x1, y2-i, x2-x1);
+            }
+        }
+    }
+}
+
+void GLCD::drawCircle(int x, int y, int radius)
+{
+    int f = 1 - radius;
+    int ddF_x = 1;
+    int ddF_y = -2 * radius;
+    int x1 = 0;
+    int y1 = radius;
+//    char ch, cl;
+    
+//    ch=((fcolorr&248)|fcolorg>>5);
+//    cl=((fcolorg&28)<<3|fcolorb>>3);
+ 
+//    cbi(P_CS, B_CS);
+    drawPixel(x, y + radius);
+
+    drawPixel(x, y - radius);
+
+    drawPixel(x + radius, y);
+
+    drawPixel(x - radius, y);
+
+ 
+    while(x1 < y1)
+    {
+        if(f >= 0) 
+        {
+            y1--;
+            ddF_y += 2;
+            f += ddF_y;
+        }
+        x1++;
+        ddF_x += 2;
+        f += ddF_x;    
+        drawPixel(x + x1, y + y1);
+
+        drawPixel(x - x1, y + y1);
+
+        drawPixel(x + x1, y - y1);
+
+        drawPixel(x - x1, y - y1);
+
+        drawPixel(x + y1, y + x1);
+
+        drawPixel(x - y1, y + x1);
+
+        drawPixel(x + y1, y - x1);
+
+        drawPixel(x - y1, y - x1);
+
+    }
+//    sbi(P_CS, B_CS);
+//    clrXY();
+}
+
+void GLCD::fillCircle(int x, int y, int radius)
+{
+//    cbi(P_CS, B_CS);
+    for(int y1=-radius; y1<=radius; y1++) 
+        for(int x1=-radius; x1<=radius; x1++) 
+            if(x1*x1+y1*y1 <= radius*radius) 
+            {
+                drawPixel(x+x1, y+y1);
+            }
+//    sbi(P_CS, B_CS);
+//    clrXY();
+}
+
+
+
+
+void GLCD::lcdOff()
+{
+}
+
+void GLCD::lcdOn()
+{
+}
+
+void GLCD::setContrast(char c)
+{
+}
+
+
 
 
 
@@ -1456,11 +1833,11 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
+void GLCD::Bargraph (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int val) {
   int i,j;
 
   x = WIDTH-x-w;
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
       wr_reg(0x44, y);                      /* Horizontal GRAM Start Address      */
     wr_reg(0x44, y |((y+CHAR_H-1)<<8));   /* Horizontal GRAM End   Address (-1) */
@@ -1476,7 +1853,7 @@
   }
 
   val = (val * w) >> 10;                /* Scale value for 24x12 characters   */
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
       wr_reg(0x4e, y);
       wr_reg(0x4f, x);
@@ -1492,9 +1869,9 @@
   for (i = 0; i < h; i++) {
     for (j = w-1; j >= 0; j--) {
       if(j >= val) {
-        wr_dat_only(BackColor);
+        wr_dat_only(_backColor);
       } else {
-        wr_dat_only(TextColor);
+        wr_dat_only(_textColor);
       }
     }
   }
@@ -1514,12 +1891,12 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) {
+void GLCD::Bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) {
   unsigned int    i, j;
   unsigned short *bitmap_ptr = (unsigned short *)bitmap;
 
   x = WIDTH-x-w;
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
       wr_reg(0x44, y);                      /* Horizontal GRAM Start Address      */
     wr_reg(0x44, y |((y+h-1)<<8));        /* Horizontal GRAM End   Address (-1) */
@@ -1563,13 +1940,13 @@
 *   Return:                                                                    *
 *******************************************************************************/
 
-void GLCD_Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) {
+void GLCD::Bmp (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bmp) {
   unsigned int    i, j;
   unsigned short *bitmap_ptr = (unsigned short *)bmp;
 
 //wh  x = WIDTH-x-w;
 
-  if(driverCode==0x8989)
+  if(_driverCode==SSD1289_ID)
   {
 //wh      wr_reg(0x44, y);                      /* Horizontal GRAM Start Address      */
     wr_reg(0x44, y |((y+h-1)<<8));        /* Horizontal GRAM End   Address (-1) */
--- a/main.cpp	Sun Nov 04 18:13:01 2012 +0000
+++ b/main.cpp	Tue Nov 06 21:39:33 2012 +0000
@@ -77,7 +77,7 @@
 Ticker heartbeat;
 bool heartbeatflag=false;
 
-Ticker LCD_Ani;
+Ticker GLCD_Ani;
 
 void clear_screen() {
 //ANSI Terminal Commands
@@ -123,21 +123,351 @@
 }
 
 
+// GLCD
+GLCD myGLCD;
+
 // LCD Animation
-void LCD_pulse() {
+#if(0)  
+void GLCD_pulse() {
   static int pic =  0;
+  static int x2 =  0;  
+  static int y2 =  200;  
+    
+  if (pic++ > 8) pic = 0;
+  myGLCD.Bmp (99, 99, 120, 45, (unsigned char*) &ARM_Ani_16bpp[pic*(120*45*2)]);
+
+  myGLCD.drawLine(0, 0, x2, y2);
   
+  x2=x2+5;
+  y2=y2-5;
+  if (y2 <= 0) {
+    x2 =  0;  
+    y2 =  200;
+    myGLCD.setTextColor(~glcd._textColor);      
+  } 
+}
+#else
+void GLCD_pulse() {
+  static int pic =  0;
+    
   if (pic++ > 8) pic = 0;
-  GLCD_Bmp (99, 99, 120, 45, (unsigned char*) &ARM_Ani_16bpp[pic*(120*45*2)]);
+  myGLCD.Bmp (99, 99, 120, 45, (unsigned char*) &ARM_Ani_16bpp[pic*(120*45*2)]);
+}
+#endif
+
+void GLCD_Ani_start() {
+//  GLCD_Ani.attach(&GLCD_pulse, 0.05);
+  GLCD_Ani.attach(&GLCD_pulse, 0.25);  
+}
+
+void GLCD_Ani_stop() {
+  GLCD_Ani.detach();
+}
+
+void delay(int ms) {
+  wait_ms(ms);
+}
+
+
+int random(int max) {
+  int rnd = rand() % max;
+
+  return rnd;
 }
 
-void LCD_Ani_start() {
-//  LCD_Ani.attach(&LCD_pulse, 0.05);
-  LCD_Ani.attach(&LCD_pulse, 0.25);  
-}
+void loop()
+{
+  int buf[318];
+  int x, x2;
+  int y, y2;
+  int r;
+
+// Clear the screen and draw the frame
+  myGLCD.clearScreen(White);
+
+  myGLCD.setColor(255, 0, 0);
+  myGLCD.fillRect(0, 0, 319, 13);
+  myGLCD.setColor(64, 64, 64);
+  myGLCD.fillRect(0, 226, 319, 239);
+  myGLCD.setColor(255, 255, 255);
+  myGLCD.setBackColor(255, 0, 0);
+//  myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
+  myGLCD.setBackColor(64, 64, 64);
+  myGLCD.setColor(255,255,0);
+//  myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227);
+
+  myGLCD.setColor(0, 0, 255);
+  myGLCD.drawRect(0, 14, 319, 225);
+
+// Draw crosshairs
+  myGLCD.setColor(0, 0, 255);
+  myGLCD.setBackColor(0, 0, 0);
+  myGLCD.drawLine(159, 15, 159, 224);
+  myGLCD.drawLine(1, 119, 318, 119);
+  for (int i=9; i<310; i+=10)
+    myGLCD.drawLine(i, 117, i, 121);
+  for (int i=19; i<220; i+=10)
+    myGLCD.drawLine(157, i, 161, i);
+
+// Draw sin-, cos- and tan-lines  
+  myGLCD.setColor(0,255,255);
+//  myGLCD.print("Sin", 5, 15);
+  for (int i=1; i<318; i++)
+  {
+    myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
+  }
+  
+  myGLCD.setColor(255,0,0);
+//  myGLCD.print("Cos", 5, 27);
+  for (int i=1; i<318; i++)
+  {
+    myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
+  }
+
+  myGLCD.setColor(255,255,0);
+//  myGLCD.print("Tan", 5, 39);
+  for (int i=1; i<318; i++)
+  {
+    myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
+  }
+
+  delay(2000);
+
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+  myGLCD.setColor(0, 0, 255);
+  myGLCD.setBackColor(0, 0, 0);
+  myGLCD.drawLine(159, 15, 159, 224);
+  myGLCD.drawLine(1, 119, 318, 119);
+
+// Draw a moving sinewave
+  x=1;
+  for (int i=1; i<(318*20); i++) 
+  {
+    x++;
+    if (x==319)
+      x=1;
+    if (i>319)
+    {
+      if ((x==159)||(buf[x-1]==119))
+        myGLCD.setColor(0,0,255);
+      else
+        myGLCD.setColor(0,0,0);
+      myGLCD.drawPixel(x,buf[x-1]);
+    }
+    myGLCD.setColor(0,255,255);
+    y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
+    myGLCD.drawPixel(x,y);
+    buf[x-1]=y;
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+// Draw some filled rectangles
+  for (int i=1; i<6; i++)
+  {
+    switch (i)
+    {
+      case 1:
+        myGLCD.setColor(255,0,255);
+        break;
+      case 2:
+        myGLCD.setColor(255,0,0);
+        break;
+      case 3:
+        myGLCD.setColor(0,255,0);
+        break;
+      case 4:
+        myGLCD.setColor(0,0,255);
+        break;
+      case 5:
+        myGLCD.setColor(255,255,0);
+        break;
+    }
+    myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
 
-void LCD_Ani_stop() {
-  LCD_Ani.detach();
+// Draw some filled, rounded rectangles
+  for (int i=1; i<6; i++)
+  {
+    switch (i)
+    {
+      case 1:
+        myGLCD.setColor(255,0,255);
+        break;
+      case 2:
+        myGLCD.setColor(255,0,0);
+        break;
+      case 3:
+        myGLCD.setColor(0,255,0);
+        break;
+      case 4:
+        myGLCD.setColor(0,0,255);
+        break;
+      case 5:
+        myGLCD.setColor(255,255,0);
+        break;
+    }
+    myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
+  }
+  
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+// Draw some filled circles
+  for (int i=1; i<6; i++)
+  {
+    switch (i)
+    {
+      case 1:
+        myGLCD.setColor(255,0,255);
+        break;
+      case 2:
+        myGLCD.setColor(255,0,0);
+        break;
+      case 3:
+        myGLCD.setColor(0,255,0);
+        break;
+      case 4:
+        myGLCD.setColor(0,0,255);
+        break;
+      case 5:
+        myGLCD.setColor(255,255,0);
+        break;
+    }
+    myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
+  }
+  
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+// Draw some lines in a pattern
+  myGLCD.setColor (255,0,0);
+  for (int i=15; i<224; i+=5)
+  {
+    myGLCD.drawLine(1, i, (i*1.44)-10, 224);
+  }
+  myGLCD.setColor (255,0,0);
+  for (int i=224; i>15; i-=5)
+  {
+    myGLCD.drawLine(318, i, (i*1.44)-11, 15);
+  }
+  myGLCD.setColor (0,255,255);
+  for (int i=224; i>15; i-=5)
+  {
+    myGLCD.drawLine(1, i, 331-(i*1.44), 15);
+  }
+  myGLCD.setColor (0,255,255);
+  for (int i=15; i<224; i+=5)
+  {
+    myGLCD.drawLine(318, i, 330-(i*1.44), 224);
+  }
+  
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,225);
+
+// Draw some random circles
+  for (int i=0; i<100; i++)
+  {
+    myGLCD.setColor(random(255), random(255), random(255));
+    x=32+random(256);
+    y=45+random(146);
+    r=random(30);
+    myGLCD.drawCircle(x, y, r);
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+// Draw some random rectangles
+  for (int i=0; i<100; i++)
+  {
+    myGLCD.setColor(random(255), random(255), random(255));
+    x=2+random(316);
+    y=16+random(207);
+    x2=2+random(316);
+    y2=16+random(207);
+    myGLCD.drawRect(x, y, x2, y2);
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+// Draw some random rounded rectangles
+  for (int i=0; i<100; i++)
+  {
+    myGLCD.setColor(random(255), random(255), random(255));
+    x=2+random(316);
+    y=16+random(207);
+    x2=2+random(316);
+    y2=16+random(207);
+    myGLCD.drawRoundRect(x, y, x2, y2);
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+  for (int i=0; i<100; i++)
+  {
+    myGLCD.setColor(random(255), random(255), random(255));
+    x=2+random(316);
+    y=16+random(209);
+    x2=2+random(316);
+    y2=16+random(209);
+    myGLCD.drawLine(x, y, x2, y2);
+  }
+
+  delay(2000);
+  
+  myGLCD.setColor(0,0,0);
+  myGLCD.fillRect(1,15,318,224);
+
+  for (int i=0; i<10000; i++)
+  {
+    myGLCD.setColor(random(255), random(255), random(255));
+    myGLCD.drawPixel(2+random(316), 16+random(209));
+  }
+
+  delay(2000);
+
+//  myGLCD.fillScr(0, 0, 255);
+  myGLCD.clearScreen(Blue);  
+
+  myGLCD.setColor(255, 0, 0);
+  myGLCD.fillRoundRect(80, 70, 239, 169);
+  
+  myGLCD.setColor(255, 255, 255);
+  myGLCD.setBackColor(255, 0, 0);
+//  myGLCD.print("That's it!", CENTER, 93);
+//  myGLCD.print("Restarting in a", CENTER, 119);
+//  myGLCD.print("few seconds...", CENTER, 132);
+  
+  myGLCD.setColor(0, 255, 0);
+  myGLCD.setBackColor(0, 0, 255);
+//  myGLCD.print("Runtime: (msecs)", CENTER, 210);
+//  myGLCD.printNumI(millis(), CENTER, 225);
+  
+  delay (3000);
 }
 
 
@@ -151,32 +481,41 @@
   
     pc.printf("Hello World!\n\r");
 
-    GLCD_Init();
-    GLCD_Clear(White);
-//    GLCD_Clear(Blue);    
+    myGLCD.Init();
+    myGLCD.clearScreen(White);
+//    GLCD_clearScreen(Blue);    
 //    GLCD_Bmp(  0,   0, 320,  69, (unsigned char*) Bg_16bpp_t+70);
 //    GLCD_Bmp(  0,  69,   4, 102, (unsigned char*) Bg_16bpp_l+70);
 //    GLCD_Bmp(316,  69,   4, 102, (unsigned char*) Bg_16bpp_r+70);
 //    GLCD_Bmp(  0, 171, 320,  69, (unsigned char*) Bg_16bpp_b+70);
 //    GLCD_Bmp(  0, 171, 320,  69, (unsigned char*) Bg_16bpp_t+70);    
 
-    GLCD_SetTextColor   (Red);
-    GLCD_SetBackColor   (White);
-    GLCD_DisplayString (8, 1, (unsigned char*) "Hi Willem");
+    myGLCD.setColor   (Red);
+    myGLCD.setBackColor   (White);
+    myGLCD.DisplayString (8, 1, (unsigned char*) "Hi Willem");
 
-    LCD_Ani_start();
+//    GLCD_Ani_start();
+
+    myGLCD.drawRect (10, 10, 100, 100);
 
-    GLCD_drawRect (10, 10, 100, 100);
+    myGLCD.setColor   (Green);    
+    myGLCD.drawHLine (20, 20, 50);
+    myGLCD.drawVLine (30, 30, 50);
+    
+    myGLCD.setColor   (Blue);    
+    myGLCD.fillRoundRect  (40, 40, 100, 100);
+    myGLCD.setColor   (Cyan);    
+    myGLCD.drawCircle     (60, 60, 40);
+    
+    
+    pc.printf("LCD Controller ID = 0x%04X\n\r", myGLCD.getDriverCode());    
 
-    GLCD_SetTextColor   (Green);    
-    GLCD_drawHLine (20, 20, 50);
-    GLCD_drawVLine (30, 30, 50);
-    
-    pc.printf("LCD Controller ID = 0x%04X\n\r", GLCD_DriverCode());    
+   loop();
     
     while(1) {
       pc.printf("+"); 
-            
+
+                
       wait(0.1);
     };