basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cratliff
Date:
Mon Mar 14 17:07:53 2016 +0000
Revision:
1:7952d133e78c
Parent:
0:aa55c6eb6867
Child:
2:a4c01cf97666
Trying to add SD Card support

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