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