uLCD library
Fork of 4DGL-uLCD-SE by
Embed:
(wiki syntax)
Show/hide line numbers
uLCD_4DGL.h
00001 #ifndef ULCD_4DGL_H 00002 #define ULCD_4DGL_H 00003 // 00004 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens 00005 // 00006 // Fork of 4DGL library for 4D Systems LCD displays 00007 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> 00008 // Modifed for Goldelox processor <2013> Jim Hamblen 00009 // 00010 // uLCD_4DGL is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // uLCD_4DGL is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. 00022 00023 // @author Stephane Rochon 00024 00025 #include "mbed.h" 00026 00027 // Debug Verbose off - SGE commands echoed to USB serial for debugmode=1 00028 #ifndef DEBUGMODE 00029 #define DEBUGMODE 0 00030 #endif 00031 00032 // Common WAIT value in milliseconds between commands 00033 #define TEMPO 0 00034 00035 // 4DGL SGE Function values for Goldelox Processor 00036 #define CLS '\xD7' 00037 #define BAUDRATE '\x0B' //null prefix 00038 #define VERSION '\x08' //null prefix 00039 #define BCKGDCOLOR '\x6E' 00040 #define TXTBCKGDCOLOR '\x7E' 00041 #define DISPCONTROL '\x68' 00042 #define SETVOLUME '\x76' 00043 #define CIRCLE '\xCD' 00044 #define FCIRCLE '\xCC' 00045 #define TRIANGLE '\xC9' 00046 #define LINE '\xD2' 00047 #define FRECTANGLE '\xCE' 00048 #define RECTANGLE '\xCF' 00049 #define ELLIPSE '\x65' //na 00050 #define PIXEL '\xCB' 00051 #define READPIXEL '\xCA' 00052 #define SCREENCOPY '\x63' //na? 00053 #define PENSIZE '\xD8' 00054 #define SETFONT '\x7D' 00055 #define TEXTMODE '\x77' 00056 #define TEXTBOLD '\x76' 00057 #define TEXTITALIC '\x75' 00058 #define TEXTINVERSE '\x74' 00059 #define TEXTUNDERLINE '\x73' 00060 #define TEXTWIDTH '\x7C' 00061 #define TEXTHEIGHT '\x7B' 00062 #define TEXTCHAR '\xFE' 00063 #define TEXTSTRING '\x06' //null prefix 00064 #define MOVECURSOR '\xE4' 00065 #define BLITCOM '\x0A' 00066 #define PUTCHAR '\xFE' 00067 #define DISPPOWER '\x66' 00068 //media commands for uSD card 00069 #define MINIT '\xB1' 00070 #define SBADDRESS '\xB9' 00071 #define SSADDRESS '\xB8' 00072 #define READBYTE '\xB7' 00073 #define READWORD '\xB6' 00074 #define WRITEBYTE '\xB5' 00075 #define WRITEWORD '\xB4' 00076 #define FLUSHMEDIA '\xB2' 00077 #define DISPLAYIMAGE '\xB3' 00078 #define DISPLAYVIDEO '\xBB' 00079 #define DISPLAYFRAME '\xBA' 00080 00081 00082 00083 // Screen answers 00084 #define ACK '\x06' 00085 #define NAK '\x15' 00086 00087 00088 00089 // Screen states 00090 #define OFF '\x00' 00091 #define ON '\x01' 00092 00093 // Graphics modes 00094 #define SOLID '\x00' 00095 #define WIREFRAME '\x01' 00096 00097 // Text modes 00098 #define TRANSPARENT '\x00' 00099 #define OPAQUE '\x01' 00100 00101 // Fonts Sizes 00102 #define FONT_7X8 '\x00' //only builtin font 00103 #define FONT_5X7 '\x04' 00104 #define FONT_8X8 '\x01' 00105 #define FONT_8X12 '\x02' 00106 #define FONT_12X16 '\x03' 00107 #define MEDIAFONT '\x07' 00108 00109 00110 // Data speed 00111 #define BAUD_110 27271 00112 #define BAUD_300 9999 00113 #define BAUD_600 4999 00114 #define BAUD_1200 2499 00115 #define BAUD_2400 1249 00116 #define BAUD_4800 624 00117 #define BAUD_9600 312 00118 #define BAUD_14400 207 00119 #define BAUD_19200 155 00120 #define BAUD_31250 95 00121 #define BAUD_38400 77 00122 #define BAUD_56000 53 00123 #define BAUD_57600 51 00124 #define BAUD_115200 25 00125 #define BAUD_128000 22 00126 #define BAUD_256000 11 00127 #define BAUD_300000 10 00128 #define BAUD_375000 8 00129 #define BAUD_500000 6 00130 #define BAUD_600000 4 00131 #define BAUD_750000 3 00132 #define BAUD_1000000 2 00133 #define BAUD_1500000 1 00134 #define BAUD_3000000 0 00135 00136 // Defined Colors 00137 #define WHITE 0xFFFFFF 00138 #define BLACK 0x000000 00139 #define RED 0xFF0000 00140 #define GREEN 0x00FF00 00141 #define BLUE 0x0000FF 00142 #define LGREY 0xBFBFBF 00143 #define DGREY 0x5F5F5F 00144 00145 // Mode data 00146 #define BACKLIGHT '\x00' 00147 #define DISPLAY '\x01' 00148 #define CONTRAST '\x02' 00149 #define POWER '\x03' 00150 #define ORIENTATION '\x04' 00151 #define TOUCH_CTRL '\x05' 00152 #define IMAGE_FORMAT '\x06' 00153 #define PROTECT_FAT '\x08' 00154 00155 // change this to your specific screen (newer versions) if needed 00156 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y 00157 //uLCD144-G2 is a 128 by 128 pixel display 00158 #define SIZE_X 128 00159 #define SIZE_Y 128 00160 00161 #define IS_LANDSCAPE 0 00162 #define IS_PORTRAIT 1 00163 00164 // Screen orientation 00165 #define LANDSCAPE '\x00' 00166 #define LANDSCAPE_R '\x01' 00167 #define PORTRAIT '\x02' 00168 #define PORTRAIT_R '\x03' 00169 00170 // Parameters 00171 #define ENABLE '\x00' 00172 #define DISABLE '\x01' 00173 #define RESET '\x02' 00174 00175 #define NEW '\x00' 00176 #define OLD '\x01' 00177 00178 #define DOWN '\x00' 00179 #define UP '\x01' 00180 00181 #define PROTECT '\x00' 00182 #define UNPROTECT '\x02' 00183 00184 //************************************************************************** 00185 // \class uLCD_4DGL uLCD_4DGL.h 00186 // \brief This is the main class. It shoud be used like this : uLCD_4GDL myLCD(p9,p10,p11); 00187 /** 00188 Example: 00189 * @code 00190 * // Display a white circle on the screen 00191 * #include "mbed.h" 00192 * #include " uLCD_4DGL.h" 00193 * 00194 * uLCD_4GDL myLCD(p9,p10,p11); 00195 * 00196 * int main() { 00197 * myLCD.circle(120, 160, 80, WHITE); 00198 * } 00199 * @endcode 00200 */ 00201 00202 class uLCD_4DGL : public Stream 00203 { 00204 00205 public : 00206 00207 uLCD_4DGL(PinName tx, PinName rx, PinName rst); 00208 00209 // General Commands ******************************************************************************* 00210 00211 /** Clear the entire screen using the current background colour */ 00212 void cls(); 00213 00214 /** Reset screen */ 00215 void reset(); 00216 00217 00218 /** Set serial Baud rate (both sides : screen and mbed) 00219 * @param Speed Correct BAUD value (see uLCD_4DGL.h) 00220 */ 00221 void baudrate(int speed); 00222 00223 /** Set background colour to the specified value 00224 * @param color in HEX RGB like 0xFF00FF 00225 */ 00226 void background_color(int color); 00227 00228 /** Set screen display mode to specific values 00229 * @param mode See 4DGL documentation 00230 * @param value See 4DGL documentation 00231 */ 00232 void textbackground_color(int color); 00233 00234 /** Set screen display mode to specific values 00235 * @param mode See 4DGL documentation 00236 * @param value See 4DGL documentation 00237 */ 00238 void display_control(char mode); 00239 void display_power(char mode); 00240 /** Set internal speaker to specified value 00241 * @param value Correct range is 8 - 127 00242 */ 00243 void set_volume(char value); 00244 00245 // Graphics Commands ******************************************************************************* 00246 00247 /** 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 00248 * @param x Horizontal position of the circle centre 00249 * @param y Vertical position of the circle centre 00250 * @param radius Radius of the circle 00251 * @param color Circle color in HEX RGB like 0xFF00FF 00252 */ 00253 void circle(int x , int y , int radius, int color); 00254 void filled_circle(int x , int y , int radius, int color); 00255 void triangle(int, int, int, int, int, int, int); 00256 void line(int, int, int, int, int); 00257 void rectangle(int, int, int, int, int); 00258 void filled_rectangle(int, int, int, int, int); 00259 void pixel(int, int, int); 00260 int read_pixel(int, int); 00261 void pen_size(char); 00262 void BLIT(int x, int y, int w, int h, int *colors); 00263 00264 // Text Commands 00265 void set_font(char); 00266 void set_font_size(char width, char height); 00267 void text_mode(char); 00268 void text_bold(char); 00269 void text_italic(char); 00270 void text_inverse(char); 00271 void text_underline(char); 00272 void text_width(char); 00273 void text_height(char); 00274 void text_char(char, char, char, int); 00275 void text_string(char *, char, char, char, int); 00276 void locate(char, char); 00277 void color(int); 00278 void putc(char); 00279 void puts(char *); 00280 00281 //Media Commands 00282 int media_init(); 00283 void set_byte_address(int, int); 00284 void set_sector_address(int, int); 00285 char read_byte(); 00286 int read_word(); 00287 void write_byte(int); 00288 void write_word(int); 00289 void flush_media(); 00290 void display_image(int, int); 00291 void display_video(int, int); 00292 void display_frame(int, int, int); 00293 00294 // Screen Data 00295 int type; 00296 int revision; 00297 int firmware; 00298 int reserved1; 00299 int reserved2; 00300 00301 // Text data 00302 char current_col; 00303 char current_row; 00304 int current_color; 00305 char current_font; 00306 char current_orientation; 00307 char max_col; 00308 char max_row; 00309 int current_w, current_h; 00310 int current_fx, current_fy; 00311 int current_wf, current_hf; 00312 00313 00314 protected : 00315 00316 Serial _cmd; 00317 DigitalOut _rst; 00318 //used by printf 00319 virtual int _putc(int c) { 00320 putc(c); 00321 return 0; 00322 }; 00323 virtual int _getc() { 00324 return -1; 00325 } 00326 00327 void freeBUFFER (void); 00328 void writeBYTE (char); 00329 void writeBYTEfast (char); 00330 int writeCOMMAND(char *, int); 00331 int writeCOMMANDnull(char *, int); 00332 int readVERSION (char *, int); 00333 int getSTATUS (char *, int); 00334 int version (void); 00335 #if DEBUGMODE 00336 Serial pc; 00337 #endif // DEBUGMODE 00338 }; 00339 00340 typedef unsigned char BYTE; 00341 #endif 00342
Generated on Sun Jul 24 2022 03:00:39 by 1.7.2