Mini SmartGPU Intelligent Graphics Processor. Mbed library Rev1.0 Vizic Technologies 2012 http://vizictechnologies.com/#/mini-smart-gpu/4566376187
Dependents: BounceBallMSG BouncingBallsMSG HouseMSG NiceClockMSG ... more
MINISMARTGPU.cpp@0:1c3989d263f4, 2012-08-28 (annotated)
- Committer:
- emmanuelchio
- Date:
- Tue Aug 28 01:40:19 2012 +0000
- Revision:
- 0:1c3989d263f4
- Child:
- 1:83a75a056cfa
Mini SmartGPU Intelligent Graphics Processor. Vizic Technologies 2012 http://vizictechnologies.com/#/mini-smart-gpu/4566376187
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 0:1c3989d263f4 | 1 | /********************************************************* |
emmanuelchio | 0:1c3989d263f4 | 2 | VIZIC TECHNOLOGIES. COPYRIGHT 2012. |
emmanuelchio | 0:1c3989d263f4 | 3 | THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." |
emmanuelchio | 0:1c3989d263f4 | 4 | VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER |
emmanuelchio | 0:1c3989d263f4 | 5 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED |
emmanuelchio | 0:1c3989d263f4 | 6 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, |
emmanuelchio | 0:1c3989d263f4 | 7 | OR NONINFRINGEMENT. IN NO EVENT SHALL VIZIC BE LIABLE FOR |
emmanuelchio | 0:1c3989d263f4 | 8 | ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, |
emmanuelchio | 0:1c3989d263f4 | 9 | LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF |
emmanuelchio | 0:1c3989d263f4 | 10 | PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, |
emmanuelchio | 0:1c3989d263f4 | 11 | ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO |
emmanuelchio | 0:1c3989d263f4 | 12 | ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, |
emmanuelchio | 0:1c3989d263f4 | 13 | OR OTHER SIMILAR COSTS. |
emmanuelchio | 0:1c3989d263f4 | 14 | *********************************************************/ |
emmanuelchio | 0:1c3989d263f4 | 15 | |
emmanuelchio | 0:1c3989d263f4 | 16 | #include "mbed.h" |
emmanuelchio | 0:1c3989d263f4 | 17 | #include "MINISMARTGPU.h" |
emmanuelchio | 0:1c3989d263f4 | 18 | |
emmanuelchio | 0:1c3989d263f4 | 19 | // MINI SMART GPU DEFAULT BAUD RATE: 9600bps |
emmanuelchio | 0:1c3989d263f4 | 20 | //It shoud be used like this : MINISMARTGPU lcd(p13,p14,p15); for serial communication with MINISMARTGPU |
emmanuelchio | 0:1c3989d263f4 | 21 | MINISMARTGPU::MINISMARTGPU(PinName TXPin, PinName RXPin, PinName resetPin): _serialMINISMARTGPU(TXPin,RXPin), _resetPin(resetPin){ |
emmanuelchio | 0:1c3989d263f4 | 22 | init(); |
emmanuelchio | 0:1c3989d263f4 | 23 | } |
emmanuelchio | 0:1c3989d263f4 | 24 | |
emmanuelchio | 0:1c3989d263f4 | 25 | /********** high level commands, for the user! */ |
emmanuelchio | 0:1c3989d263f4 | 26 | void MINISMARTGPU::init(){ //configure the mbed for MINISMARTGPU board |
emmanuelchio | 0:1c3989d263f4 | 27 | _serialMINISMARTGPU.baud(9600); |
emmanuelchio | 0:1c3989d263f4 | 28 | _resetPin=1; //set the pin to 3.3v to avoid reset |
emmanuelchio | 0:1c3989d263f4 | 29 | } |
emmanuelchio | 0:1c3989d263f4 | 30 | |
emmanuelchio | 0:1c3989d263f4 | 31 | void MINISMARTGPU::reset(){ //Reset the MINISMARTGPU board |
emmanuelchio | 0:1c3989d263f4 | 32 | _resetPin=0; //set the pin to GND to reset |
emmanuelchio | 0:1c3989d263f4 | 33 | wait_ms(500); |
emmanuelchio | 0:1c3989d263f4 | 34 | _resetPin=1; //set the pin to 3.3v to end reset |
emmanuelchio | 0:1c3989d263f4 | 35 | wait_ms(500); |
emmanuelchio | 0:1c3989d263f4 | 36 | |
emmanuelchio | 0:1c3989d263f4 | 37 | } |
emmanuelchio | 0:1c3989d263f4 | 38 | |
emmanuelchio | 0:1c3989d263f4 | 39 | unsigned char MINISMARTGPU::start(){ //Init the MINISMARTGPU |
emmanuelchio | 0:1c3989d263f4 | 40 | wait_ms(500); |
emmanuelchio | 0:1c3989d263f4 | 41 | _serialMINISMARTGPU.putc('U'); |
emmanuelchio | 0:1c3989d263f4 | 42 | wait_ms(1500); |
emmanuelchio | 0:1c3989d263f4 | 43 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 44 | |
emmanuelchio | 0:1c3989d263f4 | 45 | } |
emmanuelchio | 0:1c3989d263f4 | 46 | |
emmanuelchio | 0:1c3989d263f4 | 47 | unsigned char MINISMARTGPU::erase(){ //Erase the MINISMARTGPU screen |
emmanuelchio | 0:1c3989d263f4 | 48 | _serialMINISMARTGPU.putc('E'); |
emmanuelchio | 0:1c3989d263f4 | 49 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 50 | |
emmanuelchio | 0:1c3989d263f4 | 51 | } |
emmanuelchio | 0:1c3989d263f4 | 52 | |
emmanuelchio | 0:1c3989d263f4 | 53 | unsigned char MINISMARTGPU::sleep(unsigned char mode){ //Send MINISMARTGPU to sleep mode |
emmanuelchio | 0:1c3989d263f4 | 54 | _serialMINISMARTGPU.putc('Z'); |
emmanuelchio | 0:1c3989d263f4 | 55 | _serialMINISMARTGPU.putc(mode); |
emmanuelchio | 0:1c3989d263f4 | 56 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 57 | |
emmanuelchio | 0:1c3989d263f4 | 58 | } |
emmanuelchio | 0:1c3989d263f4 | 59 | |
emmanuelchio | 0:1c3989d263f4 | 60 | unsigned char MINISMARTGPU::orientation(unsigned char side){ //Change display orientation |
emmanuelchio | 0:1c3989d263f4 | 61 | _serialMINISMARTGPU.putc('O'); |
emmanuelchio | 0:1c3989d263f4 | 62 | _serialMINISMARTGPU.putc(side); |
emmanuelchio | 0:1c3989d263f4 | 63 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 64 | |
emmanuelchio | 0:1c3989d263f4 | 65 | } |
emmanuelchio | 0:1c3989d263f4 | 66 | |
emmanuelchio | 0:1c3989d263f4 | 67 | unsigned char MINISMARTGPU::bright(unsigned char val){ //Change display brightness |
emmanuelchio | 0:1c3989d263f4 | 68 | _serialMINISMARTGPU.putc('V'); |
emmanuelchio | 0:1c3989d263f4 | 69 | _serialMINISMARTGPU.putc(val); |
emmanuelchio | 0:1c3989d263f4 | 70 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 71 | |
emmanuelchio | 0:1c3989d263f4 | 72 | } |
emmanuelchio | 0:1c3989d263f4 | 73 | |
emmanuelchio | 0:1c3989d263f4 | 74 | unsigned char MINISMARTGPU::baudChange(unsigned long val){ //Change baud rate of mbed and SMARTGPU board |
emmanuelchio | 0:1c3989d263f4 | 75 | unsigned char aux; |
emmanuelchio | 0:1c3989d263f4 | 76 | |
emmanuelchio | 0:1c3989d263f4 | 77 | switch(val){ |
emmanuelchio | 0:1c3989d263f4 | 78 | case 9600: |
emmanuelchio | 0:1c3989d263f4 | 79 | aux=0; |
emmanuelchio | 0:1c3989d263f4 | 80 | break; |
emmanuelchio | 0:1c3989d263f4 | 81 | case 19200: |
emmanuelchio | 0:1c3989d263f4 | 82 | aux=1; |
emmanuelchio | 0:1c3989d263f4 | 83 | break; |
emmanuelchio | 0:1c3989d263f4 | 84 | case 57600: |
emmanuelchio | 0:1c3989d263f4 | 85 | aux=2; |
emmanuelchio | 0:1c3989d263f4 | 86 | break; |
emmanuelchio | 0:1c3989d263f4 | 87 | case 115200: |
emmanuelchio | 0:1c3989d263f4 | 88 | aux=3; |
emmanuelchio | 0:1c3989d263f4 | 89 | break; |
emmanuelchio | 0:1c3989d263f4 | 90 | case 256000: |
emmanuelchio | 0:1c3989d263f4 | 91 | aux=4; |
emmanuelchio | 0:1c3989d263f4 | 92 | break; |
emmanuelchio | 0:1c3989d263f4 | 93 | case 500000: |
emmanuelchio | 0:1c3989d263f4 | 94 | aux=5; |
emmanuelchio | 0:1c3989d263f4 | 95 | break; |
emmanuelchio | 0:1c3989d263f4 | 96 | case 1000000: |
emmanuelchio | 0:1c3989d263f4 | 97 | aux=6; |
emmanuelchio | 0:1c3989d263f4 | 98 | break; |
emmanuelchio | 0:1c3989d263f4 | 99 | case 2000000: |
emmanuelchio | 0:1c3989d263f4 | 100 | aux=7; |
emmanuelchio | 0:1c3989d263f4 | 101 | break; |
emmanuelchio | 0:1c3989d263f4 | 102 | default: |
emmanuelchio | 0:1c3989d263f4 | 103 | return 'F'; |
emmanuelchio | 0:1c3989d263f4 | 104 | |
emmanuelchio | 0:1c3989d263f4 | 105 | } |
emmanuelchio | 0:1c3989d263f4 | 106 | _serialMINISMARTGPU.putc('X'); |
emmanuelchio | 0:1c3989d263f4 | 107 | _serialMINISMARTGPU.putc(aux); |
emmanuelchio | 0:1c3989d263f4 | 108 | aux=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 109 | |
emmanuelchio | 0:1c3989d263f4 | 110 | if(aux=='O'){ |
emmanuelchio | 0:1c3989d263f4 | 111 | wait_ms(150); |
emmanuelchio | 0:1c3989d263f4 | 112 | _serialMINISMARTGPU.baud(val); |
emmanuelchio | 0:1c3989d263f4 | 113 | wait_ms(200); |
emmanuelchio | 0:1c3989d263f4 | 114 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 115 | }else{ |
emmanuelchio | 0:1c3989d263f4 | 116 | return aux; |
emmanuelchio | 0:1c3989d263f4 | 117 | } |
emmanuelchio | 0:1c3989d263f4 | 118 | } |
emmanuelchio | 0:1c3989d263f4 | 119 | |
emmanuelchio | 0:1c3989d263f4 | 120 | unsigned char MINISMARTGPU::setScreenBackground(int colour){ //Change the default screen background colour for erase function |
emmanuelchio | 0:1c3989d263f4 | 121 | _serialMINISMARTGPU.putc('B'); |
emmanuelchio | 0:1c3989d263f4 | 122 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 123 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 124 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 125 | |
emmanuelchio | 0:1c3989d263f4 | 126 | } |
emmanuelchio | 0:1c3989d263f4 | 127 | |
emmanuelchio | 0:1c3989d263f4 | 128 | unsigned char MINISMARTGPU::setTextBackground(int colour){ //Set the default text background colour for letters and strings |
emmanuelchio | 0:1c3989d263f4 | 129 | _serialMINISMARTGPU.putc('A'); |
emmanuelchio | 0:1c3989d263f4 | 130 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 131 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 132 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 133 | |
emmanuelchio | 0:1c3989d263f4 | 134 | } |
emmanuelchio | 0:1c3989d263f4 | 135 | |
emmanuelchio | 0:1c3989d263f4 | 136 | unsigned char MINISMARTGPU::memoryRead(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, char buffer[]){ //Read the internal memory of the MINISMARTGPU, This command returns 24bit pixels (3 bytes) |
emmanuelchio | 0:1c3989d263f4 | 137 | unsigned int i,j,k=0; |
emmanuelchio | 0:1c3989d263f4 | 138 | |
emmanuelchio | 0:1c3989d263f4 | 139 | _serialMINISMARTGPU.putc('M'); |
emmanuelchio | 0:1c3989d263f4 | 140 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 141 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 142 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 143 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 144 | |
emmanuelchio | 0:1c3989d263f4 | 145 | //receive all the pixels |
emmanuelchio | 0:1c3989d263f4 | 146 | for(j=0;j<=(y2-y1);j++){ |
emmanuelchio | 0:1c3989d263f4 | 147 | for(i=0;i<=(x2-x1);i++){ |
emmanuelchio | 0:1c3989d263f4 | 148 | buffer[k]=_serialMINISMARTGPU.getc(); //Red |
emmanuelchio | 0:1c3989d263f4 | 149 | k++; |
emmanuelchio | 0:1c3989d263f4 | 150 | buffer[k]=_serialMINISMARTGPU.getc(); //Green |
emmanuelchio | 0:1c3989d263f4 | 151 | k++; |
emmanuelchio | 0:1c3989d263f4 | 152 | buffer[k]=_serialMINISMARTGPU.getc(); //Blue |
emmanuelchio | 0:1c3989d263f4 | 153 | k++; |
emmanuelchio | 0:1c3989d263f4 | 154 | } |
emmanuelchio | 0:1c3989d263f4 | 155 | } |
emmanuelchio | 0:1c3989d263f4 | 156 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 157 | |
emmanuelchio | 0:1c3989d263f4 | 158 | } |
emmanuelchio | 0:1c3989d263f4 | 159 | |
emmanuelchio | 0:1c3989d263f4 | 160 | unsigned char MINISMARTGPU::putPixel(unsigned char x, unsigned char y, int colour){ //Draw a pixel on the screen |
emmanuelchio | 0:1c3989d263f4 | 161 | _serialMINISMARTGPU.putc('P'); |
emmanuelchio | 0:1c3989d263f4 | 162 | _serialMINISMARTGPU.putc(x); |
emmanuelchio | 0:1c3989d263f4 | 163 | _serialMINISMARTGPU.putc(y); |
emmanuelchio | 0:1c3989d263f4 | 164 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 165 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 166 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 167 | |
emmanuelchio | 0:1c3989d263f4 | 168 | } |
emmanuelchio | 0:1c3989d263f4 | 169 | |
emmanuelchio | 0:1c3989d263f4 | 170 | unsigned char MINISMARTGPU::drawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, int colour){ //Draw a line on the screen |
emmanuelchio | 0:1c3989d263f4 | 171 | _serialMINISMARTGPU.putc('L'); |
emmanuelchio | 0:1c3989d263f4 | 172 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 173 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 174 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 175 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 176 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 177 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 178 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 179 | |
emmanuelchio | 0:1c3989d263f4 | 180 | } |
emmanuelchio | 0:1c3989d263f4 | 181 | |
emmanuelchio | 0:1c3989d263f4 | 182 | unsigned char MINISMARTGPU::drawRectangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, int colour, unsigned char fill){ //Draw a rectangle on the screen |
emmanuelchio | 0:1c3989d263f4 | 183 | _serialMINISMARTGPU.putc('R'); |
emmanuelchio | 0:1c3989d263f4 | 184 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 185 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 186 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 187 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 188 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 189 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 190 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 191 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 192 | |
emmanuelchio | 0:1c3989d263f4 | 193 | } |
emmanuelchio | 0:1c3989d263f4 | 194 | |
emmanuelchio | 0:1c3989d263f4 | 195 | unsigned char MINISMARTGPU::drawTriangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char x3, unsigned char y3, int colour, unsigned char fill){ //Draw a triangle on the screen |
emmanuelchio | 0:1c3989d263f4 | 196 | _serialMINISMARTGPU.putc('T'); |
emmanuelchio | 0:1c3989d263f4 | 197 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 198 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 199 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 200 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 201 | _serialMINISMARTGPU.putc(x3); |
emmanuelchio | 0:1c3989d263f4 | 202 | _serialMINISMARTGPU.putc(y3); |
emmanuelchio | 0:1c3989d263f4 | 203 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 204 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 205 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 206 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 207 | |
emmanuelchio | 0:1c3989d263f4 | 208 | } |
emmanuelchio | 0:1c3989d263f4 | 209 | |
emmanuelchio | 0:1c3989d263f4 | 210 | unsigned char MINISMARTGPU::drawCircle(unsigned char x, unsigned char y, unsigned char radius, int colour, unsigned char fill){ //Draw a circle on the screen |
emmanuelchio | 0:1c3989d263f4 | 211 | _serialMINISMARTGPU.putc('C'); |
emmanuelchio | 0:1c3989d263f4 | 212 | _serialMINISMARTGPU.putc(x); |
emmanuelchio | 0:1c3989d263f4 | 213 | _serialMINISMARTGPU.putc(y); |
emmanuelchio | 0:1c3989d263f4 | 214 | _serialMINISMARTGPU.putc(radius); |
emmanuelchio | 0:1c3989d263f4 | 215 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 216 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 217 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 218 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 219 | |
emmanuelchio | 0:1c3989d263f4 | 220 | } |
emmanuelchio | 0:1c3989d263f4 | 221 | |
emmanuelchio | 0:1c3989d263f4 | 222 | unsigned char MINISMARTGPU::putLetter(unsigned char x, unsigned char y, int colour, unsigned char font, unsigned char fill, unsigned char letter){ //Draw a letter on the screen |
emmanuelchio | 0:1c3989d263f4 | 223 | _serialMINISMARTGPU.putc('W'); |
emmanuelchio | 0:1c3989d263f4 | 224 | _serialMINISMARTGPU.putc(x); |
emmanuelchio | 0:1c3989d263f4 | 225 | _serialMINISMARTGPU.putc(y); |
emmanuelchio | 0:1c3989d263f4 | 226 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 227 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 228 | _serialMINISMARTGPU.putc(font); |
emmanuelchio | 0:1c3989d263f4 | 229 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 230 | _serialMINISMARTGPU.putc(letter); |
emmanuelchio | 0:1c3989d263f4 | 231 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 232 | |
emmanuelchio | 0:1c3989d263f4 | 233 | } |
emmanuelchio | 0:1c3989d263f4 | 234 | |
emmanuelchio | 0:1c3989d263f4 | 235 | unsigned char MINISMARTGPU::string(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, int colour, unsigned char font, unsigned char fill, char text[]){ //Draw a string on the screen |
emmanuelchio | 0:1c3989d263f4 | 236 | int counter=0; |
emmanuelchio | 0:1c3989d263f4 | 237 | |
emmanuelchio | 0:1c3989d263f4 | 238 | _serialMINISMARTGPU.putc('S'); |
emmanuelchio | 0:1c3989d263f4 | 239 | _serialMINISMARTGPU.putc('N'); //not SD |
emmanuelchio | 0:1c3989d263f4 | 240 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 241 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 242 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 243 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 244 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 245 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 246 | _serialMINISMARTGPU.putc(font); |
emmanuelchio | 0:1c3989d263f4 | 247 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 248 | while(1){ |
emmanuelchio | 0:1c3989d263f4 | 249 | _serialMINISMARTGPU.putc(text[counter]); |
emmanuelchio | 0:1c3989d263f4 | 250 | if(text[counter]==0x00){ |
emmanuelchio | 0:1c3989d263f4 | 251 | break; |
emmanuelchio | 0:1c3989d263f4 | 252 | } |
emmanuelchio | 0:1c3989d263f4 | 253 | counter++; |
emmanuelchio | 0:1c3989d263f4 | 254 | } |
emmanuelchio | 0:1c3989d263f4 | 255 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 256 | |
emmanuelchio | 0:1c3989d263f4 | 257 | } |
emmanuelchio | 0:1c3989d263f4 | 258 | |
emmanuelchio | 0:1c3989d263f4 | 259 | unsigned char MINISMARTGPU::stringSD(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char 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 |
emmanuelchio | 0:1c3989d263f4 | 260 | unsigned char counter=0; |
emmanuelchio | 0:1c3989d263f4 | 261 | |
emmanuelchio | 0:1c3989d263f4 | 262 | _serialMINISMARTGPU.putc('S'); |
emmanuelchio | 0:1c3989d263f4 | 263 | _serialMINISMARTGPU.putc('S'); //from SD |
emmanuelchio | 0:1c3989d263f4 | 264 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 265 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 266 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 267 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 268 | _serialMINISMARTGPU.putc(colour>>8); |
emmanuelchio | 0:1c3989d263f4 | 269 | _serialMINISMARTGPU.putc(colour); |
emmanuelchio | 0:1c3989d263f4 | 270 | _serialMINISMARTGPU.putc(font); |
emmanuelchio | 0:1c3989d263f4 | 271 | _serialMINISMARTGPU.putc(fill); |
emmanuelchio | 0:1c3989d263f4 | 272 | _serialMINISMARTGPU.putc(BS>>8); |
emmanuelchio | 0:1c3989d263f4 | 273 | _serialMINISMARTGPU.putc(BS); |
emmanuelchio | 0:1c3989d263f4 | 274 | _serialMINISMARTGPU.putc(BR>>8); |
emmanuelchio | 0:1c3989d263f4 | 275 | _serialMINISMARTGPU.putc(BR); |
emmanuelchio | 0:1c3989d263f4 | 276 | while(1){ |
emmanuelchio | 0:1c3989d263f4 | 277 | _serialMINISMARTGPU.putc(name[counter]); |
emmanuelchio | 0:1c3989d263f4 | 278 | if(name[counter]==0x00){ |
emmanuelchio | 0:1c3989d263f4 | 279 | break; |
emmanuelchio | 0:1c3989d263f4 | 280 | } |
emmanuelchio | 0:1c3989d263f4 | 281 | counter++; |
emmanuelchio | 0:1c3989d263f4 | 282 | } |
emmanuelchio | 0:1c3989d263f4 | 283 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 284 | |
emmanuelchio | 0:1c3989d263f4 | 285 | } |
emmanuelchio | 0:1c3989d263f4 | 286 | |
emmanuelchio | 0:1c3989d263f4 | 287 | unsigned char MINISMARTGPU::icon(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, char icon[]){ //Send and image or icon pixel by pixel to MINISMARTGPU, 16bit(2 bytes) each pixel RGB565 |
emmanuelchio | 0:1c3989d263f4 | 288 | unsigned int i,j,k=0; |
emmanuelchio | 0:1c3989d263f4 | 289 | |
emmanuelchio | 0:1c3989d263f4 | 290 | _serialMINISMARTGPU.putc('I'); |
emmanuelchio | 0:1c3989d263f4 | 291 | _serialMINISMARTGPU.putc('N'); //not SD |
emmanuelchio | 0:1c3989d263f4 | 292 | _serialMINISMARTGPU.putc(x1); |
emmanuelchio | 0:1c3989d263f4 | 293 | _serialMINISMARTGPU.putc(y1); |
emmanuelchio | 0:1c3989d263f4 | 294 | _serialMINISMARTGPU.putc(x2); |
emmanuelchio | 0:1c3989d263f4 | 295 | _serialMINISMARTGPU.putc(y2); |
emmanuelchio | 0:1c3989d263f4 | 296 | |
emmanuelchio | 0:1c3989d263f4 | 297 | //Send icon buffer pixel by pixel |
emmanuelchio | 0:1c3989d263f4 | 298 | for(j=0;j<=(y2-y1);j++){ |
emmanuelchio | 0:1c3989d263f4 | 299 | for(i=0;i<=(x2-x1);i++){ |
emmanuelchio | 0:1c3989d263f4 | 300 | _serialMINISMARTGPU.putc(icon[k]); |
emmanuelchio | 0:1c3989d263f4 | 301 | k++; |
emmanuelchio | 0:1c3989d263f4 | 302 | } |
emmanuelchio | 0:1c3989d263f4 | 303 | } |
emmanuelchio | 0:1c3989d263f4 | 304 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 305 | |
emmanuelchio | 0:1c3989d263f4 | 306 | } |
emmanuelchio | 0:1c3989d263f4 | 307 | |
emmanuelchio | 0:1c3989d263f4 | 308 | unsigned char MINISMARTGPU::imageSD(unsigned char x, unsigned char y, char name[]){ //Draw an Image contained on the micro SD card on the screen, top left corner coordinates |
emmanuelchio | 0:1c3989d263f4 | 309 | unsigned char counter=0; |
emmanuelchio | 0:1c3989d263f4 | 310 | |
emmanuelchio | 0:1c3989d263f4 | 311 | _serialMINISMARTGPU.putc('I'); |
emmanuelchio | 0:1c3989d263f4 | 312 | _serialMINISMARTGPU.putc('S'); //from SD |
emmanuelchio | 0:1c3989d263f4 | 313 | _serialMINISMARTGPU.putc(x>>8); |
emmanuelchio | 0:1c3989d263f4 | 314 | _serialMINISMARTGPU.putc(x); |
emmanuelchio | 0:1c3989d263f4 | 315 | _serialMINISMARTGPU.putc(y>>8); |
emmanuelchio | 0:1c3989d263f4 | 316 | _serialMINISMARTGPU.putc(y); |
emmanuelchio | 0:1c3989d263f4 | 317 | |
emmanuelchio | 0:1c3989d263f4 | 318 | while(1){ |
emmanuelchio | 0:1c3989d263f4 | 319 | _serialMINISMARTGPU.putc(name[counter]); |
emmanuelchio | 0:1c3989d263f4 | 320 | if(name[counter]==0x00){ |
emmanuelchio | 0:1c3989d263f4 | 321 | break; |
emmanuelchio | 0:1c3989d263f4 | 322 | } |
emmanuelchio | 0:1c3989d263f4 | 323 | counter++; |
emmanuelchio | 0:1c3989d263f4 | 324 | } |
emmanuelchio | 0:1c3989d263f4 | 325 | return _serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 326 | |
emmanuelchio | 0:1c3989d263f4 | 327 | } |
emmanuelchio | 0:1c3989d263f4 | 328 | |
emmanuelchio | 0:1c3989d263f4 | 329 | /****************************************************************/ |
emmanuelchio | 0:1c3989d263f4 | 330 | //Those next functions return file execution status instead of ACK 'O' or NAK 'F' |
emmanuelchio | 0:1c3989d263f4 | 331 | /****************************************************************/ |
emmanuelchio | 0:1c3989d263f4 | 332 | |
emmanuelchio | 0:1c3989d263f4 | 333 | unsigned char MINISMARTGPU::SDfopen(unsigned char mode, char name[]){ |
emmanuelchio | 0:1c3989d263f4 | 334 | unsigned char counter=0; |
emmanuelchio | 0:1c3989d263f4 | 335 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 336 | |
emmanuelchio | 0:1c3989d263f4 | 337 | wait_ms(1); |
emmanuelchio | 0:1c3989d263f4 | 338 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 339 | _serialMINISMARTGPU.putc('O'); //file open |
emmanuelchio | 0:1c3989d263f4 | 340 | _serialMINISMARTGPU.putc(mode); |
emmanuelchio | 0:1c3989d263f4 | 341 | while(1){ |
emmanuelchio | 0:1c3989d263f4 | 342 | _serialMINISMARTGPU.putc(name[counter]); |
emmanuelchio | 0:1c3989d263f4 | 343 | if(name[counter]==0x00){ |
emmanuelchio | 0:1c3989d263f4 | 344 | break; |
emmanuelchio | 0:1c3989d263f4 | 345 | } |
emmanuelchio | 0:1c3989d263f4 | 346 | counter++; |
emmanuelchio | 0:1c3989d263f4 | 347 | } |
emmanuelchio | 0:1c3989d263f4 | 348 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 349 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 350 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 351 | } |
emmanuelchio | 0:1c3989d263f4 | 352 | |
emmanuelchio | 0:1c3989d263f4 | 353 | unsigned char MINISMARTGPU::SDfclose(){ |
emmanuelchio | 0:1c3989d263f4 | 354 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 355 | |
emmanuelchio | 0:1c3989d263f4 | 356 | wait_ms(5); |
emmanuelchio | 0:1c3989d263f4 | 357 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 358 | _serialMINISMARTGPU.putc('C'); //file close |
emmanuelchio | 0:1c3989d263f4 | 359 | |
emmanuelchio | 0:1c3989d263f4 | 360 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 361 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 362 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 363 | } |
emmanuelchio | 0:1c3989d263f4 | 364 | |
emmanuelchio | 0:1c3989d263f4 | 365 | unsigned char MINISMARTGPU::SDfsync(){ |
emmanuelchio | 0:1c3989d263f4 | 366 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 367 | |
emmanuelchio | 0:1c3989d263f4 | 368 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 369 | _serialMINISMARTGPU.putc('S'); //file sync |
emmanuelchio | 0:1c3989d263f4 | 370 | |
emmanuelchio | 0:1c3989d263f4 | 371 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 372 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 373 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 374 | } |
emmanuelchio | 0:1c3989d263f4 | 375 | |
emmanuelchio | 0:1c3989d263f4 | 376 | unsigned char MINISMARTGPU::SDfpointer(unsigned long position){ |
emmanuelchio | 0:1c3989d263f4 | 377 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 378 | |
emmanuelchio | 0:1c3989d263f4 | 379 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 380 | _serialMINISMARTGPU.putc('P'); //file sync |
emmanuelchio | 0:1c3989d263f4 | 381 | _serialMINISMARTGPU.putc(position>>24); |
emmanuelchio | 0:1c3989d263f4 | 382 | _serialMINISMARTGPU.putc(position>>16); |
emmanuelchio | 0:1c3989d263f4 | 383 | _serialMINISMARTGPU.putc(position>>8); |
emmanuelchio | 0:1c3989d263f4 | 384 | _serialMINISMARTGPU.putc(position); |
emmanuelchio | 0:1c3989d263f4 | 385 | |
emmanuelchio | 0:1c3989d263f4 | 386 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 387 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 388 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 389 | } |
emmanuelchio | 0:1c3989d263f4 | 390 | |
emmanuelchio | 0:1c3989d263f4 | 391 | unsigned char MINISMARTGPU::SDfread(unsigned int BTR, char buffer[], unsigned int *SRB){ //Bytes to Read, Read Buffer, Succesfully Readed Bytes |
emmanuelchio | 0:1c3989d263f4 | 392 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 393 | unsigned int x=0, sr=0; |
emmanuelchio | 0:1c3989d263f4 | 394 | |
emmanuelchio | 0:1c3989d263f4 | 395 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 396 | _serialMINISMARTGPU.putc('R'); //file read |
emmanuelchio | 0:1c3989d263f4 | 397 | _serialMINISMARTGPU.putc(BTR>>8); |
emmanuelchio | 0:1c3989d263f4 | 398 | _serialMINISMARTGPU.putc(BTR); |
emmanuelchio | 0:1c3989d263f4 | 399 | for(x=0;x<BTR;x++){ |
emmanuelchio | 0:1c3989d263f4 | 400 | buffer[x]=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 401 | } |
emmanuelchio | 0:1c3989d263f4 | 402 | sr=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 403 | sr=sr<<8; |
emmanuelchio | 0:1c3989d263f4 | 404 | sr|=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 405 | |
emmanuelchio | 0:1c3989d263f4 | 406 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 407 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 408 | *SRB = sr; |
emmanuelchio | 0:1c3989d263f4 | 409 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 410 | } |
emmanuelchio | 0:1c3989d263f4 | 411 | |
emmanuelchio | 0:1c3989d263f4 | 412 | unsigned char MINISMARTGPU::SDfwrite(unsigned int BTW, char buffer[], unsigned int *SWB){ //Bytes to Write, Write Buffer, Succesfully Written Bytes |
emmanuelchio | 0:1c3989d263f4 | 413 | unsigned char aux = 0; |
emmanuelchio | 0:1c3989d263f4 | 414 | unsigned int x=0, sw=0; |
emmanuelchio | 0:1c3989d263f4 | 415 | |
emmanuelchio | 0:1c3989d263f4 | 416 | wait_ms(1); |
emmanuelchio | 0:1c3989d263f4 | 417 | if(BTW>512){ //Mini SmartGPU accept to write more than 512 bytes, however this is not recommended, remove this IF for fully write support |
emmanuelchio | 0:1c3989d263f4 | 418 | aux = 19; //Invalid Parameter == 19 |
emmanuelchio | 0:1c3989d263f4 | 419 | }else{ |
emmanuelchio | 0:1c3989d263f4 | 420 | _serialMINISMARTGPU.putc('F'); //memory card file management |
emmanuelchio | 0:1c3989d263f4 | 421 | _serialMINISMARTGPU.putc('W'); //file write |
emmanuelchio | 0:1c3989d263f4 | 422 | _serialMINISMARTGPU.putc(BTW>>8); |
emmanuelchio | 0:1c3989d263f4 | 423 | _serialMINISMARTGPU.putc(BTW); |
emmanuelchio | 0:1c3989d263f4 | 424 | for(x=0;x<BTW;x++){ |
emmanuelchio | 0:1c3989d263f4 | 425 | _serialMINISMARTGPU.putc(buffer[x]); |
emmanuelchio | 0:1c3989d263f4 | 426 | } |
emmanuelchio | 0:1c3989d263f4 | 427 | sw=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 428 | sw=sw<<8; |
emmanuelchio | 0:1c3989d263f4 | 429 | sw|=_serialMINISMARTGPU.getc(); |
emmanuelchio | 0:1c3989d263f4 | 430 | |
emmanuelchio | 0:1c3989d263f4 | 431 | aux= _serialMINISMARTGPU.getc(); //Get FAT result |
emmanuelchio | 0:1c3989d263f4 | 432 | _serialMINISMARTGPU.getc(); //Discard 'O' or 'F' |
emmanuelchio | 0:1c3989d263f4 | 433 | *SWB = sw; |
emmanuelchio | 0:1c3989d263f4 | 434 | } |
emmanuelchio | 0:1c3989d263f4 | 435 | return aux; //Return FAT result |
emmanuelchio | 0:1c3989d263f4 | 436 | } |