Landtiger (LPC1768) graphics LCD demo.

Dependencies:   Tiger_LCD mbed

Dependents:   Tiger_LCD

See here for more info.

Revision:
4:cdeea87f25d8
Parent:
3:2dccfa0121de
--- a/main.cpp	Fri Oct 30 01:26:40 2015 +0000
+++ b/main.cpp	Tue Nov 24 22:33:20 2015 +0000
@@ -1,35 +1,26 @@
 #include "mbed.h"
 #include "GLCD.h"
 
-#include "Bg_16bpp_t.h"
-#include "Bg_16bpp_l.h"
-#include "Bg_16bpp_r.h"
-#include "Bg_16bpp_b.h"
-#include "ARM_Ani_16bpp.h"
-
 //Host PC Baudrate (Virtual Com Port on USB)
 #define D_BAUDRATE            9600
 //#define D_BAUDRATE            57600
 
-//extern unsigned short driverCode;
-
-#define LANDTIGER 1
+// Variables for Heartbeat and Status monitoring
+//Note Port2 is used for the LCD
+//DigitalOut myled1(P2_0);
+//DigitalOut myled2(P2_1);
+//DigitalOut myled3(P2_2);
+//DigitalOut myled4(P2_3);
+//DigitalOut myled5(P2_4);
+//DigitalOut myled6(P2_5);
+//DigitalOut myled7(P2_6);
+//DigitalOut myled8(P2_7);
 
-// Variables for Heartbeat and Status monitoring
-#ifdef LANDTIGER
-DigitalOut myled1(P2_0);
-DigitalOut myled2(P2_1);
-DigitalOut myled3(P2_2);
-DigitalOut myled4(P2_3);
-DigitalOut myled5(P2_4);
-DigitalOut myled6(P2_5);
-DigitalOut myled7(P2_6);
-DigitalOut myled8(P2_7);
-
-
-//DigitalOut heartbeatLED(LED4);
-DigitalOut heartbeatLED(P3_26);      //SD_PWR, active low
-//DigitalOut USB_Host_Power(P1_19);   //USB Power, active low
+DigitalOut heartbeatLED(P3_26);      //SD_PWR, LD3: active low
+DigitalOut USB_Device_PU(P2_9);      //USB Device Pull Up, LD14: active low (OK)
+DigitalOut USB_Device_Up(P1_18);     //USB Device Up, LD13: active low (OK)
+//DigitalOut USB_Host_Power(P1_19);    //USB Host Power, LD15: active low (does not seem to go high again? ?)
+DigitalInOut USB_Host_Power(P1_19);    //USB Host Power, LD15: active low (does not seem to go high again? ?)
 
 // Need this override function on non-mbed hardware to provide the MAC address.
 //
@@ -41,35 +32,17 @@
 // you should implement your own extern "C" void mbed_mac_address(char * mac) function
 // to overwrite the existing one and avoid a call to the interface (which doesnt exist).
 
-
 extern "C" void mbed_mac_address(char * mac) {
 
 //mbed module clone
-//  mac[0] = 0x00;  
-//  mac[1] = 0x02;  
-//  mac[2] = 0xF7;  
-//  mac[3] = 0xF0;  
-//  mac[4] = 0x56;  
-//  mac[5] = 0x90;            
-
-//KPN Experia
   mac[0] = 0x00;  
-  mac[1] = 0x01;  
-  mac[2] = 0xE3;  
-  mac[3] = 0x55;  
-  mac[4] = 0xA1;  
-  mac[5] = 0xC7;           
-  
+  mac[1] = 0x02;  
+  mac[2] = 0xF7;  
+  mac[3] = 0xF0;  
+  mac[4] = 0x56;  
+  mac[5] = 0x90;            
 };
 
-#else
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-DigitalOut heartbeatLED(LED4);
-#endif
-
-
 // Host PC Communication channels
 Serial pc(USBTX, USBRX); // tx, rx
 
@@ -77,8 +50,6 @@
 Ticker heartbeat;
 bool heartbeatflag=false;
 
