For uVGAII WebBrowser
Fork of 4DGL by
TFT_4DGL.h@5:52d54f5b52cd, 2010-10-17 (annotated)
- Committer:
- Kerpower
- Date:
- Sun Oct 17 09:53:50 2010 +0000
- Revision:
- 5:52d54f5b52cd
- Parent:
- 4:6726016634ab
- Child:
- 6:d0dca0ddc329
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:6726016634ab | 181 | /** Clear screen |
Kerpower | 4:6726016634ab | 182 | */ |
Kerpower | 0:1102d253f057 | 183 | void cls(); |
Kerpower | 4:6726016634ab | 184 | |
Kerpower | 4:6726016634ab | 185 | /** Reset screen |
Kerpower | 4:6726016634ab | 186 | */ |
Kerpower | 0:1102d253f057 | 187 | void reset(); |
Kerpower | 4:6726016634ab | 188 | /** Launch Autobaud for serial communication |
Kerpower | 4:6726016634ab | 189 | */ |
Kerpower | 0:1102d253f057 | 190 | void autobaud(); |
Kerpower | 5:52d54f5b52cd | 191 | /** Set serial Baud rate (both sides : screen and mbed) |
Kerpower | 4:6726016634ab | 192 | * |
Kerpower | 4:6726016634ab | 193 | * @param Speed Correct BAUD value (see TFT_4DGL.h) |
Kerpower | 4:6726016634ab | 194 | */ |
Kerpower | 5:52d54f5b52cd | 195 | void baudrate(int speed); |
Kerpower | 4:6726016634ab | 196 | |
Kerpower | 5:52d54f5b52cd | 197 | /** Set background color to the specified value |
Kerpower | 5:52d54f5b52cd | 198 | * |
Kerpower | 5:52d54f5b52cd | 199 | * @param color in HEX RGB like 0xFF00FF |
Kerpower | 5:52d54f5b52cd | 200 | */ |
Kerpower | 5:52d54f5b52cd | 201 | void background_color(int color); |
Kerpower | 4:6726016634ab | 202 | |
Kerpower | 0:1102d253f057 | 203 | void display_control(char, char); |
Kerpower | 4:6726016634ab | 204 | |
Kerpower | 0:1102d253f057 | 205 | void set_volume(char); |
Kerpower | 0:1102d253f057 | 206 | |
Kerpower | 0:1102d253f057 | 207 | // Graphics Commands |
Kerpower | 0:1102d253f057 | 208 | void circle(int, int, int, int); |
Kerpower | 0:1102d253f057 | 209 | void triangle(int, int, int, int, int, int, int); |
Kerpower | 0:1102d253f057 | 210 | void line(int, int, int, int, int); |
Kerpower | 0:1102d253f057 | 211 | void rectangle(int, int, int, int, int); |
Kerpower | 0:1102d253f057 | 212 | void ellipse(int, int, int, int, int); |
Kerpower | 0:1102d253f057 | 213 | void pixel(int, int, int); |
Kerpower | 0:1102d253f057 | 214 | int read_pixel(int, int); |
Kerpower | 0:1102d253f057 | 215 | void screen_copy(int, int, int, int, int, int); |
Kerpower | 0:1102d253f057 | 216 | void pen_size(char); |
Kerpower | 0:1102d253f057 | 217 | |
Kerpower | 0:1102d253f057 | 218 | // Texts Commands |
Kerpower | 0:1102d253f057 | 219 | void set_font(char); |
Kerpower | 0:1102d253f057 | 220 | void text_mode(char); |
Kerpower | 0:1102d253f057 | 221 | void text_char(char, char, char, int); |
Kerpower | 0:1102d253f057 | 222 | void graphic_char(char, int, int, int, char, char); |
Kerpower | 0:1102d253f057 | 223 | void text_string(char *, char, char, char, int); |
Kerpower | 0:1102d253f057 | 224 | void graphic_string(char *, int, int, char, int, char, char); |
Kerpower | 0:1102d253f057 | 225 | void text_button(char *, char, int, int, int, char, int, char, char); |
Kerpower | 0:1102d253f057 | 226 | |
Kerpower | 0:1102d253f057 | 227 | void locate(char, char); |
Kerpower | 0:1102d253f057 | 228 | void color(int); |
Kerpower | 0:1102d253f057 | 229 | void putc(char); |
Kerpower | 0:1102d253f057 | 230 | void puts(char *); |
Kerpower | 0:1102d253f057 | 231 | |
Kerpower | 0:1102d253f057 | 232 | // Touch Command |
Kerpower | 0:1102d253f057 | 233 | void touch_mode(char); |
Kerpower | 0:1102d253f057 | 234 | void get_touch(int *, int *); |
Kerpower | 0:1102d253f057 | 235 | void wait_touch(int); |
Kerpower | 0:1102d253f057 | 236 | void set_touch(int, int, int, int); |
Kerpower | 0:1102d253f057 | 237 | int touch_status(void); |
Kerpower | 0:1102d253f057 | 238 | |
Kerpower | 0:1102d253f057 | 239 | // Screen Data |
Kerpower | 0:1102d253f057 | 240 | int type; |
Kerpower | 0:1102d253f057 | 241 | int revision; |
Kerpower | 0:1102d253f057 | 242 | int firmware; |
Kerpower | 0:1102d253f057 | 243 | int reserved1; |
Kerpower | 0:1102d253f057 | 244 | int reserved2; |
Kerpower | 0:1102d253f057 | 245 | |
Kerpower | 0:1102d253f057 | 246 | // Text data |
Kerpower | 0:1102d253f057 | 247 | char current_col; |
Kerpower | 0:1102d253f057 | 248 | char current_row; |
Kerpower | 0:1102d253f057 | 249 | int current_color; |
Kerpower | 0:1102d253f057 | 250 | char current_font; |
Kerpower | 0:1102d253f057 | 251 | char current_orientation; |
Kerpower | 0:1102d253f057 | 252 | char max_col; |
Kerpower | 0:1102d253f057 | 253 | char max_row; |
Kerpower | 0:1102d253f057 | 254 | |
Kerpower | 0:1102d253f057 | 255 | protected : |
Kerpower | 0:1102d253f057 | 256 | |
Kerpower | 0:1102d253f057 | 257 | Serial _cmd; |
Kerpower | 0:1102d253f057 | 258 | DigitalOut _rst; |
Kerpower | 0:1102d253f057 | 259 | |
Kerpower | 0:1102d253f057 | 260 | void freeBUFFER (void); |
Kerpower | 0:1102d253f057 | 261 | void writeBYTE (char); |
Kerpower | 0:1102d253f057 | 262 | int writeCOMMAND(char *, int); |
Kerpower | 0:1102d253f057 | 263 | int readVERSION (char *, int); |
Kerpower | 0:1102d253f057 | 264 | void getTOUCH (char *, int, int *,int *); |
Kerpower | 0:1102d253f057 | 265 | int getSTATUS (char *, int); |
Kerpower | 0:1102d253f057 | 266 | void version (void); |
Kerpower | 0:1102d253f057 | 267 | }; |
Kerpower | 0:1102d253f057 | 268 | |
Kerpower | 0:1102d253f057 | 269 | typedef unsigned char BYTE; |