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
Fork of 4DGL by
TFT_4DGL_Graphics.cpp@7:38db58dc6f4d, 2010-10-17 (annotated)
- Committer:
- Kerpower
- Date:
- Sun Oct 17 10:23:58 2010 +0000
- Revision:
- 7:38db58dc6f4d
- Parent:
- 0:1102d253f057
- Child:
- 9:4b25d5413a06
2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kerpower | 7:38db58dc6f4d | 1 | // |
Kerpower | 7:38db58dc6f4d | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
Kerpower | 7:38db58dc6f4d | 3 | // |
Kerpower | 7:38db58dc6f4d | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
Kerpower | 7:38db58dc6f4d | 5 | // |
Kerpower | 7:38db58dc6f4d | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
Kerpower | 7:38db58dc6f4d | 7 | // it under the terms of the GNU General Public License as published by |
Kerpower | 7:38db58dc6f4d | 8 | // the Free Software Foundation, either version 3 of the License, or |
Kerpower | 7:38db58dc6f4d | 9 | // (at your option) any later version. |
Kerpower | 7:38db58dc6f4d | 10 | // |
Kerpower | 7:38db58dc6f4d | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
Kerpower | 7:38db58dc6f4d | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
Kerpower | 7:38db58dc6f4d | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Kerpower | 7:38db58dc6f4d | 14 | // GNU General Public License for more details. |
Kerpower | 7:38db58dc6f4d | 15 | // |
Kerpower | 7:38db58dc6f4d | 16 | // You should have received a copy of the GNU General Public License |
Kerpower | 7:38db58dc6f4d | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
Kerpower | 7:38db58dc6f4d | 18 | |
Kerpower | 7:38db58dc6f4d | 19 | #include "mbed.h" |
Kerpower | 7:38db58dc6f4d | 20 | #include "TFT_4DGL.h" |
Kerpower | 7:38db58dc6f4d | 21 | |
Kerpower | 7:38db58dc6f4d | 22 | |
Kerpower | 7:38db58dc6f4d | 23 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 24 | void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) |
Kerpower | 7:38db58dc6f4d | 25 | char command[9]= ""; |
Kerpower | 7:38db58dc6f4d | 26 | |
Kerpower | 7:38db58dc6f4d | 27 | command[0] = CIRCLE; |
Kerpower | 7:38db58dc6f4d | 28 | |
Kerpower | 7:38db58dc6f4d | 29 | command[1] = (x >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 30 | command[2] = x & 0xFF; |
Kerpower | 7:38db58dc6f4d | 31 | |
Kerpower | 7:38db58dc6f4d | 32 | command[3] = (y >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 33 | command[4] = y & 0xFF; |
Kerpower | 7:38db58dc6f4d | 34 | |
Kerpower | 7:38db58dc6f4d | 35 | command[5] = (radius >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 36 | command[6] = radius & 0xFF; |
Kerpower | 7:38db58dc6f4d | 37 | |
Kerpower | 7:38db58dc6f4d | 38 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 39 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 40 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 41 | |
Kerpower | 7:38db58dc6f4d | 42 | command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 43 | command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 44 | |
Kerpower | 7:38db58dc6f4d | 45 | writeCOMMAND(command, 9); |
Kerpower | 7:38db58dc6f4d | 46 | } |
Kerpower | 7:38db58dc6f4d | 47 | |
Kerpower | 7:38db58dc6f4d | 48 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 49 | void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle |
Kerpower | 7:38db58dc6f4d | 50 | char command[15]= ""; |
Kerpower | 7:38db58dc6f4d | 51 | |
Kerpower | 7:38db58dc6f4d | 52 | command[0] = TRIANGLE; |
Kerpower | 7:38db58dc6f4d | 53 | |
Kerpower | 7:38db58dc6f4d | 54 | command[1] = (x1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 55 | command[2] = x1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 56 | |
Kerpower | 7:38db58dc6f4d | 57 | command[3] = (y1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 58 | command[4] = y1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 59 | |
Kerpower | 7:38db58dc6f4d | 60 | command[5] = (x2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 61 | command[6] = x2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 62 | |
Kerpower | 7:38db58dc6f4d | 63 | command[7] = (y2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 64 | command[8] = y2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 65 | |
Kerpower | 7:38db58dc6f4d | 66 | command[9] = (x3 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 67 | command[10] = x3 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 68 | |
Kerpower | 7:38db58dc6f4d | 69 | command[11] = (y3 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 70 | command[12] = y3 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 71 | |
Kerpower | 7:38db58dc6f4d | 72 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 73 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 74 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 75 | |
Kerpower | 7:38db58dc6f4d | 76 | command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 77 | command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 78 | |
Kerpower | 7:38db58dc6f4d | 79 | writeCOMMAND(command, 15); |
Kerpower | 7:38db58dc6f4d | 80 | } |
Kerpower | 7:38db58dc6f4d | 81 | |
Kerpower | 7:38db58dc6f4d | 82 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 83 | void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line |
Kerpower | 7:38db58dc6f4d | 84 | char command[11]= ""; |
Kerpower | 7:38db58dc6f4d | 85 | |
Kerpower | 7:38db58dc6f4d | 86 | command[0] = LINE; |
Kerpower | 7:38db58dc6f4d | 87 | |
Kerpower | 7:38db58dc6f4d | 88 | command[1] = (x1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 89 | command[2] = x1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 90 | |
Kerpower | 7:38db58dc6f4d | 91 | command[3] = (y1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 92 | command[4] = y1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 93 | |
Kerpower | 7:38db58dc6f4d | 94 | command[5] = (x2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 95 | command[6] = x2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 96 | |
Kerpower | 7:38db58dc6f4d | 97 | command[7] = (y2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 98 | command[8] = y2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 99 | |
Kerpower | 7:38db58dc6f4d | 100 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 101 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 102 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 103 | |
Kerpower | 7:38db58dc6f4d | 104 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 105 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 106 | |
Kerpower | 7:38db58dc6f4d | 107 | writeCOMMAND(command, 11); |
Kerpower | 7:38db58dc6f4d | 108 | } |
Kerpower | 7:38db58dc6f4d | 109 | |
Kerpower | 7:38db58dc6f4d | 110 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 111 | void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle |
Kerpower | 7:38db58dc6f4d | 112 | char command[11]= ""; |
Kerpower | 7:38db58dc6f4d | 113 | |
Kerpower | 7:38db58dc6f4d | 114 | command[0] = RECTANGLE; |
Kerpower | 7:38db58dc6f4d | 115 | |
Kerpower | 7:38db58dc6f4d | 116 | command[1] = (x1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 117 | command[2] = x1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 118 | |
Kerpower | 7:38db58dc6f4d | 119 | command[3] = (y1 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 120 | command[4] = y1 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 121 | |
Kerpower | 7:38db58dc6f4d | 122 | command[5] = (x2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 123 | command[6] = x2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 124 | |
Kerpower | 7:38db58dc6f4d | 125 | command[7] = (y2 >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 126 | command[8] = y2 & 0xFF; |
Kerpower | 7:38db58dc6f4d | 127 | |
Kerpower | 7:38db58dc6f4d | 128 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 129 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 130 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 131 | |
Kerpower | 7:38db58dc6f4d | 132 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 133 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 134 | |
Kerpower | 7:38db58dc6f4d | 135 | writeCOMMAND(command, 11); |
Kerpower | 7:38db58dc6f4d | 136 | } |
Kerpower | 7:38db58dc6f4d | 137 | |
Kerpower | 7:38db58dc6f4d | 138 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 139 | void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse |
Kerpower | 7:38db58dc6f4d | 140 | char command[11]= ""; |
Kerpower | 7:38db58dc6f4d | 141 | |
Kerpower | 7:38db58dc6f4d | 142 | command[0] = ELLIPSE; |
Kerpower | 7:38db58dc6f4d | 143 | |
Kerpower | 7:38db58dc6f4d | 144 | command[1] = (x >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 145 | command[2] = x & 0xFF; |
Kerpower | 7:38db58dc6f4d | 146 | |
Kerpower | 7:38db58dc6f4d | 147 | command[3] = (y >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 148 | command[4] = y & 0xFF; |
Kerpower | 7:38db58dc6f4d | 149 | |
Kerpower | 7:38db58dc6f4d | 150 | command[5] = (radius_x >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 151 | command[6] = radius_x & 0xFF; |
Kerpower | 7:38db58dc6f4d | 152 | |
Kerpower | 7:38db58dc6f4d | 153 | command[7] = (radius_y >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 154 | command[8] = radius_y & 0xFF; |
Kerpower | 7:38db58dc6f4d | 155 | |
Kerpower | 7:38db58dc6f4d | 156 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 157 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 158 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 159 | |
Kerpower | 7:38db58dc6f4d | 160 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 161 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 162 | |
Kerpower | 7:38db58dc6f4d | 163 | writeCOMMAND(command, 11); |
Kerpower | 7:38db58dc6f4d | 164 | } |
Kerpower | 7:38db58dc6f4d | 165 | |
Kerpower | 7:38db58dc6f4d | 166 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 167 | void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel |
Kerpower | 7:38db58dc6f4d | 168 | char command[7]= ""; |
Kerpower | 7:38db58dc6f4d | 169 | |
Kerpower | 7:38db58dc6f4d | 170 | command[0] = PIXEL; |
Kerpower | 7:38db58dc6f4d | 171 | |
Kerpower | 7:38db58dc6f4d | 172 | command[1] = (x >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 173 | command[2] = x & 0xFF; |
Kerpower | 7:38db58dc6f4d | 174 | |
Kerpower | 7:38db58dc6f4d | 175 | command[3] = (y >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 176 | command[4] = y & 0xFF; |
Kerpower | 7:38db58dc6f4d | 177 | |
Kerpower | 7:38db58dc6f4d | 178 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
Kerpower | 7:38db58dc6f4d | 179 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
Kerpower | 7:38db58dc6f4d | 180 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
Kerpower | 7:38db58dc6f4d | 181 | |
Kerpower | 7:38db58dc6f4d | 182 | command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 183 | command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
Kerpower | 7:38db58dc6f4d | 184 | |
Kerpower | 7:38db58dc6f4d | 185 | writeCOMMAND(command, 7); |
Kerpower | 7:38db58dc6f4d | 186 | } |
Kerpower | 7:38db58dc6f4d | 187 | |
Kerpower | 7:38db58dc6f4d | 188 | //****************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 189 | int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data |
Kerpower | 7:38db58dc6f4d | 190 | |
Kerpower | 7:38db58dc6f4d | 191 | char command[5]= ""; |
Kerpower | 7:38db58dc6f4d | 192 | |
Kerpower | 7:38db58dc6f4d | 193 | command[0] = READPIXEL; |
Kerpower | 7:38db58dc6f4d | 194 | |
Kerpower | 7:38db58dc6f4d | 195 | command[1] = (x >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 196 | command[2] = x & 0xFF; |
Kerpower | 7:38db58dc6f4d | 197 | |
Kerpower | 7:38db58dc6f4d | 198 | command[3] = (y >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 199 | command[4] = y & 0xFF; |
Kerpower | 7:38db58dc6f4d | 200 | |
Kerpower | 7:38db58dc6f4d | 201 | int i, temp = 0, color = 0, resp = 0; |
Kerpower | 7:38db58dc6f4d | 202 | char response[2] = ""; |
Kerpower | 7:38db58dc6f4d | 203 | |
Kerpower | 7:38db58dc6f4d | 204 | freeBUFFER(); |
Kerpower | 7:38db58dc6f4d | 205 | |
Kerpower | 7:38db58dc6f4d | 206 | for (i = 0; i < 5; i++) { // send all chars to serial port |
Kerpower | 7:38db58dc6f4d | 207 | writeBYTE(command[i]); |
Kerpower | 7:38db58dc6f4d | 208 | } |
Kerpower | 7:38db58dc6f4d | 209 | |
Kerpower | 7:38db58dc6f4d | 210 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
Kerpower | 7:38db58dc6f4d | 211 | |
Kerpower | 7:38db58dc6f4d | 212 | while (_cmd.readable()) { |
Kerpower | 7:38db58dc6f4d | 213 | temp = _cmd.getc(); |
Kerpower | 7:38db58dc6f4d | 214 | response[resp++] = (char)temp; |
Kerpower | 7:38db58dc6f4d | 215 | } |
Kerpower | 7:38db58dc6f4d | 216 | |
Kerpower | 7:38db58dc6f4d | 217 | color = ((response[0] << 8) + response[1]); |
Kerpower | 7:38db58dc6f4d | 218 | |
Kerpower | 7:38db58dc6f4d | 219 | return color; // WARNING : this is 16bits color, not 24bits... need to be fixed |
Kerpower | 7:38db58dc6f4d | 220 | } |
Kerpower | 7:38db58dc6f4d | 221 | |
Kerpower | 7:38db58dc6f4d | 222 | //****************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 223 | void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { |
Kerpower | 7:38db58dc6f4d | 224 | |
Kerpower | 7:38db58dc6f4d | 225 | char command[13]= ""; |
Kerpower | 7:38db58dc6f4d | 226 | |
Kerpower | 7:38db58dc6f4d | 227 | command[0] = SCREENCOPY; |
Kerpower | 7:38db58dc6f4d | 228 | |
Kerpower | 7:38db58dc6f4d | 229 | command[1] = (xs >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 230 | command[2] = xs & 0xFF; |
Kerpower | 7:38db58dc6f4d | 231 | |
Kerpower | 7:38db58dc6f4d | 232 | command[3] = (ys >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 233 | command[4] = ys & 0xFF; |
Kerpower | 7:38db58dc6f4d | 234 | |
Kerpower | 7:38db58dc6f4d | 235 | command[5] = (xd >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 236 | command[6] = xd & 0xFF; |
Kerpower | 7:38db58dc6f4d | 237 | |
Kerpower | 7:38db58dc6f4d | 238 | command[7] = (yd >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 239 | command[8] = yd & 0xFF; |
Kerpower | 7:38db58dc6f4d | 240 | |
Kerpower | 7:38db58dc6f4d | 241 | command[9] = (width >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 242 | command[10] = width & 0xFF; |
Kerpower | 7:38db58dc6f4d | 243 | |
Kerpower | 7:38db58dc6f4d | 244 | command[11] = (height >> 8) & 0xFF; |
Kerpower | 7:38db58dc6f4d | 245 | command[12] = height & 0xFF; |
Kerpower | 7:38db58dc6f4d | 246 | |
Kerpower | 7:38db58dc6f4d | 247 | writeCOMMAND(command, 13); |
Kerpower | 7:38db58dc6f4d | 248 | } |
Kerpower | 7:38db58dc6f4d | 249 | |
Kerpower | 7:38db58dc6f4d | 250 | //**************************************************************************************************** |
Kerpower | 7:38db58dc6f4d | 251 | void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME |
Kerpower | 7:38db58dc6f4d | 252 | char command[2]= ""; |
Kerpower | 7:38db58dc6f4d | 253 | |
Kerpower | 7:38db58dc6f4d | 254 | command[0] = PENSIZE; |
Kerpower | 7:38db58dc6f4d | 255 | command[1] = mode; |
Kerpower | 7:38db58dc6f4d | 256 | |
Kerpower | 7:38db58dc6f4d | 257 | writeCOMMAND(command, 2); |
Kerpower | 0:1102d253f057 | 258 | } |