basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cratliff
Date:
Wed Mar 16 12:06:43 2016 +0000
Revision:
2:a4c01cf97666
Parent:
1:7952d133e78c
Child:
3:f47fe17b34a1
Added Screen Flip and Read Touch Screen Calibration

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