4DGL-uLCD-SE

Dependents:   ECE2035_SUM17_Project Air_Rendezvous_transmitter Transmitter app-board-RTOS-Threads ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uLCD_4DGL.h Source File

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