basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cpm219
Date:
Sat Sep 17 15:07:57 2016 +0000
Revision:
22:2bdc80e45f3b
Parent:
21:a50739772892
Child:
23:0045679060e3
first version of base gui

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cratliff 5:e2e04cb5eada 1 /*
cratliff 5:e2e04cb5eada 2 Title Block
cpm219 22:2bdc80e45f3b 3 ** Project : PANEL_GUI_BASE
cpm219 18:d1566d9b6ea1 4 ** Engineers : Curtis Mattull
cpm219 22:2bdc80e45f3b 5 ** Processor : MK22
cpm219 18:d1566d9b6ea1 6 ** Version : 1.0
cpm219 18:d1566d9b6ea1 7 ** Compiler : mbed
cpm219 22:2bdc80e45f3b 8 ** Date : 9/17/2016
cpm219 22:2bdc80e45f3b 9 ** Abstract : This program serves as a starting point for most applications requiring a touch screen menu.
cpm219 22:2bdc80e45f3b 10 Note :
cratliff 5:e2e04cb5eada 11 */
cpm219 17:f98333612db8 12
cpm219 17:f98333612db8 13 #include "mbed.h"
cratliff 0:aa55c6eb6867 14 #include "FT_Platform.h"
cpm219 18:d1566d9b6ea1 15 #include "FT_color.h"
cratliff 0:aa55c6eb6867 16 #include "stdio.h"
cpm219 18:d1566d9b6ea1 17 #include "string.h"
montgojj 4:a48fc7a3bda9 18 #include "float.h"
montgojj 4:a48fc7a3bda9 19 #include "SDFileSystem.h"
cpm219 18:d1566d9b6ea1 20 #include "FATFileSystem.h"
cpm219 20:92b3e641b306 21 #include "DigitalIn.h"
cpm219 20:92b3e641b306 22 #include "nRF24L01P.h"
cpm219 22:2bdc80e45f3b 23 #include "time.h"
cpm219 17:f98333612db8 24
cpm219 17:f98333612db8 25 /************************
cpm219 17:f98333612db8 26 function prototypes
cpm219 17:f98333612db8 27 *************************/
cpm219 17:f98333612db8 28
cpm219 18:d1566d9b6ea1 29 //for display type
cpm219 18:d1566d9b6ea1 30 void rotate_newhaven(void);
cpm219 18:d1566d9b6ea1 31 void rotate_beyondtek(void);
cpm219 18:d1566d9b6ea1 32 //for gui states
cpm219 18:d1566d9b6ea1 33 void gui_manager(void);
cpm219 18:d1566d9b6ea1 34 void main_menu(uint32_t tracker, uint8_t tag); // main menu 0
cpm219 18:d1566d9b6ea1 35 void mode_a(uint32_t tracker, uint8_t tag); // mode A 1
cpm219 18:d1566d9b6ea1 36 void mode_b(uint32_t tracker, uint8_t tag); // mode B 2
cpm219 18:d1566d9b6ea1 37 void mode_c(uint32_t tracker, uint8_t tag); // mode C 3
cpm219 18:d1566d9b6ea1 38 //for plot states
cpm219 17:f98333612db8 39 void plot_nothing(void);
cpm219 17:f98333612db8 40 void plot_square(void);
cpm219 17:f98333612db8 41 void plot_triangle(void);
cpm219 17:f98333612db8 42 void plot_sine(void);
cpm219 18:d1566d9b6ea1 43 void collect_data(void);
cpm219 18:d1566d9b6ea1 44 //for sd card
cpm219 18:d1566d9b6ea1 45 uint8_t read_calibration(void);
cpm219 18:d1566d9b6ea1 46 uint8_t sd_test(void);
cpm219 18:d1566d9b6ea1 47 uint8_t bitmap_test(uint16_t x,uint16_t y);
cpm219 18:d1566d9b6ea1 48 int8_t Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address);
cpm219 18:d1566d9b6ea1 49 //general use
cpm219 18:d1566d9b6ea1 50 void display_message(uint8_t error, const ft_char8_t *pass, const ft_char8_t *fail);
cpm219 18:d1566d9b6ea1 51 void start_screen(ft_char8_t *str);
cpm219 18:d1566d9b6ea1 52 void error_screen(ft_char8_t *str1, ft_char8_t *str2);
cpm219 17:f98333612db8 53
cpm219 17:f98333612db8 54 /************************
cpm219 17:f98333612db8 55 function pointers
cpm219 17:f98333612db8 56 *************************/
cpm219 17:f98333612db8 57
cpm219 18:d1566d9b6ea1 58 void (*draw_screen[4])(uint32_t tracker, uint8_t tag) = { main_menu, // 0
cpm219 18:d1566d9b6ea1 59 mode_a, // 1
cpm219 18:d1566d9b6ea1 60 mode_b, // 2
cpm219 18:d1566d9b6ea1 61 mode_c
cpm219 18:d1566d9b6ea1 62 }; // 3
cpm219 17:f98333612db8 63
cpm219 17:f98333612db8 64 void (*plot[4])(void) = { plot_nothing, // 0
cpm219 17:f98333612db8 65 plot_square, // 1
cpm219 17:f98333612db8 66 plot_triangle, // 2
cpm219 18:d1566d9b6ea1 67 // plot_sine
cpm219 18:d1566d9b6ea1 68 collect_data
cpm219 18:d1566d9b6ea1 69 }; // 3
cpm219 18:d1566d9b6ea1 70
cratliff 0:aa55c6eb6867 71
cpm219 17:f98333612db8 72
cpm219 18:d1566d9b6ea1 73 void (*display_rotate[2])() = { rotate_newhaven, // 0
cpm219 18:d1566d9b6ea1 74 rotate_beyondtek
cpm219 18:d1566d9b6ea1 75 }; // 1
cpm219 17:f98333612db8 76
cpm219 17:f98333612db8 77 /************************
cpm219 18:d1566d9b6ea1 78 global objects and variables
cpm219 17:f98333612db8 79 *************************/
cpm219 22:2bdc80e45f3b 80 // create an LCD object
cpm219 22:2bdc80e45f3b 81 FT800 TFT ( PTD6, PTD7, PTD5, PTE0, PTB19, PTA1 );
cpm219 22:2bdc80e45f3b 82 // ( mosi, miso, sclk, ss, intr, pd );
cpm219 17:f98333612db8 83
cpm219 22:2bdc80e45f3b 84 // create an RF object
cpm219 20:92b3e641b306 85 nRF24L01P RF ( PTD2, PTD3, PTD1, PTD4, PTC11, PTD0);
cpm219 20:92b3e641b306 86 // ( mosi, miso, sck, csn, ce, irq)
cpm219 20:92b3e641b306 87
cpm219 18:d1566d9b6ea1 88
cpm219 20:92b3e641b306 89 ////Create an SDFileSystem object
cpm219 20:92b3e641b306 90 SDFileSystem sd ( PTD2, PTD3, PTD1, PTC4, "sd");
cpm219 20:92b3e641b306 91 ////SDFileSystem( mosi, miso, sclk, ss, name);
cpm219 20:92b3e641b306 92
cpm219 20:92b3e641b306 93
cpm219 20:92b3e641b306 94
cpm219 20:92b3e641b306 95 DigitalIn sdcard_present(PTB16,PullDown); // SD card detect input pin. card_present() is the name of a function within the SDFileSystem Class!!!
cpm219 20:92b3e641b306 96 AnalogIn analog_in9(A0);
cpm219 17:f98333612db8 97
cpm219 18:d1566d9b6ea1 98 const uint8_t font_button = 28,
cpm219 18:d1566d9b6ea1 99 font_title = 31,
cpm219 18:d1566d9b6ea1 100 font_author = 21;
cpm219 18:d1566d9b6ea1 101
cpm219 22:2bdc80e45f3b 102 const ft_char8_t text_menu[32] = {"Main Menu\0"},
cpm219 22:2bdc80e45f3b 103 text_a[32] = {"A\0"},
cpm219 22:2bdc80e45f3b 104 text_b[32] = {"B\0"},
cpm219 22:2bdc80e45f3b 105 text_c[32] = {"C\0"},
cpm219 18:d1566d9b6ea1 106 text_back[32] = {"Back\0"},
cpm219 22:2bdc80e45f3b 107 text_author[32] = {"by Curtis Mattull\0"},
cpm219 22:2bdc80e45f3b 108 text_time[32] = {"Run time [s]: \0"};
cpm219 18:d1566d9b6ea1 109
cpm219 18:d1566d9b6ea1 110 int16_t i = 0x00;
cpm219 18:d1566d9b6ea1 111 static const uint32_t mask_reg_tracker_tag = 0x0000FFFF;
cpm219 18:d1566d9b6ea1 112 static const uint32_t mask_reg_tracker_tracker = 0xFFFF0000;
cpm219 18:d1566d9b6ea1 113 static const uint8_t mask_tag = 0xFF;
cpm219 18:d1566d9b6ea1 114
cpm219 18:d1566d9b6ea1 115 char buffer[50]; // temporary buffer for writing characters to the LCD
cpm219 18:d1566d9b6ea1 116
cpm219 18:d1566d9b6ea1 117 ft_int16_t x_size, y_size; // stores size data for loaded jpegs, not currently used
cpm219 17:f98333612db8 118
cpm219 18:d1566d9b6ea1 119 /************************
cpm219 18:d1566d9b6ea1 120 function: main()
cpm219 18:d1566d9b6ea1 121 description:
cpm219 18:d1566d9b6ea1 122 -calibrate touch screen
cpm219 18:d1566d9b6ea1 123 -display welcome screen
cpm219 18:d1566d9b6ea1 124 -manages touch screen input, system states, and calls draw_screen functions
cpm219 18:d1566d9b6ea1 125 *************************/
cpm219 18:d1566d9b6ea1 126 int main()
cpm219 18:d1566d9b6ea1 127 {
cpm219 22:2bdc80e45f3b 128 // static const uint8_t display_type = 0x00; //not beyondtek display
cpm219 22:2bdc80e45f3b 129 static const uint8_t display_type = 0x01;
cpm219 18:d1566d9b6ea1 130 uint8_t error[4] = { 0x00, // sd_test error
cpm219 18:d1566d9b6ea1 131 0x00, // load_bitmap error
cpm219 18:d1566d9b6ea1 132 0x00, // bitmap write error
cpm219 18:d1566d9b6ea1 133 0x00
cpm219 18:d1566d9b6ea1 134 }; // gui_manager error
cpm219 20:92b3e641b306 135
cpm219 18:d1566d9b6ea1 136 (*display_rotate[display_type])(); // for proper orientation
cpm219 18:d1566d9b6ea1 137 error[3] = read_calibration();
cpm219 18:d1566d9b6ea1 138 display_message( error[3], "touch calibration load success!\0", "touch calibration save success!\0");
cpm219 20:92b3e641b306 139 TFT.Sleep(500);
cpm219 18:d1566d9b6ea1 140
cpm219 20:92b3e641b306 141 // //load jpg into graphics ram
cpm219 20:92b3e641b306 142 // error[1] = Load_jpg("/sd/Logo.jpg", &x_size, &y_size, RAM_G);
cpm219 20:92b3e641b306 143 // display_message( error[1], "load jpg success!\0", "load jpg failed!\0");
cpm219 20:92b3e641b306 144 // TFT.Sleep(100); // Wait ___ to show
cpm219 20:92b3e641b306 145
cpm219 22:2bdc80e45f3b 146 // RF.powerUp();
cpm219 22:2bdc80e45f3b 147 // RF.setTransferSize( TRANSFER_SIZE );
cpm219 22:2bdc80e45f3b 148 // RF.setReceiveMode();
cpm219 22:2bdc80e45f3b 149 // RF.enable();
cpm219 22:2bdc80e45f3b 150
cpm219 22:2bdc80e45f3b 151 set_time(0); // Set RTC time to 0
cpm219 22:2bdc80e45f3b 152
cpm219 18:d1566d9b6ea1 153 //draw initial screen
cpm219 18:d1566d9b6ea1 154 main_menu(0x0,0x0);
cpm219 18:d1566d9b6ea1 155 //program should not return from gui_manager...
cpm219 18:d1566d9b6ea1 156 gui_manager();
cpm219 17:f98333612db8 157
cpm219 18:d1566d9b6ea1 158 // Wait ___ to show
cpm219 18:d1566d9b6ea1 159 display_message( 0x1, "\0", "gui_manager failed!\0");
cpm219 18:d1566d9b6ea1 160 while(1) {
cpm219 18:d1566d9b6ea1 161 TFT.Sleep(1000);
cpm219 18:d1566d9b6ea1 162 }
cpm219 17:f98333612db8 163
cpm219 18:d1566d9b6ea1 164 return 0;
cpm219 18:d1566d9b6ea1 165 }
cpm219 17:f98333612db8 166
cpm219 17:f98333612db8 167
cpm219 17:f98333612db8 168
cpm219 17:f98333612db8 169
cpm219 17:f98333612db8 170 /************************
cpm219 18:d1566d9b6ea1 171 function: rotate_newhaven
cpm219 18:d1566d9b6ea1 172 description: rotates
cpm219 17:f98333612db8 173 *************************/
cpm219 18:d1566d9b6ea1 174 void rotate_newhaven(void)
cpm219 17:f98333612db8 175 {
cpm219 18:d1566d9b6ea1 176 TFT.MemWrite(REG_ROTATE, 1); // rotate screen
cpm219 18:d1566d9b6ea1 177 TFT.Rotate(1);
cpm219 18:d1566d9b6ea1 178 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cpm219 18:d1566d9b6ea1 179 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 180 }
cpm219 18:d1566d9b6ea1 181
cpm219 18:d1566d9b6ea1 182
cpm219 17:f98333612db8 183
cpm219 18:d1566d9b6ea1 184 /************************
cpm219 18:d1566d9b6ea1 185 function: rotate_beyondtek
cpm219 18:d1566d9b6ea1 186 description: rotates
cpm219 18:d1566d9b6ea1 187 *************************/
cpm219 18:d1566d9b6ea1 188 void rotate_beyondtek(void)
cpm219 18:d1566d9b6ea1 189 {
cpm219 18:d1566d9b6ea1 190 //dont rotate
cpm219 17:f98333612db8 191 }
cpm219 18:d1566d9b6ea1 192
cpm219 17:f98333612db8 193
cpm219 17:f98333612db8 194
cpm219 17:f98333612db8 195 /************************
cpm219 18:d1566d9b6ea1 196 function: gui_manager()
cpm219 18:d1566d9b6ea1 197 description: tracks input data and updates screen accordingly
cpm219 17:f98333612db8 198 *************************/
cpm219 18:d1566d9b6ea1 199 void gui_manager(void)
cpm219 17:f98333612db8 200 {
cpm219 18:d1566d9b6ea1 201 static const uint8_t state_lookup[32] = {0x0, 0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x1, 0x1,
cpm219 18:d1566d9b6ea1 202 0x2, 0x2, 0x2, 0x2, 0x0, 0x2, 0x2, 0x2, 0x3, 0x3, 0x3, 0x3, 0x0, 0x3, 0x3, 0x3,
cpm219 18:d1566d9b6ea1 203 };
cpm219 18:d1566d9b6ea1 204 /* array index values: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
cpm219 18:d1566d9b6ea1 205 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31};
cpm219 18:d1566d9b6ea1 206 */
cpm219 18:d1566d9b6ea1 207
cpm219 18:d1566d9b6ea1 208 static uint8_t present_state = 0x00,
cpm219 18:d1566d9b6ea1 209 tag = 0x00,
cpm219 18:d1566d9b6ea1 210 combo_input = 0x00;
cpm219 18:d1566d9b6ea1 211
cpm219 18:d1566d9b6ea1 212 static uint16_t tracker = 0x00;
cpm219 18:d1566d9b6ea1 213
cpm219 18:d1566d9b6ea1 214 static uint32_t reg32 = 0x00;
cpm219 18:d1566d9b6ea1 215
cpm219 18:d1566d9b6ea1 216 //start of gui_manager()
cpm219 18:d1566d9b6ea1 217 while(1) {
cpm219 18:d1566d9b6ea1 218 tag = 0x0;
cpm219 18:d1566d9b6ea1 219 //while(0x0 == tag)
cpm219 18:d1566d9b6ea1 220 // {
cpm219 18:d1566d9b6ea1 221 reg32 = TFT.Rd32(REG_TRACKER);
cpm219 18:d1566d9b6ea1 222 tag = reg32 & mask_reg_tracker_tag; //read tag register, update tag variable
cpm219 18:d1566d9b6ea1 223 tracker = ( reg32 & mask_reg_tracker_tracker)>> 16; //read tracker
cpm219 18:d1566d9b6ea1 224 // }
cpm219 18:d1566d9b6ea1 225 combo_input = ( present_state << 3) + tag; // concatenate present_state with tag to form combo input
cpm219 18:d1566d9b6ea1 226 present_state = state_lookup[combo_input]; // based on combo input, update present state
cpm219 18:d1566d9b6ea1 227 (*draw_screen[present_state])(tracker,tag); // use present_state as operand to draw screen function
cpm219 17:f98333612db8 228 }
cpm219 17:f98333612db8 229 }
cpm219 17:f98333612db8 230
montgojj 4:a48fc7a3bda9 231
cpm219 18:d1566d9b6ea1 232
cpm219 17:f98333612db8 233 /************************
cpm219 17:f98333612db8 234 function: main menu
cpm219 17:f98333612db8 235 description: draw main menu screen
cpm219 17:f98333612db8 236 *************************/
cpm219 18:d1566d9b6ea1 237 void main_menu(uint32_t tracker, uint8_t tag)
cpm219 17:f98333612db8 238 {
cpm219 22:2bdc80e45f3b 239 time_t seconds = time(NULL);
cpm219 18:d1566d9b6ea1 240
cpm219 17:f98333612db8 241 //start new display list
cpm219 17:f98333612db8 242 TFT.DLstart(); // start a new display command list
cpm219 17:f98333612db8 243 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
cpm219 17:f98333612db8 244 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 245
cpm219 18:d1566d9b6ea1 246 //bitmaps
cpm219 21:a50739772892 247 //TFT.DL(TAG(0)); // assign TAG value 0 to bitmap
cpm219 21:a50739772892 248 // TFT.DL(BITMAP_SOURCE(RAM_G));
cpm219 21:a50739772892 249 // TFT.DL(BITMAP_LAYOUT(RGB565,x_size*2,y_size));
cpm219 21:a50739772892 250 // TFT.DL(BITMAP_SIZE(NEAREST,BORDER,BORDER,x_size,y_size));
cpm219 21:a50739772892 251 //
cpm219 21:a50739772892 252 // TFT.DL(BEGIN(BITMAPS)); //start drawing bitmaps
cpm219 21:a50739772892 253 // TFT.DL(VERTEX2II(10,10,0,0)); // draw logo image with bit handle 0
cpm219 21:a50739772892 254 // TFT.DL(END());
cpm219 18:d1566d9b6ea1 255
cpm219 17:f98333612db8 256 //buttons
cpm219 18:d1566d9b6ea1 257 TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); //this sets the button text color
cpm219 18:d1566d9b6ea1 258 TFT.FgColor(0x007CC4); // this sets the button color
cpm219 18:d1566d9b6ea1 259
cpm219 17:f98333612db8 260 //button A
cpm219 17:f98333612db8 261 TFT.Track( 50, 165, 200, 150, 1); // track aree of button A
cpm219 18:d1566d9b6ea1 262 TFT.DL(TAG(1)); // assign TAG value 1 to "mode A" button
cpm219 18:d1566d9b6ea1 263 TFT.Button(50, 165, 200, 150, font_title, 0, text_a);
cpm219 18:d1566d9b6ea1 264
cpm219 17:f98333612db8 265 //button B
cpm219 17:f98333612db8 266 TFT.Track( 300, 165, 200, 150, 2); // track aree of button B
cpm219 17:f98333612db8 267 TFT.DL(TAG(2)); // assign TAG value 2 to "mode B" button
cpm219 18:d1566d9b6ea1 268 TFT.Button(300, 165, 200, 150, font_title, 0, text_b);
cpm219 18:d1566d9b6ea1 269
cpm219 17:f98333612db8 270 //button C
cpm219 18:d1566d9b6ea1 271 TFT.Track( 550, 165, 200, 150, 3); // track aree of button C
cpm219 17:f98333612db8 272 TFT.DL(TAG(3)); // assign TAG value 3 to "mode C" button
cpm219 18:d1566d9b6ea1 273 TFT.Button(550, 165, 200, 150, font_title, 0, text_c);
cpm219 18:d1566d9b6ea1 274
cpm219 17:f98333612db8 275 TFT.DL(TAG(0)); // assign TAG value 0 to everything else
cpm219 18:d1566d9b6ea1 276
cpm219 18:d1566d9b6ea1 277 //title text
cpm219 22:2bdc80e45f3b 278 TFT.DL(COLOR_RGB(0, 0, 0));
cpm219 17:f98333612db8 279 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_menu); // draw Text with font 31
cpm219 18:d1566d9b6ea1 280
cpm219 22:2bdc80e45f3b 281 // time
cpm219 22:2bdc80e45f3b 282 TFT.Text((TFT.DispWidth/4), TFT.DispHeight*7/8, font_title, OPT_CENTERX, text_time); // draw Text with font 31
cpm219 22:2bdc80e45f3b 283 TFT.Number((TFT.DispWidth/2), (TFT.DispHeight*7/8),font_title,OPT_CENTERX, seconds);
cpm219 22:2bdc80e45f3b 284
cpm219 17:f98333612db8 285 //author text
cpm219 18:d1566d9b6ea1 286 TFT.DL(COLOR_RGB(0x00, 0x00, 0x00));
cpm219 18:d1566d9b6ea1 287 TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31
cpm219 18:d1566d9b6ea1 288
cpm219 17:f98333612db8 289 //display the screen
cpm219 17:f98333612db8 290 TFT.DL(DISPLAY()); // display the image
cpm219 17:f98333612db8 291 TFT.Swap(); // swap the current display list
cpm219 17:f98333612db8 292 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 17:f98333612db8 293 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 17:f98333612db8 294
cpm219 18:d1566d9b6ea1 295 }
cpm219 18:d1566d9b6ea1 296
cpm219 17:f98333612db8 297
cpm219 17:f98333612db8 298 /************************
cpm219 17:f98333612db8 299 function: mode_a
cpm219 17:f98333612db8 300 description: draws mode a screen
cpm219 17:f98333612db8 301 *************************/
cpm219 18:d1566d9b6ea1 302 void mode_a(uint32_t tracker, uint8_t tag)
cpm219 18:d1566d9b6ea1 303 {
cpm219 18:d1566d9b6ea1 304
cpm219 17:f98333612db8 305 //start new display list
cpm219 17:f98333612db8 306 TFT.DLstart(); // start a new display command list
cpm219 22:2bdc80e45f3b 307 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to dark grey
cpm219 17:f98333612db8 308 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 309
cpm219 18:d1566d9b6ea1 310 TFT.DL(TAG(0)); // assign TAG value 0 to everything else
cpm219 22:2bdc80e45f3b 311
cpm219 18:d1566d9b6ea1 312
cpm219 22:2bdc80e45f3b 313
cpm219 18:d1566d9b6ea1 314
cpm219 22:2bdc80e45f3b 315
cpm219 22:2bdc80e45f3b 316
cpm219 18:d1566d9b6ea1 317
cpm219 22:2bdc80e45f3b 318 //button colors
cpm219 18:d1566d9b6ea1 319 TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF)); //this sets the button text color
cpm219 18:d1566d9b6ea1 320 TFT.FgColor(0x007CC4); // this sets the button color
cpm219 17:f98333612db8 321
cpm219 17:f98333612db8 322 //back button
cpm219 17:f98333612db8 323 TFT.Track( 50, 355, 100, 75, 4); // track aree of button back
cpm219 17:f98333612db8 324 TFT.DL(TAG(4));
cpm219 17:f98333612db8 325 TFT.Button(50, 355, 100, 75, font_button, 4, text_back); // assign TAG value 4 to text_back button
cpm219 22:2bdc80e45f3b 326
cpm219 22:2bdc80e45f3b 327 //title, author text
cpm219 22:2bdc80e45f3b 328 TFT.DL(TAG(0)); // assign TAG value 0 to everything else
cpm219 22:2bdc80e45f3b 329 TFT.DL(COLOR_RGB(0, 0, 0));
cpm219 22:2bdc80e45f3b 330 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_a); // draw Text with font 31
cpm219 22:2bdc80e45f3b 331 TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); //author text // draw Text with font 31
cpm219 18:d1566d9b6ea1 332
cpm219 17:f98333612db8 333
cpm219 17:f98333612db8 334 //display the screen
cpm219 17:f98333612db8 335 TFT.DL(DISPLAY()); // display the image
cpm219 17:f98333612db8 336 TFT.Swap(); // swap the current display list
cpm219 17:f98333612db8 337 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 17:f98333612db8 338 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 17:f98333612db8 339 }
cpm219 17:f98333612db8 340
cpm219 17:f98333612db8 341
cratliff 5:e2e04cb5eada 342
cpm219 17:f98333612db8 343 /************************
cpm219 17:f98333612db8 344 function: mode b
cpm219 17:f98333612db8 345 description: draws mode b screen.
cpm219 17:f98333612db8 346 *************************/
cpm219 18:d1566d9b6ea1 347 void mode_b(uint32_t tracker, uint8_t tag)
cpm219 22:2bdc80e45f3b 348 {
cpm219 17:f98333612db8 349 //start new display list
cpm219 17:f98333612db8 350 TFT.DLstart(); // start a new display command list
cpm219 17:f98333612db8 351 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
cpm219 17:f98333612db8 352 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 353
cpm219 18:d1566d9b6ea1 354
cpm219 22:2bdc80e45f3b 355 //button colors
cpm219 22:2bdc80e45f3b 356 TFT.DL(COLOR_RGB(255, 255, 255)); //this sets the button text color
cpm219 18:d1566d9b6ea1 357 TFT.FgColor(0x007CC4); // this sets the button color
cpm219 18:d1566d9b6ea1 358
cpm219 18:d1566d9b6ea1 359
cpm219 17:f98333612db8 360 //back button
cpm219 17:f98333612db8 361 TFT.Track( 50, 355, 100, 75, 4); // track aree of button back
cpm219 17:f98333612db8 362 TFT.DL(TAG(4));
cpm219 17:f98333612db8 363 TFT.Button(50, 355, 100, 75, font_button, 0, text_back); // assign TAG value 4 to text_back button
cpm219 18:d1566d9b6ea1 364
cpm219 22:2bdc80e45f3b 365 //title,author text
cpm219 17:f98333612db8 366 TFT.DL(TAG(0)); // assign TAG value 0 to everything else
cpm219 22:2bdc80e45f3b 367 TFT.DL(COLOR_RGB(0, 0, 0));
cpm219 17:f98333612db8 368 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_b); // draw Text with font 31
cpm219 18:d1566d9b6ea1 369 TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31
cpm219 18:d1566d9b6ea1 370
cpm219 18:d1566d9b6ea1 371 //display the screen
cpm219 18:d1566d9b6ea1 372 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 373 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 374 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 375 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 376 }
cpm219 18:d1566d9b6ea1 377
cpm219 18:d1566d9b6ea1 378
cpm219 18:d1566d9b6ea1 379 /************************
cpm219 18:d1566d9b6ea1 380 function: mode_c
cpm219 18:d1566d9b6ea1 381 description: draws mode C screen
cpm219 18:d1566d9b6ea1 382 *************************/
cpm219 18:d1566d9b6ea1 383 void mode_c(uint32_t tracker, uint8_t tag)
cpm219 18:d1566d9b6ea1 384 {
cpm219 18:d1566d9b6ea1 385 //start new display list
cpm219 18:d1566d9b6ea1 386 TFT.DLstart(); // start a new display command list
cpm219 22:2bdc80e45f3b 387 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
cpm219 20:92b3e641b306 388 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 17:f98333612db8 389
cpm219 18:d1566d9b6ea1 390
cpm219 22:2bdc80e45f3b 391 //button colors
cpm219 22:2bdc80e45f3b 392 TFT.DL(COLOR_RGB(255, 255, 255)); //this sets the button text color
cpm219 18:d1566d9b6ea1 393 TFT.FgColor(0x007CC4); // this sets the button color
cpm219 18:d1566d9b6ea1 394
cpm219 18:d1566d9b6ea1 395 //back button
cpm219 18:d1566d9b6ea1 396 TFT.Track( 50, 355, 100, 75, 4); // track aree of button back
cpm219 18:d1566d9b6ea1 397 TFT.DL(TAG(4));
cpm219 18:d1566d9b6ea1 398 TFT.Button(50, 355, 100, 75, font_button, 4, text_back); // assign TAG value 4 to text_back button
cpm219 18:d1566d9b6ea1 399
cpm219 22:2bdc80e45f3b 400 //title, author text
cpm219 18:d1566d9b6ea1 401 TFT.DL(TAG(0)); // assign TAG value 0 to everything else
cpm219 18:d1566d9b6ea1 402 TFT.DL(COLOR_RGB(0,0,0));
cpm219 22:2bdc80e45f3b 403 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/8, font_title, OPT_CENTERX, text_c); // draw Text with font 31
cpm219 18:d1566d9b6ea1 404 TFT.Text((TFT.DispWidth*7/8)+9, (TFT.DispHeight*15/16), font_button, OPT_CENTERX, text_author); // draw Text with font 31
cpm219 18:d1566d9b6ea1 405
cpm219 17:f98333612db8 406 //display the screen
cpm219 17:f98333612db8 407 TFT.DL(DISPLAY()); // display the image
cpm219 17:f98333612db8 408 TFT.Swap(); // swap the current display list
cpm219 17:f98333612db8 409 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 17:f98333612db8 410 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 17:f98333612db8 411 }
cpm219 17:f98333612db8 412
cpm219 17:f98333612db8 413
cpm219 17:f98333612db8 414
cpm219 17:f98333612db8 415 /************************
cpm219 17:f98333612db8 416 function: plot_nothing
cpm219 17:f98333612db8 417 description: clears plot area
cpm219 17:f98333612db8 418 *************************/
cpm219 17:f98333612db8 419 void plot_nothing(void)
cpm219 17:f98333612db8 420 {
cpm219 18:d1566d9b6ea1 421 TFT.DL(COLOR_RGB(0x00, 0x00, 0x00));
cpm219 17:f98333612db8 422
cpm219 17:f98333612db8 423 }
cpm219 17:f98333612db8 424
cpm219 17:f98333612db8 425
cpm219 18:d1566d9b6ea1 426
cpm219 17:f98333612db8 427 /************************
cpm219 17:f98333612db8 428 function: plot_square
cpm219 17:f98333612db8 429 description: plots square wave
cpm219 17:f98333612db8 430 *************************/
cpm219 17:f98333612db8 431 void plot_square(void)
cpm219 17:f98333612db8 432 {
cpm219 18:d1566d9b6ea1 433 static const int16_t square_wave_lookup[40] = { -100,-100,-100,-100,-100, 100,100,100,100,100,
cpm219 18:d1566d9b6ea1 434 -100,-100,-100,-100,-100, 100,100,100,100,100,
cpm219 18:d1566d9b6ea1 435 -100,-100,-100,-100,-100, 100,100,100,100,100,
cpm219 18:d1566d9b6ea1 436 -100,-100,-100,-100,-100, 100,100,100,100,100
cpm219 18:d1566d9b6ea1 437 };
cpm219 18:d1566d9b6ea1 438
cpm219 18:d1566d9b6ea1 439 TFT.DL(COLOR_RGB(0xFF, 0x00, 0x00));
cpm219 18:d1566d9b6ea1 440 for(i = 0; i<40; i++) {
cpm219 18:d1566d9b6ea1 441 TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 - (square_wave_lookup[i])*16) );
cpm219 17:f98333612db8 442 }
cpm219 17:f98333612db8 443 }
cpm219 17:f98333612db8 444
cpm219 17:f98333612db8 445
cpm219 18:d1566d9b6ea1 446
cpm219 17:f98333612db8 447 /************************
cpm219 17:f98333612db8 448 function: plot_triangle
cpm219 17:f98333612db8 449 description: plots triangle wave
cpm219 17:f98333612db8 450 *************************/
cpm219 17:f98333612db8 451 void plot_triangle(void)
cpm219 17:f98333612db8 452 {
cpm219 18:d1566d9b6ea1 453 static const int16_t tri_wave_lookup[40] = { 100,0,-100,0, 100,0,-100,0,
cpm219 18:d1566d9b6ea1 454 100,0,-100,0, 100,0,-100,0,
cpm219 18:d1566d9b6ea1 455 100,0,-100,0, 100,0,-100,0,
cpm219 18:d1566d9b6ea1 456 100,0,-100,0, 100,0,-100,0,
cpm219 18:d1566d9b6ea1 457 100,0,-100,0, 100,0,-100,0
cpm219 18:d1566d9b6ea1 458 };
cpm219 18:d1566d9b6ea1 459 TFT.DL(COLOR_RGB(0xFF, 0xFF, 0x00));
cpm219 18:d1566d9b6ea1 460 for(i = 0; i<40; i++) {
cpm219 18:d1566d9b6ea1 461 TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 - (tri_wave_lookup[i])*16) );
cpm219 17:f98333612db8 462 }
cpm219 17:f98333612db8 463 }
cpm219 18:d1566d9b6ea1 464
cpm219 18:d1566d9b6ea1 465
cpm219 18:d1566d9b6ea1 466
cpm219 18:d1566d9b6ea1 467 ///************************
cpm219 18:d1566d9b6ea1 468 // function: plot_sine
cpm219 18:d1566d9b6ea1 469 // description: plots sine wave
cpm219 18:d1566d9b6ea1 470 //*************************/
cpm219 18:d1566d9b6ea1 471 //void plot_sine(void)
cpm219 18:d1566d9b6ea1 472 //{
cpm219 18:d1566d9b6ea1 473 // static const int16_t sine_wave_lookup[40] = { 0, 16, 31, 45, 59, 71, 81, 89, 95, 99,
cpm219 18:d1566d9b6ea1 474 // 100, 99, 95, 89, 81, 71, 59, 45, 31, 16,
cpm219 18:d1566d9b6ea1 475 // -0, -16, -31, -45, -59, -71, -81, -89, -95, -99,
cpm219 18:d1566d9b6ea1 476 // -100, -99, -95, -89, -81, -71, -59, -45, -31, -16,
cpm219 18:d1566d9b6ea1 477 // };
cpm219 18:d1566d9b6ea1 478 //
cpm219 18:d1566d9b6ea1 479 // TFT.DL(COLOR_RGB(0xFF, 0x00, 0xFF));
cpm219 18:d1566d9b6ea1 480 // for(i = 0; i<40; i++) {
cpm219 18:d1566d9b6ea1 481 // TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 + (sine_wave_lookup[i])*16) );
cpm219 18:d1566d9b6ea1 482 // }
cpm219 18:d1566d9b6ea1 483 //}
cpm219 18:d1566d9b6ea1 484
cpm219 18:d1566d9b6ea1 485
cpm219 18:d1566d9b6ea1 486
cpm219 17:f98333612db8 487 /************************
cpm219 18:d1566d9b6ea1 488 function: plot_data1
cpm219 18:d1566d9b6ea1 489 description: plots analog_in data1
cpm219 17:f98333612db8 490 *************************/
cpm219 17:f98333612db8 491 void plot_sine(void)
cpm219 17:f98333612db8 492 {
cpm219 18:d1566d9b6ea1 493 static const int16_t sine_wave_lookup[40] = { 0, 16, 31, 45, 59, 71, 81, 89, 95, 99,
cpm219 18:d1566d9b6ea1 494 100, 99, 95, 89, 81, 71, 59, 45, 31, 16,
cpm219 18:d1566d9b6ea1 495 -0, -16, -31, -45, -59, -71, -81, -89, -95, -99,
cpm219 18:d1566d9b6ea1 496 -100, -99, -95, -89, -81, -71, -59, -45, -31, -16,
cpm219 18:d1566d9b6ea1 497 };
cpm219 18:d1566d9b6ea1 498
cpm219 17:f98333612db8 499 TFT.DL(COLOR_RGB(0xFF, 0x00, 0xFF));
cpm219 18:d1566d9b6ea1 500 for(i = 0; i<40; i++) {
cpm219 18:d1566d9b6ea1 501 TFT.DL( VERTEX2F(50*16 +18*i*16, 250*16 - (sine_wave_lookup[i])*16) );
cpm219 17:f98333612db8 502 }
cpm219 17:f98333612db8 503 }
cpm219 17:f98333612db8 504
cpm219 18:d1566d9b6ea1 505
cpm219 18:d1566d9b6ea1 506
cpm219 18:d1566d9b6ea1 507 /************************
cpm219 18:d1566d9b6ea1 508 function: collect_data
cpm219 18:d1566d9b6ea1 509 description: store ADC samples
cpm219 18:d1566d9b6ea1 510 *************************/
cpm219 18:d1566d9b6ea1 511 void collect_data(void)
cpm219 18:d1566d9b6ea1 512 {
cpm219 18:d1566d9b6ea1 513
cpm219 18:d1566d9b6ea1 514 static const uint16_t num_pts = 100;
cpm219 18:d1566d9b6ea1 515
cpm219 18:d1566d9b6ea1 516 static float collect_time = 0,
cpm219 18:d1566d9b6ea1 517 plot_time = 0,
cpm219 18:d1566d9b6ea1 518 trigger_time = 0;
cpm219 18:d1566d9b6ea1 519 static uint16_t i = 0x00,
cpm219 18:d1566d9b6ea1 520 j = 0x00;
cpm219 18:d1566d9b6ea1 521 static Timer timer;
cpm219 18:d1566d9b6ea1 522 static float begin[3] = {0,0,0}, // {trigger, sample, plot}
cpm219 18:d1566d9b6ea1 523 end[3] = {0,0,0}; // {trigger, sample, plot}
cpm219 18:d1566d9b6ea1 524
cpm219 18:d1566d9b6ea1 525 // static const uint16_t threshold = 10;
cpm219 18:d1566d9b6ea1 526
cpm219 18:d1566d9b6ea1 527 // data sample from ADC
cpm219 18:d1566d9b6ea1 528 static uint16_t data_raw_a9[num_pts] = {};
cpm219 18:d1566d9b6ea1 529
cpm219 18:d1566d9b6ea1 530 timer.start();
cpm219 18:d1566d9b6ea1 531 begin[0] = timer.read_us(); // trigger_begin
cpm219 18:d1566d9b6ea1 532
cpm219 18:d1566d9b6ea1 533
cpm219 18:d1566d9b6ea1 534 //do while trigger[0] < trigger[1]
cpm219 18:d1566d9b6ea1 535 //essentially find falling edge
cpm219 18:d1566d9b6ea1 536 do
cpm219 18:d1566d9b6ea1 537 {
cpm219 18:d1566d9b6ea1 538 data_raw_a9[0] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 539 data_raw_a9[1] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 540 }
cpm219 18:d1566d9b6ea1 541 while(data_raw_a9[1] < data_raw_a9[0]);
cpm219 18:d1566d9b6ea1 542
cpm219 18:d1566d9b6ea1 543 do
cpm219 18:d1566d9b6ea1 544 {
cpm219 18:d1566d9b6ea1 545 data_raw_a9[0] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 546 data_raw_a9[1] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 547 }
cpm219 18:d1566d9b6ea1 548 while(data_raw_a9[1] > data_raw_a9[0]);
cpm219 18:d1566d9b6ea1 549 //do
cpm219 18:d1566d9b6ea1 550 // {
cpm219 18:d1566d9b6ea1 551 // data_raw_a9[0] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 552 // data_raw_a9[1] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 553 // }
cpm219 18:d1566d9b6ea1 554 // while(data_raw_a9[1] < data_raw_a9[0]);
cpm219 18:d1566d9b6ea1 555 //
cpm219 18:d1566d9b6ea1 556 // do
cpm219 18:d1566d9b6ea1 557 // {
cpm219 18:d1566d9b6ea1 558 // data_raw_a9[0] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 559 // data_raw_a9[1] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 560 // }
cpm219 18:d1566d9b6ea1 561 // while(data_raw_a9[1] > data_raw_a9[0]);
cpm219 18:d1566d9b6ea1 562
cpm219 18:d1566d9b6ea1 563 timer.stop();
cpm219 18:d1566d9b6ea1 564 end[0] = timer.read_us(); //trigger_end
cpm219 18:d1566d9b6ea1 565
cpm219 18:d1566d9b6ea1 566
cpm219 18:d1566d9b6ea1 567 timer.start();
cpm219 18:d1566d9b6ea1 568 begin[1] = timer.read_us(); // sample_begin
cpm219 18:d1566d9b6ea1 569 //collect data
cpm219 18:d1566d9b6ea1 570 for(i=2;i<num_pts;i++)
cpm219 18:d1566d9b6ea1 571 {
cpm219 18:d1566d9b6ea1 572 //collect adc 9 most significant bits
cpm219 18:d1566d9b6ea1 573 data_raw_a9[i] = ((analog_in9.read_u16()>>7) & 0x1FF );
cpm219 18:d1566d9b6ea1 574 }
cpm219 18:d1566d9b6ea1 575 timer.stop();
cpm219 18:d1566d9b6ea1 576 end[1] = timer.read_us(); // sample_end
cpm219 18:d1566d9b6ea1 577
cpm219 18:d1566d9b6ea1 578
cpm219 18:d1566d9b6ea1 579 timer.start();
cpm219 18:d1566d9b6ea1 580 begin[2] = timer.read_us(); // plot_begin
cpm219 18:d1566d9b6ea1 581 //green plot
cpm219 18:d1566d9b6ea1 582 TFT.DL(COLOR_RGB(0x00, 0xFF, 0x00));
cpm219 18:d1566d9b6ea1 583 //plot data
cpm219 18:d1566d9b6ea1 584 for(i=0;i<num_pts;i++)
cpm219 18:d1566d9b6ea1 585 {
cpm219 18:d1566d9b6ea1 586 TFT.DL(VERTEX2F(8*i*16, TFT.DispHeight*16 - data_raw_a9[i]*15)); // 15/16 *512 = 480 which is disp_height
cpm219 18:d1566d9b6ea1 587 }
cpm219 18:d1566d9b6ea1 588 timer.stop();
cpm219 18:d1566d9b6ea1 589 end[2] = timer.read_us(); // plot_end
cpm219 18:d1566d9b6ea1 590
cpm219 18:d1566d9b6ea1 591
cpm219 18:d1566d9b6ea1 592 trigger_time =(end[0]-begin[0])/1000;
cpm219 18:d1566d9b6ea1 593 collect_time =(end[1]-begin[1])/1000;
cpm219 18:d1566d9b6ea1 594 plot_time = (end[2]-begin[2])/1000;
cpm219 18:d1566d9b6ea1 595
cpm219 18:d1566d9b6ea1 596 TFT.DL(COLOR_RGB(0xFF, 0xFF, 0xFF));
cpm219 18:d1566d9b6ea1 597 //data points
cpm219 18:d1566d9b6ea1 598 TFT.Text((TFT.DispWidth*7/8), TFT.DispHeight/32, font_button, OPT_RIGHTX, " data points: "); // draw Text with font 31
cpm219 18:d1566d9b6ea1 599 TFT.Number((TFT.DispWidth*7/8), (TFT.DispHeight/32),font_button,0,num_pts);
cpm219 18:d1566d9b6ea1 600
cpm219 18:d1566d9b6ea1 601 //trigger time
cpm219 18:d1566d9b6ea1 602 TFT.Text((TFT.DispWidth*7/8), TFT.DispHeight*3/32, font_button, OPT_RIGHTX, " trigger time [ms]: "); // draw Text with font 31
cpm219 18:d1566d9b6ea1 603 TFT.Number((TFT.DispWidth*7/8), (TFT.DispHeight*3/32),font_button,0,trigger_time);
cpm219 18:d1566d9b6ea1 604
cpm219 18:d1566d9b6ea1 605 //sample time
cpm219 18:d1566d9b6ea1 606 TFT.Text((TFT.DispWidth*7/8), TFT.DispHeight*5/32, font_button, OPT_RIGHTX, "sample time [ms]: "); // draw Text with font 31
cpm219 18:d1566d9b6ea1 607 TFT.Number((TFT.DispWidth*7/8), (TFT.DispHeight*5/32),font_button,0,collect_time);
cpm219 18:d1566d9b6ea1 608
cpm219 18:d1566d9b6ea1 609 //plot time
cpm219 18:d1566d9b6ea1 610 TFT.Text((TFT.DispWidth*7/8), TFT.DispHeight*7/32, font_button, OPT_RIGHTX, "plot time [ms]: "); // draw Text with font 31
cpm219 18:d1566d9b6ea1 611 TFT.Number((TFT.DispWidth*7/8), (TFT.DispHeight*7/32),font_button,0,plot_time);
cpm219 18:d1566d9b6ea1 612
cpm219 18:d1566d9b6ea1 613 }
cpm219 18:d1566d9b6ea1 614
cpm219 18:d1566d9b6ea1 615
cpm219 18:d1566d9b6ea1 616
cpm219 18:d1566d9b6ea1 617 /****************************************************************************/
cpm219 18:d1566d9b6ea1 618 /* Checks for an SD card and reads/writes the calibration data */
cpm219 18:d1566d9b6ea1 619 /* from the SD card */
cpm219 18:d1566d9b6ea1 620 /****************************************************************************/
cpm219 18:d1566d9b6ea1 621 uint8_t read_calibration()
cpm219 18:d1566d9b6ea1 622 {
cpm219 18:d1566d9b6ea1 623 static ft_char8_t temp_string[32] = {"\0"};
cpm219 18:d1566d9b6ea1 624 static uint8_t tcal[24]; // touch screen Calibration
cpm219 18:d1566d9b6ea1 625
cpm219 20:92b3e641b306 626 while(!sdcard_present.read()) {
cpm219 18:d1566d9b6ea1 627 // checks for SD card, if not present hold program until a SD card is inserted
cpm219 18:d1566d9b6ea1 628 error_screen("Error!","Insert SD card!"); // write error screen to LCD
cpm219 18:d1566d9b6ea1 629 }
cpm219 18:d1566d9b6ea1 630
cpm219 18:d1566d9b6ea1 631 sd.mount();
cpm219 18:d1566d9b6ea1 632 FILE *fp= fopen("/sd/TCal/TCalData.txt", "r");
cpm219 18:d1566d9b6ea1 633 if (fp != NULL) {
cpm219 18:d1566d9b6ea1 634 //file successfully opened for reading!
cpm219 18:d1566d9b6ea1 635 fread(temp_string,24,1,fp);
cpm219 18:d1566d9b6ea1 636 for (i = 0; i < 24; i++) {
cpm219 18:d1566d9b6ea1 637 // convert from int to char
cpm219 18:d1566d9b6ea1 638 tcal[i] = temp_string[i];
cpm219 18:d1566d9b6ea1 639 }
cpm219 18:d1566d9b6ea1 640 TFT.write_calibrate(tcal); // write cal data to screen
cpm219 18:d1566d9b6ea1 641 fclose(fp);
cpm219 18:d1566d9b6ea1 642 sd.unmount();
cpm219 18:d1566d9b6ea1 643 return 0;
cpm219 18:d1566d9b6ea1 644 } else {
cpm219 18:d1566d9b6ea1 645 //file not opened. might not exist.
cpm219 18:d1566d9b6ea1 646 TFT.Calibrate(); // calibrate the touch screen
cpm219 18:d1566d9b6ea1 647 TFT.read_calibrate(tcal); // read in cal data from screen
cpm219 18:d1566d9b6ea1 648 mkdir("/sd/TCal", 0777); // open file for saving calibration data
cpm219 18:d1566d9b6ea1 649 FILE *fp = fopen("/sd/TCal/TCalData.txt", "w");
cpm219 18:d1566d9b6ea1 650 for (i = 0; i < 25; i++) { // save integers one at a time to the file
cpm219 18:d1566d9b6ea1 651 fprintf(fp, "%c", tcal[i] );
cpm219 18:d1566d9b6ea1 652 }
cpm219 18:d1566d9b6ea1 653 fclose(fp);
cpm219 18:d1566d9b6ea1 654 sd.unmount();
cpm219 18:d1566d9b6ea1 655 return 1;
cpm219 18:d1566d9b6ea1 656
cpm219 18:d1566d9b6ea1 657 }
cpm219 18:d1566d9b6ea1 658 }
cpm219 18:d1566d9b6ea1 659
cpm219 18:d1566d9b6ea1 660
cpm219 18:d1566d9b6ea1 661
cpm219 18:d1566d9b6ea1 662 /****************************************************************************
cpm219 18:d1566d9b6ea1 663 * tests functional operation of sd card by read/write
cpm219 18:d1566d9b6ea1 664 ****************************************************************************/
cpm219 18:d1566d9b6ea1 665 uint8_t sd_test(void)
cpm219 18:d1566d9b6ea1 666 {
cpm219 20:92b3e641b306 667 while(!sdcard_present.read()) {
cpm219 18:d1566d9b6ea1 668 // checks for SD card, if not present hold program until a SD card is inserted
cpm219 18:d1566d9b6ea1 669 error_screen("Error!","Insert SD card!"); // write error screen to LCD
cpm219 18:d1566d9b6ea1 670 }
cpm219 18:d1566d9b6ea1 671
cpm219 18:d1566d9b6ea1 672 TFT.DLstart(); // start a new display command list
cpm219 18:d1566d9b6ea1 673 TFT.DL(CLEAR_COLOR_RGB(0,0,0)); // clear the screen and set the background to green
cpm219 18:d1566d9b6ea1 674 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 675 TFT.DL(COLOR_RGB(255,255,255));
cpm219 18:d1566d9b6ea1 676
cpm219 18:d1566d9b6ea1 677 sd.mount();
cpm219 18:d1566d9b6ea1 678
cpm219 18:d1566d9b6ea1 679 //Perform a write test
cpm219 18:d1566d9b6ea1 680 // printf("\nWriting to SD card...");
cpm219 18:d1566d9b6ea1 681 TFT.Text((TFT.DispWidth/2), 150, 28, OPT_CENTERX, "Writing to SD card...\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 682 FILE *fp = fopen("/sd/sdtest.txt", "w");
cpm219 18:d1566d9b6ea1 683 if (fp != NULL) {
cpm219 18:d1566d9b6ea1 684 //file successfully opened for writing!
cpm219 18:d1566d9b6ea1 685 fprintf(fp, "We're writing to an SD card!");
cpm219 18:d1566d9b6ea1 686 fclose(fp);
cpm219 18:d1566d9b6ea1 687 TFT.DL(CLEAR_COLOR_RGB(0,255,0)); // clear the screen and set the background to green
cpm219 18:d1566d9b6ea1 688 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 689 TFT.Text((TFT.DispWidth/2), 200, 28, OPT_CENTERX,"open file success\0" ); // draw Text with font 31
cpm219 18:d1566d9b6ea1 690
cpm219 18:d1566d9b6ea1 691 } else {
cpm219 18:d1566d9b6ea1 692 // printf("failed!\n");
cpm219 18:d1566d9b6ea1 693 TFT.DL(CLEAR_COLOR_RGB(255,0,0)); // clear the screen and set the background to green
cpm219 18:d1566d9b6ea1 694 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 695 TFT.Text((TFT.DispWidth/2), 200, 28, OPT_CENTERX, "open file failed!\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 696 }
cpm219 18:d1566d9b6ea1 697
cpm219 18:d1566d9b6ea1 698 //Perform a read test
cpm219 18:d1566d9b6ea1 699 // fprintf("Reading from SD card...");
cpm219 18:d1566d9b6ea1 700 TFT.Text((TFT.DispWidth/2), 250, 28, OPT_CENTERX, "Reading from SD card...\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 701
cpm219 18:d1566d9b6ea1 702 fp = fopen("/sd/sdtest.txt", "r");
cpm219 18:d1566d9b6ea1 703 if (fp != NULL) {
cpm219 18:d1566d9b6ea1 704 char c = fgetc(fp);
cpm219 18:d1566d9b6ea1 705 if (c == 'W') {
cpm219 18:d1566d9b6ea1 706 // printf("success!\n");
cpm219 18:d1566d9b6ea1 707 TFT.Text((TFT.DispWidth/2), 300, 28, OPT_CENTERX, "correct char!\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 708
cpm219 18:d1566d9b6ea1 709 } else {
cpm219 18:d1566d9b6ea1 710 // fprintf("incorrect char (%c)!\n", c);
cpm219 18:d1566d9b6ea1 711 TFT.Text((TFT.DispWidth/2), 300, 28, OPT_CENTERX, "incorrect char!\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 712 }
cpm219 18:d1566d9b6ea1 713 sd.unmount();
cpm219 18:d1566d9b6ea1 714 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 715 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 716 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 717 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 718 TFT.Sleep(2000);
cpm219 18:d1566d9b6ea1 719 fclose(fp);
cpm219 18:d1566d9b6ea1 720 return 0;
cpm219 18:d1566d9b6ea1 721
cpm219 18:d1566d9b6ea1 722 } else {
cpm219 18:d1566d9b6ea1 723 // printf("failed!\n");
cpm219 18:d1566d9b6ea1 724 TFT.Text((TFT.DispWidth/2), 250, 31, OPT_CENTERX, "failed to read!\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 725 sd.unmount();
cpm219 18:d1566d9b6ea1 726 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 727 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 728 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 729 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 730 TFT.Sleep(2000);
cpm219 18:d1566d9b6ea1 731 return 1;
cpm219 18:d1566d9b6ea1 732 }
cpm219 18:d1566d9b6ea1 733 }
cpm219 18:d1566d9b6ea1 734
cpm219 18:d1566d9b6ea1 735
cpm219 18:d1566d9b6ea1 736
cpm219 18:d1566d9b6ea1 737 uint8_t bitmap_test(uint16_t x,uint16_t y)
cpm219 18:d1566d9b6ea1 738 {
cpm219 18:d1566d9b6ea1 739
cpm219 18:d1566d9b6ea1 740 TFT.DLstart(); // start a new display command list
cpm219 18:d1566d9b6ea1 741 TFT.DL(CLEAR_COLOR_RGB(0,0,0)); // clear the screen and set the background to green
cpm219 18:d1566d9b6ea1 742 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 743 TFT.DL(COLOR_RGB(255,255,255));
cpm219 18:d1566d9b6ea1 744
cpm219 18:d1566d9b6ea1 745 //following 3 lines can be replaced with TFT.set_bitmap(0x00, 0, )
cpm219 18:d1566d9b6ea1 746 TFT.DL(BITMAP_SOURCE(RAM_G));
cpm219 18:d1566d9b6ea1 747 TFT.DL(BITMAP_LAYOUT(ARGB1555,2*x_size,y_size));
cpm219 18:d1566d9b6ea1 748 TFT.DL(BITMAP_SIZE(NEAREST,BORDER,BORDER,x_size,y_size));
cpm219 18:d1566d9b6ea1 749
cpm219 18:d1566d9b6ea1 750 TFT.DL(BEGIN(BITMAPS)); //start drawing bitmaps
cpm219 18:d1566d9b6ea1 751 TFT.DL(VERTEX2II(25,25,0,0)); // draw logo image with bit handle 0
cpm219 18:d1566d9b6ea1 752 TFT.DL(END());
cpm219 18:d1566d9b6ea1 753
cpm219 18:d1566d9b6ea1 754 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, "bitmap_test() called\0"); // draw Text with font 31
cpm219 18:d1566d9b6ea1 755
cpm219 18:d1566d9b6ea1 756 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 757 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 758 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 759 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 760
cpm219 18:d1566d9b6ea1 761 return 0;
cpm219 18:d1566d9b6ea1 762 }
cpm219 18:d1566d9b6ea1 763
cpm219 18:d1566d9b6ea1 764
cpm219 18:d1566d9b6ea1 765
cpm219 18:d1566d9b6ea1 766 /* function to load jpg file from filesystem */
cpm219 18:d1566d9b6ea1 767 /* return 0 if jpg is ok */
cpm219 18:d1566d9b6ea1 768 /* also return x_size and y_size of jpg */
cpm219 18:d1566d9b6ea1 769
cpm219 18:d1566d9b6ea1 770 int8_t Load_jpg(char* filename, ft_int16_t* x_size, ft_int16_t* y_size, ft_uint32_t address)
cpm219 18:d1566d9b6ea1 771 {
cpm219 18:d1566d9b6ea1 772 static int8_t rval = 0x00;
cpm219 18:d1566d9b6ea1 773
cpm219 20:92b3e641b306 774 while(!sdcard_present.read()) {
cpm219 18:d1566d9b6ea1 775 // checks for SD card, if not present hold program until a SD card is inserted
cpm219 18:d1566d9b6ea1 776 error_screen("Error!","Insert SD card!"); // write error screen to LCD
cpm219 18:d1566d9b6ea1 777 }
cpm219 18:d1566d9b6ea1 778
cpm219 18:d1566d9b6ea1 779 sd.mount();
cpm219 18:d1566d9b6ea1 780 rval = TFT.Load_jpg( filename, x_size, y_size, address);
cpm219 18:d1566d9b6ea1 781 sd.unmount();
cpm219 18:d1566d9b6ea1 782 return rval;
cpm219 18:d1566d9b6ea1 783 }
cpm219 18:d1566d9b6ea1 784
cpm219 18:d1566d9b6ea1 785
cpm219 18:d1566d9b6ea1 786
cpm219 18:d1566d9b6ea1 787 /************************
cpm219 18:d1566d9b6ea1 788 function: display_message
cpm219 18:d1566d9b6ea1 789 description: draws a pass/fail type message to the screen.
cpm219 18:d1566d9b6ea1 790 useful for debugging return values from functions.
cpm219 18:d1566d9b6ea1 791 *************************/
cpm219 18:d1566d9b6ea1 792 void display_message(uint8_t error, const ft_char8_t *pass, const ft_char8_t *fail)
cpm219 18:d1566d9b6ea1 793 {
cpm219 18:d1566d9b6ea1 794 TFT.DLstart(); // start a new display command list
cpm219 18:d1566d9b6ea1 795 TFT.DL(COLOR_RGB(0,0,0));
cpm219 18:d1566d9b6ea1 796
cpm219 18:d1566d9b6ea1 797 if(error == 0x00) {
cpm219 18:d1566d9b6ea1 798 TFT.DL(CLEAR_COLOR_RGB(0,255,0)); // clear the screen and set the background to green
cpm219 18:d1566d9b6ea1 799 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 800 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, pass); // draw Text with font 31
cpm219 18:d1566d9b6ea1 801 } else {
cpm219 18:d1566d9b6ea1 802 TFT.DL(CLEAR_COLOR_RGB(255,0,0)); // clear the screen and set the background to red
cpm219 18:d1566d9b6ea1 803 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 804 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, fail); // draw Text with font 31
cpm219 18:d1566d9b6ea1 805 }
cpm219 18:d1566d9b6ea1 806
cpm219 18:d1566d9b6ea1 807 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 808 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 809 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 810 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 811 }
cpm219 18:d1566d9b6ea1 812
cpm219 18:d1566d9b6ea1 813
cpm219 18:d1566d9b6ea1 814
cpm219 17:f98333612db8 815 /************************
cpm219 17:f98333612db8 816 function: Start_Screen
cpm219 17:f98333612db8 817 description: draws boot up screen as images are loaded from the sd card
cpm219 17:f98333612db8 818 *************************/
cpm219 18:d1566d9b6ea1 819 ft_void_t start_screen(ft_char8_t *str)
cratliff 0:aa55c6eb6867 820 {
montgojj 11:f6a146b62579 821 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 822 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
montgojj 11:f6a146b62579 823 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 824
cpm219 17:f98333612db8 825 TFT.DL(COLOR_RGB(0x00, 0x7C, 0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format
montgojj 4:a48fc7a3bda9 826 TFT.DL(BEGIN(LINES));
montgojj 4:a48fc7a3bda9 827 TFT.DL(LINE_WIDTH(8 * 16));
montgojj 4:a48fc7a3bda9 828 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 829 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 830 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 831 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 832 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 833 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 834 TFT.DL(VERTEX2F(0*16,479*16));
cratliff 5:e2e04cb5eada 835 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 836 TFT.DL(END());
cpm219 18:d1566d9b6ea1 837
cpm219 17:f98333612db8 838 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
cpm219 17:f98333612db8 839 TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, text_author); // draw Text with font 31
cpm219 17:f98333612db8 840 TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner
cpm219 18:d1566d9b6ea1 841
cpm219 17:f98333612db8 842 TFT.DL(DISPLAY()); // Display the image
cpm219 17:f98333612db8 843 TFT.Swap(); // Swap the current display list
cpm219 17:f98333612db8 844 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cpm219 17:f98333612db8 845 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 846 }
cpm219 18:d1566d9b6ea1 847
cpm219 18:d1566d9b6ea1 848
cpm219 18:d1566d9b6ea1 849
cpm219 18:d1566d9b6ea1 850 /****************************************************************************/
cpm219 18:d1566d9b6ea1 851 /* This function displays the error screen */
cpm219 18:d1566d9b6ea1 852 /* the function causes the screen to flash yellow and writes text to the LCD*/
cpm219 18:d1566d9b6ea1 853 /****************************************************************************/
cpm219 18:d1566d9b6ea1 854 void error_screen(ft_char8_t *str1, ft_char8_t *str2)
cpm219 18:d1566d9b6ea1 855 {
cpm219 18:d1566d9b6ea1 856 TFT.DLstart(); // start a new display command list
cpm219 18:d1566d9b6ea1 857 TFT.DL(CLEAR_COLOR_RGB(255,242,0)); // clear the screen and set the background to yellow
cpm219 18:d1566d9b6ea1 858 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cpm219 18:d1566d9b6ea1 859 TFT.DL(COLOR_RGB(0,0,0));
cpm219 18:d1566d9b6ea1 860 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, str1); // draw Text with font 31
cpm219 18:d1566d9b6ea1 861 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, str2); // draw Text with font 31
cpm219 18:d1566d9b6ea1 862 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 863 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 864 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 865 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 866 TFT.Sleep(500);
cpm219 18:d1566d9b6ea1 867
cpm219 18:d1566d9b6ea1 868 TFT.DLstart(); // start a new display command list
cpm219 18:d1566d9b6ea1 869 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set clear color to white
cpm219 18:d1566d9b6ea1 870 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer;
cpm219 18:d1566d9b6ea1 871 TFT.DL(COLOR_RGB(0,0,0));
cpm219 18:d1566d9b6ea1 872 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, str1); // draw Text with font 31
cpm219 18:d1566d9b6ea1 873 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, str2); // draw Text with font 31
cpm219 18:d1566d9b6ea1 874 TFT.DL(DISPLAY()); // display the image
cpm219 18:d1566d9b6ea1 875 TFT.Swap(); // swap the current display list
cpm219 18:d1566d9b6ea1 876 TFT.Flush_Co_Buffer(); // download the command list into fifo
cpm219 18:d1566d9b6ea1 877 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cpm219 18:d1566d9b6ea1 878 TFT.Sleep(500);
montgojj 8:886908a6127c 879 }