Library for uVGAIII

Dependents:   uVGAIII_demo

Revision:
0:de1ab53f3480
Child:
1:cd4cc4298b2a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uVGAIII.h	Mon Mar 24 17:35:56 2014 +0000
@@ -0,0 +1,335 @@
+//
+// uVGAIII is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// uVGAIII is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// uVGAIII is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with uVGAIII.  If not, see <http://www.gnu.org/licenses/>.
+
+// @author Stephane Rochon
+
+#include "mbed.h"
+
+// Debug Verbose on terminal enabled
+#ifndef DEBUGMODE
+#define DEBUGMODE 1
+#endif
+
+// Common WAIT value in millisecond
+#define TEMPO 5
+
+// 4DGL Functions values
+// Graphic Commands values
+#define CLS          0xFFCD
+#define BCKGDCOLOR   0xFFA4
+#define SCREENMODE   0xFF9E
+#define CIRCLE       0xFFC3
+#define CIRCLE_F     0xFFC2
+#define TRIANGLE     0xFFBF
+#define TRIANGLE_F   0xFFA9
+#define LINE         0xFFC8
+#define RECTANGLE    0xFFC5
+#define RECTANGLE_F  0xFFC4
+#define ELLIPSE      0xFFB2
+#define ELLIPSE_F    0xFFB1
+#define PUTPIXEL     0xFFC1
+#define READPIXEL    0xFFC0
+#define SCREENCOPY   0xFFAD
+#define CLIPPING     0xFFA2
+#define SETCLIPWIN   0xFFB5
+#define EXTCLIPREG   0xFFB3
+#define BUTTON       0x0011
+#define PANEL        0xFFAF
+#define SLIDER       0xFFAE
+#define CHANGECOLOR  0xFFB4
+#define MOVEORIGIN   0xFFCC
+#define LINEPATTERN  0xFF9B
+#define OUTLINECOLOR 0xFF9D
+#define TRANSPARENCY 0xFFA0
+#define TRANSPCOLOR  0xFFA1
+#define PARAMETERS   0xFFCE
+
+// System Commands
+#define BAUDRATE     0x0026
+#define SPEVERSION   0x001B
+#define PMMCVERSION  0x001C
+#define SETVOLUME    0xFF00
+
+// Text and String Commands
+#define MOVECURSOR   0xFFE9
+#define PUTCHAR      0xFFFE
+#define SETFONT      0xFFE5
+#define TEXTOPACITY  0xFFDF
+#define TEXTFGCOLOR  0xFFE7
+#define TEXTBGCOLOR  0xFFE6
+#define TEXTWIDTH    0xFFE4
+#define TEXTHEIGHT   0xFFE3
+#define TEXTXGAP     0xFFE2
+#define TEXTYGAP     0xFFE1
+#define TEXTBOLD     0xFFDE
+#define TEXTINVERSE  0xFFDC
+#define TEXTITALIC   0xFFDD
+#define TEXTUNDLINE  0xFFDB
+#define TEXTATTRIBU  0xFFDA
+#define PUTSTRING    0x0018
+#define CHARWIDTH    0x001E
+#define CHARHEIGHT   0x001D
+#define GETTOUCH     '\x6F'
+#define WAITTOUCH    '\x77'
+#define SETTOUCH     '\x75'
+
+// Touch Screen Commands
+#define TOUCHSET     0xFF38
+#define TOUCHGET     0xFF37
+#define TOUCHDETECT  0xFF39
+
+// Slider
+#define INTENDED     '\x00'
+#define S_RAISED     '\x01'
+#define HIDDEN       '\x02'
+
+// Button
+#define DEPRESSED    '\x00'
+#define B_RAISED     '\x01'
+
+// Panel
+#define RECESSED     '\x00'
+#define P_RAISED     '\x01'
+
+// Screen answers
+#define ACK          '\x06'
+#define NAK          '\x15'
+
+// Screen states
+#define OFF          '\x00'
+#define ON           '\x01'
+
+// Graphics parameters
+#define OBJECTCOLOR    18
+#define RESOLUTION     32
+#define PGDISPLAY      33
+#define PGREAD         34
+#define PGWRITE        35
+
+// Graphics modes
+#define SOLID        '\x00'
+#define WIREFRAME    '\x01'
+
+// Text modes
+#define TRANSPARENT  '\x00'
+#define OPAQUE       '\x01'
+
+// Fonts Sizes
+#define FONT1        '\x00'      // 7X8
+#define FONT2        '\x01'      // 8X8
+#define FONT3        '\x02'      // 8X12
+
+// Touch Values
+#define MOVE         '\x03'
+#define STATUS       '\x00'
+#define GETXPOSITION '\x01'
+#define GETYPOSITION '\x02'
+
+// Data speed
+#define BAUD_110     0x0000
+#define BAUD_300     0x0001
+#define BAUD_600     0x0002
+#define BAUD_1200    0x0003
+#define BAUD_2400    0x0004
+#define BAUD_4800    0x0005
+#define BAUD_9600    0x0006
+#define BAUD_14400   0x0007
+#define BAUD_19200   0x0008
+#define BAUD_31250   0x0009
+#define BAUD_38400   0x000A
+#define BAUD_56000   0x000B
+#define BAUD_57600   0x000C
+#define BAUD_115200  0x000D
+#define BAUD_128000  0x000E
+#define BAUD_256000  0x000F
+
+// Defined Colors
+#define BLACK   0x000000
+#define WHITE   0xFFFFFF
+#define LGREY   0xBFBFBF
+#define DGREY   0x5F5F5F
+#define RED     0xFF0000
+#define LIME    0x00FF00
+#define BLUE    0x0000FF
+#define YELLOW  0xFFFF00
+#define CYAN    0x00FFFF
+#define MAGENTA 0xFF00FF
+#define SILVER  0xC0C0C0
+#define GRAY    0x808080
+#define MAROON  0x800000
+#define OLIVE   0x808000
+#define GREEN   0x008000
+#define PURPLE  0x800080
+#define TEAL    0x008080
+#define NAVY    0x000080
+
+// Mode data
+#define BACKLIGHT    '\x00'
+#define DISPLAY      '\x01'
+#define CONTRAST     '\x02'
+#define POWER        '\x03'
+#define ORIENTATION  '\x04'
+#define TOUCH_CTRL   '\x05'
+#define IMAGE_FORMAT '\x06'
+#define PROTECT_FAT  '\x08'
+
+// change this to your specific screen (newer versions) if needed
+// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
+#define SIZE_X       480
+#define SIZE_Y       800
+
+#define IS_LANDSCAPE 0
+#define IS_PORTRAIT  1
+
+// Screen orientation
+#define LANDSCAPE    '\x00'
+#define LANDSCAPE_R  '\x01'
+#define PORTRAIT     '\x02'
+#define PORTRAIT_R   '\x03'
+
+
+class uVGAIII : public Stream
+{
+
+public :
+
+    uVGAIII(PinName tx, PinName rx, PinName rst);
+
+// General Commands *******************************************************************************
+
+/** Clear the entire screen using the current background colour */
+    void cls();
+
+/** Reset screen */
+    void reset();
+    
+/** Set serial Baud rate (both sides : screen and mbed)
+* @param Speed Correct BAUD value (see uVGAIII.h)
+*/   
+    void baudrate(int speed);
+
+/** Set internal speaker to specified value
+* @param value Correct range is 8 - 127
+*/
+    void set_volume(char value);
+
+// Graphics Commands
+    void screen_mode(char mode);
+    void background_color(int color);
+    void circle(int x , int y , int radius, int color);
+    void filled_circle(int x, int y, int radius, int color);
+    void triangle(int, int, int, int, int, int, int);
+    void filled_triangle(int, int, int, int, int, int, int);
+    void line(int, int, int, int, int);
+    void rectangle(int, int, int, int, int);
+    void filled_rectangle(int, int, int, int, int);
+    void ellipse(int, int, int, int, int);
+    void filled_ellipse(int, int, int, int, int);
+    void button(int, int, int, int, int, int, int, int, char *);
+    void panel(int, int, int, int, int, int);
+    void slider(char, int, int, int, int, int, int, int);
+    void put_pixel(int, int, int);
+    int  read_pixel(int, int);
+    void screen_copy(int, int, int, int, int, int);
+    void clipping(char);
+    void set_clipping_win(int, int, int, int);
+    void extend_clip_region();
+    void change_color(int, int);
+    void move_origin(int, int);
+    void line_pattern(int);
+    void outline_color(int);
+    void transparency(char);
+    void transparent_color(int);
+    void graphics_parameters(int, int);
+
+// Texts Commands
+    void set_font(char);
+    void move_cursor(int, int);
+    void text_opacity(char);
+    void text_width(int);
+    void text_height(int);
+    void text_x_gap(int);
+    void text_y_gap(int);
+    void text_bold(char);
+    void text_inverse(char);
+    void text_italic(char);
+    void text_underline(char);
+    void text_attributes(int);
+    void put_char(char);
+    void put_string(char *);
+    void text_fgd_color(int);
+    void text_bgd_color(int);
+    void char_width(char);
+    void char_height(char);
+
+    void locate(char, char);
+    void color(int);
+    void putc(char);
+    void puts(char *);
+
+// Touch Command
+    void detect_touch_region(int, int, int, int);
+    void touch_get_x(int *);
+    void touch_get_y(int *);
+    void touch_set(char);
+    int touch_status(void);
+
+// Screen Version Data
+    int version;
+    int SPEversion;
+    int PmmCversion;
+
+// Text data
+    char current_col;
+    char current_row;
+    int  current_color;
+    char current_font;
+    char current_orientation;
+    char max_col;
+    char max_row;
+    int current_w, current_h;
+    int current_fx, current_fy;
+
+protected :
+
+    Serial     _cmd;
+    DigitalOut _rst;
+    
+    //used by printf
+    virtual int _putc(int c) {
+        putc(c);
+        return 0;
+    };
+    virtual int _getc() {
+        return -1;
+    }
+
+    void freeBUFFER  (void);
+    void writeBYTE   (char);
+    int  writeCOMMAND(char *, int, int);
+    int  readVERSION (char *, int);
+    void getTOUCH    (char *, int, int *);
+    int  getSTATUS   (char *, int);
+    void speversion  (void);
+    void pmmcversion (void);
+#if DEBUGMODE
+    Serial pc;
+#endif // DEBUGMODE
+};
+
+typedef unsigned char BYTE;
\ No newline at end of file