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