-Ticker GLCD_Ani;
-
 void clear_screen() {
 //ANSI Terminal Commands
     pc.printf("\x1B[2J");
@@ -88,33 +59,16 @@
 void init_interfaces() {
     // Init Host PC communication, default is 9600
     pc.baud(D_BAUDRATE);
-      
-    //Done, Tell me about it
-//    show_LEDS();
 }
       
 
 // Heartbeat monitor
 void pulse() {
-  heartbeatLED = !heartbeatLED;
-
-#ifdef LANDTIGER
-//  myled1 = heartbeatLED;
-//  myled2 = heartbeatLED;
-//  myled3 = heartbeatLED;
-//  myled4 = heartbeatLED;      
-
-//  myled5 = !heartbeatLED;
-//  myled6 = !heartbeatLED;
-//  myled7 = !heartbeatLED;
-//  myled8 = !heartbeatLED;      
-
-#endif  
-  
+  heartbeatLED = !heartbeatLED; 
 }
 
 void heartbeat_start() {
-  heartbeatLED = 1;
+  heartbeatLED = 0;
   heartbeat.attach(&pulse, 0.5);
 }
 
@@ -122,61 +76,45 @@
   heartbeat.detach();
 }
 
+#if(1)
+void flip_USB_Host_Power() {
+ static bool pin = false;
+
+ //USB Host Power, LD15: active low (DigitalOut does not seem to go high enough to disable?)
+ if (pin) {  
+   USB_Host_Power.input();         // input + pull up, power is Off
+ }
+ else {
+   USB_Host_Power.output();        // output + low, power is On
+   USB_Host_Power = 0;   
+ }
+ pin = !pin;   
+}
+
+
+void set_USB_Host_Power(bool pin) {
+ //USB Host Power, LD15: active low (DigitalOut does not seem to go high enough to disable?)
+ if (pin) {  
+   USB_Host_Power.input();         // input + pull up, power is Off
+ }
+ else {
+   USB_Host_Power.output();        // output + low, power is On
+   USB_Host_Power = 0;   
+ }
+}
+#endif
 
 // GLCD
 GLCD myGLCD;
 
-#include "Julia.h"
-
-// LCD Animation
-#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;
-  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;
 }
 
+
+#if(1)
 void loop()
 {
   int buf[318];
@@ -185,7 +123,7 @@
   int r;
 
 // Clear the screen and draw the frame
-  myGLCD.clearScreen(White);
+  myGLCD.cls(White);
 
   myGLCD.setColor(255, 0, 0);
   myGLCD.fillRect(0, 0, 319, 13);
@@ -233,7 +171,7 @@
     myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
   }
 
-  delay(2000);
+  wait(2);
 
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -263,7 +201,7 @@
     buf[x-1]=y;
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -292,7 +230,7 @@
     myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -321,7 +259,7 @@
     myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
   }
   
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -350,7 +288,7 @@
     myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
   }
   
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -377,7 +315,7 @@
     myGLCD.drawLine(318, i, 330-(i*1.44), 224);
   }
   
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,225);
@@ -392,7 +330,7 @@
     myGLCD.drawCircle(x, y, r);
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -408,7 +346,7 @@
     myGLCD.drawRect(x, y, x2, y2);
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -424,7 +362,7 @@
     myGLCD.drawRoundRect(x, y, x2, y2);
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -439,7 +377,7 @@
     myGLCD.drawLine(x, y, x2, y2);
   }
 
-  delay(2000);
+  wait(2);
   
   myGLCD.setColor(0,0,0);
   myGLCD.fillRect(1,15,318,224);
@@ -450,10 +388,9 @@
     myGLCD.drawPixel(2+random(316), 16+random(209));
   }
 
-  delay(2000);
+  wait(2);
 
-//  myGLCD.fillScr(0, 0, 255);
-  myGLCD.clearScreen(Blue);  
+  myGLCD.cls(Blue);  
 
   myGLCD.setColor(255, 0, 0);
   myGLCD.fillRoundRect(80, 70, 239, 169);
