With added colors.

Fork of 4DGL-uLCD-SE by jim hamblen

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