/************************************************************************ * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved. * @file main.c * @author UartTFT Application Team * @version V1.0.0 * @date 2023-02-24 * @brief This file include main function. *************************************************************************/ #include "sys.h" #include "uart.h" #include "delay.h" #include "data.h" #include "common.h" #include "usb_const.h" #include "string.h" //#include "levetop.h" #include "eflash_drv.h" #include "cache_drv.h" #include "spi_drv.h" #include "eport_drv.h" #include "ccm_drv.h" #include "LT768_Lib.h" #include "ioctrl_drv.h" #include "pit32_drv.h" #include "pwm.h" #include "pit.h" #include "dac.h" #include "flash.h" //#include "bsp.h" #include "ctp.h" #include "rtp.h" #include "math.h" #include "iomacros.h" #include "wdt_drv.h" #include "usb_drv.h" #include "usb_const.h" #include "UI_H.h" #include "OTA_H.h" #include "meg.h" #include "CRC.h" #include "cpm_drv.h" #include "Updata.h" #include "flash.h" #include "LT768_Lib.h" #include "Uart_Vcom.h" #include "OTA_H.h" extern unsigned int gBaudrate; extern void my_APP(u32 appxaddr); uint8_t hid_rec_index; /******************my debug**************************/ unsigned char ota_lt7689_flag = 0; unsigned char ota_lt7689_flag1 = 0; unsigned char ota_lt7689_flag2 = 0; unsigned char ota_lt7689_buf1[512]; unsigned char ota_lt7689_buf2[512]; unsigned int ota_lt7689_length1 =0; unsigned int ota_lt7689_length2 =0; unsigned int ota_address = 0; #define LT_APP 0x08010000 unsigned int ota_offset = 0; /********************************************/ static void Printf_Version(void) { printf("/**************************************************/\n"); printf(" date = %s,time = %s \r\n", (char *)__DATE__, (char *)__TIME__); printf(" LT7689_LoadDown_Uart_V1.01 \r\n"); printf(" system clk = %dMHz \r\n", g_sys_clk / 1000000); printf(" ips clk = %dMHz \r\n", g_ips_clk / 1000000); printf("/**************************************************/\n"); } extern UINT8 hid_rx_buf[512]; /******************bootloader****************************/ char showbuff[9]; void display_manu(u8 sd_ok) { //提供 5M晶振 PWM_OutputInit(PWM_PORT1,2,PWM_CLK_DIV_1,4,2,0); //更改了库函数,根据实际设定打开PWM,作用提供LT768的晶振 Parallel_Init(); LT768_Init(); #if MCU_SPI *(volatile unsigned char*)(0x40019000+0x03) |= (1<<(6)); //EPORT_ConfigGpio(EPORT_PIN6,GPIO_OUTPUT);EPORT6和LT768——TEST1连接 *(volatile unsigned char*)(0x40019000+0x05) |= (1<<(6)); //EPORT_WriteGpioData(EPORT_PIN6,Bit_SET); MUC_SS_flag = 1; //先SPI1.SS; SPI1_Flash_Init(); #if UartTFT_Flash_0 MUC_CS0_OUTPUT MUC_CS0_SET #endif #else *(volatile unsigned char*)(0x40019000+0x03) |= (1<<(6)); //EPORT_ConfigGpio(EPORT_PIN6,GPIO_OUTPUT);EPORT6和LT768——TEST1连接 *(volatile unsigned char*)(0x40019000+0x05) &= ~(1<<(6)); //EPORT_WriteGpioData(EPORT_PIN6,Bit_RESET); Close_SPI1(); LT768_SPI_Init(1,1); //先设定LT768的CS1 #endif Main_Image_Start_Address(0); Main_Image_Width(LCD_XSIZE_TFT); Main_Window_Start_XY(0,0); Canvas_Image_Start_address(0); Canvas_image_width(LCD_XSIZE_TFT); Active_Window_XY(0,0); Active_Window_WH(LCD_XSIZE_TFT,LCD_YSIZE_TFT); if(sd_ok) LT768_DrawSquare_Fill(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Back_color); else LT768_DrawSquare_Fill(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Blue2); LT768_Select_Internal_Font_Init(24,1,1,0,0); LT768_PWM1_Init(1,0,5,800,400); Display_ON(); // 开启显示 } char Flash_find(void) { Flash_ID = W25QXX_ReadID();Flash_type = 0; if(Flash_ID == 0xef13) {strcpy(showbuff,"W25Q80");} else if(Flash_ID == 0xef14) {strcpy(showbuff,"W25Q16");} else if(Flash_ID == 0xef15) {strcpy(showbuff,"W25Q32");} else if(Flash_ID == 0xef16) {strcpy(showbuff,"W25Q64");} else if(Flash_ID == 0xef17) {strcpy(showbuff,"W25Q128");} else if(Flash_ID == 0x5e17) {strcpy(showbuff,"ZB25VQ128");} else if(Flash_ID == 0xef18) {strcpy(showbuff,"W25Q256");W25Q256 = 1;W25QXX_Enter_4Byte_AddressMode();} else { Flash_ID = W25N01GV_ReadID(); // printf("%x \r\n",Flash_ID); if(Flash_ID == 0xefaa21){ Flash_type = 1;strcpy(showbuff,"W25N01GV");} else { Flash_type = 2;strcpy(showbuff,"No Flash");} } // printf("%x \r\n",Flash_ID); LT768_DrawSquare_Fill(10,LINE0,300,LINE0+L_OFFSET,Back_color); LT768_Print_Internal_Font_String(10 ,LINE0,Black,White,"Flash Model:"); // LT768_Print_Internal_Font_String(144,LINE0,File_name_color,White,showbuff); if(Flash_type == 2) { LT768_Print_Internal_Font_String(164,LINE0,Warm_color,White,showbuff); return 1; } else { LT768_Print_Internal_Font_String(164,LINE0,Black,White,showbuff); return 0; } } typedef void (*iapfun)(void); iapfun jump2app; void APP(u32 appxaddr) { // printf("***enter app()***\r\n"); Disable_Interrupts; __set_PRIMASK(1); jump2app = (iapfun)*(vu32*)(appxaddr + 4); MSR_MSP(*(vu32*)appxaddr); // printf("***ready jumpapp()***\r\n"); // DCACHE_Init(cacheOff, cacheOff, cacheOff, cacheOff); // ICACHE_Init(cacheOff, cacheOff, cacheOff, cacheOff); WDT_FeedDog(); DelayMS(10); // printf("***ready jumpapp()***\r\n"); jump2app(); // printf("***ready jumpapp() fail\r\n"); Enable_Interrupts } void SCI1_Init(uint32_t pclk, uint32_t bound,uint8_t parity) { u32 band_rate=0; SCI1->SCIBRDF=(((pclk*8/bound)+1)/2)&0x003f; band_rate =(pclk*4/bound)>>6; SCI1->SCIBDH=(u8)((band_rate>>8)&0x00ff); SCI1->SCIBDL=(u8)(band_rate&0x00ff); SCI1->SCICR2 |= (1<<2)|(1<<3)|(1<<5)|(1 << 4); NVIC_Init(0, 0, SCI1_IRQn, 2); } void SCI2_Init(uint32_t pclk, uint32_t bound,uint8_t parity) { u32 band_rate=0; SCI2->SCIBRDF=(((pclk*8/bound)+1)/2)&0x003f; band_rate =(pclk*4/bound)>>6; SCI2->SCIBDH=(u8)((band_rate>>8)&0x00ff); SCI2->SCIBDL=(u8)(band_rate&0x00ff); SCI2->SCICR2 |= (1<<2)|(1<<3)|(1<<5); NVIC_Init(0, 0, SCI2_IRQn, 2); } void SCI3_Init(uint32_t pclk, uint32_t bound,uint8_t parity) { u32 band_rate=0; SCI3->SCIBRDF=(((pclk*8/bound)+1)/2)&0x003f; band_rate =(pclk*4/bound)>>6; SCI3->SCIBDH=(u8)((band_rate>>8)&0x00ff); SCI3->SCIBDL=(u8)(band_rate&0x00ff); SCI3->SCICR2 |= (1<<2)|(1<<3)|(1<<5)|(1 << 4); NVIC_Init(0, 0, SCI3_IRQn, 2); } int fputc(int ch, FILE *f) { while ((SCI1->SCISR1 & 0x40) == 0x00) { }; SCI1->SCIDRL = (uint8_t)ch; //SCI1->SCIDRL = (uint8_t)data; // while ((SCI2->SCISR1 & 0x40) == 0x00) // { // }; // SCI2->SCIDRL = (uint8_t)ch; //SCI1->SCIDRL = (uint8_t)data; // return ch; } void SCI2_IRQHandler(void) { // uint8_t ch = 0; if ((SCI2->SCISR1 & 0x20) == 0x20) { // ch = SCI2->SCIDRL; // if (Rx_Count_long > 4096 + 2) // Rx_Count_long = 0; // Rx_Buffer_long[Rx_Count_long++ % RX_SIZE] = ch; // Rx_Num++; // mcu_buf[mcu_buf_length] = ch ; // mcu_buf_length ++ ; } if((SCI2->SCISR1 & 0x10) == 0x10) //空闲中断 { //清除标志位 uint8_t clear_idle_flag; clear_idle_flag = SCI2->SCIDRL; clear_idle_flag = SCI2->SCISR1; // uart1_idle_flag = 1; } } #if 0 void SCI1_IRQHandler(void) { // u8 cjc=0; WDT_FeedDog(); if((SCI1->SCISR1 & 0x20)== 0x20) { // cjc = SCI1->SCIDRL; // LT_SingleByteToPc_uart3(cjc); // uart_buf[uart_rx_number++] = SCI1->SCIDRL; // if(ota_lt7689_flag1==0) // { ota_lt7689_buf1[ota_lt7689_length1++]=SCI1->SCIDRL; // } // else if(ota_lt7689_flag2==0) // { // ota_lt7689_buf2[ota_lt7689_length++]=SCI1->SCIDRL; // } // printf("%x ",ota_lt7689_buf[ota_lt7689_length]); // ota_lt7689_length++; // ota_offset++; // if(uart_rx_number>(4096+512)) // uart_rx_number =0 ; // PIT1_reload(); } if((SCI1->SCISR1 & 0x10) == 0x10) //空闲中断 { //清除标志位 uint8_t clear_idle_flag; clear_idle_flag = SCI1->SCIDRL; clear_idle_flag = SCI1->SCISR1; ota_lt7689_flag = 1; } } #endif extern unsigned char app_flag; /******************************************************************/ extern uint8_t Rx_Buffer_short[512] ; extern uint16_t Rx_Count_short ; unsigned int page = 0; unsigned int ui_offset=0; unsigned char last_flag=0; unsigned short block = 0; unsigned int number1 =0; unsigned int number =0; //unsigned int time = 0; unsigned char flash[2050] = {0}; int main(void) { // printf("***app!!**\r\n"); // u8 inBuf[64]; // u16 X_pos=0; // u16 Y_pos=0; // uint16_t cx, cy; // uint8_t w_temp, h_temp; // u8 Sd_card_exist = 0; char Download_flag = 0; NVIC_SetVectorTable(0x800A000, 0);//0x800A000 0x8010000 // NVIC_SetVectorTable(0x800F800, 0); // PeripheralInit(); Sys_Init(); Enable_Interrupts; SCI1_Init(g_ips_clk,921600 ,0); //115200 921600 // SCI2_Init(g_ips_clk, 115200,0); // SCI3_Init(g_ips_clk,921600 ,0); /********************升级*******************/ ota_address = LT_APP; Make_CRC32_Table(); ota_address = 0x08010000; printf("***bootloader1!!**\r\n"); // APP(APP_ADDR); //21KB // SCI3_DMA_Init(g_ips_clk,115200); SCI3_DMA_Init(g_ips_clk,921600);//921600 unsigned short i = 0; // APP(APP2_ADDR); #if 0 while(1) { WDT_FeedDog(); printf("***bootloader3***\r\n"); printf("***Sd_card_exist=%d***\r\n",Sd_card_exist); printf("***CPM_PADWKINTCR=%d***\r\n",CPM->CPM_PADWKINTCR); printf("***CPM_PADWKINTCR&=%d***\r\n",CPM->CPM_PADWKINTCR&0x02000000); //通过检测wake up脚电平来判断SD card 是否有插入 if((CPM->CPM_PADWKINTCR&0x02000000)==0) //0:有插入 { printf("enter if 1\r\n"); Sd_card_exist = 1; // CPM->CPM_PADWKINTCR |= 0x02; } // else if((CPM->CPM_PADWKINTCR&0x02000000)==0) //0:有插入 // { // printf("enter if 2\r\n"); // Sd_card_exist = 1; //// CPM->CPM_PADWKINTCR |= 0x02; // } DelayMS(1000*3); Sd_card_exist = 1; printf("***Sd_card_exist=%d***\r\n",Sd_card_exist); if(Sd_card_exist) { printf("Sd_card_exist!\r\n"); printf("Sd_card_exist!\r\n"); display_manu(1); signed char res = 0; LT768_Print_Internal_Font_String(10,LINE1,File_name_color,White,"1: UartTFT-II_Flash.bin"); LT768_Print_Internal_Font_String(10,LINE2,File_name_color,White,"2: MCU_Code.bin"); LT768_Print_Internal_Font_String(310,LINE0,File_name_color,White,"V2.00"); #if UartTFT_Flash_0 LT768_Print_Internal_Font_String(0,LINE4,File_name_color,White,"3: UartTFT_Flash_0.bin"); #endif // if(Flash_find()==0) //识别出了Flash 才操作 // { // printf("***find flash****\r\n"); // res = Flash_Updata("0:/UartTFT_Flash/UartTFT-II_Flash.bin",1); // if(res==FR_NO_FILE||res==FR_NO_PATH) res = Flash_Updata("0:/UartTFT_Flash_No_CRC/UartTFT-II_Flash.bin",2); // if(res == 0) //UartTFT-II_Flash OK // { // LT768_Print_Internal_Font_String(370,LINE1,OK_color,White,"OK"); // LT768_Print_Internal_Font_String(310,LINE1,Progress_color,White,"100%"); // Download_flag++; // } // else if(res>=1 && res <=19) //FatFs 故障 // { // strcpy(showbuff,"None."); // sprintf(&showbuff[5],"%d",res); // LT768_Print_Internal_Font_String(310,LINE1,None_color,White,showbuff); // } // else if(res == -1) //CRC 错误 // { // LT768_Print_Internal_Font_String(370,LINE1,NG_color,White,"NG"); // LT768_Print_Internal_Font_String(46 ,LINE5,Black,White,"NG: CRC error"); // LT768_Print_Internal_Font_String(10 ,LINE4,Black,White,"Result:"); // LT768_Print_Internal_Font_String(96,LINE4,Red,White,"Failed"); // while(1) WDT_FeedDog(); // } // else if(res == -2) //BBM 错误 // { // LT768_Print_Internal_Font_String(370,LINE1,NG_color,White,"NG"); // LT768_Print_Internal_Font_String(46 ,LINE5,Black,White,"NG: BBM error"); // LT768_Print_Internal_Font_String(10 ,LINE4,Black,White,"Result:"); // LT768_Print_Internal_Font_String(96,LINE4,Red,White,"Failed"); // while(1) WDT_FeedDog(); // } // printf("******res = %d \r\n",res); // } // else // { // LT768_Print_Internal_Font_String(10 ,LINE6,Black,White,"Result:"); // LT768_Print_Internal_Font_String(96,LINE6,Red,White,"Fail"); // printf("***enter esle****\r\n"); // while(1) WDT_FeedDog(); // } #if UartTFT_Flash_0 #if MCU_SPI #else #endif #endif printf("next APP_Updata!!!! \r\n"); res = APP_Updata("0:/MCU_Code/MCU_Code1.bin"); if(res == 0) //UserInfo OK { LT768_Print_Internal_Font_String(370,LINE2,OK_color,White,"OK"); LT768_Print_Internal_Font_String(310,LINE2,Progress_color,White,"100%"); Download_flag++; } else if(res>=1 && res <=19) //FatFs 故障 { strcpy(showbuff,"None."); sprintf(&showbuff[5],"%d",res); LT768_Print_Internal_Font_String(370,LINE2,None_color,White,showbuff); } else if(res == -1) //CRC 错误 { LT768_Print_Internal_Font_String(370,LINE2,NG_color,White,"NG"); LT768_Print_Internal_Font_String(46 ,LINE5,Black,White,"NG: CRC error"); LT768_Print_Internal_Font_String(10 ,LINE4,Black,White,"Result:"); LT768_Print_Internal_Font_String(96,LINE4,Red,White,"Failed"); while(1) WDT_FeedDog(); } if(Download_flag == 0) { LT768_Print_Internal_Font_String(10 ,LINE4,Black,White,"Result:"); LT768_Print_Internal_Font_String(96,LINE4,Red,White,"Failed"); } else { LT768_Print_Internal_Font_String(10 ,LINE4,Black,White,"Result:"); LT768_Print_Internal_Font_String(96,LINE4,OK_color,White,"OK"); } if(LCD_XSIZE_TFT >= 800) { LT768_Print_Internal_Font_String(10,LINE5,Warm_color,White,"Remove the SD card to enter the main program"); } else { LT768_Print_Internal_Font_String(10,LINE5,Warm_color,White,"Remove the SD card"); LT768_Print_Internal_Font_String(10,LINE6,Warm_color,White," to enter the main program"); } printf("res =%d \r\n",res); while(1) { if((CPM->CPM_PADWKINTCR&0x02000000) != 0) //0:有插入 { printf("***ready enter app***\r\n"); APP(APP_ADDR); // CPM->CPM_PADWKINTCR |= 0x02; } WDT_FeedDog(); } } } #endif #if 0 /********************************************/ PIT2_Init(23438); WDT_Init(0x4786*2); // APP(0x8000000); // Uart3_Init(g_ips_clk, 115200); /* uint8_t mcu_package_buf[30]; uint8_t cmd = 0x10 ; uint16_t adress = 0x0901 ; uint16_t data[3] = {0x0020,0x0010,0x1314}; uint8_t data_amount = 3; send_mcu_package( mcu_package_buf , //数据包地址 cmd , //指令码 adress , // 变量地址 data , // 数据 2字节 data_amount); //数据个数 */ // for(unsigned char i = 0 ; i < 20 ; i++) // printf("flash: %x\r\n",EFLASH_ByteRead(flh_sAddr1 + i)); // SaveData(); //GetAdjdata(); // for(unsigned char i = 0 ; i < 20 ; i++) // printf("flash: %x\r\n",EFLASH_ByteRead(flh_sAddr1 + i)); // printf("flash%x \r\n",*((unsigned int *)0x0807D800)); // SaveData(); // GetAdjdata(); // printf("flash%x \r\n",*((unsigned int *)0x0807D800)); // printf("flash%x \r\n",*((unsigned char *)(0x0807D800))); // printf("flash%x \r\n",(*(volatile UINT8 *)(0x0807D800))); //(*(volatile UINT8 *)(addr)) // EFLASH_PageErase(0x0807D800); // printf("flash%x \r\n",EFLASH_ByteRead(0807D800)); // unsigned short test = 0x0064; // unsigned short * test_p = &test; // printf("test = %x\r\n",test); // printf("test0 = %x test1 = %x\r\n",*((unsigned char *)test_p),*(((unsigned char *)test_p)+1)); // // unsigned char test_array[2]; // test_array[0] = test ; // test_array[1] = *((unsigned char *)&test+1 ); // printf("array0 = %x array1 = %x\r\n",test_array[0],test_array[1]); // unsigned short addr = 0x0040; // unsigned char data[4]; // data[0] = var[2 * (addr + 0)]; // data[1] = var[2 * (addr + 0) + 1]; // data[2] = var[2 * (addr + 0) + 2]; // data[3] = var[2 * (addr + 0) + 3]; // printf("\r\n ***0:%d 1:%d 2:%d 3:%d*** \r\n",data[0],data[1],data[2],data[3]); // printf("\r\n ***var:%d *** \r\n",var[2 * (addr + 0)]); // data[1] = 100; // var[2 * (addr + 0)] = data[0]; // var[2 * (addr + 0) + 1] =data[1]; // printf("***APP-A***\r\n"); // printf("ID=%x\r\n",(*(volatile UINT32 *)(0x20000000+0x37000))); // printf("EFLASH=%x\r\n",(EFLASH_WordRead(0x8009E00))); device_working_status_buff.wifi_status = 1; printf("wifi_status=%d\r\n",device_working_status_buff.wifi_status); //0x8043A00 // 0x800A000 0x8043A00 180kB // SaveData(); WDT_FeedDog(); // printf("OK!!\r\n"); // printf("\r\n*******after********\r\n"); // EFLASH_Init(g_sys_clk / 1000); // EFLASH_SetWritePermission(); // EFLASH_PageErase(0x08043A00); // EFLASH_ClrWritePermission(); // GetAdjdata(0x08043A00); // NVIC_SetVectorTable(0x08043A00, 0); // PeripheralInit(); // PIT2_Init(23438); // WDT_Init(0x4786*2); // printf("*****APP-2*****\r\n"); // printf("***enter APP_B***\r\n"); // my_APP(0x8043A00); while(1) { WDT_FeedDog(); //Clear watchdog // printf("*****APP-2!!*****\r\n"); #if !IIC_BUS #if (UARTBUS_OPTION == 0) Main_From_UartRxBuff(); if (gUsartRx.Flag) { LT_ReceiveCmd(gUsartRx.Buf); } if(UI_update == 1) { while(1) { WDT_FeedDog(); //Clear watchdog; Main_From_UartRxBuff(); if (gUsartRx.Flag) LT_ReceiveCmd(gUsartRx.Buf); if(UI_update == 0) break; } } #elif (UARTBUS_OPTION == 1) LT_ModBus_REG_Cmd(); #elif (UARTBUS_OPTION == 2) if (Sum_ModbusTX) Uart_cmd_Send(); LT_ModBus_REG_Cmd(); #elif (UARTBUS_OPTION == 3 || UARTBUS_OPTION == 4) Hid_Main_From_UartRxBuff(); if (gHidRx.Flag) LT_Hid_ReceiveCmd(gHidRx.Buf); if(UI_update == 1) { while(1) { WDT_FeedDog(); //Clear watchdog; Hid_Main_From_UartRxBuff(); if (gHidRx.Flag) LT_Hid_ReceiveCmd(gHidRx.Buf); if(UI_update == 0) break; } } #else #endif #endif #if IIC_BUS // Based on the IIC protocol, executes the functions of the registers LT_IIC_REG_Cmd(); #endif if (var[0x700e * 2 + 1]) BackLight_control(); // Backlight control if (page_refreshing > 20) { page_refreshing = 0; Get_date_variable_Id_Regular_update(pic_id); } if(Count_reg_num > 0) { Count_reg_num--; reg_operation(Count_reg[Count_reg_num]); } if (gWavFlag == 1 || gWavType == 1) LT_PlayWav_DAC(); #if !IIC_BUS /*The current hardware that CTP and IIC slave use the same set of IOs If you use the IIC slave function, you need to block the touch function first*/ gTpInfo.scan(); // 打印触摸屏的坐标 // printf("gTpInfo.x[0]=%d gTpInfo.y[0]=%d gTpInfo.x[1]=%d gTpInfo.y[1]=%d\r\n" // ,gTpInfo.x[0],gTpInfo.y[0],gTpInfo.x[1],gTpInfo.y[1]); #endif #if 1 if(all_flag == 1) { all_flag = 0; debug_flag(); } if(status_flag ==1) { status_flag = 0; debug_status(); } #endif #if 0 show_gif(); // gif show_Clock(); // Analog clock show_RTC(); // Digital clock scroll_text(); // Text scroll1 Display_Curve(); // Curve show_Count(); // Time counter #endif Check_Var_Count(); Check_Pointer(); #if encoder_on if (gEncoderFlag) encoder(); #endif if (Ges_sc_flag) slide_screen(); // gesture_sliding if (Gesture_flag) Gesture_touch(); // gesture_no_sliding Basic_touch(); // Basic touch control Adj_touch(); // Variable adjustment slideMune(); // Slide menu #if 0 Progress_bar_sliding(); // Sliding progress bar data_input(); // Data input RingSld_touch(); // Ring progress bar with touch Ascii_input(); // ASCII keyboard GBK_input(); // GBK keyboard VarKey_touch(); // Multivariable adjustment pop_up_touch(); // Pop-up window #endif /**** Screen test ****/ // if (scr_flag == 1 && scr_time > 100) // { // scr_time = 0; // Detection_screen(scr_flag) ; // } // else if (scr_flag == 2) // { // if (gTpInfo.sta) // press down // { // scr_key = 1; // } // if (gTpInfo.sta == 0 &&scr_key == 1) // { // scr_key = 0; // Detection_screen(scr_flag) ; // } // } #if 0 /****Keyboard cursor display****/ if (Cusor_time > 60) { Cusor_time = 0; if (DioKb_flag == 1) { if (Screen_DIR == 0) { if (gDio_Info[Dio_num].Alig == 0) cx = cur_x + input_w; else cx = cur_x; cy = cur_y; w_temp = cur_w; h_temp = gDio_Info[Dio_num].zk_h; } else if (Screen_DIR == 1) { if (gDio_Info[Dio_num].Alig == 0) cy = cur_y + input_w; else cy = cur_y; cx = cur_x; w_temp = gDio_Info[Dio_num].zk_h; h_temp = cur_w; } else if (Screen_DIR == 2) { if (gDio_Info[Dio_num].Alig == 0) cx = cur_x - input_w; else cx = cur_x; cy = cur_y; w_temp = cur_w; h_temp = gDio_Info[Dio_num].zk_h; } else if (Screen_DIR == 3) { if (gDio_Info[Dio_num].Alig == 0) cy = cur_y - input_w; else cy = cur_y; cx = cur_x; w_temp = gDio_Info[Dio_num].zk_h; h_temp = cur_w; } } else if (AioKb_flag == 1) { if (Screen_DIR == 0) { cx = cur_x + input_w; cy = cur_y; w_temp = cur_w; h_temp = gAio_Info[Aio_num].zk_h; } else if (Screen_DIR == 1) { cy = cur_y + input_w; cx = cur_x; w_temp = gAio_Info[Aio_num].zk_w; h_temp = cur_w; } else if (Screen_DIR == 2) { cx = cur_x - input_w; cy = cur_y; w_temp = cur_w; h_temp = gAio_Info[Aio_num].zk_h; } else if (Screen_DIR == 3) { cy = cur_y - input_w; cx = cur_x; w_temp = gAio_Info[Aio_num].zk_h; h_temp = cur_w; } } else if (GBKioKb_flag == 1) { if (Screen_DIR == 0) { cx = cur_x + input_w; cy = cur_y; w_temp = cur_w; h_temp = gGBKio_Info[GBKio_num].zk_h; } else if (Screen_DIR == 1) { cy = cur_y + input_w; cx = cur_x; w_temp = gGBKio_Info[GBKio_num].zk_w; h_temp = cur_w; } else if (Screen_DIR == 2) { cx = cur_x - input_w; cy = cur_y; w_temp = cur_w; h_temp = gGBKio_Info[GBKio_num].zk_h; } else if (Screen_DIR == 3) { cy = cur_y - input_w; cx = cur_x; w_temp = gGBKio_Info[GBKio_num].zk_h; h_temp = cur_w; } } if (Cusor_sw == 0) { Cusor_sw++; LT768_BTE_Memory_Copy(MAIN_BUFF, LCD_XSIZE_TFT, cx, cy, MAIN_BUFF, LCD_XSIZE_TFT, cx, cy, Display_Layer, LCD_XSIZE_TFT, cx, cy, 0x0c, w_temp, h_temp); } else { Cusor_sw = 0; LT768_BTE_Memory_Copy(LAY_BUFF5, LCD_XSIZE_TFT, cur_x, cur_y, LAY_BUFF5, LCD_XSIZE_TFT, cur_x, cur_y, Display_Layer, LCD_XSIZE_TFT, cx, cy, 0x0c, w_temp, h_temp); } } #endif } #endif // APP(APP_ADDR); #if 0 Run_Boot_ID = 0x47210659; if((Run_Boot_ID == 0x47210659) || (EFLASH_WordRead(0x8009E00)!=0x21436587)) { // printf("enter-updata\r\n"); uart_rx_number = 0; uart_buf[0] = 0x0; uart_rx_endIndex = 0; uart_act_index = 0; vcom_rp[0].fullIndex = 0; vcom_rp[1].fullIndex = 0; baud_index = 0x7F; display_manu(0); Enable_Interrupts; // Uart_Init(g_ips_clk, 921600); //升级的串口初始化 1382400;//921600;//230400;//115200; Uart_Init(g_ips_clk, 115200); PIT1_Init_Uart(); //PIT定时器初始化,用来监控串口数据结束的 #if Display_Progress PIT2_Loop(); #endif LT_SingleByteToPc(0xAA); inBuf[0]=0xAA; inBuf[1]=0xFF; inBuf[2]=0x42; inBuf[3]=0x4F; inBuf[4]=0x4F; inBuf[5]=0x54; inBuf[6]=0x55; inBuf[7]=0x50; inBuf[8]=0x44; inBuf[9]=0x41; inBuf[10]=0x54; inBuf[11]=0x45; inBuf[12]=0xA4; inBuf[13]=0x18; inBuf[14]=0xE4; inBuf[15]=0x1B; inBuf[16]=0x11; inBuf[17]=0xEE; uart_send(inBuf,18); unsigned char buff[1024],buff1[1024]; LT768_Print_Internal_Font_String(50,50,Red,Blue2,"Uart_Updating,please keep power on"); // LT768_Print_Internal_Font_String(100,2*50,Red,Blue2,"Uart_Updating,do not off"); printf("***baud_index=%d***\r\n",baud_index); while(1) { // printf("uart updata!\r\n"); WDT_FeedDog(); #if 1 if( app_flag ==1) { app_flag = 0; WDT_FeedDog(); APP(APP2_ADDR); //21KB APP_ADDR 0x8022000 } #endif if(uart_act_index == 1) { do_all_uart(); } if(baud_index<11) { DelayMS(5); Uart_Init(g_ips_clk,bdRate[baud_index]); printf("bdRate[baud_index]=%d\r\n",bdRate[baud_index]); baud_index = 0x7F; } #if Display_Progress if(Flag_Loop) { Flag_Loop=0; if(FLag_Pos==0) { X_pos=202; Y_pos=120; } else if(FLag_Pos==1) { X_pos=226; Y_pos=170; } if(count_Loop==0) LT768_Print_Internal_Font_String(X_pos,Y_pos,Red,Blue2,"* "); else if(count_Loop==1) LT768_Print_Internal_Font_String(X_pos,Y_pos,Red,Blue2," *"); count_Loop++; if(count_Loop>1) count_Loop=0; } #endif } } // else //没有卡,离开BootLoader,跳转到app // { // // APP(APP_ADDR); // } #endif #if 0 unsigned char flash[256]={0}; unsigned char flash1[256]={0}; unsigned char flash2[256]={0}; unsigned char flash3[512]={0}; unsigned char flash4[512]={0}; for(unsigned int i = 0 ; i < 256 ; i++) { flash[i] = 6; } // W25N01GV_Erase_Block(0);//W25N01GV_Erase_Block(0x200000/131072); for(unsigned int i = 0 ; i < 256 ; i++) { printf(" %x" , flash1[i]); } W25N01GV_ReadPageAddr_Data(flash1,0,0,256); //W25N01GV_ReadPageAddr_Data(flash1,0,0x200000/2048,256); printf("\r\n--------Erase---------------\r\n"); for(unsigned int i = 0 ; i < 256 ; i++) { printf(" %x" , flash1[i]); } W25N01GV_ReadPageAddr_Data(flash1,256,0,256); //W25N01GV_ReadPageAddr_Data(flash1,256,0x200000/2048,256); printf("\r\n--------Erase---------------\r\n"); for(unsigned int i = 0 ; i < 256 ; i++) { printf(" %x" , flash1[i]); } W25N01GV_ReadPageAddr_Data(flash3,0,0,512); //W25N01GV_ReadPageAddr_Data(flash3,0,0x200000/2048,512); printf("\r\n--------Erase---------------\r\n"); for(unsigned int i = 0 ; i < 512 ; i++) { printf(" %x" , flash3[i]); } //写入 W25N01GV_WritePageAddr_Data(flash,0,0,256); //W25N01GV_WritePageAddr_Data(flash,0,0x200000/2048,256); //读取 W25N01GV_ReadPageAddr_Data(flash1,0,0,256); //W25N01GV_ReadPageAddr_Data(flash1,0,0x200000/2048,256); printf("\r\n-----------write--flash1----------\r\n"); for(unsigned int i = 0 ; i < 256 ; i++) { printf(" %x" , flash1[i]); } printf("\r\n-----------write---flash2---------\r\n"); W25N01GV_WritePageAddr_Data(flash,256,0,256); // W25N01GV_WritePageAddr_Data(flash,256,0x200000/2048,256); W25N01GV_ReadPageAddr_Data(flash2,256,0,256); // W25N01GV_ReadPageAddr_Data(flash2,256,0x200000/2048,256); for(unsigned int i = 0 ; i < 256 ; i++) { printf(" %x" , flash2[i]); } printf("\r\n-----------write---flash3---------\r\n"); W25N01GV_ReadPageAddr_Data(flash3,0,0,512);//W25N01GV_ReadPageAddr_Data(flash3,0,0x200000/2048,512); for(unsigned int i = 0 ; i < 512 ; i++) { printf(" %x" , flash3[i]); } printf("\r\n-----------write---flash4---------\r\n"); W25N01GV_ReadPageAddr_Data(flash4,512,0,512);//W25N01GV_ReadPageAddr_Data(flash4,512,0x200000/2048,512); for(unsigned int i = 0 ; i < 512 ; i++) { printf(" %x" , flash4[i]); } #endif //W25N01GV_Erase_Block(0); while(1) { WDT_FeedDog(); // printf("init finish!\r\n"); // DelayMS(500); if(ota_lt7689_flag==1) { WDT_FeedDog(); if((Rx_Buffer_short[0]==0xA5)&& (Rx_Buffer_short[1]==0x5A)&& (Rx_Buffer_short[2]==0x08)&& (Rx_Buffer_short[3]==0x01)&& (Rx_Buffer_short[4]==0x00)&& (Rx_Buffer_short[5]==0x00)&& (Rx_Buffer_short[6]==0xFF)&& (Rx_Buffer_short[7]==0xFE) ) { printf("enter APP_ADDR!\r\n"); APP(APP_ADDR); } else if((Rx_Buffer_short[0]==0xA5)&& (Rx_Buffer_short[1]==0x5A)&& (Rx_Buffer_short[2]==0x08)&& (Rx_Buffer_short[3]==0x04)&& (Rx_Buffer_short[4]==0x90)&& (Rx_Buffer_short[5]==0x00)&& (Rx_Buffer_short[6]==0xFF)&& (Rx_Buffer_short[7]==0xFE) ) { printf("enter APP2_ADDR!\r\n"); APP(APP2_ADDR); } #if 0 // printf("length:%d\r\n",ui_buf_length); for(unsigned int i = 0 ; i < Rx_Count_short; i++) { ui_buf[i+ui_buf_length]=Rx_Buffer_short[i]; } ui_buf_length += Rx_Count_short; printf("ui=%d\r\n",ui_buf_length); if(ui_buf_length==2048)//||(ui_buf_length==662) { #if 0 W25N01GV_Erase_Block(0); printf("erase0\r\n"); W25N01GV_Erase_Block(1); printf("erase1\r\n"); WDT_FeedDog(); W25N01GV_WritePageAddr_Data(ui_buf,0,0,ui_buf_length); printf("Write\r\n"); WDT_FeedDog(); W25N01GV_ReadPageAddr_Data(flash,0,0,ui_buf_length); printf("Read\r\n"); WDT_FeedDog(); for(unsigned int i = 0 ; i < ui_buf_length; i++) { printf(" %x",flash[i]); } printf("\r\n"); #endif if(page%64==0) { printf("erase:%d\r\n",block); W25N01GV_Erase_Block(block); block++; } printf("page:%d length:%d\r\n",page,ui_buf_length); W25N01GV_WritePageAddr_Data(ui_buf,0,page,ui_buf_length); // for(unsigned int i = 0 ; i < ui_buf_length ; i++) // { // printf(" %x",ui_buf[i]); // } // printf("\r\n"); ui_buf_length=0; page++; } #endif #if 0 // 块擦除 每64页(128KB)的时候擦除下一块 if(page%64==0) { printf("block=%d\r\n",block); W25N01GV_Erase_Block(1); block++; } //写入 到2048(2KB)的时候 换页 // W25N01GV_Erase_Block(0); // if(ui_offset%2048==0) // { // // W25N01GV_Erase_Block(page); // printf("erase\r\n"); // } printf("%d %d %d\r\n",ui_offset,Rx_Count_short,page); // ota_ui(page , Rx_Buffer_short ,Rx_Count_short,ui_offset); // W25N01GV_WritePageAddr_Data(Rx_Buffer_short,ui_offset,page,Rx_Count_short); // W25N01GV_ReadPageAddr_Data(flash,ui_offset,page,Rx_Count_short); printf("OTA\r\n"); for(unsigned short i = 0 ; i < Rx_Count_short ; i++) { printf(" %x",Rx_Buffer_short[i]);//Rx_Buffer_short flash } printf("\r\n"); if(ui_offset==2048) { printf("enter 2048 \r\n"); page++; ui_offset=0; } ui_offset+=Rx_Count_short; Rx_Count_short=0; printf("end %d %d %d\r\n",ui_offset,Rx_Count_short,page); #endif // for(i=0 ; i<256 ;i++) // { // printf("%x ",Rx_Buffer_short[i]); // } // printf("\r\n"); // if(Rx_Count_short<256) // { // printf("end number=%d Rx_Count_short=%d\r\n",number1,Rx_Count_short); // } #if 0 //OTA BIN-core ota_offset = Rx_Count_short; // printf("ota_address %x\r\n",ota_address);// 256 0x8010000 printf("\r\n"); printf("start:%x length:%d \r\n",ota_address,Rx_Count_short); ota_lt7689(Rx_Buffer_short,Rx_Count_short,ota_address); printf("\r\n"); ota_address += ota_offset; if(ota_offset<256) { printf("\r\n"); // printf("end number:%d\r\n",number); APP(APP_ADDR); } #endif number+=Rx_Count_short; for(unsigned short i = 0 ; i < Rx_Count_short; i++) { printf(" %x",Rx_Buffer_short[i]); } printf("\r\n"); Rx_Count_short=0; ota_lt7689_flag=0; printf("number=%d\r\n",number); } } }