a version of 4DGL with a minor change for the uVGAII 640 by 480 res

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TFT_4DGL.h Source File

TFT_4DGL.h

00001 //
00002 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
00003 //
00004 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
00005 //
00006 // TFT_4DGL is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // TFT_4DGL is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 // @author Stephane Rochon
00020 
00021 #include "mbed.h"
00022 
00023 // Debug Verbose on terminal enabled
00024 #ifndef DEBUGMODE
00025 #define DEBUGMODE 1
00026 #endif
00027 
00028 // Common WAIT value in millisecond
00029 #define TEMPO 5
00030 
00031 // 4DGL Functions values
00032 #define AUTOBAUD     '\x55'
00033 #define CLS          '\x45'
00034 #define BAUDRATE     '\x51'
00035 #define VERSION      '\x56'
00036 #define BCKGDCOLOR   '\x42'
00037 #define DISPCONTROL  '\x59'
00038 #define SETVOLUME    '\x76'
00039 #define CIRCLE       '\x43'
00040 #define TRIANGLE     '\x47'
00041 #define LINE         '\x4C'
00042 #define RECTANGLE    '\x72'
00043 #define ELLIPSE      '\x65'
00044 #define PIXEL        '\x50'
00045 #define READPIXEL    '\x52'
00046 #define SCREENCOPY   '\x63'
00047 #define PENSIZE      '\x70'
00048 #define SETFONT      '\x46'
00049 #define TEXTMODE     '\x4F'
00050 #define TEXTCHAR     '\x54'
00051 #define GRAPHCHAR    '\x74'
00052 #define TEXTSTRING   '\x73'
00053 #define GRAPHSTRING  '\x53'
00054 #define TEXTBUTTON   '\x62'
00055 #define GETTOUCH     '\x6F'
00056 #define WAITTOUCH    '\x77'
00057 #define SETTOUCH     '\x75'
00058 
00059 
00060 // Screen answers
00061 #define ACK          '\x06'
00062 #define NAK          '\x15'
00063 
00064 // Screen states
00065 #define OFF          '\x00'
00066 #define ON           '\x01'
00067 
00068 // Graphics modes
00069 #define SOLID        '\x00'
00070 #define WIREFRAME    '\x01'
00071 
00072 // Text modes
00073 #define TRANSPARENT  '\x00'
00074 #define OPAQUE       '\x01'
00075 
00076 // Fonts Sizes
00077 #define FONT_5X7     '\x00'
00078 #define FONT_8X8     '\x01'
00079 #define FONT_8X12    '\x02'
00080 #define FONT_12X16   '\x03'
00081 
00082 // Touch Values
00083 #define WAIT         '\x00'
00084 #define PRESS        '\x01'
00085 #define RELEASE      '\x02'
00086 #define MOVE         '\x03'
00087 #define STATUS       '\x04'
00088 #define GETPOSITION  '\x05'
00089 
00090 // Data speed
00091 #define BAUD_110     '\x00'
00092 #define BAUD_300     '\x01'
00093 #define BAUD_600     '\x02'
00094 #define BAUD_1200    '\x03'
00095 #define BAUD_2400    '\x04'
00096 #define BAUD_4800    '\x05'
00097 #define BAUD_9600    '\x06'
00098 #define BAUD_14400   '\x07'
00099 #define BAUD_19200   '\x09'
00100 #define BAUD_31250   '\x09'
00101 #define BAUD_38400   '\x0A'
00102 #define BAUD_56000   '\x0B'
00103 #define BAUD_57600   '\x0C'
00104 #define BAUD_115200  '\x0D'
00105 #define BAUD_128000  '\x0E'
00106 #define BAUD_256000  '\x0F'
00107 
00108 // Defined Colors
00109 #define WHITE 0xFFFFFF
00110 #define BLACK 0x000000
00111 #define RED   0xFF0000
00112 #define GREEN 0x00FF00
00113 #define BLUE  0x0000FF
00114 #define LGREY 0xBFBFBF
00115 #define DGREY 0x5F5F5F
00116 
00117 // Mode data
00118 #define BACKLIGHT    '\x00'
00119 #define DISPLAY      '\x01'
00120 #define CONTRAST     '\x02'
00121 #define POWER        '\x03'
00122 #define ORIENTATION  '\x04'
00123 #define TOUCH_CTRL   '\x05'
00124 #define IMAGE_FORMAT '\x06'
00125 #define PROTECT_FAT  '\x08'
00126 #define SCREEN_RES   '\x0C'
00127 
00128 // change this to your specific screen (newer versions) if needed
00129 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
00130 #define SIZE_X       480
00131 #define SIZE_Y       640
00132 
00133 #define IS_LANDSCAPE 0
00134 #define IS_PORTRAIT  1
00135 
00136 // Screen orientation
00137 #define LANDSCAPE    '\x01'
00138 #define LANDSCAPE_R  '\x02'
00139 #define PORTRAIT     '\x03'
00140 #define PORTRAIT_R   '\x04'
00141 
00142 // Parameters
00143 #define ENABLE       '\x00'
00144 #define DISABLE      '\x01'
00145 #define RESET        '\x02'
00146 
00147 #define NEW          '\x00'
00148 #define OLD          '\x01'
00149 
00150 #define DOWN         '\x00'
00151 #define UP           '\x01'
00152 
00153 #define PROTECT      '\x00'
00154 #define UNPROTECT    '\x02'
00155 
00156 //**************************************************************************
00157 // \class TFT_4DGL TFT_4DGL.h
00158 // \brief This is the main class. It shoud be used like this : TFT_4GDL myLCD(p9,p10,p11);
00159 /**
00160 Example:
00161 * @code
00162 * // Display a white circle on the screen
00163 * #include "mbed.h"
00164 * #include " TFT_4DGL.h"
00165 * 
00166 * TFT_4GDL myLCD(p9,p10,p11);
00167 * 
00168 * int main() {
00169 *     myLCD.circle(120, 160, 80, WHITE);
00170 * }
00171 * @endcode
00172 */
00173 
00174 class TFT_4DGL {
00175 
00176 public :
00177 
00178     TFT_4DGL(PinName tx, PinName rx, PinName rst);
00179 
00180 // General Commands
00181     void cls();
00182     void reset();
00183     void autobaud();
00184     void baudrate(int);
00185     void background_color(int);
00186     void display_control(char, char);
00187     void set_volume(char);
00188 
00189 // Graphics Commands
00190     void circle(int, int, int, int);
00191     void triangle(int, int, int, int, int, int, int);
00192     void line(int, int, int, int, int);
00193     void rectangle(int, int, int, int, int);
00194     void ellipse(int, int, int, int, int);
00195     void pixel(int, int, int);
00196     int  read_pixel(int, int);
00197     void screen_copy(int, int, int, int, int, int);
00198     void pen_size(char);
00199 
00200 // Texts Commands
00201     void set_font(char);
00202     void text_mode(char);
00203     void text_char(char, char, char, int);
00204     void graphic_char(char, int, int, int, char, char);
00205     void text_string(char *, char, char, char, int);
00206     void graphic_string(char *, int, int, char, int, char, char);
00207     void text_button(char *, char, int, int, int, char, int, char, char);
00208 
00209     void locate(char, char);
00210     void color(int);
00211     void putc(char);
00212     void puts(char *);
00213 
00214 // Touch Command
00215     void touch_mode(char);
00216     void get_touch(int *, int *);
00217     void wait_touch(int);
00218     void set_touch(int, int, int, int);
00219     int  touch_status(void);
00220 
00221 // Screen Data
00222     int type;
00223     int revision;
00224     int firmware;
00225     int reserved1;
00226     int reserved2;
00227 
00228 // Text data
00229     char current_col;
00230     char current_row;
00231     int  current_color;
00232     char current_font;
00233     char current_orientation;
00234     char max_col;
00235     char max_row;
00236 
00237 protected :
00238 
00239     Serial     _cmd;
00240     DigitalOut _rst;
00241 
00242     void freeBUFFER  (void);
00243     void writeBYTE   (char);
00244     int  writeCOMMAND(char *, int);
00245     int  readVERSION (char *, int);
00246     void getTOUCH    (char *, int, int *,int *);
00247     int  getSTATUS   (char *, int);
00248     void version     (void);
00249 };
00250 
00251 typedef unsigned char BYTE;