This is a library for 4DGL screens from 4D Systems in Autralia (http://www.4dsystems.com.au). Most graphic, touch and text functions are supported

Dependents:   snake

Fork of 4DGL by Stephane ROCHON

Committer:
Kerpower
Date:
Tue Sep 07 12:07:29 2010 +0000
Revision:
0:1102d253f057
Child:
1:4f9c6de0879f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kerpower 0:1102d253f057 1 //
Kerpower 0:1102d253f057 2 // TFT_4DGL is a class to drive 4D Systems TFT touch screens
Kerpower 0:1102d253f057 3 //
Kerpower 0:1102d253f057 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
Kerpower 0:1102d253f057 5 //
Kerpower 0:1102d253f057 6 // TFT_4DGL is free software: you can redistribute it and/or modify
Kerpower 0:1102d253f057 7 // it under the terms of the GNU General Public License as published by
Kerpower 0:1102d253f057 8 // the Free Software Foundation, either version 3 of the License, or
Kerpower 0:1102d253f057 9 // (at your option) any later version.
Kerpower 0:1102d253f057 10 //
Kerpower 0:1102d253f057 11 // TFT_4DGL is distributed in the hope that it will be useful,
Kerpower 0:1102d253f057 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
Kerpower 0:1102d253f057 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Kerpower 0:1102d253f057 14 // GNU General Public License for more details.
Kerpower 0:1102d253f057 15 //
Kerpower 0:1102d253f057 16 // You should have received a copy of the GNU General Public License
Kerpower 0:1102d253f057 17 // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>.
Kerpower 0:1102d253f057 18
Kerpower 0:1102d253f057 19 #include "mbed.h"
Kerpower 0:1102d253f057 20
Kerpower 0:1102d253f057 21 #ifndef DEBUGMODE
Kerpower 0:1102d253f057 22 #define DEBUGMODE 1
Kerpower 0:1102d253f057 23 #endif
Kerpower 0:1102d253f057 24
Kerpower 0:1102d253f057 25 // Common WAIT value in millisecond
Kerpower 0:1102d253f057 26 #define TEMPO 5
Kerpower 0:1102d253f057 27
Kerpower 0:1102d253f057 28 // 4DGL Functions values
Kerpower 0:1102d253f057 29 #define AUTOBAUD '\x55'
Kerpower 0:1102d253f057 30 #define CLS '\x45'
Kerpower 0:1102d253f057 31 #define BAUDRATE '\x51'
Kerpower 0:1102d253f057 32 #define VERSION '\x56'
Kerpower 0:1102d253f057 33 #define BCKGDCOLOR '\x42'
Kerpower 0:1102d253f057 34 #define DISPCONTROL '\x59'
Kerpower 0:1102d253f057 35 #define SETVOLUME '\x76'
Kerpower 0:1102d253f057 36 #define CIRCLE '\x43'
Kerpower 0:1102d253f057 37 #define TRIANGLE '\x47'
Kerpower 0:1102d253f057 38 #define LINE '\x4C'
Kerpower 0:1102d253f057 39 #define RECTANGLE '\x72'
Kerpower 0:1102d253f057 40 #define ELLIPSE '\x65'
Kerpower 0:1102d253f057 41 #define PIXEL '\x50'
Kerpower 0:1102d253f057 42 #define READPIXEL '\x52'
Kerpower 0:1102d253f057 43 #define SCREENCOPY '\x63'
Kerpower 0:1102d253f057 44 #define PENSIZE '\x70'
Kerpower 0:1102d253f057 45 #define SETFONT '\x46'
Kerpower 0:1102d253f057 46 #define TEXTMODE '\x4F'
Kerpower 0:1102d253f057 47 #define TEXTCHAR '\x54'
Kerpower 0:1102d253f057 48 #define GRAPHCHAR '\x74'
Kerpower 0:1102d253f057 49 #define TEXTSTRING '\x73'
Kerpower 0:1102d253f057 50 #define GRAPHSTRING '\x53'
Kerpower 0:1102d253f057 51 #define TEXTBUTTON '\x62'
Kerpower 0:1102d253f057 52 #define GETTOUCH '\x6F'
Kerpower 0:1102d253f057 53 #define WAITTOUCH '\x77'
Kerpower 0:1102d253f057 54 #define SETTOUCH '\x75'
Kerpower 0:1102d253f057 55
Kerpower 0:1102d253f057 56
Kerpower 0:1102d253f057 57 // Screen answers
Kerpower 0:1102d253f057 58 #define ACK '\x06'
Kerpower 0:1102d253f057 59 #define NAK '\x15'
Kerpower 0:1102d253f057 60
Kerpower 0:1102d253f057 61 // Screen states
Kerpower 0:1102d253f057 62 #define OFF '\x00'
Kerpower 0:1102d253f057 63 #define ON '\x01'
Kerpower 0:1102d253f057 64
Kerpower 0:1102d253f057 65 // Graphics modes
Kerpower 0:1102d253f057 66 #define SOLID '\x00'
Kerpower 0:1102d253f057 67 #define WIREFRAME '\x01'
Kerpower 0:1102d253f057 68
Kerpower 0:1102d253f057 69 // Text modes
Kerpower 0:1102d253f057 70 #define TRANSPARENT '\x00'
Kerpower 0:1102d253f057 71 #define OPAQUE '\x01'
Kerpower 0:1102d253f057 72
Kerpower 0:1102d253f057 73 // Fonts Sizes
Kerpower 0:1102d253f057 74 #define FONT_5X7 '\x00'
Kerpower 0:1102d253f057 75 #define FONT_8X8 '\x01'
Kerpower 0:1102d253f057 76 #define FONT_8X12 '\x02'
Kerpower 0:1102d253f057 77 #define FONT_12X16 '\x03'
Kerpower 0:1102d253f057 78
Kerpower 0:1102d253f057 79 // Touch Values
Kerpower 0:1102d253f057 80 #define WAIT '\x00'
Kerpower 0:1102d253f057 81 #define PRESS '\x01'
Kerpower 0:1102d253f057 82 #define RELEASE '\x02'
Kerpower 0:1102d253f057 83 #define MOVE '\x03'
Kerpower 0:1102d253f057 84 #define STATUS '\x04'
Kerpower 0:1102d253f057 85 #define GETPOSITION '\x05'
Kerpower 0:1102d253f057 86
Kerpower 0:1102d253f057 87 // Data speed
Kerpower 0:1102d253f057 88 #define BAUD_110 '\x00'
Kerpower 0:1102d253f057 89 #define BAUD_300 '\x01'
Kerpower 0:1102d253f057 90 #define BAUD_600 '\x02'
Kerpower 0:1102d253f057 91 #define BAUD_1200 '\x03'
Kerpower 0:1102d253f057 92 #define BAUD_2400 '\x04'
Kerpower 0:1102d253f057 93 #define BAUD_4800 '\x05'
Kerpower 0:1102d253f057 94 #define BAUD_9600 '\x06'
Kerpower 0:1102d253f057 95 #define BAUD_14400 '\x07'
Kerpower 0:1102d253f057 96 #define BAUD_19200 '\x09'
Kerpower 0:1102d253f057 97 #define BAUD_31250 '\x09'
Kerpower 0:1102d253f057 98 #define BAUD_38400 '\x0A'
Kerpower 0:1102d253f057 99 #define BAUD_56000 '\x0B'
Kerpower 0:1102d253f057 100 #define BAUD_57600 '\x0C'
Kerpower 0:1102d253f057 101 #define BAUD_115200 '\x0D'
Kerpower 0:1102d253f057 102 #define BAUD_128000 '\x0E'
Kerpower 0:1102d253f057 103 #define BAUD_256000 '\x0F'
Kerpower 0:1102d253f057 104
Kerpower 0:1102d253f057 105 // Defined Colors
Kerpower 0:1102d253f057 106 #define WHITE 0xFFFFFF
Kerpower 0:1102d253f057 107 #define BLACK 0x000000
Kerpower 0:1102d253f057 108 #define RED 0xFF0000
Kerpower 0:1102d253f057 109 #define GREEN 0x00FF00
Kerpower 0:1102d253f057 110 #define BLUE 0x0000FF
Kerpower 0:1102d253f057 111 #define LGREY 0xBFBFBF
Kerpower 0:1102d253f057 112 #define DGREY 0x5F5F5F
Kerpower 0:1102d253f057 113
Kerpower 0:1102d253f057 114 // Mode data
Kerpower 0:1102d253f057 115 #define BACKLIGHT '\x00'
Kerpower 0:1102d253f057 116 #define DISPLAY '\x01'
Kerpower 0:1102d253f057 117 #define CONTRAST '\x02'
Kerpower 0:1102d253f057 118 #define POWER '\x03'
Kerpower 0:1102d253f057 119 #define ORIENTATION '\x04'
Kerpower 0:1102d253f057 120 #define TOUCH_CTRL '\x05'
Kerpower 0:1102d253f057 121 #define IMAGE_FORMAT '\x06'
Kerpower 0:1102d253f057 122 #define PROTECT_FAT '\x08'
Kerpower 0:1102d253f057 123
Kerpower 0:1102d253f057 124 // change this to your specific screen (newer versions) if needed
Kerpower 0:1102d253f057 125 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
Kerpower 0:1102d253f057 126 #define SIZE_X 240
Kerpower 0:1102d253f057 127 #define SIZE_Y 320
Kerpower 0:1102d253f057 128
Kerpower 0:1102d253f057 129 #define IS_LANDSCAPE 0
Kerpower 0:1102d253f057 130 #define IS_PORTRAIT 1
Kerpower 0:1102d253f057 131
Kerpower 0:1102d253f057 132 // Screen orientation
Kerpower 0:1102d253f057 133 #define LANDSCAPE '\x01'
Kerpower 0:1102d253f057 134 #define LANDSCAPE_R '\x02'
Kerpower 0:1102d253f057 135 #define PORTRAIT '\x03'
Kerpower 0:1102d253f057 136 #define PORTRAIT_R '\x04'
Kerpower 0:1102d253f057 137
Kerpower 0:1102d253f057 138 // Parameters
Kerpower 0:1102d253f057 139 #define ENABLE '\x00'
Kerpower 0:1102d253f057 140 #define DISABLE '\x01'
Kerpower 0:1102d253f057 141 #define RESET '\x02'
Kerpower 0:1102d253f057 142
Kerpower 0:1102d253f057 143 #define NEW '\x00'
Kerpower 0:1102d253f057 144 #define OLD '\x01'
Kerpower 0:1102d253f057 145
Kerpower 0:1102d253f057 146 #define DOWN '\x00'
Kerpower 0:1102d253f057 147 #define UP '\x01'
Kerpower 0:1102d253f057 148
Kerpower 0:1102d253f057 149 #define PROTECT '\x00'
Kerpower 0:1102d253f057 150 #define UNPROTECT '\x02'
Kerpower 0:1102d253f057 151
Kerpower 0:1102d253f057 152 //**************************************************************************
Kerpower 0:1102d253f057 153 class TFT_4DGL {
Kerpower 0:1102d253f057 154
Kerpower 0:1102d253f057 155 public :
Kerpower 0:1102d253f057 156
Kerpower 0:1102d253f057 157 TFT_4DGL(PinName tx, PinName rx, PinName rst);
Kerpower 0:1102d253f057 158
Kerpower 0:1102d253f057 159 // General Commands
Kerpower 0:1102d253f057 160 void cls();
Kerpower 0:1102d253f057 161 void reset();
Kerpower 0:1102d253f057 162 void autobaud();
Kerpower 0:1102d253f057 163 void baudrate(int);
Kerpower 0:1102d253f057 164 void background_color(int);
Kerpower 0:1102d253f057 165 void display_control(char, char);
Kerpower 0:1102d253f057 166 void set_volume(char);
Kerpower 0:1102d253f057 167
Kerpower 0:1102d253f057 168 // Graphics Commands
Kerpower 0:1102d253f057 169 void circle(int, int, int, int);
Kerpower 0:1102d253f057 170 void triangle(int, int, int, int, int, int, int);
Kerpower 0:1102d253f057 171 void line(int, int, int, int, int);
Kerpower 0:1102d253f057 172 void rectangle(int, int, int, int, int);
Kerpower 0:1102d253f057 173 void ellipse(int, int, int, int, int);
Kerpower 0:1102d253f057 174 void pixel(int, int, int);
Kerpower 0:1102d253f057 175 int read_pixel(int, int);
Kerpower 0:1102d253f057 176 void screen_copy(int, int, int, int, int, int);
Kerpower 0:1102d253f057 177 void pen_size(char);
Kerpower 0:1102d253f057 178
Kerpower 0:1102d253f057 179 // Texts Commands
Kerpower 0:1102d253f057 180 void set_font(char);
Kerpower 0:1102d253f057 181 void text_mode(char);
Kerpower 0:1102d253f057 182 void text_char(char, char, char, int);
Kerpower 0:1102d253f057 183 void graphic_char(char, int, int, int, char, char);
Kerpower 0:1102d253f057 184 void text_string(char *, char, char, char, int);
Kerpower 0:1102d253f057 185 void graphic_string(char *, int, int, char, int, char, char);
Kerpower 0:1102d253f057 186 void text_button(char *, char, int, int, int, char, int, char, char);
Kerpower 0:1102d253f057 187
Kerpower 0:1102d253f057 188 void locate(char, char);
Kerpower 0:1102d253f057 189 void color(int);
Kerpower 0:1102d253f057 190 void putc(char);
Kerpower 0:1102d253f057 191 void puts(char *);
Kerpower 0:1102d253f057 192
Kerpower 0:1102d253f057 193 // Touch Command
Kerpower 0:1102d253f057 194 void touch_mode(char);
Kerpower 0:1102d253f057 195 void get_touch(int *, int *);
Kerpower 0:1102d253f057 196 void wait_touch(int);
Kerpower 0:1102d253f057 197 void set_touch(int, int, int, int);
Kerpower 0:1102d253f057 198 int touch_status(void);
Kerpower 0:1102d253f057 199
Kerpower 0:1102d253f057 200 // Screen Data
Kerpower 0:1102d253f057 201 int type;
Kerpower 0:1102d253f057 202 int revision;
Kerpower 0:1102d253f057 203 int firmware;
Kerpower 0:1102d253f057 204 int reserved1;
Kerpower 0:1102d253f057 205 int reserved2;
Kerpower 0:1102d253f057 206
Kerpower 0:1102d253f057 207 // Text data
Kerpower 0:1102d253f057 208 char current_col;
Kerpower 0:1102d253f057 209 char current_row;
Kerpower 0:1102d253f057 210 int current_color;
Kerpower 0:1102d253f057 211 char current_font;
Kerpower 0:1102d253f057 212 char current_orientation;
Kerpower 0:1102d253f057 213 char max_col;
Kerpower 0:1102d253f057 214 char max_row;
Kerpower 0:1102d253f057 215
Kerpower 0:1102d253f057 216 protected :
Kerpower 0:1102d253f057 217
Kerpower 0:1102d253f057 218 Serial _cmd;
Kerpower 0:1102d253f057 219 DigitalOut _rst;
Kerpower 0:1102d253f057 220
Kerpower 0:1102d253f057 221 void freeBUFFER (void);
Kerpower 0:1102d253f057 222 void writeBYTE (char);
Kerpower 0:1102d253f057 223 int writeCOMMAND(char *, int);
Kerpower 0:1102d253f057 224 int readVERSION (char *, int);
Kerpower 0:1102d253f057 225 void getTOUCH (char *, int, int *,int *);
Kerpower 0:1102d253f057 226 int getSTATUS (char *, int);
Kerpower 0:1102d253f057 227 void version (void);
Kerpower 0:1102d253f057 228 };
Kerpower 0:1102d253f057 229
Kerpower 0:1102d253f057 230 typedef unsigned char BYTE;