Rihards Balass / 4DGL-mbed-32PTU

Picaso_4DGL-32PTU_graphics.cpp

Committer:
CaptainR
Date:
2016-09-09
Revision:
2:81eaaa491a02
Parent:
1:e2337e2653e1
Child:
3:dcfbceb81fef

File content as of revision 2:81eaaa491a02:

//
//  Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
//  Tested with NUCLEO L152RE development board
//  Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
//
// Picaso_4DGL-32PTU 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.
//
// Picaso_4DGL-32PTU 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 can see GNU General Public License at <http://www.gnu.org/licenses/>.
//

#include "mbed.h"
#include "Picaso_4DGL-32PTU.h"

//**************************************************************************
// The Clear Screen command clears the screen using the current background colour.
// This command brings some of the settings back to default; such as,
//  Transparency turned OFF
//  Outline colour set to BLACK
//  Opacity set to OPAQUE
//  Pen set to OUTLINE
//  Line patterns set to OFF
//  Right text margin set to full width
//  Text magnifications set to 1
//  All origins set to 0:0
// The alternative to maintain settings and clear screen is 
// to draw a filled rectangle with the required background colour.
//**************************************************************************
void TFT_4DGL :: cls() {  // clear screen

    char command[2] = "";
    
    command[0] = (CLS >> (8*1)) & 0xff;
    command[1] = (CLS >> (8*0)) & 0xff;
    
    writeCOMMAND(command, 2);
}

//**************************************************************************
// The Change Colour command changes all oldColour pixels to newColour 
// within the clipping window area.
//**************************************************************************
void TFT_4DGL :: changeColor(short oldColor, short newColor) {
    
    char command[6] = "";
    
    command[0] = (CHANGE_COLOR >> (8*1)) & 0xff;
    command[1] = (CHANGE_COLOR >> (8*0)) & 0xff;
    command[2] = (oldColor >> (8*1)) & 0xff;
    command[3] = (oldColor >> (8*0)) & 0xff;
    command[4] = (newColor >> (8*1)) & 0xff;
    command[5] = (newColor >> (8*0)) & 0xff;
    
    writeCOMMAND(command, 6);
}

//**************************************************************************
// The Draw Circle command draws a circle with centre point x, y 
// with radius r using the specified colour.
//**************************************************************************
void TFT_4DGL :: drawCircle(short x, short y, short r, short color) {
    
    char command[10] = "";
    
    command[0] = (DRAW_CIRCLE >> (8*1)) & 0xff;
    command[1] = (DRAW_CIRCLE >> (8*0)) & 0xff;
    command[2] = (x >> (8*1)) & 0xff;
    command[3] = (x >> (8*0)) & 0xff;
    command[4] = (y >> (8*1)) & 0xff;
    command[5] = (y >> (8*0)) & 0xff;
    command[6] = (r >> (8*1)) & 0xff;
    command[7] = (r >> (8*0)) & 0xff;
    command[8] = (color >> (8*1)) & 0xff;
    command[9] = (color >> (8*0)) & 0xff;
    
    writeCOMMAND(command, 10);
}