@@ -469,74 +406,66 @@
 //  myGLCD.print("Runtime: (msecs)", CENTER, 210);
 //  myGLCD.printNumI(millis(), CENTER, 225);
   
-  delay (3000);
+  wait(2);
 }
-
+#endif
 
 
 int main() {
     init_interfaces();
     
-    heartbeat_start();
-
     clear_screen(); 
+    
+    heartbeat_start();    
   
     pc.printf("Hello World!\n\r");
-
-//    myGLCD.init();  // done in cosntructor
-    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);    
-
-    myGLCD.setColor   (Red);
-    myGLCD.setBackColor   (White);
-    myGLCD.DisplayString (8, 1, (unsigned char*) "Hi Willem");
-
-//    GLCD_Ani_start();
-
-    myGLCD.drawRect (10, 10, 100, 100);
+    pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);       
+    
+#if(1)
+    myGLCD.cls(White);
+    myGLCD.setColor(Red);
+    myGLCD.setBackColor(White);
+    myGLCD.printf ("Hi Willem\n"); 
+    myGLCD.printf("CPU SystemCoreClock is %d Hz\n", SystemCoreClock);              
+        
+    wait(0.5);
+    
+    myGLCD.drawRect (100, 100, 150, 150);
 
     myGLCD.setColor   (Green);    
-    myGLCD.drawHLine (20, 20, 50);
-    myGLCD.drawVLine (30, 30, 50);
+    myGLCD.drawHLine (120, 160, 80);
+    myGLCD.drawVLine (160, 120, 80);
     
     myGLCD.setColor   (Blue);    
-    myGLCD.fillRoundRect  (40, 40, 100, 100);
+    myGLCD.fillRoundRect  (100, 100, 130, 130);
     myGLCD.setColor   (Cyan);    
-    myGLCD.drawCircle     (60, 60, 40);
-    
-    
+    myGLCD.drawCircle     (160, 160, 40);
+       
     pc.printf("LCD Controller ID = 0x%04X\n\r", myGLCD.getDriverCode());    
+    pc.printf("PixelsY= %d, PixelsX= %d\n\r", myGLCD.getDisplayYSize(), myGLCD.getDisplayXSize());            
+    pc.printf("Lines= %d, Cols= %d\n\r", myGLCD.getRows(), myGLCD.getCols());        
 
+#if(1)
+    wait(2);
     loop();
-    
-//    float k = 0.0;
-    float re_min=-0.17775;
-    float im_min= 0.7675;
-    float len= 0.32375;
-        
-    while(1) {
-      pc.printf("+"); 
+#endif
 
-      pc.printf("\n\rEnter re_min: "); 
-      pc.scanf("%f", &re_min);       
-      pc.printf("\n\rEnter im_min: "); 
-      pc.scanf("%f", &im_min);       
-      pc.printf("\n\rEnter len: "); 
-      pc.scanf("%f", &len);       
+    myGLCD.setColor(Black);
+    myGLCD.locate(9,0);            
+    myGLCD.printf("Bye Willem");        
+#endif    
+    pc.printf("Bye World!\n\r"); 
 
-      pc.printf("\n\rValues: re_min=%0.5f, im_min=%0.5f, len=%0.5f\n\r", re_min, im_min, len);             
-      mandelbrot(320, 240, 400, re_min, re_min+len, im_min, im_min+len);    
-//      mandelbrot(150, 150, 400, re_min, re_min+len, im_min, im_min+len+k);    
-           
-//      k = k + 0.023;          
+    USB_Device_PU  = 1;   //USB Device Pull Up, LD14: active low
+    USB_Device_Up  = 1;   //USB Device Up, LD13: active low
+    
+    while (1) {
+      //USB_Host_Power = !USB_Host_Power;  //Does not switch off!
+      flip_USB_Host_Power();
+      USB_Device_PU  = !USB_Device_PU;
+      USB_Device_Up  = !USB_Device_Up;
       
-      wait(0.1);
-    };
-    
-    pc.printf("Bye World!\n\r");   
+      pc.putc('*');       
+      wait(1.5);
+    }  
 }