For uVGAII WebBrowser

Fork of 4DGL by Stephane ROCHON

Committer:
Kerpower
Date:
Sun Oct 17 10:11:49 2010 +0000
Revision:
6:d0dca0ddc329
Parent:
5:52d54f5b52cd
Child:
7:38db58dc6f4d

        

Who changed what in which revision?

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