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