Demo of the FT810 Based on Code from FTDI modified by Peter Drescher
Fork of FT800_RGB_demo2 by
This code, adapted from Peter Drescher, adapted from FTDI, to use on the FTDI FT810 chip with a nice 800x480 screen. Basically the memory locations have moved since the screen is bigger and so there is more RAM memory before the registers.
main.cpp@2:8800d9144869, 2016-02-24 (annotated)
- Committer:
- davidchilds
- Date:
- Wed Feb 24 16:40:22 2016 +0000
- Revision:
- 2:8800d9144869
- Parent:
- 1:7a29cc1298ef
now with two bigger squares
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:528baa4e7913 | 1 | /* Demo for mbed Library for FTDI FT800 Enbedded Video Engine "EVE" |
davidchilds | 1:7a29cc1298ef | 2 | Updated for FTDI FT810 driver and 800x480 display. |
dreschpe | 0:528baa4e7913 | 3 | * by Peter Drescher, DC2PD 2014 |
dreschpe | 0:528baa4e7913 | 4 | * Released under the MIT License: http://mbed.org/license/mit */ |
dreschpe | 0:528baa4e7913 | 5 | |
dreschpe | 0:528baa4e7913 | 6 | #include "mbed.h" |
dreschpe | 0:528baa4e7913 | 7 | #include "FT_Platform.h" |
dreschpe | 0:528baa4e7913 | 8 | |
dreschpe | 0:528baa4e7913 | 9 | |
dreschpe | 0:528baa4e7913 | 10 | |
davidchilds | 1:7a29cc1298ef | 11 | FT800 TFT(p5,p6,p7,p8,p9,p10); // the FT800 is connected to SPI 5-7, then we have CS, INT, PD |
dreschpe | 0:528baa4e7913 | 12 | // global Vars |
dreschpe | 0:528baa4e7913 | 13 | unsigned int r,b,g; |
dreschpe | 0:528baa4e7913 | 14 | |
dreschpe | 0:528baa4e7913 | 15 | // function to convert hue , saturation and value to RGB |
dreschpe | 0:528baa4e7913 | 16 | // see http://en.wikipedia.org/wiki/HSL_and_HSV |
dreschpe | 0:528baa4e7913 | 17 | void hsv2rgb(float H,float S, float V) |
dreschpe | 0:528baa4e7913 | 18 | { |
dreschpe | 0:528baa4e7913 | 19 | float f,h,p,q,t; |
dreschpe | 0:528baa4e7913 | 20 | int i; |
dreschpe | 0:528baa4e7913 | 21 | if( S == 0.0) { |
dreschpe | 0:528baa4e7913 | 22 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 23 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 24 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 25 | return; |
dreschpe | 0:528baa4e7913 | 26 | } |
davidchilds | 1:7a29cc1298ef | 27 | if(H > 480.0) H = 0.0; // check values |
dreschpe | 0:528baa4e7913 | 28 | if(S > 1.0) S = 1.0; |
dreschpe | 0:528baa4e7913 | 29 | if(S < 0.0) S = 0.0; |
dreschpe | 0:528baa4e7913 | 30 | if(V > 1.0) V = 1.0; |
dreschpe | 0:528baa4e7913 | 31 | if(V < 0.0) V = 0.0; |
dreschpe | 0:528baa4e7913 | 32 | |
dreschpe | 0:528baa4e7913 | 33 | h = H / 60.0; |
dreschpe | 0:528baa4e7913 | 34 | i = (int) h; |
dreschpe | 0:528baa4e7913 | 35 | f = h - i; |
dreschpe | 0:528baa4e7913 | 36 | p = V * (1.0 - S); |
dreschpe | 0:528baa4e7913 | 37 | q = V * (1.0 - (S * f)); |
dreschpe | 0:528baa4e7913 | 38 | t = V * (1.0 - (S * (1.0 - f))); |
dreschpe | 0:528baa4e7913 | 39 | |
dreschpe | 0:528baa4e7913 | 40 | switch(i) { |
dreschpe | 0:528baa4e7913 | 41 | case 0: |
dreschpe | 0:528baa4e7913 | 42 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 43 | g = t * 255; |
dreschpe | 0:528baa4e7913 | 44 | b = p * 255; |
dreschpe | 0:528baa4e7913 | 45 | break; |
dreschpe | 0:528baa4e7913 | 46 | case 1: |
dreschpe | 0:528baa4e7913 | 47 | r = q * 255; |
dreschpe | 0:528baa4e7913 | 48 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 49 | b = p * 255; |
dreschpe | 0:528baa4e7913 | 50 | break; |
dreschpe | 0:528baa4e7913 | 51 | case 2: |
dreschpe | 0:528baa4e7913 | 52 | r = p * 255; |
dreschpe | 0:528baa4e7913 | 53 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 54 | b = t * 255; |
dreschpe | 0:528baa4e7913 | 55 | break; |
dreschpe | 0:528baa4e7913 | 56 | case 3: |
dreschpe | 0:528baa4e7913 | 57 | r = p * 255; |
dreschpe | 0:528baa4e7913 | 58 | g = q * 255; |
dreschpe | 0:528baa4e7913 | 59 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 60 | break; |
dreschpe | 0:528baa4e7913 | 61 | case 4: |
dreschpe | 0:528baa4e7913 | 62 | r = t * 255; |
dreschpe | 0:528baa4e7913 | 63 | g = p * 255; |
dreschpe | 0:528baa4e7913 | 64 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 65 | break; |
dreschpe | 0:528baa4e7913 | 66 | case 5: |
dreschpe | 0:528baa4e7913 | 67 | default: |
dreschpe | 0:528baa4e7913 | 68 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 69 | g = p * 255; |
dreschpe | 0:528baa4e7913 | 70 | b = q * 255; |
dreschpe | 0:528baa4e7913 | 71 | break; |
dreschpe | 0:528baa4e7913 | 72 | } |
dreschpe | 0:528baa4e7913 | 73 | } |
dreschpe | 0:528baa4e7913 | 74 | |
dreschpe | 0:528baa4e7913 | 75 | |
dreschpe | 0:528baa4e7913 | 76 | /***************************************************************************/ |
dreschpe | 0:528baa4e7913 | 77 | /* Show a Screen with Text for 5 seconds */ |
dreschpe | 0:528baa4e7913 | 78 | /* A spinner shows the delay */ |
dreschpe | 0:528baa4e7913 | 79 | /***************************************************************************/ |
dreschpe | 0:528baa4e7913 | 80 | |
dreschpe | 0:528baa4e7913 | 81 | ft_void_t Start_Screen(ft_char8_t *str) |
dreschpe | 0:528baa4e7913 | 82 | { |
dreschpe | 0:528baa4e7913 | 83 | TFT.DLstart(); // start a new display command list |
dreschpe | 0:528baa4e7913 | 84 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
dreschpe | 0:528baa4e7913 | 85 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 0:528baa4e7913 | 86 | TFT.DL(COLOR_RGB(0x80,0x80,0x00)); // set current color |
dreschpe | 0:528baa4e7913 | 87 | TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 |
dreschpe | 0:528baa4e7913 | 88 | TFT.DL(COLOR_RGB(0xFF,0x00,0x00)); // change current color |
dreschpe | 0:528baa4e7913 | 89 | TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner |
dreschpe | 0:528baa4e7913 | 90 | |
dreschpe | 0:528baa4e7913 | 91 | TFT.DL(DISPLAY()); // Display the image |
dreschpe | 0:528baa4e7913 | 92 | TFT.Swap(); // Swap the current display list |
dreschpe | 0:528baa4e7913 | 93 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
dreschpe | 0:528baa4e7913 | 94 | |
dreschpe | 0:528baa4e7913 | 95 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 96 | TFT.Sleep(5000); // Wait 5 s to show |
dreschpe | 0:528baa4e7913 | 97 | } |
dreschpe | 0:528baa4e7913 | 98 | |
davidchilds | 2:8800d9144869 | 99 | // construct the screen and download it to the LCD |
dreschpe | 0:528baa4e7913 | 100 | void screen_1(unsigned int color,unsigned int bright) |
dreschpe | 0:528baa4e7913 | 101 | { |
dreschpe | 0:528baa4e7913 | 102 | TFT.DLstart(); // start a new display command list |
dreschpe | 0:528baa4e7913 | 103 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 0:528baa4e7913 | 104 | TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white |
dreschpe | 0:528baa4e7913 | 105 | TFT.DL(TAG(1)); // assign TAG value 1 |
dreschpe | 0:528baa4e7913 | 106 | //TFT.FgColor(COLOR_RGB(0xff,0,0)); // forground color red |
dreschpe | 0:528baa4e7913 | 107 | TFT.Dial(249, 86, 55, 0, color); // dial for color |
dreschpe | 0:528baa4e7913 | 108 | TFT.DL(TAG(2)); // assign TAG value 2 |
dreschpe | 0:528baa4e7913 | 109 | //TFT.FgColor(COLOR_RGB(0,0xff,0)); // forground color green |
dreschpe | 0:528baa4e7913 | 110 | TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness |
dreschpe | 0:528baa4e7913 | 111 | TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white |
dreschpe | 0:528baa4e7913 | 112 | TFT.Text(22, 84, 30, 0, "Color"); // text Color |
dreschpe | 0:528baa4e7913 | 113 | TFT.Text(22, 208, 30, 0, "Brightness");// text Brightness |
dreschpe | 0:528baa4e7913 | 114 | |
dreschpe | 0:528baa4e7913 | 115 | TFT.DL(POINT_SIZE(100)); // color point around the dial |
davidchilds | 1:7a29cc1298ef | 116 | TFT.DL(BEGIN(FTPOINTS)); |
dreschpe | 0:528baa4e7913 | 117 | TFT.DL(COLOR_RGB(0x0,0x0,0xff)); // color of next point |
dreschpe | 0:528baa4e7913 | 118 | TFT.DL(VERTEX2II(183,47,0,0)); // set point x,y |
dreschpe | 0:528baa4e7913 | 119 | TFT.DL(COLOR_RGB(0xff,0x0,0x0)); |
dreschpe | 0:528baa4e7913 | 120 | TFT.DL(VERTEX2II(249,162,0,0)); |
dreschpe | 0:528baa4e7913 | 121 | TFT.DL(COLOR_RGB(0xff,0x0,0xff)); |
dreschpe | 0:528baa4e7913 | 122 | TFT.DL(VERTEX2II(183,123,0,0)); |
dreschpe | 0:528baa4e7913 | 123 | TFT.DL(COLOR_RGB(0xff,0xff,0x0)); |
dreschpe | 0:528baa4e7913 | 124 | TFT.DL(VERTEX2II(317,123,0,0)); |
dreschpe | 0:528baa4e7913 | 125 | TFT.DL(COLOR_RGB(0x0,0xff,0xff)); |
dreschpe | 0:528baa4e7913 | 126 | TFT.DL(VERTEX2II(249,11,0,0)); |
dreschpe | 0:528baa4e7913 | 127 | TFT.DL(COLOR_RGB(0x0,0xff,0x00)); |
dreschpe | 0:528baa4e7913 | 128 | TFT.DL(VERTEX2II(317,50,0,0)); |
davidchilds | 2:8800d9144869 | 129 | |
dreschpe | 0:528baa4e7913 | 130 | TFT.DL(SCISSOR_XY(10,10)); // define sub area starting at 10,10 |
davidchilds | 2:8800d9144869 | 131 | TFT.DL(SCISSOR_SIZE(50,50)); // size 50,50 |
davidchilds | 2:8800d9144869 | 132 | hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings |
davidchilds | 2:8800d9144869 | 133 | TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b |
davidchilds | 2:8800d9144869 | 134 | TFT.DL(CLEAR(1,1,1)); // fill the area |
davidchilds | 2:8800d9144869 | 135 | |
davidchilds | 2:8800d9144869 | 136 | TFT.DL(SCISSOR_XY(500,10)); // define sub area starting at 10,10 |
davidchilds | 2:8800d9144869 | 137 | TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200 |
davidchilds | 2:8800d9144869 | 138 | hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings |
davidchilds | 2:8800d9144869 | 139 | TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b |
davidchilds | 2:8800d9144869 | 140 | TFT.DL(CLEAR(1,1,1)); // fill the area |
davidchilds | 2:8800d9144869 | 141 | |
davidchilds | 2:8800d9144869 | 142 | TFT.DL(SCISSOR_XY(500,210)); // define sub area starting at 10,10 |
davidchilds | 2:8800d9144869 | 143 | TFT.DL(SCISSOR_SIZE(200,200)); // size 200,200 |
dreschpe | 0:528baa4e7913 | 144 | hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings |
dreschpe | 0:528baa4e7913 | 145 | TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b |
dreschpe | 0:528baa4e7913 | 146 | TFT.DL(CLEAR(1,1,1)); // fill the area |
dreschpe | 0:528baa4e7913 | 147 | |
dreschpe | 0:528baa4e7913 | 148 | TFT.DL(DISPLAY()); // Display the image |
dreschpe | 0:528baa4e7913 | 149 | TFT.Swap(); // Swap the current display list |
dreschpe | 0:528baa4e7913 | 150 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
dreschpe | 0:528baa4e7913 | 151 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 152 | } |
dreschpe | 0:528baa4e7913 | 153 | |
dreschpe | 0:528baa4e7913 | 154 | int main() |
dreschpe | 0:528baa4e7913 | 155 | { |
davidchilds | 1:7a29cc1298ef | 156 | |
dreschpe | 0:528baa4e7913 | 157 | unsigned int color = 0,bright = 0; |
dreschpe | 0:528baa4e7913 | 158 | ft_uint32_t TrackRegisterVal = 0; // touch track |
dreschpe | 0:528baa4e7913 | 159 | |
dreschpe | 0:528baa4e7913 | 160 | Start_Screen("RGB DEMO2 START"); // Show start screen |
dreschpe | 0:528baa4e7913 | 161 | TFT.Calibrate(); // calibrate the touch screen |
dreschpe | 0:528baa4e7913 | 162 | |
dreschpe | 0:528baa4e7913 | 163 | /* Set the tracker for the dial - define the Area for touching */ |
dreschpe | 0:528baa4e7913 | 164 | TFT.Track(249, 86, 1, 1, 1); // Dial - dimension 1,1 means rotary |
dreschpe | 0:528baa4e7913 | 165 | TFT.Track(179, 199, 277, 48, 2); // Slider |
dreschpe | 0:528baa4e7913 | 166 | TFT.Flush_Co_Buffer(); // Download the commands into fifo |
dreschpe | 0:528baa4e7913 | 167 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 168 | screen_1(color,bright); // paint screen |
dreschpe | 0:528baa4e7913 | 169 | |
dreschpe | 0:528baa4e7913 | 170 | /* the demo is updating the screen in a endless loop */ |
dreschpe | 0:528baa4e7913 | 171 | while(1) { |
dreschpe | 0:528baa4e7913 | 172 | ft_uint8_t tagval = 0; |
dreschpe | 0:528baa4e7913 | 173 | TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched |
dreschpe | 0:528baa4e7913 | 174 | tagval = TrackRegisterVal & 0xff; |
dreschpe | 0:528baa4e7913 | 175 | if(0 != tagval) { // touch -> get new values |
dreschpe | 0:528baa4e7913 | 176 | if(1 == tagval) { // the dial touched |
dreschpe | 0:528baa4e7913 | 177 | color = TrackRegisterVal>>16; // get the new value |
dreschpe | 0:528baa4e7913 | 178 | } else if(2 == tagval) { // the slider is touched |
dreschpe | 0:528baa4e7913 | 179 | bright = TrackRegisterVal>>16; // get new slider value |
dreschpe | 0:528baa4e7913 | 180 | bright = bright * 255/65536; // scale it down to 255 |
dreschpe | 0:528baa4e7913 | 181 | } |
dreschpe | 0:528baa4e7913 | 182 | screen_1(color,bright); // paint new screen |
dreschpe | 0:528baa4e7913 | 183 | TFT.Sleep(10); // wait 10ms for next check |
dreschpe | 0:528baa4e7913 | 184 | } |
dreschpe | 0:528baa4e7913 | 185 | |
dreschpe | 0:528baa4e7913 | 186 | } // end of display loop |
dreschpe | 0:528baa4e7913 | 187 | } |
dreschpe | 0:528baa4e7913 | 188 | |
dreschpe | 0:528baa4e7913 | 189 | |
dreschpe | 0:528baa4e7913 | 190 |