Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.

Dependents:   mythermostat MorseCode SuperMbedBall frogger_G ... more

Fork of 4DGL by Adam Green

Revision:
7:e39a44de229a
Parent:
6:b759b69cbaf9
--- a/uLCD_4DGL_main.cpp	Mon Nov 25 04:24:22 2013 +0000
+++ b/uLCD_4DGL_main.cpp	Sat Nov 30 02:05:15 2013 +0000
@@ -2,6 +2,7 @@
 // uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2
 //
 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+// Modifed for Goldelox processor <2013> Jim Hamblen
 //
 // uLCD_4DGL is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -44,11 +45,7 @@
 
     _rst = 1;    // put RESET pin to high to start TFT screen
     reset();
-
-//  autobaud();  // send autobaud command
-//   version();   // get version information
     cls();       // clear screen
-
     current_col         = 0;            // initial cursor col
     current_row         = 0;            // initial cursor row
     current_color       = WHITE;        // initial text color
@@ -64,7 +61,7 @@
 {
 
     _cmd.putc(c);
-    wait_ms(1);  //mbed is too fast for LCD at high baud rates in long commands
+    wait_us(500);  //mbed is too fast for LCD at high baud rates in some long commands
 
 #if DEBUGMODE
     pc.printf("   Char sent : 0x%02X\n",c);
@@ -77,7 +74,7 @@
 {
 
     _cmd.putc(c);
-    //wait_ms(0.0);  //mbed is too fast for LCD at high baud rates - but not in some commands
+    //wait_ms(0.0);  //mbed is too fast for LCD at high baud rates - but not in short commands
 
 #if DEBUGMODE
     pc.printf("   Char sent : 0x%02X\n",c);
@@ -151,10 +148,10 @@
     freeBUFFER();
     writeBYTE(0x00); //command has a null prefix byte
     for (i = 0; i < number; i++) {
-        if (i<16)
+        if (i<16) //don't overflow LCD UART buffer
             writeBYTEfast(command[i]); // send command to serial port
         else
-            writeBYTE(command[i]); // send command to serial port
+            writeBYTE(command[i]); // send command to serial port with delay
     }
     while (!_cmd.readable()) wait_ms(TEMPO);              // wait for screen answer
     if (_cmd.readable()) resp = _cmd.getc();           // read response if any
@@ -176,16 +173,6 @@
     return resp;
 }
 
-
-//**************************************************************************
-void uLCD_4DGL :: autobaud()   // send AutoBaud command (9600)
-{
-    writeBYTE(AUTOBAUD);
-    char command[1] = "";
-    command[0] = AUTOBAUD;
-    writeCOMMAND(command, 1);
-}
-
 //**************************************************************************
 void uLCD_4DGL :: cls()    // clear screen
 {
@@ -193,18 +180,21 @@
 
     command[0] = CLS;
     writeCOMMAND(command, 1);
+    current_row=0;
+    current_col=0;
     current_hf = 1;
     current_wf = 1;
     set_font(FONT_7X8);                 // initial font
 }
 
 //**************************************************************************
-void uLCD_4DGL :: version()    // get API version
+int uLCD_4DGL :: version()    // get API version
 {
+
     char command[2] = "";
-    command[0] = VERSION;
-    command[1] = OFF;
-    readVERSION(command, 2);
+    command[0] = '\x00';
+    command[1] = VERSION;
+    return readVERSION(command, 2);
 }
 
 //**************************************************************************
@@ -279,6 +269,18 @@
         case 600000 :
             newbaud = BAUD_600000;
             break;
+        case 750000 : //rates over 600000 are not documented, but seem to work
+            newbaud = BAUD_750000;
+            break;
+        case 1000000 :  
+            newbaud = BAUD_1000000;
+            break;
+        case 1500000 :
+            newbaud = BAUD_1500000;
+            break;
+        case 3000000 :
+            newbaud = BAUD_3000000;
+            break;
         default   :
             newbaud = BAUD_9600;
             speed = 9600;
@@ -292,7 +294,8 @@
     command[2] = char(newbaud % 256);
     wait_ms(1);
     for (i = 0; i <3; i++) writeBYTEfast(command[i]);      // send command to serial port
-    wait_ms(10); //dont change baud until all characters get sent out
+    for (i = 0; i<10; i++) wait_ms(1); 
+    //dont change baud until all characters get sent out
     _cmd.baud(speed);                                  // set mbed to same speed
     i=0;
     while ((!_cmd.readable()) && (i<25000)) {
@@ -377,16 +380,16 @@
 }
 
 //****************************************************************************************************
-void uLCD_4DGL :: display_control(char mode, char value)     // set screen mode to value
+void uLCD_4DGL :: display_control(char mode)     // set screen mode to value
 {
     char command[3]= "";
 
     command[0] = DISPCONTROL;
-    command[1] = mode;
-    command[2] = value;
+    command[1] = 0;
+    command[2] = mode;
 
     if (mode ==  ORIENTATION) {
-        switch (value) {
+        switch (mode) {
             case LANDSCAPE :
                 current_orientation = IS_LANDSCAPE;
                 break;
@@ -404,7 +407,16 @@
     writeCOMMAND(command, 3);
     set_font(current_font);
 }
+//****************************************************************************************************
+void uLCD_4DGL :: display_power(char mode)     // set screen mode to value
+{
+    char command[3]= "";
 
+    command[0] = DISPPOWER;
+    command[1] = 0;
+    command[2] = mode;
+    writeCOMMAND(command, 3);
+}
 //****************************************************************************************************
 void uLCD_4DGL :: set_volume(char value)     // set sound volume to value
 {
@@ -418,48 +430,6 @@
 
 
 //******************************************************************************************************
-void uLCD_4DGL :: getTOUCH(char *command, int number, int *x, int *y)   // read screen info and populate data
-{
-
-#if DEBUGMODE
-    pc.printf("\n");
-    pc.printf("New COMMAND : 0x%02X\n", command[0]);
-#endif
-    int i, temp = 0, resp = 0;
-    char response[5] = "";
-
-    freeBUFFER();
-
-    for (i = 0; i < number; i++) writeBYTE(command[i]);    // send all chars to serial port
-
-    while (!_cmd.readable()) wait_ms(TEMPO);               // wait for screen answer
-
-    while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
-        temp = _cmd.getc();
-        response[resp++] = (char)temp;
-    }
-
-#if DEBUGMODE
-    pc.printf("   Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2], response[3]);
-#endif
-
-    switch (resp) {
-        case 4 :                                                              // if OK populate data
-            *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF);
-            *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF);
-            break;
-        default :
-            *x = -1;
-            *y = -1;
-            break;
-    }
-
-#if DEBUGMODE
-    pc.printf("   X,Y : %03d,%03d\n", *x, *y);
-#endif
-}
-
-//******************************************************************************************************
 int uLCD_4DGL :: getSTATUS(char *command, int number)   // read screen info and populate data
 {
 
@@ -496,3 +466,4 @@
 
     return resp;
 }
+