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.
Picaso_4DGL-32PTU.h@4:50511ed54ab4, 2016-09-09 (annotated)
- Committer:
- CaptainR
- Date:
- Fri Sep 09 12:45:28 2016 +0000
- Revision:
- 4:50511ed54ab4
- Parent:
- 3:dcfbceb81fef
- Child:
- 5:890ddd974624
added graphic functions and started on data receive function...;
Who changed what in which revision?
| User | Revision | Line number | New 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 | 3:dcfbceb81fef | 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 | 3:dcfbceb81fef | 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 | 3:dcfbceb81fef | 67 | |
| CaptainR | 0:a5ef6bc3c2e8 | 68 | |
| CaptainR | 0:a5ef6bc3c2e8 | 69 | |
| CaptainR | 0:a5ef6bc3c2e8 | 70 | // Screen answers |
| CaptainR | 0:a5ef6bc3c2e8 | 71 | #define ACK 0x06 |
| CaptainR | 0:a5ef6bc3c2e8 | 72 | #define NACK 0x15 |
| CaptainR | 0:a5ef6bc3c2e8 | 73 | |
| CaptainR | 0:a5ef6bc3c2e8 | 74 | // Predefined Fonts |
| CaptainR | 2:81eaaa491a02 | 75 | #define FONT1 0x0000 |
| CaptainR | 2:81eaaa491a02 | 76 | #define FONT2 0x0001 |
| CaptainR | 2:81eaaa491a02 | 77 | #define FONT3 0x0002 |
| CaptainR | 0:a5ef6bc3c2e8 | 78 | |
| CaptainR | 0:a5ef6bc3c2e8 | 79 | // Line and column values depending on orientation and font F1LL = font1 landscape line |
| CaptainR | 0:a5ef6bc3c2e8 | 80 | #define F1LL 29 |
| CaptainR | 0:a5ef6bc3c2e8 | 81 | #define F1LC 44 |
| CaptainR | 0:a5ef6bc3c2e8 | 82 | #define F1PL 39 |
| CaptainR | 0:a5ef6bc3c2e8 | 83 | #define F1PC 33 |
| CaptainR | 0:a5ef6bc3c2e8 | 84 | |
| CaptainR | 0:a5ef6bc3c2e8 | 85 | #define F2LL 29 |
| CaptainR | 0:a5ef6bc3c2e8 | 86 | #define F2LC 39 |
| CaptainR | 0:a5ef6bc3c2e8 | 87 | #define F2PL 39 |
| CaptainR | 0:a5ef6bc3c2e8 | 88 | #define F2PC 29 |
| CaptainR | 0:a5ef6bc3c2e8 | 89 | |
| CaptainR | 0:a5ef6bc3c2e8 | 90 | #define F3LL 19 |
| CaptainR | 0:a5ef6bc3c2e8 | 91 | #define F3LC 39 |
| CaptainR | 0:a5ef6bc3c2e8 | 92 | #define F3PL 26 |
| CaptainR | 0:a5ef6bc3c2e8 | 93 | #define F3PC 29 |
| CaptainR | 0:a5ef6bc3c2e8 | 94 | |
| CaptainR | 0:a5ef6bc3c2e8 | 95 | // Data speed |
| CaptainR | 2:81eaaa491a02 | 96 | #define BAUD_300 0x0001 |
| CaptainR | 2:81eaaa491a02 | 97 | #define BAUD_600 0x0002 |
| CaptainR | 2:81eaaa491a02 | 98 | #define BAUD_1200 0x0003 |
| CaptainR | 2:81eaaa491a02 | 99 | #define BAUD_2400 0x0004 |
| CaptainR | 2:81eaaa491a02 | 100 | #define BAUD_4800 0x0005 |
| CaptainR | 2:81eaaa491a02 | 101 | #define BAUD_9600 0x0006 |
| CaptainR | 2:81eaaa491a02 | 102 | #define BAUD_14400 0x0007 |
| CaptainR | 2:81eaaa491a02 | 103 | #define BAUD_19200 0x0008 |
| CaptainR | 2:81eaaa491a02 | 104 | #define BAUD_31250 0x0009 |
| CaptainR | 2:81eaaa491a02 | 105 | #define BAUD_38400 0x000A |
| CaptainR | 2:81eaaa491a02 | 106 | #define BAUD_56000 0x000B |
| CaptainR | 2:81eaaa491a02 | 107 | #define BAUD_57600 0x000C |
| CaptainR | 2:81eaaa491a02 | 108 | #define BAUD_115200 0x000D |
| CaptainR | 2:81eaaa491a02 | 109 | #define BAUD_128000 0x000E |
| CaptainR | 2:81eaaa491a02 | 110 | #define BAUD_256000 0x000F |
| CaptainR | 2:81eaaa491a02 | 111 | #define BAUD_300000 0x0010 |
| CaptainR | 2:81eaaa491a02 | 112 | #define BAUD_375000 0x0011 |
| CaptainR | 2:81eaaa491a02 | 113 | #define BAUD_500000 0x0012 |
| CaptainR | 2:81eaaa491a02 | 114 | #define BAUD_600000 0x0013 |
| CaptainR | 0:a5ef6bc3c2e8 | 115 | |
| CaptainR | 3:dcfbceb81fef | 116 | // Defined colors |
| CaptainR | 2:81eaaa491a02 | 117 | #define Black 0x0000 |
| CaptainR | 2:81eaaa491a02 | 118 | #define Navy 0x000F |
| CaptainR | 2:81eaaa491a02 | 119 | #define DGreen 0x03E0 |
| CaptainR | 2:81eaaa491a02 | 120 | #define DCyan 0x03EF |
| CaptainR | 2:81eaaa491a02 | 121 | #define Purple 0x780F |
| CaptainR | 2:81eaaa491a02 | 122 | #define Olive 0x7BE0 |
| CaptainR | 2:81eaaa491a02 | 123 | #define Grey 0x8410 |
| CaptainR | 2:81eaaa491a02 | 124 | #define Blue 0x001F |
| CaptainR | 2:81eaaa491a02 | 125 | #define Green 0x07E0 |
| CaptainR | 2:81eaaa491a02 | 126 | #define Red 0xF800 |
| CaptainR | 2:81eaaa491a02 | 127 | #define Yellow 0xFFE0 |
| CaptainR | 2:81eaaa491a02 | 128 | #define White 0xFFFF |
| CaptainR | 2:81eaaa491a02 | 129 | #define Orange 0xFD20 |
| CaptainR | 2:81eaaa491a02 | 130 | #define GYellow 0xAFE5 |
| CaptainR | 2:81eaaa491a02 | 131 | #define Pink 0xF81F |
| CaptainR | 2:81eaaa491a02 | 132 | #define Violet 0x901A |
| CaptainR | 2:81eaaa491a02 | 133 | #define Aqua 0x07FF |
| CaptainR | 2:81eaaa491a02 | 134 | #define Cream 0xFFDE |
| CaptainR | 0:a5ef6bc3c2e8 | 135 | |
| CaptainR | 0:a5ef6bc3c2e8 | 136 | // Screen orientation |
| CaptainR | 2:81eaaa491a02 | 137 | #define LANDSCAPE 0x0000 |
| CaptainR | 2:81eaaa491a02 | 138 | #define LANDSCAPE_R 0x0001 |
| CaptainR | 2:81eaaa491a02 | 139 | #define PORTRAIT 0x0002 |
| CaptainR | 2:81eaaa491a02 | 140 | #define PORTRAIT_R 0x0003 |
| CaptainR | 0:a5ef6bc3c2e8 | 141 | |
| CaptainR | 0:a5ef6bc3c2e8 | 142 | // Parameters |
| CaptainR | 2:81eaaa491a02 | 143 | #define ENABLE 1 |
| CaptainR | 2:81eaaa491a02 | 144 | #define DISABLE 0 |
| CaptainR | 2:81eaaa491a02 | 145 | |
| CaptainR | 2:81eaaa491a02 | 146 | #define landscape 1 |
| CaptainR | 2:81eaaa491a02 | 147 | #define landscapeRew 2 |
| CaptainR | 2:81eaaa491a02 | 148 | #define portrait 3 |
| CaptainR | 2:81eaaa491a02 | 149 | #define portraitRew 4 |
| CaptainR | 0:a5ef6bc3c2e8 | 150 | |
| CaptainR | 2:81eaaa491a02 | 151 | #define bold 16 |
| CaptainR | 2:81eaaa491a02 | 152 | #define italic 32 |
| CaptainR | 2:81eaaa491a02 | 153 | #define inverse 64 |
| CaptainR | 2:81eaaa491a02 | 154 | #define underline 128 |
| CaptainR | 0:a5ef6bc3c2e8 | 155 | |
| CaptainR | 2:81eaaa491a02 | 156 | #define font1 1 |
| CaptainR | 2:81eaaa491a02 | 157 | #define font2 2 |
| CaptainR | 2:81eaaa491a02 | 158 | #define font3 3 |
| CaptainR | 0:a5ef6bc3c2e8 | 159 | |
| CaptainR | 4:50511ed54ab4 | 160 | #define bufLen 32 |
| CaptainR | 0:a5ef6bc3c2e8 | 161 | |
| CaptainR | 0:a5ef6bc3c2e8 | 162 | //************************************************************************** |
| CaptainR | 3:dcfbceb81fef | 163 | class PICASO_4DGL { |
| CaptainR | 0:a5ef6bc3c2e8 | 164 | |
| CaptainR | 0:a5ef6bc3c2e8 | 165 | public : |
| CaptainR | 0:a5ef6bc3c2e8 | 166 | |
| CaptainR | 0:a5ef6bc3c2e8 | 167 | Serial pc; // serial variable for debug information |
| CaptainR | 3:dcfbceb81fef | 168 | PICASO_4DGL(PinName tx, PinName rx, PinName rst); // LCD serial construnctor |
| CaptainR | 0:a5ef6bc3c2e8 | 169 | int resp, respLen; // received response from screen |
| CaptainR | 0:a5ef6bc3c2e8 | 170 | char response[]; |
| CaptainR | 4:50511ed54ab4 | 171 | uint8_t rxBuf[]; |
| CaptainR | 0:a5ef6bc3c2e8 | 172 | |
| CaptainR | 0:a5ef6bc3c2e8 | 173 | // General Commands |
| CaptainR | 0:a5ef6bc3c2e8 | 174 | void getResponse(); |
| CaptainR | 4:50511ed54ab4 | 175 | void responseBuild(int); |
| CaptainR | 0:a5ef6bc3c2e8 | 176 | void reset(); // reset screen |
| CaptainR | 0:a5ef6bc3c2e8 | 177 | void baudrate(long); // set baudrate |
| CaptainR | 0:a5ef6bc3c2e8 | 178 | void screenOrientation(char); // set desired orientation of a screen |
| CaptainR | 0:a5ef6bc3c2e8 | 179 | void mainDemo(); // play demo with text based functions |
| CaptainR | 0:a5ef6bc3c2e8 | 180 | void textDemo(); // play demo with text based functions |
| CaptainR | 0:a5ef6bc3c2e8 | 181 | void graphicsDemo(); // play demo with text based functions |
| CaptainR | 0:a5ef6bc3c2e8 | 182 | |
| CaptainR | 0:a5ef6bc3c2e8 | 183 | // Graphics Commands |
| CaptainR | 0:a5ef6bc3c2e8 | 184 | void cls(); // clear screen |
| CaptainR | 2:81eaaa491a02 | 185 | void changeColor(short, short); // change one color to another |
| CaptainR | 2:81eaaa491a02 | 186 | void drawCircle(short, short, short, short); // draw a circle (x, y, radius, color) |
| CaptainR | 3:dcfbceb81fef | 187 | void drawFilledCircle(short, short, short, short); // draw a filled circle (x, y, radius, color) |
| CaptainR | 3:dcfbceb81fef | 188 | void drawLine(short, short, short, short, short); // draw a line (x1, y1, x2, y2, color) |
| CaptainR | 3:dcfbceb81fef | 189 | void drawRectangle(short, short, short, short, short); // draw a rectangle (x1, y1, x2, y2, color) |
| CaptainR | 3:dcfbceb81fef | 190 | void drawFilledRectangle(short, short, short, short, short); // draw a solid rectangle (x1, y1, x2, y2, color) |
| CaptainR | 3:dcfbceb81fef | 191 | void drawPolyline(short, short *, short *, short); // draw multiple lines (n, vx1…vxN, vy1…vyN, color) |
| CaptainR | 3:dcfbceb81fef | 192 | void drawPolygon(short, short *, short *, short); // draw a polygon (n, vx1…vxN, vy1…vyN, color) |
| CaptainR | 3:dcfbceb81fef | 193 | void drawFilledPolygon(short, short *, short *, short); // draw a solid polygon (n, vx1…vxN, vy1…vyN, color) |
| CaptainR | 3:dcfbceb81fef | 194 | void drawTriangle(short, short, short, short, short, short, short); // draw a triangle (x1, y1, x2, y2, x3, y3, color) |
| CaptainR | 3:dcfbceb81fef | 195 | void drawFilledTriangle(short, short, short, short, short, short, short); // draw a solid triangle (x1, y1, x2, y2, x3, y3, color) |
| CaptainR | 4:50511ed54ab4 | 196 | void calculateOrbit(short, short); // calculate distant point coordinates (angle, distance) |
| CaptainR | 2:81eaaa491a02 | 197 | |
| CaptainR | 0:a5ef6bc3c2e8 | 198 | // Texts Commands |
| CaptainR | 0:a5ef6bc3c2e8 | 199 | void setFont(char); // set desired font from embedded fonts |
| CaptainR | 0:a5ef6bc3c2e8 | 200 | char moveCursor(short, short); // move cursot to a specific location |
| CaptainR | 0:a5ef6bc3c2e8 | 201 | char validateMoveCursor(short, short); // check if requested values are not out of range, based on font and orientation |
| CaptainR | 2:81eaaa491a02 | 202 | void textBgColor(short); // set background color of next text messages |
| CaptainR | 0:a5ef6bc3c2e8 | 203 | void putc(char); // send a single character to LCD |
| CaptainR | 0:a5ef6bc3c2e8 | 204 | void puts(char *); // send a string to LCD |
| CaptainR | 2:81eaaa491a02 | 205 | void textFgColor(short); // set text color |
| CaptainR | 2:81eaaa491a02 | 206 | int textWidth(short); // set width of a text |
| CaptainR | 2:81eaaa491a02 | 207 | int textHeight(short); // set text height |
| CaptainR | 2:81eaaa491a02 | 208 | int textXGap(short); // set gap between characters in pixels (X axis) |
| CaptainR | 2:81eaaa491a02 | 209 | int textYGap(short); // set gap between characters in pixels (Y axis) |
| CaptainR | 2:81eaaa491a02 | 210 | void textBold(short); // set text to bold |
| CaptainR | 2:81eaaa491a02 | 211 | void textInverse(short); // invert text BG and FG colors |
| CaptainR | 2:81eaaa491a02 | 212 | void textItalic(short); // set text to italic |
| CaptainR | 2:81eaaa491a02 | 213 | void textOpacity(short); // set text opacity |
| CaptainR | 2:81eaaa491a02 | 214 | void textUnderline(short); // set text to underline |
| CaptainR | 2:81eaaa491a02 | 215 | void textAttributes(short); // set 4 attributes (bold, italic, inverse, underline) |
| CaptainR | 0:a5ef6bc3c2e8 | 216 | |
| CaptainR | 0:a5ef6bc3c2e8 | 217 | // Text data |
| CaptainR | 2:81eaaa491a02 | 218 | char currentFont; // stores current used font |
| CaptainR | 2:81eaaa491a02 | 219 | char currentOrientation; // stores current orientation |
| CaptainR | 0:a5ef6bc3c2e8 | 220 | |
| CaptainR | 0:a5ef6bc3c2e8 | 221 | protected : |
| CaptainR | 0:a5ef6bc3c2e8 | 222 | |
| CaptainR | 2:81eaaa491a02 | 223 | Serial _cmd; // serial variable, to comunicate with screen |
| CaptainR | 2:81eaaa491a02 | 224 | DigitalOut _rst; // screen reset pin |
| CaptainR | 4:50511ed54ab4 | 225 | |
| CaptainR | 4:50511ed54ab4 | 226 | |
| CaptainR | 0:a5ef6bc3c2e8 | 227 | void freeBUFFER (void); |
| CaptainR | 4:50511ed54ab4 | 228 | void clearResponse(); |
| CaptainR | 0:a5ef6bc3c2e8 | 229 | void writeBYTE (char); |
| CaptainR | 2:81eaaa491a02 | 230 | void writeCOMMAND(char *, int); // send command to screen |
| CaptainR | 0:a5ef6bc3c2e8 | 231 | }; |