A demo program using uVGAIII board.

Dependencies:   mbed uVGAIII

Fork of uVGAIII_demo by Jingyi Zhang

Committer:
ivygatech
Date:
Sun Mar 23 23:43:19 2014 +0000
Revision:
0:9e5b26a137ec
uVGAIII demo program

Who changed what in which revision?

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