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