Tapton School Sentinel Project

Fork of SMARTGPU2 by Vizic Technologies

Files at this revision

API Documentation at this revision

Comitter:
emmanuelchio
Date:
Thu Apr 17 20:36:42 2014 +0000
Parent:
0:210b5ba62803
Child:
2:3ae3f28ae9fe
Commit message:
SmartGPU2 Mbed library V2 - Works with any smartGPU2 board: 2.4", 3.5", 4.3" and 7.0"

Changed in this revision

SMARTGPU2.cpp Show annotated file Show diff for this revision Revisions of this file
SMARTGPU2.h Show annotated file Show diff for this revision Revisions of this file
--- a/SMARTGPU2.cpp	Tue Jul 09 08:18:07 2013 +0000
+++ b/SMARTGPU2.cpp	Thu Apr 17 20:36:42 2014 +0000
@@ -1,5 +1,5 @@
 /*********************************************************
-VIZIC TECHNOLOGIES. COPYRIGHT 2013.
+VIZIC TECHNOLOGIES. COPYRIGHT 2014.
 THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." 
 VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER 
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED 
@@ -12,42 +12,47 @@
 ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
 OR OTHER SIMILAR COSTS.
 *********************************************************/
-
+ 
 /********************************************************
- MBED SMARTGPU2 LIBRARY VERSION V1.0
+ MBED SMARTGPU2 LIBRARY VERSION V2.0
  IMPORTANT : This library is created for the MBED Software IDE
 ********************************************************/
-
+ 
 #include "mbed.h"
 #include "SMARTGPU2.h"
-
+ 
 /****************************************************************/
 //Communication Functions(PLATFORM DEPENDENT) - MODIFY TO FIT YOUR PLATFORM IF DIFFERENT THAN MBED
 /****************************************************************/
 //Sends a single character through the serial port(USART)
-#define putcharTX(data) _serialSMARTGPU2.putc(data)
+void putcharTX(char data){
+    _serialSMARTGPU2.putc(data);
+}
 
 //Returns a single character obtained from the serial port(USART)
-#define getcharRX()     _serialSMARTGPU2.getc()
+char getcharRX(){
+    return _serialSMARTGPU2.getc();
+}
 
-//Changes/Sets a new baudrate of the Host
-#define setBaud(newBaud) _serialSMARTGPU2.baud(newBaud)
+//Changes/Sets a new Baudrate to the Host processor
+void setBaud(unsigned long newBaud){
+    _serialSMARTGPU2.baud(newBaud);
+}
 
 //Performs a Hardware Reset on smartGPU2 RESETPIN
