Rihards Balass / 4DGL-mbed-32PTU
Committer:
CaptainR
Date:
Tue Sep 27 10:45:38 2016 +0000
Revision:
23:dd2c28fa4dfd
Parent:
22:cea582ea74c1
Child:
24:19c77967674e
findFirstReturn - done :)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CaptainR 0:a5ef6bc3c2e8 1 //
CaptainR 2:81eaaa491a02 2 // Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
CaptainR 2:81eaaa491a02 3 // Tested with NUCLEO L152RE development board
CaptainR 2:81eaaa491a02 4 // Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
CaptainR 0:a5ef6bc3c2e8 5 //
CaptainR 2:81eaaa491a02 6 // Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify
CaptainR 2:81eaaa491a02 7 // it under the terms of the GNU General Public License as published by
CaptainR 2:81eaaa491a02 8 // the Free Software Foundation, either version 3 of the License, or
CaptainR 2:81eaaa491a02 9 // (at your option) any later version.
CaptainR 2:81eaaa491a02 10 //
CaptainR 2:81eaaa491a02 11 // Picaso_4DGL-32PTU is distributed in the hope that it will be useful,
CaptainR 2:81eaaa491a02 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
CaptainR 2:81eaaa491a02 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
CaptainR 2:81eaaa491a02 14 // GNU General Public License for more details.
CaptainR 2:81eaaa491a02 15 //
CaptainR 2:81eaaa491a02 16 // You can see GNU General Public License at <http://www.gnu.org/licenses/>.
CaptainR 0:a5ef6bc3c2e8 17 //
CaptainR 0:a5ef6bc3c2e8 18
CaptainR 0:a5ef6bc3c2e8 19 #include "mbed.h"
CaptainR 21:ea68a8a3cea4 20 #include "Picaso_4DGL-32PTU_CONSTANTS.h"
CaptainR 21:ea68a8a3cea4 21 #include <string>
CaptainR 12:29f5ad896382 22
CaptainR 0:a5ef6bc3c2e8 23 // functions
CaptainR 2:81eaaa491a02 24 #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) // to check if required bit is set
CaptainR 0:a5ef6bc3c2e8 25
CaptainR 0:a5ef6bc3c2e8 26
CaptainR 12:29f5ad896382 27 // Main commands
CaptainR 3:dcfbceb81fef 28 #define BAUDRATE 0x0026
CaptainR 3:dcfbceb81fef 29 #define ORIENTATION 0xFF9E
CaptainR 0:a5ef6bc3c2e8 30
CaptainR 12:29f5ad896382 31 // text commands
CaptainR 5:890ddd974624 32 #define TEXT_BG_COLOR 0xFFE6
CaptainR 3:dcfbceb81fef 33 #define SET_FONT 0xFFE5
CaptainR 3:dcfbceb81fef 34 #define PUT_CHAR 0xFFFE
CaptainR 3:dcfbceb81fef 35 #define PUT_STRING 0x0018
CaptainR 3:dcfbceb81fef 36 #define MOVE_CURSOR 0xFFE9
CaptainR 3:dcfbceb81fef 37 #define TEXT_FG_COLOR 0xFFE7
CaptainR 3:dcfbceb81fef 38 #define TEXT_WIDTH 0xFFE4
CaptainR 3:dcfbceb81fef 39 #define TEXT_HEIGHT 0xFFE3
CaptainR 3:dcfbceb81fef 40 #define TEXT_X_GAP 0xFFE2
CaptainR 3:dcfbceb81fef 41 #define TEXT_Y_GAP 0xFFE1
CaptainR 3:dcfbceb81fef 42 #define TEXT_BOLD 0xFFDE
CaptainR 3:dcfbceb81fef 43 #define TEXT_INVERSE 0xFFDC
CaptainR 3:dcfbceb81fef 44 #define TEXT_ITALIC 0xFFDD
CaptainR 3:dcfbceb81fef 45 #define TEXT_OPACITY 0xFFDF
CaptainR 3:dcfbceb81fef 46 #define TEXT_UNDERLINE 0xFFDB
CaptainR 3:dcfbceb81fef 47 #define TEXT_ATTRIBUTES 0xFFDA
CaptainR 0:a5ef6bc3c2e8 48
CaptainR 12:29f5ad896382 49 // graphics commands
CaptainR 5:890ddd974624 50 #define CHANGE_COLOR 0xFFB4
CaptainR 3:dcfbceb81fef 51 #define DRAW_CIRCLE 0xFFC3
CaptainR 3:dcfbceb81fef 52 #define CIRCLE_FILLED 0xFFC2
CaptainR 3:dcfbceb81fef 53 #define DRAW_LINE 0xFFC8
CaptainR 3:dcfbceb81fef 54 #define DRAW_RECTANGLE 0xFFC5
CaptainR 3:dcfbceb81fef 55 #define RECTANGLE_FILLED 0xFFC4
CaptainR 3:dcfbceb81fef 56 #define DRAW_POLYLINE 0x0015
CaptainR 3:dcfbceb81fef 57 #define DRAW_POLYGON 0x0013
CaptainR 3:dcfbceb81fef 58 #define POLYGON_FILLED 0x0014
CaptainR 3:dcfbceb81fef 59 #define DRAW_TRIANGLE 0xFFBF
CaptainR 3:dcfbceb81fef 60 #define TRIANGLE_FILLED 0xFFA9
CaptainR 4:50511ed54ab4 61 #define CALCULATE_ORBIT 0x0012
CaptainR 6:a1a85f2bc04b 62 #define PUT_PIXEL 0xFFC1
CaptainR 6:a1a85f2bc04b 63 #define MOVE_ORIGIN 0xFFCC
CaptainR 8:b634ac9c92f8 64 #define LINE_TO 0xFFCA
CaptainR 9:32eb75c01e9d 65 #define SET_CLIP_WINDOW 0xFFB5
CaptainR 9:32eb75c01e9d 66 #define CLIPPING 0xFFA2
CaptainR 9:32eb75c01e9d 67 #define EXTEND_CLIP 0xFFB3
CaptainR 10:b959bb206e6b 68 #define DRAW_ELIPSE 0xFFB2
CaptainR 10:b959bb206e6b 69 #define ELIPSE_FILLED 0xFFB1
CaptainR 10:b959bb206e6b 70 #define DRAW_BUTTON 0x0011
CaptainR 10:b959bb206e6b 71 #define BEVEL_SHADOW 0xFF98
CaptainR 11:3ebd2263f3e9 72 #define BEVEL_WIDTH 0xFF99
CaptainR 10:b959bb206e6b 73 #define DRAW_PANEL 0xFFAF
CaptainR 10:b959bb206e6b 74 #define DRAW_SLIDER 0xFFAE
CaptainR 10:b959bb206e6b 75 #define SCREEN_CP 0xFFAD
CaptainR 11:3ebd2263f3e9 76 #define BG_COLOR 0xFFA4
CaptainR 11:3ebd2263f3e9 77 #define OUTLINE_COLOR 0xFF9D
CaptainR 11:3ebd2263f3e9 78 #define CONTRAST 0xFF9C
CaptainR 11:3ebd2263f3e9 79 #define FRAME_DELAY 0xFF9F
CaptainR 11:3ebd2263f3e9 80 #define LINE_PATERN 0xFF9B
CaptainR 11:3ebd2263f3e9 81 #define TRANSPARENCY 0xFFA0
CaptainR 11:3ebd2263f3e9 82 #define TRANSPARENT_COLOR 0xFFA1
CaptainR 11:3ebd2263f3e9 83 #define SET_GRAPHICS 0xFFCE
CaptainR 11:3ebd2263f3e9 84 #define GET_GRAPHICS 0xFFA6
CaptainR 12:29f5ad896382 85 #define CLS 0xFFCD
CaptainR 8:b634ac9c92f8 86
CaptainR 12:29f5ad896382 87 // media commands
CaptainR 12:29f5ad896382 88 #define MEDIA_INIT 0xFF89
CaptainR 12:29f5ad896382 89 #define MEDIA_SET_ADD 0xFF93
CaptainR 12:29f5ad896382 90 #define MEDIA_SET_SECTOR 0xFF92
CaptainR 12:29f5ad896382 91 #define MEDIA_READ_SECTOR 0x0016
CaptainR 12:29f5ad896382 92 #define MEDIA_WRITE_SECTOR 0x0017
CaptainR 16:cb072eea16e9 93 #define MEDIA_READ_BYTE 0xFF8F
CaptainR 18:829f3e2c064c 94 #define MEDIA_READ_WORD 0xFF8E
CaptainR 19:a259bc128867 95 #define MEDIA_WRITE_BYTE 0xFF8D
CaptainR 20:88e137b9ea46 96 #define MEDIA_WRITE_WORD 0xFF8C
CaptainR 20:88e137b9ea46 97 #define MEDIA_FLUSH 0xFF8A
CaptainR 20:88e137b9ea46 98
CaptainR 20:88e137b9ea46 99 // FAT16 file system commands
CaptainR 20:88e137b9ea46 100 #define FILE_MOUNT 0xFF03
CaptainR 21:ea68a8a3cea4 101 #define FILE_ERROR 0xFF1F
CaptainR 22:cea582ea74c1 102 #define FILE_COUNT 0x0001
CaptainR 22:cea582ea74c1 103 #define FILE_DIR 0x0002
CaptainR 22:cea582ea74c1 104 #define FILE_FIRST 0x0006
CaptainR 22:cea582ea74c1 105 #define FILE_FIRST_RET 0x0024
CaptainR 22:cea582ea74c1 106 #define FILE_NEXT 0x
CaptainR 22:cea582ea74c1 107 #define FILE_NEXT_REP 0x
CaptainR 22:cea582ea74c1 108 #define FILE_EXISTS 0x
CaptainR 22:cea582ea74c1 109 #define FILE_OPEN 0x
CaptainR 22:cea582ea74c1 110 #define FILE_CLOSE 0x
CaptainR 22:cea582ea74c1 111 #define FILE_READ 0x
CaptainR 22:cea582ea74c1 112 #define FILE_SEEK 0x
CaptainR 22:cea582ea74c1 113 #define FILE_INDEX 0x
CaptainR 22:cea582ea74c1 114 #define FILE_TELL 0x
CaptainR 22:cea582ea74c1 115 #define FILE_WRITE 0x
CaptainR 22:cea582ea74c1 116 #define FILE_SIZE 0x
CaptainR 22:cea582ea74c1 117 #define FILE_IMAGE 0x
CaptainR 22:cea582ea74c1 118 #define FILE_S_CAPTURE 0x
CaptainR 22:cea582ea74c1 119 #define FILE_CHAR_TO 0x
CaptainR 22:cea582ea74c1 120 #define FILE_CHAR_FROM 0x
CaptainR 22:cea582ea74c1 121 #define FILE_WORD_TO 0x
CaptainR 22:cea582ea74c1 122 #define FILE_WORD_FROM 0x
CaptainR 22:cea582ea74c1 123 #define FILE_STRING_TO 0x
CaptainR 22:cea582ea74c1 124 #define FILE_STRING_FROM 0x
CaptainR 22:cea582ea74c1 125 #define FILE_ERASE 0x
CaptainR 22:cea582ea74c1 126 #define FILE_REWIND 0x
CaptainR 22:cea582ea74c1 127 #define FILE_LOAD_F 0x
CaptainR 22:cea582ea74c1 128 #define FILE_CALL_F 0x
CaptainR 22:cea582ea74c1 129 #define FILE_RUN 0x
CaptainR 22:cea582ea74c1 130 #define FILE_EXECUTE 0x
CaptainR 22:cea582ea74c1 131 #define FILE_IMAGE_CTRL 0x
CaptainR 22:cea582ea74c1 132 #define FILE_UNMOUNT 0x
CaptainR 22:cea582ea74c1 133 #define FILE_WAV 0x
CaptainR 0:a5ef6bc3c2e8 134
CaptainR 0:a5ef6bc3c2e8 135
CaptainR 0:a5ef6bc3c2e8 136
CaptainR 0:a5ef6bc3c2e8 137 //**************************************************************************
CaptainR 3:dcfbceb81fef 138 class PICASO_4DGL {
CaptainR 0:a5ef6bc3c2e8 139
CaptainR 0:a5ef6bc3c2e8 140 public :
CaptainR 0:a5ef6bc3c2e8 141
CaptainR 0:a5ef6bc3c2e8 142 Serial pc; // serial variable for debug information
CaptainR 3:dcfbceb81fef 143 PICASO_4DGL(PinName tx, PinName rx, PinName rst); // LCD serial construnctor
CaptainR 5:890ddd974624 144 int index; // received response from screen
CaptainR 6:a1a85f2bc04b 145 short Xdest, Ydest;
CaptainR 13:1a0800957412 146 char buffer[BUFFER_SIZE];
CaptainR 13:1a0800957412 147 char rxBuf[RXBUFLEN];
CaptainR 14:561cb06a2739 148 char sendBlock[BUFFER_SIZE];
CaptainR 12:29f5ad896382 149 char currentFont; // stores current used font
CaptainR 12:29f5ad896382 150 char currentMode; // stores current orientation
CaptainR 0:a5ef6bc3c2e8 151
CaptainR 0:a5ef6bc3c2e8 152 // General Commands
CaptainR 5:890ddd974624 153 void rxCallback();
CaptainR 0:a5ef6bc3c2e8 154 void reset(); // reset screen
CaptainR 0:a5ef6bc3c2e8 155 void baudrate(long); // set baudrate
CaptainR 12:29f5ad896382 156 void mainDemo(); // play demo with main functions
CaptainR 0:a5ef6bc3c2e8 157 void textDemo(); // play demo with text based functions
CaptainR 12:29f5ad896382 158 void graphicsDemo(); // play demo with graphics based functions
CaptainR 12:29f5ad896382 159 void mediaDemo(); // play demo with media based functions
CaptainR 20:88e137b9ea46 160 void fileSystemDemo(); // play FAT16 demo
CaptainR 0:a5ef6bc3c2e8 161
CaptainR 0:a5ef6bc3c2e8 162 // Graphics Commands
CaptainR 0:a5ef6bc3c2e8 163 void cls(); // clear screen
CaptainR 2:81eaaa491a02 164 void changeColor(short, short); // change one color to another
CaptainR 2:81eaaa491a02 165 void drawCircle(short, short, short, short); // draw a circle (x, y, radius, color)
CaptainR 3:dcfbceb81fef 166 void drawFilledCircle(short, short, short, short); // draw a filled circle (x, y, radius, color)
CaptainR 3:dcfbceb81fef 167 void drawLine(short, short, short, short, short); // draw a line (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 168 void drawRectangle(short, short, short, short, short); // draw a rectangle (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 169 void drawFilledRectangle(short, short, short, short, short); // draw a solid rectangle (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 170 void drawPolyline(short, short *, short *, short); // draw multiple lines (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 171 void drawPolygon(short, short *, short *, short); // draw a polygon (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 172 void drawFilledPolygon(short, short *, short *, short); // draw a solid polygon (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 173 void drawTriangle(short, short, short, short, short, short, short); // draw a triangle (x1, y1, x2, y2, x3, y3, color)
CaptainR 3:dcfbceb81fef 174 void drawFilledTriangle(short, short, short, short, short, short, short); // draw a solid triangle (x1, y1, x2, y2, x3, y3, color)
CaptainR 10:b959bb206e6b 175 void drawElipse(short, short, short, short, short); // draw elipse (x1, y1, xrad, yrad, color)
CaptainR 10:b959bb206e6b 176 void drawFilledElipse(short, short, short, short, short); // draw a solid elipse (x1, y1, xrad, yrad, color)
CaptainR 4:50511ed54ab4 177 void calculateOrbit(short, short); // calculate distant point coordinates (angle, distance)
CaptainR 6:a1a85f2bc04b 178 void putPixel(short, short, short); // draw a pixel (x, y, color)
CaptainR 6:a1a85f2bc04b 179 void moveOrigin(short, short); // change origin point (x, y)
CaptainR 8:b634ac9c92f8 180 void lineTo(short, short); // draw a line from current origin to set point (x, y)
CaptainR 9:32eb75c01e9d 181 void setClipWindow(short, short, short, short); // set a clipping window
CaptainR 9:32eb75c01e9d 182 void clipping(short); // enable / disable clipping
CaptainR 9:32eb75c01e9d 183 void extendClipRegion(); // extend clipping region to the last text or image shown
CaptainR 10:b959bb206e6b 184 void drawButton(short, short, short, short, short, short, short, short, char *); // draw a 3D button (state, x, y, btnColor, txtColor, font, txtWidth, txtHeight, string)
CaptainR 11:3ebd2263f3e9 185 bool bevelShadow(short); // change the drawButton bevel shadow depth
CaptainR 11:3ebd2263f3e9 186 bool bevelWidth(short); // change the drawButton bevel width
CaptainR 10:b959bb206e6b 187 void drawPanel(short, short, short, short, short, short); // draw a 3D panel (state, x, y, width, height, color)
CaptainR 10:b959bb206e6b 188 void drawSlider(short, short, short, short, short, short, short, short); // draw a slider bar (mode, x1, y1, x2, y2, color, scale, value)
CaptainR 10:b959bb206e6b 189 void screenCopyPaste(short, short, short, short, short, short); // copy a portion of screen (xs, ys, xd, yd, width, height)
CaptainR 11:3ebd2263f3e9 190 void bgColor(short); // change background color
CaptainR 11:3ebd2263f3e9 191 void outlineColor(short); // change outline color
CaptainR 11:3ebd2263f3e9 192 void contrast(short); // change display contrast
CaptainR 11:3ebd2263f3e9 193 bool frameDelay(short); // set inter frame delay for media video command
CaptainR 11:3ebd2263f3e9 194 void linePatern(short); // set the line draw pattern for line drawing
CaptainR 11:3ebd2263f3e9 195 void screenMode(char); // set desired orientation of a screen
CaptainR 11:3ebd2263f3e9 196 void transparency(short); // turn on or off transparency
CaptainR 11:3ebd2263f3e9 197 void transparentColor(short); // change transparent to color
CaptainR 11:3ebd2263f3e9 198 void setGraphics(short, short); // set graphics parameters
CaptainR 11:3ebd2263f3e9 199 short getGraphics(short); // get graphics parameters
CaptainR 2:81eaaa491a02 200
CaptainR 12:29f5ad896382 201 // Media Commands
CaptainR 12:29f5ad896382 202 short media_Init(); // initialise memory card
CaptainR 12:29f5ad896382 203 bool media_SetAdd(int); // set byte address
CaptainR 12:29f5ad896382 204 bool media_SetSector(int); // set sector address
CaptainR 13:1a0800957412 205 bool media_RdSector(); // read sector
CaptainR 13:1a0800957412 206 bool media_WrSector(char *); // write sector
CaptainR 14:561cb06a2739 207 bool media_WrData(char *, int); // write sector
CaptainR 16:cb072eea16e9 208 bool media_ReadByte(); // read byte
CaptainR 19:a259bc128867 209 bool media_ReadWord(); // read word
CaptainR 19:a259bc128867 210 bool media_WriteByte(short); // write byte
CaptainR 20:88e137b9ea46 211 bool media_WriteWord(short); // write word
CaptainR 20:88e137b9ea46 212 bool media_Flush(); // flush written bytes or words
CaptainR 12:29f5ad896382 213
CaptainR 0:a5ef6bc3c2e8 214 // Texts Commands
CaptainR 0:a5ef6bc3c2e8 215 void setFont(char); // set desired font from embedded fonts
CaptainR 0:a5ef6bc3c2e8 216 char moveCursor(short, short); // move cursot to a specific location
CaptainR 0:a5ef6bc3c2e8 217 char validateMoveCursor(short, short); // check if requested values are not out of range, based on font and orientation
CaptainR 2:81eaaa491a02 218 void textBgColor(short); // set background color of next text messages
CaptainR 0:a5ef6bc3c2e8 219 void putc(char); // send a single character to LCD
CaptainR 0:a5ef6bc3c2e8 220 void puts(char *); // send a string to LCD
CaptainR 2:81eaaa491a02 221 void textFgColor(short); // set text color
CaptainR 2:81eaaa491a02 222 int textWidth(short); // set width of a text
CaptainR 2:81eaaa491a02 223 int textHeight(short); // set text height
CaptainR 2:81eaaa491a02 224 int textXGap(short); // set gap between characters in pixels (X axis)
CaptainR 2:81eaaa491a02 225 int textYGap(short); // set gap between characters in pixels (Y axis)
CaptainR 2:81eaaa491a02 226 void textBold(short); // set text to bold
CaptainR 2:81eaaa491a02 227 void textInverse(short); // invert text BG and FG colors
CaptainR 2:81eaaa491a02 228 void textItalic(short); // set text to italic
CaptainR 2:81eaaa491a02 229 void textOpacity(short); // set text opacity
CaptainR 2:81eaaa491a02 230 void textUnderline(short); // set text to underline
CaptainR 2:81eaaa491a02 231 void textAttributes(short); // set 4 attributes (bold, italic, inverse, underline)
CaptainR 0:a5ef6bc3c2e8 232
CaptainR 18:829f3e2c064c 233 // Response commands
CaptainR 18:829f3e2c064c 234 bool getResponse(int); // wait for LCD response
CaptainR 18:829f3e2c064c 235 bool calculateOrbitResponse(); // wait for LCD response
CaptainR 18:829f3e2c064c 236 short getGraphicsResponse(); // wait for LCD response
CaptainR 18:829f3e2c064c 237 short mediaInitResponse(); // response from mediaInit command
CaptainR 18:829f3e2c064c 238 bool readSectorResponse(int); // response from read sector command
CaptainR 18:829f3e2c064c 239 bool writeSectorResponse(int); // response from write sector command
CaptainR 18:829f3e2c064c 240 bool readResponse(); // response from read byte or read word commands
CaptainR 19:a259bc128867 241 bool writeByteResponse(); // response from write sector command
CaptainR 21:ea68a8a3cea4 242 bool fileMountResponse(); // response from file mount
CaptainR 21:ea68a8a3cea4 243 short fileErrorResponse(); // returns error code
CaptainR 22:cea582ea74c1 244 short fileCountResponse(); // returns searched file count
CaptainR 23:dd2c28fa4dfd 245 short getFilenameResponse(char*); // returns searched filename and length
CaptainR 0:a5ef6bc3c2e8 246
CaptainR 20:88e137b9ea46 247 // File system commands
CaptainR 20:88e137b9ea46 248 bool file_Mount(); // mount file system
CaptainR 21:ea68a8a3cea4 249 short file_Error(); // get latest error code
CaptainR 22:cea582ea74c1 250 short file_Count(char*); // get file count by given name
CaptainR 22:cea582ea74c1 251 short file_Dir(char*); // list the stream of filenames by given name and return count
CaptainR 22:cea582ea74c1 252 void file_FindFirst(char*); // list the stream of filenames by given name
CaptainR 23:dd2c28fa4dfd 253 short file_FindFirstRet(char*, char*); // list the stream of filenames by given name
CaptainR 20:88e137b9ea46 254
CaptainR 0:a5ef6bc3c2e8 255 protected :
CaptainR 0:a5ef6bc3c2e8 256
CaptainR 2:81eaaa491a02 257 Serial _cmd; // serial variable, to comunicate with screen
CaptainR 2:81eaaa491a02 258 DigitalOut _rst; // screen reset pin
CaptainR 4:50511ed54ab4 259
CaptainR 4:50511ed54ab4 260
CaptainR 0:a5ef6bc3c2e8 261 void freeBUFFER (void);
CaptainR 0:a5ef6bc3c2e8 262 void writeBYTE (char);
CaptainR 2:81eaaa491a02 263 void writeCOMMAND(char *, int); // send command to screen
CaptainR 15:86bdf382e6f7 264 void writeCOMMAND_2(char *, int); // send command to screen
CaptainR 0:a5ef6bc3c2e8 265 };