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

Committer:
4180_1
Date:
Thu Feb 24 15:14:36 2011 +0000
Revision:
0:e25ba425dc7b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:e25ba425dc7b 1 //
4180_1 0:e25ba425dc7b 2 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
4180_1 0:e25ba425dc7b 3 //
4180_1 0:e25ba425dc7b 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
4180_1 0:e25ba425dc7b 5 //
4180_1 0:e25ba425dc7b 6 // TFT_4DGL is free software: you can redistribute it and/or modify
4180_1 0:e25ba425dc7b 7 // it under the terms of the GNU General Public License as published by
4180_1 0:e25ba425dc7b 8 // the Free Software Foundation, either version 3 of the License, or
4180_1 0:e25ba425dc7b 9 // (at your option) any later version.
4180_1 0:e25ba425dc7b 10 //
4180_1 0:e25ba425dc7b 11 // TFT_4DGL is distributed in the hope that it will be useful,
4180_1 0:e25ba425dc7b 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4180_1 0:e25ba425dc7b 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4180_1 0:e25ba425dc7b 14 // GNU General Public License for more details.
4180_1 0:e25ba425dc7b 15 //
4180_1 0:e25ba425dc7b 16 // You should have received a copy of the GNU General Public License
4180_1 0:e25ba425dc7b 17 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
4180_1 0:e25ba425dc7b 18
4180_1 0:e25ba425dc7b 19 // @author Stephane Rochon
4180_1 0:e25ba425dc7b 20
4180_1 0:e25ba425dc7b 21 #include "mbed.h"
4180_1 0:e25ba425dc7b 22
4180_1 0:e25ba425dc7b 23 // Debug Verbose on terminal enabled
4180_1 0:e25ba425dc7b 24 #ifndef DEBUGMODE
4180_1 0:e25ba425dc7b 25 #define DEBUGMODE 1
4180_1 0:e25ba425dc7b 26 #endif
4180_1 0:e25ba425dc7b 27
4180_1 0:e25ba425dc7b 28 // Common WAIT value in millisecond
4180_1 0:e25ba425dc7b 29 #define TEMPO 5
4180_1 0:e25ba425dc7b 30
4180_1 0:e25ba425dc7b 31 // 4DGL Functions values
4180_1 0:e25ba425dc7b 32 #define AUTOBAUD '\x55'
4180_1 0:e25ba425dc7b 33 #define CLS '\x45'
4180_1 0:e25ba425dc7b 34 #define BAUDRATE '\x51'
4180_1 0:e25ba425dc7b 35 #define VERSION '\x56'
4180_1 0:e25ba425dc7b 36 #define BCKGDCOLOR '\x42'
4180_1 0:e25ba425dc7b 37 #define DISPCONTROL '\x59'
4180_1 0:e25ba425dc7b 38 #define SETVOLUME '\x76'
4180_1 0:e25ba425dc7b 39 #define CIRCLE '\x43'
4180_1 0:e25ba425dc7b 40 #define TRIANGLE '\x47'
4180_1 0:e25ba425dc7b 41 #define LINE '\x4C'
4180_1 0:e25ba425dc7b 42 #define RECTANGLE '\x72'
4180_1 0:e25ba425dc7b 43 #define ELLIPSE '\x65'
4180_1 0:e25ba425dc7b 44 #define PIXEL '\x50'
4180_1 0:e25ba425dc7b 45 #define READPIXEL '\x52'
4180_1 0:e25ba425dc7b 46 #define SCREENCOPY '\x63'
4180_1 0:e25ba425dc7b 47 #define PENSIZE '\x70'
4180_1 0:e25ba425dc7b 48 #define SETFONT '\x46'
4180_1 0:e25ba425dc7b 49 #define TEXTMODE '\x4F'
4180_1 0:e25ba425dc7b 50 #define TEXTCHAR '\x54'
4180_1 0:e25ba425dc7b 51 #define GRAPHCHAR '\x74'
4180_1 0:e25ba425dc7b 52 #define TEXTSTRING '\x73'
4180_1 0:e25ba425dc7b 53 #define GRAPHSTRING '\x53'
4180_1 0:e25ba425dc7b 54 #define TEXTBUTTON '\x62'
4180_1 0:e25ba425dc7b 55 #define GETTOUCH '\x6F'
4180_1 0:e25ba425dc7b 56 #define WAITTOUCH '\x77'
4180_1 0:e25ba425dc7b 57 #define SETTOUCH '\x75'
4180_1 0:e25ba425dc7b 58
4180_1 0:e25ba425dc7b 59
4180_1 0:e25ba425dc7b 60 // Screen answers
4180_1 0:e25ba425dc7b 61 #define ACK '\x06'
4180_1 0:e25ba425dc7b 62 #define NAK '\x15'
4180_1 0:e25ba425dc7b 63
4180_1 0:e25ba425dc7b 64 // Screen states
4180_1 0:e25ba425dc7b 65 #define OFF '\x00'
4180_1 0:e25ba425dc7b 66 #define ON '\x01'
4180_1 0:e25ba425dc7b 67
4180_1 0:e25ba425dc7b 68 // Graphics modes
4180_1 0:e25ba425dc7b 69 #define SOLID '\x00'
4180_1 0:e25ba425dc7b 70 #define WIREFRAME '\x01'
4180_1 0:e25ba425dc7b 71
4180_1 0:e25ba425dc7b 72 // Text modes
4180_1 0:e25ba425dc7b 73 #define TRANSPARENT '\x00'
4180_1 0:e25ba425dc7b 74 #define OPAQUE '\x01'
4180_1 0:e25ba425dc7b 75
4180_1 0:e25ba425dc7b 76 // Fonts Sizes
4180_1 0:e25ba425dc7b 77 #define FONT_5X7 '\x00'
4180_1 0:e25ba425dc7b 78 #define FONT_8X8 '\x01'
4180_1 0:e25ba425dc7b 79 #define FONT_8X12 '\x02'
4180_1 0:e25ba425dc7b 80 #define FONT_12X16 '\x03'
4180_1 0:e25ba425dc7b 81
4180_1 0:e25ba425dc7b 82 // Touch Values
4180_1 0:e25ba425dc7b 83 #define WAIT '\x00'
4180_1 0:e25ba425dc7b 84 #define PRESS '\x01'
4180_1 0:e25ba425dc7b 85 #define RELEASE '\x02'
4180_1 0:e25ba425dc7b 86 #define MOVE '\x03'
4180_1 0:e25ba425dc7b 87 #define STATUS '\x04'
4180_1 0:e25ba425dc7b 88 #define GETPOSITION '\x05'
4180_1 0:e25ba425dc7b 89
4180_1 0:e25ba425dc7b 90 // Data speed
4180_1 0:e25ba425dc7b 91 #define BAUD_110 '\x00'
4180_1 0:e25ba425dc7b 92 #define BAUD_300 '\x01'
4180_1 0:e25ba425dc7b 93 #define BAUD_600 '\x02'
4180_1 0:e25ba425dc7b 94 #define BAUD_1200 '\x03'
4180_1 0:e25ba425dc7b 95 #define BAUD_2400 '\x04'
4180_1 0:e25ba425dc7b 96 #define BAUD_4800 '\x05'
4180_1 0:e25ba425dc7b 97 #define BAUD_9600 '\x06'
4180_1 0:e25ba425dc7b 98 #define BAUD_14400 '\x07'
4180_1 0:e25ba425dc7b 99 #define BAUD_19200 '\x09'
4180_1 0:e25ba425dc7b 100 #define BAUD_31250 '\x09'
4180_1 0:e25ba425dc7b 101 #define BAUD_38400 '\x0A'
4180_1 0:e25ba425dc7b 102 #define BAUD_56000 '\x0B'
4180_1 0:e25ba425dc7b 103 #define BAUD_57600 '\x0C'
4180_1 0:e25ba425dc7b 104 #define BAUD_115200 '\x0D'
4180_1 0:e25ba425dc7b 105 #define BAUD_128000 '\x0E'
4180_1 0:e25ba425dc7b 106 #define BAUD_256000 '\x0F'
4180_1 0:e25ba425dc7b 107
4180_1 0:e25ba425dc7b 108 // Defined Colors
4180_1 0:e25ba425dc7b 109 #define WHITE 0xFFFFFF
4180_1 0:e25ba425dc7b 110 #define BLACK 0x000000
4180_1 0:e25ba425dc7b 111 #define RED 0xFF0000
4180_1 0:e25ba425dc7b 112 #define GREEN 0x00FF00
4180_1 0:e25ba425dc7b 113 #define BLUE 0x0000FF
4180_1 0:e25ba425dc7b 114 #define LGREY 0xBFBFBF
4180_1 0:e25ba425dc7b 115 #define DGREY 0x5F5F5F
4180_1 0:e25ba425dc7b 116
4180_1 0:e25ba425dc7b 117 // Mode data
4180_1 0:e25ba425dc7b 118 #define BACKLIGHT '\x00'
4180_1 0:e25ba425dc7b 119 #define DISPLAY '\x01'
4180_1 0:e25ba425dc7b 120 #define CONTRAST '\x02'
4180_1 0:e25ba425dc7b 121 #define POWER '\x03'
4180_1 0:e25ba425dc7b 122 #define ORIENTATION '\x04'
4180_1 0:e25ba425dc7b 123 #define TOUCH_CTRL '\x05'
4180_1 0:e25ba425dc7b 124 #define IMAGE_FORMAT '\x06'
4180_1 0:e25ba425dc7b 125 #define PROTECT_FAT '\x08'
4180_1 0:e25ba425dc7b 126 #define SCREEN_RES '\x0C'
4180_1 0:e25ba425dc7b 127
4180_1 0:e25ba425dc7b 128 // change this to your specific screen (newer versions) if needed
4180_1 0:e25ba425dc7b 129 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
4180_1 0:e25ba425dc7b 130 #define SIZE_X 480
4180_1 0:e25ba425dc7b 131 #define SIZE_Y 640
4180_1 0:e25ba425dc7b 132
4180_1 0:e25ba425dc7b 133 #define IS_LANDSCAPE 0
4180_1 0:e25ba425dc7b 134 #define IS_PORTRAIT 1
4180_1 0:e25ba425dc7b 135
4180_1 0:e25ba425dc7b 136 // Screen orientation
4180_1 0:e25ba425dc7b 137 #define LANDSCAPE '\x01'
4180_1 0:e25ba425dc7b 138 #define LANDSCAPE_R '\x02'
4180_1 0:e25ba425dc7b 139 #define PORTRAIT '\x03'
4180_1 0:e25ba425dc7b 140 #define PORTRAIT_R '\x04'
4180_1 0:e25ba425dc7b 141
4180_1 0:e25ba425dc7b 142 // Parameters
4180_1 0:e25ba425dc7b 143 #define ENABLE '\x00'
4180_1 0:e25ba425dc7b 144 #define DISABLE '\x01'
4180_1 0:e25ba425dc7b 145 #define RESET '\x02'
4180_1 0:e25ba425dc7b 146
4180_1 0:e25ba425dc7b 147 #define NEW '\x00'
4180_1 0:e25ba425dc7b 148 #define OLD '\x01'
4180_1 0:e25ba425dc7b 149
4180_1 0:e25ba425dc7b 150 #define DOWN '\x00'
4180_1 0:e25ba425dc7b 151 #define UP '\x01'
4180_1 0:e25ba425dc7b 152
4180_1 0:e25ba425dc7b 153 #define PROTECT '\x00'
4180_1 0:e25ba425dc7b 154 #define UNPROTECT '\x02'
4180_1 0:e25ba425dc7b 155
4180_1 0:e25ba425dc7b 156 //**************************************************************************
4180_1 0:e25ba425dc7b 157 // \class TFT_4DGL TFT_4DGL.h
4180_1 0:e25ba425dc7b 158 // \brief This is the main class. It shoud be used like this : TFT_4GDL myLCD(p9,p10,p11);
4180_1 0:e25ba425dc7b 159 /**
4180_1 0:e25ba425dc7b 160 Example:
4180_1 0:e25ba425dc7b 161 * @code
4180_1 0:e25ba425dc7b 162 * // Display a white circle on the screen
4180_1 0:e25ba425dc7b 163 * #include "mbed.h"
4180_1 0:e25ba425dc7b 164 * #include " TFT_4DGL.h"
4180_1 0:e25ba425dc7b 165 *
4180_1 0:e25ba425dc7b 166 * TFT_4GDL myLCD(p9,p10,p11);
4180_1 0:e25ba425dc7b 167 *
4180_1 0:e25ba425dc7b 168 * int main() {
4180_1 0:e25ba425dc7b 169 * myLCD.circle(120, 160, 80, WHITE);
4180_1 0:e25ba425dc7b 170 * }
4180_1 0:e25ba425dc7b 171 * @endcode
4180_1 0:e25ba425dc7b 172 */
4180_1 0:e25ba425dc7b 173
4180_1 0:e25ba425dc7b 174 class TFT_4DGL {
4180_1 0:e25ba425dc7b 175
4180_1 0:e25ba425dc7b 176 public :
4180_1 0:e25ba425dc7b 177
4180_1 0:e25ba425dc7b 178 TFT_4DGL(PinName tx, PinName rx, PinName rst);
4180_1 0:e25ba425dc7b 179
4180_1 0:e25ba425dc7b 180 // General Commands
4180_1 0:e25ba425dc7b 181 void cls();
4180_1 0:e25ba425dc7b 182 void reset();
4180_1 0:e25ba425dc7b 183 void autobaud();
4180_1 0:e25ba425dc7b 184 void baudrate(int);
4180_1 0:e25ba425dc7b 185 void background_color(int);
4180_1 0:e25ba425dc7b 186 void display_control(char, char);
4180_1 0:e25ba425dc7b 187 void set_volume(char);
4180_1 0:e25ba425dc7b 188
4180_1 0:e25ba425dc7b 189 // Graphics Commands
4180_1 0:e25ba425dc7b 190 void circle(int, int, int, int);
4180_1 0:e25ba425dc7b 191 void triangle(int, int, int, int, int, int, int);
4180_1 0:e25ba425dc7b 192 void line(int, int, int, int, int);
4180_1 0:e25ba425dc7b 193 void rectangle(int, int, int, int, int);
4180_1 0:e25ba425dc7b 194 void ellipse(int, int, int, int, int);
4180_1 0:e25ba425dc7b 195 void pixel(int, int, int);
4180_1 0:e25ba425dc7b 196 int read_pixel(int, int);
4180_1 0:e25ba425dc7b 197 void screen_copy(int, int, int, int, int, int);
4180_1 0:e25ba425dc7b 198 void pen_size(char);
4180_1 0:e25ba425dc7b 199
4180_1 0:e25ba425dc7b 200 // Texts Commands
4180_1 0:e25ba425dc7b 201 void set_font(char);
4180_1 0:e25ba425dc7b 202 void text_mode(char);
4180_1 0:e25ba425dc7b 203 void text_char(char, char, char, int);
4180_1 0:e25ba425dc7b 204 void graphic_char(char, int, int, int, char, char);
4180_1 0:e25ba425dc7b 205 void text_string(char *, char, char, char, int);
4180_1 0:e25ba425dc7b 206 void graphic_string(char *, int, int, char, int, char, char);
4180_1 0:e25ba425dc7b 207 void text_button(char *, char, int, int, int, char, int, char, char);
4180_1 0:e25ba425dc7b 208
4180_1 0:e25ba425dc7b 209 void locate(char, char);
4180_1 0:e25ba425dc7b 210 void color(int);
4180_1 0:e25ba425dc7b 211 void putc(char);
4180_1 0:e25ba425dc7b 212 void puts(char *);
4180_1 0:e25ba425dc7b 213
4180_1 0:e25ba425dc7b 214 // Touch Command
4180_1 0:e25ba425dc7b 215 void touch_mode(char);
4180_1 0:e25ba425dc7b 216 void get_touch(int *, int *);
4180_1 0:e25ba425dc7b 217 void wait_touch(int);
4180_1 0:e25ba425dc7b 218 void set_touch(int, int, int, int);
4180_1 0:e25ba425dc7b 219 int touch_status(void);
4180_1 0:e25ba425dc7b 220
4180_1 0:e25ba425dc7b 221 // Screen Data
4180_1 0:e25ba425dc7b 222 int type;
4180_1 0:e25ba425dc7b 223 int revision;
4180_1 0:e25ba425dc7b 224 int firmware;
4180_1 0:e25ba425dc7b 225 int reserved1;
4180_1 0:e25ba425dc7b 226 int reserved2;
4180_1 0:e25ba425dc7b 227
4180_1 0:e25ba425dc7b 228 // Text data
4180_1 0:e25ba425dc7b 229 char current_col;
4180_1 0:e25ba425dc7b 230 char current_row;
4180_1 0:e25ba425dc7b 231 int current_color;
4180_1 0:e25ba425dc7b 232 char current_font;
4180_1 0:e25ba425dc7b 233 char current_orientation;
4180_1 0:e25ba425dc7b 234 char max_col;
4180_1 0:e25ba425dc7b 235 char max_row;
4180_1 0:e25ba425dc7b 236
4180_1 0:e25ba425dc7b 237 protected :
4180_1 0:e25ba425dc7b 238
4180_1 0:e25ba425dc7b 239 Serial _cmd;
4180_1 0:e25ba425dc7b 240 DigitalOut _rst;
4180_1 0:e25ba425dc7b 241
4180_1 0:e25ba425dc7b 242 void freeBUFFER (void);
4180_1 0:e25ba425dc7b 243 void writeBYTE (char);
4180_1 0:e25ba425dc7b 244 int writeCOMMAND(char *, int);
4180_1 0:e25ba425dc7b 245 int readVERSION (char *, int);
4180_1 0:e25ba425dc7b 246 void getTOUCH (char *, int, int *,int *);
4180_1 0:e25ba425dc7b 247 int getSTATUS (char *, int);
4180_1 0:e25ba425dc7b 248 void version (void);
4180_1 0:e25ba425dc7b 249 };
4180_1 0:e25ba425dc7b 250
4180_1 0:e25ba425dc7b 251 typedef unsigned char BYTE;