/// @brief Obtain SPI bus for TFT display, assert chip select /// return: void void tft_spi_begin() { hspi_waitReady(); hspi_init(tft_clock, 0); hspi_cs_enable(TFT_CS_PIN); //TFT_CS_ACTIVE; }
/** @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); }
/** @brief main() Initialize user task @return void */ MEMSPACE void setup(void) { int i; char time[20]; int ret; uint16_t *ptr; double ang; extern web_init(); int w,h; ip_msg[0] = 0; // CPU // 160MHZ REG_SET_BIT(0x3ff00014, BIT(0)); // 80MHZ // REG_CLR_BIT(0x3ff00014, BIT(0)); os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle // Configure the UART //uart_init(BIT_RATE_115200,BIT_RATE_115200); uart_init(BIT_RATE_74880,BIT_RATE_74880); os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle os_delay_us(200000L); // Power Up dalay - lets power supplies and devices settle printf("\n\n\n\n"); sep(); printf("System init...\n"); printf("ESP8266 multidevice project\n"); printf(" (c) 2014-2017 by Mike Gore\n"); printf(" GNU version 3\n"); printf("-> https://github.com/magore/esp8266_ili9341\n"); printf(" GIT last pushed: %s\n", GIT_VERSION); printf(" Last updated file: %s\n", LOCAL_MOD); sep(); PrintRam(); sep(); printf("HSPI init...\n"); hspi_init(1,0); printf("Timers init...\n"); init_timers(); // 1000HZ timer ms_init(); test_types(); // Functions manage user defined address pins chip_addr_init(); initialize_clock(300); #ifdef ADF4351 #ifdef ADF4351_CS chip_select_init(ADF4351_CS); #endif ADF4351_Init(); printf("ADF4351 init done\n"); #endif // Make sure all other GPIO pins are initialized BEFORE SD card #ifdef FATFS_SUPPORT sep(); // Functions manage chip selects #ifdef MMC_CS chip_select_init(MMC_CS); #endif printf("SD Card init...\n"); mmc_init(1); #endif #ifdef DISPLAY sep(); #ifdef ILI9341_CS chip_select_init(ILI9341_CS); #endif #ifdef XPT2046_CS XPT2046_spi_init(); #endif // Initialize TFT master = tft_init(); tft_calX = MatRead("/tft_calX"); tft_calY = MatRead("/tft_calY"); if(tft_calX.data == NULL || tft_calY.data == NULL) tft_is_calibrated = 0; else tft_is_calibrated = 1; printf("TFT calibration %s\n", tft_is_calibrated ? "YES" : "NO"); // rotateion = 1, debug = 1 setup_windows(1,1); #endif wdt_reset(); sep(); printf("Setup Tasks\n"); sep(); setup_networking(); #ifdef TELNET_SERIAL printf("Setup Network Serial Bridge\n"); bridge_task_init(23); #endif if ( espconn_tcp_set_max_con(MAX_CONNECTIONS+1) ) printf("espconn_tcp_set_max_con(%d) != (%d) - failed!\n", MAX_CONNECTIONS+1, espconn_tcp_get_max_con()); else printf("espconn_tcp_set_max_con(%d) = (%d) - success!\n", MAX_CONNECTIONS+1, espconn_tcp_get_max_con()); #ifdef NETWORK_TEST printf("Setup Network TFT Display Client\n"); servertest_setup(TCP_PORT); #endif #ifdef WEBSERVER printf("Setup Network WEB SERVER\n"); web_init(80); #endif sep(); PrintRam(); system_set_os_print(0); } //setup()
/// @brief Obtain SPI bus for TFT display, assert chip select /// return: void void tft_spi_init(uint16_t prescale) { // start with slow SPI, no hardware CS tft_spi_end(); hspi_init( (tft_clock = prescale) , 0); }