for 4180 final project

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
4180_1
Date:
Fri Nov 22 02:44:37 2013 +0000
Revision:
5:8936798c19a3
Parent:
4:74df7fc26fef
Child:
6:b759b69cbaf9
ver1.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 1:8b656995301f 1 //
4180_1 1:8b656995301f 2 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens
4180_1 1:8b656995301f 3 //
4180_1 1:8b656995301f 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
4180_1 1:8b656995301f 5 //
4180_1 1:8b656995301f 6 // uLCD_4DGL is free software: you can redistribute it and/or modify
4180_1 1:8b656995301f 7 // it under the terms of the GNU General Public License as published by
4180_1 1:8b656995301f 8 // the Free Software Foundation, either version 3 of the License, or
4180_1 1:8b656995301f 9 // (at your option) any later version.
4180_1 1:8b656995301f 10 //
4180_1 1:8b656995301f 11 // uLCD_4DGL is distributed in the hope that it will be useful,
4180_1 1:8b656995301f 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4180_1 1:8b656995301f 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4180_1 1:8b656995301f 14 // GNU General Public License for more details.
4180_1 1:8b656995301f 15 //
4180_1 1:8b656995301f 16 // You should have received a copy of the GNU General Public License
4180_1 1:8b656995301f 17 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
4180_1 1:8b656995301f 18
4180_1 1:8b656995301f 19 // @author Stephane Rochon
4180_1 1:8b656995301f 20
4180_1 1:8b656995301f 21 #include "mbed.h"
4180_1 1:8b656995301f 22
4180_1 1:8b656995301f 23 // Debug Verbose on terminal enabled
4180_1 1:8b656995301f 24 #ifndef DEBUGMODE
4180_1 2:edae99e4abe7 25 #define DEBUGMODE 0
4180_1 1:8b656995301f 26 #endif
4180_1 1:8b656995301f 27
4180_1 1:8b656995301f 28 // Common WAIT value in millisecond
4180_1 4:74df7fc26fef 29 #define TEMPO 0.05
4180_1 1:8b656995301f 30
4180_1 1:8b656995301f 31 // 4DGL Functions values
4180_1 1:8b656995301f 32 #define AUTOBAUD '\x55'
4180_1 1:8b656995301f 33 #define CLS '\xD7'
4180_1 1:8b656995301f 34 #define BAUDRATE '\x0B' //null prefix
4180_1 1:8b656995301f 35 #define VERSION '\x08' //null prefix
4180_1 1:8b656995301f 36 #define BCKGDCOLOR '\x6E'
4180_1 2:edae99e4abe7 37 #define TXTBCKGDCOLOR '\x7E'
4180_1 1:8b656995301f 38 #define DISPCONTROL '\x68'
4180_1 1:8b656995301f 39 #define SETVOLUME '\x76'
4180_1 1:8b656995301f 40 #define CIRCLE '\xCC'
4180_1 1:8b656995301f 41 #define TRIANGLE '\xC9'
4180_1 1:8b656995301f 42 #define LINE '\xD2'
4180_1 1:8b656995301f 43 #define RECTANGLE '\xCE'
4180_1 1:8b656995301f 44 #define ELLIPSE '\x65' //na
4180_1 1:8b656995301f 45 #define PIXEL '\xCB'
4180_1 1:8b656995301f 46 #define READPIXEL '\xCA'
4180_1 1:8b656995301f 47 #define SCREENCOPY '\x63' //na?
4180_1 2:edae99e4abe7 48 #define PENSIZE '\xD8'
4180_1 1:8b656995301f 49 #define SETFONT '\x7D'
4180_1 1:8b656995301f 50 #define TEXTMODE '\x77'
4180_1 5:8936798c19a3 51 #define TEXTBOLD '\x76'
4180_1 5:8936798c19a3 52 #define TEXTITALIC '\x75'
4180_1 5:8936798c19a3 53 #define TEXTINVERSE '\x74'
4180_1 2:edae99e4abe7 54 #define TEXTWIDTH '\x7C'
4180_1 2:edae99e4abe7 55 #define TEXTHEIGHT '\x7B'
4180_1 1:8b656995301f 56 #define TEXTCHAR '\xFE'
4180_1 1:8b656995301f 57 #define GRAPHCHAR '\x74'
4180_1 1:8b656995301f 58 #define TEXTSTRING '\x06' //null prefix
4180_1 1:8b656995301f 59 #define GRAPHSTRING '\x53'
4180_1 1:8b656995301f 60 #define TEXTBUTTON '\x62'
4180_1 1:8b656995301f 61 #define GETTOUCH '\x6F'
4180_1 1:8b656995301f 62 #define WAITTOUCH '\x77'
4180_1 1:8b656995301f 63 #define SETTOUCH '\x75'
4180_1 3:9ba47197d94f 64 #define BLITCOM '\x0A'
4180_1 2:edae99e4abe7 65 #define PUTCHAR '\xFE'
4180_1 1:8b656995301f 66
4180_1 1:8b656995301f 67
4180_1 1:8b656995301f 68 // Screen answers
4180_1 1:8b656995301f 69 #define ACK '\x06'
4180_1 1:8b656995301f 70 #define NAK '\x15'
4180_1 1:8b656995301f 71
4180_1 1:8b656995301f 72 // Screen states
4180_1 1:8b656995301f 73 #define OFF '\x00'
4180_1 1:8b656995301f 74 #define ON '\x01'
4180_1 1:8b656995301f 75
4180_1 1:8b656995301f 76 // Graphics modes
4180_1 1:8b656995301f 77 #define SOLID '\x00'
4180_1 1:8b656995301f 78 #define WIREFRAME '\x01'
4180_1 1:8b656995301f 79
4180_1 1:8b656995301f 80 // Text modes
4180_1 1:8b656995301f 81 #define TRANSPARENT '\x00'
4180_1 1:8b656995301f 82 #define OPAQUE '\x01'
4180_1 1:8b656995301f 83
4180_1 1:8b656995301f 84 // Fonts Sizes
4180_1 2:edae99e4abe7 85 #define FONT_7X8 '\x00' //only builtin font
4180_1 2:edae99e4abe7 86 #define FONT_5X7 '\x04'
4180_1 1:8b656995301f 87 #define FONT_8X8 '\x01'
4180_1 1:8b656995301f 88 #define FONT_8X12 '\x02'
4180_1 1:8b656995301f 89 #define FONT_12X16 '\x03'
4180_1 1:8b656995301f 90
4180_1 1:8b656995301f 91 // Touch Values
4180_1 1:8b656995301f 92 #define WAIT '\x00'
4180_1 1:8b656995301f 93 #define PRESS '\x01'
4180_1 1:8b656995301f 94 #define RELEASE '\x02'
4180_1 1:8b656995301f 95 #define MOVE '\x03'
4180_1 1:8b656995301f 96 #define STATUS '\x04'
4180_1 1:8b656995301f 97 #define GETPOSITION '\x05'
4180_1 1:8b656995301f 98
4180_1 1:8b656995301f 99 // Data speed
4180_1 1:8b656995301f 100 #define BAUD_110 27271
4180_1 1:8b656995301f 101 #define BAUD_300 9999
4180_1 1:8b656995301f 102 #define BAUD_600 4999
4180_1 1:8b656995301f 103 #define BAUD_1200 2499
4180_1 1:8b656995301f 104 #define BAUD_2400 1249
4180_1 1:8b656995301f 105 #define BAUD_4800 624
4180_1 1:8b656995301f 106 #define BAUD_9600 312
4180_1 1:8b656995301f 107 #define BAUD_14400 207
4180_1 1:8b656995301f 108 #define BAUD_19200 155
4180_1 1:8b656995301f 109 #define BAUD_31250 95
4180_1 1:8b656995301f 110 #define BAUD_38400 77
4180_1 1:8b656995301f 111 #define BAUD_56000 53
4180_1 1:8b656995301f 112 #define BAUD_57600 51
4180_1 1:8b656995301f 113 #define BAUD_115200 25
4180_1 1:8b656995301f 114 #define BAUD_128000 22
4180_1 1:8b656995301f 115 #define BAUD_256000 11
4180_1 5:8936798c19a3 116 #define BAUD_300000 10
4180_1 5:8936798c19a3 117 #define BAUD_375000 8
4180_1 5:8936798c19a3 118 #define BAUD_500000 6
4180_1 5:8936798c19a3 119 #define BAUD_600000 4
4180_1 1:8b656995301f 120
4180_1 1:8b656995301f 121 // Defined Colors
4180_1 1:8b656995301f 122 #define WHITE 0xFFFFFF
4180_1 1:8b656995301f 123 #define BLACK 0x000000
4180_1 1:8b656995301f 124 #define RED 0xFF0000
4180_1 1:8b656995301f 125 #define GREEN 0x00FF00
4180_1 1:8b656995301f 126 #define BLUE 0x0000FF
4180_1 1:8b656995301f 127 #define LGREY 0xBFBFBF
4180_1 1:8b656995301f 128 #define DGREY 0x5F5F5F
4180_1 1:8b656995301f 129
4180_1 1:8b656995301f 130 // Mode data
4180_1 1:8b656995301f 131 #define BACKLIGHT '\x00'
4180_1 1:8b656995301f 132 #define DISPLAY '\x01'
4180_1 1:8b656995301f 133 #define CONTRAST '\x02'
4180_1 1:8b656995301f 134 #define POWER '\x03'
4180_1 1:8b656995301f 135 #define ORIENTATION '\x04'
4180_1 1:8b656995301f 136 #define TOUCH_CTRL '\x05'
4180_1 1:8b656995301f 137 #define IMAGE_FORMAT '\x06'
4180_1 1:8b656995301f 138 #define PROTECT_FAT '\x08'
4180_1 1:8b656995301f 139
4180_1 1:8b656995301f 140 // change this to your specific screen (newer versions) if needed
4180_1 1:8b656995301f 141 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
4180_1 1:8b656995301f 142 #define SIZE_X 128
4180_1 1:8b656995301f 143 #define SIZE_Y 128
4180_1 1:8b656995301f 144
4180_1 1:8b656995301f 145 #define IS_LANDSCAPE 0
4180_1 1:8b656995301f 146 #define IS_PORTRAIT 1
4180_1 1:8b656995301f 147
4180_1 1:8b656995301f 148 // Screen orientation
4180_1 1:8b656995301f 149 #define LANDSCAPE '\x01'
4180_1 1:8b656995301f 150 #define LANDSCAPE_R '\x02'
4180_1 1:8b656995301f 151 #define PORTRAIT '\x03'
4180_1 1:8b656995301f 152 #define PORTRAIT_R '\x04'
4180_1 1:8b656995301f 153
4180_1 1:8b656995301f 154 // Parameters
4180_1 1:8b656995301f 155 #define ENABLE '\x00'
4180_1 1:8b656995301f 156 #define DISABLE '\x01'
4180_1 1:8b656995301f 157 #define RESET '\x02'
4180_1 1:8b656995301f 158
4180_1 1:8b656995301f 159 #define NEW '\x00'
4180_1 1:8b656995301f 160 #define OLD '\x01'
4180_1 1:8b656995301f 161
4180_1 1:8b656995301f 162 #define DOWN '\x00'
4180_1 1:8b656995301f 163 #define UP '\x01'
4180_1 1:8b656995301f 164
4180_1 1:8b656995301f 165 #define PROTECT '\x00'
4180_1 1:8b656995301f 166 #define UNPROTECT '\x02'
4180_1 1:8b656995301f 167
4180_1 1:8b656995301f 168 //**************************************************************************
4180_1 1:8b656995301f 169 // \class uLCD_4DGL uLCD_4DGL.h
4180_1 1:8b656995301f 170 // \brief This is the main class. It shoud be used like this : uLCD_4GDL myLCD(p9,p10,p11);
4180_1 1:8b656995301f 171 /**
4180_1 1:8b656995301f 172 Example:
4180_1 1:8b656995301f 173 * @code
4180_1 1:8b656995301f 174 * // Display a white circle on the screen
4180_1 1:8b656995301f 175 * #include "mbed.h"
4180_1 1:8b656995301f 176 * #include " uLCD_4DGL.h"
4180_1 1:8b656995301f 177 *
4180_1 1:8b656995301f 178 * uLCD_4GDL myLCD(p9,p10,p11);
4180_1 1:8b656995301f 179 *
4180_1 1:8b656995301f 180 * int main() {
4180_1 1:8b656995301f 181 * myLCD.circle(120, 160, 80, WHITE);
4180_1 1:8b656995301f 182 * }
4180_1 1:8b656995301f 183 * @endcode
4180_1 1:8b656995301f 184 */
4180_1 1:8b656995301f 185
4180_1 2:edae99e4abe7 186 class uLCD_4DGL : public Stream
4180_1 1:8b656995301f 187 {
4180_1 1:8b656995301f 188
4180_1 1:8b656995301f 189 public :
4180_1 1:8b656995301f 190
4180_1 1:8b656995301f 191 uLCD_4DGL(PinName tx, PinName rx, PinName rst);
4180_1 1:8b656995301f 192
4180_1 1:8b656995301f 193 // General Commands *******************************************************************************
4180_1 1:8b656995301f 194
4180_1 1:8b656995301f 195 /** Clear the entire screen using the current background colour */
4180_1 1:8b656995301f 196 void cls();
4180_1 1:8b656995301f 197
4180_1 1:8b656995301f 198 /** Reset screen */
4180_1 1:8b656995301f 199 void reset();
4180_1 1:8b656995301f 200
4180_1 1:8b656995301f 201 /** Launch Autobaud for serial communication. This function is automatically called at startup */
4180_1 1:8b656995301f 202 void autobaud();
4180_1 1:8b656995301f 203 /** Set serial Baud rate (both sides : screen and mbed)
4180_1 1:8b656995301f 204 * @param Speed Correct BAUD value (see uLCD_4DGL.h)
4180_1 1:8b656995301f 205 */
4180_1 1:8b656995301f 206 void baudrate(int speed);
4180_1 1:8b656995301f 207
4180_1 1:8b656995301f 208 /** Set background colour to the specified value
4180_1 1:8b656995301f 209 * @param color in HEX RGB like 0xFF00FF
4180_1 1:8b656995301f 210 */
4180_1 1:8b656995301f 211 void background_color(int color);
4180_1 1:8b656995301f 212
4180_1 1:8b656995301f 213 /** Set screen display mode to specific values
4180_1 1:8b656995301f 214 * @param mode See 4DGL documentation
4180_1 1:8b656995301f 215 * @param value See 4DGL documentation
4180_1 1:8b656995301f 216 */
4180_1 2:edae99e4abe7 217 void textbackground_color(int color);
4180_1 2:edae99e4abe7 218
4180_1 2:edae99e4abe7 219 /** Set screen display mode to specific values
4180_1 2:edae99e4abe7 220 * @param mode See 4DGL documentation
4180_1 2:edae99e4abe7 221 * @param value See 4DGL documentation
4180_1 2:edae99e4abe7 222 */
4180_1 1:8b656995301f 223 void display_control(char mode, char value);
4180_1 1:8b656995301f 224
4180_1 1:8b656995301f 225 /** Set internal speaker to specified value
4180_1 1:8b656995301f 226 * @param value Correct range is 8 - 127
4180_1 1:8b656995301f 227 */
4180_1 1:8b656995301f 228 void set_volume(char value);
4180_1 1:8b656995301f 229
4180_1 1:8b656995301f 230 // Graphics Commands *******************************************************************************
4180_1 1:8b656995301f 231
4180_1 1:8b656995301f 232 /** 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
4180_1 1:8b656995301f 233 * @param x Horizontal position of the circle centre
4180_1 1:8b656995301f 234 * @param y Vertical position of the circle centre
4180_1 1:8b656995301f 235 * @param radius Radius of the circle
4180_1 1:8b656995301f 236 * @param color Circle color in HEX RGB like 0xFF00FF
4180_1 1:8b656995301f 237 */
4180_1 1:8b656995301f 238 void circle(int x , int y , int radius, int color);
4180_1 1:8b656995301f 239
4180_1 1:8b656995301f 240 void triangle(int, int, int, int, int, int, int);
4180_1 1:8b656995301f 241 void line(int, int, int, int, int);
4180_1 1:8b656995301f 242 void rectangle(int, int, int, int, int);
4180_1 1:8b656995301f 243 void ellipse(int, int, int, int, int);
4180_1 1:8b656995301f 244 void pixel(int, int, int);
4180_1 1:8b656995301f 245 int read_pixel(int, int);
4180_1 1:8b656995301f 246 void screen_copy(int, int, int, int, int, int);
4180_1 1:8b656995301f 247 void pen_size(char);
4180_1 3:9ba47197d94f 248 void BLIT(int x, int y, int w, int h, int *colors);
4180_1 1:8b656995301f 249
4180_1 1:8b656995301f 250 // Texts Commands
4180_1 1:8b656995301f 251 void set_font(char);
4180_1 1:8b656995301f 252 void text_mode(char);
4180_1 5:8936798c19a3 253 void text_bold(char);
4180_1 5:8936798c19a3 254 void text_italic(char);
4180_1 5:8936798c19a3 255 void text_inverse(char);
4180_1 2:edae99e4abe7 256 void text_width(char);
4180_1 2:edae99e4abe7 257 void text_height(char);
4180_1 1:8b656995301f 258 void text_char(char, char, char, int);
4180_1 1:8b656995301f 259 void graphic_char(char, int, int, int, char, char);
4180_1 1:8b656995301f 260 void text_string(char *, char, char, char, int);
4180_1 1:8b656995301f 261 void graphic_string(char *, int, int, char, int, char, char);
4180_1 1:8b656995301f 262 void text_button(char *, char, int, int, int, char, int, char, char);
4180_1 1:8b656995301f 263
4180_1 1:8b656995301f 264 void locate(char, char);
4180_1 1:8b656995301f 265 void color(int);
4180_1 1:8b656995301f 266 void putc(char);
4180_1 1:8b656995301f 267 void puts(char *);
4180_1 1:8b656995301f 268
4180_1 2:edae99e4abe7 269
4180_1 2:edae99e4abe7 270
4180_1 1:8b656995301f 271 // Touch Command
4180_1 1:8b656995301f 272 void touch_mode(char);
4180_1 1:8b656995301f 273 void get_touch(int *, int *);
4180_1 1:8b656995301f 274 void wait_touch(int);
4180_1 1:8b656995301f 275 void set_touch(int, int, int, int);
4180_1 1:8b656995301f 276 int touch_status(void);
4180_1 1:8b656995301f 277
4180_1 1:8b656995301f 278 // Screen Data
4180_1 1:8b656995301f 279 int type;
4180_1 1:8b656995301f 280 int revision;
4180_1 1:8b656995301f 281 int firmware;
4180_1 1:8b656995301f 282 int reserved1;
4180_1 1:8b656995301f 283 int reserved2;
4180_1 1:8b656995301f 284
4180_1 1:8b656995301f 285 // Text data
4180_1 1:8b656995301f 286 char current_col;
4180_1 1:8b656995301f 287 char current_row;
4180_1 1:8b656995301f 288 int current_color;
4180_1 1:8b656995301f 289 char current_font;
4180_1 1:8b656995301f 290 char current_orientation;
4180_1 1:8b656995301f 291 char max_col;
4180_1 1:8b656995301f 292 char max_row;
4180_1 2:edae99e4abe7 293 int current_w, current_h;
4180_1 2:edae99e4abe7 294 int current_fx, current_fy;
4180_1 2:edae99e4abe7 295 int current_wf, current_hf;
4180_1 5:8936798c19a3 296
4180_1 1:8b656995301f 297
4180_1 1:8b656995301f 298 protected :
4180_1 1:8b656995301f 299
4180_1 1:8b656995301f 300 Serial _cmd;
4180_1 1:8b656995301f 301 DigitalOut _rst;
4180_1 2:edae99e4abe7 302 //used by printf
4180_1 2:edae99e4abe7 303 virtual int _putc(int c) {
4180_1 2:edae99e4abe7 304 putc(c);
4180_1 2:edae99e4abe7 305 return 0;
4180_1 2:edae99e4abe7 306 };
4180_1 2:edae99e4abe7 307 virtual int _getc() {
4180_1 2:edae99e4abe7 308 return 0;
4180_1 2:edae99e4abe7 309 }
4180_1 2:edae99e4abe7 310
4180_1 1:8b656995301f 311
4180_1 1:8b656995301f 312 void freeBUFFER (void);
4180_1 1:8b656995301f 313 void writeBYTE (char);
4180_1 4:74df7fc26fef 314 void writeBYTEfast (char);
4180_1 1:8b656995301f 315 int writeCOMMAND(char *, int);
4180_1 1:8b656995301f 316 int writeCOMMANDnull(char *, int);
4180_1 1:8b656995301f 317 int readVERSION (char *, int);
4180_1 1:8b656995301f 318 void getTOUCH (char *, int, int *,int *);
4180_1 1:8b656995301f 319 int getSTATUS (char *, int);
4180_1 1:8b656995301f 320 void version (void);
4180_1 1:8b656995301f 321 #if DEBUGMODE
4180_1 1:8b656995301f 322 Serial pc;
4180_1 1:8b656995301f 323 #endif // DEBUGMODE
4180_1 1:8b656995301f 324 };
4180_1 1:8b656995301f 325
4180_1 1:8b656995301f 326 typedef unsigned char BYTE;
4180_1 1:8b656995301f 327
4180_1 1:8b656995301f 328
4180_1 2:edae99e4abe7 329
4180_1 4:74df7fc26fef 330
4180_1 5:8936798c19a3 331
4180_1 5:8936798c19a3 332