basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cratliff
Date:
Thu Mar 03 16:32:08 2016 +0000
Revision:
0:aa55c6eb6867
Child:
1:7952d133e78c
Child:
4:a48fc7a3bda9
Something to share

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cratliff 0:aa55c6eb6867 1 /* Demo for mbed Library for FTDI FT800 Enbedded Video Engine "EVE"
cratliff 0:aa55c6eb6867 2 Updated for FTDI FT810 driver and 800x480 display.
cratliff 0:aa55c6eb6867 3 * by Peter Drescher, DC2PD 2014
cratliff 0:aa55c6eb6867 4 * Released under the MIT License: http://mbed.org/license/mit */
cratliff 0:aa55c6eb6867 5
cratliff 0:aa55c6eb6867 6 #include "mbed.h"
cratliff 0:aa55c6eb6867 7 #include "FT_Platform.h"
cratliff 0:aa55c6eb6867 8 #include "FT_color.h"
cratliff 0:aa55c6eb6867 9 #include "stdio.h"
cratliff 0:aa55c6eb6867 10
cratliff 0:aa55c6eb6867 11 #define SAMAPP_DELAY_BTW_APIS (1000)
cratliff 0:aa55c6eb6867 12 #define SAMAPP_ENABLE_DELAY() Ft_Gpu_Hal_Sleep(SAMAPP_DELAY_BTW_APIS)
cratliff 0:aa55c6eb6867 13 #define SAMAPP_ENABLE_DELAY_VALUE(x) Ft_Gpu_Hal_Sleep(x)
cratliff 0:aa55c6eb6867 14
cratliff 0:aa55c6eb6867 15 #define Nucleo_F303K8
cratliff 0:aa55c6eb6867 16 //#define K22
cratliff 0:aa55c6eb6867 17
cratliff 0:aa55c6eb6867 18
cratliff 0:aa55c6eb6867 19 #ifdef Nucleo_F303K8
cratliff 0:aa55c6eb6867 20 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
cratliff 0:aa55c6eb6867 21 #endif
cratliff 0:aa55c6eb6867 22
cratliff 0:aa55c6eb6867 23 #ifdef K22
cratliff 0:aa55c6eb6867 24 FT800 TFT(D11,D12,D13,D10,D9,D8); // the FT800 is connected to SPI 5-7, then we have CS, INT, PD
cratliff 0:aa55c6eb6867 25 #endif
cratliff 0:aa55c6eb6867 26
cratliff 0:aa55c6eb6867 27 //Analog inputs and outputs are normalized
cratliff 0:aa55c6eb6867 28 AnalogIn Feedback(A0);
cratliff 0:aa55c6eb6867 29 AnalogOut Control(A3);
cratliff 0:aa55c6eb6867 30
cratliff 0:aa55c6eb6867 31 // global Vars
cratliff 0:aa55c6eb6867 32 unsigned int r,b,g,PressDown, PressUp ;
cratliff 0:aa55c6eb6867 33 double xyz = 10.13;
cratliff 0:aa55c6eb6867 34 char buffer[50];
cratliff 0:aa55c6eb6867 35
cratliff 0:aa55c6eb6867 36 // function to convert hue , saturation and value to RGB
cratliff 0:aa55c6eb6867 37 // see http://en.wikipedia.org/wiki/HSL_and_HSV
cratliff 0:aa55c6eb6867 38 void hsv2rgb(double H,double S, double V)
cratliff 0:aa55c6eb6867 39 {
cratliff 0:aa55c6eb6867 40 double f,h,p,q,t;
cratliff 0:aa55c6eb6867 41 int i;
cratliff 0:aa55c6eb6867 42 if( S == 0.0) {
cratliff 0:aa55c6eb6867 43 r = V * 255;
cratliff 0:aa55c6eb6867 44 g = V * 255;
cratliff 0:aa55c6eb6867 45 b = V * 255;
cratliff 0:aa55c6eb6867 46 return;
cratliff 0:aa55c6eb6867 47 }
cratliff 0:aa55c6eb6867 48 if(H > 480.0) H = 0.0; // check values
cratliff 0:aa55c6eb6867 49 if(S > 1.0) S = 1.0;
cratliff 0:aa55c6eb6867 50 if(S < 0.0) S = 0.0;
cratliff 0:aa55c6eb6867 51 if(V > 1.0) V = 1.0;
cratliff 0:aa55c6eb6867 52 if(V < 0.0) V = 0.0;
cratliff 0:aa55c6eb6867 53
cratliff 0:aa55c6eb6867 54 h = H / 60.0;
cratliff 0:aa55c6eb6867 55 i = (int) h;
cratliff 0:aa55c6eb6867 56 f = h - i;
cratliff 0:aa55c6eb6867 57 p = V * (1.0 - S);
cratliff 0:aa55c6eb6867 58 q = V * (1.0 - (S * f));
cratliff 0:aa55c6eb6867 59 t = V * (1.0 - (S * (1.0 - f)));
cratliff 0:aa55c6eb6867 60
cratliff 0:aa55c6eb6867 61 switch(i) {
cratliff 0:aa55c6eb6867 62 case 0:
cratliff 0:aa55c6eb6867 63 r = V * 255;
cratliff 0:aa55c6eb6867 64 g = t * 255;
cratliff 0:aa55c6eb6867 65 b = p * 255;
cratliff 0:aa55c6eb6867 66 break;
cratliff 0:aa55c6eb6867 67 case 1:
cratliff 0:aa55c6eb6867 68 r = q * 255;
cratliff 0:aa55c6eb6867 69 g = V * 255;
cratliff 0:aa55c6eb6867 70 b = p * 255;
cratliff 0:aa55c6eb6867 71 break;
cratliff 0:aa55c6eb6867 72 case 2:
cratliff 0:aa55c6eb6867 73 r = p * 255;
cratliff 0:aa55c6eb6867 74 g = V * 255;
cratliff 0:aa55c6eb6867 75 b = t * 255;
cratliff 0:aa55c6eb6867 76 break;
cratliff 0:aa55c6eb6867 77 case 3:
cratliff 0:aa55c6eb6867 78 r = p * 255;
cratliff 0:aa55c6eb6867 79 g = q * 255;
cratliff 0:aa55c6eb6867 80 b = V * 255;
cratliff 0:aa55c6eb6867 81 break;
cratliff 0:aa55c6eb6867 82 case 4:
cratliff 0:aa55c6eb6867 83 r = t * 255;
cratliff 0:aa55c6eb6867 84 g = p * 255;
cratliff 0:aa55c6eb6867 85 b = V * 255;
cratliff 0:aa55c6eb6867 86 break;
cratliff 0:aa55c6eb6867 87 case 5:
cratliff 0:aa55c6eb6867 88 default:
cratliff 0:aa55c6eb6867 89 r = V * 255;
cratliff 0:aa55c6eb6867 90 g = p * 255;
cratliff 0:aa55c6eb6867 91 b = q * 255;
cratliff 0:aa55c6eb6867 92 break;
cratliff 0:aa55c6eb6867 93 }
cratliff 0:aa55c6eb6867 94 }
cratliff 0:aa55c6eb6867 95
cratliff 0:aa55c6eb6867 96
cratliff 0:aa55c6eb6867 97 /***************************************************************************/
cratliff 0:aa55c6eb6867 98 /* Show a Screen with Text for 5 seconds */
cratliff 0:aa55c6eb6867 99 /* A spinner shows the delay */
cratliff 0:aa55c6eb6867 100 /***************************************************************************/
cratliff 0:aa55c6eb6867 101
cratliff 0:aa55c6eb6867 102 ft_void_t Start_Screen(ft_char8_t *str)
cratliff 0:aa55c6eb6867 103 {
cratliff 0:aa55c6eb6867 104 TFT.DLstart(); // start a new display command list
cratliff 0:aa55c6eb6867 105 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
cratliff 0:aa55c6eb6867 106 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cratliff 0:aa55c6eb6867 107 TFT.DL(COLOR_RGB(0x80,0x80,0x00)); // set current color
cratliff 0:aa55c6eb6867 108 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
cratliff 0:aa55c6eb6867 109 TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel!"); // draw Text with font 31
cratliff 0:aa55c6eb6867 110 TFT.DL(COLOR_RGB(0x00,0xFF,0x00)); // change current color
cratliff 0:aa55c6eb6867 111 TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner
cratliff 0:aa55c6eb6867 112
cratliff 0:aa55c6eb6867 113 TFT.DL(DISPLAY()); // Display the image
cratliff 0:aa55c6eb6867 114 TFT.Swap(); // Swap the current display list
cratliff 0:aa55c6eb6867 115 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cratliff 0:aa55c6eb6867 116
cratliff 0:aa55c6eb6867 117 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 118 TFT.Sleep(1000); // Wait 5 s to show
cratliff 0:aa55c6eb6867 119 }
cratliff 0:aa55c6eb6867 120
cratliff 0:aa55c6eb6867 121 // construct the screen and download it to the LCD
cratliff 0:aa55c6eb6867 122 void screen_1(unsigned int color,unsigned int bright)
cratliff 0:aa55c6eb6867 123 {
cratliff 0:aa55c6eb6867 124 TFT.DLstart(); // start a new display command list
cratliff 0:aa55c6eb6867 125 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cratliff 0:aa55c6eb6867 126 TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white
cratliff 0:aa55c6eb6867 127 sprintf(buffer, "%.2f", xyz);
cratliff 0:aa55c6eb6867 128 TFT.Text(500, 71, 31, 0, buffer);
cratliff 0:aa55c6eb6867 129
cratliff 0:aa55c6eb6867 130 //TFT.Number(545, 135, 31, 0, printf(buffer, "%f", xyz));
cratliff 0:aa55c6eb6867 131 TFT.DL(TAG(1)); // assign TAG value 1
cratliff 0:aa55c6eb6867 132 //TFT.FgColor(COLOR_RGB(0xff,0,0)); // forground color red
cratliff 0:aa55c6eb6867 133 TFT.Dial(249, 86, 55, 0, color); // dial for color
cratliff 0:aa55c6eb6867 134 TFT.DL(TAG(2)); // assign TAG value 2
cratliff 0:aa55c6eb6867 135 //TFT.FgColor(COLOR_RGB(0,0xff,0)); // forground color green
cratliff 0:aa55c6eb6867 136 TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness
cratliff 0:aa55c6eb6867 137 TFT.Text(22, 84, 30, 0, "Color"); // text Color
cratliff 0:aa55c6eb6867 138 TFT.Text(22, 208, 30, 0, "Brightness");// text Brightness
cratliff 0:aa55c6eb6867 139 TFT.DL(TAG(3)); // assign TAG value 2
cratliff 0:aa55c6eb6867 140 TFT.Button(22, 300,200,100,31,PressDown,"Down!"); //test button
cratliff 0:aa55c6eb6867 141 TFT.GradColor(COLOR_RGB(0xff,0,0));
cratliff 0:aa55c6eb6867 142 TFT.DL(TAG(4)); // assign TAG value 2
cratliff 0:aa55c6eb6867 143 TFT.Button(250, 300,200,100,31,PressUp,"Up!"); //test button
cratliff 0:aa55c6eb6867 144 TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white
cratliff 0:aa55c6eb6867 145
cratliff 0:aa55c6eb6867 146
cratliff 0:aa55c6eb6867 147 TFT.DL(POINT_SIZE(100)); // color point around the dial
cratliff 0:aa55c6eb6867 148 TFT.DL(BEGIN(FTPOINTS));
cratliff 0:aa55c6eb6867 149 TFT.DL(COLOR_RGB(0x0,0x0,0xff)); // color of next point
cratliff 0:aa55c6eb6867 150 TFT.DL(VERTEX2II(183,47,0,0)); // set point x,y
cratliff 0:aa55c6eb6867 151 TFT.DL(COLOR_RGB(0xff,0x0,0x0));
cratliff 0:aa55c6eb6867 152 TFT.DL(VERTEX2II(249,162,0,0));
cratliff 0:aa55c6eb6867 153 TFT.DL(COLOR_RGB(0xff,0x0,0xff));
cratliff 0:aa55c6eb6867 154 TFT.DL(VERTEX2II(183,123,0,0));
cratliff 0:aa55c6eb6867 155 TFT.DL(COLOR_RGB(0xff,0xff,0x0));
cratliff 0:aa55c6eb6867 156 TFT.DL(VERTEX2II(317,123,0,0));
cratliff 0:aa55c6eb6867 157 TFT.DL(COLOR_RGB(0x0,0xff,0xff));
cratliff 0:aa55c6eb6867 158 TFT.DL(VERTEX2II(249,11,0,0));
cratliff 0:aa55c6eb6867 159 TFT.DL(COLOR_RGB(0x0,0xff,0x00));
cratliff 0:aa55c6eb6867 160 TFT.DL(VERTEX2II(317,50,0,0));
cratliff 0:aa55c6eb6867 161
cratliff 0:aa55c6eb6867 162 TFT.DL(SCISSOR_XY(10,10)); // define sub area starting at 10,10
cratliff 0:aa55c6eb6867 163 TFT.DL(SCISSOR_SIZE(50,50)); // size 50,50
cratliff 0:aa55c6eb6867 164 hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings
cratliff 0:aa55c6eb6867 165 TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b
cratliff 0:aa55c6eb6867 166 TFT.DL(CLEAR(1,1,1)); // fill the area
cratliff 0:aa55c6eb6867 167
cratliff 0:aa55c6eb6867 168
cratliff 0:aa55c6eb6867 169
cratliff 0:aa55c6eb6867 170
cratliff 0:aa55c6eb6867 171
cratliff 0:aa55c6eb6867 172 /* TFT.DL(SCISSOR_XY(500,10)); // define sub area starting at 10,10
cratliff 0:aa55c6eb6867 173 TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200
cratliff 0:aa55c6eb6867 174 hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings
cratliff 0:aa55c6eb6867 175 TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b
cratliff 0:aa55c6eb6867 176 TFT.DL(CLEAR(1,1,1)); // fill the area
cratliff 0:aa55c6eb6867 177
cratliff 0:aa55c6eb6867 178 TFT.DL(SCISSOR_XY(500,210)); // define sub area starting at 10,10
cratliff 0:aa55c6eb6867 179 TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200
cratliff 0:aa55c6eb6867 180 hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings
cratliff 0:aa55c6eb6867 181 TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b
cratliff 0:aa55c6eb6867 182 TFT.DL(CLEAR(1,1,1)); // fill the area
cratliff 0:aa55c6eb6867 183 */
cratliff 0:aa55c6eb6867 184 TFT.DL(DISPLAY()); // Display the image
cratliff 0:aa55c6eb6867 185 TFT.Swap(); // Swap the current display list
cratliff 0:aa55c6eb6867 186 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cratliff 0:aa55c6eb6867 187 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 188 }
cratliff 0:aa55c6eb6867 189
cratliff 0:aa55c6eb6867 190
cratliff 0:aa55c6eb6867 191
cratliff 0:aa55c6eb6867 192 int main()
cratliff 0:aa55c6eb6867 193 {
cratliff 0:aa55c6eb6867 194
cratliff 0:aa55c6eb6867 195
cratliff 0:aa55c6eb6867 196 unsigned int color = 0,bright = 0;
cratliff 0:aa55c6eb6867 197 ft_uint32_t TrackRegisterVal = 0; // touch track
cratliff 0:aa55c6eb6867 198
cratliff 0:aa55c6eb6867 199
cratliff 0:aa55c6eb6867 200
cratliff 0:aa55c6eb6867 201
cratliff 0:aa55c6eb6867 202
cratliff 0:aa55c6eb6867 203
cratliff 0:aa55c6eb6867 204 Start_Screen("5"); // Show start screen
cratliff 0:aa55c6eb6867 205 Start_Screen("4"); // Show start screen
cratliff 0:aa55c6eb6867 206 Start_Screen("3"); // Show start screen
cratliff 0:aa55c6eb6867 207 Start_Screen("2"); // Show start screen
cratliff 0:aa55c6eb6867 208 Start_Screen("1"); // Show start screen
cratliff 0:aa55c6eb6867 209 TFT.Calibrate(); // calibrate the touch screen
cratliff 0:aa55c6eb6867 210
cratliff 0:aa55c6eb6867 211 /* Set the tracker for the dial - define the Area for touching */
cratliff 0:aa55c6eb6867 212 TFT.Track(249, 86, 1, 1, 1); // Dial - dimension 1,1 means rotary
cratliff 0:aa55c6eb6867 213 TFT.Track(179, 199, 277, 48, 2); // Slider
cratliff 0:aa55c6eb6867 214 TFT.Flush_Co_Buffer(); // Download the commands into fifo
cratliff 0:aa55c6eb6867 215 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 216 screen_1(color,bright); // paint screen
cratliff 0:aa55c6eb6867 217
cratliff 0:aa55c6eb6867 218 /* the demo is updating the screen in a endless loop */
cratliff 0:aa55c6eb6867 219 while(1) {
cratliff 0:aa55c6eb6867 220 ft_uint8_t tagval = 0;
cratliff 0:aa55c6eb6867 221 TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched
cratliff 0:aa55c6eb6867 222 tagval = TrackRegisterVal & 0xff;
cratliff 0:aa55c6eb6867 223 if(0 != tagval) { // touch -> get new values
cratliff 0:aa55c6eb6867 224 if(1 == tagval) { // the dial touched
cratliff 0:aa55c6eb6867 225 color = TrackRegisterVal>>16; // get the new value
cratliff 0:aa55c6eb6867 226 } else if(2 == tagval) { // the slider is touched
cratliff 0:aa55c6eb6867 227 bright = TrackRegisterVal>>16; // get new slider value
cratliff 0:aa55c6eb6867 228 bright = bright * 255/65536; // scale it down to 255
cratliff 0:aa55c6eb6867 229 } else if(3 == tagval) { // the slider is touched
cratliff 0:aa55c6eb6867 230 PressDown = OPT_FLAT;
cratliff 0:aa55c6eb6867 231 if(Control <= 0)
cratliff 0:aa55c6eb6867 232 {
cratliff 0:aa55c6eb6867 233 Control = 0;
cratliff 0:aa55c6eb6867 234 }
cratliff 0:aa55c6eb6867 235 else{
cratliff 0:aa55c6eb6867 236 Control = Control - 0.01;
cratliff 0:aa55c6eb6867 237 }
cratliff 0:aa55c6eb6867 238 // bright = 0; // scale it down to 255
cratliff 0:aa55c6eb6867 239 }
cratliff 0:aa55c6eb6867 240 else if(4 == tagval) { // the slider is touched
cratliff 0:aa55c6eb6867 241 PressUp = OPT_FLAT;
cratliff 0:aa55c6eb6867 242 if(Control >= 1)
cratliff 0:aa55c6eb6867 243 {
cratliff 0:aa55c6eb6867 244 Control = 1;
cratliff 0:aa55c6eb6867 245 }
cratliff 0:aa55c6eb6867 246 else{
cratliff 0:aa55c6eb6867 247 Control = Control + 0.01;
cratliff 0:aa55c6eb6867 248 }
cratliff 0:aa55c6eb6867 249 // bright = 255; // scale it down to 255
cratliff 0:aa55c6eb6867 250 }
cratliff 0:aa55c6eb6867 251
cratliff 0:aa55c6eb6867 252 //xyz = Control;
cratliff 0:aa55c6eb6867 253 // screen_1(color,bright); // paint new screen
cratliff 0:aa55c6eb6867 254 // TFT.Sleep(10); // wait 10ms for next check
cratliff 0:aa55c6eb6867 255 }
cratliff 0:aa55c6eb6867 256
cratliff 0:aa55c6eb6867 257 xyz = Feedback;
cratliff 0:aa55c6eb6867 258 screen_1(color,bright); // paint new screen
cratliff 0:aa55c6eb6867 259 TFT.Sleep(10); // wait 10ms for next time to repaint the screen
cratliff 0:aa55c6eb6867 260 PressDown = 0; // Clear Buttons being pressed
cratliff 0:aa55c6eb6867 261 PressUp = 0;
cratliff 0:aa55c6eb6867 262 } // end of display loop
cratliff 0:aa55c6eb6867 263 }
cratliff 0:aa55c6eb6867 264
cratliff 0:aa55c6eb6867 265
cratliff 0:aa55c6eb6867 266