This library is the modified library of 4DGL by Stephane ROCHON <stephane.rochon at free.fr> modified at drawImage() by Kazushi Mukaiyama <i@kazushi.info>
TFT_4DGL_Graphics.cpp
- Committer:
- kazushi2008
- Date:
- 2010-10-29
- Revision:
- 0:c2aeac7c2d15
File content as of revision 0:c2aeac7c2d15:
// // TFT_4DGL is a class to drive 4D Systems TFT touch screens // // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> // modified at drawImage() by Kazushi Mukaiyama <i@kazushi.info> // // TFT_4DGL is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // TFT_4DGL is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. #include "mbed.h" #include "TFT_4DGL.h" //**************************************************************************************************** void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) char command[9]= ""; command[0] = CIRCLE; command[1] = (x >> 8) & 0xFF; command[2] = x & 0xFF; command[3] = (y >> 8) & 0xFF; command[4] = y & 0xFF; command[5] = (radius >> 8) & 0xFF; command[6] = radius & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 9); } //**************************************************************************************************** void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle char command[15]= ""; command[0] = TRIANGLE; command[1] = (x1 >> 8) & 0xFF; command[2] = x1 & 0xFF; command[3] = (y1 >> 8) & 0xFF; command[4] = y1 & 0xFF; command[5] = (x2 >> 8) & 0xFF; command[6] = x2 & 0xFF; command[7] = (y2 >> 8) & 0xFF; command[8] = y2 & 0xFF; command[9] = (x3 >> 8) & 0xFF; command[10] = x3 & 0xFF; command[11] = (y3 >> 8) & 0xFF; command[12] = y3 & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 15); } //**************************************************************************************************** void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line char command[11]= ""; command[0] = LINE; command[1] = (x1 >> 8) & 0xFF; command[2] = x1 & 0xFF; command[3] = (y1 >> 8) & 0xFF; command[4] = y1 & 0xFF; command[5] = (x2 >> 8) & 0xFF; command[6] = x2 & 0xFF; command[7] = (y2 >> 8) & 0xFF; command[8] = y2 & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 11); } //**************************************************************************************************** void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle char command[11]= ""; command[0] = RECTANGLE; command[1] = (x1 >> 8) & 0xFF; command[2] = x1 & 0xFF; command[3] = (y1 >> 8) & 0xFF; command[4] = y1 & 0xFF; command[5] = (x2 >> 8) & 0xFF; command[6] = x2 & 0xFF; command[7] = (y2 >> 8) & 0xFF; command[8] = y2 & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 11); } //**************************************************************************************************** void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse char command[11]= ""; command[0] = ELLIPSE; command[1] = (x >> 8) & 0xFF; command[2] = x & 0xFF; command[3] = (y >> 8) & 0xFF; command[4] = y & 0xFF; command[5] = (radius_x >> 8) & 0xFF; command[6] = radius_x & 0xFF; command[7] = (radius_y >> 8) & 0xFF; command[8] = radius_y & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 11); } //**************************************************************************************************** void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel char command[7]= ""; command[0] = PIXEL; command[1] = (x >> 8) & 0xFF; command[2] = x & 0xFF; command[3] = (y >> 8) & 0xFF; command[4] = y & 0xFF; int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color writeCOMMAND(command, 7); } //****************************************************************************************************** int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data char command[5]= ""; command[0] = READPIXEL; command[1] = (x >> 8) & 0xFF; command[2] = x & 0xFF; command[3] = (y >> 8) & 0xFF; command[4] = y & 0xFF; int i, temp = 0, color = 0, resp = 0; char response[2] = ""; freeBUFFER(); for (i = 0; i < 5; i++) { // send all chars to serial port writeBYTE(command[i]); } while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer while (_cmd.readable()) { temp = _cmd.getc(); response[resp++] = (char)temp; } color = ((response[0] << 8) + response[1]); return color; // WARNING : this is 16bits color, not 24bits... need to be fixed } //****************************************************************************************************** void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { char command[13]= ""; command[0] = SCREENCOPY; command[1] = (xs >> 8) & 0xFF; command[2] = xs & 0xFF; command[3] = (ys >> 8) & 0xFF; command[4] = ys & 0xFF; command[5] = (xd >> 8) & 0xFF; command[6] = xd & 0xFF; command[7] = (yd >> 8) & 0xFF; command[8] = yd & 0xFF; command[9] = (width >> 8) & 0xFF; command[10] = width & 0xFF; command[11] = (height >> 8) & 0xFF; command[12] = height & 0xFF; writeCOMMAND(command, 13); } //**************************************************************************************************** void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME char command[2]= ""; command[0] = PENSIZE; command[1] = mode; writeCOMMAND(command, 2); } //**************************************************************************************************** void TFT_4DGL :: displayImage(char x, char y, char w, char h, int ad) { char command[10]= ""; char hi, mid, lo; hi = (ad >> 16)&0x0000FF; //Work out the sector address mid = (ad >> 8)&0x0000FF; lo = ad&0x0000FF; command[0] = 0x40; command[1] = 0x49; command[2] = x; command[3] = y; command[4] = w; command[5] = h; command[6] = 16; //colour mode 16 command[7] = hi; command[8] = mid; command[9] = lo; writeCOMMAND(command, 10); } //void TFT_4DGL :: animImages(char x, char y, char w, char h, int ad, int frames, bool loop = false) //{ // int size = 0x18; // int adress = ad + (count * size); // displayImage(x, y, w, h, adress) // count++; // if(count >= ((data[3]<<8)+data[4])) // { // count = 0; // if(data[8]==0) OLED4Dplay = false; // } //} //**************************************************************************************************** void TFT_4DGL :: displayMovie(char x, char y, char w, char h, int ad, int frames) { char command[18]= ""; char hi, mid, lo, mfr, lfr; hi = (ad >> 16)&0x0000FF; //Work out the sector address mid = (ad >> 8)&0x0000FF; lo = ad&0x0000FF; mfr = (frames >> 8)&0x0000FF; lfr = frames&0x0000FF; command[0] = 0x40; command[1] = 0x56; command[2] = x; command[3] = y; command[4] = w; command[5] = h; command[6] = 16; //colour mode 16 command[7] = 0x27; //delay command[8] = mfr; command[9] = lfr; command[10] = hi; command[11] = mid; command[12] = lo; command[13] = 0xB0; command[14] = 0x00; command[15] = 0x00; command[16] = 0x00; command[17] = 0x00; writeCOMMAND(command, 18); }