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
Revision 7:e39a44de229a, committed 2013-11-30
- Comitter:
- 4180_1
- Date:
- Sat Nov 30 02:05:15 2013 +0000
- Parent:
- 6:b759b69cbaf9
- Commit message:
- ver1.5
Changed in this revision
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL.h --- a/uLCD_4DGL.h Mon Nov 25 04:24:22 2013 +0000 +++ b/uLCD_4DGL.h Sat Nov 30 02:05:15 2013 +0000 @@ -1,7 +1,9 @@ // // uLCD_4DGL is a class to drive 4D Systems TFT touch screens // +// Fork of 4DGL library for 4D Systems LCD displays // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen // // uLCD_4DGL is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,16 +22,15 @@ #include "mbed.h" -// Debug Verbose on terminal enabled +// Debug Verbose off - SGE commands echoed to USB serial for debugmode=1 #ifndef DEBUGMODE #define DEBUGMODE 0 #endif -// Common WAIT value in millisecond -#define TEMPO 0.05 +// Common WAIT value in milliseconds between commands +#define TEMPO 0 -// 4DGL Functions values -#define AUTOBAUD '\x55' +// 4DGL SGE Function values for Goldelox Processor #define CLS '\xD7' #define BAUDRATE '\x0B' //null prefix #define VERSION '\x08' //null prefix @@ -37,10 +38,12 @@ #define TXTBCKGDCOLOR '\x7E' #define DISPCONTROL '\x68' #define SETVOLUME '\x76' -#define CIRCLE '\xCC' +#define CIRCLE '\xCD' +#define FCIRCLE '\xCC' #define TRIANGLE '\xC9' #define LINE '\xD2' -#define RECTANGLE '\xCE' +#define FRECTANGLE '\xCE' +#define RECTANGLE '\xCF' #define ELLIPSE '\x65' //na #define PIXEL '\xCB' #define READPIXEL '\xCA' @@ -51,19 +54,16 @@ #define TEXTBOLD '\x76' #define TEXTITALIC '\x75' #define TEXTINVERSE '\x74' +#define TEXTUNDERLINE '\x73' #define TEXTWIDTH '\x7C' #define TEXTHEIGHT '\x7B' #define TEXTCHAR '\xFE' -#define GRAPHCHAR '\x74' #define TEXTSTRING '\x06' //null prefix -#define GRAPHSTRING '\x53' -#define TEXTBUTTON '\x62' -#define GETTOUCH '\x6F' -#define WAITTOUCH '\x77' -#define SETTOUCH '\x75' +#define MOVECURSOR '\xE4' #define BLITCOM '\x0A' #define PUTCHAR '\xFE' - +#define DISPPOWER '\x66' +//media commands for uSD card #define MINIT '\xB1' #define SBADDRESS '\xB9' #define SSADDRESS '\xB8' @@ -102,14 +102,8 @@ #define FONT_8X8 '\x01' #define FONT_8X12 '\x02' #define FONT_12X16 '\x03' +#define MEDIAFONT '\x07' -// Touch Values -#define WAIT '\x00' -#define PRESS '\x01' -#define RELEASE '\x02' -#define MOVE '\x03' -#define STATUS '\x04' -#define GETPOSITION '\x05' // Data speed #define BAUD_110 27271 @@ -132,6 +126,10 @@ #define BAUD_375000 8 #define BAUD_500000 6 #define BAUD_600000 4 +#define BAUD_750000 3 +#define BAUD_1000000 2 +#define BAUD_1500000 1 +#define BAUD_3000000 0 // Defined Colors #define WHITE 0xFFFFFF @@ -154,6 +152,7 @@ // change this to your specific screen (newer versions) if needed // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y +//uLCD144-G2 is a 128 by 128 pixel display #define SIZE_X 128 #define SIZE_Y 128 @@ -161,10 +160,10 @@ #define IS_PORTRAIT 1 // Screen orientation -#define LANDSCAPE '\x01' -#define LANDSCAPE_R '\x02' -#define PORTRAIT '\x03' -#define PORTRAIT_R '\x04' +#define LANDSCAPE '\x00' +#define LANDSCAPE_R '\x01' +#define PORTRAIT '\x02' +#define PORTRAIT_R '\x03' // Parameters #define ENABLE '\x00' @@ -213,8 +212,7 @@ /** Reset screen */ void reset(); - /** Launch Autobaud for serial communication. This function is automatically called at startup */ - void autobaud(); + /** Set serial Baud rate (both sides : screen and mbed) * @param Speed Correct BAUD value (see uLCD_4DGL.h) */ @@ -235,8 +233,8 @@ * @param mode See 4DGL documentation * @param value See 4DGL documentation */ - void display_control(char mode, char value); - + void display_control(char mode); + void display_power(char mode); /** Set internal speaker to specified value * @param value Correct range is 8 - 127 */ @@ -251,31 +249,28 @@ * @param color Circle color in HEX RGB like 0xFF00FF */ 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 line(int, int, int, int, int); void rectangle(int, int, int, int, int); - void ellipse(int, int, int, int, int); + void filled_rectangle(int, int, int, int, int); void pixel(int, int, int); int read_pixel(int, int); - void screen_copy(int, int, int, int, int, int); void pen_size(char); void BLIT(int x, int y, int w, int h, int *colors); -// Texts Commands +// Text Commands void set_font(char); + void set_font_size(char width, char height); void text_mode(char); void text_bold(char); void text_italic(char); void text_inverse(char); + void text_underline(char); void text_width(char); void text_height(char); void text_char(char, char, char, int); - void graphic_char(char, int, int, int, char, char); void text_string(char *, char, char, char, int); - void graphic_string(char *, int, int, char, int, char, char); - void text_button(char *, char, int, int, int, char, int, char, char); - void locate(char, char); void color(int); void putc(char); @@ -292,18 +287,7 @@ void flush_media(); void display_image(int, int); void display_video(int, int); - void display_frame(int, int, int); - - - - - -// Touch Command - void touch_mode(char); - void get_touch(int *, int *); - void wait_touch(int); - void set_touch(int, int, int, int); - int touch_status(void); + void display_frame(int, int, int); // Screen Data int type; @@ -335,19 +319,17 @@ return 0; }; virtual int _getc() { - return 0; + return -1; } - void freeBUFFER (void); void writeBYTE (char); void writeBYTEfast (char); int writeCOMMAND(char *, int); int writeCOMMANDnull(char *, int); int readVERSION (char *, int); - void getTOUCH (char *, int, int *,int *); int getSTATUS (char *, int); - void version (void); + int version (void); #if DEBUGMODE Serial pc; #endif // DEBUGMODE @@ -361,3 +343,4 @@ +
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL_Graphics.cpp --- a/uLCD_4DGL_Graphics.cpp Mon Nov 25 04:24:22 2013 +0000 +++ b/uLCD_4DGL_Graphics.cpp Sat Nov 30 02:05:15 2013 +0000 @@ -2,6 +2,7 @@ // uLCD_4DGL is a class to drive 4D Systems LCD screens // // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen // // uLCD_4DGL is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -46,6 +47,31 @@ writeCOMMAND(command, 9); } +//**************************************************************************************************** +void uLCD_4DGL :: filled_circle(int x, int y , int radius, int color) // draw a circle in (x,y) +{ + char command[9]= ""; + + command[0] = FCIRCLE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (radius >> 8) & 0xFF; + command[6] = 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[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 9); +} //**************************************************************************************************** void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) // draw a traingle @@ -141,23 +167,23 @@ } //**************************************************************************************************** -void uLCD_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) // draw an ellipse +void uLCD_4DGL :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle { char command[11]= ""; - command[0] = ELLIPSE; + command[0] = FRECTANGLE; - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; - command[5] = (radius_x >> 8) & 0xFF; - command[6] = radius_x & 0xFF; + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; - command[7] = (radius_y >> 8) & 0xFF; - command[8] = radius_y & 0xFF; + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits @@ -169,6 +195,8 @@ writeCOMMAND(command, 11); } + + //**************************************************************************************************** void uLCD_4DGL :: pixel(int x, int y, int color) // draw a pixel { @@ -195,13 +223,13 @@ void uLCD_4DGL :: BLIT(int x, int y, int w, int h, int *colors) // draw a block of pixels { int red5, green6, blue5; - writeBYTE('\x00'); - writeBYTE(BLITCOM); - writeBYTE((x >> 8) & 0xFF); - writeBYTE(x & 0xFF); - writeBYTE((y >> 8) & 0xFF); - writeBYTE(y & 0xFF); - writeBYTE((w >> 8) & 0xFF); + writeBYTEfast('\x00'); + writeBYTEfast(BLITCOM); + writeBYTEfast((x >> 8) & 0xFF); + writeBYTEfast(x & 0xFF); + writeBYTEfast((y >> 8) & 0xFF); + writeBYTEfast(y & 0xFF); + writeBYTEfast((w >> 8) & 0xFF); writeBYTE(w & 0xFF); writeBYTE((h >> 8) & 0xFF); writeBYTE(h & 0xFF); @@ -267,34 +295,6 @@ return color; // WARNING : this is 16bits color, not 24bits... need to be fixed } -//****************************************************************************************************** -void uLCD_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) -{ - - char command[13]= ""; - - command[0] = SCREENCOPY; - - command[1] = (xs >> 8) & 0xFF; - command[2] = xs & 0xFF; - - command[3] = (ys >> 8) & 0xFF; - command[4] = ys & 0xFF; - - command[5] = (xd >> 8) & 0xFF; - command[6] = xd & 0xFF; - - command[7] = (yd >> 8) & 0xFF; - command[8] = yd & 0xFF; - - command[9] = (width >> 8) & 0xFF; - command[10] = width & 0xFF; - - command[11] = (height >> 8) & 0xFF; - command[12] = height & 0xFF; - - writeCOMMAND(command, 13); -} //**************************************************************************************************** void uLCD_4DGL :: pen_size(char mode) // set pen to SOLID or WIREFRAME @@ -303,8 +303,8 @@ command[0] = PENSIZE; command[1] = mode; - writeCOMMAND(command, 2); } +
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL_Media.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uLCD_4DGL_Media.cpp Sat Nov 30 02:05:15 2013 +0000 @@ -0,0 +1,177 @@ +// +// uLCD_4DGL is a class to drive 4D Systems LCD screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen +// +// uLCD_4DGL 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. +// +// uLCD_4DGL 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 uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "uLCD_4DGL.h" + + +//Media Commands + +//****************************************************************************************************** +int uLCD_4DGL :: media_init() +{ + int resp = 0; + char command[1] = ""; + command[0] = MINIT; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = resp << 8 + _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +void uLCD_4DGL :: set_byte_address(int hi, int lo) +{ + char command[5]= ""; + command[0] = SBADDRESS; + + command[1] = (hi >> 8) & 0xFF; + command[2] = hi & 0xFF; + + command[3] = (lo >> 8) & 0xFF; + command[4] = lo & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: set_sector_address(int hi, int lo) +{ + + char command[5]= ""; + command[0] = SSADDRESS; + + command[1] = (hi >> 8) & 0xFF; + command[2] = hi & 0xFF; + + command[3] = (lo >> 8) & 0xFF; + command[4] = lo & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +char uLCD_4DGL :: read_byte() +{ + char resp = 0; + char command[1] = ""; + command[0] = READBYTE; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +int uLCD_4DGL :: read_word() +{ + int resp=0; + char command[1] = ""; + command[0] = READWORD; + writeCOMMAND(command, 1); + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) { + resp = _cmd.getc(); // read response + resp = resp << 8 + _cmd.getc(); + } + return resp; +} + +//****************************************************************************************************** +void uLCD_4DGL :: write_byte(int value) +{ + char command[3]= ""; + + command[0] = WRITEBYTE; + + command[1] = (value >> 8) & 0xFF; + command[2] = value & 0xFF; + writeCOMMAND(command,3); +} + +//****************************************************************************************************** +void uLCD_4DGL :: write_word(int value) +{ + char command[3]= ""; + + command[0] = WRITEWORD; + + command[1] = (value >> 8) & 0xFF; + command[2] = value & 0xFF; + writeCOMMAND(command,3); +} + +//****************************************************************************************************** +void uLCD_4DGL :: flush_media() +{ + char command[1] = ""; + command[0] = FLUSHMEDIA; + writeCOMMAND(command, 1); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_image(int x, int y) +{ + char command[6]= ""; + command[0] = DISPLAYIMAGE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_video(int x, int y) +{ + char command[5]= ""; + command[0] = DISPLAYVIDEO; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + writeCOMMAND(command, 5); +} + +//****************************************************************************************************** +void uLCD_4DGL :: display_frame(int x, int y, int w) +{ + char command[7]= ""; + + command[0] = DISPLAYFRAME; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (w >> 8) & 0xFF; + command[6] = w & 0xFF; + writeCOMMAND(command,7); +} +
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL_Text.cpp --- a/uLCD_4DGL_Text.cpp Mon Nov 25 04:24:22 2013 +0000 +++ b/uLCD_4DGL_Text.cpp Sat Nov 30 02:05:15 2013 +0000 @@ -2,6 +2,7 @@ // uLCD_4DGL is a class to drive 4D Systems TFT touch screens // // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen // // uLCD_4DGL is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,7 +21,21 @@ #include "uLCD_4DGL.h" //**************************************************************************************************** -void uLCD_4DGL :: set_font(char mode) // set font size +void uLCD_4DGL :: set_font_size(char width, char height) // set font size +{ + if (current_orientation == IS_PORTRAIT) { + current_fx = width; + current_fy = height; + } else { + current_fy = height; + current_fx = width; + } + max_col = current_w / (current_fx*current_wf); + max_row = current_h / (current_fy*current_hf); +} + +//**************************************************************************************************** +void uLCD_4DGL :: set_font(char mode) // set font - system or SD media { char command[3]= ""; @@ -40,6 +55,7 @@ switch (mode) { case FONT_5X7 : + current_fx = 6; current_fy = 8; break; @@ -59,6 +75,9 @@ current_fx = 12; current_fy = 16; break; + default: + current_fx = 8; + current_fy = 8; } max_col = current_w / (current_fx*current_wf); @@ -118,6 +137,18 @@ } //**************************************************************************************************** +void uLCD_4DGL :: text_underline(char mode) // set text mode +{ + char command[3]= ""; + + command[0] = TEXTUNDERLINE; + command[1] = 0; + command[2] = mode; + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** void uLCD_4DGL :: text_width(char width) // set text width { char command[3]= ""; @@ -172,34 +203,6 @@ } -//**************************************************************************************************** -void uLCD_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) // draw a graphic char -{ - char command[10]= ""; - - command[0] = GRAPHCHAR; - - command[1] = c; - - 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 - - command[8] = width; - - command[9] = height; - - writeCOMMAND(command, 10); -} //**************************************************************************************************** void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color) // draw a text string @@ -233,86 +236,7 @@ writeCOMMANDnull(command, 2 + size); } -//**************************************************************************************************** -void uLCD_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) // draw a text string -{ - char command[1000]= ""; - int size = strlen(s); - int i = 0; - - command[0] = GRAPHSTRING; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - command[5] = font; - - 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 - - command[8] = width; - - command[9] = height; - - for (i=0; i<size; i++) command[10+i] = s[i]; - - command[10+size] = 0; - - writeCOMMAND(command, 11 + size); -} - -//**************************************************************************************************** -void uLCD_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height) // draw a text string -{ - - char command[1000]= ""; - int size = strlen(s); - int i = 0, red5, green6, blue5; - - command[0] = TEXTBUTTON; - - command[1] = mode; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (button_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 - - command[8] = font; - - red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - command[11] = width; - - command[12] = height; - - for (i=0; i<size; i++) command[13+i] = s[i]; - - command[13+size] = 0; - - writeCOMMAND(command, 14 + size); -} //**************************************************************************************************** void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row @@ -320,7 +244,7 @@ char command[5] = ""; current_col = col; current_row = row; - command[0] = 0xE4; //move cursor + command[0] = MOVECURSOR; //move cursor command[1] = 0; command[2] = current_row; command[3] = 0; @@ -349,26 +273,40 @@ //used by virtual printf function _putc { char command[6] =""; - - if(c=='\n') { - current_col = 0; - current_row++; - command[0] = 0xE4; //move cursor to start of next line - command[1] = 0; - command[2] = current_row; - command[3] = 0; - command[4] = current_col; - writeCOMMAND(command, 5); + if(c<0x20) { + if(c=='\n') { + current_col = 0; + current_row++; + command[0] = MOVECURSOR; //move cursor to start of next line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } + if(c=='\r') { + current_col = 0; + command[0] = MOVECURSOR; //move cursor to start of line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } + if(c=='\f') { + uLCD_4DGL::cls(); //clear screen on form feed + } } else { command[0] = PUTCHAR; command[1] = 0x00; command[2] = c; writeCOMMAND(command,3); + current_col++; } if (current_col == max_col) { current_col = 0; current_row++; - command[0] = 0xE4; //move cursor to next line + command[0] = MOVECURSOR; //move cursor to next line command[1] = 0; command[2] = current_row; command[3] = 0; @@ -377,7 +315,7 @@ } if (current_row == max_row) { current_row = 0; - command[0] = 0xE4; //move cursor back to start + command[0] = MOVECURSOR; //move cursor back to start command[1] = 0; command[2] = current_row; command[3] = 0;
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL_Touch.cpp --- a/uLCD_4DGL_Touch.cpp Mon Nov 25 04:24:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,247 +0,0 @@ -// -// uLCD_4DGL is a class to drive 4D Systems LCD screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// uLCD_4DGL 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. -// -// uLCD_4DGL 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 uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. - -#include "mbed.h" -#include "uLCD_4DGL.h" - -//****************************************************************************************************** -void uLCD_4DGL :: touch_mode(char mode) // Send touch mode (WAIT, PRESS, RELEASE or MOVE) -{ - - char command[2]= ""; - - command[0] = GETTOUCH; - command[1] = mode; - - writeCOMMAND(command, 2); -} - -//****************************************************************************************************** -void uLCD_4DGL :: get_touch(int *x, int *y) // Get the touch coordinates -{ - - char command[2] = ""; - - command[0] = GETTOUCH; - command[1] = GETPOSITION; - - getTOUCH(command, 2, x, y); -} - -//****************************************************************************************************** -int uLCD_4DGL :: touch_status(void) // Get the touch screen status -{ - - char command[2] = ""; - - command[0] = GETTOUCH; - command[1] = STATUS; - - return getSTATUS(command, 2); -} - - -//****************************************************************************************************** -void uLCD_4DGL :: wait_touch(int delay) // wait until touch within a delay in milliseconds -{ - - char command[3]= ""; - - command[0] = WAITTOUCH; - - command[1] = (delay >> 8) & 0xFF; - command[2] = delay & 0xFF; - - writeCOMMAND(command, 3); -} - -//****************************************************************************************************** -void uLCD_4DGL :: set_touch(int x1, int y1 , int x2, int y2) // define touch area -{ - - char command[9]= ""; - - command[0] = SETTOUCH; - - command[1] = (x1 >> 8) & 0xFF; - command[2] = x1 & 0xFF; - - command[3] = (y1 >> 8) & 0xFF; - command[4] = y1 & 0xFF; - - command[5] = (x2 >> 8) & 0xFF; - command[6] = x2 & 0xFF; - - command[7] = (y2 >> 8) & 0xFF; - command[8] = y2 & 0xFF; - - writeCOMMAND(command, 9); -} -//Media Commands - -//****************************************************************************************************** -int uLCD_4DGL :: media_init() -{ - int resp = 0; - char command[1] = ""; - command[0] = MINIT; - writeCOMMAND(command, 1); - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) { - resp = _cmd.getc(); // read response - resp = resp << 8 + _cmd.getc(); - } - return resp; -} - -//****************************************************************************************************** -void uLCD_4DGL :: set_byte_address(int hi, int lo) -{ - char command[5]= ""; - command[0] = SBADDRESS; - - command[1] = (hi >> 8) & 0xFF; - command[2] = hi & 0xFF; - - command[3] = (lo >> 8) & 0xFF; - command[4] = lo & 0xFF; - writeCOMMAND(command, 5); -} - -//****************************************************************************************************** -void uLCD_4DGL :: set_sector_address(int hi, int lo) -{ - - char command[5]= ""; - command[0] = SSADDRESS; - - command[1] = (hi >> 8) & 0xFF; - command[2] = hi & 0xFF; - - command[3] = (lo >> 8) & 0xFF; - command[4] = lo & 0xFF; - writeCOMMAND(command, 5); -} - -//****************************************************************************************************** -char uLCD_4DGL :: read_byte() -{ - char resp = 0; - char command[1] = ""; - command[0] = READBYTE; - writeCOMMAND(command, 1); - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) { - resp = _cmd.getc(); // read response - resp = _cmd.getc(); - } - return resp; -} - -//****************************************************************************************************** -int uLCD_4DGL :: read_word() -{ - int resp=0; - char command[1] = ""; - command[0] = READWORD; - writeCOMMAND(command, 1); - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) { - resp = _cmd.getc(); // read response - resp = resp << 8 + _cmd.getc(); - } - return resp; -} - -//****************************************************************************************************** -void uLCD_4DGL :: write_byte(int value) -{ - char command[3]= ""; - - command[0] = WRITEBYTE; - - command[1] = (value >> 8) & 0xFF; - command[2] = value & 0xFF; - writeCOMMAND(command,3); -} - -//****************************************************************************************************** -void uLCD_4DGL :: write_word(int value) -{ - char command[3]= ""; - - command[0] = WRITEWORD; - - command[1] = (value >> 8) & 0xFF; - command[2] = value & 0xFF; - writeCOMMAND(command,3); -} - -//****************************************************************************************************** -void uLCD_4DGL :: flush_media() -{ - char command[1] = ""; - command[0] = FLUSHMEDIA; - writeCOMMAND(command, 1); -} - -//****************************************************************************************************** -void uLCD_4DGL :: display_image(int x, int y) -{ - char command[6]= ""; - command[0] = DISPLAYIMAGE; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - writeCOMMAND(command, 5); -} - -//****************************************************************************************************** -void uLCD_4DGL :: display_video(int x, int y) -{ - char command[5]= ""; - command[0] = DISPLAYVIDEO; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - writeCOMMAND(command, 5); -} - -//****************************************************************************************************** -void uLCD_4DGL :: display_frame(int x, int y, int w) -{ - char command[7]= ""; - - command[0] = DISPLAYFRAME; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - command[5] = (w >> 8) & 0xFF; - command[6] = w & 0xFF; - writeCOMMAND(command,7); -}
diff -r b759b69cbaf9 -r e39a44de229a uLCD_4DGL_main.cpp --- a/uLCD_4DGL_main.cpp Mon Nov 25 04:24:22 2013 +0000 +++ b/uLCD_4DGL_main.cpp Sat Nov 30 02:05:15 2013 +0000 @@ -2,6 +2,7 @@ // uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2 // // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// Modifed for Goldelox processor <2013> Jim Hamblen // // uLCD_4DGL is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -44,11 +45,7 @@ _rst = 1; // put RESET pin to high to start TFT screen reset(); - -// autobaud(); // send autobaud command -// version(); // get version information cls(); // clear screen - current_col = 0; // initial cursor col current_row = 0; // initial cursor row current_color = WHITE; // initial text color @@ -64,7 +61,7 @@ { _cmd.putc(c); - wait_ms(1); //mbed is too fast for LCD at high baud rates in long commands + wait_us(500); //mbed is too fast for LCD at high baud rates in some long commands #if DEBUGMODE pc.printf(" Char sent : 0x%02X\n",c); @@ -77,7 +74,7 @@ { _cmd.putc(c); - //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in some commands + //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in short commands #if DEBUGMODE pc.printf(" Char sent : 0x%02X\n",c); @@ -151,10 +148,10 @@ freeBUFFER(); writeBYTE(0x00); //command has a null prefix byte for (i = 0; i < number; i++) { - if (i<16) + if (i<16) //don't overflow LCD UART buffer writeBYTEfast(command[i]); // send command to serial port else - writeBYTE(command[i]); // send command to serial port + writeBYTE(command[i]); // send command to serial port with delay } while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer if (_cmd.readable()) resp = _cmd.getc(); // read response if any @@ -176,16 +173,6 @@ return resp; } - -//************************************************************************** -void uLCD_4DGL :: autobaud() // send AutoBaud command (9600) -{ - writeBYTE(AUTOBAUD); - char command[1] = ""; - command[0] = AUTOBAUD; - writeCOMMAND(command, 1); -} - //************************************************************************** void uLCD_4DGL :: cls() // clear screen { @@ -193,18 +180,21 @@ command[0] = CLS; writeCOMMAND(command, 1); + current_row=0; + current_col=0; current_hf = 1; current_wf = 1; set_font(FONT_7X8); // initial font } //************************************************************************** -void uLCD_4DGL :: version() // get API version +int uLCD_4DGL :: version() // get API version { + char command[2] = ""; - command[0] = VERSION; - command[1] = OFF; - readVERSION(command, 2); + command[0] = '\x00'; + command[1] = VERSION; + return readVERSION(command, 2); } //************************************************************************** @@ -279,6 +269,18 @@ case 600000 : newbaud = BAUD_600000; break; + case 750000 : //rates over 600000 are not documented, but seem to work + newbaud = BAUD_750000; + break; + case 1000000 : + newbaud = BAUD_1000000; + break; + case 1500000 : + newbaud = BAUD_1500000; + break; + case 3000000 : + newbaud = BAUD_3000000; + break; default : newbaud = BAUD_9600; speed = 9600; @@ -292,7 +294,8 @@ command[2] = char(newbaud % 256); wait_ms(1); for (i = 0; i <3; i++) writeBYTEfast(command[i]); // send command to serial port - wait_ms(10); //dont change baud until all characters get sent out + for (i = 0; i<10; i++) wait_ms(1); + //dont change baud until all characters get sent out _cmd.baud(speed); // set mbed to same speed i=0; while ((!_cmd.readable()) && (i<25000)) { @@ -377,16 +380,16 @@ } //**************************************************************************************************** -void uLCD_4DGL :: display_control(char mode, char value) // set screen mode to value +void uLCD_4DGL :: display_control(char mode) // set screen mode to value { char command[3]= ""; command[0] = DISPCONTROL; - command[1] = mode; - command[2] = value; + command[1] = 0; + command[2] = mode; if (mode == ORIENTATION) { - switch (value) { + switch (mode) { case LANDSCAPE : current_orientation = IS_LANDSCAPE; break; @@ -404,7 +407,16 @@ writeCOMMAND(command, 3); set_font(current_font); } +//**************************************************************************************************** +void uLCD_4DGL :: display_power(char mode) // set screen mode to value +{ + char command[3]= ""; + command[0] = DISPPOWER; + command[1] = 0; + command[2] = mode; + writeCOMMAND(command, 3); +} //**************************************************************************************************** void uLCD_4DGL :: set_volume(char value) // set sound volume to value { @@ -418,48 +430,6 @@ //****************************************************************************************************** -void uLCD_4DGL :: getTOUCH(char *command, int number, int *x, int *y) // read screen info and populate data -{ - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X\n", command[0]); -#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 0x%02X\n", resp, response[0], response[1], response[2], response[3]); -#endif - - switch (resp) { - case 4 : // if OK populate data - *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF); - *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF); - break; - default : - *x = -1; - *y = -1; - break; - } - -#if DEBUGMODE - pc.printf(" X,Y : %03d,%03d\n", *x, *y); -#endif -} - -//****************************************************************************************************** int uLCD_4DGL :: getSTATUS(char *command, int number) // read screen info and populate data { @@ -496,3 +466,4 @@ return resp; } +