basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cpm219
Date:
Wed Sep 07 23:11:49 2016 +0000
Revision:
21:a50739772892
Parent:
20:92b3e641b306
Child:
22:2bdc80e45f3b
latest

Who changed what in which revision?

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