Rihards Balass / 4DGL-mbed-32PTU
Committer:
CaptainR
Date:
Tue Sep 13 05:53:39 2016 +0000
Revision:
10:b959bb206e6b
Parent:
9:32eb75c01e9d
Child:
11:3ebd2263f3e9
drawElipse, drawFilledElipse, drawTextButton, drawPanel, DrawSlider, ScreenCopyPaste, BevelShadow

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 0:a5ef6bc3c2e8 20
CaptainR 0:a5ef6bc3c2e8 21 #ifndef DEBUGMODE
CaptainR 0:a5ef6bc3c2e8 22 #define DEBUGMODE 1
CaptainR 0:a5ef6bc3c2e8 23 #endif
CaptainR 0:a5ef6bc3c2e8 24
CaptainR 0:a5ef6bc3c2e8 25 // functions
CaptainR 2:81eaaa491a02 26 #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) // to check if required bit is set
CaptainR 0:a5ef6bc3c2e8 27
CaptainR 0:a5ef6bc3c2e8 28 // Common WAIT value in millisecond
CaptainR 0:a5ef6bc3c2e8 29 #define TEMPO 1
CaptainR 0:a5ef6bc3c2e8 30
CaptainR 0:a5ef6bc3c2e8 31 // Main Functions values
CaptainR 3:dcfbceb81fef 32 #define CLS 0xFFCD
CaptainR 3:dcfbceb81fef 33 #define BAUDRATE 0x0026
CaptainR 3:dcfbceb81fef 34 #define ORIENTATION 0xFF9E
CaptainR 0:a5ef6bc3c2e8 35
CaptainR 0:a5ef6bc3c2e8 36 // text functions values
CaptainR 5:890ddd974624 37 #define TEXT_BG_COLOR 0xFFE6
CaptainR 3:dcfbceb81fef 38 #define SET_FONT 0xFFE5
CaptainR 3:dcfbceb81fef 39 #define PUT_CHAR 0xFFFE
CaptainR 3:dcfbceb81fef 40 #define PUT_STRING 0x0018
CaptainR 3:dcfbceb81fef 41 #define MOVE_CURSOR 0xFFE9
CaptainR 3:dcfbceb81fef 42 #define TEXT_FG_COLOR 0xFFE7
CaptainR 3:dcfbceb81fef 43 #define TEXT_WIDTH 0xFFE4
CaptainR 3:dcfbceb81fef 44 #define TEXT_HEIGHT 0xFFE3
CaptainR 3:dcfbceb81fef 45 #define TEXT_X_GAP 0xFFE2
CaptainR 3:dcfbceb81fef 46 #define TEXT_Y_GAP 0xFFE1
CaptainR 3:dcfbceb81fef 47 #define TEXT_BOLD 0xFFDE
CaptainR 3:dcfbceb81fef 48 #define TEXT_INVERSE 0xFFDC
CaptainR 3:dcfbceb81fef 49 #define TEXT_ITALIC 0xFFDD
CaptainR 3:dcfbceb81fef 50 #define TEXT_OPACITY 0xFFDF
CaptainR 3:dcfbceb81fef 51 #define TEXT_UNDERLINE 0xFFDB
CaptainR 3:dcfbceb81fef 52 #define TEXT_ATTRIBUTES 0xFFDA
CaptainR 0:a5ef6bc3c2e8 53
CaptainR 0:a5ef6bc3c2e8 54 // graphics functions values
CaptainR 5:890ddd974624 55 #define CHANGE_COLOR 0xFFB4
CaptainR 3:dcfbceb81fef 56 #define DRAW_CIRCLE 0xFFC3
CaptainR 3:dcfbceb81fef 57 #define CIRCLE_FILLED 0xFFC2
CaptainR 3:dcfbceb81fef 58 #define DRAW_LINE 0xFFC8
CaptainR 3:dcfbceb81fef 59 #define DRAW_RECTANGLE 0xFFC5
CaptainR 3:dcfbceb81fef 60 #define RECTANGLE_FILLED 0xFFC4
CaptainR 3:dcfbceb81fef 61 #define DRAW_POLYLINE 0x0015
CaptainR 3:dcfbceb81fef 62 #define DRAW_POLYGON 0x0013
CaptainR 3:dcfbceb81fef 63 #define POLYGON_FILLED 0x0014
CaptainR 3:dcfbceb81fef 64 #define DRAW_TRIANGLE 0xFFBF
CaptainR 3:dcfbceb81fef 65 #define TRIANGLE_FILLED 0xFFA9
CaptainR 4:50511ed54ab4 66 #define CALCULATE_ORBIT 0x0012
CaptainR 6:a1a85f2bc04b 67 #define PUT_PIXEL 0xFFC1
CaptainR 6:a1a85f2bc04b 68 #define MOVE_ORIGIN 0xFFCC
CaptainR 8:b634ac9c92f8 69 #define LINE_TO 0xFFCA
CaptainR 9:32eb75c01e9d 70 #define SET_CLIP_WINDOW 0xFFB5
CaptainR 9:32eb75c01e9d 71 #define CLIPPING 0xFFA2
CaptainR 9:32eb75c01e9d 72 #define EXTEND_CLIP 0xFFB3
CaptainR 10:b959bb206e6b 73 #define DRAW_ELIPSE 0xFFB2
CaptainR 10:b959bb206e6b 74 #define ELIPSE_FILLED 0xFFB1
CaptainR 10:b959bb206e6b 75 #define DRAW_BUTTON 0x0011
CaptainR 10:b959bb206e6b 76 #define BEVEL_SHADOW 0xFF98
CaptainR 10:b959bb206e6b 77 #define DRAW_PANEL 0xFFAF
CaptainR 10:b959bb206e6b 78 #define DRAW_SLIDER 0xFFAE
CaptainR 10:b959bb206e6b 79 #define SCREEN_CP 0xFFAD
CaptainR 8:b634ac9c92f8 80
CaptainR 3:dcfbceb81fef 81
CaptainR 0:a5ef6bc3c2e8 82
CaptainR 0:a5ef6bc3c2e8 83
CaptainR 0:a5ef6bc3c2e8 84 // Screen answers
CaptainR 0:a5ef6bc3c2e8 85 #define ACK 0x06
CaptainR 8:b634ac9c92f8 86 #define NACK 0x15
CaptainR 0:a5ef6bc3c2e8 87
CaptainR 0:a5ef6bc3c2e8 88 // Predefined Fonts
CaptainR 2:81eaaa491a02 89 #define FONT1 0x0000
CaptainR 2:81eaaa491a02 90 #define FONT2 0x0001
CaptainR 2:81eaaa491a02 91 #define FONT3 0x0002
CaptainR 0:a5ef6bc3c2e8 92
CaptainR 0:a5ef6bc3c2e8 93 // Line and column values depending on orientation and font F1LL = font1 landscape line
CaptainR 0:a5ef6bc3c2e8 94 #define F1LL 29
CaptainR 0:a5ef6bc3c2e8 95 #define F1LC 44
CaptainR 0:a5ef6bc3c2e8 96 #define F1PL 39
CaptainR 0:a5ef6bc3c2e8 97 #define F1PC 33
CaptainR 0:a5ef6bc3c2e8 98
CaptainR 0:a5ef6bc3c2e8 99 #define F2LL 29
CaptainR 0:a5ef6bc3c2e8 100 #define F2LC 39
CaptainR 0:a5ef6bc3c2e8 101 #define F2PL 39
CaptainR 0:a5ef6bc3c2e8 102 #define F2PC 29
CaptainR 0:a5ef6bc3c2e8 103
CaptainR 0:a5ef6bc3c2e8 104 #define F3LL 19
CaptainR 0:a5ef6bc3c2e8 105 #define F3LC 39
CaptainR 0:a5ef6bc3c2e8 106 #define F3PL 26
CaptainR 0:a5ef6bc3c2e8 107 #define F3PC 29
CaptainR 0:a5ef6bc3c2e8 108
CaptainR 0:a5ef6bc3c2e8 109 // Data speed
CaptainR 2:81eaaa491a02 110 #define BAUD_300 0x0001
CaptainR 2:81eaaa491a02 111 #define BAUD_600 0x0002
CaptainR 2:81eaaa491a02 112 #define BAUD_1200 0x0003
CaptainR 2:81eaaa491a02 113 #define BAUD_2400 0x0004
CaptainR 2:81eaaa491a02 114 #define BAUD_4800 0x0005
CaptainR 2:81eaaa491a02 115 #define BAUD_9600 0x0006
CaptainR 2:81eaaa491a02 116 #define BAUD_14400 0x0007
CaptainR 2:81eaaa491a02 117 #define BAUD_19200 0x0008
CaptainR 2:81eaaa491a02 118 #define BAUD_31250 0x0009
CaptainR 2:81eaaa491a02 119 #define BAUD_38400 0x000A
CaptainR 2:81eaaa491a02 120 #define BAUD_56000 0x000B
CaptainR 2:81eaaa491a02 121 #define BAUD_57600 0x000C
CaptainR 2:81eaaa491a02 122 #define BAUD_115200 0x000D
CaptainR 2:81eaaa491a02 123 #define BAUD_128000 0x000E
CaptainR 2:81eaaa491a02 124 #define BAUD_256000 0x000F
CaptainR 2:81eaaa491a02 125 #define BAUD_300000 0x0010
CaptainR 2:81eaaa491a02 126 #define BAUD_375000 0x0011
CaptainR 2:81eaaa491a02 127 #define BAUD_500000 0x0012
CaptainR 2:81eaaa491a02 128 #define BAUD_600000 0x0013
CaptainR 0:a5ef6bc3c2e8 129
CaptainR 3:dcfbceb81fef 130 // Defined colors
CaptainR 2:81eaaa491a02 131 #define Black 0x0000
CaptainR 2:81eaaa491a02 132 #define Navy 0x000F
CaptainR 2:81eaaa491a02 133 #define DGreen 0x03E0
CaptainR 2:81eaaa491a02 134 #define DCyan 0x03EF
CaptainR 2:81eaaa491a02 135 #define Purple 0x780F
CaptainR 2:81eaaa491a02 136 #define Olive 0x7BE0
CaptainR 2:81eaaa491a02 137 #define Grey 0x8410
CaptainR 2:81eaaa491a02 138 #define Blue 0x001F
CaptainR 2:81eaaa491a02 139 #define Green 0x07E0
CaptainR 2:81eaaa491a02 140 #define Red 0xF800
CaptainR 2:81eaaa491a02 141 #define Yellow 0xFFE0
CaptainR 2:81eaaa491a02 142 #define White 0xFFFF
CaptainR 2:81eaaa491a02 143 #define Orange 0xFD20
CaptainR 2:81eaaa491a02 144 #define GYellow 0xAFE5
CaptainR 2:81eaaa491a02 145 #define Pink 0xF81F
CaptainR 2:81eaaa491a02 146 #define Violet 0x901A
CaptainR 2:81eaaa491a02 147 #define Aqua 0x07FF
CaptainR 2:81eaaa491a02 148 #define Cream 0xFFDE
CaptainR 0:a5ef6bc3c2e8 149
CaptainR 0:a5ef6bc3c2e8 150 // Screen orientation
CaptainR 2:81eaaa491a02 151 #define LANDSCAPE 0x0000
CaptainR 2:81eaaa491a02 152 #define LANDSCAPE_R 0x0001
CaptainR 2:81eaaa491a02 153 #define PORTRAIT 0x0002
CaptainR 2:81eaaa491a02 154 #define PORTRAIT_R 0x0003
CaptainR 0:a5ef6bc3c2e8 155
CaptainR 0:a5ef6bc3c2e8 156 // Parameters
CaptainR 2:81eaaa491a02 157 #define ENABLE 1
CaptainR 2:81eaaa491a02 158 #define DISABLE 0
CaptainR 10:b959bb206e6b 159 // orientation
CaptainR 2:81eaaa491a02 160 #define landscape 1
CaptainR 2:81eaaa491a02 161 #define landscapeRew 2
CaptainR 2:81eaaa491a02 162 #define portrait 3
CaptainR 2:81eaaa491a02 163 #define portraitRew 4
CaptainR 10:b959bb206e6b 164 // text attributes
CaptainR 2:81eaaa491a02 165 #define bold 16
CaptainR 2:81eaaa491a02 166 #define italic 32
CaptainR 2:81eaaa491a02 167 #define inverse 64
CaptainR 2:81eaaa491a02 168 #define underline 128
CaptainR 10:b959bb206e6b 169 // Fonts
CaptainR 2:81eaaa491a02 170 #define font1 1
CaptainR 2:81eaaa491a02 171 #define font2 2
CaptainR 2:81eaaa491a02 172 #define font3 3
CaptainR 10:b959bb206e6b 173 // Receive buffer length
CaptainR 5:890ddd974624 174 #define RXBUFLEN 32
CaptainR 10:b959bb206e6b 175 // 3D states
CaptainR 10:b959bb206e6b 176 #define DEPRESSED 0
CaptainR 10:b959bb206e6b 177 #define INDENTED 0
CaptainR 10:b959bb206e6b 178 #define RAISED 1
CaptainR 10:b959bb206e6b 179 #define HIDDEN 2
CaptainR 0:a5ef6bc3c2e8 180
CaptainR 0:a5ef6bc3c2e8 181 //**************************************************************************
CaptainR 3:dcfbceb81fef 182 class PICASO_4DGL {
CaptainR 0:a5ef6bc3c2e8 183
CaptainR 0:a5ef6bc3c2e8 184 public :
CaptainR 0:a5ef6bc3c2e8 185
CaptainR 0:a5ef6bc3c2e8 186 Serial pc; // serial variable for debug information
CaptainR 3:dcfbceb81fef 187 PICASO_4DGL(PinName tx, PinName rx, PinName rst); // LCD serial construnctor
CaptainR 5:890ddd974624 188 int index; // received response from screen
CaptainR 6:a1a85f2bc04b 189 short Xdest, Ydest;
CaptainR 0:a5ef6bc3c2e8 190 char response[];
CaptainR 5:890ddd974624 191 char rxBuf[];
CaptainR 0:a5ef6bc3c2e8 192
CaptainR 0:a5ef6bc3c2e8 193 // General Commands
CaptainR 5:890ddd974624 194 void rxCallback();
CaptainR 5:890ddd974624 195 void getResponse(int); // wait for LCD response
CaptainR 6:a1a85f2bc04b 196 void calculateOrbitResponse(); // wait for LCD response
CaptainR 0:a5ef6bc3c2e8 197 void reset(); // reset screen
CaptainR 0:a5ef6bc3c2e8 198 void baudrate(long); // set baudrate
CaptainR 0:a5ef6bc3c2e8 199 void screenOrientation(char); // set desired orientation of a screen
CaptainR 0:a5ef6bc3c2e8 200 void mainDemo(); // play demo with text based functions
CaptainR 0:a5ef6bc3c2e8 201 void textDemo(); // play demo with text based functions
CaptainR 0:a5ef6bc3c2e8 202 void graphicsDemo(); // play demo with text based functions
CaptainR 0:a5ef6bc3c2e8 203
CaptainR 0:a5ef6bc3c2e8 204 // Graphics Commands
CaptainR 0:a5ef6bc3c2e8 205 void cls(); // clear screen
CaptainR 2:81eaaa491a02 206 void changeColor(short, short); // change one color to another
CaptainR 2:81eaaa491a02 207 void drawCircle(short, short, short, short); // draw a circle (x, y, radius, color)
CaptainR 3:dcfbceb81fef 208 void drawFilledCircle(short, short, short, short); // draw a filled circle (x, y, radius, color)
CaptainR 3:dcfbceb81fef 209 void drawLine(short, short, short, short, short); // draw a line (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 210 void drawRectangle(short, short, short, short, short); // draw a rectangle (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 211 void drawFilledRectangle(short, short, short, short, short); // draw a solid rectangle (x1, y1, x2, y2, color)
CaptainR 3:dcfbceb81fef 212 void drawPolyline(short, short *, short *, short); // draw multiple lines (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 213 void drawPolygon(short, short *, short *, short); // draw a polygon (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 214 void drawFilledPolygon(short, short *, short *, short); // draw a solid polygon (n, vx1…vxN, vy1…vyN, color)
CaptainR 3:dcfbceb81fef 215 void drawTriangle(short, short, short, short, short, short, short); // draw a triangle (x1, y1, x2, y2, x3, y3, color)
CaptainR 3:dcfbceb81fef 216 void drawFilledTriangle(short, short, short, short, short, short, short); // draw a solid triangle (x1, y1, x2, y2, x3, y3, color)
CaptainR 10:b959bb206e6b 217 void drawElipse(short, short, short, short, short); // draw elipse (x1, y1, xrad, yrad, color)
CaptainR 10:b959bb206e6b 218 void drawFilledElipse(short, short, short, short, short); // draw a solid elipse (x1, y1, xrad, yrad, color)
CaptainR 4:50511ed54ab4 219 void calculateOrbit(short, short); // calculate distant point coordinates (angle, distance)
CaptainR 6:a1a85f2bc04b 220 void putPixel(short, short, short); // draw a pixel (x, y, color)
CaptainR 6:a1a85f2bc04b 221 void moveOrigin(short, short); // change origin point (x, y)
CaptainR 8:b634ac9c92f8 222 void lineTo(short, short); // draw a line from current origin to set point (x, y)
CaptainR 9:32eb75c01e9d 223 void setClipWindow(short, short, short, short); // set a clipping window
CaptainR 9:32eb75c01e9d 224 void clipping(short); // enable / disable clipping
CaptainR 9:32eb75c01e9d 225 void extendClipRegion(); // extend clipping region to the last text or image shown
CaptainR 10:b959bb206e6b 226 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 10:b959bb206e6b 227 void bevelShadow(short); // change the drawButton bevel shadow depth
CaptainR 10:b959bb206e6b 228 void drawPanel(short, short, short, short, short, short); // draw a 3D panel (state, x, y, width, height, color)
CaptainR 10:b959bb206e6b 229 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 230 void screenCopyPaste(short, short, short, short, short, short); // copy a portion of screen (xs, ys, xd, yd, width, height)
CaptainR 2:81eaaa491a02 231
CaptainR 0:a5ef6bc3c2e8 232 // Texts Commands
CaptainR 0:a5ef6bc3c2e8 233 void setFont(char); // set desired font from embedded fonts
CaptainR 0:a5ef6bc3c2e8 234 char moveCursor(short, short); // move cursot to a specific location
CaptainR 0:a5ef6bc3c2e8 235 char validateMoveCursor(short, short); // check if requested values are not out of range, based on font and orientation
CaptainR 2:81eaaa491a02 236 void textBgColor(short); // set background color of next text messages
CaptainR 0:a5ef6bc3c2e8 237 void putc(char); // send a single character to LCD
CaptainR 0:a5ef6bc3c2e8 238 void puts(char *); // send a string to LCD
CaptainR 2:81eaaa491a02 239 void textFgColor(short); // set text color
CaptainR 2:81eaaa491a02 240 int textWidth(short); // set width of a text
CaptainR 2:81eaaa491a02 241 int textHeight(short); // set text height
CaptainR 2:81eaaa491a02 242 int textXGap(short); // set gap between characters in pixels (X axis)
CaptainR 2:81eaaa491a02 243 int textYGap(short); // set gap between characters in pixels (Y axis)
CaptainR 2:81eaaa491a02 244 void textBold(short); // set text to bold
CaptainR 2:81eaaa491a02 245 void textInverse(short); // invert text BG and FG colors
CaptainR 2:81eaaa491a02 246 void textItalic(short); // set text to italic
CaptainR 2:81eaaa491a02 247 void textOpacity(short); // set text opacity
CaptainR 2:81eaaa491a02 248 void textUnderline(short); // set text to underline
CaptainR 2:81eaaa491a02 249 void textAttributes(short); // set 4 attributes (bold, italic, inverse, underline)
CaptainR 0:a5ef6bc3c2e8 250
CaptainR 0:a5ef6bc3c2e8 251 // Text data
CaptainR 2:81eaaa491a02 252 char currentFont; // stores current used font
CaptainR 2:81eaaa491a02 253 char currentOrientation; // stores current orientation
CaptainR 0:a5ef6bc3c2e8 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 0:a5ef6bc3c2e8 264 };