This is a library for 4DGL screens from 4D Systems in Autralia (http://www.4dsystems.com.au). Most graphic, touch and text functions are supported

Dependents:   Conways_Game_Life uVGAII_demo 4DGLtest_CalSol uVGA_4180

Files at this revision

API Documentation at this revision

Comitter:
Kerpower
Date:
Sun Oct 17 10:23:58 2010 +0000
Parent:
6:d0dca0ddc329
Child:
8:b95348b8030e
Commit message:
2

Changed in this revision

TFT_4DGL.h Show annotated file Show diff for this revision Revisions of this file
TFT_4DGL_Graphics.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TFT_4DGL.h	Sun Oct 17 10:11:49 2010 +0000
+++ b/TFT_4DGL.h	Sun Oct 17 10:23:58 2010 +0000
@@ -176,7 +176,7 @@
 
     TFT_4DGL(PinName tx, PinName rx, PinName rst);
 
-// General Commands
+// General Commands *******************************************************************************
 
 /** Clear the entire screen using the current background colour */
     void cls();
@@ -187,32 +187,36 @@
 /** Launch Autobaud for serial communication. This function is automatically called at startup */
     void autobaud();
 /** Set serial Baud rate (both sides : screen and mbed)
-*
 * @param Speed Correct BAUD value (see TFT_4DGL.h)
 */   
     void baudrate(int speed);
 
 /** Set background colour to the specified value
-*
 * @param color in HEX RGB like 0xFF00FF
 */
     void background_color(int color);
 
 /** Set screen display mode to specific values
-*
 * @param mode See 4DGL documentation
 * @param value See 4DGL documentation
 */
     void display_control(char mode, char value);
 
 /** Set internal speaker to specified value
-*
 * @param value Correct range is 8 - 127
 */
     void set_volume(char value);
 
-// Graphics Commands
-    void circle(int, int, int, int);
+// Graphics Commands *******************************************************************************
+
+/** Draw a ciscle centered at x,y with a radius and a colour. It uses PEn Size to draw a solid or wireframe circle
+* @param x Horizontal position of the circle centre
+* @param y Vertical position of the circle centre
+* @param radius Radius of the circle
+* @param color Circle color in HEX RGB like 0xFF00FF
+*/
+    void circle(int x , int y , int radius, int color);
+
     void triangle(int, int, int, int, int, int, int);
     void line(int, int, int, int, int);
     void rectangle(int, int, int, int, int);
--- a/TFT_4DGL_Graphics.cpp	Sun Oct 17 10:11:49 2010 +0000
+++ b/TFT_4DGL_Graphics.cpp	Sun Oct 17 10:23:58 2010 +0000
@@ -1,258 +1,258 @@
-//
-// TFT_4DGL is a class to drive 4D Systems TFT touch screens
-//
-// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
-//
-// TFT_4DGL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// TFT_4DGL is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.
-
-#include "mbed.h"
-#include "TFT_4DGL.h"
-
-
-//****************************************************************************************************
-void TFT_4DGL :: circle(int x, int y , int radius, int color) {   // draw a circle in (x,y)
-    char command[9]= "";
-
-    command[0] = CIRCLE;
-
-    command[1] = (x >> 8) & 0xFF;
-    command[2] = x & 0xFF;
-
-    command[3] = (y >> 8) & 0xFF;
-    command[4] = y & 0xFF;
-
-    command[5] = (radius >> 8) & 0xFF;
-    command[6] = radius & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;              // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;              // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
-
-    command[7] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[8] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 9);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) {   // draw a traingle
-    char command[15]= "";
-
-    command[0] = TRIANGLE;
-
-    command[1] = (x1 >> 8) & 0xFF;
-    command[2] = x1 & 0xFF;
-
-    command[3] = (y1 >> 8) & 0xFF;
-    command[4] = y1 & 0xFF;
-
-    command[5] = (x2 >> 8) & 0xFF;
-    command[6] = x2 & 0xFF;
-
-    command[7] = (y2 >> 8) & 0xFF;
-    command[8] = y2 & 0xFF;
-
-    command[9] = (x3 >> 8) & 0xFF;
-    command[10] = x3 & 0xFF;
-
-    command[11] = (y3 >> 8) & 0xFF;
-    command[12] = y3 & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
-
-    command[13] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[14] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 15);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) {   // draw a line
-    char command[11]= "";
-
-    command[0] = LINE;
-
-    command[1] = (x1 >> 8) & 0xFF;
-    command[2] = x1 & 0xFF;
-
-    command[3] = (y1 >> 8) & 0xFF;
-    command[4] = y1 & 0xFF;
-
-    command[5] = (x2 >> 8) & 0xFF;
-    command[6] = x2 & 0xFF;
-
-    command[7] = (y2 >> 8) & 0xFF;
-    command[8] = y2 & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
-
-    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
-    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 11);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) {   // draw a rectangle
-    char command[11]= "";
-
-    command[0] = RECTANGLE;
-
-    command[1] = (x1 >> 8) & 0xFF;
-    command[2] = x1 & 0xFF;
-
-    command[3] = (y1 >> 8) & 0xFF;
-    command[4] = y1 & 0xFF;
-
-    command[5] = (x2 >> 8) & 0xFF;
-    command[6] = x2 & 0xFF;
-
-    command[7] = (y2 >> 8) & 0xFF;
-    command[8] = y2 & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
-
-    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
-    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 11);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) {   // draw an ellipse
-    char command[11]= "";
-
-    command[0] = ELLIPSE;
-
-    command[1] = (x >> 8) & 0xFF;
-    command[2] = x & 0xFF;
-
-    command[3] = (y >> 8) & 0xFF;
-    command[4] = y & 0xFF;
-
-    command[5] = (radius_x >> 8) & 0xFF;
-    command[6] = radius_x & 0xFF;
-
-    command[7] = (radius_y >> 8) & 0xFF;
-    command[8] = radius_y & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
-
-    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
-    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 11);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: pixel(int x, int y, int color) {   // draw a pixel
-    char command[7]= "";
-
-    command[0] = PIXEL;
-
-    command[1] = (x >> 8) & 0xFF;
-    command[2] = x & 0xFF;
-
-    command[3] = (y >> 8) & 0xFF;
-    command[4] = y & 0xFF;
-
-    int red5   = (color >> (16 + 3)) & 0x1F;              // get red on 5 bits
-    int green6 = (color >> (8 + 2))  & 0x3F;              // get green on 6 bits
-    int blue5  = (color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
-
-    command[5] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
-    command[6] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
-
-    writeCOMMAND(command, 7);
-}
-
-//******************************************************************************************************
-int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
-
-    char command[5]= "";
-
-    command[0] = READPIXEL;
-
-    command[1] = (x >> 8) & 0xFF;
-    command[2] = x & 0xFF;
-
-    command[3] = (y >> 8) & 0xFF;
-    command[4] = y & 0xFF;
-
-    int i, temp = 0, color = 0, resp = 0;
-    char response[2] = "";
-
-    freeBUFFER();
-
-    for (i = 0; i < 5; i++) {                   // send all chars to serial port
-        writeBYTE(command[i]);
-    }
-
-    while (!_cmd.readable()) wait_ms(TEMPO);    // wait for screen answer
-
-    while (_cmd.readable()) {
-        temp = _cmd.getc();
-        response[resp++] = (char)temp;
-    }
-
-    color = ((response[0] << 8) + response[1]);
-
-    return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
-}
-
-//******************************************************************************************************
-void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
-
-    char command[13]= "";
-
-    command[0] = SCREENCOPY;
-
-    command[1] = (xs >> 8) & 0xFF;
-    command[2] = xs & 0xFF;
-
-    command[3] = (ys >> 8) & 0xFF;
-    command[4] = ys & 0xFF;
-
-    command[5] = (xd >> 8) & 0xFF;
-    command[6] = xd & 0xFF;
-
-    command[7] = (yd >> 8) & 0xFF;
-    command[8] = yd & 0xFF;
-
-    command[9] = (width >> 8) & 0xFF;
-    command[10] = width & 0xFF;
-
-    command[11] = (height >> 8) & 0xFF;
-    command[12] = height & 0xFF;
-
-    writeCOMMAND(command, 13);
-}
-
-//****************************************************************************************************
-void TFT_4DGL :: pen_size(char mode) {   // set pen to SOLID or WIREFRAME
-    char command[2]= "";
-
-    command[0] = PENSIZE;
-    command[1] = mode;
-
-    writeCOMMAND(command, 2);
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// TFT_4DGL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+#include "TFT_4DGL.h"
+
+
+//****************************************************************************************************
+void TFT_4DGL :: circle(int x, int y , int radius, int color) {   // draw a circle in (x,y)
+    char command[9]= "";
+
+    command[0] = CIRCLE;
+
+    command[1] = (x >> 8) & 0xFF;
+    command[2] = x & 0xFF;
+
+    command[3] = (y >> 8) & 0xFF;
+    command[4] = y & 0xFF;
+
+    command[5] = (radius >> 8) & 0xFF;
+    command[6] = radius & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;              // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;              // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
+
+    command[7] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
+    command[8] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 9);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) {   // draw a traingle
+    char command[15]= "";
+
+    command[0] = TRIANGLE;
+
+    command[1] = (x1 >> 8) & 0xFF;
+    command[2] = x1 & 0xFF;
+
+    command[3] = (y1 >> 8) & 0xFF;
+    command[4] = y1 & 0xFF;
+
+    command[5] = (x2 >> 8) & 0xFF;
+    command[6] = x2 & 0xFF;
+
+    command[7] = (y2 >> 8) & 0xFF;
+    command[8] = y2 & 0xFF;
+
+    command[9] = (x3 >> 8) & 0xFF;
+    command[10] = x3 & 0xFF;
+
+    command[11] = (y3 >> 8) & 0xFF;
+    command[12] = y3 & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
+
+    command[13] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
+    command[14] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 15);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) {   // draw a line
+    char command[11]= "";
+
+    command[0] = LINE;
+
+    command[1] = (x1 >> 8) & 0xFF;
+    command[2] = x1 & 0xFF;
+
+    command[3] = (y1 >> 8) & 0xFF;
+    command[4] = y1 & 0xFF;
+
+    command[5] = (x2 >> 8) & 0xFF;
+    command[6] = x2 & 0xFF;
+
+    command[7] = (y2 >> 8) & 0xFF;
+    command[8] = y2 & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
+
+    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
+    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) {   // draw a rectangle
+    char command[11]= "";
+
+    command[0] = RECTANGLE;
+
+    command[1] = (x1 >> 8) & 0xFF;
+    command[2] = x1 & 0xFF;
+
+    command[3] = (y1 >> 8) & 0xFF;
+    command[4] = y1 & 0xFF;
+
+    command[5] = (x2 >> 8) & 0xFF;
+    command[6] = x2 & 0xFF;
+
+    command[7] = (y2 >> 8) & 0xFF;
+    command[8] = y2 & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
+
+    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
+    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) {   // draw an ellipse
+    char command[11]= "";
+
+    command[0] = ELLIPSE;
+
+    command[1] = (x >> 8) & 0xFF;
+    command[2] = x & 0xFF;
+
+    command[3] = (y >> 8) & 0xFF;
+    command[4] = y & 0xFF;
+
+    command[5] = (radius_x >> 8) & 0xFF;
+    command[6] = radius_x & 0xFF;
+
+    command[7] = (radius_y >> 8) & 0xFF;
+    command[8] = radius_y & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;               // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;               // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;               // get blue on 5 bits
+
+    command[9] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;   // first part of 16 bits color
+    command[10] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 11);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: pixel(int x, int y, int color) {   // draw a pixel
+    char command[7]= "";
+
+    command[0] = PIXEL;
+
+    command[1] = (x >> 8) & 0xFF;
+    command[2] = x & 0xFF;
+
+    command[3] = (y >> 8) & 0xFF;
+    command[4] = y & 0xFF;
+
+    int red5   = (color >> (16 + 3)) & 0x1F;              // get red on 5 bits
+    int green6 = (color >> (8 + 2))  & 0x3F;              // get green on 6 bits
+    int blue5  = (color >> (0 + 3))  & 0x1F;              // get blue on 5 bits
+
+    command[5] = ((red5 << 3)   + (green6 >> 3)) & 0xFF;  // first part of 16 bits color
+    command[6] = ((green6 << 5) + (blue5 >>  0)) & 0xFF;  // second part of 16 bits color
+
+    writeCOMMAND(command, 7);
+}
+
+//******************************************************************************************************
+int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data
+
+    char command[5]= "";
+
+    command[0] = READPIXEL;
+
+    command[1] = (x >> 8) & 0xFF;
+    command[2] = x & 0xFF;
+
+    command[3] = (y >> 8) & 0xFF;
+    command[4] = y & 0xFF;
+
+    int i, temp = 0, color = 0, resp = 0;
+    char response[2] = "";
+
+    freeBUFFER();
+
+    for (i = 0; i < 5; i++) {                   // send all chars to serial port
+        writeBYTE(command[i]);
+    }
+
+    while (!_cmd.readable()) wait_ms(TEMPO);    // wait for screen answer
+
+    while (_cmd.readable()) {
+        temp = _cmd.getc();
+        response[resp++] = (char)temp;
+    }
+
+    color = ((response[0] << 8) + response[1]);
+
+    return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
+}
+
+//******************************************************************************************************
+void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) {
+
+    char command[13]= "";
+
+    command[0] = SCREENCOPY;
+
+    command[1] = (xs >> 8) & 0xFF;
+    command[2] = xs & 0xFF;
+
+    command[3] = (ys >> 8) & 0xFF;
+    command[4] = ys & 0xFF;
+
+    command[5] = (xd >> 8) & 0xFF;
+    command[6] = xd & 0xFF;
+
+    command[7] = (yd >> 8) & 0xFF;
+    command[8] = yd & 0xFF;
+
+    command[9] = (width >> 8) & 0xFF;
+    command[10] = width & 0xFF;
+
+    command[11] = (height >> 8) & 0xFF;
+    command[12] = height & 0xFF;
+
+    writeCOMMAND(command, 13);
+}
+
+//****************************************************************************************************
+void TFT_4DGL :: pen_size(char mode) {   // set pen to SOLID or WIREFRAME
+    char command[2]= "";
+
+    command[0] = PENSIZE;
+    command[1] = mode;
+
+    writeCOMMAND(command, 2);
 }
\ No newline at end of file