Jingyi Zhang
/
uVGAIII_demo
A demo program using uVGAIII board.
Fork of uVGAIII_demo by
Revision 2:6ecb8ceea422, committed 2014-03-24
- Comitter:
- ivygatech
- Date:
- Mon Mar 24 19:58:17 2014 +0000
- Parent:
- 1:333b7b189790
- Commit message:
- update
Changed in this revision
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uVGAIII.lib Mon Mar 24 19:58:17 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/ivygatech/code/uVGAIII/#8acc50389659
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII/uVGAIII.h --- a/uVGAIII/uVGAIII.h Mon Mar 24 17:29:15 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,335 +0,0 @@ -// -// 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
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII/uVGAIII_Graphics.cpp --- a/uVGAIII/uVGAIII_Graphics.cpp Mon Mar 24 17:29:15 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,833 +0,0 @@ -// -// 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/>. - -#include "mbed.h" -#include "uVGAIII.h" - -#define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) - -//************************************************************************** -void uVGAIII :: cls() { // clear screen - char command[2] = ""; - command[0] = ( CLS >> 8 ) & 0xFF; - command[1] = CLS & 0xFF; - writeCOMMAND(command, 2, 1); - -#if DEBUGMODE - pc.printf("Clear screen completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: change_color(int oldColor, int newColor) { // change all old color pixels to new color within the clipping window area - char command[6] = ""; - - command[0] = (CHANGECOLOR >> 8) & 0xFF; - command[1] = CHANGECOLOR & 0xFF; - - int red5 = (oldColor >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (oldColor >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (oldColor >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - red5 = (newColor >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (newColor >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (newColor >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 6, 1); - -#if DEBUGMODE - pc.printf("Change color completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: background_color(int color) { // set screen background color - - char command[4]= ""; // input color is in 24bits like 0xRRGGBB - - command[0] = ( BCKGDCOLOR >> 8 ) & 0xFF; - command[1] = BCKGDCOLOR & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - //command[2] = 0x00; - //command[3] = 0x10; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Set background color completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: screen_mode(char mode) { // set the graphics orientation LANDSCAPE, LANDSCAPE_R, PORTRAIT, PORTRAIT_R - char command[4]= ""; - - command[0] = (SCREENMODE >> 8) & 0xFF; - command[1] = SCREENMODE & 0xFF; - command[2] = 0x00; - command[3] = mode; - - switch (mode) { - case LANDSCAPE : - current_orientation = IS_LANDSCAPE; - break; - case LANDSCAPE_R : - current_orientation = IS_LANDSCAPE; - break; - case PORTRAIT : - current_orientation = IS_PORTRAIT; - break; - case PORTRAIT_R : - current_orientation = IS_PORTRAIT; - break; - } - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Screen mode completed.\n"); -#endif - - set_font(current_font); -} - -//**************************************************************************************************** -void uVGAIII :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) - char command[10]= ""; - - command[0] = (CIRCLE >> 8) & 0xFF; - command[1] = CIRCLE & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - command[6] = (radius >> 8) & 0xFF; - command[7] = radius & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 10, 1); - -#if DEBUGMODE - pc.printf("Draw circle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: filled_circle(int x, int y , int radius, int color) { // draw a filled circle in (x,y) - char command[10]= ""; - - command[0] = (CIRCLE_F >> 8) & 0xFF; - command[1] = CIRCLE_F & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - command[6] = (radius >> 8) & 0xFF; - command[7] = radius & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 10, 1); - -#if DEBUGMODE - pc.printf("Draw filled circle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle - char command[16]= ""; - - command[0] = (TRIANGLE >> 8) & 0xFF; - command[1] = TRIANGLE & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - command[10] = (x3 >> 8) & 0xFF; - command[11] = x3 & 0xFF; - - command[12] = (y3 >> 8) & 0xFF; - command[13] = y3 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[14] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[15] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 16, 1); - -#if DEBUGMODE - pc.printf("Draw triangle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: filled_triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a filled traingle - char command[16]= ""; - - command[0] = (TRIANGLE_F >> 8) & 0xFF; - command[1] = TRIANGLE_F & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - command[10] = (x3 >> 8) & 0xFF; - command[11] = x3 & 0xFF; - - command[12] = (y3 >> 8) & 0xFF; - command[13] = y3 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[14] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[15] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 16, 1); - -#if DEBUGMODE - pc.printf("Draw filled triangle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line - char command[12]= ""; - - command[0] = (LINE >> 8) & 0xFF; - command[1] = LINE & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 12, 1); - -#if DEBUGMODE - pc.printf("Draw line completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle - char command[12]= ""; - - command[0] = (RECTANGLE >> 8) & 0xFF; - command[1] = RECTANGLE & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 12, 1); - -#if DEBUGMODE - pc.printf("Draw rectangle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a filled rectangle - char command[12]= ""; - - command[0] = (RECTANGLE_F >> 8) & 0xFF; - command[1] = RECTANGLE_F & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 12, 1); - -#if DEBUGMODE - pc.printf("Draw filled rectangle completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse - char command[12]= ""; - - command[0] = (ELLIPSE >> 8) & 0xFF; - command[1] = ELLIPSE & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - command[6] = (radius_x >> 8) & 0xFF; - command[7] = radius_x & 0xFF; - - command[8] = (radius_y >> 8) & 0xFF; - command[9] = radius_y & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 12, 1); - -#if DEBUGMODE - pc.printf("Draw ellipse completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: filled_ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw a filled ellipse - char command[12] = ""; - - command[0] = (ELLIPSE_F >> 8) & 0xFF; - command[1] = ELLIPSE_F & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - command[6] = (radius_x >> 8) & 0xFF; - command[7] = radius_x & 0xFF; - - command[8] = (radius_y >> 8) & 0xFF; - command[9] = radius_y & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 12, 1); - -#if DEBUGMODE - pc.printf("Draw filled ellipse completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: button(int state, int x, int y, int buttoncolor, int txtcolor, int font, int txtWidth, int txtHeight, char * text) { // draw a button - char command[1000] = ""; - int size = strlen(text); - int i = 0; - - command[0] = (BUTTON >> 8) & 0xFF; - command[1] = BUTTON & 0xFF; - - command[2] = (state >> 8) & 0xFF; - command[3] = state & 0xFF; - - command[4] = (x >> 8) & 0xFF; - command[5] = x & 0xFF; - - command[6] = (y >> 8) & 0xFF; - command[7] = y & 0xFF; - - int red5 = (buttoncolor >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (buttoncolor >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (buttoncolor >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - red5 = (txtcolor >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (txtcolor >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (txtcolor >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - command[12] = (font >> 8) & 0xFF; - command[13] = font & 0xFF; - - command[14] = (txtWidth >> 8) & 0xFF; - command[15] = txtWidth & 0xFF; - - command[16] = (txtHeight >> 8) & 0xFF; - command[17] = txtHeight & 0xFF; - - for (i=0; i<size; i++) command[18+i] = text[i]; - - command[18+size] = 0; - - writeCOMMAND(command, 19 + size, 1); - -#if DEBUGMODE - pc.printf("Draw button completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: panel(int state, int x, int y, int Width, int Height, int color) { // draw a panel - char command[14] = ""; - - command[0] = (PANEL >> 8) & 0xFF; - command[1] = PANEL & 0xFF; - - command[2] = (state >> 8) & 0xFF; - command[3] = state & 0xFF; - - command[4] = (x >> 8) & 0xFF; - command[5] = x & 0xFF; - - command[6] = (y >> 8) & 0xFF; - command[7] = y & 0xFF; - - command[8] = (Width >> 8) & 0xFF; - command[9] = Width & 0xFF; - - command[10] = (Height >> 8) & 0xFF; - command[11] = Height & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[12] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[13] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - writeCOMMAND(command, 14, 1); - -#if DEBUGMODE - pc.printf("Draw panel completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: slider(char mode, int x1, int y1, int x2, int y2, int color, int scale, int value) { // draw a slider - char command[18] = ""; - - command[0] = (SLIDER >> 8) & 0xFF; - command[1] = SLIDER & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - command[4] = (x1 >> 8) & 0xFF; - command[5] = x1 & 0xFF; - - command[6] = (y1 >> 8) & 0xFF; - command[7] = y1 & 0xFF; - - command[8] = (x2 >> 8) & 0xFF; - command[9] = x2 & 0xFF; - - command[10] = (y2 >> 8) & 0xFF; - command[11] = y2 & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[12] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[13] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - command[14] = (scale >> 8) & 0xFF; - command[15] = scale & 0xFF; - - command[16] = (value) & 0xFF; - command[17] = value & 0xFF; - - writeCOMMAND(command, 18, 1); - -#if DEBUGMODE - pc.printf("Draw slider completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: put_pixel(int x, int y, int color) { // draw a pixel - char command[8] = ""; - - command[0] = (PUTPIXEL >> 8) & 0xFF; - command[1] = PUTPIXEL & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 8, 1); - -#if DEBUGMODE - pc.printf("Put pixel completed.\n"); -#endif -} - -//****************************************************************************************************** -int uVGAIII :: read_pixel(int x, int y) { // read screen info and populate data - - char command[6]= ""; - - command[0] = (READPIXEL >> 8) & 0xFF; - command[1] = READPIXEL & 0xFF; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - int i, temp = 0, color = 0, resp = 0; - char response[3] = ""; - - freeBUFFER(); - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - - for (i = 0; i < 6; i++) { // send all chars to serial port - writeBYTE(command[i]); - } - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable() && resp < ARRAY_SIZE(response)) { - temp = _cmd.getc(); -#if DEBUGMODE - pc.printf("Response = 0x%02X\n",int(temp)); -#endif - response[resp++] = (char)temp; - } - - color = ((response[1] << 8) + response[2]); - -#if DEBUGMODE - pc.printf("Read pixel completed.\n"); -#endif - - return color; // WARNING : this is 16bits color, not 24bits... need to be fixed -} - -//****************************************************************************************************** -void uVGAIII :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { // copy an area of a screen from xs, ys of size given by width and height parameters and pastes it to another location determined by xd, yd - - char command[14]= ""; - - command[0] = (SCREENCOPY >> 8) & 0xFF; - command[1] = SCREENCOPY & 0xFF; - - command[2] = (xs >> 8) & 0xFF; - command[3] = xs & 0xFF; - - command[4] = (ys >> 8) & 0xFF; - command[5] = ys & 0xFF; - - command[6] = (xd >> 8) & 0xFF; - command[7] = xd & 0xFF; - - command[8] = (yd >> 8) & 0xFF; - command[9] = yd & 0xFF; - - command[10] = (width >> 8) & 0xFF; - command[11] = width & 0xFF; - - command[12] = (height >> 8) & 0xFF; - command[13] = height & 0xFF; - - writeCOMMAND(command, 14, 1); - -#if DEBUGMODE - pc.printf("Screen copy completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: clipping(char value) { // To enable or disable the ability for Clippling to be used - char command[4] = ""; - - command[0] = (CLIPPING >> 8) & 0xFF; - command[1] = CLIPPING & 0xFF; - - command[2] = 0x00; - command[3] = value & 0xFF; - - writeCOMMAND(command, 4, 1); - -#if DEBUGMODE - pc.printf("Clipping completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: set_clipping_win(int x1, int y1, int x2, int y2) { // Set the clipping window region - char command[10] = ""; - - command[0] = (SETCLIPWIN >> 8) & 0xFF; - command[1] = SETCLIPWIN & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - writeCOMMAND(command, 10, 1); - -#if DEBUGMODE - pc.printf("Set clipping window completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: extend_clip_region() { // to force the clip region to the extent of the last text that was printed, or the last image that was shown - char command[2] = ""; - - command[0] = (EXTCLIPREG) & 0xFF; - command[1] = EXTCLIPREG & 0xFF; - - writeCOMMAND(command, 2, 1); - -#if DEBUGMODE - pc.printf("Extend clip region completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: move_origin(int xpos, int ypos) { // Move the origin to a new position - char command[6] = ""; - - command[0] = (MOVEORIGIN) & 0xFF; - command[1] = MOVEORIGIN & 0xFF; - - command[2] = (xpos >> 8) & 0xFF; - command[3] = xpos & 0xFF; - - command[4] = (ypos >> 8) & 0xFF; - command[5] = ypos & 0xFF; - - writeCOMMAND(command, 6, 1); - -#if DEBUGMODE - pc.printf("Move origin completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: line_pattern(int pattern) { // Set the line pattern - char command[4] = ""; // If set to zero means lines are solid, else each '1' bit represents a pixel that is turned off - - command[0] = (LINEPATTERN) & 0xFF; - command[1] = LINEPATTERN & 0xFF; - - command[2] = (pattern >> 8) & 0xFF; - command[3] = pattern & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Line pattern completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: transparency(char mode) { // set whether to enable the transparency - char command[4] = ""; - - command[0] = (TRANSPARENCY) & 0xFF; - command[1] = TRANSPARENCY & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Transparency completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: outline_color(int color) { // set the outline color for rectangles and circles - char command[4] = ""; - - command[0] = (OUTLINECOLOR) & 0xFF; - command[1] = OUTLINECOLOR & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Outline color completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: transparent_color(int color) { // Set the color to be transparent - char command[4] = ""; - - command[0] = (TRANSPCOLOR) & 0xFF; - command[1] = TRANSPCOLOR & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Transparent color completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: graphics_parameters(int function, int value) { //Set graphics parameters - char command[6] = ""; - - command[0] = (PARAMETERS >> 8) & 0xFF; - command[1] = PARAMETERS & 0xFF; - - command[2] = (function >> 8) & 0xFF; - command[3] = function & 0xFF; - - command[4] = (value >> 8) & 0xFF; - command[5] = value & 0xFF; - - writeCOMMAND(command, 6, 1); - -#if DEBUGMODE - pc.printf("Graphics parameters completed.\n"); -#endif -} \ No newline at end of file
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII/uVGAIII_Text.cpp --- a/uVGAIII/uVGAIII_Text.cpp Mon Mar 24 17:29:15 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,431 +0,0 @@ -// -// 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/>. - -#include "mbed.h" -#include "uVGAIII.h" - -//**************************************************************************************************** -void uVGAIII :: set_font(char mode) { // set font size - char command[4] = ""; - - command[0] = (SETFONT >> 8) & 0xFF; - command[1] = SETFONT & 0xFF; - command[2] = 0; - command[3] = mode; - - current_font = mode; - - if (current_orientation == IS_PORTRAIT) { - current_w = SIZE_X; - current_h = SIZE_Y; - } else { - current_w = SIZE_Y; - current_h = SIZE_X; - } - - switch (mode) { - case FONT1 : - current_fx = 7; - current_fy = 8; - break; - case FONT2 : - current_fx = 8; - current_fy = 8; - break; - case FONT3 : - current_fx = 8; - current_fy = 12; - break; - } - - max_col = current_w / current_fx; - max_row = current_h / current_fy; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Set font completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: char_width(char c) { // Get the width in pixel units for a character - char command[3] = ""; - - command[0] = (CHARWIDTH >> 8) & 0xFF; - command[1] = CHARWIDTH & 0xFF; - - command[2] = c; - - writeCOMMAND(command, 3, 3); - -#if DEBUGMODE - pc.printf("Character width completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: char_height(char c) { // Get the height in pixel units for a character - char command[3] = ""; - - command[0] = (CHARHEIGHT >> 8) & 0xFF; - command[1] = CHARHEIGHT & 0xFF; - - command[2] = c; - - writeCOMMAND(command, 3, 3); - -#if DEBUGMODE - pc.printf("Character height completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_opacity(char mode) { // set text mode - char command[4] = ""; - - command[0] = (TEXTOPACITY >> 8) & 0xFF; - command[1] = TEXTOPACITY & 0xFF; - command[2] = 0x00; - command[3] = mode; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text opacity completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_width(int multiplier) { // Set teh text width multiplier between 1 and 16 - char command[4] = ""; - - command[0] = (TEXTWIDTH >> 8) & 0xFF; - command[1] = TEXTWIDTH & 0xFF; - - command[2] = (multiplier >> 8) & 0xFF; - command[3] = multiplier & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text width completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_height(int multiplier) { // Set teh text height multiplier between 1 and 16 - char command[4] = ""; - - command[0] = (TEXTHEIGHT >> 8) & 0xFF; - command[1] = TEXTHEIGHT & 0xFF; - - command[2] = (multiplier >> 8) & 0xFF; - command[3] = multiplier & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text width completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_y_gap(int pixelcount) { // set the pixel gap between characters(y-axis), and the gap is in pixel units - char command[4] = ""; - - command[0] = (TEXTYGAP >> 8) & 0xFF; - command[1] = TEXTYGAP & 0xFF; - - command[2] = (pixelcount >> 8) & 0xFF; - command[3] = pixelcount & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text Y-gap completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_x_gap(int pixelcount) { // set the pixel gap between characters(x-axis), and the gap is in pixel units - char command[4] = ""; - - command[0] = (TEXTXGAP >> 8) & 0xFF; - command[1] = TEXTXGAP & 0xFF; - - command[2] = (pixelcount >> 8) & 0xFF; - command[3] = pixelcount & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text X-gap completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_bold(char mode) { // set the Bold attribute for the text - char command[4] = ""; - - command[0] = (TEXTBOLD >> 8) & 0xFF; - command[1] = TEXTBOLD & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text bold completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_inverse(char mode) { // set the text foreground and background color to be inverse - char command[4] = ""; - - command[0] = (TEXTINVERSE >> 8) & 0xFF; - command[1] = TEXTINVERSE & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text inverse completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_italic(char mode) { // set the text to italic - char command[4] = ""; - - command[0] = (TEXTITALIC >> 8) & 0xFF; - command[1] = TEXTITALIC & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text italic completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_underline(char mode) { // Set whether the text to be underlined - char command[4] = ""; // For text underline to work, text Y-gap must be set to at least 2 - - command[0] = (TEXTUNDLINE >> 8) & 0xFF; - command[1] = TEXTUNDLINE & 0xFF; - - command[2] = 0x00; - command[3] = mode & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text underline completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_attributes(int value) { // Set text attributes: bold, italic, inverse, underlined - char command[4] = ""; // For text underline to work, text Y-gap must be set to at least 2 - - command[0] = (TEXTATTRIBU >> 8) & 0xFF; - command[1] = TEXTATTRIBU & 0xFF; - - command[2] = (value >> 8) & 0xFF; - command[3] = value & 0xFF; - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Text attributes completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: move_cursor(int line, int column) { // move cursor - char command[6] = ""; - - command[0] = (MOVECURSOR >> 8) & 0xFF; - command[1] = MOVECURSOR & 0xFF; - - command[2] = (line >> 8) & 0xFF; - command[3] = line & 0xFF; - - command[4] = (column >> 8) & 0xFF; - command[5] = column & 0xFF; - - writeCOMMAND(command, 6, 1); - current_row = line; - current_col = column; - -#if DEBUGMODE - pc.printf("Move cursor completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: put_char(char c) { // draw a text char - char command[4] = ""; - - command[0] = (PUTCHAR >> 8) & 0xFF; - command[1] = PUTCHAR & 0xFF; - - command[2] = 0x00; - command[3] = c; - - writeCOMMAND(command, 4, 1); - -#if DEBUGMODE - pc.printf("Put character completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: put_string(char *s) { // draw a text string - - char command[1000]= ""; - int size = strlen(s); - int i = 0; - - command[0] = (PUTSTRING >> 8) & 0xFF; - command[1] = PUTSTRING & 0xFF; - - for (i=0; i<size; i++) command[2+i] = s[i]; - - command[2+size] = 0; - - writeCOMMAND(command, 3 + size, 1); - -#if DEBUGMODE - pc.printf("Put string completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_fgd_color(int color) { // Set text foreground color - char command[4] = ""; - - command[0] = (TEXTFGCOLOR >> 8) & 0xFF; - command[1] = TEXTFGCOLOR & 0xFF; - - current_color = color; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Set text foreground color completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: text_bgd_color(int color) { // Set text background color - char command[4] = ""; - - command[0] = (TEXTBGCOLOR >> 8) & 0xFF; - command[1] = TEXTBGCOLOR & 0xFF; - - int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits - int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits - int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 4, 3); - -#if DEBUGMODE - pc.printf("Set text foreground color completed.\n"); -#endif -} - -//**************************************************************************************************** -void uVGAIII :: locate(char col, char row) { // place text curssor at col, row - current_col = col; - current_row = row; -} - -//**************************************************************************************************** -void uVGAIII :: color(int color) { // set text foreground color - current_color = color; -} - -//**************************************************************************************************** -void uVGAIII :: putc(char c) // place char at current cursor position - //used by virtual printf function _putc -{ - - pc.printf("\nCursor position: %d, %d",current_row,current_col); - if(c<0x20) { - if(c=='\n') { - current_col = 0; - current_row++; - move_cursor(current_row, current_col); - } - if(c=='\r') { - current_col = 0; - move_cursor(current_row, current_col); - } - if(c=='\f') { - cls(); //clear screen on form feed - } - } else { - put_char(c); - current_col++; - move_cursor(current_row, current_col); - } - if (current_col >= max_col) { - current_col = 0; - current_row++; - move_cursor(current_row, current_col); - } - if (current_row >= max_row) { - current_row = 0; - move_cursor(current_row, current_col); - } -} - -//**************************************************************************************************** -void uVGAIII :: puts(char *s) { // place string at current cursor position - - put_string(s); - - current_col += strlen(s); - - if (current_col >= max_col) { - current_row += current_col / max_col; - current_col %= max_col; - } - if (current_row >= max_row) { - current_row %= max_row; - } -} \ No newline at end of file
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII/uVGAIII_Touch.cpp --- a/uVGAIII/uVGAIII_Touch.cpp Mon Mar 24 17:29:15 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -// -// 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/>. - -#include "mbed.h" -#include "uVGAIII.h" - -//****************************************************************************************************** -int uVGAIII :: touch_status(void) { // Get the touch screen status - char command[4] = ""; - - command[0] = (TOUCHGET >> 8) & 0xFF; - command[1] = TOUCHGET & 0xFF; - - command[2] = (STATUS >> 8) & 0xFF; - command[3] = STATUS & 0xFF; - - return getSTATUS(command, 4); -} - -//****************************************************************************************************** -void uVGAIII :: touch_get_x(int *x) { // Get X coordinates - char command[4] = ""; - - command[0] = (TOUCHGET >> 8) & 0xFF; - command[1] = TOUCHGET & 0xFF; - - command[2] = 0; - command[3] = GETXPOSITION; - - getTOUCH(command, 4, x); - -#if DEBUGMODE - pc.printf("Get X coordinates completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: touch_get_y(int *y) { // Get Y coordinates - char command[4] = ""; - - command[0] = (TOUCHGET >> 8) & 0xFF; - command[1] = TOUCHGET & 0xFF; - - command[2] = 0; - command[3] = GETYPOSITION; - - getTOUCH(command, 4, y); - -#if DEBUGMODE - pc.printf("Get Y coordinates completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: touch_set(char mode) { // Sets various Touch Screen related parameters - - char command[4]= ""; - - command[0] = (TOUCHSET >>8) & 0xFF; - command[1] = TOUCHSET & 0xFF; - - command[2] = 0; - command[3] = mode; - - writeCOMMAND(command, 4, 1); - -#if DEBUGMODE - pc.printf("Touch set completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: detect_touch_region(int x1, int y1, int x2, int y2) { // Specificies a new touch detect region on the screen - char command[10] = ""; - - command[0] = (TOUCHDETECT >> 8) & 0xFF; - command[1] = TOUCHDETECT & 0xFF; - - command[2] = (x1 >> 8) & 0xFF; - command[3] = x1 & 0xFF; - - command[4] = (y1 >> 8) & 0xFF; - command[5] = y1 & 0xFF; - - command[6] = (x2 >> 8) & 0xFF; - command[7] = x2 & 0xFF; - - command[8] = (y2 >> 8) & 0xFF; - command[9] = y2 & 0xFF; - - writeCOMMAND(command, 10, 1); - -#if DEBUGMODE - pc.printf("Detect touch region completed.\n"); -#endif -} \ No newline at end of file
diff -r 333b7b189790 -r 6ecb8ceea422 uVGAIII/uVGAIII_main.cpp --- a/uVGAIII/uVGAIII_main.cpp Mon Mar 24 17:29:15 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,364 +0,0 @@ -// -// 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/>. - -#include "mbed.h" -#include "uVGAIII.h" - -#define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0]) - -//Serial pc(USBTX,USBRX); - -//****************************************************************************************************** -uVGAIII :: uVGAIII(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), - _rst(rst) -#if DEBUGMODE - ,pc(USBTX, USBRX) -#endif // DEBUGMODE -{ // Constructor - -#if DEBUGMODE - pc.baud(115200); - - pc.printf("\n\n\n"); - pc.printf("********************\n"); - pc.printf("uVGAIII CONSTRUCTOR\n"); - pc.printf("********************\n"); -#endif - _cmd.baud(9600); - _rst = 1; // put RESET pin to high to start TFT screen - - reset(); - cls(); // clear screen - speversion(); // get SPE version information - pmmcversion(); // get PmmC version information - - current_col = 0; // initial cursor col - current_row = 0; // initial cursor row - current_color = WHITE; // initial text color - current_orientation = IS_LANDSCAPE; // initial screen orientation - - set_font(FONT3); // initial font ( This line can be removed because font has been set to be FONT3 ) - text_opacity(OPAQUE); // initial text opacity ( This line can be removed because text opacity has been set to be OPAQUE ) -} - -//****************************************************************************************************** -void uVGAIII :: writeBYTE(char c) { // send a BYTE command to screen - - _cmd.putc(c); - wait_ms(1); - -#if DEBUGMODE - pc.printf(" Char sent : 0x%02X\n",c); -#endif - -} - -//****************************************************************************************************** -void uVGAIII :: freeBUFFER(void) { // Clear serial buffer before writing command - - while (_cmd.readable()) _cmd.getc(); // clear buffer garbage -} - -//****************************************************************************************************** -int uVGAIII :: writeCOMMAND(char *command, int commNum, int respNum) { // send several BYTES making a command and return an answer - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - int i, resp = 0; - freeBUFFER(); - - for (i = 0; i < commNum; i++) {writeBYTE(command[i]); wait_ms(100);} // send command to serial port - - for (i = 0; i < respNum; i++) { - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) { - resp = _cmd.getc(); // read response if any -#if DEBUGMODE - pc.printf("response = 0x%02X\n",resp); -#endif - } - } - return resp; -} - -//************************************************************************** -void uVGAIII :: reset() { // Reset Screen - - _rst = 0; // put RESET pin to low - wait_ms(TEMPO); // wait a few milliseconds for command reception - _rst = 1; // put RESET back to high - wait(3.2); // wait 3s for screen to restart - - freeBUFFER(); // clean buffer from possible garbage - -#if DEBUGMODE - pc.printf("Reset completed.\n"); -#endif -} - -//************************************************************************** -void uVGAIII :: speversion() { // get SPE version - char command[2] = ""; - int spe = 0; - command[0] = (SPEVERSION >> 8) & 0xFF; - command[1] = SPEVERSION & 0xFF; - - spe = readVERSION(command, 2); - - pc.printf("spe:%d\n",spe); -} - -//************************************************************************** -void uVGAIII :: pmmcversion() { // get PmmC version - char command[2] = ""; - int pmmc = 0; - command[0] = (PMMCVERSION >> 8) & 0xFF; - command[1] = PMMCVERSION & 0xFF; - - pmmc = readVERSION(command, 2); - - pc.printf("pmmc:%d\n",pmmc); -} - -//************************************************************************** -void uVGAIII :: baudrate(int speed) { // set screen baud rate - char command[4]= ""; - command[0] = ( BAUDRATE >> 8 ) & 0xFF; - command[1] = BAUDRATE & 0xFF; - switch (speed) { - case 110 : - command[2] = ( BAUD_110 >> 8 ) & 0xFF; - command[3] = BAUD_110 & 0xFF; - break; - case 300 : - command[2] = ( BAUD_300 >> 8 ) & 0xFF; - command[3] = BAUD_300 & 0xFF; - break; - case 600 : - command[2] = ( BAUD_600 >> 8 ) & 0xFF; - command[3] = BAUD_600 & 0xFF; - break; - case 1200 : - command[2] = ( BAUD_1200>> 8 ) & 0xFF; - command[3] = BAUD_1200 & 0xFF; - break; - case 2400 : - command[2] = ( BAUD_2400 >> 8 ) & 0xFF; - command[3] = BAUD_2400 & 0xFF; - break; - case 4800 : - command[2] = ( BAUD_4800 >> 8 ) & 0xFF; - command[3] = BAUD_4800 & 0xFF; - break; - case 9600 : - command[2] = ( BAUD_9600 >> 8 ) & 0xFF; - command[3] = BAUD_9600 & 0xFF; - break; - case 14400 : - command[2] = ( BAUD_9600 >> 8 ) & 0xFF; - command[3] = BAUD_9600 & 0xFF; - break; - case 19200 : - command[2] = ( BAUD_19200 >> 8 ) & 0xFF; - command[3] = BAUD_19200 & 0xFF; - break; - case 31250 : - command[2] = ( BAUD_31250 >> 8 ) & 0xFF; - command[3] = BAUD_31250 & 0xFF; - break; - case 38400 : - command[2] = ( BAUD_38400 >> 8 ) & 0xFF; - command[3] = BAUD_38400 & 0xFF; - break; - case 56000 : - command[2] = ( BAUD_56000 >> 8 ) & 0xFF; - command[3] = BAUD_56000 & 0xFF; - break; - case 57600 : - command[2] = ( BAUD_57600 >> 8 ) & 0xFF; - command[3] = BAUD_57600 & 0xFF; - break; - case 115200 : - command[2] = ( BAUD_115200 >> 8 ) & 0xFF; - command[3] = BAUD_115200 & 0xFF; - break; - case 128000 : - command[2] = ( BAUD_128000 >> 8 ) & 0xFF; - command[3] = BAUD_128000 & 0xFF; - break; - case 256000 : - command[2] = ( BAUD_256000 >> 8 ) & 0xFF; - command[3] = BAUD_256000 & 0xFF; - break; - default : - command[2] = ( BAUD_9600 >> 8 ) & 0xFF; - command[3] = BAUD_9600 & 0xFF; - speed = 9600; - break; - } -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - int i, resp = 0; - freeBUFFER(); - - for (i = 0; i < 4; i++) writeBYTE(command[i]); // send command to serial port - wait_ms(5); - _cmd.baud(speed); // set mbed to same speed - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) resp = _cmd.getc(); // read response if any - -#if DEBUGMODE - pc.printf("response = 0x%02X\n",resp); -#endif - -#if DEBUGMODE - pc.printf("Set baudrate completed.\n"); -#endif -} - -//****************************************************************************************************** -int uVGAIII :: readVERSION(char *command, int number) { // read screen info and populate data - - int i, temp = 0, resp = 0; - char response[5] = ""; - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable() && resp < ARRAY_SIZE(response)) { - temp = _cmd.getc(); - response[resp] = (char)temp; - pc.printf("response = 0x%02X\n",response[resp]); - resp++; - } - switch (resp) { - case 3 : // if OK populate data and return version - version = int(response[1]) << 8 | response[2]; - break; - default : - version = 0; // return 0 - break; - } - return version; -} - -//**************************************************************************************************** -void uVGAIII :: set_volume(char value) { // set sound volume to value - char command[4] = ""; - - command[0] = (SETVOLUME >> 8) & 0xFF; - command[1] = SETVOLUME & 0xFF; - - command[2] = 0; - command[3] = value; - - writeCOMMAND(command, 4, 1); - -#if DEBUGMODE - pc.printf("Sound volume completed.\n"); -#endif -} - -//****************************************************************************************************** -void uVGAIII :: getTOUCH(char *command, int number, int *xy) { // read screen info and populate data - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - int i, temp = 0, resp = 0; - char response[5] = ""; - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable() && resp < ARRAY_SIZE(response)) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - -#if DEBUGMODE - pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2]); -#endif - - switch (resp) { - case 3 : // if OK populate data - *xy = ((response[1]<<8)+ response[2]) * (response[1] != 0xFF); - break; - default : - *xy = -1; - break; - } - -#if DEBUGMODE - pc.printf(" X or Y : %03d\n", *xy); -#endif -} - -//****************************************************************************************************** -int uVGAIII :: getSTATUS(char *command, int number) { // read screen info and populate data - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); -#endif - - int i, temp = 0, resp = 0; - char response[5] = ""; - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable() && resp < ARRAY_SIZE(response)) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - switch (resp) { - case 3 : - resp = (int)response[2]; // if OK populate data - break; - default : - resp = -1; // else return 0 - break; - } - -#if DEBUGMODE - pc.printf(" Answer received : %d\n", resp); -#endif - - return resp; -} \ No newline at end of file