Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

Display QVGA test.

// Built with BFTC Rev. 1.0.0, mer 20 agosto 2014 11:09:24

/*
    Copyright 2014 Digital Technology Art SRL
    This file is part of Blackfin Toolchain (BFTC) project.

    BFTC 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.

    BFTC 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 Name-Program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "main.h"

#include <stdlib.h>

unsigned randx(unsigned val)
{
    return Get_TimerCounter(TIMER_0) * 0x1961957 + val;
}

gCOL const colorIndex[16] ={TFT_BLACK,
                            TFT_NAVY,
                            TFT_DARK_GREEN,
                            TFT_DARK_CYAN,
                            TFT_MAROON,
                            TFT_PURPLE,
                            TFT_OLIVE,
                            TFT_LIGHT_GRAY,
                            TFT_DARK_GRAY,
                            TFT_BLUE,
                            TFT_GREEN,
                            TFT_CYAN,
                            TFT_RED,
                            TFT_MAGENTA,
                            TFT_YELLOW,
                            TFT_WHITE
};

void TFT_ColorTest()
{
    unsigned int        i,j;
    Set_TFThome();

    // Draw vertical stripes
    for(i = 0; i < 320; i++)
    {
        for(j = 0; j < 240; j++)
        {
            if(i > 279)                 Set_TFTdata16(TFT_BLACK);
            else if(i > 239)    Set_TFTdata16(TFT_BLUE);
            else if(i > 199)    Set_TFTdata16(TFT_GREEN);
            else if(i > 159)    Set_TFTdata16(TFT_CYAN);
            else if(i > 119)    Set_TFTdata16(TFT_RED);
            else if(i > 79)             Set_TFTdata16(TFT_MAGENTA);
            else if(i > 39)             Set_TFTdata16(TFT_YELLOW);
            else                                Set_TFTdata16(TFT_WHITE);
        }
    }
}

void CLineDemo()
{
    gInt x0, y0;
    gInt x1, y1;
    gInt color;   
    gInt no;
    const gInt CENTER_X = 160;
    const gInt CENTER_Y = 120;
    Set_TFThome();      // Set display window to maximum size
    for(no = 0; no < 5000; no++)
    {
        x0 = randx(x0) % 320;
        y0 = randx(y0) % 160;
        color = no % 16;
        x1 = 2 * CENTER_X - x0;
        y1 = 2 * CENTER_Y - y0;
        gxLine(x0, y0, x1, y1, colorIndex[color]);
    }
    gxClear(TFT_BLACK);
}

void CRectangleFilledDemo()
{
    gInt x0, y0;
    gInt x1, y1;
    gInt color;
    gInt no;
      
    for(no = 0; no < 500; no++)
    {
        x0 = randx(x0) % 160;
        y0 = randx(y0) % 120;
        color = no % 16;
        x1 = x0 + randx(x1) % 160;
        y1 = y0 + randx(y1) % 120;
        gxRectFilled(x0, y0, x1, y1, colorIndex[color]);
    }
    gxClear(TFT_BLACK);
}

void CRectangleDemo()
{
    gInt x0, y0;
    gInt x1, y1;
    gInt color;
    gInt no;
      
    for(no = 0; no < 5000; no++)
    {
        x0 = randx(x0) % 160;
        y0 = randx(y0) % 120;
        color = no % 16;
        x1 = x0 + randx(x1) % 160;
        y1 = y0 + randx(y1) % 120;
        gxRect(x0, y0, x1, y1, colorIndex[color]);
    }
    gxClear(TFT_BLACK);
}

void CCircleDemo()
{
    gInt        x0, y0;
    gInt        radius;
    gInt        color;
    gInt        no;
      
    for(no = 0; no < 2000; no++)
    {
        x0 = randx(x0) % 240;
        y0 = randx(y0) % 320;
        color = no % 16;
        radius = randx(radius) % 100;
        gxCircle(x0, y0, radius, colorIndex[color]);
    }
    gxClear(TFT_BLACK);
}

void TextDemo()
{
    char        buf[32];
    int         i;
    gxClear(TFT_BLACK);
    for(i = 0; i < 200; i++)
    {
        sprintf(buf, "COUNT = %04d", i);
        gxFontColorSize(TFT_YELLOW, TFT_BLACK, 1, 1);
        gxPutString(5, 10, buf);
        gxFontColorSize(TFT_BLACK, TFT_YELLOW, 1, 1);
        gxPutString(85, 10, buf);
        gxFontColorSize(TFT_BLUE, TFT_WHITE, 1, 1);
        gxPutString(165, 10, buf);
        gxFontColorSize(TFT_BLACK, TFT_GREEN, 1, 1);
        gxPutString(245, 10, buf);
        
        gxFontColorSize(TFT_YELLOW, TFT_BLACK, 1, 1);
        gxPutString(5, 20, buf);
        gxFontColorSize(TFT_BLACK, TFT_YELLOW, 1, 1);
        gxPutString(85, 20, buf);
        gxFontColorSize(TFT_BLUE, TFT_WHITE, 1, 1);
        gxPutString(165, 20, buf);
        gxFontColorSize(TFT_BLACK, TFT_GREEN, 1, 1);
        gxPutString(245, 20, buf);
    }
    gxClear(TFT_BLACK);
}

void TextDemoVarSize()
{
    char        buf[32];
    int         i, xs, ys;
    for(ys = 1; ys < 5; ys++)
        for(xs = 1; xs < 5; xs++)
        {
            gxClear(TFT_BLACK);
            gxFontColorSize(TFT_WHITE, TFT_BLACK, 1, 1);
            sprintf(buf, "X SIZE = %d, Y SIZE = %d", xs, ys);
            gxPutString(10, 10, buf);
            gxFontColorSize(TFT_GREEN, TFT_BLACK, xs, ys);
            for(i = 0; i < 100; i++)
            {
                sprintf(buf, "COUNT = %04d", i);
                gxPutString(10, 150, buf);
            }
        }
    gxClear(TFT_BLACK);
}

void Title()
{
    char        buf[32];
    int         i, n;
    int         size = 27;
    sprintf(buf, "... DEMO TFT Sharkduino ...");
    gxClear(TFT_BLACK);
    gxFontColorSize(TFT_WHITE, TFT_BLACK, 4, 4);
    for(n = 0; n < size; n++)
    {
        i = size - n - 1;
        gxPutString(10, 120, &buf[i]);
        DelayUs(150000);
    }
    
    for(n = 0; n < size; n++)
    {
        // Shift by one
        for(i = 1; i < size; i++)
            buf[size - i] = buf[size - i - 1];
        buf[0] = ' ';
        gxPutString(10, 120, buf);
        DelayUs(150000);
    }
}

int main(void)
{
    Set_PLL(16, 4);         // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz
    Set_Port();             // Set the port according to project set
    Set_Uart0(115200);      // printf is redirected to UART0
    
    Set_TimerCounter(TIMER_0);
    Set_TimerEnable(TIMER_0, true);
    
    Set_SPI(SPI_PP);
    Set_ExpansionPort(0xF0);
    Set_TFTlightPower(true);
    Set_TFTlight(15);
    Set_SPI(SPI_TFT);
    Set_TFTinit();

    while(1)                    // Main loop
    {
        Title();
        TFT_ColorTest();
        CRectangleFilledDemo();
        CLineDemo();
        CRectangleDemo();
        CCircleDemo();
        TextDemo();
        TextDemoVarSize();
    }
    return 0;
}

Generated on Tue Apr 7 20:07:44 2015 for BF592A Library by doxygen 1.3.1