/// @brief Initialize TFT /// @return diplay ID 9341 MEMSPACE window *tft_init(void) { // Start with slow clock so tft_readId works // This is the only function that fails at less then 1. // tft_readId is the ONLY SPI bus command that needs this. // Nomal reads work fine. tft_addr_init(); tft_spi_init_slow(); // reset display tft_reset_init(); tft_reset_enable(); tft_delay_us(10000); tft_reset_disable(); tft_delay_us(1000); /* Adafruit 9341 TFT Display Initialization */ tft_configRegister(); /* Read the TFT ID value */ tft_ID = tft_readId(); // fast SPI tft_spi_init_fast(); /* Setup the master window */ tft_window_init(tft, TFT_XOFF, TFT_YOFF, TFT_W, TFT_H); tft_setRotation(0); tft_fillWin(tft, tft->bg); return (tft); }
/// @brief Initialize TFT /// @return diplay ID 9341 MEMSPACE window *tft_init(void) { TFT_RST_INIT; // RESET PIN TFT_INIT; // DATA/COMMAND TFT_CS_INIT; // CHIP SELLECT hspi_cs_disable(TFT_CS_PIN); // TFT_CS_DISABLE; // Start with slow clock so tft_readId works // This is the only function that fails at less then 1. // tft_readId is the ONLY SPI bus command that needs this. // Nomal reads work fine. tft_spi_init(2); TFT_RST_ACTIVE; os_delay_us(10000); TFT_RST_DEACTIVE; os_delay_us(1000); /* Adafruit 9341 TFT Display Initialization */ tft_configRegister(); /* Read the TFT ID value */ tft_ID = tft_readId(); // fast SPI tft_spi_init(1); /* Setup the master window */ tft_window_init(tft, TFT_XOFF, TFT_YOFF, TFT_W, TFT_H); tft_setRotation(0); tft_fillWin(tft, tft->bg); return (tft); }
/** @brief main() Initialize user task @return void */ MEMSPACE void user_init(void) { int i; os_event_t *handlerQueue; char time[20]; int ret; uint16_t *ptr; uint32_t time1,time2; uint32_t ID; extern uint16_t tft_ID; double ang; os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle // Configure the UART uart_init(BIT_RATE_115200,BIT_RATE_115200); DEBUG_PRINTF("\n"); DEBUG_PRINTF("System init...\n"); DEBUG_PRINTF("HSPI init...\n"); hspi_init(1,0); DEBUG_PRINTF("Timers init...\n"); init_timers(); DEBUG_PRINTF("SD Card init...\n"); mmc_init(1); // CPU // 160MHZ // REG_SET_BIT(0x3ff00014, BIT(0)); // 80MHZ // REG_CLR_BIT(0x3ff00014, BIT(0)); DEBUG_PRINTF("Display Init\n"); // Initialize TFT master = tft_init(); ID = tft_ID; // Set master rotation tft_setRotation(1); /* Setup main status window */ tft_window_init(winstats,0,0, master->w * 7 / 10, master->h/2); tft_setpos(winstats, 0,0); tft_set_font(winstats,5); tft_font_var(winstats); tft_setTextColor(winstats, ILI9341_RED,0); tft_printf(winstats, "DISP ID: %04lx\n", ID); ip_xpos = winstats->x; ip_ypos = winstats->y; tft_printf(winstats, "\n"); tft_setTextColor(winstats, ILI9341_WHITE,0); #if ILI9341_DEBUG & 1 DEBUG_PRINTF("\nDisplay ID=%08lx\n",ID); #endif tft_font_fixed(winstats); // Save last display offset of the status update line - used in the demo task xpos = winstats->x; ypos = winstats->y; /* Setup cube/wireframe demo window */ tft_window_init(windemo,winstats->w,0, master->w - winstats->w, master->h/2); // Cube points were defined with sides of 1.0 // We want a scale of +/- w/2 if(windemo->w < windemo->h) dscale_max = windemo->w/2; else dscale_max = windemo->h/2; dscale = dscale_max; dscale_inc = dscale_max / 100; /* Setup second window for window testing*/ tft_window_init(wintest,0,master->h/2, master->w/2, master->h/2); tft_setTextColor(wintest, ILI9341_WHITE,ILI9341_NAVY); tft_fillWin(wintest, wintest->bg); tft_set_font(wintest,3); //tft_font_var(wintest); // write some text tft_setpos(wintest, 0,0); tft_printf(wintest, "Test1\nTest2\nTest3"); /* Test demo area window */ tft_window_init(wintestdemo,master->w/2,master->h/2,master->w/2, master->h/2); tft_setTextColor(wintestdemo, ILI9341_WHITE,0); tft_fillWin(wintestdemo, wintestdemo->bg); tft_set_font(wintestdemo,3); tft_font_var(wintestdemo); #if ILI9341_DEBUG & 1 DEBUG_PRINTF("Test Display Read\n"); read_tests(wintest); #endif /* Draw cube in the second window as a test */ #if defined(WIRECUBE) && !defined(EARTH) DEBUG_PRINTF("Draw Cube\n"); // Cube points were defined with sides of 1.0 // We want a scale of +/- w/2 double tscale_max; if(wintestdemo->w < wintestdemo->h) tscale_max = wintestdemo->w/2; else tscale_max = wintestdemo->h/2; ang = 45.0; V.x = ang; V.y = ang; V.z = ang; wire_draw(wintestdemo, cube_points, cube_edges, &V, wintestdemo->w/2, wintestdemo->h/2, tscale_max, ILI9341_RED); #endif #ifdef EARTH DEBUG_PRINTF("Draw Earth\n"); // Earth points were defined with radius of 0.5, diameter of 1.0 // We want a scale of +/- w/2 double tscale_max; if(wintestdemo->w < wintestdemo->h) tscale_max = wintestdemo->w; else tscale_max = wintestdemo->h; V.x = -90; V.y = -90; V.z = -90; // draw earth //time1 = system_get_time(); // Earth points were defined over with a scale of -0.5/+0.5 scale - so scale must be 1 or less wire_draw(wintestdemo, earth_data, NULL, &V, wintestdemo->w/2, wintestdemo->h/2, tscale_max, wintestdemo->fg); //time2 = system_get_time(); #endif wdt_reset(); DEBUG_PRINTF("User Task\n"); // Set up a timer to send the message to User Task os_timer_disarm(&UserTimerHandler); os_timer_setfn(&UserTimerHandler,(os_timer_func_t *)sendMsgToUserTask,(void *)0); os_timer_arm(&UserTimerHandler, USER_TASK_DELAY_TIMER, 1); // Setup the user task system_os_task(UserTask, UserTaskPrio, UserTaskQueue, UserTaskQueueLen); #ifdef TELNET_SERIAL DEBUG_PRINTF("Setup Network Serial Bridge\n"); bridge_task_init(23); #endif #ifdef NETWORK_TEST DEBUG_PRINTF("Setup Network TFT DIsplay Client\n"); setup_networking(TCP_PORT); #endif #if 0 // Misc Task init - testing only system_os_task(HighTask, HighTaskPrio, HighTaskQueue, HighTaskQueueLen); system_os_task(NormalTask, NormalTaskPrio, NormalTaskQueue, NormalTaskQueueLen); system_os_task(IdleTask, IdleTaskPrio, IdleTaskQueue, IdleTaskQueueLen); system_os_post(IdleTaskPrio, 0, 0); #endif DEBUG_PRINTF("Done Setup\n"); DEBUG_PRINTF("Heap Size(%d) bytes\n" , system_get_free_heap_size()); // disable os_printf at this time system_set_os_print(0); system_init_done_cb(init_done_cb); }
setup_windows(int rotation, int debug) { int16_t x,y,w,h; uint32_t ID; extern uint16_t tft_ID; ID = tft_ID; // Set master rotation tft_setRotation(rotation); tft_setTextColor(master, ILI9341_WHITE,ILI9341_BLUE); tft_fillWin(master, master->bg); #if ILI9341_DEBUG & 1 if(debug) printf("\nDisplay ID=%08lx\n",ID); #endif // Message window setup #ifdef EARTH w = master->w * 7 / 10; #else w = master->w; #endif // TOP #ifdef DEBUG_STATS tft_window_init(wintop,0,0, w, font_H(0)*4); tft_setTextColor(wintop, ILI9341_WHITE, ILI9341_NAVY); #else tft_window_init(wintop,0,0, w, font_H(2)*2); tft_setTextColor(wintop, ILI9341_WHITE, tft_RGBto565(0,64,255)); #endif tft_set_font(wintop,0); tft_font_var(wintop); tft_fillWin(wintop, wintop->bg); tft_set_textpos(wintop, 0,0); #ifdef EARTH tft_window_init(winearth,w,0, master->w - w + 1, wintop->h); tft_setTextColor(winearth, ILI9341_WHITE, ILI9341_NAVY); tft_fillWin(winearth, winearth->bg); #endif // BOTOM // TIME,DATE tft_window_init(winbottom, 0, master->h - 1 - font_H(2)*2, master->w, font_H(2)*2); if(master->rotation & 1) tft_set_font(winbottom,2); else tft_set_font(winbottom,1); tft_font_var(winbottom); tft_setTextColor(winbottom, 0, tft_RGBto565(0,255,0)); tft_fillWin(winbottom, winbottom->bg); tft_set_textpos(winbottom, 0,0); // Message window setup #ifdef WIRECUBE w = master->w * 7 / 10; #else w = master->w; #endif // MSG tft_window_init(winmsg,0,wintop->h, w, master->h - (wintop->h + winbottom->h)); tft_setTextColor(winmsg, ILI9341_WHITE,ILI9341_BLUE); tft_fillWin(winmsg, winmsg->bg); // write some text tft_set_font(winmsg,0); tft_font_var(winmsg); tft_set_textpos(winmsg, 0,0); // CUBE setup #ifdef WIRECUBE /* Setup cube/wireframe demo window */ /* This is to the right of the winmsg window and the same height */ tft_window_init(wincube, winmsg->w, wintop->h, master->w - winmsg->w, winmsg->h); tft_setTextColor(wincube, ILI9341_WHITE,ILI9341_BLUE); tft_fillWin(wincube, wincube->bg); #endif #ifdef DEBUG_STATS if(debug) { // Display ID tft_setTextColor(winmsg, ILI9341_RED,winmsg->bg); tft_printf(winmsg, "DISP ID: %04lx\n", ID); tft_setTextColor(winmsg, ILI9341_WHITE,winmsg->bg); #ifdef XPT2046 if(!tft_is_calibrated) { tft_set_font(winmsg,0); tft_printf(winmsg,"Please Calibrate Display\n"); tft_printf(winmsg,"serial command: calibrate N\n"); tft_printf(winmsg,"N is rotation, 0..3\n"); tft_printf(winmsg,"%d is current\n",master->rotation); } #endif } #endif // Cube points were defined with sides of 1.0 // We want a scale of +/- w/2 #ifdef WIRECUBE if(wincube->w < wincube->h) dscale_max = wincube->w/2; else dscale_max = wincube->h/2; dscale = dscale_max; dscale_inc = dscale_max / 100; #endif #if ILI9341_DEBUG & 1 if(debug) { printf("Test Display Read\n"); read_tests(winmsg); } #endif // Draw Wireframe earth in message area #ifdef EARTH // Earth points were defined with radius of 0.5, diameter of 1.0 // We want a scale of +/- w/2 double tscale_max; if(winearth->w < winearth->h) tscale_max = winearth->w; else tscale_max = winearth->h; V.x = -90; V.y = -90; V.z = -90; // draw earth // Earth points were defined over with a scale of -0.5/+0.5 scale - so scale must be 1 or less wire_draw(winearth, earth_data, NULL, &V, winearth->w/2, winearth->h/2, tscale_max, winearth->fg); #endif }