-SMARTGPUREPLY SMARTGPU2::reset(){       //Physically Reset the SMARTGPU2 board
+void resetSmartGPU(){            //Reset the SMARTGPU2 board
   _resetPin=GND;                 // set the pin to GND to reset 
-  wait_ms(500);
+  delay(500);
   _resetPin=VCC;                 // set the pin to 5v to end reset
-  wait_ms(500);   
-  return OK;
+  delay(500);
 }
-
+ 
 //MBED Exclusive - Hardware Configuration
 void SMARTGPU2::init(){          //configure the MBED board for SMARTGPU2 board
     setBaud(9600);
     _resetPin=VCC;               // set the pin to 5v to end reset  
 }
-
+ 
 /****************************************************************/
 /****************************************************************/ 
 /****************************************************************/
@@ -56,19 +61,24 @@
 /****************************************************************/
 /****************************************************************/
  // SMART GPU2 DEFAULT BAUD RATE: 9600bps
-//It shoud be used like this : SMARTGPU2 lcd(TXPIN,RXPIN,RESET); for serial communication with SMARTGPU2
+//It should be used like this : SMARTGPU2 lcd(TXPIN,RXPIN,RESET); for serial communication with SMARTGPU2
 SMARTGPU2::SMARTGPU2(PinName TXPin, PinName RXPin, PinName resetPin): _serialSMARTGPU2(TXPin,RXPin), _resetPin(resetPin){    
     init();
 }
 
+SMARTGPUREPLY SMARTGPU2::reset(){       //Physically Reset the SMARTGPU2 board
+  resetSmartGPU();
+  return OK;
+}
+
 SMARTGPUREPLY SMARTGPU2::start(){       //Init the SMARTGPU2
-  wait_ms(500); 
+  delay(500); 
   putcharTX('U');  
-  wait_ms(500);
+  delay(500);
   return (SMARTGPUREPLY)getcharRX();
 }
-
-
+ 
+ 
 /****************************************************************/
 //Master Functions
 /****************************************************************/
@@ -77,32 +87,32 @@
   putcharTX('E'); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::sleep(STATE state){       //Send SMARTGPU2 to sleep mode
   putcharTX('M');             //Master function
   putcharTX('Z'); 
   putcharTX(state);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::orientation(LCDORIENTATIONS side){       //Change display orientation
   putcharTX('M');             //Master function
   putcharTX('O'); 
   putcharTX(side);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::bright(unsigned char val){       //Change display brightness
   putcharTX('M');             //Master function
   putcharTX('B'); 
   putcharTX(val);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 // SMART GPU 2 DEFAULT/INITIAL BAUD RATE: 9600bps
 SMARTGPUREPLY SMARTGPU2::baudChange(unsigned long baud){       //Change baud rate of MBED and SMARTGPU2 board
   unsigned char aux;
-
+ 
   putcharTX('M');             //Master function  
   putcharTX('X');
   putcharTX(baud>>24);
@@ -111,15 +121,15 @@
   putcharTX(baud);
   aux=getcharRX();
   if(aux=='O'){ //if command is successfull, change baudrate, if not just leave and return 'F'
-    wait_ms(150);
+    delay(150);
     setBaud(baud);
-    wait_ms(200);
+    delat(200);
     return (SMARTGPUREPLY)getcharRX();
   }else{
     return (SMARTGPUREPLY)aux;
   }
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setEraseBackColour(COLOUR colour){       //Change the default screen background colour for erase function
   putcharTX('M');             //Master function
   putcharTX('C');             //Background Colour
@@ -127,8 +137,8 @@
   putcharTX(colour); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
-
+ 
+ 
 /****************************************************************/
 //Geometric Functions
 /****************************************************************/
@@ -143,7 +153,7 @@
   putcharTX(colour);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawLine(AXIS x1, AXIS y1, AXIS x2, AXIS y2, COLOUR colour){       //Draw a line on the screen
   putcharTX('G');             //Geometric function  
   putcharTX('L'); 
@@ -159,7 +169,7 @@
   putcharTX(colour);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawRectangle(AXIS x1, AXIS y1, AXIS x2, AXIS y2, COLOUR colour, FILLGEOM fill){       //Draw a rectangle on the screen
   putcharTX('G');             //Geometric function 
   putcharTX('R');             //Rectangle   
@@ -176,7 +186,7 @@
   putcharTX(fill);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawRoundRect(AXIS x1, AXIS y1, AXIS x2, AXIS y2, RADIUS radius, COLOUR colour, FILLGEOM fill){      //Draw a rounded rectangle on the screen
   putcharTX('G');             //Geometric function 
   putcharTX('O');             //Rounded Rectangle   
@@ -214,7 +224,7 @@
   putcharTX(direction);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 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
   putcharTX('G');             //Geometric function  
   putcharTX('T'); 
@@ -235,7 +245,7 @@
   putcharTX(fill);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawArc(AXIS x, AXIS y, RADIUS radiusx, RADIUS radiusy, ARCQUADRANT quadrant, COLOUR colour, FILLGEOM fill){ //Draw an Arc on the screen
   putcharTX('G');             //Geometric function  
   putcharTX('A');             //Arc
@@ -253,7 +263,7 @@
   putcharTX(fill);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawCircle(AXIS x, AXIS y, RADIUS radius, COLOUR colour, FILLGEOM fill){       //Draw a circle on the screen
   putcharTX('G');             //Geometric function  
   putcharTX('C');             //Circle 
@@ -268,7 +278,7 @@
   putcharTX(fill);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::drawEllipse(AXIS x, AXIS y, RADIUS radiusx, RADIUS radiusy, COLOUR colour, FILLGEOM fill){       //Draw an Ellipse on the screen
   putcharTX('G');             //Geometric function 
   putcharTX('E');             //Ellipse 
@@ -285,8 +295,8 @@
   putcharTX(fill);  
   return (SMARTGPUREPLY)getcharRX();
 }
-
-
+ 
+ 
 /****************************************************************/
 //String Functions
 /****************************************************************/
@@ -301,13 +311,12 @@
   putcharTX(y);
   putcharTX(letter); 
  
-  xUp=getcharRX();
-  xUp=xUp<<8;
-  xUp|=getcharRX();
+  ((unsigned char*)&xUp)[1]=getcharRX();
+  ((unsigned char*)&xUp)[0]=getcharRX(); 
   *xUpdated = xUp;
   return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::printNumber(AXIS x, AXIS y, float number){ //Prints a float number on screen 
   putcharTX('S');           //String Function 
   putcharTX('N');           //Number
@@ -321,7 +330,7 @@
   putcharTX(((char *)&number)[0]);    
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 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
   unsigned int counter=0, sp=0; 
   
@@ -342,14 +351,13 @@
     }   
     counter++;
   }  
-
-  sp=getcharRX();
-  sp=sp<<8;
-  sp|=getcharRX();
+ 
+  ((unsigned char*)&sp)[1]=getcharRX();
+  ((unsigned char*)&sp)[0]=getcharRX();
   *SPB = sp;
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 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
   unsigned char counter=0, sp=0;
   
@@ -374,14 +382,13 @@
     }   
     counter++;
   }
-
-  sp=getcharRX();
-  sp=sp<<8;
-  sp|=getcharRX();
+ 
+  ((unsigned char*)&sp)[1]=getcharRX();
+  ((unsigned char*)&sp)[0]=getcharRX();
   *SPB = sp; 
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setTextColour(COLOUR colour){        //Set the default text colour for letters and strings
   putcharTX('S');             //String Function 
   putcharTX('C');             //Config  
@@ -390,7 +397,7 @@
   putcharTX(colour); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setTextBackColour(COLOUR colour){    //Set the default text background colour for letters and strings
   putcharTX('S');             //String Function 
   putcharTX('C');             //Config  
@@ -399,7 +406,7 @@
   putcharTX(colour); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setTextSize(FONTSIZE size){           //Set the default text size for letters and strings
   putcharTX('S');             //String Function 
   putcharTX('C');             //Config  
@@ -407,7 +414,7 @@
   putcharTX(size); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setTextBackFill(TEXTBACKGROUNDCOLOURFILLUNFILL fillState){  //Set the default text FILL or UNFILL background letters and strings
   putcharTX('S');             //String Function 
   putcharTX('C');             //Config  
@@ -415,8 +422,8 @@
   putcharTX(fillState); 
   return (SMARTGPUREPLY)getcharRX();
 }
-
-
+ 
+ 
 /****************************************************************/
 //Image Functions
 /****************************************************************/
@@ -443,7 +450,7 @@
   
   return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 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
   unsigned char counter=0;
   
@@ -462,7 +469,7 @@
   }
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 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
   unsigned char counter=0;
   
@@ -482,7 +489,7 @@
   }
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 //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
 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)
   unsigned int i,j,k=0;
@@ -507,15 +514,15 @@
   }
   return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 //takes a screenshot of SmartGPU2 display and stores it in the microSD card with consecutive names Screenshot000.bmp, Screenshot001.bmp, etc
 SMARTGPUREPLY SMARTGPU2::screenshot(){ 
   putcharTX('I');             //Image function
   putcharTX('S');             //Screenshot
   return (SMARTGPUREPLY)getcharRX();    
 }
-
-
+ 
+ 
 /****************************************************************/
 //Video Functions
 /****************************************************************/
@@ -533,7 +540,7 @@
     }   
     counter++;
   }
-
+ 
   ((unsigned char *) &wid)[1]=getcharRX(); //get video width
   ((unsigned char *) &wid)[0]=getcharRX(); 
   ((unsigned char *) &hei)[1]=getcharRX(); //get video height
@@ -548,14 +555,14 @@
   videoData->totalFrames  = tot;
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
 //deAllocates a ".vid" video previously allocated, must be called when no more calls to video will be done
 SMARTGPUREPLY SMARTGPU2::freeVideoSD(){  
   putcharTX('V');             //Video function   
   putcharTX('D');             //DeAllocate
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
  //Sets a video start Frame position, this function can be used to FastForward video or Rewing, returns 'F' if invalid position
 SMARTGPUREPLY SMARTGPU2::setFrameVideoSD(unsigned int startFrame){
   putcharTX('V');             //Video function   
@@ -564,7 +571,7 @@
   putcharTX(startFrame);
   return (SMARTGPUREPLY)getcharRX();
 }
-
+ 
  //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
 SMARTGPUREPLY SMARTGPU2::playVideoSD(AXIS x, AXIS y, unsigned int framesToPlay){ //frames to play from current video Frame
   putcharTX('V');             //Video function   
@@ -578,7 +585,7 @@
   return (SMARTGPUREPLY)getcharRX();
 }
     
-
+ 
 /****************************************************************/
 //Audio Functions
 /****************************************************************/      
@@ -588,21 +595,21 @@
   putcharTX(state);           //Enable/Disable  
   return (SMARTGPUREPLY)getcharRX();      
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::audioBoost(STATE state){
   putcharTX('A');             //Audio Function
   putcharTX('B');             //Boost
   putcharTX(state);           //Enable/Disable
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::getWAVPlayState(STATE* state){ //returns ENABLE or DISABLE if any file is playing
   putcharTX('A');             //Audio Function
   putcharTX('G');             //Get playing File status  
   *state = (STATE)getcharRX();        //Get state
   return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::playWAVFile(FILENAME name, unsigned int* seconds){ //returns in "seconds" variable the song duration in seconds
   unsigned int counter=0;
   unsigned int secs=0;
@@ -616,25 +623,25 @@
     }   
     counter++;
   }
-
+ 
   ((unsigned char *) &secs)[1]=getcharRX();  
   ((unsigned char *) &secs)[0]=getcharRX();     
   *seconds = secs;
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::pauseWAVFile(){ //pauses a playing file, returns 'F' if no file is playing
   putcharTX('A');             //Audio Function
   putcharTX('W');             //Pause file
   return (SMARTGPUREPLY)getcharRX();   
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::stopWAVFile(){
   putcharTX('A');             //Audio Function
   putcharTX('S');             //Stop playing file
   return (SMARTGPUREPLY)getcharRX();   
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::advanceWAVFile(unsigned int seconds){ //advance to the file to the given seconds parameter  
   putcharTX('A');             //Audio Function
   putcharTX('A');             //Advance file  
@@ -642,15 +649,15 @@
   putcharTX(seconds);  
   return (SMARTGPUREPLY)getcharRX();          //returns 'F' if no file is playing or if no seconds position exists, in this case file will stop playing
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::setVolumeWAV(unsigned char volume){
   putcharTX('A');             //Audio Function
   putcharTX('V');             //Volume
   putcharTX(volume);
   return (SMARTGPUREPLY)getcharRX();  
 }
-
-
+ 
+ 
 /****************************************************************/
 //Real Time Clock Functions
 /****************************************************************/          
@@ -719,7 +726,7 @@
   }    
   return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::objSwitch(AXIS x, AXIS y, unsigned int switchSize, ACTIVE activeState){
   putcharTX('O');              //Object function
   putcharTX('T');              //Switch
@@ -745,7 +752,7 @@
   putcharTX(activeState);
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::objProgressBar(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char progress){
   putcharTX('O');              //Object function
   putcharTX('P');              //Progress Bar
@@ -760,7 +767,7 @@
   putcharTX(progress);
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::objSlider(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char position, unsigned char divisions, ORIENTATIONPARAMETER sliderOrientation){
   putcharTX('O');              //Object function
   putcharTX('L');              //Slider
@@ -777,7 +784,7 @@
   putcharTX(sliderOrientation);
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::objScrollBar(AXIS x1, AXIS y1, AXIS x2, AXIS y2, unsigned char position, unsigned char divisions, ORIENTATIONPARAMETER scrollBarOrientation, ACTIVE activeState){
   putcharTX('O');              //Object function
   putcharTX('S');              //Scroll bar
@@ -795,7 +802,7 @@
   putcharTX(activeState);
   return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::objWindow(AXIS x1, AXIS y1, AXIS x2, AXIS y2, FONTSIZE textSize, WINDOWTYPE winType, char text[]){
   unsigned int counter=0;
   
@@ -820,8 +827,8 @@
   }
   return (SMARTGPUREPLY)getcharRX();    
 }
-
-
+ 
+ 
 /****************************************************************/
 //EEPROM-FLASH Functions - Refer to "smartGPU2 Command Set" to learn about READ-WRITE procedure.
 /****************************************************************/          
@@ -830,7 +837,7 @@
   putcharTX('I');              //Init/Clear EEPROM Buffer
   return (SMARTGPUREPLY)getcharRX(); 
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::readEEPROMBuff(char buffer[], ADDRESS EEPROMbufferAddress, NUMBEROFBYTES bytesToRead, NUMBEROFBYTES *SRB){
   unsigned int x=0, sr=0;
   
@@ -844,13 +851,12 @@
   for(x=0; x<bytesToRead; x++){
     buffer[x]=getcharRX();
   }
-  sr=getcharRX();
-  sr=sr<<8;
-  sr|=getcharRX();
+  ((unsigned char*)&sr)[1]=getcharRX();
+  ((unsigned char*)&sr)[0]=getcharRX();
   *SRB = sr;                   //store succesfully read bytes  
    return (SMARTGPUREPLY)getcharRX();  
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::writeEEPROMBuff(char buffer[], ADDRESS EEPROMbufferAddress, NUMBEROFBYTES bytesToWrite, NUMBEROFBYTES *SWB){
   unsigned int x=0, sw=0;
   
@@ -863,28 +869,27 @@
   for(x=0; x<bytesToWrite; x++){
     putcharTX(buffer[x]);
   }  
-
-  sw=getcharRX();
-  sw=sw<<8;
-  sw|=getcharRX();
+ 
+  ((unsigned char*)&sw)[1]=getcharRX();
+  ((unsigned char*)&sw)[0]=getcharRX();
   *SWB = sw;                   //store succesfully written bytes
    return (SMARTGPUREPLY)getcharRX();    
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::saveBuffToEEPROMPage(EEPROMPAGE page){
   putcharTX('E');              //EEPROM function
   putcharTX('S');              //Save EEPROM buffer contents to received EEPROM page#
   putcharTX(page);
   return (SMARTGPUREPLY)getcharRX(); 
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::fillBuffFromEEPROMPage(EEPROMPAGE page){
   putcharTX('E');              //EEPROM function
   putcharTX('F');              //Fill(copy) EEPROM buffer with received EEPROM page# contents
   putcharTX(page);
   return (SMARTGPUREPLY)getcharRX(); 
 }
-
+ 
 SMARTGPUREPLY SMARTGPU2::compBuffToEEPROMPage(EEPROMPAGE page, unsigned char *result){
   putcharTX('E');              //EEPROM function
   putcharTX('C');              //Compare EEPROM buffer contents with received EEPROM page#
@@ -892,14 +897,14 @@
   *result = getcharRX();
   return (SMARTGPUREPLY)getcharRX(); 
 }   
-
+ 
 SMARTGPUREPLY SMARTGPU2::eraseEEPROMPage(EEPROMPAGE page){
   putcharTX('E');              //EEPROM function
   putcharTX('E');              //Erase received EEPROM page#
   putcharTX(page);
   return (SMARTGPUREPLY)getcharRX(); 
 }   
-
+ 
     
 /****************************************************************/
 //Touch Functions
@@ -921,6 +926,7 @@
   return (TOUCHREPLY)INVALID;
 }
 
+#ifdef  LCD320X240 //define function only for the SmartGPU2 LCD320x240 2.4" is selected, as it is the only board with touch icons
 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
   putcharTX('T');             //Touch Function
   putcharTX('I');             //Icons touch
@@ -930,8 +936,20 @@
   }
   return (TOUCHREPLY)INVALID;
 }
-
-
+#elif defined  LCD320X240SH //define function only for the SmartGPU2 LCD320x240SH 2.4" is selected, as it is the only board with touch icons
+ 
+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
+  putcharTX('T');             //Touch Function
+  putcharTX('I');             //Icons touch
+  *icon = (ICON)getcharRX();
+  if(getcharRX()=='O'){  //if touch coordinates are valid
+    return (TOUCHREPLY)VALID;
+  }
+  return (TOUCHREPLY)INVALID;
+}
+#endif
+ 
+ 
 /****************************************************************/
 //SD FAT management Functions
 //Those next SDF - SD Functions return file execution status(FILERESULT) instead of ACK 'O' or NAK 'F'(SMARTGPUREPLY)
@@ -953,11 +971,11 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 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
   FILERESULT  res;
   unsigned int  i=0;
-
+ 
   putcharTX('F');           //File function - memory card file management
   putcharTX('G');           //Get name of given item file number
   putcharTX('D');           //Directory
@@ -975,17 +993,17 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status
  }
-
+ 
 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
   FILERESULT  res;
   unsigned int  i=0;
-
+ 
   putcharTX('F');           //File function - memory card file management
   putcharTX('G');           //Get name of given item file number
   putcharTX('F');           //File  
   putcharTX(itemNumber>>8); //Send Upper part of itemNumber
   putcharTX(itemNumber);    //Send Lower part of itemNumber
-
+ 
   while(1){
     name[i]=getcharRX(); 
     if(name[i]==0x00){         //if we find NULL character, means end of name
@@ -1015,7 +1033,7 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFnewDir(FILENAME name){ //create a new Directory, fails if already exist
   FILERESULT res;
   unsigned int counter=0;  
@@ -1030,12 +1048,12 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFnewFile(FILENAME name){ //create a new File, fails if already exist
   FILERESULT res;
   unsigned int counter=0;  
@@ -1050,12 +1068,12 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFopenDir(FILENAME name){ //opens an existing Dir
   FILERESULT res;
   unsigned int counter=0;  
@@ -1069,12 +1087,12 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFopenFile(FILENAME name, OPENMODE mode, WORKSPACEBLOCK objectWorkspaceNo){ //opens an existing file in READONLY, WRITEONLY or READWRITE mode on the received object # workspace
   FILERESULT res;
   unsigned int counter=0;  
@@ -1090,36 +1108,36 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                    //Return SD file execution status  
 }
-
+ 
 FILERESULT SMARTGPU2::SDFcloseFile(WORKSPACEBLOCK objectWorkspaceNo){ //close and save file object # workspace
   FILERESULT res;
-
+ 
   putcharTX('F');           //File function - memory card file management
   putcharTX('C');           //Close File
   putcharTX(objectWorkspaceNo); //object workspace number to close 0-4  
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFsaveFile(WORKSPACEBLOCK objectWorkspaceNo){ //sync/save file object # workspace
   FILERESULT res;
   
   putcharTX('F');           //File function - memory card file management
   putcharTX('S');           //Save/Sync file - Save changes on file
   putcharTX(objectWorkspaceNo); //object workspace number to save changes 0-4  
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFsetFilePointer(POINTERPOSITION pointerPosition, WORKSPACEBLOCK objectWorkspaceNo){ // set/move file pointer of file object # workspace
   FILERESULT res;
   
@@ -1131,12 +1149,12 @@
   putcharTX(pointerPosition>>16);
   putcharTX(pointerPosition>>8);
   putcharTX(pointerPosition);
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }   
-
+ 
 FILERESULT SMARTGPU2::SDFgetFilePointer(POINTERPOSITION *pointerPosition, WORKSPACEBLOCK objectWorkspaceNo){ // get file pointer of file object # workspace
   FILERESULT res;
   unsigned long pos = 0;
@@ -1155,29 +1173,28 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }   
-
+ 
 FILERESULT SMARTGPU2::SDFreadFile(char buffer[], NUMBEROFBYTES BTR, NUMBEROFBYTES *SRB, WORKSPACEBLOCK objectWorkspaceNo){ //Bytes to Read, Succesfully Read Bytes, file object # to read bytes from
   FILERESULT res;
   unsigned int x=0, sr=0;
-
+ 
   putcharTX('F');           //File function - memory card file management
   putcharTX('R');           //Read file
   putcharTX(objectWorkspaceNo); //object workspace number to read 0-4    
   putcharTX(BTR>>8);
   putcharTX(BTR);  
-
+ 
   for(x=0;x<BTR;x++){
     buffer[x]=getcharRX();
   }
-  sr=getcharRX();
-  sr=sr<<8;
-  sr|=getcharRX();
+  ((unsigned char*)&sr)[1]=getcharRX();
+  ((unsigned char*)&sr)[0]=getcharRX();
   *SRB = sr;                   //store succesfully read bytes
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }   
-
+ 
 FILERESULT SMARTGPU2::SDFwriteFile(char buffer[], NUMBEROFBYTES BTW, NUMBEROFBYTES *SWB,  WORKSPACEBLOCK objectWorkspaceNo){ //Bytes to Write, Succesfully Written Bytes, file object # to write bytes
   FILERESULT res;
   unsigned int x=0, sw=0;
@@ -1190,29 +1207,28 @@
   for(x=0;x<BTW;x++){
     putcharTX(buffer[x]);
   }
-
-  sw=getcharRX();
-  sw=sw<<8;
-  sw|=getcharRX();
+ 
+  ((unsigned char*)&sw)[1]=getcharRX();
+  ((unsigned char*)&sw)[0]=getcharRX();
   *SWB = sw;                   //store succesfully written bytes   
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFtestFileError(WORKSPACEBLOCK objectWorkspaceNo){  //test for an error on file # workspace
   FILERESULT res;
-
+ 
   putcharTX('F');           //File function - memory card file management
   putcharTX('Q');           //Test 
   putcharTX(objectWorkspaceNo); //object workspace number to write bytes 0-4    
   putcharTX('R');           //Test Error  
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFtestFileEnd(WORKSPACEBLOCK objectWorkspaceNo){  //test for an error on file # workspace
   FILERESULT res;
   
@@ -1220,24 +1236,24 @@
   putcharTX('Q');           //Test 
   putcharTX(objectWorkspaceNo); //object workspace number to write bytes 0-4    
   putcharTX('E');           //Test End of File
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
-
+ 
 FILERESULT SMARTGPU2::SDFtruncateFile(WORKSPACEBLOCK objectWorkspaceNo){  //truncates the file size to the current file read/write pointer of the file # workspace
   FILERESULT res;
   
   putcharTX('F');           //File function - memory card file management
   putcharTX('V');           //Truncate
   putcharTX(objectWorkspaceNo); //object workspace number 0-4 to truncate on current pointerPosition
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
-
+ 
 FILERESULT SMARTGPU2::SDFeraseDirFile(FILENAME name){ //Erases an existing Dir or File
   FILERESULT res;
   unsigned int counter=0;  
@@ -1252,12 +1268,12 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFsetFileTimeDate(TIME *timeDate, FILENAME name){ //Set Time and Date to an existing File
   FILERESULT res;
   unsigned int counter=0;  
@@ -1279,12 +1295,12 @@
     }   
     counter++;
   }
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
-
+ 
 FILERESULT SMARTGPU2::SDFgetFileTimeDate(TIME *timeDate, FILENAME name){ //Get Time and Date to an existing File
   FILERESULT res;
   unsigned int counter=0;  
@@ -1299,7 +1315,7 @@
     }   
     counter++;
   } 
-
+ 
   timeDate->hour = getcharRX();   //hour
   timeDate->minute = getcharRX(); //min
   timeDate->second = getcharRX(); //sec
@@ -1312,7 +1328,7 @@
   getcharRX();                    //Discard 'O' or 'F'
   return res;                     //Return SD file execution status
 }
-
+ 
 FILERESULT SMARTGPU2::SDFgetFileSize(FILENAME name, unsigned long *fileSize){ //Get Size of an existing File
   FILERESULT res;
   unsigned int counter=0;  
@@ -1328,7 +1344,7 @@
         }   
         counter++;
     }   
-
+ 
   ((unsigned char *) &size)[3]=getcharRX();
   ((unsigned char *) &size)[2]=getcharRX();
   ((unsigned char *) &size)[1]=getcharRX();  
@@ -1338,7 +1354,7 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
-
+ 
 FILERESULT SMARTGPU2::SDFrenameMoveDirFile(FILENAME oldName, FILENAME newName){ //renames or moves an existing Dir or File
   FILERESULT res;
   unsigned int counter=0;  
@@ -1360,19 +1376,19 @@
         }   
         counter++;
   } 
-
+ 
   res = (FILERESULT)getcharRX(); //Get SD file execution status
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
-
+ 
 FILERESULT SMARTGPU2::SDFgetFreeTotalSpace(unsigned long *freeSpace,unsigned long *totalSpace){ //Get free and total space in bytes of the microSD card
   FILERESULT res;
   unsigned long fSpace=0, tSpace=0;
   
   putcharTX('F');           //File function - memory card file management
   putcharTX('F');           //Free/Total space
-
+ 
   ((unsigned char *) &fSpace)[3]=getcharRX();
   ((unsigned char *) &fSpace)[2]=getcharRX();
   ((unsigned char *) &fSpace)[1]=getcharRX();  
@@ -1387,3 +1403,4 @@
   getcharRX();                   //Discard 'O' or 'F'
   return res;                      //Return SD file execution status 
 }
+ 
\ No newline at end of file
--- a/SMARTGPU2.h	Tue Jul 09 08:18:07 2013 +0000
+++ b/SMARTGPU2.h	Thu Apr 17 20:36:42 2014 +0000
@@ -1,5 +1,5 @@
 /*********************************************************
-VIZIC TECHNOLOGIES. COPYRIGHT 2013.
+VIZIC TECHNOLOGIES. COPYRIGHT 2014.
 THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." 
 VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER 
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED 
@@ -12,29 +12,64 @@
 ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
 OR OTHER SIMILAR COSTS.
 *********************************************************/
-
+ 
 /********************************************************
- MBED SMARTGPU2 LIBRARY VERSION V1.0
+ MBED SMARTGPU2 LIBRARY VERSION V2.0
  IMPORTANT : This library is created for the MBED Software IDE
 ********************************************************/
-
+ 
 #ifndef SMARTGPU2_h
 #define SMARTGPU2_h
-
+ 
 #include <mbed.h>
+ 
+/*******************USER MODIFABLE**********************/
+//-Uncomment your preferred smartGPU2 board(only 1 at time)----------------
+//#define LCD160X128   //SmartGPU2 1.8" connected via SmartSHIELD
+//#define LCD320X240   //SmartGPU2 2.4" connected via SmartSHIELD
+//#define LCD480X320   //SmartGPU2 3.5" connected via SmartSHIELD
+//#define LCD480X272   //SmartGPU2 4.3" connected via SmartSHIELD
+//#define LCD800X480   //SmartGPU2 7.0" connected via SmartSHIELD
 
 //General MBED pinout defines
 #define TXPIN    p13
 #define RXPIN    p14
-#define RESETPIN p15
+//-SmartGPU2-MBED RESET PIN definition 
+#define RESETPIN p15   //Define for the smartGPU2 RESET pin connected to the MBED board
+
+//delay word compatibility for mbed
+#define delay wait_ms
+
+/****************END OF USER MODIFABLE******************/
 
-//defines for SmartGPU2 LCD320x240 ONLY
+/**************DON'T MODIFY UP FROM HERE****************/
+#ifdef  LCD160X128          //defines for SmartGPU2 LCD160x128 1.8" ONLY
+#define LCD_WIDTH  160
+#define LCD_HEIGHT 128
+#elif defined  LCD320X240   //defines for SmartGPU2 LCD320x240 2.4" ONLY
+#define LCD_WIDTH  320
+#define LCD_HEIGHT 240
+#elif defined  LCD320X240SH //defines for SmartGPU2 LCD320x240SH 2.4" ONLY
 #define LCD_WIDTH  320
 #define LCD_HEIGHT 240
-#define MAX_X_LANDSCAPE 319
-#define MAX_Y_LANDSCAPE 239
-#define MAX_X_PORTRAIT  239
-#define MAX_Y_PORTRAIT  319
+#elif defined  LCD480X320   //defines for SmartGPU2 LCD480x320 3.5" ONLY
+#define LCD_WIDTH  480
+#define LCD_HEIGHT 320
+#elif defined  LCD480X272   //defines for SmartGPU2 LCD480x272 4.3" ONLY
+#define LCD_WIDTH  480
+#define LCD_HEIGHT 272
+#elif defined  LCD800X480   //defines for SmartGPU2 LCD800x480 7.0" ONLY
+#define LCD_WIDTH  800
+#define LCD_HEIGHT 480
+#else
+#error "No smartGPU2 LCDXXXxXXX board defined in smartGPU2.h file"
+#endif
+
+//Max X, Y values depending on orientation definitions
+#define MAX_X_LANDSCAPE LCD_WIDTH-1
+#define MAX_Y_LANDSCAPE LCD_HEIGHT-1
+#define MAX_X_PORTRAIT  LCD_HEIGHT-1
+#define MAX_Y_PORTRAIT  LCD_WIDTH-1
 
 //General definitions
 #define OFF 0
@@ -50,7 +85,7 @@
 typedef unsigned int ADDRESS;
 typedef unsigned long POINTERPOSITION;
 typedef char FILENAME[];
-
+ 
 typedef enum {
     DISABLE, //0
     ENABLE   //1
@@ -171,12 +206,12 @@
 //SMARTGPU2 Command Execution responses definitions
 typedef enum {
     F_OK = 0,               /* (0) Succeeded */
-    F_DISK_ERR,         /* (1) A hard error occurred in the low level disk I/O layer */
+    F_DISK_ERR,             /* (1) A hard error occurred in the low level disk I/O layer */
     F_INT_ERR,              /* (2) Assertion failed */
     F_NOT_READY,            /* (3) The physical drive cannot work */
     F_NO_FILE,              /* (4) Could not find the file */
     F_NO_PATH,              /* (5) Could not find the path */
-    F_INVALID_NAME,     /* (6) The path name format is invalid */
+    F_INVALID_NAME,         /* (6) The path name format is invalid */
     F_DENIED,               /* (7) Access denied due to prohibited access or directory full */
     F_EXIST,                /* (8) Access denied due to prohibited access */
     F_INVALID_OBJECT,       /* (9) The file/directory object is invalid */
@@ -184,13 +219,13 @@
     F_INVALID_DRIVE,        /* (11) The logical drive number is invalid */
     F_NOT_ENABLED,          /* (12) The volume has no work area */
     F_NO_FILESYSTEM,        /* (13) There is no valid FAT volume */
-    F_MKFS_ABORTED,     /* (14) The f_mkfs() aborted due to any parameter error */
+    F_MKFS_ABORTED,         /* (14) The f_mkfs() aborted due to any parameter error */
     F_TIMEOUT,              /* (15) Could not get a grant to access the volume within defined period */
     F_LOCKED,               /* (16) The operation is rejected according to the file sharing policy */
     F_NOT_ENOUGH_CORE,      /* (17) LFN working buffer could not be allocated */
     F_TOO_MANY_OPEN_FILES,  /* (18) Number of open files > _FS_SHARE */
-    F_INVALID_PARAMETER /* (19) Given parameter is invalid */
-} FILERESULT;              //to get all FAT related functions responses
+    F_INVALID_PARAMETER     /* (19) Given parameter is invalid */
+} FILERESULT;               //Gets all FAT functions related responses
 
 //SMARTGPU2 WorkSpaces definitions
 typedef enum {
@@ -230,7 +265,7 @@
     SCALE1_8       // 1 to 8
 } JPGSCALEFACTOR; //to set the desired JPG image decompression scale factor
 
-//Recommended(but not limited to) MBED-SmartGPU Baud rate definitions
+//Recommended(but not limited to) Arduino-SmartGPU Baud rate definitions
 typedef enum{
     BAUD0 = 9600,
     BAUD1 = 19200,
@@ -241,10 +276,10 @@
     BAUD6 = 1000000,
     BAUD7 = 2000000
 } BAUDRATE;
-
+ 
 //**************************************************************************
 // class SMARTGPU2 SMARTGPU2.h
-// This is the main class. It shoud be used like this : SMARTGPU2 lcd(p13,p14,p15);
+// This is the main class. It should be used like this : SMARTGPU2 lcd(p13,p14,p15);
 //***************************************************************************
 class SMARTGPU2{
     
@@ -406,8 +441,11 @@
 //Those next Touch Functions return valid or invalid touch coordinates status(TOUCHREPLY) instead of ACK 'O' or NAK 'F'(SMARTGPUREPLY)
 /****************************************************************/  
     TOUCHREPLY touchScreen(POINT*);
-    
+#ifdef  LCD320X240 //define function only for the SmartGPU2 LCD320x240 2.4" is selected, as it is the only board with touch icons
     TOUCHREPLY touchIcon(ICON*);
+#elif defined  LCD320X240SH //define function only for the SmartGPU2 LCD320x240SH 2.4" is selected, as it is the only board with touch icons
+    TOUCHREPLY touchIcon(ICON*);
+#endif
     
 /****************************************************************/
 //SD FAT management Functions
@@ -465,5 +503,5 @@
     DigitalOut _resetPin;   
      
 };
-
-#endif
+ 
+#endif
\ No newline at end of file