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