Tinkerbell fractal

Committer:
JLS
Date:
Sun Dec 26 19:53:45 2010 +0000
Revision:
1:1ea2331f9cbe
update

Who changed what in which revision?

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