With added colors.

Dependents:   Arcade_RedX

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
soapy12312
Date:
Thu Nov 26 02:57:48 2015 +0000
Revision:
9:caa5d62f11f6
Parent:
8:2cb1845d7681
Working game selection with Simon Says, Super Tic-Tac-Toe and Pac-Man.

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