This is the Official SmartGPU 2 processor board library to use with MBED boards!!!
Dependents: BounceBall_SG2 BounceBalls_SG2 EEPROM_SG2 Ellipses_SG2 ... more
SMARTGPU2.cpp
00001 /********************************************************* 00002 VIZIC TECHNOLOGIES. COPYRIGHT 2014. 00003 THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." 00004 VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER 00005 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED 00006 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 00007 OR NONINFRINGEMENT. IN NO EVENT SHALL VIZIC BE LIABLE FOR 00008 ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, 00009 LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF 00010 PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, 00011 ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO 00012 ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, 00013 OR OTHER SIMILAR COSTS. 00014 *********************************************************/ 00015 00016 /******************************************************** 00017 MBED SMARTGPU2 LIBRARY VERSION V2.2 00018 IMPORTANT : This library is created for the MBED Software IDE 00019 ********************************************************/ 00020 00021 #include "mbed.h" 00022 #include "SMARTGPU2.h" 00023 00024 /**********************USER MODIFABLE****************************/ 00025 /****************************************************************/ 00026 //Communication Functions(PLATFORM DEPENDENT) - MODIFY TO FIT YOUR PLATFORM IF DIFFERENT THAN MBED 00027 /****************************************************************/ 00028 //Sends a single character through the serial port(USART) 00029 #define putcharTX(data) _serialSMARTGPU2.putc(data) 00030 00031 //Returns a single character obtained from the serial port(USART) 00032 #define getcharRX() _serialSMARTGPU2.getc() 00033 00034 //Changes/Sets a new baudrate of the Host 00035 #define setBaud(newBaud) _serialSMARTGPU2.baud(newBaud) 00036 00037 //Reset pin 00038 #define resetHigh _resetPin=VCC // set the pin to 5v to end reset 00039 #define resetLow _resetPin=GND // set the pin to GND to reset 00040 00041 //MBED Exclusive - Hardware Configuration 00042 void SMARTGPU2::init(){ //configure the MBED board for SMARTGPU2 board 00043 setBaud(9600); 00044 resetLow; // set the pin to GND to reset 00045 delay(500); 00046 resetHigh; // set the pin to 5v to end reset 00047 delay(500); 00048 } 00049 /*********************END OF USER MODIFABLE**********************/ 00050 00051 /*******************DON'T MODIFY UP FROM HERE********************/ 00052 /****************************************************************/ 00053 /****************************************************************/ 00054 /****************************************************************/ 00055 //SmartGPU2 Library exclusive Functions - DO NOT MODIFY DOWN FROM HERE 00056 /****************************************************************/ 00057 /****************************************************************/ 00058 /****************************************************************/ 00059 // SMART GPU2 DEFAULT BAUD RATE: 9600bps 00060 //It should always be used like this : SMARTGPU2 lcd(TXPIN,RXPIN,RESET); for serial communication with SMARTGPU2 00061 SMARTGPU2::SMARTGPU2(PinName TXPin, PinName RXPin, PinName resetPin): _serialSMARTGPU2(TXPin,RXPin), _resetPin(resetPin){ 00062 init(); 00063 } 00064 00065 SMARTGPUREPLY SMARTGPU2::reset(){ //Physically Reset the SMARTGPU2 board 00066 resetLow; // set the pin to GND to reset 00067 delay(500); 00068 resetHigh; // set the pin to 5v to end reset 00069 delay(500); 00070 return (SMARTGPUREPLY)OK; 00071 } 00072 00073 SMARTGPUREPLY SMARTGPU2::start(){ //Init the SMARTGPU2 00074 delay(500); 00075 putcharTX('U'); 00076 delay(500); 00077 return (SMARTGPUREPLY)getcharRX(); 00078 } 00079 00080 00081 /****************************************************************/ 00082 //Master Functions 00083 /****************************************************************/ 00084 SMARTGPUREPLY SMARTGPU2::erase(){ //Erase the SMARTGPU2 screen 00085 putcharTX('M'); //Master function 00086 putcharTX('E'); 00087 return (SMARTGPUREPLY)getcharRX(); 00088 } 00089 00090 SMARTGPUREPLY SMARTGPU2::sleep(STATE state){ //Send SMARTGPU2 to sleep mode 00091 putcharTX('M'); //Master function 00092 putcharTX('Z'); 00093 putcharTX(state); 00094 return (SMARTGPUREPLY)getcharRX(); 00095 } 00096 00097 SMARTGPUREPLY SMARTGPU2::orientation(LCDORIENTATIONS side){ //Change display orientation 00098 putcharTX('M'); //Master function 00099 putcharTX('O'); 00100 putcharTX(side); 00101 return (SMARTGPUREPLY)getcharRX(); 00102 } 00103 00104 SMARTGPUREPLY SMARTGPU2::bright(unsigned char val){ //Change display brightness 00105 putcharTX('M'); //Master function 00106 putcharTX('B'); 00107 putcharTX(val); 00108 return (SMARTGPUREPLY)getcharRX(); 00109 } 00110 00111 // SMART GPU 2 DEFAULT/INITIAL BAUD RATE: 9600bps 00112 SMARTGPUREPLY SMARTGPU2::baudChange(unsigned long baud){ //Change baud rate of MBED and SMARTGPU2 board 00113 unsigned char aux; 00114 00115 putcharTX('M'); //Master function 00116 putcharTX('X'); 00117 putcharTX(baud>>24); 00118 putcharTX(baud>>16); 00119 putcharTX(baud>>8); 00120 putcharTX(baud); 00121 aux=getcharRX(); 00122 if(aux=='O'){ //if command is successfull, change baudrate, if not just leave and return 'F' 00123 delay(150); 00124 setBaud(baud); 00125 delay(200); 00126 return (SMARTGPUREPLY)getcharRX(); 00127 }else{ 00128 return (SMARTGPUREPLY)aux; 00129 } 00130 } 00131 00132 SMARTGPUREPLY SMARTGPU2::setEraseBackColour(COLOUR colour){ //Change the default screen background colour for erase function 00133 putcharTX('M'); //Master function 00134 putcharTX('C'); //Background Colour 00135 putcharTX(colour>>8); 00136 putcharTX(colour); 00137 return (SMARTGPUREPLY)getcharRX(); 00138 } 00139 00140 00141 /****************************************************************/ 00142 //Geometric Functions 00143 /****************************************************************/ 00144 SMARTGPUREPLY SMARTGPU2::putPixel(AXIS x, AXIS y, COLOUR colour){ //Draw a pixel on the screen 00145 putcharTX('G'); //Geometric function 00146 putcharTX('P'); 00147 putcharTX(x>>8); 00148 putcharTX(x); 00149 putcharTX(y>>8); 00150 putcharTX(y); 00151 putcharTX(colour>>8); 00152 putcharTX(colour); 00153 return (SMARTGPUREPLY)getcharRX(); 00154 } 00155 00156 SMARTGPUREPLY SMARTGPU2::drawLine(AXIS x1, AXIS y1, AXIS x2, AXIS y2, COLOUR colour){ //Draw a line on the screen 00157 putcharTX('G'); //Geometric function 00158 putcharTX('L'); 00159 putcharTX(x1>>8); 00160 putcharTX(x1); 00161 putcharTX(y1>>8); 00162 putcharTX(y1); 00163 putcharTX(x2>>8); 00164 putcharTX(x2); 00165 putcharTX(y2>>8); 00166 putcharTX(y2); 00167 putcharTX(colour>>8); 00168 putcharTX(colour); 00169 return (SMARTGPUREPLY)getcharRX(); 00170 } 00171 00172 SMARTGPUREPLY SMARTGPU2::drawRectangle(AXIS x1, AXIS y1, AXIS x2, AXIS y2, COLOUR colour, FILLGEOM fill){ //Draw a rectangle on the screen 00173 putcharTX('G'); //Geometric function 00174 putcharTX('R'); //Rectangle 00175 putcharTX(x1>>8); 00176 putcharTX(x1); 00177 putcharTX(y1>>8); 00178 putcharTX(y1); 00179 putcharTX(x2>>8); 00180 putcharTX(x2); 00181 putcharTX(y2>>8); 00182 putcharTX(y2); 00183 putcharTX(colour>>8); 00184 putcharTX(colour); 00185 putcharTX(fill); 00186 return (SMARTGPUREPLY)getcharRX(); 00187 } 00188 00189 SMARTGPUREPLY SMARTGPU2::drawRoundRect(AXIS x1, AXIS y1, AXIS x2, AXIS y2, RADIUS radius, COLOUR colour, FILLGEOM fill){ //Draw a rounded rectangle on the screen 00190 putcharTX('G'); //Geometric function 00191 putcharTX('O'); //Rounded Rectangle 00192 putcharTX(x1>>8); 00193 putcharTX(x1); 00194 putcharTX(y1>>8); 00195 putcharTX(y1); 00196 putcharTX(x2>>8); 00197 putcharTX(x2); 00198 putcharTX(y2>>8); 00199 putcharTX(y2); 00200 putcharTX(radius>>8); 00201 putcharTX(radius); 00202 putcharTX(colour>>8); 00203 putcharTX(colour); 00204 putcharTX(fill); 00205 return (SMARTGPUREPLY)getcharRX(); 00206 } 00207 00208 SMARTGPUREPLY SMARTGPU2::drawGradientRect(AXIS x1, AXIS y1, AXIS x2, AXIS y2, COLOUR firstColour, COLOUR lastColour, ORIENTATIONPARAMETER direction){ 00209 putcharTX('G'); //Geometric function 00210 putcharTX('G'); //Gradient rectangle function 00211 putcharTX(x1>>8); 00212 putcharTX(x1); 00213 putcharTX(y1>>8); 00214 putcharTX(y1); 00215 putcharTX(x2>>8); 00216 putcharTX(x2); 00217 putcharTX(y2>>8); 00218 putcharTX(y2); 00219 putcharTX(firstColour>>8); 00220 putcharTX(firstColour); 00221 putcharTX(lastColour>>8); 00222 putcharTX(lastColour); 00223 putcharTX(direction); 00224 return (SMARTGPUREPLY)getcharRX(); 00225 } 00226 00227 SMARTGPUREPLY SMARTGPU2::drawTriangle(AXIS x1, AXIS y1, AXIS x2, AXIS y2, AXIS x3, AXIS y3, COLOUR colour, FILLGEOM fill){ //Draw a triangle on the screen 00228 putcharTX('G'); //Geometric function 00229 putcharTX('T'); 00230 putcharTX(x1>>8); 00231 putcharTX(x1); 00232 putcharTX(y1>>8); 00233 putcharTX(y1); 00234 putcharTX(x2>>8); 00235 putcharTX(x2); 00236 putcharTX(y2>>8); 00237 putcharTX(y2); 00238 putcharTX(x3>>8); 00239 putcharTX(x3); 00240 putcharTX(y3>>8); 00241 putcharTX(y3); 00242 putcharTX(colour>>8); 00243 putcharTX(colour); 00244 putcharTX(fill); 00245 return (SMARTGPUREPLY)getcharRX(); 00246 } 00247 00248 SMARTGPUREPLY SMARTGPU2::drawArc(AXIS x, AXIS y, RADIUS radiusx, RADIUS radiusy, ARCQUADRANT quadrant, COLOUR colour, FILLGEOM fill){ //Draw an Arc on the screen 00249 putcharTX('G'); //Geometric function 00250 putcharTX('A'); //Arc 00251 putcharTX(x>>8); 00252 putcharTX(x); 00253 putcharTX(y>>8); 00254 putcharTX(y); 00255 putcharTX(radiusx>>8); 00256 putcharTX(radiusx); 00257 putcharTX(radiusy>>8); 00258 putcharTX(radiusy); 00259 putcharTX(quadrant); 00260 putcharTX(colour>>8); 00261 putcharTX(colour); 00262 putcharTX(fill); 00263 return (SMARTGPUREPLY)getcharRX(); 00264 } 00265 00266 SMARTGPUREPLY SMARTGPU2::drawCircle(AXIS x, AXIS y, RADIUS radius, COLOUR colour, FILLGEOM fill){ //Draw a circle on the screen 00267 putcharTX('G'); //Geometric function 00268 putcharTX('C'); //Circle 00269 putcharTX(x>>8); 00270 putcharTX(x); 00271 putcharTX(y>>8); 00272 putcharTX(y); 00273 putcharTX(radius>>8); 00274 putcharTX(radius); 00275 putcharTX(colour>>8); 00276 putcharTX(colour); 00277 putcharTX(fill); 00278 return (SMARTGPUREPLY)getcharRX(); 00279 } 00280 00281 SMARTGPUREPLY SMARTGPU2::drawEllipse(AXIS x, AXIS y, RADIUS radiusx, RADIUS radiusy, COLOUR colour, FILLGEOM fill){ //Draw an Ellipse on the screen 00282 putcharTX('G'); //Geometric function 00283 putcharTX('E'); //Ellipse 00284 putcharTX(x>>8); 00285 putcharTX(x); 00286 putcharTX(y>>8); 00287 putcharTX(y); 00288 putcharTX(radiusx>>8); 00289 putcharTX(radiusx); 00290 putcharTX(radiusy>>8); 00291 putcharTX(radiusy); 00292 putcharTX(colour>>8); 00293 putcharTX(colour); 00294 putcharTX(fill); 00295 return (SMARTGPUREPLY)getcharRX(); 00296 } 00297 00298 00299 /****************************************************************/ 00300 //String Functions 00301 /****************************************************************/ 00302 SMARTGPUREPLY SMARTGPU2::putLetter(AXIS x, AXIS y, char letter, AXIS *xUpdated){ //Draw a letter on the screen on X,Y coords, returns updated value of X axis in xUpdated variable 00303 unsigned int xUp = 0; //variable to store the updated position of X axis after command is called/char is printed 00304 00305 putcharTX('S'); //String Function 00306 putcharTX('L'); //Letter - a simple letter 00307 putcharTX(x>>8); 00308 putcharTX(x); 00309 putcharTX(y>>8); 00310 putcharTX(y); 00311 putcharTX(letter); 00312 00313 ((unsigned char*)&xUp)[1]=getcharRX(); 00314 ((unsigned char*)&xUp)[0]=getcharRX(); 00315 *xUpdated = xUp; 00316 return (SMARTGPUREPLY)getcharRX(); 00317 } 00318 00319 SMARTGPUREPLY SMARTGPU2::printNumber(AXIS x, AXIS y, float number){ //Prints a float number on screen 00320 putcharTX('S'); //String Function 00321 putcharTX('N'); //Number 00322 putcharTX(x>>8); 00323 putcharTX(x); 00324 putcharTX(y>>8); 00325 putcharTX(y); 00326 putcharTX(((char *)&number)[3]); 00327 putcharTX(((char *)&number)[2]); 00328 putcharTX(((char *)&number)[1]); 00329 putcharTX(((char *)&number)[0]); 00330 return (SMARTGPUREPLY)getcharRX(); 00331 } 00332 00333 SMARTGPUREPLY SMARTGPU2::string(AXIS x1, AXIS y1, AXIS x2, AXIS y2, char text[], NUMBEROFBYTES *SPB){ //Draw a string on the screen on defined Text Box coords, and stores the successfully printed bytes on SPB 00334 unsigned int counter=0, sp=0; 00335 00336 putcharTX('S'); //String Function 00337 putcharTX('S'); //String 00338 putcharTX(x1>>8); 00339 putcharTX(x1); 00340 putcharTX(y1>>8); 00341 putcharTX(y1); 00342 putcharTX(x2>>8); 00343 putcharTX(x2); 00344 putcharTX(y2>>8); 00345 putcharTX(y2); 00346 while(1){ 00347 putcharTX(text[counter]); 00348 if(text[counter]==0x00){ 00349 break; 00350 } 00351 counter++; 00352 } 00353 00354 ((unsigned char*)&sp)[1]=getcharRX(); 00355 ((unsigned char*)&sp)[0]=getcharRX(); 00356 *SPB = sp; 00357 return (SMARTGPUREPLY)getcharRX(); 00358 } 00359 00360 SMARTGPUREPLY SMARTGPU2::stringSD(AXIS x1, AXIS y1, AXIS x2, AXIS y2, NUMBEROFBYTES BS, NUMBEROFBYTES BR, FILENAME name, NUMBEROFBYTES *SPB){ //Draw a String from a text file stored on the micro SD card 00361 unsigned char counter=0, sp=0; 00362 00363 putcharTX('S'); //String function 00364 putcharTX('F'); //text File from SD 00365 putcharTX(x1>>8); 00366 putcharTX(x1); 00367 putcharTX(y1>>8); 00368 putcharTX(y1); 00369 putcharTX(x2>>8); 00370 putcharTX(x2); 00371 putcharTX(y2>>8); 00372 putcharTX(y2); 00373 putcharTX(BS>>8); 00374 putcharTX(BS); 00375 putcharTX(BR>>8); 00376 putcharTX(BR); 00377 while(1){ 00378 putcharTX(name[counter]); 00379 if(name[counter]==0x00){ 00380 break; 00381 } 00382 counter++; 00383 } 00384 00385 ((unsigned char*)&sp)[1]=getcharRX(); 00386 ((unsigned char*)&sp)[0]=getcharRX(); 00387 *SPB = sp; 00388 return (SMARTGPUREPLY)getcharRX(); 00389 } 00390 00391 SMARTGPUREPLY SMARTGPU2::setTextColour(COLOUR colour){ //Set the default text colour for letters and strings 00392 putcharTX('S'); //String Function 00393 putcharTX('C'); //Config 00394 putcharTX('T'); //Text 00395 putcharTX(colour>>8); 00396 putcharTX(colour); 00397 return (SMARTGPUREPLY)getcharRX(); 00398 } 00399 00400 SMARTGPUREPLY SMARTGPU2::setTextBackColour(COLOUR colour){ //Set the default text background colour for letters and strings 00401 putcharTX('S'); //String Function 00402 putcharTX('C'); //Config 00403 putcharTX('B'); //Background 00404 putcharTX(colour>>8); 00405 putcharTX(colour); 00406 return (SMARTGPUREPLY)getcharRX(); 00407 } 00408 00409 SMARTGPUREPLY SMARTGPU2::setTextSize(FONTSIZE size){ //Set the default text size for letters and strings 00410 putcharTX('S'); //String Function 00411 putcharTX('C'); //Config 00412 putcharTX('S'); //Size 00413 putcharTX(size); 00414 return (SMARTGPUREPLY)getcharRX(); 00415 } 00416 00417 SMARTGPUREPLY SMARTGPU2::setTextBackFill(TEXTBACKGROUNDCOLOURFILLUNFILL fillState){ //Set the default text FILL or UNFILL background letters and strings 00418 putcharTX('S'); //String Function 00419 putcharTX('C'); //Config 00420 putcharTX('F'); //Fill 00421 putcharTX(fillState); 00422 return (SMARTGPUREPLY)getcharRX(); 00423 } 00424 00425 00426 /****************************************************************/ 00427 //Image Functions 00428 /****************************************************************/ 00429 SMARTGPUREPLY SMARTGPU2::drawIcon(AXIS x1, AXIS y1, AXIS x2, AXIS y2, char icon[]){ //Send and image or icon pixel by pixel to SMARTGPU2, 16bit(2 bytes) each pixel RGB565 00430 unsigned int i,j,k=0; 00431 00432 putcharTX('I'); //Image function 00433 putcharTX('I'); //Icon image received pixel by pixel 00434 putcharTX(x1>>8); 00435 putcharTX(x1); 00436 putcharTX(y1>>8); 00437 putcharTX(y1); 00438 putcharTX(x2>>8); 00439 putcharTX(x2); 00440 putcharTX(y2>>8); 00441 putcharTX(y2); 00442 //Send icon buffer pixel by pixel 00443 for(j=0;j<=(y2-y1);j++){ 00444 for(i=0;i<=(x2-x1);i++){ 00445 putcharTX(icon[k++]); //16bit per pixel - Upper 8bits part 00446 putcharTX(icon[k++]); //16bit per pixel - Lower 8bits part 00447 } 00448 } 00449 00450 return (SMARTGPUREPLY)getcharRX(); 00451 } 00452 00453 SMARTGPUREPLY SMARTGPU2::imageBMPSD(AXIS x, AXIS y, FILENAME name){ //Draw an Image stored on the micro SD card on the screen, at X,Y top right corner coordinates 00454 unsigned char counter=0; 00455 00456 putcharTX('I'); //Image function 00457 putcharTX('B'); //BMP from SD card 00458 putcharTX(x>>8); 00459 putcharTX(x); 00460 putcharTX(y>>8); 00461 putcharTX(y); 00462 while(1){ 00463 putcharTX(name[counter]); 00464 if(name[counter]==0x00){ 00465 break; 00466 } 00467 counter++; 00468 } 00469 return (SMARTGPUREPLY)getcharRX(); 00470 } 00471 00472 SMARTGPUREPLY SMARTGPU2::imageJPGSD(AXIS x, AXIS y, JPGSCALEFACTOR scaleFactor, FILENAME name){ //Draw an Image stored on the micro SD card on the screen, at X,Y top right corner coordinates 00473 unsigned char counter=0; 00474 00475 putcharTX('I'); //Image function 00476 putcharTX('J'); //JPG from SD card 00477 putcharTX(x>>8); 00478 putcharTX(x); 00479 putcharTX(y>>8); 00480 putcharTX(y); 00481 putcharTX(scaleFactor); 00482 while(1){ 00483 putcharTX(name[counter]); 00484 if(name[counter]==0x00){ 00485 break; 00486 } 00487 counter++; 00488 } 00489 return (SMARTGPUREPLY)getcharRX(); 00490 } 00491 00492 //Reads a defined x1,x1,x2,y2 box of the SmartGPU display, and returns it pixel by pixel in RGB 888 format, 1 byte per colour, 3 bytes per pixel 00493 SMARTGPUREPLY SMARTGPU2::getImageFromMemory(AXIS x1, AXIS y1, AXIS x2, AXIS y2, char buffer[]){ //Read the internal memory of the SMARTGPU2, This command returns 24bit pixels (3 bytes) 00494 unsigned int i,j,k=0; 00495 00496 putcharTX('I'); //Image function 00497 putcharTX('M'); //from SmartGPU internal Display Memory 00498 putcharTX(x1>>8); 00499 putcharTX(x1); 00500 putcharTX(y1>>8); 00501 putcharTX(y1); 00502 putcharTX(x2>>8); 00503 putcharTX(x2); 00504 putcharTX(y2>>8); 00505 putcharTX(y2); 00506 //receive all the pixels 00507 for(j=0;j<=(y2-y1);j++){ 00508 for(i=0;i<=(x2-x1);i++){ 00509 buffer[k++]=getcharRX(); //Red 00510 buffer[k++]=getcharRX(); //Green 00511 buffer[k++]=getcharRX(); //Blue 00512 } 00513 } 00514 return (SMARTGPUREPLY)getcharRX(); 00515 } 00516 00517 //takes a screenshot of SmartGPU2 display and stores it in the microSD card with consecutive names Screenshot000.bmp, Screenshot001.bmp, etc 00518 SMARTGPUREPLY SMARTGPU2::screenshot(){ 00519 putcharTX('I'); //Image function 00520 putcharTX('S'); //Screenshot 00521 return (SMARTGPUREPLY)getcharRX(); 00522 } 00523 00524 00525 /****************************************************************/ 00526 //Video Functions 00527 /****************************************************************/ 00528 //Allocates a ".vid" video stored on the micro SD card with the given filename name 00529 SMARTGPUREPLY SMARTGPU2::allocateVideoSD(FILENAME name, VIDDATA *videoData){ 00530 unsigned int wid=0, hei=0, fra=0, tot=0; 00531 unsigned char counter=0; 00532 00533 putcharTX('V'); //Video function 00534 putcharTX('A'); //Allocate 00535 while(1){ //Send Video Name 00536 putcharTX(name[counter]); 00537 if(name[counter]==0x00){ 00538 break; 00539 } 00540 counter++; 00541 } 00542 00543 ((unsigned char *) &wid)[1]=getcharRX(); //get video width 00544 ((unsigned char *) &wid)[0]=getcharRX(); 00545 ((unsigned char *) &hei)[1]=getcharRX(); //get video height 00546 ((unsigned char *) &hei)[0]=getcharRX(); 00547 ((unsigned char *) &fra)[1]=getcharRX(); //get video frames per second 00548 ((unsigned char *) &fra)[0]=getcharRX(); 00549 ((unsigned char *) &tot)[1]=getcharRX(); //get video total frames 00550 ((unsigned char *) &tot)[0]=getcharRX(); 00551 videoData->width = wid; 00552 videoData->height = hei; 00553 videoData->framesPerSec = fra; 00554 videoData->totalFrames = tot; 00555 return (SMARTGPUREPLY)getcharRX(); 00556 } 00557 00558 //deAllocates a ".vid" video previously allocated, must be called when no more calls to video will be done 00559 SMARTGPUREPLY SMARTGPU2::freeVideoSD(){ 00560 putcharTX('V'); //Video function 00561 putcharTX('D'); //DeAllocate 00562 return (SMARTGPUREPLY)getcharRX(); 00563 } 00564 00565 //Sets a video start Frame position, this function can be used to FastForward video or Rewing, returns 'F' if invalid position 00566 SMARTGPUREPLY SMARTGPU2::setFrameVideoSD(unsigned int startFrame){ 00567 putcharTX('V'); //Video function 00568 putcharTX('F'); //set Video Frame 00569 putcharTX(startFrame>>8); 00570 putcharTX(startFrame); 00571 return (SMARTGPUREPLY)getcharRX(); 00572 } 00573 00574 //Plays a previously allocated ".vid" video stored on mSD card on X,Y top right corner coordinates, starting from current Video Frame and plays framesToPlay 00575 SMARTGPUREPLY SMARTGPU2::playVideoSD(AXIS x, AXIS y, unsigned int framesToPlay){ //frames to play from current video Frame 00576 putcharTX('V'); //Video function 00577 putcharTX('P'); //Play 00578 putcharTX(x>>8); 00579 putcharTX(x); 00580 putcharTX(y>>8); 00581 putcharTX(y); 00582 putcharTX(framesToPlay>>8); 00583 putcharTX(framesToPlay); 00584 return (SMARTGPUREPLY)getcharRX(); 00585 } 00586 00587 00588 /****************************************************************/ 00589 //Audio Functions 00590 /****************************************************************/ 00591 SMARTGPUREPLY SMARTGPU2::initDACAudio(STATE state){ 00592 putcharTX('A'); //Audio Function 00593 putcharTX('I'); //Init - Deinit DACs 00594 putcharTX(state); //Enable/Disable 00595 return (SMARTGPUREPLY)getcharRX(); 00596 } 00597 00598 SMARTGPUREPLY SMARTGPU2::audioBoost(STATE state){ 00599 putcharTX('A'); //Audio Function 00600 putcharTX('B'); //Boost 00601 putcharTX(state); //Enable/Disable 00602 return (SMARTGPUREPLY)getcharRX(); 00603 } 00604 00605 SMARTGPUREPLY SMARTGPU2::getWAVPlayState(STATE* state){ //returns ENABLE or DISABLE if any file is playing 00606 putcharTX('A'); //Audio Function 00607 putcharTX('G'); //Get playing File status 00608 *state = (STATE)getcharRX(); //Get state 00609 return (SMARTGPUREPLY)getcharRX(); 00610 } 00611 00612 SMARTGPUREPLY SMARTGPU2::playWAVFile(FILENAME name, unsigned int* seconds){ //returns in "seconds" variable the song duration in seconds 00613 unsigned int counter=0; 00614 unsigned int secs=0; 00615 00616 putcharTX('A'); //Audio Function 00617 putcharTX('P'); //Play WAV file 00618 while(1){ //Send file name 00619 putcharTX(name[counter]); 00620 if(name[counter]==0x00){ 00621 break; 00622 } 00623 counter++; 00624 } 00625 00626 ((unsigned char *) &secs)[1]=getcharRX(); 00627 ((unsigned char *) &secs)[0]=getcharRX(); 00628 *seconds = secs; 00629 return (SMARTGPUREPLY)getcharRX(); 00630 } 00631 00632 SMARTGPUREPLY SMARTGPU2::pauseWAVFile(){ //pauses a playing file, returns 'F' if no file is playing 00633 putcharTX('A'); //Audio Function 00634 putcharTX('W'); //Pause file 00635 return (SMARTGPUREPLY)getcharRX(); 00636 } 00637 00638 SMARTGPUREPLY SMARTGPU2::stopWAVFile(){ 00639 putcharTX('A'); //Audio Function 00640 putcharTX('S'); //Stop playing file 00641 return (SMARTGPUREPLY)getcharRX(); 00642 } 00643 00644 SMARTGPUREPLY SMARTGPU2::advanceWAVFile(unsigned int seconds){ //advance to the file to the given seconds parameter 00645 putcharTX('A'); //Audio Function 00646 putcharTX('A'); //Advance file 00647 putcharTX(seconds>>8); 00648 putcharTX(seconds); 00649 return (SMARTGPUREPLY)getcharRX(); //returns 'F' if no file is playing or if no seconds position exists, in this case file will stop playing 00650 } 00651 00652 SMARTGPUREPLY SMARTGPU2::setVolumeWAV(unsigned char volume){ 00653 putcharTX('A'); //Audio Function 00654 putcharTX('V'); //Volume 00655 putcharTX(volume); 00656 return (SMARTGPUREPLY)getcharRX(); 00657 } 00658 00659 00660 /****************************************************************/ 00661 //Real Time Clock Functions 00662 /****************************************************************/ 00663 SMARTGPUREPLY SMARTGPU2::setupRTC(STATE *state){ 00664 putcharTX('R'); //RTC function - Real Time Clock 00665 putcharTX('S'); //Setup RTC 00666 *state = (STATE)getcharRX(); //Get state 00667 return (SMARTGPUREPLY)getcharRX(); 00668 } 00669 00670 SMARTGPUREPLY SMARTGPU2::getRTCTimeDate(TIME *timeDate){ 00671 unsigned int counter=0; 00672 00673 putcharTX('R'); //RTC function - Real Time Clock 00674 putcharTX('P'); //Parameters 00675 putcharTX('G'); //Get 00676 timeDate->hour = getcharRX(); //hour 00677 timeDate->minute = getcharRX(); //min 00678 timeDate->second = getcharRX(); //sec 00679 timeDate->day = getcharRX(); //day 00680 timeDate->month = getcharRX(); //month 00681 ((unsigned char*)&counter)[1] = getcharRX(); //year upper 00682 ((unsigned char*)&counter)[0] = getcharRX(); //year lower 00683 timeDate->year = counter; //year 00684 return (SMARTGPUREPLY)getcharRX(); 00685 } 00686 00687 SMARTGPUREPLY SMARTGPU2::setRTCTimeDate(TIME *timeDate){ 00688 putcharTX('R'); //RTC function - Real Time Clock 00689 putcharTX('P'); //Parameters 00690 putcharTX('S'); //Set 00691 putcharTX(timeDate->hour); //hour 00692 putcharTX(timeDate->minute); //min 00693 putcharTX(timeDate->second); //sec 00694 putcharTX(timeDate->day); //day 00695 putcharTX(timeDate->month); //month 00696 putcharTX(timeDate->year>>8);//year upper 00697 putcharTX(timeDate->year); //year lower 00698 return (SMARTGPUREPLY)getcharRX(); 00699 } 00700 00701 00702 /****************************************************************/ 00703 //Objects Functions 00704 /****************************************************************/ 00705 SMARTGPUREPLY SMARTGPU2::objButton(AXIS x1, AXIS y1, AXIS x2, AXIS y2, ACTIVE activeState, char text[]){ 00706 unsigned int counter=0; 00707 00708 putcharTX('O'); //Object function 00709 putcharTX('B'); //Button 00710 putcharTX(x1>>8); 00711 putcharTX(x1); 00712 putcharTX(y1>>8); 00713 putcharTX(y1); 00714 putcharTX(x2>>8); 00715 putcharTX(x2); 00716 putcharTX(y2>>8); 00717 putcharTX(y2); 00718 putcharTX(activeState); 00719 while(1){ //Send button text 00720 putcharTX(text[counter]); 00721 if(text[counter]==0x00){ 00722 break; 00723 } 00724 counter++; 00725 } 00726 return (SMARTGPUREPLY)getcharRX(); 00727 } 00728 00729 SMARTGPUREPLY SMARTGPU2::objSwitch(AXIS x, AXIS y, unsigned int switchSize, ACTIVE activeState){ 00730 putcharTX('O'); //Object function 00731 putcharTX('T'); //Switch 00732 putcharTX(x>>8); 00733 putcharTX(x); 00734 putcharTX(y>>8); 00735 putcharTX(y); 00736 putcharTX(switchSize>>8); 00737 putcharTX(switchSize); 00738 putcharTX(activeState); 00739 return (SMARTGPUREPLY)getcharRX(); 00740 } 00741 00742 SMARTGPUREPLY SMARTGPU2::objCheckbox(AXIS x, AXIS y, unsigned int checkboxSize, ACTIVE activeState){ 00743 putcharTX('O'); //Object function 00744 putcharTX('C'); //Checkbox 00745 putcharTX(x>>8); 00746 putcharTX(x); 00747 putcharTX(y>>8); 00748 putcharTX(y); 00749 putcharTX(checkboxSize>>8); 00750 putcharTX(checkboxSize); 00751 putcharTX(activeState); 00752 return (SMARTGPUREPLY)getcharRX(); 00753 } 00754 00755 SMARTGPUREPLY SMARTGPU2::objProgressBar(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char progress){ 00756 putcharTX('O'); //Object function 00757 putcharTX('P'); //Progress Bar 00758 putcharTX(x1>>8); 00759 putcharTX(x1); 00760 putcharTX(y1>>8); 00761 putcharTX(y1); 00762 putcharTX(x2>>8); 00763 putcharTX(x2); 00764 putcharTX(y2>>8); 00765 putcharTX(y2); 00766 putcharTX(progress); 00767 return (SMARTGPUREPLY)getcharRX(); 00768 } 00769 00770 SMARTGPUREPLY SMARTGPU2::objSlider(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char position, unsigned char divisions, ORIENTATIONPARAMETER sliderOrientation){ 00771 putcharTX('O'); //Object function 00772 putcharTX('L'); //Slider 00773 putcharTX(x1>>8); 00774 putcharTX(x1); 00775 putcharTX(y1>>8); 00776 putcharTX(y1); 00777 putcharTX(x2>>8); 00778 putcharTX(x2); 00779 putcharTX(y2>>8); 00780 putcharTX(y2); 00781 putcharTX(position); 00782 putcharTX(divisions); 00783 putcharTX(sliderOrientation); 00784 return (SMARTGPUREPLY)getcharRX(); 00785 } 00786 00787 SMARTGPUREPLY SMARTGPU2::objScrollBar(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char position, unsigned char divisions, ORIENTATIONPARAMETER scrollBarOrientation, ACTIVE activeState){ 00788 putcharTX('O'); //Object function 00789 putcharTX('S'); //Scroll bar 00790 putcharTX(x1>>8); 00791 putcharTX(x1); 00792 putcharTX(y1>>8); 00793 putcharTX(y1); 00794 putcharTX(x2>>8); 00795 putcharTX(x2); 00796 putcharTX(y2>>8); 00797 putcharTX(y2); 00798 putcharTX(position); 00799 putcharTX(divisions); 00800 putcharTX(scrollBarOrientation); 00801 putcharTX(activeState); 00802 return (SMARTGPUREPLY)getcharRX(); 00803 } 00804 00805 SMARTGPUREPLY SMARTGPU2::objWindow(AXIS x1, AXIS y1, AXIS x2, AXIS y2, FONTSIZE textSize, WINDOWTYPE winType, char text[]){ 00806 unsigned int counter=0; 00807 00808 putcharTX('O'); //Object function 00809 putcharTX('W'); //Window 00810 putcharTX(x1>>8); 00811 putcharTX(x1); 00812 putcharTX(y1>>8); 00813 putcharTX(y1); 00814 putcharTX(x2>>8); 00815 putcharTX(x2); 00816 putcharTX(y2>>8); 00817 putcharTX(y2); 00818 putcharTX(textSize); 00819 putcharTX(winType); 00820 while(1){ //Send button text 00821 putcharTX(text[counter]); 00822 if(text[counter]==0x00){ 00823 break; 00824 } 00825 counter++; 00826 } 00827 return (SMARTGPUREPLY)getcharRX(); 00828 } 00829 00830 00831 /****************************************************************/ 00832 //EEPROM-FLASH Functions - Refer to "smartGPU2 Command Set" to learn about READ-WRITE procedure. 00833 /****************************************************************/ 00834 SMARTGPUREPLY SMARTGPU2::initClearEEPROMBuff(){ 00835 putcharTX('E'); //EEPROM function 00836 putcharTX('I'); //Init/Clear EEPROM Buffer 00837 return (SMARTGPUREPLY)getcharRX(); 00838 } 00839 00840 SMARTGPUREPLY SMARTGPU2::readEEPROMBuff(char buffer[], ADDRESS EEPROMbufferAddress, NUMBEROFBYTES bytesToRead, NUMBEROFBYTES *SRB){ 00841 unsigned int x=0, sr=0; 00842 00843 putcharTX('E'); //EEPROM function 00844 putcharTX('R'); //Read N bytes from EEPROM buffer to received buffer[] 00845 putcharTX(EEPROMbufferAddress>>8); //address to start reading from EEPROM buffer 00846 putcharTX(EEPROMbufferAddress); 00847 putcharTX(bytesToRead>>8); 00848 putcharTX(bytesToRead); 00849 00850 for(x=0; x<bytesToRead; x++){ 00851 buffer[x]=getcharRX(); 00852 } 00853 ((unsigned char*)&sr)[1]=getcharRX(); 00854 ((unsigned char*)&sr)[0]=getcharRX(); 00855 *SRB = sr; //store succesfully read bytes 00856 return (SMARTGPUREPLY)getcharRX(); 00857 } 00858 00859 SMARTGPUREPLY SMARTGPU2::writeEEPROMBuff(char buffer[], ADDRESS EEPROMbufferAddress, NUMBEROFBYTES bytesToWrite, NUMBEROFBYTES *SWB){ 00860 unsigned int x=0, sw=0; 00861 00862 putcharTX('E'); //EEPROM function 00863 putcharTX('W'); //Write N bytes to EEPROM buffer from received buffer[] 00864 putcharTX(EEPROMbufferAddress>>8); //address to start writting to EEPROM buffer 00865 putcharTX(EEPROMbufferAddress); 00866 putcharTX(bytesToWrite>>8); 00867 putcharTX(bytesToWrite); 00868 for(x=0; x<bytesToWrite; x++){ 00869 putcharTX(buffer[x]); 00870 } 00871 00872 ((unsigned char*)&sw)[1]=getcharRX(); 00873 ((unsigned char*)&sw)[0]=getcharRX(); 00874 *SWB = sw; //store succesfully written bytes 00875 return (SMARTGPUREPLY)getcharRX(); 00876 } 00877 00878 SMARTGPUREPLY SMARTGPU2::saveBuffToEEPROMPage(EEPROMPAGE page){ 00879 putcharTX('E'); //EEPROM function 00880 putcharTX('S'); //Save EEPROM buffer contents to received EEPROM page# 00881 putcharTX(page); 00882 return (SMARTGPUREPLY)getcharRX(); 00883 } 00884 00885 SMARTGPUREPLY SMARTGPU2::fillBuffFromEEPROMPage(EEPROMPAGE page){ 00886 putcharTX('E'); //EEPROM function 00887 putcharTX('F'); //Fill(copy) EEPROM buffer with received EEPROM page# contents 00888 putcharTX(page); 00889 return (SMARTGPUREPLY)getcharRX(); 00890 } 00891 00892 SMARTGPUREPLY SMARTGPU2::compBuffToEEPROMPage(EEPROMPAGE page, unsigned char *result){ 00893 putcharTX('E'); //EEPROM function 00894 putcharTX('C'); //Compare EEPROM buffer contents with received EEPROM page# 00895 putcharTX(page); 00896 *result = getcharRX(); 00897 return (SMARTGPUREPLY)getcharRX(); 00898 } 00899 00900 SMARTGPUREPLY SMARTGPU2::eraseEEPROMPage(EEPROMPAGE page){ 00901 putcharTX('E'); //EEPROM function 00902 putcharTX('E'); //Erase received EEPROM page# 00903 putcharTX(page); 00904 return (SMARTGPUREPLY)getcharRX(); 00905 } 00906 00907 00908 /****************************************************************/ 00909 //Touch Functions 00910 //Those next Touch Functions return valid or invalid touch coordinates status(TOUCHREPLY) instead of ACK 'O' or NAK 'F'(SMARTGPUREPLY) 00911 /****************************************************************/ 00912 TOUCHREPLY SMARTGPU2::touchScreen(POINT *point){ //Ask for a touch on the screen, if return==VALID, touch coords are valid and stored on xAxis and yAxis 00913 unsigned int x=0,y=0; 00914 putcharTX('T'); //Touch Function 00915 putcharTX('S'); //Screen touch 00916 ((unsigned char *) &x)[1]=getcharRX(); 00917 ((unsigned char *) &x)[0]=getcharRX(); 00918 ((unsigned char *) &y)[1]=getcharRX(); 00919 ((unsigned char *) &y)[0]=getcharRX(); 00920 if(getcharRX()=='O'){ //if touch coordinates are valid, assign values 00921 point->x=x; 00922 point->y=y; 00923 return (TOUCHREPLY)VALID; 00924 } 00925 return (TOUCHREPLY)INVALID; 00926 } 00927 00928 #ifdef LCD320X240 //define function only for the SmartGPU2 LCD320x240 2.4" is selected, as it is the only board with touch icons 00929 TOUCHREPLY SMARTGPU2::touchIcon(ICON *icon){ //Ask for a touch on the icons of the screen, if return==VALID, icon first letter is stored on icon 00930 putcharTX('T'); //Touch Function 00931 putcharTX('I'); //Icons touch 00932 *icon = (ICON)getcharRX(); 00933 if(getcharRX()=='O'){ //if touch coordinates are valid 00934 return (TOUCHREPLY)VALID; 00935 } 00936 return (TOUCHREPLY)INVALID; 00937 } 00938 #elif defined LCD320X240SH //define function only for the SmartGPU2 LCD320x240SH 2.4" is selected, as it is the only board with touch icons 00939 00940 TOUCHREPLY SMARTGPU2::touchIcon(ICON *icon){ //Ask for a touch on the icons of the screen, if return==VALID, icon first letter is stored on icon 00941 putcharTX('T'); //Touch Function 00942 putcharTX('I'); //Icons touch 00943 *icon = (ICON)getcharRX(); 00944 if(getcharRX()=='O'){ //if touch coordinates are valid 00945 return (TOUCHREPLY)VALID; 00946 } 00947 return (TOUCHREPLY)INVALID; 00948 } 00949 #endif 00950 00951 00952 /****************************************************************/ 00953 //SD FAT management Functions 00954 //Those next SDF - SD Functions return file execution status(FILERESULT) instead of ACK 'O' or NAK 'F'(SMARTGPUREPLY) 00955 /****************************************************************/ 00956 FILERESULT SMARTGPU2::SDFgetList(unsigned int *numOfDirs, unsigned int *numOfFiles){ //get number of dirs and files 00957 FILERESULT res; 00958 unsigned int dirs=0, files=0; 00959 00960 putcharTX('F'); //File function - memory card file management 00961 putcharTX('L'); //List/count dirs and files 00962 00963 ((unsigned char *) &dirs)[1]= getcharRX(); //Get Upper part 00964 ((unsigned char *) &dirs)[0]= getcharRX(); //Get Lower part 00965 ((unsigned char *) &files)[1]= getcharRX(); //Get Upper part 00966 ((unsigned char *) &files)[0]= getcharRX(); //Get Lower part 00967 *numOfDirs=dirs; 00968 *numOfFiles=files; 00969 res = (FILERESULT)getcharRX(); //Get SD file execution status 00970 getcharRX(); //Discard 'O' or 'F' 00971 return res; //Return SD file execution status 00972 } 00973 00974 FILERESULT SMARTGPU2::SDFgetDirName(ITEMNUMBER itemNumber, FILENAME name){ //searches for the "itemNumber" on the SD current folder and updates the buffer with the Dir name ended with NULL character 00975 FILERESULT res; 00976 unsigned int i=0; 00977 00978 putcharTX('F'); //File function - memory card file management 00979 putcharTX('G'); //Get name of given item file number 00980 putcharTX('D'); //Directory 00981 putcharTX(itemNumber>>8); //Send Upper part of itemNumber 00982 putcharTX(itemNumber); //Send Lower part of itemNumber 00983 00984 while(1){ 00985 name[i]=getcharRX(); 00986 if(name[i]==0x00){ //if we find NULL character, means end of name 00987 break; 00988 } 00989 i++; 00990 } 00991 res = (FILERESULT)getcharRX(); //Get SD file execution status 00992 getcharRX(); //Discard 'O' or 'F' 00993 return res; //Return SD file execution status 00994 } 00995 00996 FILERESULT SMARTGPU2::SDFgetFileName(ITEMNUMBER itemNumber, FILENAME name){ //searches for the "itemNumber" on the SD current folder and updates the buffer with the File name ended with NULL character 00997 FILERESULT res; 00998 unsigned int i=0; 00999 01000 putcharTX('F'); //File function - memory card file management 01001 putcharTX('G'); //Get name of given item file number 01002 putcharTX('F'); //File 01003 putcharTX(itemNumber>>8); //Send Upper part of itemNumber 01004 putcharTX(itemNumber); //Send Lower part of itemNumber 01005 01006 while(1){ 01007 name[i]=getcharRX(); 01008 if(name[i]==0x00){ //if we find NULL character, means end of name 01009 break; 01010 } 01011 i++; 01012 } 01013 res = (FILERESULT)getcharRX(); //Get SD file execution status 01014 getcharRX(); //Discard 'O' or 'F' 01015 return res; //Return SD file execution status 01016 } 01017 01018 FILERESULT SMARTGPU2::SDFgetDirPath(char path[]){ //obtains current dir path and stores on path[] buffer 01019 FILERESULT res; 01020 unsigned int i=0; 01021 putcharTX('F'); //File function - memory card file management 01022 putcharTX('H'); //Get current Dir Path 01023 01024 while(1){ 01025 path[i]=getcharRX(); 01026 if(path[i]==0x00){ //if we find NULL character, means end of path 01027 break; 01028 } 01029 i++; 01030 } 01031 res = (FILERESULT)getcharRX(); //Get SD file execution status 01032 getcharRX(); //Discard 'O' or 'F' 01033 return res; //Return SD file execution status 01034 } 01035 01036 FILERESULT SMARTGPU2::SDFnewDir(FILENAME name){ //create a new Directory, fails if already exist 01037 FILERESULT res; 01038 unsigned int counter=0; 01039 01040 putcharTX('F'); //File function - memory card file management 01041 putcharTX('N'); //New 01042 putcharTX('D'); //Directory/Folder 01043 while(1){ 01044 putcharTX(name[counter]); 01045 if(name[counter]==0x00){ 01046 break; 01047 } 01048 counter++; 01049 } 01050 01051 res = (FILERESULT)getcharRX(); //Get SD file execution status 01052 getcharRX(); //Discard 'O' or 'F' 01053 return res; //Return SD file execution status 01054 } 01055 01056 FILERESULT SMARTGPU2::SDFnewFile(FILENAME name){ //create a new File, fails if already exist 01057 FILERESULT res; 01058 unsigned int counter=0; 01059 01060 putcharTX('F'); //File function - memory card file management 01061 putcharTX('N'); //New 01062 putcharTX('F'); //File 01063 while(1){ 01064 putcharTX(name[counter]); 01065 if(name[counter]==0x00){ 01066 break; 01067 } 01068 counter++; 01069 } 01070 01071 res = (FILERESULT)getcharRX(); //Get SD file execution status 01072 getcharRX(); //Discard 'O' or 'F' 01073 return res; //Return SD file execution status 01074 } 01075 01076 FILERESULT SMARTGPU2::SDFopenDir(FILENAME name){ //opens an existing Dir 01077 FILERESULT res; 01078 unsigned int counter=0; 01079 01080 putcharTX('F'); //File function - memory card file management 01081 putcharTX('D'); //Open Dir 01082 while(1){ 01083 putcharTX(name[counter]); 01084 if(name[counter]==0x00){ 01085 break; 01086 } 01087 counter++; 01088 } 01089 01090 res = (FILERESULT)getcharRX(); //Get SD file execution status 01091 getcharRX(); //Discard 'O' or 'F' 01092 return res; //Return SD file execution status 01093 } 01094 01095 FILERESULT SMARTGPU2::SDFopenFile(FILENAME name, OPENMODE mode, WORKSPACEBLOCK objectWorkspaceNo){ //opens an existing file in READONLY, WRITEONLY or READWRITE mode on the received object # workspace 01096 FILERESULT res; 01097 unsigned int counter=0; 01098 01099 putcharTX('F'); //File function - memory card file management 01100 putcharTX('O'); //Open file 01101 putcharTX(objectWorkspaceNo); //object workspace number to allocate open file 0-4 01102 putcharTX(mode); //Mode - READONLY,WRITEONLY,READWRITE 01103 while(1){ 01104 putcharTX(name[counter]); 01105 if(name[counter]==0x00){ 01106 break; 01107 } 01108 counter++; 01109 } 01110 01111 res = (FILERESULT)getcharRX(); //Get SD file execution status 01112 getcharRX(); //Discard 'O' or 'F' 01113 return res; //Return SD file execution status 01114 } 01115 01116 FILERESULT SMARTGPU2::SDFcloseFile(WORKSPACEBLOCK objectWorkspaceNo){ //close and save file object # workspace 01117 FILERESULT res; 01118 01119 putcharTX('F'); //File function - memory card file management 01120 putcharTX('C'); //Close File 01121 putcharTX(objectWorkspaceNo); //object workspace number to close 0-4 01122 01123 res = (FILERESULT)getcharRX(); //Get SD file execution status 01124 getcharRX(); //Discard 'O' or 'F' 01125 return res; //Return SD file execution status 01126 } 01127 01128 FILERESULT SMARTGPU2::SDFsaveFile(WORKSPACEBLOCK objectWorkspaceNo){ //sync/save file object # workspace 01129 FILERESULT res; 01130 01131 putcharTX('F'); //File function - memory card file management 01132 putcharTX('S'); //Save/Sync file - Save changes on file 01133 putcharTX(objectWorkspaceNo); //object workspace number to save changes 0-4 01134 01135 res = (FILERESULT)getcharRX(); //Get SD file execution status 01136 getcharRX(); //Discard 'O' or 'F' 01137 return res; //Return SD file execution status 01138 } 01139 01140 FILERESULT SMARTGPU2::SDFsetFilePointer(POINTERPOSITION pointerPosition, WORKSPACEBLOCK objectWorkspaceNo){ // set/move file pointer of file object # workspace 01141 FILERESULT res; 01142 01143 putcharTX('F'); //File function - memory card file management 01144 putcharTX('P'); //Pointer position 01145 putcharTX(objectWorkspaceNo); //object workspace number to move pointer 0-4 01146 putcharTX('S'); //Set 01147 putcharTX(pointerPosition>>24); 01148 putcharTX(pointerPosition>>16); 01149 putcharTX(pointerPosition>>8); 01150 putcharTX(pointerPosition); 01151 01152 res = (FILERESULT)getcharRX(); //Get SD file execution status 01153 getcharRX(); //Discard 'O' or 'F' 01154 return res; //Return SD file execution status 01155 } 01156 01157 FILERESULT SMARTGPU2::SDFgetFilePointer(POINTERPOSITION *pointerPosition, WORKSPACEBLOCK objectWorkspaceNo){ // get file pointer of file object # workspace 01158 FILERESULT res; 01159 unsigned long pos = 0; 01160 01161 putcharTX('F'); //File function - memory card file management 01162 putcharTX('P'); //Pointer position 01163 putcharTX(objectWorkspaceNo); //object workspace number to get pointer 0-4 01164 putcharTX('G'); //Get 01165 01166 ((unsigned char *) &pos)[3]=getcharRX(); 01167 ((unsigned char *) &pos)[2]=getcharRX(); 01168 ((unsigned char *) &pos)[1]=getcharRX(); 01169 ((unsigned char *) &pos)[0]=getcharRX(); 01170 *pointerPosition =pos; 01171 res = (FILERESULT)getcharRX(); //Get SD file execution status 01172 getcharRX(); //Discard 'O' or 'F' 01173 return res; //Return SD file execution status 01174 } 01175 01176 FILERESULT SMARTGPU2::SDFreadFile(char buffer[], NUMBEROFBYTES BTR, NUMBEROFBYTES *SRB, WORKSPACEBLOCK objectWorkspaceNo){ //Bytes to Read, Succesfully Read Bytes, file object # to read bytes from 01177 FILERESULT res; 01178 unsigned int x=0, sr=0; 01179 01180 putcharTX('F'); //File function - memory card file management 01181 putcharTX('R'); //Read file 01182 putcharTX(objectWorkspaceNo); //object workspace number to read 0-4 01183 putcharTX(BTR>>8); 01184 putcharTX(BTR); 01185 01186 for(x=0;x<BTR;x++){ 01187 buffer[x]=getcharRX(); 01188 } 01189 ((unsigned char*)&sr)[1]=getcharRX(); 01190 ((unsigned char*)&sr)[0]=getcharRX(); 01191 *SRB = sr; //store succesfully read bytes 01192 res = (FILERESULT)getcharRX(); //Get SD file execution status 01193 getcharRX(); //Discard 'O' or 'F' 01194 return res; //Return SD file execution status 01195 } 01196 01197 FILERESULT SMARTGPU2::SDFwriteFile(char buffer[], NUMBEROFBYTES BTW, NUMBEROFBYTES *SWB, WORKSPACEBLOCK objectWorkspaceNo){ //Bytes to Write, Succesfully Written Bytes, file object # to write bytes 01198 FILERESULT res; 01199 unsigned int x=0, sw=0; 01200 01201 putcharTX('F'); //File function - memory card file management 01202 putcharTX('W'); //Write file 01203 putcharTX(objectWorkspaceNo); //object workspace number to write bytes 0-4 01204 putcharTX(BTW>>8); 01205 putcharTX(BTW); 01206 for(x=0;x<BTW;x++){ 01207 putcharTX(buffer[x]); 01208 } 01209 01210 ((unsigned char*)&sw)[1]=getcharRX(); 01211 ((unsigned char*)&sw)[0]=getcharRX(); 01212 *SWB = sw; //store succesfully written bytes 01213 res = (FILERESULT)getcharRX(); //Get SD file execution status 01214 getcharRX(); //Discard 'O' or 'F' 01215 return res; //Return SD file execution status 01216 } 01217 01218 FILERESULT SMARTGPU2::SDFtestFileError(WORKSPACEBLOCK objectWorkspaceNo){ //test for an error on file # workspace 01219 FILERESULT res; 01220 01221 putcharTX('F'); //File function - memory card file management 01222 putcharTX('Q'); //Test 01223 putcharTX(objectWorkspaceNo); //object workspace number to write bytes 0-4 01224 putcharTX('R'); //Test Error 01225 01226 res = (FILERESULT)getcharRX(); //Get SD file execution status 01227 getcharRX(); //Discard 'O' or 'F' 01228 return res; //Return SD file execution status 01229 } 01230 01231 FILERESULT SMARTGPU2::SDFtestFileEnd(WORKSPACEBLOCK objectWorkspaceNo){ //test for an error on file # workspace 01232 FILERESULT res; 01233 01234 putcharTX('F'); //File function - memory card file management 01235 putcharTX('Q'); //Test 01236 putcharTX(objectWorkspaceNo); //object workspace number to write bytes 0-4 01237 putcharTX('E'); //Test End of File 01238 01239 res = (FILERESULT)getcharRX(); //Get SD file execution status 01240 getcharRX(); //Discard 'O' or 'F' 01241 return res; //Return SD file execution status 01242 } 01243 01244 FILERESULT SMARTGPU2::SDFtruncateFile(WORKSPACEBLOCK objectWorkspaceNo){ //truncates the file size to the current file read/write pointer of the file # workspace 01245 FILERESULT res; 01246 01247 putcharTX('F'); //File function - memory card file management 01248 putcharTX('V'); //Truncate 01249 putcharTX(objectWorkspaceNo); //object workspace number 0-4 to truncate on current pointerPosition 01250 01251 res = (FILERESULT)getcharRX(); //Get SD file execution status 01252 getcharRX(); //Discard 'O' or 'F' 01253 return res; //Return SD file execution status 01254 } 01255 01256 FILERESULT SMARTGPU2::SDFeraseDirFile(FILENAME name){ //Erases an existing Dir or File 01257 FILERESULT res; 01258 unsigned int counter=0; 01259 01260 putcharTX('F'); //File function - memory card file management 01261 putcharTX('E'); //Erase Dir File 01262 putcharTX('O'); //Unlock Erase Protection 01263 while(1){ 01264 putcharTX(name[counter]); 01265 if(name[counter]==0x00){ 01266 break; 01267 } 01268 counter++; 01269 } 01270 01271 res = (FILERESULT)getcharRX(); //Get SD file execution status 01272 getcharRX(); //Discard 'O' or 'F' 01273 return res; //Return SD file execution status 01274 } 01275 01276 FILERESULT SMARTGPU2::SDFsetFileTimeDate(TIME *timeDate, FILENAME name){ //Set Time and Date to an existing File 01277 FILERESULT res; 01278 unsigned int counter=0; 01279 01280 putcharTX('F'); //File function - memory card file management 01281 putcharTX('T'); //Time/Date 01282 putcharTX('S'); //Set 01283 putcharTX(timeDate->hour); //hour 01284 putcharTX(timeDate->minute); //min 01285 putcharTX(timeDate->second); //sec 01286 putcharTX(timeDate->day); //day 01287 putcharTX(timeDate->month); //month 01288 putcharTX(timeDate->year>>8);//year upper 01289 putcharTX(timeDate->year); //year lower 01290 while(1){ 01291 putcharTX(name[counter]); 01292 if(name[counter]==0x00){ 01293 break; 01294 } 01295 counter++; 01296 } 01297 01298 res = (FILERESULT)getcharRX(); //Get SD file execution status 01299 getcharRX(); //Discard 'O' or 'F' 01300 return res; //Return SD file execution status 01301 } 01302 01303 FILERESULT SMARTGPU2::SDFgetFileTimeDate(TIME *timeDate, FILENAME name){ //Get Time and Date to an existing File 01304 FILERESULT res; 01305 unsigned int counter=0; 01306 01307 putcharTX('F'); //File function - memory card file management 01308 putcharTX('T'); //Time/Date 01309 putcharTX('G'); //Get 01310 while(1){ 01311 putcharTX(name[counter]); 01312 if(name[counter]==0x00){ 01313 break; 01314 } 01315 counter++; 01316 } 01317 01318 timeDate->hour = getcharRX(); //hour 01319 timeDate->minute = getcharRX(); //min 01320 timeDate->second = getcharRX(); //sec 01321 timeDate->day = getcharRX(); //day 01322 timeDate->month = getcharRX(); //month 01323 ((unsigned char*)&counter)[1] = getcharRX(); //year upper 01324 ((unsigned char*)&counter)[0] = getcharRX(); //year lower 01325 timeDate->year = counter; //year 01326 res = (FILERESULT)getcharRX(); //Get SD file execution status 01327 getcharRX(); //Discard 'O' or 'F' 01328 return res; //Return SD file execution status 01329 } 01330 01331 FILERESULT SMARTGPU2::SDFgetFileSize(FILENAME name, unsigned long *fileSize){ //Get Size of an existing File 01332 FILERESULT res; 01333 unsigned int counter=0; 01334 unsigned long size=0; 01335 01336 putcharTX('F'); //File function - memory card file management 01337 putcharTX('I'); //Info 01338 putcharTX('S'); //Size 01339 while(1){ 01340 putcharTX(name[counter]); 01341 if(name[counter]==0x00){ 01342 break; 01343 } 01344 counter++; 01345 } 01346 01347 ((unsigned char *) &size)[3]=getcharRX(); 01348 ((unsigned char *) &size)[2]=getcharRX(); 01349 ((unsigned char *) &size)[1]=getcharRX(); 01350 ((unsigned char *) &size)[0]=getcharRX(); 01351 *fileSize=size; 01352 res = (FILERESULT)getcharRX(); //Get SD file execution status 01353 getcharRX(); //Discard 'O' or 'F' 01354 return res; //Return SD file execution status 01355 } 01356 01357 FILERESULT SMARTGPU2::SDFrenameMoveDirFile(FILENAME oldName, FILENAME newName){ //renames or moves an existing Dir or File 01358 FILERESULT res; 01359 unsigned int counter=0; 01360 01361 putcharTX('F'); //File function - memory card file management 01362 putcharTX('M'); //Rename / Move 01363 while(1){ 01364 putcharTX(oldName[counter]); 01365 if(oldName[counter]==0x00){ 01366 break; 01367 } 01368 counter++; 01369 } 01370 counter=0; 01371 while(1){ 01372 putcharTX(newName[counter]); 01373 if(newName[counter]==0x00){ 01374 break; 01375 } 01376 counter++; 01377 } 01378 01379 res = (FILERESULT)getcharRX(); //Get SD file execution status 01380 getcharRX(); //Discard 'O' or 'F' 01381 return res; //Return SD file execution status 01382 } 01383 01384 FILERESULT SMARTGPU2::SDFgetFreeTotalSpace(unsigned long *freeSpace,unsigned long *totalSpace){ //Get free and total space in bytes of the microSD card 01385 FILERESULT res; 01386 unsigned long fSpace=0, tSpace=0; 01387 01388 putcharTX('F'); //File function - memory card file management 01389 putcharTX('F'); //Free/Total space 01390 01391 ((unsigned char *) &fSpace)[3]=getcharRX(); 01392 ((unsigned char *) &fSpace)[2]=getcharRX(); 01393 ((unsigned char *) &fSpace)[1]=getcharRX(); 01394 ((unsigned char *) &fSpace)[0]=getcharRX(); 01395 ((unsigned char *) &tSpace)[3]=getcharRX(); 01396 ((unsigned char *) &tSpace)[2]=getcharRX(); 01397 ((unsigned char *) &tSpace)[1]=getcharRX(); 01398 ((unsigned char *) &tSpace)[0]=getcharRX(); 01399 *freeSpace=fSpace; 01400 *totalSpace=tSpace; 01401 res = (FILERESULT)getcharRX(); //Get SD file execution status 01402 getcharRX(); //Discard 'O' or 'F' 01403 return res; //Return SD file execution status 01404 } 01405
Generated on Thu Jul 14 2022 14:58:56 by 1.7.2