Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
main.cpp
- Committer:
- cpm219
- Date:
- 2016-07-21
- Revision:
- 17:f98333612db8
- Parent:
- 16:19ade236df07
- Child:
- 18:d1566d9b6ea1
File content as of revision 17:f98333612db8:
/* Title Block ** Project : data logger: lcd power levels ** Engineers : Curtis Mattull ** Processor : MK20 ** Version : 1.0 ** Compiler : mbed ** Date/Time : 7/18/2016 ** Abstract : This program functions as a simple data logger. This program also serves as a learning experience with using touch screen LCDs. modes of operation: (mcu never sleeps) NOTE: comment line 12 of FT_LCD_TYPE.h unless using beyondtek display! */ #include "mbed.h" #include "FT_Platform.h" #include "stdio.h" #include "float.h" #include "SDFileSystem.h" /************************ global *************************/ //comment out for standard display #define beyondtek #define mask_present_state 0x38 #define mask_tag_input 0x7 #define mask_reg_tracker_tag 0xF #define font_title 0x1F #define font_button 0x1D #define font_author 0x15 // create object for the LCD, handles all of the data passing and slave select commands (SPI) FT800 TFT( D11, //mosi D12, //miso D13, //sclk D9, //ss D8, //intr D14 ); // pd DigitalIn card_present(D7); // digital in pin connected to the SD card detect pin input AnalogIn analog_in9(A9); // analog 9 pin connected to the PSE input 4 AnalogIn analog_in8(A8); // analog 9 pin connected to the PFW input 5 AnalogIn analog_in3(A3); // analog 9 pin connected to the ITV1 input 10 AnalogIn analog_in2(A2); // analog 9 pin connected to the ITV2 input 11 from usb, starting at 1 /************************ function prototypes *************************/ void Start_Screen(ft_char8_t *str); int16_t collect_data(void); void plot_data(); //for gui state machine void main_menu(uint8_t tag); // main menu 0 void mode_a(uint8_t tag); // mode A 1 void mode_b(uint8_t tag); // mode B 2 void mode_c(uint8_t tag); // mode C 3 //for plot state machine void plot_nothing(void); void plot_square(void); void plot_triangle(void); void plot_sine(void); /************************ function pointers *************************/ void (*draw_screen[4])(uint8_t tag) = { main_menu, // 0 mode_a, // 1 mode_b, // 2 mode_c }; // 3 void (*plot[4])(void) = { plot_nothing, // 0 plot_square, // 1 plot_triangle, // 2 plot_sine }; // 3 /************************ lookup tables *************************/ //gui menu state table static const uint8_t state_lookup[32] = {0x0, 0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2, 0x0, 0x2, 0x2, 0x2, 0x3, 0x3, 0x3, 0x3, 0x0, 0x3, 0x3, 0x3,}; // ///* array index values: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}; // */ static const uint8_t plot_lookup[32] = {0x0, 0x0, 0x2, 0x3, 0x0, 0x0, 0x1, 0x0, 0x1, 0x1, 0x2, 0x3, 0x1, 0x0, 0x1, 0x1, 0x2, 0x2, 0x2, 0x3, 0x2, 0x0, 0x1, 0x2, 0x3, 0x3, 0x2, 0x3, 0x3, 0x0, 0x1, 0x3,}; // ///* array index values: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}; //// //fallback gui menu state table //static const uint8_t state_lookup[32] = {0x0, 0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // 0x2, 0x2, 0x2, 0x2, 0x0, 0x0, 0x2, 0x2, 0x3, 0x3, 0x3, 0x3, 0x0, 0x3, 0x3, 0x3}; ///* array index values: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}; // */ static const int16_t square_wave_lookup[40] = { -100,-100,-100,-100,-100, 100,100,100,100,100, -100,-100,-100,-100,-100, 100,100,100,100,100, -100,-100,-100,-100,-100, 100,100,100,100,100, -100,-100,-100,-100,-100, 100,100,100,100,100}; static const int16_t tri_wave_lookup[40] = { 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0, 100,0,-100,0}; static const int16_t sine_wave_lookup[40] = { 0, 16, 31, 45, 59, 71, 81, 89, 95, 99, 100, 99, 95, 89, 81, 71, 59, 45, 31, 16, -0, -16, -31, -45, -59, -71, -81, -89, -95, -99, -100, -99, -95, -89, -81, -71, -59, -45, -31, -16, }; /************************ global variables *************************/ int16_t i =0; uint8_t present_states = 0x0, tags = 0x0, combo_inputs = 0x0; // data sample from ADC int16_t data1[40] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //pointer to data1 array //int16_t *p = data1; static const ft_char8_t text_menu[32]= {"Main Menu\0"}; static const ft_char8_t text_a[32]= {"Mode A\0"}; static const ft_char8_t text_b[32]= {"Mode B\0"}; static const ft_char8_t text_c[32]= {"Mode C\0"}; static const ft_char8_t text_back[32]= {"Back\0"}; static const ft_char8_t text_author[32]= {"by Curtis Mattull\0"}; /************************ main function: -calibrate touch screen -display welcome screen -manages touch screen input, system states, and calls draw_screen functions *************************/ int main() { uint8_t present_state = 0x0, tag = 0x0, combo_input = 0x0; TFT.Calibrate(); TFT.Flush_Co_Buffer(); // Download the command list into fifo TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation // Start_Screen("gui by\0"); main_menu(0x0); /* gui manager: -handles touch screen input -updates system state -calls draw screen function */ while(1) { tag = 0x0; while(0x0 == tag) { tag = ((TFT.Rd32(REG_TRACKER)) & mask_reg_tracker_tag); //read tag register, update tag variable } combo_input = ( present_state << 3) + tag; // concatenate present_state with tag to form combo input present_state = state_lookup[combo_input]; // based on present state and touch input, update present state (*draw_screen[present_state])(tag); // use present_state as operand to draw screen function TFT.Sleep(10); // wait 10ms for next check } return 0; } // end of main() /************************ function: collect_data description: store ADC samples *************************/ void collect_data(int16_t *p) { for(i=0;i<400;i++) { //p points to data1 array *(p +i) = square_wave_lookup[i]; } } /************************ function: main menu description: draw main menu screen *************************/ void main_menu(uint8_t tag) { TFT.Wr16(REG_PWM_DUTY, 100); //start new display list TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer //buttons TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); //button A TFT.Track( 50, 165, 200, 150, 1); // track aree of button A TFT.DL(TAG(1)); // assign TAG value 1 to "mode A" button TFT.Button(50, 165, 200, 150, font_button, 0, text_a); //button B TFT.Track( 300, 165, 200, 150, 2); // track aree of button B TFT.DL(TAG(2)); // assign TAG value 2 to "mode B" button TFT.Button(300, 165, 200, 150, font_button, 0, text_b); //button C TFT.Track( 550, 165, 200, 150, 3); // track aree of button C TFT.DL(TAG(3)); // assign TAG value 3 to "mode C" button TFT.Button(550, 165, 200, 150, font_button, 0, text_c); TFT.DL(TAG(0)); // assign TAG value 0 to everything else //title text TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_menu); // draw Text with font 31 //author text TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*15/16)-5, 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen TFT.DL(DISPLAY()); // display the image TFT.Swap(); // swap the current display list TFT.Flush_Co_Buffer(); // download the command list into fifo TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation } //fallback mode_a ///************************ // function: mode_a // description: draws mode a screen //*************************/ //void mode_a(void) //{ // TFT.Track( 50, 355, 100, 75, 4); // track aree of button back // // //start new display list // TFT.DLstart(); // start a new display command list // TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white // TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer // // //back button // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // TFT.DL(TAG(4)); // TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button // // TFT.DL(TAG(0)); // assign TAG value 0 to everything else // // //title text // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_a); // draw Text with font 31 // // //author text // TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); // TFT.Text((TFT.DispWidth*15/16), 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 // // //display the screen // TFT.DL(DISPLAY()); // display the image // TFT.Swap(); // swap the current display list // TFT.Flush_Co_Buffer(); // download the command list into fifo // TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation // //} /************************ function: mode_a description: draws mode a screen *************************/ void mode_a(uint8_t tag) { // collect_data(p); combo_inputs = ( present_states << 3) + tag; // concatenate present_state with tag to form combo input present_states = plot_lookup[combo_inputs]; // based on present state and touch input, update present state //start new display list TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); //back button TFT.Track( 50, 355, 100, 75, 4); // track aree of button back TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 4, text_back); // assign TAG value 4 to text_back button //plot square button TFT.Track( 200, 355, 100, 75, 6); // track aree of button square TFT.DL(TAG(6)); TFT.Button(200, 355, 100, 75, font_button, 6, "square"); // assign TAG value 1 to text_back button//back button //plot triangle button TFT.Track( 350, 355, 100, 75, 2); // track aree of button triangle TFT.DL(TAG(2)); TFT.Button(350, 355, 100, 75, font_button, 2, "triangle"); // assign TAG value 2 to text_back button//back button //plot sine button TFT.Track( 500, 355, 100, 75, 3); // track aree of button sine TFT.DL(TAG(3)); TFT.Button(500, 355, 100, 75, font_button, 3, "sine"); // assign TAG value 3 to text_back button//back button //plot nothing button TFT.Track( 650, 355, 100, 75, 5); // track aree of button square TFT.DL(TAG(5)); TFT.Button(650, 355, 100, 75, font_button, 5, "clear"); // assign TAG value 1 to text_back button//back button TFT.DL(TAG(0)); // assign TAG value 0 to everything else //border for plot TFT.DL(COLOR_RGB(0x00,0x00,0x00)); TFT.DL(BEGIN(LINES)); TFT.DL(LINE_WIDTH(3 * 16)); TFT.DL(VERTEX2F(50*16,150*16)); TFT.DL(VERTEX2F(50*16,350*16)); TFT.DL(VERTEX2F(50*16,350*16)); TFT.DL(VERTEX2F(750*16,350*16)); TFT.DL(VERTEX2F(750*16,350*16)); TFT.DL(VERTEX2F(750*16,150*16)); TFT.DL(VERTEX2F(750*16,150*16)); TFT.DL(VERTEX2F(50*16,150*16)); TFT.DL(END()); //plot algorithm TFT.DL( BEGIN(LINE_STRIP) ); TFT.DL(LINE_WIDTH(3 * 16)); (*plot[present_states])(); // use present_state as operand to draw screen function //title text TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_a); // draw Text with font 31 //author text TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*15/16)-5, 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen TFT.DL(DISPLAY()); // display the image TFT.Swap(); // swap the current display list TFT.Flush_Co_Buffer(); // download the command list into fifo TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation } //fallback mode_b ///************************ // function: mode b // description: draws mode b screen. //*************************/ //void mode_b(void) //{ // // TFT.Track( 50, 355, 100, 75, 4); // track aree of button back // // //start new display list // TFT.DLstart(); // start a new display command list // TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white // TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer // // //buttons // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // // TFT.DL(TAG(4)); // TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button // // TFT.DL(TAG(0)); // assign TAG value 0 to everything else // // // //title text // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_b); // draw Text with font 31 // // //author text // TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); // TFT.Text((TFT.DispWidth*15/16), 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 // // //display the screen // TFT.DL(DISPLAY()); // display the image // TFT.Swap(); // swap the current display list // TFT.Flush_Co_Buffer(); // download the command list into fifo // TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation //} /************************ function: mode b description: draws mode b screen. *************************/ void mode_b(uint8_t tag) { //start new display list TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); //back button TFT.Track( 50, 355, 100, 75, 4); // track aree of button back TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button TFT.DL(TAG(0)); // assign TAG value 0 to everything else //title text TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_b); // draw Text with font 31 //author text TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*15/16)-5, 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen TFT.DL(DISPLAY()); // display the image TFT.Swap(); // swap the current display list TFT.Flush_Co_Buffer(); // download the command list into fifo TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation } // fallback mode_c ///************************ // function: mode_c // description: draws mode C screen //*************************/ //void mode_c(void) //{ // // //start new display list // TFT.DLstart(); // start a new display command list // TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white // TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer // // //buttons // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // // TFT.Track( 50, 355, 100, 75, 4); // track aree of button back // TFT.DL(TAG(4)); // TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button // // TFT.DL(TAG(0)); // assign TAG value 0 to everything else // // // //title text // TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_c); // draw Text with font 31 // // //author text // TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); // TFT.Text((TFT.DispWidth*15/16), 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 // // //display the screen // TFT.DL(DISPLAY()); // display the image // TFT.Swap(); // swap the current display list // TFT.Flush_Co_Buffer(); // download the command list into fifo // TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation //} /************************ function: mode_c description: draws mode C screen *************************/ void mode_c(uint8_t tag) { //start new display list TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer //back button TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); TFT.Track( 50, 355, 100, 75, 4); // track aree of button back TFT.DL(TAG(4)); TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button TFT.DL(TAG(0)); // assign TAG value 0 to everything else //title text TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_c); // draw Text with font 31 //author text TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); TFT.Text((TFT.DispWidth*15/16)-5, 460, font_author, OPT_CENTERX, text_author); // draw Text with font 31 //display the screen TFT.DL(DISPLAY()); // display the image TFT.Swap(); // swap the current display list TFT.Flush_Co_Buffer(); // download the command list into fifo TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation } /************************ function: plot_nothing description: clears plot area *************************/ void plot_nothing(void) { TFT.DL(COLOR_RGB(0x00, 0x00, 0x00)); } /************************ function: plot_square description: plots square wave *************************/ void plot_square(void) { TFT.DL(COLOR_RGB(0xFF, 0x00, 0x00)); for(i = 0;i<40;i++) { TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 + (square_wave_lookup[i])*16) ); } } /************************ function: plot_triangle description: plots triangle wave *************************/ void plot_triangle(void) { TFT.DL(COLOR_RGB(0x00, 0xFF, 0x00)); for(i = 0;i<40;i++) { TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 + (tri_wave_lookup[i])*16) ); } } /************************ function: plot_sine description: plots sine wave *************************/ void plot_sine(void) { TFT.DL(COLOR_RGB(0xFF, 0x00, 0xFF)); for(i = 0;i<40;i++) { TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 + (sine_wave_lookup[i])*16) ); } } /************************ function: Start_Screen description: draws boot up screen as images are loaded from the sd card *************************/ ft_void_t Start_Screen(ft_char8_t *str) { TFT.DLstart(); // start a new display command list TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format TFT.DL(BEGIN(LINES)); TFT.DL(LINE_WIDTH(8 * 16)); TFT.DL(VERTEX2F(0*16,0*16)); TFT.DL(VERTEX2F(799*16,0*16)); TFT.DL(VERTEX2F(799*16,0*16)); TFT.DL(VERTEX2F(799*16,479*16)); TFT.DL(VERTEX2F(799*16,479*16)); TFT.DL(VERTEX2F(0*16,479*16)); TFT.DL(VERTEX2F(0*16,479*16)); TFT.DL(VERTEX2F(0*16,0*16)); TFT.DL(END()); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, text_author); // draw Text with font 31 TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner TFT.DL(DISPLAY()); // Display the image TFT.Swap(); // Swap the current display list TFT.Flush_Co_Buffer(); // Download the command list into fifo TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation TFT.Sleep(1000); // Wait 1s to show }