Demo for FT800 lib. Use a dial wheel to select the color and a slider to change the brightness.
Use a dial to select the color and a slider to change the brightness
main.cpp@0:528baa4e7913, 2014-09-21 (annotated)
- Committer:
- dreschpe
- Date:
- Sun Sep 21 21:25:09 2014 +0000
- Revision:
- 0:528baa4e7913
Demo for FT800 Lib
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" |
dreschpe | 0:528baa4e7913 | 2 | * by Peter Drescher, DC2PD 2014 |
dreschpe | 0:528baa4e7913 | 3 | * Released under the MIT License: http://mbed.org/license/mit */ |
dreschpe | 0:528baa4e7913 | 4 | |
dreschpe | 0:528baa4e7913 | 5 | #include "mbed.h" |
dreschpe | 0:528baa4e7913 | 6 | #include "FT_Platform.h" |
dreschpe | 0:528baa4e7913 | 7 | |
dreschpe | 0:528baa4e7913 | 8 | |
dreschpe | 0:528baa4e7913 | 9 | FT800 TFT(PA_7,PA_6,PA_5,PC_7,PB_4,PA_9); // mosi, miso, sck, ss, int, pd // the FT800 is connected to SPI 11-13 |
dreschpe | 0:528baa4e7913 | 10 | |
dreschpe | 0:528baa4e7913 | 11 | // global Vars |
dreschpe | 0:528baa4e7913 | 12 | unsigned int r,b,g; |
dreschpe | 0:528baa4e7913 | 13 | |
dreschpe | 0:528baa4e7913 | 14 | // function to convert hue , saturation and value to RGB |
dreschpe | 0:528baa4e7913 | 15 | // see http://en.wikipedia.org/wiki/HSL_and_HSV |
dreschpe | 0:528baa4e7913 | 16 | void hsv2rgb(float H,float S, float V) |
dreschpe | 0:528baa4e7913 | 17 | { |
dreschpe | 0:528baa4e7913 | 18 | float f,h,p,q,t; |
dreschpe | 0:528baa4e7913 | 19 | int i; |
dreschpe | 0:528baa4e7913 | 20 | if( S == 0.0) { |
dreschpe | 0:528baa4e7913 | 21 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 22 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 23 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 24 | return; |
dreschpe | 0:528baa4e7913 | 25 | } |
dreschpe | 0:528baa4e7913 | 26 | if(H > 360.0) H = 0.0; // check values |
dreschpe | 0:528baa4e7913 | 27 | if(S > 1.0) S = 1.0; |
dreschpe | 0:528baa4e7913 | 28 | if(S < 0.0) S = 0.0; |
dreschpe | 0:528baa4e7913 | 29 | if(V > 1.0) V = 1.0; |
dreschpe | 0:528baa4e7913 | 30 | if(V < 0.0) V = 0.0; |
dreschpe | 0:528baa4e7913 | 31 | |
dreschpe | 0:528baa4e7913 | 32 | h = H / 60.0; |
dreschpe | 0:528baa4e7913 | 33 | i = (int) h; |
dreschpe | 0:528baa4e7913 | 34 | f = h - i; |
dreschpe | 0:528baa4e7913 | 35 | p = V * (1.0 - S); |
dreschpe | 0:528baa4e7913 | 36 | q = V * (1.0 - (S * f)); |
dreschpe | 0:528baa4e7913 | 37 | t = V * (1.0 - (S * (1.0 - f))); |
dreschpe | 0:528baa4e7913 | 38 | |
dreschpe | 0:528baa4e7913 | 39 | switch(i) { |
dreschpe | 0:528baa4e7913 | 40 | case 0: |
dreschpe | 0:528baa4e7913 | 41 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 42 | g = t * 255; |
dreschpe | 0:528baa4e7913 | 43 | b = p * 255; |
dreschpe | 0:528baa4e7913 | 44 | break; |
dreschpe | 0:528baa4e7913 | 45 | case 1: |
dreschpe | 0:528baa4e7913 | 46 | r = q * 255; |
dreschpe | 0:528baa4e7913 | 47 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 48 | b = p * 255; |
dreschpe | 0:528baa4e7913 | 49 | break; |
dreschpe | 0:528baa4e7913 | 50 | case 2: |
dreschpe | 0:528baa4e7913 | 51 | r = p * 255; |
dreschpe | 0:528baa4e7913 | 52 | g = V * 255; |
dreschpe | 0:528baa4e7913 | 53 | b = t * 255; |
dreschpe | 0:528baa4e7913 | 54 | break; |
dreschpe | 0:528baa4e7913 | 55 | case 3: |
dreschpe | 0:528baa4e7913 | 56 | r = p * 255; |
dreschpe | 0:528baa4e7913 | 57 | g = q * 255; |
dreschpe | 0:528baa4e7913 | 58 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 59 | break; |
dreschpe | 0:528baa4e7913 | 60 | case 4: |
dreschpe | 0:528baa4e7913 | 61 | r = t * 255; |
dreschpe | 0:528baa4e7913 | 62 | g = p * 255; |
dreschpe | 0:528baa4e7913 | 63 | b = V * 255; |
dreschpe | 0:528baa4e7913 | 64 | break; |
dreschpe | 0:528baa4e7913 | 65 | case 5: |
dreschpe | 0:528baa4e7913 | 66 | default: |
dreschpe | 0:528baa4e7913 | 67 | r = V * 255; |
dreschpe | 0:528baa4e7913 | 68 | g = p * 255; |
dreschpe | 0:528baa4e7913 | 69 | b = q * 255; |
dreschpe | 0:528baa4e7913 | 70 | break; |
dreschpe | 0:528baa4e7913 | 71 | } |
dreschpe | 0:528baa4e7913 | 72 | } |
dreschpe | 0:528baa4e7913 | 73 | |
dreschpe | 0:528baa4e7913 | 74 | |
dreschpe | 0:528baa4e7913 | 75 | /***************************************************************************/ |
dreschpe | 0:528baa4e7913 | 76 | /* Show a Screen with Text for 5 seconds */ |
dreschpe | 0:528baa4e7913 | 77 | /* A spinner shows the delay */ |
dreschpe | 0:528baa4e7913 | 78 | /***************************************************************************/ |
dreschpe | 0:528baa4e7913 | 79 | |
dreschpe | 0:528baa4e7913 | 80 | ft_void_t Start_Screen(ft_char8_t *str) |
dreschpe | 0:528baa4e7913 | 81 | { |
dreschpe | 0:528baa4e7913 | 82 | TFT.DLstart(); // start a new display command list |
dreschpe | 0:528baa4e7913 | 83 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
dreschpe | 0:528baa4e7913 | 84 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 0:528baa4e7913 | 85 | TFT.DL(COLOR_RGB(0x80,0x80,0x00)); // set current color |
dreschpe | 0:528baa4e7913 | 86 | TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 |
dreschpe | 0:528baa4e7913 | 87 | TFT.DL(COLOR_RGB(0xFF,0x00,0x00)); // change current color |
dreschpe | 0:528baa4e7913 | 88 | TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner |
dreschpe | 0:528baa4e7913 | 89 | |
dreschpe | 0:528baa4e7913 | 90 | TFT.DL(DISPLAY()); // Display the image |
dreschpe | 0:528baa4e7913 | 91 | TFT.Swap(); // Swap the current display list |
dreschpe | 0:528baa4e7913 | 92 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
dreschpe | 0:528baa4e7913 | 93 | |
dreschpe | 0:528baa4e7913 | 94 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 95 | TFT.Sleep(5000); // Wait 5 s to show |
dreschpe | 0:528baa4e7913 | 96 | } |
dreschpe | 0:528baa4e7913 | 97 | |
dreschpe | 0:528baa4e7913 | 98 | // construct the screen and downloasd it to the LCD |
dreschpe | 0:528baa4e7913 | 99 | void screen_1(unsigned int color,unsigned int bright) |
dreschpe | 0:528baa4e7913 | 100 | { |
dreschpe | 0:528baa4e7913 | 101 | TFT.DLstart(); // start a new display command list |
dreschpe | 0:528baa4e7913 | 102 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
dreschpe | 0:528baa4e7913 | 103 | TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white |
dreschpe | 0:528baa4e7913 | 104 | TFT.DL(TAG(1)); // assign TAG value 1 |
dreschpe | 0:528baa4e7913 | 105 | //TFT.FgColor(COLOR_RGB(0xff,0,0)); // forground color red |
dreschpe | 0:528baa4e7913 | 106 | TFT.Dial(249, 86, 55, 0, color); // dial for color |
dreschpe | 0:528baa4e7913 | 107 | TFT.DL(TAG(2)); // assign TAG value 2 |
dreschpe | 0:528baa4e7913 | 108 | //TFT.FgColor(COLOR_RGB(0,0xff,0)); // forground color green |
dreschpe | 0:528baa4e7913 | 109 | TFT.Slider(196, 215, 236, 21, 0, bright , 255); // slider for brightness |
dreschpe | 0:528baa4e7913 | 110 | TFT.DL(COLOR_RGB(0xff,0xff,0xff)); // set current color to white |
dreschpe | 0:528baa4e7913 | 111 | TFT.Text(22, 84, 30, 0, "Color"); // text Color |
dreschpe | 0:528baa4e7913 | 112 | TFT.Text(22, 208, 30, 0, "Brightness");// text Brightness |
dreschpe | 0:528baa4e7913 | 113 | |
dreschpe | 0:528baa4e7913 | 114 | TFT.DL(POINT_SIZE(100)); // color point around the dial |
dreschpe | 0:528baa4e7913 | 115 | TFT.DL(BEGIN(POINTS)); |
dreschpe | 0:528baa4e7913 | 116 | TFT.DL(COLOR_RGB(0x0,0x0,0xff)); // color of next point |
dreschpe | 0:528baa4e7913 | 117 | TFT.DL(VERTEX2II(183,47,0,0)); // set point x,y |
dreschpe | 0:528baa4e7913 | 118 | TFT.DL(COLOR_RGB(0xff,0x0,0x0)); |
dreschpe | 0:528baa4e7913 | 119 | TFT.DL(VERTEX2II(249,162,0,0)); |
dreschpe | 0:528baa4e7913 | 120 | TFT.DL(COLOR_RGB(0xff,0x0,0xff)); |
dreschpe | 0:528baa4e7913 | 121 | TFT.DL(VERTEX2II(183,123,0,0)); |
dreschpe | 0:528baa4e7913 | 122 | TFT.DL(COLOR_RGB(0xff,0xff,0x0)); |
dreschpe | 0:528baa4e7913 | 123 | TFT.DL(VERTEX2II(317,123,0,0)); |
dreschpe | 0:528baa4e7913 | 124 | TFT.DL(COLOR_RGB(0x0,0xff,0xff)); |
dreschpe | 0:528baa4e7913 | 125 | TFT.DL(VERTEX2II(249,11,0,0)); |
dreschpe | 0:528baa4e7913 | 126 | TFT.DL(COLOR_RGB(0x0,0xff,0x00)); |
dreschpe | 0:528baa4e7913 | 127 | TFT.DL(VERTEX2II(317,50,0,0)); |
dreschpe | 0:528baa4e7913 | 128 | TFT.DL(SCISSOR_XY(10,10)); // define sub area starting at 10,10 |
dreschpe | 0:528baa4e7913 | 129 | TFT.DL(SCISSOR_SIZE(50,50)); // size 50,50 |
dreschpe | 0:528baa4e7913 | 130 | hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0); // calculate rgb color from settings |
dreschpe | 0:528baa4e7913 | 131 | TFT.DL(CLEAR_COLOR_RGB(r,b,g)); // set filling color to r,g,b |
dreschpe | 0:528baa4e7913 | 132 | TFT.DL(CLEAR(1,1,1)); // fill the area |
dreschpe | 0:528baa4e7913 | 133 | |
dreschpe | 0:528baa4e7913 | 134 | TFT.DL(DISPLAY()); // Display the image |
dreschpe | 0:528baa4e7913 | 135 | TFT.Swap(); // Swap the current display list |
dreschpe | 0:528baa4e7913 | 136 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
dreschpe | 0:528baa4e7913 | 137 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 138 | } |
dreschpe | 0:528baa4e7913 | 139 | |
dreschpe | 0:528baa4e7913 | 140 | int main() |
dreschpe | 0:528baa4e7913 | 141 | { |
dreschpe | 0:528baa4e7913 | 142 | unsigned int color = 0,bright = 0; |
dreschpe | 0:528baa4e7913 | 143 | ft_uint32_t TrackRegisterVal = 0; // touch track |
dreschpe | 0:528baa4e7913 | 144 | |
dreschpe | 0:528baa4e7913 | 145 | Start_Screen("RGB DEMO2 START"); // Show start screen |
dreschpe | 0:528baa4e7913 | 146 | TFT.Calibrate(); // calibrate the touch screen |
dreschpe | 0:528baa4e7913 | 147 | |
dreschpe | 0:528baa4e7913 | 148 | /* Set the tracker for the dial - define the Area for touching */ |
dreschpe | 0:528baa4e7913 | 149 | TFT.Track(249, 86, 1, 1, 1); // Dial - dimension 1,1 means rotary |
dreschpe | 0:528baa4e7913 | 150 | TFT.Track(179, 199, 277, 48, 2); // Slider |
dreschpe | 0:528baa4e7913 | 151 | TFT.Flush_Co_Buffer(); // Download the commands into fifo |
dreschpe | 0:528baa4e7913 | 152 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
dreschpe | 0:528baa4e7913 | 153 | screen_1(color,bright); // paint screen |
dreschpe | 0:528baa4e7913 | 154 | |
dreschpe | 0:528baa4e7913 | 155 | /* the demo is updating the screen in a endless loop */ |
dreschpe | 0:528baa4e7913 | 156 | while(1) { |
dreschpe | 0:528baa4e7913 | 157 | ft_uint8_t tagval = 0; |
dreschpe | 0:528baa4e7913 | 158 | TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched |
dreschpe | 0:528baa4e7913 | 159 | tagval = TrackRegisterVal & 0xff; |
dreschpe | 0:528baa4e7913 | 160 | if(0 != tagval) { // touch -> get new values |
dreschpe | 0:528baa4e7913 | 161 | if(1 == tagval) { // the dial touched |
dreschpe | 0:528baa4e7913 | 162 | color = TrackRegisterVal>>16; // get the new value |
dreschpe | 0:528baa4e7913 | 163 | } else if(2 == tagval) { // the slider is touched |
dreschpe | 0:528baa4e7913 | 164 | bright = TrackRegisterVal>>16; // get new slider value |
dreschpe | 0:528baa4e7913 | 165 | bright = bright * 255/65536; // scale it down to 255 |
dreschpe | 0:528baa4e7913 | 166 | } |
dreschpe | 0:528baa4e7913 | 167 | screen_1(color,bright); // paint new screen |
dreschpe | 0:528baa4e7913 | 168 | TFT.Sleep(10); // wait 10ms for next check |
dreschpe | 0:528baa4e7913 | 169 | } |
dreschpe | 0:528baa4e7913 | 170 | |
dreschpe | 0:528baa4e7913 | 171 | } // end of display loop |
dreschpe | 0:528baa4e7913 | 172 | } |
dreschpe | 0:528baa4e7913 | 173 | |
dreschpe | 0:528baa4e7913 | 174 | |
dreschpe | 0:528baa4e7913 | 175 |