This is the Official SmartGPU 2 processor board library to use with MBED boards!!!

Dependents:   BounceBall_SG2 BounceBalls_SG2 EEPROM_SG2 Ellipses_SG2 ... more

Revision:
1:0bf6fac21233
Parent:
0:210b5ba62803
Child:
2:3ae3f28ae9fe
diff -r 210b5ba62803 -r 0bf6fac21233 SMARTGPU2.cpp
--- 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