SMARTGPU intelligent embedded graphics processor, this library helps to communicate mBed with SMARTGPU dev board 2.4\" touch, excellent serial board that only require TX,RX, and Reset pin to mbed. Powerfull graphics and text processor with universal 4GB micro SD (FAT windows) format compatible. For detailed information visit: http://www.vizictechnologies.com/#/desarrollo/4554296549 www.vizictechnologies.com

Dependents:   VariousSG BouncingBalls BounceBall House ... more

Files at this revision

API Documentation at this revision

Comitter:
emmanuelchio
Date:
Mon Sep 12 23:23:11 2011 +0000
Child:
1:96ed067e95a6
Commit message:
SMARTGPU library Rev1.0

Changed in this revision

SMARTGPU.cpp Show annotated file Show diff for this revision Revisions of this file
SMARTGPU.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SMARTGPU.cpp	Mon Sep 12 23:23:11 2011 +0000
@@ -0,0 +1,372 @@
+ 
+#include "mbed.h"
+#include "SMARTGPU.h"
+
+Serial SGSERIALPORT(TXpin, RXpin);  //create the serial port which is connected to SMARTGPU serial port
+DigitalOut Rst(resetPin);
+
+// SMART GPU DEFAULT BAUD RATE: 9600bps
+// Mbed default configured port for serial communication with SMARTGPU is p13 for TX, and p14 for RX, Resetpin =p15
+SMARTGPU::SMARTGPU(){    
+    init();
+}
+
+/********** high level commands, for the user! */
+void SMARTGPU::init(){         //configure the mbed for SMARTGPU board    
+    SGSERIALPORT.baud(9600);
+    Rst=1;                     //set the pin to 3.3v to avoid reset 
+}
+ 
+void SMARTGPU::reset(){        //Reset the SMARTGPU board
+    Rst=0;                     //set the pin to GND to reset 
+    wait_ms(500);
+    Rst=1;                     //set the pin to 3.3v to end reset
+    wait_ms(500);    
+}
+
+unsigned char SMARTGPU::start(){           //Init the SMARTGPU
+  wait_ms(500); 
+  SGSERIALPORT.putc('U');  
+  wait_ms(1000);
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::erase(){          //Erase the SMARTGPU screen
+  SGSERIALPORT.putc('E');  
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::sleep(unsigned char mode){       //Send SMARTGPU to sleep mode
+  SGSERIALPORT.putc('Z'); 
+  SGSERIALPORT.putc(mode);
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::orientation(unsigned char side){       //Change display orientation
+  SGSERIALPORT.putc('O'); 
+  SGSERIALPORT.putc(side);
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::bright(unsigned char val){       //Change display brightness
+  SGSERIALPORT.putc('V'); 
+  SGSERIALPORT.putc(val); 
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::baudChange(unsigned long val){       //Change baud rate of arduino and SMARTGPU board
+  unsigned char aux;
+ 
+  switch(val){
+    case 9600:
+      aux=0;
+    break;
+    case 19200:
+      aux=1;
+    break;
+    case 57600:
+      aux=2;
+    break;
+    case 115200:
+      aux=3;
+    break;
+    case 256000:
+      aux=4;
+    break;    
+    case 500000:
+      aux=5;
+    break;
+    case 1000000:
+      aux=6;
+    break;
+    case 2000000:
+      aux=7;
+    break;
+    default:
+      return 'F';
+    break;
+  } 
+  SGSERIALPORT.putc('X');
+  SGSERIALPORT.putc(aux);  
+  aux=SGSERIALPORT.getc();
+  if(aux=='O'){
+    wait_ms(150);
+    SGSERIALPORT.baud(val);
+    wait_ms(200);
+    return SGSERIALPORT.getc();
+  }else{
+    return aux;
+  }
+}
+
+unsigned char SMARTGPU::digitalOut(unsigned char number, unsigned char val ){       //Set Digital out pins to a logic value
+  SGSERIALPORT.putc('D'); 
+  SGSERIALPORT.putc(number);
+  SGSERIALPORT.putc(val); 
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::setScreenBackground(int colour){       //Change the default screen background colour for erase function
+  SGSERIALPORT.putc('B'); 
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);  
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::setTextBackground(int colour){       //Set the default text background colour for letters and strings
+  SGSERIALPORT.putc('A'); 
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);  
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::memoryRead(int x1, int y1, int x2, int y2, char buffer[]){ //Read the internal memory of the SMARTGPU, This command returns 24bit pixels (3 bytes)
+  unsigned int i,j,k=0;
+  
+  SGSERIALPORT.putc('M'); 
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2); 
+
+  //receive all the pixels
+  for(j=0;j<=(y2-y1);j++){
+    for(i=0;i<=(x2-x1);i++){
+        buffer[k]=SGSERIALPORT.getc(); //Red
+        k++;
+        buffer[k]=SGSERIALPORT.getc(); //Green
+        k++;
+        buffer[k]=SGSERIALPORT.getc(); //Blue
+        k++;
+    }    
+  } 
+  return SGSERIALPORT.getc();  
+}
+
+unsigned char SMARTGPU::putPixel(int x, int y, int colour){       //Draw a pixel on the screen
+  SGSERIALPORT.putc('P'); 
+  SGSERIALPORT.putc(x>>8); 
+  SGSERIALPORT.putc(x);
+  SGSERIALPORT.putc(y>>8);
+  SGSERIALPORT.putc(y);
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::drawLine(int x1, int y1, int x2, int y2, int colour){       //Draw a line on the screen
+  SGSERIALPORT.putc('L'); 
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);  
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::drawRectangle(int x1, int y1, int x2, int y2, int colour, unsigned char fill){       //Draw a rectangle on the screen
+  SGSERIALPORT.putc('R'); 
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);  
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(fill);   
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int colour, unsigned char fill){       //Draw a triangle on the screen
+  SGSERIALPORT.putc('T'); 
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);  
+  SGSERIALPORT.putc(x3>>8); 
+  SGSERIALPORT.putc(x3);
+  SGSERIALPORT.putc(y3>>8);
+  SGSERIALPORT.putc(y3);    
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(fill);   
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::drawCircle(int x, int y, int radius, int colour, unsigned char fill){       //Draw a circle on the screen
+  SGSERIALPORT.putc('C'); 
+  SGSERIALPORT.putc(x>>8); 
+  SGSERIALPORT.putc(x);
+  SGSERIALPORT.putc(y>>8);
+  SGSERIALPORT.putc(y);
+  SGSERIALPORT.putc(radius>>8);
+  SGSERIALPORT.putc(radius);
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(fill);   
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::putLetter(int x, int y, int colour, unsigned char font, unsigned char fill, unsigned char letter){       //Draw a letter on the screen
+  
+  SGSERIALPORT.putc('W'); 
+  SGSERIALPORT.putc(x>>8); 
+  SGSERIALPORT.putc(x);
+  SGSERIALPORT.putc(y>>8);
+  SGSERIALPORT.putc(y);
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(font); 
+  SGSERIALPORT.putc(fill); 
+  SGSERIALPORT.putc(letter);  
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::string(int x1, int y1, int x2, int y2, int colour, unsigned char font, unsigned char fill, char text[]){       //Draw a string on the screen
+  int counter=0;
+  
+  SGSERIALPORT.putc('S'); 
+  SGSERIALPORT.putc('N'); //not SD
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);  
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(font); 
+  SGSERIALPORT.putc(fill); 
+  while(1){
+    SGSERIALPORT.putc(text[counter]);
+    if(text[counter]==0x00){
+      break;
+    }    
+    counter++;
+  } 
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::stringSD(int x1, int y1, int x2, int y2, int colour, unsigned char font, unsigned char fill, int BS, int BR, char name[]){       //Draw a String from a text file contained on the micro SD card on the screen
+  unsigned char counter=0;
+  
+  SGSERIALPORT.putc('S'); 
+  SGSERIALPORT.putc('S'); //from SD
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);  
+  SGSERIALPORT.putc(colour>>8);
+  SGSERIALPORT.putc(colour);
+  SGSERIALPORT.putc(font); 
+  SGSERIALPORT.putc(fill); 
+  SGSERIALPORT.putc(BS>>8);
+  SGSERIALPORT.putc(BS);  
+  SGSERIALPORT.putc(BR>>8);
+  SGSERIALPORT.putc(BR);  
+  while(1){
+    SGSERIALPORT.putc(name[counter]);
+    if(name[counter]==0x00){
+      break;
+    }    
+    counter++;
+  }
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::icon(int x1, int y1, int x2, int y2, char icon[]){            //Send and image or icon pixel by pixel to SMARTGPU, 16bit(2 bytes) each pixel RGB565
+  unsigned int i,j,k=0; 
+  
+  SGSERIALPORT.putc('I'); 
+  SGSERIALPORT.putc('N'); //not SD
+  SGSERIALPORT.putc(x1>>8); 
+  SGSERIALPORT.putc(x1);
+  SGSERIALPORT.putc(y1>>8);
+  SGSERIALPORT.putc(y1);
+  SGSERIALPORT.putc(x2>>8); 
+  SGSERIALPORT.putc(x2);
+  SGSERIALPORT.putc(y2>>8);
+  SGSERIALPORT.putc(y2);
+  
+  //Send icon buffer pixel by pixel
+  for(j=0;j<=(y2-y1);j++){
+    for(i=0;i<=(x2-x1);i++){
+        SGSERIALPORT.putc(icon[k]);
+        k++;
+    }
+  } 
+  return SGSERIALPORT.getc();  
+}
+
+unsigned char SMARTGPU::imageSD(int x, int y, char name[]){        //Draw an Image contained on the micro SD card on the screen, top left corner coordinates
+  unsigned char counter=0;
+  
+  SGSERIALPORT.putc('I'); 
+  SGSERIALPORT.putc('S'); //from SD
+  SGSERIALPORT.putc(x>>8); 
+  SGSERIALPORT.putc(x);
+  SGSERIALPORT.putc(y>>8);
+  SGSERIALPORT.putc(y);
+  while(1){
+    SGSERIALPORT.putc(name[counter]);
+    if(name[counter]==0x00){
+      break;
+    }    
+    counter++;
+  }
+  return SGSERIALPORT.getc();
+}
+
+unsigned char SMARTGPU::touchScreen(int buffer[]){          //Ask for a touch on the screen, if return=1, touch coordinates are stored on the buffer[]
+  
+  SGSERIALPORT.putc('G');
+  buffer[0]=SGSERIALPORT.getc();
+  buffer[0]=buffer[0]<<8;
+  buffer[0]|=SGSERIALPORT.getc();
+  buffer[1]=SGSERIALPORT.getc();
+  buffer[1]=buffer[1]<<8;
+  buffer[1]|=SGSERIALPORT.getc();
+  SGSERIALPORT.getc();  
+  if(buffer[0]<0x0200){
+    return 1;
+  }else{
+    return 0;
+  }
+}
+
+unsigned char SMARTGPU::touchIcon(char buffer[]){          //Ask for a touch on the icons of the screen, if return=1, icon name is stored on the buffer[]
+  
+  SGSERIALPORT.putc('G');
+  buffer[0]=SGSERIALPORT.getc();
+  buffer[1]=SGSERIALPORT.getc();
+  buffer[2]=SGSERIALPORT.getc();
+  buffer[3]=SGSERIALPORT.getc();
+  SGSERIALPORT.getc();  
+  if(!(buffer[0]<0x02) & (buffer[0]!=0x4E)){
+    return 1;
+  }else{
+    return 0;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SMARTGPU.h	Mon Sep 12 23:23:11 2011 +0000
@@ -0,0 +1,117 @@
+
+#ifndef SMARTGPU_H
+#define SMARTGPU_H
+
+#include <mbed.h>
+
+//****USER DEFINED PINS (modify to select another serial port of MBED*****//
+
+//PinOUT for MBED Definitions
+#define TXpin    p13
+#define RXpin    p14
+#define resetPin p15
+//**********************END OF USER DEFINED PINS**************************//
+
+
+//******************LIBRARY DEFINED PINS (don't modify)*******************//
+//General definitions
+#define RESET 13
+#define TX 1
+#define RX 0
+#define OFF 0
+#define ON 1
+#define FULL 127
+#define UNFILL 0
+#define FILL 1
+#define TRANS 0
+#define COLOUR 1
+#define BEGINNING 0
+#define ALLCONTENTS 0
+#define LANDSCAPEL  0x00  //left
+#define PORTRAITL   0x01  //low
+#define LANDSCAPER  0x02  //right
+#define PORTRAITT   0x03  //top
+#define DOUT0 0
+#define DOUT1 1
+#define GND 0
+#define VCC 1
+#define XCOORD 0
+#define YCOORD 1
+#define WIDTH  320
+#define HEIGHT 240
+
+//basic colours definition
+#define BLACK   0x0000
+#define WHITE   0xFFFF
+#define RED     0xF800
+#define GREEN   0x07E0
+#define BLUE    0x001F
+#define YELLOW  0xFFE0
+#define CYAN    0x07FF
+#define MAGENTA 0xF81F
+
+//fonts definition
+#define FONT0   0x00
+#define FONT1   0x01
+#define FONT2   0x02
+#define FONT3   0x03
+#define FONT4   0x04
+#define FONT5   0x05
+#define FONT6   0x06
+#define FONT7   0x07
+
+class SMARTGPU{
+    
+public:
+    SMARTGPU();
+    
+    void init();
+
+    void reset();
+    
+    unsigned char start();  
+
+    unsigned char erase();
+
+    unsigned char sleep(unsigned char);
+    
+    unsigned char orientation(unsigned char);
+    
+    unsigned char bright(unsigned char);
+    
+    unsigned char baudChange(unsigned long val);
+    
+    unsigned char digitalOut(unsigned char, unsigned char);
+    
+    unsigned char setScreenBackground(int);
+    
+    unsigned char setTextBackground(int);
+    
+    unsigned char memoryRead(int, int, int, int, char[]);
+    
+    unsigned char putPixel(int, int, int);
+    
+    unsigned char drawLine(int, int, int, int, int);
+    
+    unsigned char drawRectangle(int, int, int, int, int, unsigned char);
+    
+    unsigned char drawTriangle(int, int, int, int, int, int, int, unsigned char);
+    
+    unsigned char drawCircle(int, int, int, int, unsigned char);
+    
+    unsigned char putLetter(int, int, int, unsigned char, unsigned char, unsigned char);
+    
+    unsigned char string(int, int, int, int, int, unsigned char, unsigned char, char[]);
+    
+    unsigned char stringSD(int, int, int, int, int, unsigned char, unsigned char, int, int, char[]);
+    
+    unsigned char icon(int, int, int, int, char[]);
+    
+    unsigned char imageSD(int , int , char[]);
+    
+    unsigned char touchScreen(int[]);
+    
+    unsigned char touchIcon(char[]);
+};
+
+#endif