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