Paint Pro Demo with stylus drawing - MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Committer:
emmanuelchio
Date:
Thu Apr 17 23:50:49 2014 +0000
Revision:
1:9a127bd5a336
Parent:
0:d54096bf4bc6
SmartGPU2 PaintPro_SG2 demo- Please select(uncomment) your smartGPU2 board under SMARTGPU2.h file before compiling!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 1:9a127bd5a336 1 /**************************************************************************************/
emmanuelchio 0:d54096bf4bc6 2 /**************************************************************************************/
emmanuelchio 0:d54096bf4bc6 3 /*SMARTGPU2 intelligent embedded graphics processor unit
emmanuelchio 1:9a127bd5a336 4 those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:d54096bf4bc6 5 Board:
emmanuelchio 1:9a127bd5a336 6 http://www.vizictechnologies.com/
emmanuelchio 0:d54096bf4bc6 7
emmanuelchio 0:d54096bf4bc6 8 www.vizictechnologies.com
emmanuelchio 1:9a127bd5a336 9 Vizic Technologies copyright 2014 */
emmanuelchio 1:9a127bd5a336 10 /**************************************************************************************/
emmanuelchio 0:d54096bf4bc6 11 /**************************************************************************************/
emmanuelchio 0:d54096bf4bc6 12
emmanuelchio 0:d54096bf4bc6 13 #include "mbed.h"
emmanuelchio 0:d54096bf4bc6 14 #include "SMARTGPU2.h"
emmanuelchio 0:d54096bf4bc6 15
emmanuelchio 0:d54096bf4bc6 16 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd"
emmanuelchio 0:d54096bf4bc6 17
emmanuelchio 0:d54096bf4bc6 18 char pixelArray[3]; //Array to store the RGB888 pixel obtained with memoryRead()
emmanuelchio 0:d54096bf4bc6 19
emmanuelchio 0:d54096bf4bc6 20 /**************************************************/
emmanuelchio 0:d54096bf4bc6 21 //Funcion to convert a 3 byte array to an int RGB565
emmanuelchio 0:d54096bf4bc6 22 int RGB888ToRGB565(char pixBuffer[]){ //get an array of 3 bytes( red, green, blue), and convert them to RGB565 returned in an int
emmanuelchio 0:d54096bf4bc6 23 unsigned char R,G,B;
emmanuelchio 0:d54096bf4bc6 24 unsigned int col;
emmanuelchio 0:d54096bf4bc6 25 unsigned long colour;
emmanuelchio 0:d54096bf4bc6 26
emmanuelchio 0:d54096bf4bc6 27 R=pixBuffer[0];
emmanuelchio 0:d54096bf4bc6 28 G=pixBuffer[1];
emmanuelchio 0:d54096bf4bc6 29 B=pixBuffer[2];
emmanuelchio 0:d54096bf4bc6 30 ((unsigned char *) &colour)[1]=(R & 0xF8);
emmanuelchio 0:d54096bf4bc6 31 R=G;
emmanuelchio 0:d54096bf4bc6 32 G=G>>5;
emmanuelchio 0:d54096bf4bc6 33 ((unsigned char *) &colour)[1]|=G;
emmanuelchio 0:d54096bf4bc6 34 G=(R<<3)& 0xE0;
emmanuelchio 0:d54096bf4bc6 35 ((unsigned char *) &colour)[0]=B;
emmanuelchio 0:d54096bf4bc6 36 ((unsigned char *) &colour)[0]=((unsigned char *) &colour)[0]>>3;
emmanuelchio 0:d54096bf4bc6 37 ((unsigned char *) &colour)[0]|=G;
emmanuelchio 0:d54096bf4bc6 38 col=colour;
emmanuelchio 0:d54096bf4bc6 39 return col;
emmanuelchio 0:d54096bf4bc6 40 }
emmanuelchio 0:d54096bf4bc6 41
emmanuelchio 0:d54096bf4bc6 42 /***************************************************/
emmanuelchio 0:d54096bf4bc6 43 /***************************************************/
emmanuelchio 0:d54096bf4bc6 44 void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board
emmanuelchio 0:d54096bf4bc6 45 lcd.reset(); //physically reset SMARTGPU2
emmanuelchio 0:d54096bf4bc6 46 lcd.start(); //initialize the SMARTGPU2 processor
emmanuelchio 0:d54096bf4bc6 47 }
emmanuelchio 0:d54096bf4bc6 48
emmanuelchio 0:d54096bf4bc6 49 /***************************************************/
emmanuelchio 0:d54096bf4bc6 50 /***************************************************/
emmanuelchio 0:d54096bf4bc6 51 /***************************************************/
emmanuelchio 0:d54096bf4bc6 52 /***************************************************/
emmanuelchio 0:d54096bf4bc6 53 int main() {
emmanuelchio 0:d54096bf4bc6 54 POINT point;
emmanuelchio 0:d54096bf4bc6 55 unsigned char penSize=1;
emmanuelchio 0:d54096bf4bc6 56 COLOUR colour = BLACK;
emmanuelchio 0:d54096bf4bc6 57 char pen[4]={'x','0','1',0x00}; //Array that show the current penSize
emmanuelchio 0:d54096bf4bc6 58 NUMBEROFBYTES charsPrinted;
emmanuelchio 0:d54096bf4bc6 59
emmanuelchio 0:d54096bf4bc6 60 initializeSmartGPU2(); //Init communication with SmartGPU2 board
emmanuelchio 0:d54096bf4bc6 61
emmanuelchio 0:d54096bf4bc6 62 lcd.baudChange(BAUD7); //set a fast baud! for fast drawing
emmanuelchio 0:d54096bf4bc6 63
emmanuelchio 0:d54096bf4bc6 64 //Load paint design
emmanuelchio 0:d54096bf4bc6 65 lcd.imageBMPSD(0,0,"paint");
emmanuelchio 0:d54096bf4bc6 66 //strings config
emmanuelchio 0:d54096bf4bc6 67 lcd.setTextColour(GREEN);
emmanuelchio 0:d54096bf4bc6 68 lcd.setTextSize(FONT0);
emmanuelchio 0:d54096bf4bc6 69 lcd.setTextBackFill(FILLED);
emmanuelchio 0:d54096bf4bc6 70 lcd.string(7,54,48,65,"Erase",&charsPrinted); //draw Erase word
emmanuelchio 0:d54096bf4bc6 71 lcd.string(77,54,110,65,pen,&charsPrinted); //draw penSize
emmanuelchio 0:d54096bf4bc6 72
emmanuelchio 0:d54096bf4bc6 73 while(1){ //Start the Paint application
emmanuelchio 0:d54096bf4bc6 74 while(!lcd.touchScreen(&point)); //Wait for a touch on the screen to do something
emmanuelchio 0:d54096bf4bc6 75 //Once we get a touch somewhere on the screen:
emmanuelchio 0:d54096bf4bc6 76 if((point.y-penSize)<67){ //the touch was on the menu
emmanuelchio 0:d54096bf4bc6 77 if(point.x<45){ //touch on erase circle
emmanuelchio 0:d54096bf4bc6 78 lcd.drawRectangle(0,67,319,239,WHITE,FILL); //Draw a white rectangle on drawing area
emmanuelchio 0:d54096bf4bc6 79 }else if(point.x<75){ //touch to select the eraser
emmanuelchio 0:d54096bf4bc6 80 colour=WHITE;
emmanuelchio 0:d54096bf4bc6 81 lcd.drawCircle(25,34,14,colour,FILL); //draw WHITE colour circle on top left corner
emmanuelchio 0:d54096bf4bc6 82 }else if(point.x<108){ //touch to change pen Size
emmanuelchio 0:d54096bf4bc6 83 penSize=penSize*2; //double the penSize
emmanuelchio 0:d54096bf4bc6 84 if(penSize==16){ //maximum pen size = 8, if we reach 16 we set to 1.
emmanuelchio 0:d54096bf4bc6 85 penSize=1;
emmanuelchio 0:d54096bf4bc6 86 }
emmanuelchio 0:d54096bf4bc6 87 pen[1]=(penSize/10)+0x30; //get the tens of penSize and convert them to ascii
emmanuelchio 0:d54096bf4bc6 88 pen[2]=(penSize%10)+0x30; //get the ones of penSize and convert them to ascii
emmanuelchio 0:d54096bf4bc6 89 lcd.string(77,54,110,65,pen,&charsPrinted); //draw penSize
emmanuelchio 0:d54096bf4bc6 90 wait_ms(500); //delay to avoid fast penSize changing
emmanuelchio 0:d54096bf4bc6 91 }else if(point.x<312 & point.y>20 & point.y<59){//touch on the colours bar
emmanuelchio 0:d54096bf4bc6 92 lcd.getImageFromMemory(point.x,point.y,point.x,point.y,pixelArray); //assign new colour based on touch coordinates and memory read, this function return a 24 bit pixel array,
emmanuelchio 0:d54096bf4bc6 93 colour=RGB888ToRGB565(pixelArray);
emmanuelchio 0:d54096bf4bc6 94 lcd.drawCircle(25,34,14,colour,FILL); //draw new selected colour on top left corner
emmanuelchio 0:d54096bf4bc6 95 }
emmanuelchio 0:d54096bf4bc6 96 }else{ //Touch on drawing area
emmanuelchio 0:d54096bf4bc6 97 lcd.drawCircle(point.x,point.y,penSize,colour,FILL); //Draw
emmanuelchio 0:d54096bf4bc6 98 }
emmanuelchio 0:d54096bf4bc6 99 }
emmanuelchio 0:d54096bf4bc6 100 }