uVGA II for display using vga

Dependents:   4DGL

Committer:
pprasad7
Date:
Thu Oct 11 20:12:02 2012 +0000
Revision:
0:6741e7724181
hangman

Who changed what in which revision?

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