Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
Diff: main.cpp
- Revision:
- 0:aa55c6eb6867
- Child:
- 1:7952d133e78c
- Child:
- 4:a48fc7a3bda9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 03 16:32:08 2016 +0000 @@ -0,0 +1,266 @@ +/* Demo for mbed Library for FTDI FT800 Enbedded Video Engine "EVE" +Updated for FTDI FT810 driver and 800x480 display. + * by Peter Drescher, DC2PD 2014 + * Released under the MIT License: http://mbed.org/license/mit */ + +#include "mbed.h" +#include "FT_Platform.h" +#include "FT_color.h" +#include "stdio.h" + +#define SAMAPP_DELAY_BTW_APIS (1000) +#define SAMAPP_ENABLE_DELAY() Ft_Gpu_Hal_Sleep(SAMAPP_DELAY_BTW_APIS) +#define SAMAPP_ENABLE_DELAY_VALUE(x) Ft_Gpu_Hal_Sleep(x) + +#define Nucleo_F303K8 +//#define K22 + + +#ifdef Nucleo_F303K8 +FT800 TFT(PB_5,PB_4,PB_3,PA_11,PA_8,PF_1); // the FT800 is connected to SPI 5-7, then we have CS, INT, PD +#endif + +#ifdef K22 +FT800 TFT(D11,D12,D13,D10,D9,D8); // the FT800 is connected to SPI 5-7, then we have CS, INT, PD +#endif + +//Analog inputs and outputs are normalized +AnalogIn Feedback(A0); +AnalogOut Control(A3); + +// global Vars +unsigned int r,b,g,PressDown, PressUp ; +double xyz = 10.13; +char buffer[50]; + +// function to convert hue , saturation and value to RGB +// see http://en.wikipedia.org/wiki/HSL_and_HSV +void hsv2rgb(double H,double S, double V) +{ + double f,h,p,q,t; + int i; + if( S == 0.0) { + r = V * 255; + g = V * 255; + b = V * 255; + return; + } + if(H > 480.0) H = 0.0; // check values + if(S > 1.0) S = 1.0; + if(S < 0.0) S = 0.0; + if(V > 1.0) V = 1.0; + if(V < 0.0) V = 0.0; + + h = H / 60.0; + i = (int) h; + f = h - i; + p = V * (1.0 - S); + q = V * (1.0 - (S * f)); + t = V * (1.0 - (S * (1.0 - f))); + + switch(i) { + case 0: + r = V * 255; + g = t * 255; + b = p * 255; + break; + case 1: + r = q * 255; + g = V * 255; + b = p * 255; + break; + case 2: + r = p * 255; + g = V * 255; + b = t * 255; + break; + case 3: + r = p * 255; + g = q * 255; + b = V * 255; + break; + case 4: + r = t * 255; + g = p * 255; + b = V * 255; + break; + case 5: + default: + r = V * 255; + g = p * 255; + b = q * 255; + break; + } +} + + +/***************************************************************************/ +/* Show a Screen with Text for 5 seconds */ +/* A spinner shows the delay */ +/***************************************************************************/ + +ft_void_t Start_Screen(ft_char8_t *str) +{ + TFT.DLstart(); // start a new display command list + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white + TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer + TFT.DL(COLOR_RGB(0x80,0x80,0x00)); // set current color + TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 + TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel!"); // draw Text with font 31 + TFT.DL(COLOR_RGB(0x00,0xFF,0x00)); // change current color + TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner + + TFT.DL(DISPLAY()); // Display the image + TFT.Swap(); // Swap the current display list + TFT.Flush_Co_Buffer(); // Download the command list into fifo + + TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation + TFT.Sleep(1000); // Wait 5 s to show +} + +// construct the screen and download it to the LCD +void screen_1(unsigned int color,unsigned int bright) +{ + TFT.DLstart(); // start a new display command list + TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer + TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white + sprintf(buffer, "%.2f", xyz); + TFT.Text(500, 71, 31, 0, buffer); + + //TFT.Number(545, 135, 31, 0, printf(buffer, "%f", xyz)); + TFT.DL(TAG(1)); // assign TAG value 1 + //TFT.FgColor(COLOR_RGB(0xff,0,0)); // forground color red + TFT.Dial(249, 86, 55, 0, color); // dial for color + TFT.DL(TAG(2)); // assign TAG value 2 + //TFT.FgColor(COLOR_RGB(0,0xff,0)); // forground color green + TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness + TFT.Text(22, 84, 30, 0, "Color"); // text Color + TFT.Text(22, 208, 30, 0, "Brightness");// text Brightness + TFT.DL(TAG(3)); // assign TAG value 2 + TFT.Button(22, 300,200,100,31,PressDown,"Down!"); //test button + TFT.GradColor(COLOR_RGB(0xff,0,0)); + TFT.DL(TAG(4)); // assign TAG value 2 + TFT.Button(250, 300,200,100,31,PressUp,"Up!"); //test button + TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white + + + TFT.DL(POINT_SIZE(100)); // color point around the dial + TFT.DL(BEGIN(FTPOINTS)); + TFT.DL(COLOR_RGB(0x0,0x0,0xff)); // color of next point + TFT.DL(VERTEX2II(183,47,0,0)); // set point x,y + TFT.DL(COLOR_RGB(0xff,0x0,0x0)); + TFT.DL(VERTEX2II(249,162,0,0)); + TFT.DL(COLOR_RGB(0xff,0x0,0xff)); + TFT.DL(VERTEX2II(183,123,0,0)); + TFT.DL(COLOR_RGB(0xff,0xff,0x0)); + TFT.DL(VERTEX2II(317,123,0,0)); + TFT.DL(COLOR_RGB(0x0,0xff,0xff)); + TFT.DL(VERTEX2II(249,11,0,0)); + TFT.DL(COLOR_RGB(0x0,0xff,0x00)); + TFT.DL(VERTEX2II(317,50,0,0)); + + TFT.DL(SCISSOR_XY(10,10)); // define sub area starting at 10,10 + TFT.DL(SCISSOR_SIZE(50,50)); // size 50,50 + hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings + TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b + TFT.DL(CLEAR(1,1,1)); // fill the area + + + + + + /* TFT.DL(SCISSOR_XY(500,10)); // define sub area starting at 10,10 + TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200 + hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings + TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b + TFT.DL(CLEAR(1,1,1)); // fill the area + + TFT.DL(SCISSOR_XY(500,210)); // define sub area starting at 10,10 + TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200 + hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings + TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b + TFT.DL(CLEAR(1,1,1)); // fill the area + */ + TFT.DL(DISPLAY()); // Display the image + TFT.Swap(); // Swap the current display list + TFT.Flush_Co_Buffer(); // Download the command list into fifo + TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation +} + + + +int main() +{ + + + unsigned int color = 0,bright = 0; + ft_uint32_t TrackRegisterVal = 0; // touch track + + + + + + + Start_Screen("5"); // Show start screen + Start_Screen("4"); // Show start screen + Start_Screen("3"); // Show start screen + Start_Screen("2"); // Show start screen + Start_Screen("1"); // Show start screen + TFT.Calibrate(); // calibrate the touch screen + + /* Set the tracker for the dial - define the Area for touching */ + TFT.Track(249, 86, 1, 1, 1); // Dial - dimension 1,1 means rotary + TFT.Track(179, 199, 277, 48, 2); // Slider + TFT.Flush_Co_Buffer(); // Download the commands into fifo + TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation + screen_1(color,bright); // paint screen + + /* the demo is updating the screen in a endless loop */ + while(1) { + ft_uint8_t tagval = 0; + TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched + tagval = TrackRegisterVal & 0xff; + if(0 != tagval) { // touch -> get new values + if(1 == tagval) { // the dial touched + color = TrackRegisterVal>>16; // get the new value + } else if(2 == tagval) { // the slider is touched + bright = TrackRegisterVal>>16; // get new slider value + bright = bright * 255/65536; // scale it down to 255 + } else if(3 == tagval) { // the slider is touched + PressDown = OPT_FLAT; + if(Control <= 0) + { + Control = 0; + } + else{ + Control = Control - 0.01; + } + // bright = 0; // scale it down to 255 + } + else if(4 == tagval) { // the slider is touched + PressUp = OPT_FLAT; + if(Control >= 1) + { + Control = 1; + } + else{ + Control = Control + 0.01; + } + // bright = 255; // scale it down to 255 + } + + //xyz = Control; + // screen_1(color,bright); // paint new screen + // TFT.Sleep(10); // wait 10ms for next check + } + + xyz = Feedback; + screen_1(color,bright); // paint new screen + TFT.Sleep(10); // wait 10ms for next time to repaint the screen + PressDown = 0; // Clear Buttons being pressed + PressUp = 0; + } // end of display loop +} + + +