void init_all(){ ticks_init(); // for delay_ms() and for time sync button_init(); //init button led_init(); //init led tft_init(0, WHITE, BLACK, RED); //initialize LCD screen xbc_init(0); //initialize Xbox controller }
/*int main() { LED_INIT(); uart_init(COM3, 115200); //uart_interrupt_init(COM3, &listener); tft_init(0, WHITE, BLACK, GREEN); button_init(); ticks_init(); motor_init(); pneumatic_init(); int count = 0; tft_init(0, WHITE, BLACK, GREEN); linear_ccd_init(); adc_init(); while(true) { if(count != get_ms_ticks()){ count = get_ms_ticks(); if(count % 40 == 0){ linear_ccd_clear(); linear_ccd_read(); linear_ccd_prints(); if(find_white_line() != 0) { tft_prints(2, 1, "%3d", find_white_line()); tft_update(); } if(find_white_line() < 50) { motor_control(1,0,100); } else { motor_control(1,0,0); } //tft_update(); } } } return 0; }*/ int main() { tft_init(0,WHITE,BLACK,RED); linear_ccd_init(); ticks_init(); GPIO_switch_init(); pneumatic_init(); button_init(); LED_INIT(); motor_init(); uart_init(COM3, 115200); uart_interrupt_init(COM3,&listener); while(true) { //listener(const uint8_t byte); tft_clear(); tft_prints(2,4,"okay la") ; tft_update(); while(!read_button(1)) { LED_ON(GPIOB, LED_M); motor_control(1,1,100); } /*if(read_GPIO_switch(GPIOA,GPIO_Pin_9)==1&&!read_button(1)) { tft_clear(); tft_prints(2,4,"grip"); tft_update();*/ /*pneumatic_control(GPIOB,GPIO_Pin_13,1);} else { tft_clear(); tft_prints(2,4,"let it go~"); tft_update(); pneumatic_control(GPIOB,GPIO_Pin_13,0);}*/ int time = get_ms_ticks(); if(time%40==0) { linear_ccd_clear(); linear_ccd_read(); linear_ccd_prints(); } //turnn(find_white_line()); } }
// {{{ 初始化系统参数 static int do_init_all_hardware() { int32 ret; ret = tft_init(); if (ret) { error_exit(1, "不能初始化LCD显示"); } lcd_160_clr(); ret = key_led_init(); if (ret) { error_exit(1, "不能初始化keyboard"); } //led_dis_clear(); RFDEV = dc_init_rf(); if (RFDEV < 0) { error_exit(1, "不能初始化射频卡模块"); } dc_config_card(RFDEV, 'A'); if (dc_typeb_timeout(RFDEV, 9)) { error_exit(1, "dc_typeb_timeout错误"); } ret = fs_print_init(); if (ret) { p16log(LOG_ERROR, "不能初始化打印机模块"); } SAMDEV = dc_int_sam(); if (SAMDEV < 0) { p16log(LOG_ERROR, "不能初始化SAM模块,%d", SAMDEV); } return 0; }
/** @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()
int main(void) { static struct ImageParams imageParams; // *** init display ****************************************************** tft_init(); tft_test_image(); // *** init network interfaces ******************************************* init_all_network_interfaces(); if(!eth0_up){ diag_printf("failed to initialize eth0\naborting\n"); return 1; } else{ diag_printf(" eth0 up\n"); } diag_printf("\n\n"); diag_printf("########################################\n"); diag_printf("# Netimage receiver Demo #\n"); diag_printf("########################################\n"); diag_printf("\n\n"); // *** tcp/ip connect **************************************************** diag_printf("waiting for connection...\n"); int fd = accept_connection(); if(fd < 0){ diag_printf("connection failed\naborting\n"); return 1; } diag_printf("connection established\n"); if(!recv_header(fd, &imageParams)){ diag_printf("failed reading image parameters (header)\n"); return 1; } diag_printf("\n"); diag_printf("Image stream header: width = %d\n", imageParams.width); diag_printf(" height = %d\n", imageParams.height); diag_printf(" bpc = %d\n", imageParams.depth); diag_printf(" channels = %d\n", imageParams.nChannels); while(1){ // current pixel coordinates int x,y; // number of bytes between the end of a line in the framebuffer // and the beginning of the next line. int step = tft_info.rlen/4 - imageParams.width; // buffer for incomming pixel data uint8_t line[4096]; // frame buffer pointer uint32_t * fb_pos = tft_info.fb; for(y = 0; y < imageParams.height; y++){ // read a line into the buffer tcp_read(fd, line, imageParams.depth/8*imageParams.nChannels*imageParams.width); // current position uint8_t * p = line; for(x = 0; x < imageParams.width; x++){ // write pixel to framebuffer *fb_pos = p[0] | (p[1] << 8) | (p[2] << 16); // next pixel p += 3; fb_pos++; } // next line fb_pos += step; } } return 0; // never }
sint32 main (sint32 * argc, uint8 * argv[]) { dio_init (); tft_init (&tft_initialConfigTft_s); tft_selectBacklight (); tft_clearScreen (BLACK); #if BENCHMARK == TRUE struct timeval start, stop; double start_mil; double stop_mil; double time_diff; uint16 cmp = 0; gettimeofday (&start, NULL); while (cmp < CYCLES) { cmp++; tft_clearScreen (cmp); } gettimeofday (&stop, NULL); start_mil = (start.tv_sec) * 1000 + (start.tv_usec) / 1000; // convert tv_sec & tv_usec to millisecond stop_mil = (stop.tv_sec) * 1000 + (stop.tv_usec) / 1000; // convert tv_sec & tv_usec to millisecond time_diff = stop_mil - start_mil; printf ("Finished in about %f seconds. \n", time_diff); printf ("%d Frames sent in %f seconds. -> FPS: %f\n", cmp, time_diff, (cmp / (time_diff / 1000))); #endif #if BENCHMARK == FALSE /* Use MAIN 1 for fullscreen updates! */ #if MAIN == 1 uint16 buf_display[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the current display content uint16 buf_source[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the source framebuffer content FILE *fb; int i, j; fb = fopen (argv[1], "rb"); // run forever... while (1) { fseek (fb, 0, SEEK_SET); // rewind source framebuffer fread (buf_source, 1, TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2, fb); // read complete source framebuffer tft_setWindow (0, 0, TFT_WIDTH_UI16 - 1, TFT_HEIGHT_UI16 - 1); tft_drawStart (); // re-transmit the unchanged pixels of current row up to here for (j = 0; j < TFT_WIDTH_UI16 * TFT_HEIGHT_UI16; j++) { tft_sendPixelData (buf_source[j]); } usleep (5000L); // sleep for 5ms } // actually we never get here fclose (fb); #endif /* Use MAIN 2 for line based update */ #if MAIN == 2 int y, x, j, i; // open the source framebuffer deviarm-linux-gnueabihf-gcc srce FILE *fb = fopen (argv[1], "rb"); // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the current display content uint16 buf_source[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the source framebuffer content // run forever... while (TRUE) { fseek (fb, 0, SEEK_SET); // rewind source framebuffer fread (buf_source, 1, TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2, fb); // read complete source framebuffer // statistics uint32 changed = 0; // how many pixels have changed since last refresh uint32 drawed = 0; // how many pixel actualy where transmitted since last refresh // state for merging adjacent changes into one transmission uint32 i = 0; // current pixel index boolean drawing = FALSE; // if pixels are currently transmitted uint32 lastChange = 0; // index of first pixel of this transmission // for all pixels on screen... for (y = 0; y < TFT_HEIGHT_UI16; y++) { for (x = 0; x < TFT_WIDTH_UI16; x++) { uint16 color = buf_source[i]; // get this pixels source color if (color != buf_display[i]) { // the pixel has changed changed++; lastChange = i; // store last change index if (!drawing) { // whe are not drawing, so start a run here. // we only draw full rows: // set display area to the rest of the screen, including this row tft_setWindow (0, y, TFT_WIDTH_UI16 - 1, TFT_HEIGHT_UI16 - 1); tft_drawStart (); // re-transmit the unchanged pixels of current row up to here for (j = 0; j < x; j++) tft_sendPixelData (buf_display [y * TFT_WIDTH_UI16 + j]); drawing = TRUE; } } if (drawing) { // where in a transmission run. tft_sendPixelData (color); // send pixel buf_display[i] = color; // store change drawed++; // end transmission, if the was no change for some time if (i > lastChange + 400) { // stop drawing, lcd actually gets updated. tft_drawStop (); drawing = FALSE; } } i++; } } // if(changed>0) printf("Pixels changed: %i, drawed: %i\n",changed,drawed); usleep (10000L); // sleep for 10ms } // actually we never get here fclose (fb); #endif /* this routine sends every pixel by itself */ #if MAIN == 3 int y, x, j, i; // open the source framebuffer device FILE *fb = fopen (argv[1], "rb"); // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the current display content uint16 buf_source[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the source framebuffer content // run forever... while (TRUE) { fseek (fb, 0, SEEK_SET); // rewind source framebuffer fread (buf_source, 1, TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2, fb); // read complete source framebuffer // statistics uint32 changed = 0; // how many pixels have changed since last refresh uint32 drawed = 0; //for(n = 0; n < f_size; n++) // { // printf("old_buffer[%d]: %c \t new_buffer[%d]: %c\n", n, old_buffer[n], n, new_buffer[n]); // }/ how many pixel actualy where transmitted since last refresh // state for merging adjacent changes into one transmission uint32 i = 0; // current pixel index boolean drawing = FALSE; // if pixels are currently transmitted uint32 lastChange = 0; // index of first pixel of this transmission uint16 color = 0; // for all pixels on screen... for (y = 0; y < TFT_HEIGHT_UI16; y++) { for (x = 0; x < TFT_WIDTH_UI16; x++) { color = buf_source[i]; if (color != buf_display[i]) { buf_display[i] = color; changed++; tft_drawPixel (x, y, color); } i++; } } //printf("pixel changed: %d\n", changed); // if(changed>0) printf("Pixels changed: %i, drawed: %i\n",changed,drawed); usleep (10000L); // sleep for 10ms } // actually we never get here fclose (fb); #endif /* This Routine sends a group of pixels after one has altered */ #if MAIN == 5 #define PIXELGROUPLEN 40 int y, x, j, i, xend; // open the source framebuffer device FILE *fb = fopen (argv[1], "rb"); // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_HEIGHT_UI16][TFT_WIDTH_UI16]; // the current display content uint16 buf_source[TFT_HEIGHT_UI16][TFT_WIDTH_UI16]; // the source framebuffer content for (i = 0; i < TFT_HEIGHT_UI16; i++) { for (j = 0; j < TFT_WIDTH_UI16; j++) { buf_display[i][j] = 0; } } // run forever... while (TRUE) { /* This can be speed up a little by using DMA or memcopy */ fseek (fb, 0, SEEK_SET); // rewind source framebuffer for (i = 0; i < TFT_HEIGHT_UI16 * 2; i++) //fread(buf_source[i], 2, TFT_WIDTH_UI16, fb); // read complete source framebuffer fread (buf_source[i], 1, TFT_WIDTH_UI16 * 2, fb); // read complete source framebuffer for (y = 0; y < TFT_HEIGHT_UI16; y++) { uint32 changed = 0; // how many pixels have changed since last refresh uint32 drawed = 0; // how many pixel actualy where transmitted since last refresh xend = 0; for (x = 0; x < TFT_WIDTH_UI16; x++) { //x = i ;//% TFT_WIDTH_UI16; //y = lines; if (buf_source[y][x] != buf_display[y][x]) { //printf("buf_source[%d] = %d \t | \t buf_display[%d]: %d\n",i, buf_source[i], i, buf_display[i]); changed++; if ((x + PIXELGROUPLEN) > TFT_WIDTH_UI16) { xend = TFT_WIDTH_UI16 - 1; //printf("x: %d\n", x); } else { xend = x + PIXELGROUPLEN; } tft_setWindow (x, y, xend, y); tft_drawStart (); //for(j = tmpx; j < tmpx+xend; j++) for (j = x; j <= xend; j++) { tft_sendPixelData (buf_source[y][j]); buf_display[y][j] = buf_source[y][j]; drawed++; // x++; } x = xend; } } } usleep (15000L); // sleep for 15ms } fclose (fb); #endif /* This Routine analyzes the screen alteration and switches to the best method for the screen update */ #if MAIN == 6 int y, x, j, i, cnt; // open the source framebuffer device FILE *fb = fopen (argv[1], "rb"); // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the current display content uint16 buf_source[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the source framebuffer content // run forever... while (TRUE) { fseek (fb, 0, SEEK_SET); // rewind source framebuffer fread (buf_source, 1, TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2, fb); // read complete source framebuffer // statistics uint32 changed = 0; // how many pixels have changed since last refresh uint32 drawed = 0; // how many pixel actualy where transmitted since last refresh // state for merging adjacent changes into one transmission uint32 i = 0; // current pixel index boolean drawing = FALSE; // if pixels are currently transmitted uint32 lastChange = 0; // index of first pixel of this transmission cnt = 0; // for all pixels on screen... for (y = 0; y < TFT_HEIGHT_UI16; y++) { for (x = 0; x < TFT_WIDTH_UI16; x++) { cnt++; if (buf_display[cnt] != buf_source[cnt]) changed++; } } if (changed < 1000) { // open the source framebuffer device //FILE* fb=fopen(argv[1],"rb"); // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the current display content uint16 buf_source[TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2]; // the source framebuffer content fseek (fb, 0, SEEK_SET); // rewind source framebuffer fread (buf_source, 1, TFT_WIDTH_UI16 * TFT_HEIGHT_UI16 * 2, fb); // read complete source framebuffer // statistics // uint32 changed=0; // how many pixels have changed since last refresh //for(n = 0; n < f_size; n++) // { // printf("old_buffer[%d]: %c \t new_buffer[%d]: %c\n", n, old_buffer[n], n, new_buffer[n]); // }/ how many pixel actualy where transmitted since last refresh // state for merging adjacent changes into one transmission uint32 i = 0; // current pixel index boolean drawing = FALSE; // if pixels are currently transmitted uint32 lastChange = 0; // index of first pixel of this transmission uint16 color = 0; // for all pixels on screen... for (y = 0; y < TFT_HEIGHT_UI16; y++) { for (x = 0; x < TFT_WIDTH_UI16; x++) { color = buf_source[i]; if (color != buf_display[i]) { buf_display[i] = color; drawed++; tft_drawPixel (x, y, color); } i++; } } //printf("pixel changed: %d\n", changed); // if(changed>0) printf("Pixels changed: %i, drawed: %i\n",changed,drawed); usleep (15000L); // sleep for 15ms } else { #define PIXELGROUPLEN 40 int y, x, j, i, xend, lines, tmpx; // open the source framebuffer device // allocate two buffers for tracking the source framebuffer changes uint16 buf_display[TFT_HEIGHT_UI16][TFT_WIDTH_UI16]; // the current display content uint16 buf_source[TFT_HEIGHT_UI16][TFT_WIDTH_UI16]; // the source framebuffer content for (i = 0; i < TFT_HEIGHT_UI16; i++) for (j = 0; j < TFT_WIDTH_UI16; j++) buf_display[i][j] = 0; // run forever... fseek (fb, 0, SEEK_SET); // rewind source framebuffer for (i = 0; i < TFT_HEIGHT_UI16 * 2; i++) //fread(buf_source[i], 2, TFT_WIDTH_UI16, fb); // read complete source framebuffer fread (buf_source[i], 1, TFT_WIDTH_UI16 * 2, fb); // read complete source framebuffer i = 0; tmpx = 0; for (y = 0; y < TFT_HEIGHT_UI16; y++) { //uint32 changed=0; // how many pixels have changed since last refresh //uint32 drawed=0; // how many pixel actualy where transmitted since last refresh xend = 0; for (x = 0; x < TFT_WIDTH_UI16; x++) { //x = i ;//% TFT_WIDTH_UI16; //y = lines; tmpx = x; if (buf_source[y][x] != buf_display[y][x]) { //printf("buf_source[%d] = %d \t | \t buf_display[%d]: %d\n",i, buf_source[i], i, buf_display[i]); //changed++; if ((x + PIXELGROUPLEN) > TFT_WIDTH_UI16) { xend = TFT_WIDTH_UI16 - 1; //printf("x: %d\n", x); //system("sleep 2"); } else xend = x + PIXELGROUPLEN; tft_setWindow (x, y, xend, y); tft_drawStart (); //for(j = tmpx; j < tmpx+xend; j++) for (j = x; j <= xend; j++) { tft_sendPixelData (buf_source[y][j]); buf_display[y][j] = buf_source[y][j]; drawed++; // x++; } x = xend; } } } usleep (15000L); // sleep for 15ms } //printf("Pixels changed: %i, drawed: %i\n",changed,drawed); } // actually we never get here fclose (fb); #endif #endif return 0; }
//================================================================================================= // Platform demo code //================================================================================================= void Platform_Demo_Code(void) { char video_path[32] ="C:\\Demo0091NBA.avi"; char audio_path[32] = "C:\\happy.mp3"; char image_path1[32] = "C:\\chen52.jpg"; char image_path2[32] = "C:\\chen53.jpg"; INT8S volume; INT32S nRet; INT32U decode_output_ptr; AUDIO_ARGUMENT audio_arg; IMAGE_ARGUMENT image_arg; VIDEO_ARGUMENT video_arg; VIDEO_INFO information; MEDIA_SOURCE src; AUDIO_CODEC_STATUS audio_status; IMAGE_CODEC_STATUS image_status; VIDEO_CODEC_STATUS video_status; while(1) { if(_devicemount(USE_DISK)) // Mount device { DBG_PRINT("Mount Disk Fail[%d]\r\n", USE_DISK); #if USE_DISK == FS_NAND1 nRet = _format(FS_NAND1, FAT32_Type); DrvNand_flush_allblk(); _deviceunmount(FS_NAND1); #endif } else { DBG_PRINT("Mount Disk success[%d]\r\n", USE_DISK); break; } } switch(USE_DISK) { case FS_SD: gp_memcpy((INT8S*)video_path, (INT8S*)"C:\\Demo0091NBA.avi", sizeof(video_path)); gp_memcpy((INT8S*)audio_path, (INT8S*)"C:\\happy.mp3", sizeof(audio_path)); gp_memcpy((INT8S*)image_path1, (INT8S*)"C:\\chen52.jpg", sizeof(image_path1)); gp_memcpy((INT8S*)image_path2, (INT8S*)"C:\\chen53.jpg", sizeof(image_path2)); break; case FS_NAND1: gp_memcpy((INT8S*)video_path, (INT8S*)"A:\\Demo0091NBA.avi", sizeof(video_path)); gp_memcpy((INT8S*)audio_path, (INT8S*)"A:\\happy.mp3", sizeof(audio_path)); gp_memcpy((INT8S*)image_path1, (INT8S*)"A:\\chen52.jpg", sizeof(image_path1)); gp_memcpy((INT8S*)image_path2, (INT8S*)"A:\\chen53.jpg", sizeof(image_path2)); break; case FS_USBH: gp_memcpy((INT8S*)video_path, (INT8S*)"G:\\Demo0091NBA.avi", sizeof(video_path)); gp_memcpy((INT8S*)audio_path, (INT8S*)"G:\\happy.mp3", sizeof(audio_path)); gp_memcpy((INT8S*)image_path1, (INT8S*)"G:\\chen52.jpg", sizeof(image_path1)); gp_memcpy((INT8S*)image_path2, (INT8S*)"G:\\chen53.jpg", sizeof(image_path2)); break; } // Initialize display device #if C_DISPLAY_DEVICE >= C_TV_QVGA tv_init(); #if C_DISPLAY_DEVICE == C_TV_QVGA tv_start (TVSTD_NTSC_J_NONINTL, TV_QVGA, TV_NON_INTERLACE); #elif C_DISPLAY_DEVICE == C_TV_VGA tv_start (TVSTD_NTSC_J, TV_HVGA, TV_INTERLACE); #elif C_DISPLAY_DEVICE == C_TV_D1 tv_start (TVSTD_NTSC_J, TV_D1, TV_NON_INTERLACE); #else while(1); #endif #else tft_init(); tft_start(C_DISPLAY_DEVICE); #endif user_defined_video_codec_entrance(); audio_decode_entrance(); image_decode_entrance(); video_decode_entrance(); adc_key_scan_init(); //init key scan volume = 0x3F; nRet = C_DISPLAY_DEV_HPIXEL*C_DISPLAY_DEV_VPIXEL*2; decode_output_ptr = (INT32U) gp_malloc_align(nRet, 64);//malloc decode frame buffer while(!decode_output_ptr); while(1) { adc_key_scan(); if(ADKEY_IO1) { //play audio if(video_decode_status() == VIDEO_CODEC_PROCESS_END) { src.type = SOURCE_TYPE_FS; src.type_ID.FileHandle = open(audio_path, O_RDONLY); src.Format.AudioFormat = MP3; audio_arg.Main_Channel = 1; // Use DAC Channel A+B audio_arg.L_R_Channel = 3; // Left + Right Channel audio_arg.mute = 0; audio_arg.volume = volume; // volume level = 0~63 G_snd_info.Speed = 12; //for speed control(golbal var) G_snd_info.Pitch = 12; //for pitch control(golbal var) audio_status = audio_decode_start(audio_arg, src); } } else if(ADKEY_IO2) { if(audio_decode_status(audio_arg) == AUDIO_CODEC_PROCESSING) audio_decode_stop(audio_arg); } else if(ADKEY_IO3) { //play image if(video_decode_status() == VIDEO_CODEC_PROCESS_END) { src.type = SOURCE_TYPE_FS; if((nRet++ % 2) == 0) src.type_ID.FileHandle = (INT32U)open(image_path1, O_RDONLY); else src.type_ID.FileHandle = (INT32U)open(image_path2, O_RDONLY); image_arg.OutputBufPtr=(INT8U *)decode_output_ptr; //decode output buffer image_arg.OutputBufWidth = C_DISPLAY_DEV_HPIXEL; //width of output buffer image_arg.OutputBufHeight = C_DISPLAY_DEV_VPIXEL; //Heigh of output buffer image_arg.OutputWidth = C_DISPLAY_DEV_HPIXEL; //scaler width of output image image_arg.OutputHeight = C_DISPLAY_DEV_VPIXEL; //scaler Heigh of output image image_arg.OutBoundaryColor = 0x008080; image_arg.ScalerOutputRatio = FIT_OUTPUT_SIZE; image_arg.OutputFormat = IMAGE_OUTPUT_FORMAT_YUYV; image_decode_start(image_arg, src); while (1) { image_status=image_decode_status(); if (image_status == IMAGE_CODEC_DECODE_END) { video_codec_show_image(C_DISPLAY_DEVICE, (INT32U)decode_output_ptr, C_DISPLAY_DEVICE,IMAGE_OUTPUT_FORMAT_YUYV); break; } else if(image_status==IMAGE_CODEC_DECODE_FAIL) { DBG_PRINT("image decode failed\r\n"); break; } } image_encode_stop(); close(src.type_ID.FileHandle); } } else if(ADKEY_IO4) { audio_arg.Main_Channel = 1; if(audio_decode_status(audio_arg) == AUDIO_CODEC_PROCESS_END) { DBG_PRINT("video_decode_start\r\n"); video_arg.bScaler = TRUE; video_arg.bUseDefBuf = FALSE; video_arg.DisplayWidth = C_DISPLAY_DEV_HPIXEL; video_arg.DisplayHeight = C_DISPLAY_DEV_VPIXEL; video_arg.DisplayBufferWidth = C_DISPLAY_DEV_HPIXEL; video_arg.DisplayBufferHeight = C_DISPLAY_DEV_VPIXEL; video_arg.OutputFormat = IMAGE_OUTPUT_FORMAT_YUYV; src.type = SOURCE_TYPE_FS; src.Format.VideoFormat = MJPEG; src.type_ID.FileHandle = open(video_path, O_RDONLY); if(src.type_ID.FileHandle < 0) { DBG_PRINT("file open fail\r\n"); close(src.type_ID.FileHandle); continue; } video_status = video_decode_paser_header(&information, video_arg, src); if(video_status != VIDEO_CODEC_STATUS_OK) { DBG_PRINT("paser header fail !!!\r\n"); continue; } video_decode_start(video_arg, src); audio_decode_volume(volume); } } else if(ADKEY_IO5) { if(video_decode_status() == VIDEO_CODEC_PROCESSING) { video_decode_stop(); DBG_PRINT("video_decode_stop\r\n"); } } else if(ADKEY_IO6) { } else if(ADKEY_IO7) { } else if(ADKEY_IO8) { } } }