Updated serial prints for debugging

Dependents:   mbedica_on_yehowshua mbedica

Committer:
ivygatech
Date:
Mon Mar 24 17:35:56 2014 +0000
Revision:
0:de1ab53f3480
Child:
6:58c02c38e75f
Library for uVGAIII

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ivygatech 0:de1ab53f3480 1 //
ivygatech 0:de1ab53f3480 2 // uVGAIII is a class to drive 4D Systems TFT touch screens
ivygatech 0:de1ab53f3480 3 //
ivygatech 0:de1ab53f3480 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
ivygatech 0:de1ab53f3480 5 //
ivygatech 0:de1ab53f3480 6 // uVGAIII is free software: you can redistribute it and/or modify
ivygatech 0:de1ab53f3480 7 // it under the terms of the GNU General Public License as published by
ivygatech 0:de1ab53f3480 8 // the Free Software Foundation, either version 3 of the License, or
ivygatech 0:de1ab53f3480 9 // (at your option) any later version.
ivygatech 0:de1ab53f3480 10 //
ivygatech 0:de1ab53f3480 11 // uVGAIII is distributed in the hope that it will be useful,
ivygatech 0:de1ab53f3480 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ivygatech 0:de1ab53f3480 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ivygatech 0:de1ab53f3480 14 // GNU General Public License for more details.
ivygatech 0:de1ab53f3480 15 //
ivygatech 0:de1ab53f3480 16 // You should have received a copy of the GNU General Public License
ivygatech 0:de1ab53f3480 17 // along with uVGAIII. If not, see <http://www.gnu.org/licenses/>.
ivygatech 0:de1ab53f3480 18
ivygatech 0:de1ab53f3480 19 #include "mbed.h"
ivygatech 0:de1ab53f3480 20 #include "uVGAIII.h"
ivygatech 0:de1ab53f3480 21
ivygatech 0:de1ab53f3480 22 #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0])
ivygatech 0:de1ab53f3480 23
ivygatech 0:de1ab53f3480 24 //**************************************************************************
ivygatech 0:de1ab53f3480 25 void uVGAIII :: cls() { // clear screen
ivygatech 0:de1ab53f3480 26 char command[2] = "";
ivygatech 0:de1ab53f3480 27 command[0] = ( CLS >> 8 ) & 0xFF;
ivygatech 0:de1ab53f3480 28 command[1] = CLS & 0xFF;
ivygatech 0:de1ab53f3480 29 writeCOMMAND(command, 2, 1);
ivygatech 0:de1ab53f3480 30
ivygatech 0:de1ab53f3480 31 #if DEBUGMODE
ivygatech 0:de1ab53f3480 32 pc.printf("Clear screen completed.\n");
ivygatech 0:de1ab53f3480 33 #endif
ivygatech 0:de1ab53f3480 34 }
ivygatech 0:de1ab53f3480 35
ivygatech 0:de1ab53f3480 36 //****************************************************************************************************
ivygatech 0:de1ab53f3480 37 void uVGAIII :: change_color(int oldColor, int newColor) { // change all old color pixels to new color within the clipping window area
ivygatech 0:de1ab53f3480 38 char command[6] = "";
ivygatech 0:de1ab53f3480 39
ivygatech 0:de1ab53f3480 40 command[0] = (CHANGECOLOR >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 41 command[1] = CHANGECOLOR & 0xFF;
ivygatech 0:de1ab53f3480 42
ivygatech 0:de1ab53f3480 43 int red5 = (oldColor >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 44 int green6 = (oldColor >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 45 int blue5 = (oldColor >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 46
ivygatech 0:de1ab53f3480 47 command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 48 command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 49
ivygatech 0:de1ab53f3480 50 red5 = (newColor >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 51 green6 = (newColor >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 52 blue5 = (newColor >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 53
ivygatech 0:de1ab53f3480 54 command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 55 command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 56
ivygatech 0:de1ab53f3480 57 writeCOMMAND(command, 6, 1);
ivygatech 0:de1ab53f3480 58
ivygatech 0:de1ab53f3480 59 #if DEBUGMODE
ivygatech 0:de1ab53f3480 60 pc.printf("Change color completed.\n");
ivygatech 0:de1ab53f3480 61 #endif
ivygatech 0:de1ab53f3480 62 }
ivygatech 0:de1ab53f3480 63
ivygatech 0:de1ab53f3480 64 //****************************************************************************************************
ivygatech 0:de1ab53f3480 65 void uVGAIII :: background_color(int color) { // set screen background color
ivygatech 0:de1ab53f3480 66
ivygatech 0:de1ab53f3480 67 char command[4]= ""; // input color is in 24bits like 0xRRGGBB
ivygatech 0:de1ab53f3480 68
ivygatech 0:de1ab53f3480 69 command[0] = ( BCKGDCOLOR >> 8 ) & 0xFF;
ivygatech 0:de1ab53f3480 70 command[1] = BCKGDCOLOR & 0xFF;
ivygatech 0:de1ab53f3480 71
ivygatech 0:de1ab53f3480 72 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 73 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 74 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 75
ivygatech 0:de1ab53f3480 76 command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 77 command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 78
ivygatech 0:de1ab53f3480 79 //command[2] = 0x00;
ivygatech 0:de1ab53f3480 80 //command[3] = 0x10;
ivygatech 0:de1ab53f3480 81
ivygatech 0:de1ab53f3480 82 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 83
ivygatech 0:de1ab53f3480 84 #if DEBUGMODE
ivygatech 0:de1ab53f3480 85 pc.printf("Set background color completed.\n");
ivygatech 0:de1ab53f3480 86 #endif
ivygatech 0:de1ab53f3480 87 }
ivygatech 0:de1ab53f3480 88
ivygatech 0:de1ab53f3480 89 //****************************************************************************************************
ivygatech 0:de1ab53f3480 90 void uVGAIII :: screen_mode(char mode) { // set the graphics orientation LANDSCAPE, LANDSCAPE_R, PORTRAIT, PORTRAIT_R
ivygatech 0:de1ab53f3480 91 char command[4]= "";
ivygatech 0:de1ab53f3480 92
ivygatech 0:de1ab53f3480 93 command[0] = (SCREENMODE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 94 command[1] = SCREENMODE & 0xFF;
ivygatech 0:de1ab53f3480 95 command[2] = 0x00;
ivygatech 0:de1ab53f3480 96 command[3] = mode;
ivygatech 0:de1ab53f3480 97
ivygatech 0:de1ab53f3480 98 switch (mode) {
ivygatech 0:de1ab53f3480 99 case LANDSCAPE :
ivygatech 0:de1ab53f3480 100 current_orientation = IS_LANDSCAPE;
ivygatech 0:de1ab53f3480 101 break;
ivygatech 0:de1ab53f3480 102 case LANDSCAPE_R :
ivygatech 0:de1ab53f3480 103 current_orientation = IS_LANDSCAPE;
ivygatech 0:de1ab53f3480 104 break;
ivygatech 0:de1ab53f3480 105 case PORTRAIT :
ivygatech 0:de1ab53f3480 106 current_orientation = IS_PORTRAIT;
ivygatech 0:de1ab53f3480 107 break;
ivygatech 0:de1ab53f3480 108 case PORTRAIT_R :
ivygatech 0:de1ab53f3480 109 current_orientation = IS_PORTRAIT;
ivygatech 0:de1ab53f3480 110 break;
ivygatech 0:de1ab53f3480 111 }
ivygatech 0:de1ab53f3480 112
ivygatech 0:de1ab53f3480 113 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 114
ivygatech 0:de1ab53f3480 115 #if DEBUGMODE
ivygatech 0:de1ab53f3480 116 pc.printf("Screen mode completed.\n");
ivygatech 0:de1ab53f3480 117 #endif
ivygatech 0:de1ab53f3480 118
ivygatech 0:de1ab53f3480 119 set_font(current_font);
ivygatech 0:de1ab53f3480 120 }
ivygatech 0:de1ab53f3480 121
ivygatech 0:de1ab53f3480 122 //****************************************************************************************************
ivygatech 0:de1ab53f3480 123 void uVGAIII :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y)
ivygatech 0:de1ab53f3480 124 char command[10]= "";
ivygatech 0:de1ab53f3480 125
ivygatech 0:de1ab53f3480 126 command[0] = (CIRCLE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 127 command[1] = CIRCLE & 0xFF;
ivygatech 0:de1ab53f3480 128
ivygatech 0:de1ab53f3480 129 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 130 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 131
ivygatech 0:de1ab53f3480 132 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 133 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 134
ivygatech 0:de1ab53f3480 135 command[6] = (radius >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 136 command[7] = radius & 0xFF;
ivygatech 0:de1ab53f3480 137
ivygatech 0:de1ab53f3480 138 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 139 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 140 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 141
ivygatech 0:de1ab53f3480 142 command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 143 command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 144
ivygatech 0:de1ab53f3480 145 writeCOMMAND(command, 10, 1);
ivygatech 0:de1ab53f3480 146
ivygatech 0:de1ab53f3480 147 #if DEBUGMODE
ivygatech 0:de1ab53f3480 148 pc.printf("Draw circle completed.\n");
ivygatech 0:de1ab53f3480 149 #endif
ivygatech 0:de1ab53f3480 150 }
ivygatech 0:de1ab53f3480 151
ivygatech 0:de1ab53f3480 152 //****************************************************************************************************
ivygatech 0:de1ab53f3480 153 void uVGAIII :: filled_circle(int x, int y , int radius, int color) { // draw a filled circle in (x,y)
ivygatech 0:de1ab53f3480 154 char command[10]= "";
ivygatech 0:de1ab53f3480 155
ivygatech 0:de1ab53f3480 156 command[0] = (CIRCLE_F >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 157 command[1] = CIRCLE_F & 0xFF;
ivygatech 0:de1ab53f3480 158
ivygatech 0:de1ab53f3480 159 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 160 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 161
ivygatech 0:de1ab53f3480 162 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 163 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 164
ivygatech 0:de1ab53f3480 165 command[6] = (radius >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 166 command[7] = radius & 0xFF;
ivygatech 0:de1ab53f3480 167
ivygatech 0:de1ab53f3480 168 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 169 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 170 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 171
ivygatech 0:de1ab53f3480 172 command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 173 command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 174
ivygatech 0:de1ab53f3480 175 writeCOMMAND(command, 10, 1);
ivygatech 0:de1ab53f3480 176
ivygatech 0:de1ab53f3480 177 #if DEBUGMODE
ivygatech 0:de1ab53f3480 178 pc.printf("Draw filled circle completed.\n");
ivygatech 0:de1ab53f3480 179 #endif
ivygatech 0:de1ab53f3480 180 }
ivygatech 0:de1ab53f3480 181
ivygatech 0:de1ab53f3480 182 //****************************************************************************************************
ivygatech 0:de1ab53f3480 183 void uVGAIII :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle
ivygatech 0:de1ab53f3480 184 char command[16]= "";
ivygatech 0:de1ab53f3480 185
ivygatech 0:de1ab53f3480 186 command[0] = (TRIANGLE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 187 command[1] = TRIANGLE & 0xFF;
ivygatech 0:de1ab53f3480 188
ivygatech 0:de1ab53f3480 189 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 190 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 191
ivygatech 0:de1ab53f3480 192 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 193 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 194
ivygatech 0:de1ab53f3480 195 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 196 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 197
ivygatech 0:de1ab53f3480 198 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 199 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 200
ivygatech 0:de1ab53f3480 201 command[10] = (x3 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 202 command[11] = x3 & 0xFF;
ivygatech 0:de1ab53f3480 203
ivygatech 0:de1ab53f3480 204 command[12] = (y3 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 205 command[13] = y3 & 0xFF;
ivygatech 0:de1ab53f3480 206
ivygatech 0:de1ab53f3480 207 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 208 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 209 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 210
ivygatech 0:de1ab53f3480 211 command[14] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 212 command[15] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 213
ivygatech 0:de1ab53f3480 214 writeCOMMAND(command, 16, 1);
ivygatech 0:de1ab53f3480 215
ivygatech 0:de1ab53f3480 216 #if DEBUGMODE
ivygatech 0:de1ab53f3480 217 pc.printf("Draw triangle completed.\n");
ivygatech 0:de1ab53f3480 218 #endif
ivygatech 0:de1ab53f3480 219 }
ivygatech 0:de1ab53f3480 220
ivygatech 0:de1ab53f3480 221 //****************************************************************************************************
ivygatech 0:de1ab53f3480 222 void uVGAIII :: filled_triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a filled traingle
ivygatech 0:de1ab53f3480 223 char command[16]= "";
ivygatech 0:de1ab53f3480 224
ivygatech 0:de1ab53f3480 225 command[0] = (TRIANGLE_F >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 226 command[1] = TRIANGLE_F & 0xFF;
ivygatech 0:de1ab53f3480 227
ivygatech 0:de1ab53f3480 228 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 229 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 230
ivygatech 0:de1ab53f3480 231 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 232 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 233
ivygatech 0:de1ab53f3480 234 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 235 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 236
ivygatech 0:de1ab53f3480 237 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 238 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 239
ivygatech 0:de1ab53f3480 240 command[10] = (x3 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 241 command[11] = x3 & 0xFF;
ivygatech 0:de1ab53f3480 242
ivygatech 0:de1ab53f3480 243 command[12] = (y3 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 244 command[13] = y3 & 0xFF;
ivygatech 0:de1ab53f3480 245
ivygatech 0:de1ab53f3480 246 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 247 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 248 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 249
ivygatech 0:de1ab53f3480 250 command[14] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 251 command[15] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 252
ivygatech 0:de1ab53f3480 253 writeCOMMAND(command, 16, 1);
ivygatech 0:de1ab53f3480 254
ivygatech 0:de1ab53f3480 255 #if DEBUGMODE
ivygatech 0:de1ab53f3480 256 pc.printf("Draw filled triangle completed.\n");
ivygatech 0:de1ab53f3480 257 #endif
ivygatech 0:de1ab53f3480 258 }
ivygatech 0:de1ab53f3480 259
ivygatech 0:de1ab53f3480 260 //****************************************************************************************************
ivygatech 0:de1ab53f3480 261 void uVGAIII :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line
ivygatech 0:de1ab53f3480 262 char command[12]= "";
ivygatech 0:de1ab53f3480 263
ivygatech 0:de1ab53f3480 264 command[0] = (LINE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 265 command[1] = LINE & 0xFF;
ivygatech 0:de1ab53f3480 266
ivygatech 0:de1ab53f3480 267 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 268 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 269
ivygatech 0:de1ab53f3480 270 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 271 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 272
ivygatech 0:de1ab53f3480 273 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 274 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 275
ivygatech 0:de1ab53f3480 276 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 277 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 278
ivygatech 0:de1ab53f3480 279 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 280 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 281 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 282
ivygatech 0:de1ab53f3480 283 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 284 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 285
ivygatech 0:de1ab53f3480 286 writeCOMMAND(command, 12, 1);
ivygatech 0:de1ab53f3480 287
ivygatech 0:de1ab53f3480 288 #if DEBUGMODE
ivygatech 0:de1ab53f3480 289 pc.printf("Draw line completed.\n");
ivygatech 0:de1ab53f3480 290 #endif
ivygatech 0:de1ab53f3480 291 }
ivygatech 0:de1ab53f3480 292
ivygatech 0:de1ab53f3480 293 //****************************************************************************************************
ivygatech 0:de1ab53f3480 294 void uVGAIII :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle
ivygatech 0:de1ab53f3480 295 char command[12]= "";
ivygatech 0:de1ab53f3480 296
ivygatech 0:de1ab53f3480 297 command[0] = (RECTANGLE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 298 command[1] = RECTANGLE & 0xFF;
ivygatech 0:de1ab53f3480 299
ivygatech 0:de1ab53f3480 300 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 301 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 302
ivygatech 0:de1ab53f3480 303 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 304 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 305
ivygatech 0:de1ab53f3480 306 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 307 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 308
ivygatech 0:de1ab53f3480 309 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 310 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 311
ivygatech 0:de1ab53f3480 312 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 313 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 314 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 315
ivygatech 0:de1ab53f3480 316 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 317 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 318
ivygatech 0:de1ab53f3480 319 writeCOMMAND(command, 12, 1);
ivygatech 0:de1ab53f3480 320
ivygatech 0:de1ab53f3480 321 #if DEBUGMODE
ivygatech 0:de1ab53f3480 322 pc.printf("Draw rectangle completed.\n");
ivygatech 0:de1ab53f3480 323 #endif
ivygatech 0:de1ab53f3480 324 }
ivygatech 0:de1ab53f3480 325
ivygatech 0:de1ab53f3480 326 //****************************************************************************************************
ivygatech 0:de1ab53f3480 327 void uVGAIII :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a filled rectangle
ivygatech 0:de1ab53f3480 328 char command[12]= "";
ivygatech 0:de1ab53f3480 329
ivygatech 0:de1ab53f3480 330 command[0] = (RECTANGLE_F >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 331 command[1] = RECTANGLE_F & 0xFF;
ivygatech 0:de1ab53f3480 332
ivygatech 0:de1ab53f3480 333 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 334 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 335
ivygatech 0:de1ab53f3480 336 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 337 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 338
ivygatech 0:de1ab53f3480 339 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 340 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 341
ivygatech 0:de1ab53f3480 342 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 343 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 344
ivygatech 0:de1ab53f3480 345 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 346 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 347 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 348
ivygatech 0:de1ab53f3480 349 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 350 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 351
ivygatech 0:de1ab53f3480 352 writeCOMMAND(command, 12, 1);
ivygatech 0:de1ab53f3480 353
ivygatech 0:de1ab53f3480 354 #if DEBUGMODE
ivygatech 0:de1ab53f3480 355 pc.printf("Draw filled rectangle completed.\n");
ivygatech 0:de1ab53f3480 356 #endif
ivygatech 0:de1ab53f3480 357 }
ivygatech 0:de1ab53f3480 358
ivygatech 0:de1ab53f3480 359 //****************************************************************************************************
ivygatech 0:de1ab53f3480 360 void uVGAIII :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse
ivygatech 0:de1ab53f3480 361 char command[12]= "";
ivygatech 0:de1ab53f3480 362
ivygatech 0:de1ab53f3480 363 command[0] = (ELLIPSE >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 364 command[1] = ELLIPSE & 0xFF;
ivygatech 0:de1ab53f3480 365
ivygatech 0:de1ab53f3480 366 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 367 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 368
ivygatech 0:de1ab53f3480 369 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 370 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 371
ivygatech 0:de1ab53f3480 372 command[6] = (radius_x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 373 command[7] = radius_x & 0xFF;
ivygatech 0:de1ab53f3480 374
ivygatech 0:de1ab53f3480 375 command[8] = (radius_y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 376 command[9] = radius_y & 0xFF;
ivygatech 0:de1ab53f3480 377
ivygatech 0:de1ab53f3480 378 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 379 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 380 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 381
ivygatech 0:de1ab53f3480 382 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 383 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 384
ivygatech 0:de1ab53f3480 385 writeCOMMAND(command, 12, 1);
ivygatech 0:de1ab53f3480 386
ivygatech 0:de1ab53f3480 387 #if DEBUGMODE
ivygatech 0:de1ab53f3480 388 pc.printf("Draw ellipse completed.\n");
ivygatech 0:de1ab53f3480 389 #endif
ivygatech 0:de1ab53f3480 390 }
ivygatech 0:de1ab53f3480 391
ivygatech 0:de1ab53f3480 392 //****************************************************************************************************
ivygatech 0:de1ab53f3480 393 void uVGAIII :: filled_ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw a filled ellipse
ivygatech 0:de1ab53f3480 394 char command[12] = "";
ivygatech 0:de1ab53f3480 395
ivygatech 0:de1ab53f3480 396 command[0] = (ELLIPSE_F >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 397 command[1] = ELLIPSE_F & 0xFF;
ivygatech 0:de1ab53f3480 398
ivygatech 0:de1ab53f3480 399 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 400 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 401
ivygatech 0:de1ab53f3480 402 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 403 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 404
ivygatech 0:de1ab53f3480 405 command[6] = (radius_x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 406 command[7] = radius_x & 0xFF;
ivygatech 0:de1ab53f3480 407
ivygatech 0:de1ab53f3480 408 command[8] = (radius_y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 409 command[9] = radius_y & 0xFF;
ivygatech 0:de1ab53f3480 410
ivygatech 0:de1ab53f3480 411 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 412 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 413 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 414
ivygatech 0:de1ab53f3480 415 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 416 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 417
ivygatech 0:de1ab53f3480 418 writeCOMMAND(command, 12, 1);
ivygatech 0:de1ab53f3480 419
ivygatech 0:de1ab53f3480 420 #if DEBUGMODE
ivygatech 0:de1ab53f3480 421 pc.printf("Draw filled ellipse completed.\n");
ivygatech 0:de1ab53f3480 422 #endif
ivygatech 0:de1ab53f3480 423 }
ivygatech 0:de1ab53f3480 424
ivygatech 0:de1ab53f3480 425 //****************************************************************************************************
ivygatech 0:de1ab53f3480 426 void uVGAIII :: button(int state, int x, int y, int buttoncolor, int txtcolor, int font, int txtWidth, int txtHeight, char * text) { // draw a button
ivygatech 0:de1ab53f3480 427 char command[1000] = "";
ivygatech 0:de1ab53f3480 428 int size = strlen(text);
ivygatech 0:de1ab53f3480 429 int i = 0;
ivygatech 0:de1ab53f3480 430
ivygatech 0:de1ab53f3480 431 command[0] = (BUTTON >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 432 command[1] = BUTTON & 0xFF;
ivygatech 0:de1ab53f3480 433
ivygatech 0:de1ab53f3480 434 command[2] = (state >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 435 command[3] = state & 0xFF;
ivygatech 0:de1ab53f3480 436
ivygatech 0:de1ab53f3480 437 command[4] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 438 command[5] = x & 0xFF;
ivygatech 0:de1ab53f3480 439
ivygatech 0:de1ab53f3480 440 command[6] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 441 command[7] = y & 0xFF;
ivygatech 0:de1ab53f3480 442
ivygatech 0:de1ab53f3480 443 int red5 = (buttoncolor >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 444 int green6 = (buttoncolor >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 445 int blue5 = (buttoncolor >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 446
ivygatech 0:de1ab53f3480 447 command[8] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 448 command[9] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 449
ivygatech 0:de1ab53f3480 450 red5 = (txtcolor >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 451 green6 = (txtcolor >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 452 blue5 = (txtcolor >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 453
ivygatech 0:de1ab53f3480 454 command[10] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 455 command[11] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 456
ivygatech 0:de1ab53f3480 457 command[12] = (font >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 458 command[13] = font & 0xFF;
ivygatech 0:de1ab53f3480 459
ivygatech 0:de1ab53f3480 460 command[14] = (txtWidth >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 461 command[15] = txtWidth & 0xFF;
ivygatech 0:de1ab53f3480 462
ivygatech 0:de1ab53f3480 463 command[16] = (txtHeight >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 464 command[17] = txtHeight & 0xFF;
ivygatech 0:de1ab53f3480 465
ivygatech 0:de1ab53f3480 466 for (i=0; i<size; i++) command[18+i] = text[i];
ivygatech 0:de1ab53f3480 467
ivygatech 0:de1ab53f3480 468 command[18+size] = 0;
ivygatech 0:de1ab53f3480 469
ivygatech 0:de1ab53f3480 470 writeCOMMAND(command, 19 + size, 1);
ivygatech 0:de1ab53f3480 471
ivygatech 0:de1ab53f3480 472 #if DEBUGMODE
ivygatech 0:de1ab53f3480 473 pc.printf("Draw button completed.\n");
ivygatech 0:de1ab53f3480 474 #endif
ivygatech 0:de1ab53f3480 475 }
ivygatech 0:de1ab53f3480 476
ivygatech 0:de1ab53f3480 477 //****************************************************************************************************
ivygatech 0:de1ab53f3480 478 void uVGAIII :: panel(int state, int x, int y, int Width, int Height, int color) { // draw a panel
ivygatech 0:de1ab53f3480 479 char command[14] = "";
ivygatech 0:de1ab53f3480 480
ivygatech 0:de1ab53f3480 481 command[0] = (PANEL >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 482 command[1] = PANEL & 0xFF;
ivygatech 0:de1ab53f3480 483
ivygatech 0:de1ab53f3480 484 command[2] = (state >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 485 command[3] = state & 0xFF;
ivygatech 0:de1ab53f3480 486
ivygatech 0:de1ab53f3480 487 command[4] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 488 command[5] = x & 0xFF;
ivygatech 0:de1ab53f3480 489
ivygatech 0:de1ab53f3480 490 command[6] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 491 command[7] = y & 0xFF;
ivygatech 0:de1ab53f3480 492
ivygatech 0:de1ab53f3480 493 command[8] = (Width >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 494 command[9] = Width & 0xFF;
ivygatech 0:de1ab53f3480 495
ivygatech 0:de1ab53f3480 496 command[10] = (Height >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 497 command[11] = Height & 0xFF;
ivygatech 0:de1ab53f3480 498
ivygatech 0:de1ab53f3480 499 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 500 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 501 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 502
ivygatech 0:de1ab53f3480 503 command[12] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 504 command[13] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 505
ivygatech 0:de1ab53f3480 506 writeCOMMAND(command, 14, 1);
ivygatech 0:de1ab53f3480 507
ivygatech 0:de1ab53f3480 508 #if DEBUGMODE
ivygatech 0:de1ab53f3480 509 pc.printf("Draw panel completed.\n");
ivygatech 0:de1ab53f3480 510 #endif
ivygatech 0:de1ab53f3480 511 }
ivygatech 0:de1ab53f3480 512
ivygatech 0:de1ab53f3480 513 //****************************************************************************************************
ivygatech 0:de1ab53f3480 514 void uVGAIII :: slider(char mode, int x1, int y1, int x2, int y2, int color, int scale, int value) { // draw a slider
ivygatech 0:de1ab53f3480 515 char command[18] = "";
ivygatech 0:de1ab53f3480 516
ivygatech 0:de1ab53f3480 517 command[0] = (SLIDER >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 518 command[1] = SLIDER & 0xFF;
ivygatech 0:de1ab53f3480 519
ivygatech 0:de1ab53f3480 520 command[2] = 0x00;
ivygatech 0:de1ab53f3480 521 command[3] = mode & 0xFF;
ivygatech 0:de1ab53f3480 522
ivygatech 0:de1ab53f3480 523 command[4] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 524 command[5] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 525
ivygatech 0:de1ab53f3480 526 command[6] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 527 command[7] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 528
ivygatech 0:de1ab53f3480 529 command[8] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 530 command[9] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 531
ivygatech 0:de1ab53f3480 532 command[10] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 533 command[11] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 534
ivygatech 0:de1ab53f3480 535 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 536 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 537 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 538
ivygatech 0:de1ab53f3480 539 command[12] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 540 command[13] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 541
ivygatech 0:de1ab53f3480 542 command[14] = (scale >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 543 command[15] = scale & 0xFF;
ivygatech 0:de1ab53f3480 544
ivygatech 0:de1ab53f3480 545 command[16] = (value) & 0xFF;
ivygatech 0:de1ab53f3480 546 command[17] = value & 0xFF;
ivygatech 0:de1ab53f3480 547
ivygatech 0:de1ab53f3480 548 writeCOMMAND(command, 18, 1);
ivygatech 0:de1ab53f3480 549
ivygatech 0:de1ab53f3480 550 #if DEBUGMODE
ivygatech 0:de1ab53f3480 551 pc.printf("Draw slider completed.\n");
ivygatech 0:de1ab53f3480 552 #endif
ivygatech 0:de1ab53f3480 553 }
ivygatech 0:de1ab53f3480 554
ivygatech 0:de1ab53f3480 555 //****************************************************************************************************
ivygatech 0:de1ab53f3480 556 void uVGAIII :: put_pixel(int x, int y, int color) { // draw a pixel
ivygatech 0:de1ab53f3480 557 char command[8] = "";
ivygatech 0:de1ab53f3480 558
ivygatech 0:de1ab53f3480 559 command[0] = (PUTPIXEL >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 560 command[1] = PUTPIXEL & 0xFF;
ivygatech 0:de1ab53f3480 561
ivygatech 0:de1ab53f3480 562 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 563 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 564
ivygatech 0:de1ab53f3480 565 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 566 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 567
ivygatech 0:de1ab53f3480 568 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 569 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 570 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 571
ivygatech 0:de1ab53f3480 572 command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ivygatech 0:de1ab53f3480 573 command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ivygatech 0:de1ab53f3480 574
ivygatech 0:de1ab53f3480 575 writeCOMMAND(command, 8, 1);
ivygatech 0:de1ab53f3480 576
ivygatech 0:de1ab53f3480 577 #if DEBUGMODE
ivygatech 0:de1ab53f3480 578 pc.printf("Put pixel completed.\n");
ivygatech 0:de1ab53f3480 579 #endif
ivygatech 0:de1ab53f3480 580 }
ivygatech 0:de1ab53f3480 581
ivygatech 0:de1ab53f3480 582 //******************************************************************************************************
ivygatech 0:de1ab53f3480 583 int uVGAIII :: read_pixel(int x, int y) { // read screen info and populate data
ivygatech 0:de1ab53f3480 584
ivygatech 0:de1ab53f3480 585 char command[6]= "";
ivygatech 0:de1ab53f3480 586
ivygatech 0:de1ab53f3480 587 command[0] = (READPIXEL >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 588 command[1] = READPIXEL & 0xFF;
ivygatech 0:de1ab53f3480 589
ivygatech 0:de1ab53f3480 590 command[2] = (x >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 591 command[3] = x & 0xFF;
ivygatech 0:de1ab53f3480 592
ivygatech 0:de1ab53f3480 593 command[4] = (y >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 594 command[5] = y & 0xFF;
ivygatech 0:de1ab53f3480 595
ivygatech 0:de1ab53f3480 596 int i, temp = 0, color = 0, resp = 0;
ivygatech 0:de1ab53f3480 597 char response[3] = "";
ivygatech 0:de1ab53f3480 598
ivygatech 0:de1ab53f3480 599 freeBUFFER();
ivygatech 0:de1ab53f3480 600
ivygatech 0:de1ab53f3480 601 #if DEBUGMODE
ivygatech 0:de1ab53f3480 602 pc.printf("\n");
ivygatech 0:de1ab53f3480 603 pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]);
ivygatech 0:de1ab53f3480 604 #endif
ivygatech 0:de1ab53f3480 605
ivygatech 0:de1ab53f3480 606 for (i = 0; i < 6; i++) { // send all chars to serial port
ivygatech 0:de1ab53f3480 607 writeBYTE(command[i]);
ivygatech 0:de1ab53f3480 608 }
ivygatech 0:de1ab53f3480 609
ivygatech 0:de1ab53f3480 610 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ivygatech 0:de1ab53f3480 611
ivygatech 0:de1ab53f3480 612 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
ivygatech 0:de1ab53f3480 613 temp = _cmd.getc();
ivygatech 0:de1ab53f3480 614 #if DEBUGMODE
ivygatech 0:de1ab53f3480 615 pc.printf("Response = 0x%02X\n",int(temp));
ivygatech 0:de1ab53f3480 616 #endif
ivygatech 0:de1ab53f3480 617 response[resp++] = (char)temp;
ivygatech 0:de1ab53f3480 618 }
ivygatech 0:de1ab53f3480 619
ivygatech 0:de1ab53f3480 620 color = ((response[1] << 8) + response[2]);
ivygatech 0:de1ab53f3480 621
ivygatech 0:de1ab53f3480 622 #if DEBUGMODE
ivygatech 0:de1ab53f3480 623 pc.printf("Read pixel completed.\n");
ivygatech 0:de1ab53f3480 624 #endif
ivygatech 0:de1ab53f3480 625
ivygatech 0:de1ab53f3480 626 return color; // WARNING : this is 16bits color, not 24bits... need to be fixed
ivygatech 0:de1ab53f3480 627 }
ivygatech 0:de1ab53f3480 628
ivygatech 0:de1ab53f3480 629 //******************************************************************************************************
ivygatech 0:de1ab53f3480 630 void uVGAIII :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { // copy an area of a screen from xs, ys of size given by width and height parameters and pastes it to another location determined by xd, yd
ivygatech 0:de1ab53f3480 631
ivygatech 0:de1ab53f3480 632 char command[14]= "";
ivygatech 0:de1ab53f3480 633
ivygatech 0:de1ab53f3480 634 command[0] = (SCREENCOPY >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 635 command[1] = SCREENCOPY & 0xFF;
ivygatech 0:de1ab53f3480 636
ivygatech 0:de1ab53f3480 637 command[2] = (xs >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 638 command[3] = xs & 0xFF;
ivygatech 0:de1ab53f3480 639
ivygatech 0:de1ab53f3480 640 command[4] = (ys >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 641 command[5] = ys & 0xFF;
ivygatech 0:de1ab53f3480 642
ivygatech 0:de1ab53f3480 643 command[6] = (xd >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 644 command[7] = xd & 0xFF;
ivygatech 0:de1ab53f3480 645
ivygatech 0:de1ab53f3480 646 command[8] = (yd >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 647 command[9] = yd & 0xFF;
ivygatech 0:de1ab53f3480 648
ivygatech 0:de1ab53f3480 649 command[10] = (width >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 650 command[11] = width & 0xFF;
ivygatech 0:de1ab53f3480 651
ivygatech 0:de1ab53f3480 652 command[12] = (height >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 653 command[13] = height & 0xFF;
ivygatech 0:de1ab53f3480 654
ivygatech 0:de1ab53f3480 655 writeCOMMAND(command, 14, 1);
ivygatech 0:de1ab53f3480 656
ivygatech 0:de1ab53f3480 657 #if DEBUGMODE
ivygatech 0:de1ab53f3480 658 pc.printf("Screen copy completed.\n");
ivygatech 0:de1ab53f3480 659 #endif
ivygatech 0:de1ab53f3480 660 }
ivygatech 0:de1ab53f3480 661
ivygatech 0:de1ab53f3480 662 //******************************************************************************************************
ivygatech 0:de1ab53f3480 663 void uVGAIII :: clipping(char value) { // To enable or disable the ability for Clippling to be used
ivygatech 0:de1ab53f3480 664 char command[4] = "";
ivygatech 0:de1ab53f3480 665
ivygatech 0:de1ab53f3480 666 command[0] = (CLIPPING >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 667 command[1] = CLIPPING & 0xFF;
ivygatech 0:de1ab53f3480 668
ivygatech 0:de1ab53f3480 669 command[2] = 0x00;
ivygatech 0:de1ab53f3480 670 command[3] = value & 0xFF;
ivygatech 0:de1ab53f3480 671
ivygatech 0:de1ab53f3480 672 writeCOMMAND(command, 4, 1);
ivygatech 0:de1ab53f3480 673
ivygatech 0:de1ab53f3480 674 #if DEBUGMODE
ivygatech 0:de1ab53f3480 675 pc.printf("Clipping completed.\n");
ivygatech 0:de1ab53f3480 676 #endif
ivygatech 0:de1ab53f3480 677 }
ivygatech 0:de1ab53f3480 678
ivygatech 0:de1ab53f3480 679 //******************************************************************************************************
ivygatech 0:de1ab53f3480 680 void uVGAIII :: set_clipping_win(int x1, int y1, int x2, int y2) { // Set the clipping window region
ivygatech 0:de1ab53f3480 681 char command[10] = "";
ivygatech 0:de1ab53f3480 682
ivygatech 0:de1ab53f3480 683 command[0] = (SETCLIPWIN >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 684 command[1] = SETCLIPWIN & 0xFF;
ivygatech 0:de1ab53f3480 685
ivygatech 0:de1ab53f3480 686 command[2] = (x1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 687 command[3] = x1 & 0xFF;
ivygatech 0:de1ab53f3480 688
ivygatech 0:de1ab53f3480 689 command[4] = (y1 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 690 command[5] = y1 & 0xFF;
ivygatech 0:de1ab53f3480 691
ivygatech 0:de1ab53f3480 692 command[6] = (x2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 693 command[7] = x2 & 0xFF;
ivygatech 0:de1ab53f3480 694
ivygatech 0:de1ab53f3480 695 command[8] = (y2 >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 696 command[9] = y2 & 0xFF;
ivygatech 0:de1ab53f3480 697
ivygatech 0:de1ab53f3480 698 writeCOMMAND(command, 10, 1);
ivygatech 0:de1ab53f3480 699
ivygatech 0:de1ab53f3480 700 #if DEBUGMODE
ivygatech 0:de1ab53f3480 701 pc.printf("Set clipping window completed.\n");
ivygatech 0:de1ab53f3480 702 #endif
ivygatech 0:de1ab53f3480 703 }
ivygatech 0:de1ab53f3480 704
ivygatech 0:de1ab53f3480 705 //******************************************************************************************************
ivygatech 0:de1ab53f3480 706 void uVGAIII :: extend_clip_region() { // to force the clip region to the extent of the last text that was printed, or the last image that was shown
ivygatech 0:de1ab53f3480 707 char command[2] = "";
ivygatech 0:de1ab53f3480 708
ivygatech 0:de1ab53f3480 709 command[0] = (EXTCLIPREG) & 0xFF;
ivygatech 0:de1ab53f3480 710 command[1] = EXTCLIPREG & 0xFF;
ivygatech 0:de1ab53f3480 711
ivygatech 0:de1ab53f3480 712 writeCOMMAND(command, 2, 1);
ivygatech 0:de1ab53f3480 713
ivygatech 0:de1ab53f3480 714 #if DEBUGMODE
ivygatech 0:de1ab53f3480 715 pc.printf("Extend clip region completed.\n");
ivygatech 0:de1ab53f3480 716 #endif
ivygatech 0:de1ab53f3480 717 }
ivygatech 0:de1ab53f3480 718
ivygatech 0:de1ab53f3480 719 //******************************************************************************************************
ivygatech 0:de1ab53f3480 720 void uVGAIII :: move_origin(int xpos, int ypos) { // Move the origin to a new position
ivygatech 0:de1ab53f3480 721 char command[6] = "";
ivygatech 0:de1ab53f3480 722
ivygatech 0:de1ab53f3480 723 command[0] = (MOVEORIGIN) & 0xFF;
ivygatech 0:de1ab53f3480 724 command[1] = MOVEORIGIN & 0xFF;
ivygatech 0:de1ab53f3480 725
ivygatech 0:de1ab53f3480 726 command[2] = (xpos >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 727 command[3] = xpos & 0xFF;
ivygatech 0:de1ab53f3480 728
ivygatech 0:de1ab53f3480 729 command[4] = (ypos >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 730 command[5] = ypos & 0xFF;
ivygatech 0:de1ab53f3480 731
ivygatech 0:de1ab53f3480 732 writeCOMMAND(command, 6, 1);
ivygatech 0:de1ab53f3480 733
ivygatech 0:de1ab53f3480 734 #if DEBUGMODE
ivygatech 0:de1ab53f3480 735 pc.printf("Move origin completed.\n");
ivygatech 0:de1ab53f3480 736 #endif
ivygatech 0:de1ab53f3480 737 }
ivygatech 0:de1ab53f3480 738
ivygatech 0:de1ab53f3480 739 //******************************************************************************************************
ivygatech 0:de1ab53f3480 740 void uVGAIII :: line_pattern(int pattern) { // Set the line pattern
ivygatech 0:de1ab53f3480 741 char command[4] = ""; // If set to zero means lines are solid, else each '1' bit represents a pixel that is turned off
ivygatech 0:de1ab53f3480 742
ivygatech 0:de1ab53f3480 743 command[0] = (LINEPATTERN) & 0xFF;
ivygatech 0:de1ab53f3480 744 command[1] = LINEPATTERN & 0xFF;
ivygatech 0:de1ab53f3480 745
ivygatech 0:de1ab53f3480 746 command[2] = (pattern >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 747 command[3] = pattern & 0xFF;
ivygatech 0:de1ab53f3480 748
ivygatech 0:de1ab53f3480 749 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 750
ivygatech 0:de1ab53f3480 751 #if DEBUGMODE
ivygatech 0:de1ab53f3480 752 pc.printf("Line pattern completed.\n");
ivygatech 0:de1ab53f3480 753 #endif
ivygatech 0:de1ab53f3480 754 }
ivygatech 0:de1ab53f3480 755
ivygatech 0:de1ab53f3480 756 //******************************************************************************************************
ivygatech 0:de1ab53f3480 757 void uVGAIII :: transparency(char mode) { // set whether to enable the transparency
ivygatech 0:de1ab53f3480 758 char command[4] = "";
ivygatech 0:de1ab53f3480 759
ivygatech 0:de1ab53f3480 760 command[0] = (TRANSPARENCY) & 0xFF;
ivygatech 0:de1ab53f3480 761 command[1] = TRANSPARENCY & 0xFF;
ivygatech 0:de1ab53f3480 762
ivygatech 0:de1ab53f3480 763 command[2] = 0x00;
ivygatech 0:de1ab53f3480 764 command[3] = mode & 0xFF;
ivygatech 0:de1ab53f3480 765
ivygatech 0:de1ab53f3480 766 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 767
ivygatech 0:de1ab53f3480 768 #if DEBUGMODE
ivygatech 0:de1ab53f3480 769 pc.printf("Transparency completed.\n");
ivygatech 0:de1ab53f3480 770 #endif
ivygatech 0:de1ab53f3480 771 }
ivygatech 0:de1ab53f3480 772
ivygatech 0:de1ab53f3480 773 //******************************************************************************************************
ivygatech 0:de1ab53f3480 774 void uVGAIII :: outline_color(int color) { // set the outline color for rectangles and circles
ivygatech 0:de1ab53f3480 775 char command[4] = "";
ivygatech 0:de1ab53f3480 776
ivygatech 0:de1ab53f3480 777 command[0] = (OUTLINECOLOR) & 0xFF;
ivygatech 0:de1ab53f3480 778 command[1] = OUTLINECOLOR & 0xFF;
ivygatech 0:de1ab53f3480 779
ivygatech 0:de1ab53f3480 780 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 781 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 782 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 783
ivygatech 0:de1ab53f3480 784 command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 785 command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 786
ivygatech 0:de1ab53f3480 787 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 788
ivygatech 0:de1ab53f3480 789 #if DEBUGMODE
ivygatech 0:de1ab53f3480 790 pc.printf("Outline color completed.\n");
ivygatech 0:de1ab53f3480 791 #endif
ivygatech 0:de1ab53f3480 792 }
ivygatech 0:de1ab53f3480 793
ivygatech 0:de1ab53f3480 794 //******************************************************************************************************
ivygatech 0:de1ab53f3480 795 void uVGAIII :: transparent_color(int color) { // Set the color to be transparent
ivygatech 0:de1ab53f3480 796 char command[4] = "";
ivygatech 0:de1ab53f3480 797
ivygatech 0:de1ab53f3480 798 command[0] = (TRANSPCOLOR) & 0xFF;
ivygatech 0:de1ab53f3480 799 command[1] = TRANSPCOLOR & 0xFF;
ivygatech 0:de1ab53f3480 800
ivygatech 0:de1ab53f3480 801 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ivygatech 0:de1ab53f3480 802 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ivygatech 0:de1ab53f3480 803 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ivygatech 0:de1ab53f3480 804
ivygatech 0:de1ab53f3480 805 command[2] = ((red5 << 3) + (green6 >> 3)) & 0xFF;
ivygatech 0:de1ab53f3480 806 command[3] = ((green6 << 5) + (blue5 >> 0)) & 0xFF;
ivygatech 0:de1ab53f3480 807
ivygatech 0:de1ab53f3480 808 writeCOMMAND(command, 4, 3);
ivygatech 0:de1ab53f3480 809
ivygatech 0:de1ab53f3480 810 #if DEBUGMODE
ivygatech 0:de1ab53f3480 811 pc.printf("Transparent color completed.\n");
ivygatech 0:de1ab53f3480 812 #endif
ivygatech 0:de1ab53f3480 813 }
ivygatech 0:de1ab53f3480 814
ivygatech 0:de1ab53f3480 815 //******************************************************************************************************
ivygatech 0:de1ab53f3480 816 void uVGAIII :: graphics_parameters(int function, int value) { //Set graphics parameters
ivygatech 0:de1ab53f3480 817 char command[6] = "";
ivygatech 0:de1ab53f3480 818
ivygatech 0:de1ab53f3480 819 command[0] = (PARAMETERS >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 820 command[1] = PARAMETERS & 0xFF;
ivygatech 0:de1ab53f3480 821
ivygatech 0:de1ab53f3480 822 command[2] = (function >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 823 command[3] = function & 0xFF;
ivygatech 0:de1ab53f3480 824
ivygatech 0:de1ab53f3480 825 command[4] = (value >> 8) & 0xFF;
ivygatech 0:de1ab53f3480 826 command[5] = value & 0xFF;
ivygatech 0:de1ab53f3480 827
ivygatech 0:de1ab53f3480 828 writeCOMMAND(command, 6, 1);
ivygatech 0:de1ab53f3480 829
ivygatech 0:de1ab53f3480 830 #if DEBUGMODE
ivygatech 0:de1ab53f3480 831 pc.printf("Graphics parameters completed.\n");
ivygatech 0:de1ab53f3480 832 #endif
ivygatech 0:de1ab53f3480 833 }