Procházet zdrojové kódy

1、配置下载增加S528型号,触控识别为GT2933/36
2、增加GT2933/36的固件下载功能
3、GT2931的固件下载功能还有问题,读取不到ISP标志,待查

robbin před 1 rokem
rodič
revize
cbef5841c2

+ 1 - 1
.idea/misc.xml

@@ -29,7 +29,7 @@
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 2 - 2
app/build.gradle

@@ -7,14 +7,14 @@ android {
         minSdkVersion 18
         targetSdkVersion 28
         versionCode 1
-        versionName "3.0.2"
+        versionName "3.0.3"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     android.applicationVariants.all {
         variant ->
             variant.outputs.all{
                 //此处指定生成的apk文件名
-                outputFileName = "WingCoolAPK_V3.0.2_20230509_debug.apk"
+                outputFileName = "WingCoolAPK_V3.0.3_20230515_debug.apk"
             }
     }
     lintOptions {

+ 1 - 1
app/src/main/java/com/example/administrator/wingcool_gt9_apk/Config.java

@@ -1996,7 +1996,7 @@ public class Config extends AppCompatActivity
                                     byProductType = GT29336;
                                 }
                                 */
-                                if (iProductId == 0x0829)
+                                if ((iProductId == 0x0829) || (iProductId == 0x0528))
                                 {
                                     byProductType = GT29336;
                                 }

+ 957 - 91
app/src/main/java/com/example/administrator/wingcool_gt9_apk/FirmwareUpdate.java

@@ -83,6 +83,7 @@ public class FirmwareUpdate extends AppCompatActivity
     private byte[] mSendData = new byte[1024];
     private byte[] mConfigData = new byte[1024];
     private String[] mVersionShow = new String[16];
+    byte[] mGt293xFirmwareData = new byte[500 * 1024];
 
     private boolean isReceiverMessage = true;
     private boolean isSendMessage = true;
@@ -101,6 +102,8 @@ public class FirmwareUpdate extends AppCompatActivity
     private byte byProductType = 0;
     private static final byte GT9 = 0x01;
     private static final byte GT7 = 0x02;
+    private static final byte GT29336 = 0x03;
+    private static final byte GT2931 = 0x04;
     
     int FW_HEAD_LENGTH	=		14;
     int FW_SECTION_LENGTH	=	0x2000; 	/** 8K */
@@ -132,6 +135,22 @@ public class FirmwareUpdate extends AppCompatActivity
         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     };
 
+    //-------------------------------------------------------------------------------------------------------------------------------//
+    byte TYPE_BERLIN_B = (byte)0x97;
+    byte TYPE_BERLIN_D = (byte)0x98;  // 兼容GT9916 BerlinD
+    byte SS51_ISP_CODE = 0x01;
+    byte	SS51_PATCH_CODE = 0x02;//Const Code for Berlin
+    byte	SS51_PATCH_OVERLAY = 0x03;
+    byte	DSP_CODE = 0x04;
+    byte	HOTKNOT_CODE = 0x05;
+    byte	GESTURE_CODE =	0x06;
+    byte	GSETURE_OVERLAY_CODE = 0x07;
+    byte	FLASHLESS_CODE = 0x08;
+
+    int MAX_SEND_BYTES = 4096;
+
+    //-------------------------------------------------------------------------------------------------------------------------------//
+
     private Button btn_update;
     private Button btn_AutoUpdate;
 
@@ -271,7 +290,8 @@ public class FirmwareUpdate extends AppCompatActivity
                  updateLogShow =  "";
                  Update_log2 =  "";
                  mHandler.sendEmptyMessage(UPDATE_FW);
-                 if(updateProc() == true) {
+                 if(GT29xxupdateProc() == true)
+                 {
                     // mHandler.sendEmptyMessage(UPDATE_FW);
                      Update_log1 =  "UPDATE SUCCESS!!!";  //升级成功
                      mHandler.sendEmptyMessage(UPDATE_FW);
@@ -445,11 +465,19 @@ public class FirmwareUpdate extends AppCompatActivity
                             mUsbDeviceConnection.claimInterface(mUsbInterface, true);
                             if(null != mUsbEndpointIn){
                                 iProductId = usbDevice.getProductId();
-                                if ((iProductId == 0x0819) || (iProductId == 0x8191)||(iProductId == 0x0528))
+                                //if ((iProductId == 0x0819) || (iProductId == 0x8191)||(iProductId == 0x0528))
+                                //{
+                                //    byProductType = GT7;
+                                //}else{
+                                //    byProductType = GT9;
+                                //}
+
+                                if ((iProductId == 0x0829) || (iProductId == 0x0528))
                                 {
-                                    byProductType = GT7;
-                                }else{
-                                    byProductType = GT9;
+                                    byProductType = GT29336;
+                                }
+                                else{
+                                    byProductType = GT2931;
                                 }
                                 mHandler.sendEmptyMessage(CONNECTED_SUCCESS);
                             }
@@ -475,6 +503,7 @@ public class FirmwareUpdate extends AppCompatActivity
                 mSendData = mSendGetGt9VersionData;
                 isSendMessage = false;
 
+                /*
                 if (byProductType == GT7)  //GT7
                 {
                     addressH = (byte)0x82;
@@ -496,11 +525,12 @@ public class FirmwareUpdate extends AppCompatActivity
                     else if (mBytes[0] == 0x37 && mBytes[1] == 0x33 && mBytes[2] == 0x38 && mBytes[3] == 0x32){
                         mShow.setText( "GT7382H_" + mVersionShow[4] + "." + mVersionShow[5] + "." + mVersionShow[6] + "." + mVersionShow[7]);//输出显示
                     }
-                    else{
+                    else
                         mShow.setText( "Null" );//输出显示
                     }
                 }
                 else  //GT9
+                */
                 {
 
                     iicRead32Bits((byte)0x01, (byte)0x00, (byte)0x14, mBytes, 23);
@@ -588,7 +618,8 @@ public class FirmwareUpdate extends AppCompatActivity
                 //mSendData = mSendGetGt9VersionData;
                 isSendMessage = false;
                 //mHandler.sendEmptyMessage(UPDATE_FW);
-                if (byProductType == GT9) {
+                //if (byProductType == GT9)
+                {
                     updateProcHandle();
                 }
                 break;
@@ -689,6 +720,10 @@ public class FirmwareUpdate extends AppCompatActivity
                         edit_search.setText(dir.getPath() + "/GT738x.bin");
 
                         dataFile = new File(dir.getPath(), "GT738x.bin");
+                    }else if (byProductType == GT29336 || (byProductType == GT2931)) {  //GT293x
+                        edit_search.setText(dir.getPath() + "/GT293x.bin");
+
+                        dataFile = new File(dir.getPath(), "GT293X.bin");
                     }else{  //other
                         edit_search.setText(dir.getPath() + "/GTxxxx.bin");
 
@@ -822,89 +857,6 @@ public class FirmwareUpdate extends AppCompatActivity
         return true;
     }
 
-    //发送命令,使得S818可以通过IIC向GT9的固定地址读取任意bytes的数据
-    private boolean iicRead32Bits(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte[] wBuffer,int length) {
-
-        int i;
-
-        iicByteData[1] = 0x0f; //7bit:0-read,1-write;other:command
-        //iicByteData[2] = 0x0f; //no command
-        iicByteData[2] = addrfirstbyte;
-        iicByteData[3] = addrsecondbyte;
-        iicByteData[4] = addrthirdbyte;
-        iicByteData[5] = 0x00;
-        iicByteData[6] = 63;  //length 一次接收63个数据
-
-        for (int j = 7; j < 64; j++) {
-            iicWriteData[j] = 0x00;
-        }
-
-        //int address1 = ((addrfirstbyte&0xff)<<8);
-        //int address2 = addressLow&0xff;
-        //int address = address1|address2;
-
-        int sendTimes = length/63 + 1;  //预计是向下取整,所以+1
-
-        iicByteData[5] = (byte)(length>>8);
-        iicByteData[6] = (byte)length;  //length 一次接收63个数据
-
-        //发送读取命令
-        i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
-        if (i != 0x40)
-            return false;  //传输失败
-
-        for (int k = 0; k < sendTimes; k++) {
-            //int finalOffset = k*63; //每次只能发57bytes数据
-            int offset = k*64;
-
-            //  if(length - (finalOffset ) < 63) {
-
-            // iicByteData[6] = (byte) (length - (finalOffset));  //length
-            // }
-            //   else
-            //   {
-            //  iicByteData[6] = 63;
-            //  }
-
-
-            // SystemClock.sleep(1);
-
-            isReceiverMessage = false;  //先关闭循环接收信息
-
-            //接收数据
-            // i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);
-            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);
-
-            //if (i != 0x40) {
-            if (i != 0x40) {
-                // mError.setText("iicWrite Failed");
-                Update_log = "iicRead Failed";
-                mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
-                return false;
-
-            }
-
-            // address = address + 63;
-            //  iicByteData[3] = (byte)(address>>8);
-            //  iicByteData[4] = (byte)address;
-        }
-
-        //将report id从数组中去除
-        //byte[] temperBuffer =new byte[length];
-        if(true) {
-            int count1 = 0;
-            for (int k = 0; k < length; k++) {
-                if (k % 63 == 0) {
-                    count1++;
-                }
-
-                wBuffer[k] = wBuffer[k + count1];
-
-            }
-        }
-        return true;
-    }
-
     //发送命令,使得S818可以通过IIC向GT9的固定地址写任意bytes的数据
     private  boolean iicWrite(byte addressHigh,byte addressLow,byte[] wBuffer,int offset,int length) {
         int i;
@@ -1015,6 +967,172 @@ public class FirmwareUpdate extends AppCompatActivity
         // }
     }
 
+    //发送命令,使得S8xx可以通过IIC向GT29xx的固定地址读取任意bytes的数据
+    private boolean iicRead32Bits(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte[] wBuffer,int length) {
+
+        int i;
+
+        iicByteData[1] = 0x0f; //7bit:0-read,1-write;other:command
+        //iicByteData[2] = 0x0f; //no command
+        iicByteData[2] = addrfirstbyte;
+        iicByteData[3] = addrsecondbyte;
+        iicByteData[4] = addrthirdbyte;
+        iicByteData[5] = 0x00;
+        iicByteData[6] = 63;  //length 一次接收63个数据
+
+        for (int j = 7; j < 64; j++) {
+            iicByteData[j] = 0x00;
+        }
+
+        int address1 = ((addrsecondbyte & 0xff) << 8);
+        int address2 = addrthirdbyte & 0xff;
+        int address = address1 | address2;
+
+        int sendTimes = length / 63;  //预计是向下取整,所以+1
+
+        if ((length % 63) != 0)
+        {
+            sendTimes += 1;   //预计是向下取整,所以+1
+        }
+        //iicByteData[5] = (byte)(length>>8);
+        //iicByteData[6] = (byte)length;  //length 一次接收63个数据
+
+        for (int k = 0; k < sendTimes; k++)
+        {
+            int finalOffset = k*63; //每次只能发57bytes数据
+            int offset = k * 64;
+
+            if(length - (finalOffset ) < 63) {
+
+                iicByteData[6] = (byte) (length - (finalOffset));  //length
+            }
+            else
+            {
+                iicByteData[6] = 63;
+            }
+
+            //发送读取命令
+            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
+            if (i != 0x40)
+                return false;  //传输失败
+
+            // SystemClock.sleep(1);
+
+            //接收数据
+            // i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);
+            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointIn, wBuffer, offset, 0x40, 100);
+
+            //if (i != 0x40) {
+            if (i != 0x40) {
+                //editname.setText("IIC Read Failed!!");
+                return false;
+
+            }
+
+            address = address + 63;
+            iicByteData[3] = (byte)(address>>8);
+            iicByteData[4] = (byte)address;
+        }
+
+        //将report id从数组中去除
+        //byte[] temperBuffer =new byte[length];
+        if(true) {
+            int count1 = 0;
+            for (int k = 0; k < length; k++) {
+                if (k % 63 == 0) {
+                    count1++;
+                }
+
+                wBuffer[k] = wBuffer[k + count1];
+
+            }
+        }
+        return true;
+    }
+
+    //发送命令,使得S8xx可以通过IIC向GT79xx的固定地址写任意bytes的数据
+    private  boolean iicWrite32Bits(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte[] wBuffer,int offset, int length) {
+
+        int i;
+
+        iicWriteData[1] = (byte)0x8f; //7bit:0-read,1-write;other:command
+        //iicWriteData[2] = 0x0f; //no command
+        iicWriteData[2] = addrfirstbyte;
+        iicWriteData[3] = addrsecondbyte;
+        iicWriteData[4] = addrthirdbyte;
+        iicWriteData[5] = 0x00;
+        iicWriteData[6] = 63;  //length 一次接收63个数据
+
+        for (int j = 7; j < 64; j++) {
+            iicWriteData[j] = 0x00;
+        }
+
+        int address1 = ((addrsecondbyte&0xff)<<8);
+        int address2 = addrthirdbyte&0xff;
+        int address = address1|address2;
+
+        int sendTimes = length / 57 + 1;  //预计是向下取整,所以+1
+
+        //iicByteData[5] = (byte)(length>>8);
+        //iicByteData[6] = (byte)length;  //length 一次接收63个数据
+
+        for (int k = 0; k < sendTimes; k++) {
+            int finalOffset = offset + k * 57; //每次只能发57bytes数据
+
+            if(length - (finalOffset -offset) < 57) {
+
+                iicWriteData[6] = (byte) (length - (finalOffset -offset));  //length
+            }
+            else
+            {
+                iicWriteData[6] = 0x39;
+            }
+
+            for (int j = 7; j < 64; j++) {
+                iicWriteData[j] = wBuffer[finalOffset + j -7];
+            }
+            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicWriteData, 0, 0x40, 100);
+
+            if (i != 0x40) {
+                //editname.setText("iicWrite Failed");
+                return false;
+
+            }
+
+            address = address + 57;
+            //iicWriteData[2] = (byte)((address & 0xFF0000) >> 16);
+            iicWriteData[3] = (byte)(address >> 8);
+            iicWriteData[4] = (byte)address;
+        }
+
+        return true;
+    }
+
+    //发送命令,使得S818可以通过IIC向GT9的固定地址写1byte数据
+    private  boolean IicWriteOneByte(byte addrfirstbyte,byte addrsecondbyte,byte addrthirdbyte,byte subCommand,byte data) {
+        int i;
+
+        iicByteData[1] = (byte)(0x80 | subCommand); //write GT9 command
+        iicByteData[2] = addrfirstbyte;
+        iicByteData[3] = addrsecondbyte;
+        iicByteData[4] = addrthirdbyte;
+        iicByteData[5] = 0x00;
+        iicByteData[6] = 0x01;  //length
+
+        iicByteData[7] = data;
+        if ((null == mUsbEndpointIn) || (null == mUsbEndpointOut)){
+            i=0;
+        }
+        else {
+            i = mUsbDeviceConnection.bulkTransfer(mUsbEndpointOut, iicByteData, 0, 0x40, 100);
+        }
+        // i = 0;
+        if(i == 0x40)
+            return true;
+        else
+            return false;
+    }
+
     private boolean enterUpdateMode() {
         // if ( == false)
         {
@@ -1207,6 +1325,34 @@ public class FirmwareUpdate extends AppCompatActivity
 
     }
 
+    boolean recallCheck32Bits(byte addrfirstbyte,byte addrsecondbyte, byte addrthirdbyte, byte[] wBuffer,int offset,int length)
+    {
+        //BYTE* pbBuf = new BYTE[wLen];
+        byte[] pbBuf =new byte[length+0x3000];
+
+        //if(false)
+        {
+            if (!iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, pbBuf, length))
+            //if (!iicRead(addressHigh, addressLow, pbBuf, length))
+            {
+                //FwUpdateMessage(L"recall i2c error failed", MSG_ERR);
+                Update_log2 =Update_log2.concat("recall i2c error failed!") ;
+                Update_log2 = Update_log2.concat("\n");
+                return false;
+            }
+            if (!memCmp(pbBuf, wBuffer, offset, length)) {
+
+                // FwUpdateMessage(L"Recall frame data fail,not equal.", MSG_ERR);
+                //mMessage.setText("Recall frame data fail,not equal.");
+                Update_log2 =Update_log2.concat("recall frame data fail,not equal") ;
+                Update_log2 = Update_log2.concat("\n");
+                return false;
+            }
+        }
+        return true;
+
+    }
+
     byte[] mGt9FirmwareData = new byte[88 * 1024 + 512];
     /**
     public void readFile() throws IOException {
@@ -1314,7 +1460,8 @@ public class FirmwareUpdate extends AppCompatActivity
                 {
                     filename = edit_search.getText().toString();
                     FileInputStream fw = new FileInputStream(filename);
-                    fw.read(mGt9FirmwareData);
+                    //fw.read(mGt9FirmwareData);
+                    fw.read(mGt293xFirmwareData);
                     fw.close();
                 }
                 else {
@@ -2532,6 +2679,725 @@ public class FirmwareUpdate extends AppCompatActivity
         return true;
     }
 
+    //---------------------------------------------------------------------------------------------------------------------------//
+    private byte iChipType;
+    private byte iFwCnt;
+
+    int BERLINB_MAX_FW_NUM =  47;
+
+    private byte[] p_fw_info_fw_type = new byte[BERLINB_MAX_FW_NUM];
+    private int[] p_fw_info_fw_len = new int[BERLINB_MAX_FW_NUM];
+    private int[] p_fw_info_fw_flash_addr = new int[BERLINB_MAX_FW_NUM];
+    private int[] p_fw_info_fw_data_index = new int[BERLINB_MAX_FW_NUM];
+    /*
+    private boolean CheckBinFileValid()
+    {
+        int nValidLen = (mGt293xFirmwareData[0]) + (mGt293xFirmwareData[1] << 8)
+                + (mGt293xFirmwareData[2] << 16) + (mGt293xFirmwareData[3] << 24);
+
+        if(nValidLen + 8 > m_nBinFileLen)
+        {
+            return false;
+        }
+
+        INT32 nCheckSum = mGt293xFirmwareData[4] + (mGt293xFirmwareData[5] << 8)
+                + (mGt293xFirmwareData[6] << 16) + (mGt293xFirmwareData[7] << 24);
+
+        if (nCheckSum != GetCheckSum((WORD*)(m_pbBinBuf + 8), nValidLen>>1))
+        {
+            return false;
+        }
+
+        return true;
+    }
+    */
+    private boolean UpdateInit(){
+        //if (!CheckBinFileValid())
+        //    return false;
+
+        iChipType = mGt293xFirmwareData[30];
+        iFwCnt = mGt293xFirmwareData[29];
+        //增加GT9916支持,chiptype=0x98
+        if (iChipType != TYPE_BERLIN_B && iChipType != TYPE_BERLIN_D)
+        {
+            Update_log = "[FW update]Chip_type error!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+        if (iFwCnt == 0 || iFwCnt > (byte)BERLINB_MAX_FW_NUM)
+        {
+            Update_log = "[FW update]Fw_cnt error!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+        int nInfoOffset = 42;
+        int nDataOffset = 512;
+        int nInfoStepSize = 10;
+
+        for (int i = 0; i < iFwCnt; i++)
+        {
+            int index = nInfoOffset + i * nInfoStepSize;
+            p_fw_info_fw_type[i] = mGt293xFirmwareData[index];
+            p_fw_info_fw_len[i] = (mGt293xFirmwareData[index + 1] & 0xff) + ((mGt293xFirmwareData[index + 2] & 0xff) << 8) + ((mGt293xFirmwareData[index + 3] & 0xff) << 16) + ((mGt293xFirmwareData[index + 4] & 0xff) << 24);
+            //p_fw_info_fw_len[i] = p_fw_info_fw_len[i] & 0xffff;
+
+            p_fw_info_fw_flash_addr[i] = (mGt293xFirmwareData[index + 5] & 0xff) + ((mGt293xFirmwareData[index + 6] & 0xff) << 8) + ((mGt293xFirmwareData[index + 7] & 0xff) << 16) + ((mGt293xFirmwareData[index + 8] & 0xff) << 24);
+            p_fw_info_fw_data_index[i] = nDataOffset;  //存储固件起始位置的下标
+            nDataOffset += p_fw_info_fw_len[i];
+        }
+
+        Update_log = "[FW update]UpdateInit Success";
+        mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+        return true;
+    }
+
+    private boolean EnterUpdateMode(){
+
+        boolean ret = false;
+
+        byte addrfirstbyte = (byte)0x01;
+        byte addrsecondbyte = (byte)0x01;
+        byte addrthirdbyte = (byte)0x74;
+        byte msubcommand = (byte)0x12;  //最高位置1,写命令18 DISABLE_DIGITER_INTERFACE
+        byte mdata = (byte)0x00;
+
+        if(!IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata)) {
+            return false;
+        }
+
+        SystemClock.sleep(10);
+
+        msubcommand = (byte)0x2B;  //最高位置1,写命令43 DISABLE_ESD_CHECK
+        //mdata = (byte)0x00;
+
+        if(!IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata)) {
+            return false;
+        }
+
+        msubcommand = (byte)0x24;  //最高位置1,写命令36 GTXXX_ENTER_UPDATE_MODE
+
+        for (int i = 0; i < 10; i++)
+        {
+            ret = IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata);
+            if (ret) break;
+        }
+
+        if (!ret) {
+            Update_log = "[FW update]Enter Update Mode Fail!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+        else
+        {
+            for (int i = 0; i < 150; i++)
+            {
+                //gpI2C1->I2CByteWrite(0xD807, 0xFF);
+                //iicByteWrite((byte)0xD8, (byte)0x07, (byte)0, (byte)0xFF);
+                addrfirstbyte = (byte)0x00;
+                addrsecondbyte = (byte)0xD8;
+                addrthirdbyte = (byte)0x07;
+                msubcommand = (byte)0x0f;
+                mdata = (byte)0xFF;
+
+                IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata);
+                //iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,byte[] wBuffer, 0, 1);
+                SystemClock.sleep(20);
+                //if (0xFF == gpI2C1->I2CByteRead(0xD807))
+                iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,mBytes, 1);
+                if ((byte)0xFF == mBytes[0])
+                {
+                    addrfirstbyte = (byte)0x00;
+                    addrsecondbyte = (byte)0xD0;
+                    addrthirdbyte = (byte)0x54;
+                    msubcommand = (byte)0x0f;
+                    mdata = (byte)0;
+
+                    //gpI2C1->I2CByteWrite(0xD054, 0);
+                    //iicByteWrite((byte)0xD0, (byte)0x54, (byte)0, (byte)0);
+                    IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata);
+
+                    SystemClock.sleep(10);
+
+                    Update_log = "[FW update]Enter Update Mode Success";
+                    mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                    return true;
+                }
+                SystemClock.sleep(10);
+            }
+
+        }
+
+        Update_log = "[FW update]Enter Update Mode Fail!";
+        mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+        return false;
+    }
+
+    private boolean UpdateIsp(){
+
+        int fw_len = 0;
+        int fw_type = 0;
+        int fw_data_index = 0;
+
+        byte addrfirstbyte, addrsecondbyte, addrthirdbyte;
+
+        // ISP fw data get
+        for (int i = 0; i < iFwCnt; i++)
+        {
+            if (SS51_ISP_CODE == p_fw_info_fw_type[i])
+            {
+                fw_data_index = p_fw_info_fw_data_index[i];
+                fw_len = p_fw_info_fw_len[i];
+                fw_type = SS51_ISP_CODE;
+                break;
+            }
+        }
+
+        if (fw_type != SS51_ISP_CODE)
+        {
+            Update_log = "[FW update]Update ISP Code Fail!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+
+        if (iChipType == TYPE_BERLIN_B)//默认 Berlin B
+        {   //download isp to chip sram buffer addr
+            addrfirstbyte = 0x05;
+            addrsecondbyte = 0x70;
+            addrthirdbyte = 0x00;
+
+            //if (!gpI2C1->I2CWrite(BLB_ISP_RAM_ADDR, tmp_fw_info.p_fw_data, tmp_fw_info.fw_len))
+            if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,mGt293xFirmwareData,fw_data_index, fw_len))
+            {
+                Update_log = "[FW update]Update ISP Code Fail!";
+                mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                return false;
+            }
+
+            //todo
+            //BYTE* CheckIsp = new BYTE[tmp_fw_info.fw_len];
+            //if (!gpI2C1->I2CRead(BLB_ISP_RAM_ADDR, CheckIsp, tmp_fw_info.fw_len))
+            //{
+            //    return false;
+            //}
+            //if (memcmp(tmp_fw_info.p_fw_data, CheckIsp, tmp_fw_info.fw_len) != 0)
+            //{
+            //    return false;
+            //}
+        }
+        else if (iChipType == TYPE_BERLIN_D)
+        {
+            addrfirstbyte = 0x02;
+            addrsecondbyte = 0x38;
+            addrthirdbyte = 0x00;
+
+            //if (!gpI2C1->I2CWrite(BLD_ISP_RAM_ADDR, tmp_fw_info.p_fw_data, tmp_fw_info.fw_len))
+            if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,mGt293xFirmwareData,fw_data_index, fw_len))
+            {
+                return false;
+            }
+            SystemClock.sleep(20);
+            if (!recallCheck32Bits(addrfirstbyte,addrsecondbyte, addrthirdbyte, mGt293xFirmwareData,fw_data_index,fw_len))
+            {
+                return false;
+            }
+            /* todo
+            BYTE* CheckIsp = new BYTE[tmp_fw_info.fw_len];
+            if (!gpI2C1->I2CRead(BLD_ISP_RAM_ADDR, CheckIsp, tmp_fw_info.fw_len))
+            {
+                return false;
+            }
+            if (memcmp(tmp_fw_info.p_fw_data, CheckIsp, tmp_fw_info.fw_len) != 0)
+            {
+                return false;
+            }
+            */
+        }
+
+        //SystemClock.sleep(100);
+        //BYTE cmdClearBackDoor[10];
+        //BYTE ReadBackCheck[10];
+        //
+        for (int j = 0; j < 20; j++) {
+            for (int i = 0; i < 10; i++) {
+                mBytes[i] = (byte) 0x55;
+            }
+
+            //clear back door
+            //if (!gpI2C1->I2CWrite(BOOT_OPT_ADDR, cmdClearBackDoor, 8))
+            addrfirstbyte = 0x01;
+            addrsecondbyte = 0x00;
+            addrthirdbyte = 0x00;
+            if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, 0, 8)) {
+                return false;
+            }
+            SystemClock.sleep(20);
+
+            //if (!recallCheck32Bits(addrfirstbyte,addrsecondbyte, addrthirdbyte, mBytes,0,8))
+            if (!iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, 8))
+            //if (!gpI2C1->I2CRead(BOOT_OPT_ADDR, ReadBackCheck, 8))  //todo
+            {
+                //Update_log = "[FW update]Clear Back Door Fail!";
+                //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                return false;
+            }
+            //SystemClock.sleep(40);
+            int count;
+            for (count = 0; count < 8; count++) {
+                if (mBytes[count] != (byte) 0x55) {
+                    //Update_log = "[FW update]Clear Back Door Fail!";
+                    //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                    //return false;
+                    break;
+                }
+            }
+
+            if (count == 8){
+                //Update_log = "[FW update]Clear Back Door Fail!";
+                //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                //return false;
+                break;
+            }
+        }
+
+        //if (memcmp(cmdClearBackDoor, ReadBackCheck, 8) != 0)  //todo
+        //{
+        //    return false;
+        //}
+
+        addrfirstbyte = (byte)0x00;
+        addrsecondbyte = (byte)0xD8;
+        addrthirdbyte = (byte)0x08;
+        //msubcommand = (byte)0x0f;
+        //mdata = (byte)0;
+
+        if (!IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, (byte)0x0f, (byte)0))
+        //if (!gpI2C1->I2CByteWrite(0xD808, 0))//?sea
+        {
+            return false;
+        }
+
+        SystemClock.sleep(20);
+
+        boolean ret = false;
+        for (int i = 0; i < 200; i++)
+        {
+            //read buffer [0x01001E]
+            if (!iicRead32Bits((byte)0x01, (byte)0x00, (byte)0x1E, mBytes, 6))
+            {
+                continue;
+            }
+
+            if ((mBytes[3] == 'I') && (mBytes[4] == 'S') && (mBytes[5] == 'P'))
+            {
+                ret = true;
+                break;
+            }
+
+            SystemClock.sleep(5);
+        }
+
+        if (!ret)
+        {
+            Update_log = "[FW update]Update ISP Code Fail!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+        Update_log = "[FW update]Update ISP Code Success";
+        //mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+        return true;
+    }
+
+    private boolean DownloadSection(int index)
+    {
+        boolean ret = true;
+        int nOffset = 0;
+        int nLen;
+        byte[] pbSendBuf = new byte[MAX_SEND_BYTES + 10];
+        //BYTE* pbReadBuf = new BYTE[MAX_SEND_BYTES + 10];
+        //BYTE cmd[16];
+        //INT nCmdLen;
+        int nFlashAddr = p_fw_info_fw_flash_addr[index];
+
+        byte addrfirstbyte, addrsecondbyte, addrthirdbyte;
+
+        int ichecksum;
+
+        do
+        {
+            nLen = p_fw_info_fw_len[index] - nOffset > MAX_SEND_BYTES ? MAX_SEND_BYTES : p_fw_info_fw_len[index] - nOffset;
+
+            //memcpy(pbSendBuf, pFwInfo->p_fw_data + nOffset, nLen);
+            for (int i = 0; i < nLen; i++) {
+                pbSendBuf[i] = mGt293xFirmwareData[p_fw_info_fw_data_index[index] + nOffset + i];
+            }
+            //(*(DWORD*)(pbSendBuf + nLen)) = GetCheckSum((WORD*)pbSendBuf, nLen>>1);  //todo
+            ichecksum = 0;
+            for (int i = 0; i < nLen; i += 2) {
+                int vb = ((pbSendBuf[i + 1] & 0xFF) << 8) + (pbSendBuf[i] & 0xFF);
+                ichecksum = ichecksum + vb;
+            }
+
+            pbSendBuf[nLen] = (byte)(ichecksum & 0x000000ff);
+            pbSendBuf[nLen + 1] = (byte)((ichecksum & 0x0000ff00) >> 8);
+            pbSendBuf[nLen + 2] = (byte)((ichecksum & 0x00ff0000) >> 16);
+            pbSendBuf[nLen + 3] = (byte)((ichecksum & 0xff000000) >> 24);
+
+            //for (INT i = 0; i < 3; i++)
+            {
+                if (iChipType == TYPE_BERLIN_B)
+                {
+                    addrfirstbyte = 0x01;
+                    addrsecondbyte = 0x34;
+                    addrthirdbyte = 0x10;
+                    if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,pbSendBuf,0, nLen + 4))
+                    //if (!gpI2C1->I2CWrite(BLB_CMD_DATA_ADDR, pbSendBuf, nLen + 4))
+                    {
+                        ret = false;
+                        break;
+                    }
+                }
+                else if (iChipType == TYPE_BERLIN_D)
+                {
+                    addrfirstbyte = 0x01;
+                    addrsecondbyte = 0x24;
+                    addrthirdbyte = 0x10;
+                    if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,pbSendBuf,0, nLen + 4))
+                    //if (!gpI2C1->I2CWrite(BLD_CMD_DATA_ADDR, pbSendBuf, nLen + 4))
+                    {
+                        ret = false;
+                        break;
+                    }
+                }
+		/*	if (!gpI2C1->I2CRead(BLB_CMD_DATA_ADDR, pbReadBuf, nLen + 4))
+			{
+				ret = false;
+				break;
+			}
+
+			if (memcmp(pbReadBuf, pbSendBuf, nLen + 4) == 0)
+			{
+				ret = true;
+
+				break;;
+			}*/
+            }
+
+            if (!ret) {
+                return false;
+            }
+
+            mBytes[0] = 0x00;
+            mBytes[1] = 0x00;
+            mBytes[2] = 0x0B;//cmd len
+            mBytes[3] = (byte)0xBB;//FLASH_CMD_MASTER_W;//0xAA,0xBB,0xCC,0xDD
+            mBytes[4] = p_fw_info_fw_type[index];
+            mBytes[5] = (byte)((nLen + 4) & 0xFF);
+            mBytes[6] = (byte)(((nLen + 4) & 0xFF00) >> 8) ;
+            mBytes[7] = (byte)(nFlashAddr & 0xFF);
+            mBytes[8] = (byte)((nFlashAddr & 0xFF00) >> 8);
+            mBytes[9] = (byte)((nFlashAddr & 0xFF0000) >> 16);
+            mBytes[10] = (byte)((nFlashAddr & 0xFF000000) >> 24);
+
+            ichecksum = 0;
+            for (int i = 0; i < 11; i++)
+            {
+                ichecksum += (mBytes[i] & 0xFF);
+            }
+
+            mBytes[11] = (byte)(ichecksum & 0xFF);
+            mBytes[12] = (byte)((ichecksum & 0xFF00) >> 8) ;
+
+            //(*(WORD*)&cmd[11]) = GetCheckSum(cmd, 11);
+
+            if (iChipType == TYPE_BERLIN_B)
+            {
+                addrfirstbyte = 0x01;
+                addrsecondbyte = 0x34;
+                addrthirdbyte = 0x00;
+                if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,mBytes,0, 13))
+                //if (!gpI2C1->I2CWrite(BLB_CMD_ADDR, cmd, 13))
+                {
+                    ret = false;
+                    break;
+                }
+
+                int i;
+                for (i = 0; i < 50; i++)  //check 50 times
+                {
+
+                    SystemClock.sleep(30);
+
+                    iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, 1);
+                    //if (!gpI2C1->I2CCheckRegister(BLB_CMD_STATUS_ADDR, FLASH_CMD_W_STATUS_WRITE_OK))
+                    if (mBytes[0] == (byte) 0xEE)
+                    {
+                        break;
+                    }
+                }
+                if (i == 50){
+                    ret = false;
+                    break;
+                }
+            }
+            else if (iChipType == TYPE_BERLIN_D)
+            {
+                addrfirstbyte = 0x01;
+                addrsecondbyte = 0x24;
+                addrthirdbyte = 0x00;
+                if (!iicWrite32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte,mBytes,0, 13))
+                //if (!gpI2C1->I2CWrite(BLD_CMD_ADDR, cmd, 13))
+                {
+                    ret = false;
+                    break;
+                }
+
+                int i;
+                for (i = 0; i < 50; i++)  //check 50 times
+                {
+                    SystemClock.sleep(30);
+
+                    iicRead32Bits(addrfirstbyte, addrsecondbyte, addrthirdbyte, mBytes, 1);
+                    //if (!gpI2C1->I2CCheckRegister(BLD_CMD_STATUS_ADDR, FLASH_CMD_W_STATUS_WRITE_OK))
+                    if (mBytes[0] == (byte) 0xEE)
+                    {
+                        break;
+                    }
+                }
+                if (i == 50){
+                    ret = false;
+                    break;
+                }
+            }
+            nOffset += nLen;
+            nFlashAddr += nLen;
+
+            //m_bHaveDownloadLength += nLen;
+            //CString str = LS(IDC_GTXXX_DOWNLOAD_BIN) + ":%d%%";
+            //str.Format(str, m_bHaveDownloadLength * 100 / (m_nBinFileLen-8));
+            //FwUpdateMessage(str, MSG_FRESH);
+        } while (nOffset < p_fw_info_fw_len[index]);
+
+        if (!ret)
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    private boolean DownloadBinFile() {
+        //m_bHaveDownloadLength = 0;
+
+        Update_log2 = "[FW update]Download Bin File start......";
+        mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+
+        for (int i = 0; i < iFwCnt; i++)
+        {
+            if (p_fw_info_fw_type[i] == SS51_ISP_CODE)
+            {
+                continue;
+            }
+            if (p_fw_info_fw_type[i] == SS51_PATCH_CODE)
+            {
+                continue;
+            }
+
+            if (!DownloadSection(i))
+            {
+                Update_log2 = "[FW update]Download Bin File Fail!";
+                mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                return false;
+            }
+        }
+        for (int i = 0; i < iFwCnt; i++)
+        {
+            if (p_fw_info_fw_type[i] == SS51_PATCH_CODE)
+            {
+                if (!DownloadSection(i))
+                {
+                    Update_log2 = "[FW update]Download Patch Code Fail!";
+                    mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+                    return false;
+                }
+            }
+        }
+
+        Update_log2 = "[FW update]Download Bin File Success";
+        mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+        return true;
+    }
+
+    private boolean UpdateFinish() {
+
+        byte addrfirstbyte = (byte)0x01;
+        byte addrsecondbyte = (byte)0x01;
+        byte addrthirdbyte = (byte)0x74;
+        byte msubcommand = (byte)0x04 ;  //最高位置1。写命令4 rst IC
+        byte mdata = (byte)0x00;
+
+        msubcommand = (byte)0x11 ;  //最高位置1,写命令17 ENABLE_DIGITER_INTERFACE
+        IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata);
+
+        SystemClock.sleep(10);
+
+        msubcommand = (byte)0x2A ;  //最高位置1,写命令42 ENABLE_ESD_CHECK
+        IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata);
+
+        SystemClock.sleep(10);
+
+        msubcommand = (byte)0x04 ;  //最高位置1。写命令4 rst IC
+        if(!IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata)) {
+            Update_log = "[FW update]Reset touch IC failed!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+        Update_log2 = "[FW update]Update Finish!!";
+        mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+        return true;
+    }
+
+    private boolean GT29xxupdateProc() {
+
+        //读取文件内容:
+        /**
+         try {
+         readFile();
+         } catch (IOException e) {
+         mMessage.setText("文件不存在!");
+         // e.printStackTrace();
+         }
+         */
+
+        ActivityCompat.requestPermissions(  FirmwareUpdate.this, new String[]{android
+                .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);   //申请权限,android6.0以上系统首次使用必须添加
+
+        StringBuffer buffer = new StringBuffer();
+        StringBuilder stringBuilder = new StringBuilder("");
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+
+            try {
+
+                //String filename = Environment.getExternalStorageDirectory() + "/Download/GT9110H_2002(A2E3).BIN";
+                String filename = "GT9110H_2002(A2E3).BIN";
+                //mError.setText(filename);
+                //FileInputStream fis = new FileInputStream(filename);
+                if(bottonMode == 4)
+                {
+                    filename = edit_search.getText().toString();
+                    FileInputStream fw = new FileInputStream(filename);
+                    //fw.read(mGt9FirmwareData);
+                    fw.read(mGt293xFirmwareData);
+                    fw.close();
+                }
+                else {
+
+                    if(bottonMode == 3) {
+                        InputStream config = getResources().openRawResource(R.raw.gt9110h_config_2018110802);
+                        //InputStream config = getResources().openRawResource(R.raw.xinjian);\
+                        config.read(mConfigData);
+
+                        InputStream fis = getResources().openRawResource(R.raw.gt9110h_2002);
+                        //gt9110h_config_20181108
+                        fis.read(mGt9FirmwareData);
+
+                        config.close();
+                        fis.close();
+                    }
+                }
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+                Update_log = getResources().getString(R.string.invalidfile);
+                mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+
+                return false;
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+                Update_log = "IOException";
+                mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+
+                return false;
+            }
+
+        }
+        else{
+            Update_log = getResources().getString(R.string.nopermission);
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+
+            return false;
+        }
+
+        byte addrfirstbyte = (byte)0x01;
+        byte addrsecondbyte = (byte)0x01;
+        byte addrthirdbyte = (byte)0x74;
+        byte msubcommand = (byte)0x04 ;  //最高位置1。写命令4 rst IC
+        byte mdata = (byte)0x00;
+
+        //msubcommand = (byte)0x04 ;  //最高位置1。写命令4 rst IC
+        if(!IicWriteOneByte(addrfirstbyte, addrsecondbyte, addrthirdbyte, msubcommand, mdata)) {
+            Update_log = "[FW update]Reset touch IC failed!";
+            mHandler.sendEmptyMessage(DEBUG_MESSAGE_ERROR);
+            return false;
+        }
+
+        SystemClock.sleep(80);
+
+        if (!UpdateInit())  //NO1
+        {
+            //FwUpdateMessage(L"[FW update]Enter update mode failed", MSG_ERR);
+            UpdateFinish();
+            return false;
+        }
+
+        if (!EnterUpdateMode())  //NO2
+        {
+            //FwUpdateMessage(L"[FW update]Enter update mode failed", MSG_ERR);
+            UpdateFinish();
+            return false;
+        }
+
+        if (!UpdateIsp())  //NO3
+        {
+            //FwUpdateMessage(L"[FW update]Enter update mode failed", MSG_ERR);
+            UpdateFinish();
+            return false;
+        }
+
+        /*
+        if (m_nConfigLen > 0 && m_nConfigLen < 4096 &&  m_pbConfigBuf != NULL)
+        {
+            FwUpdateMessage(LS(IDS_UPGRADE_CONFIG_BY_ISP), MSG_PROC);
+            if (!UpdateConfigByIsp())
+            {
+                FwUpdateMessage(LS(IDS_UPGRADE_CONFIG_BY_ISP_FAILE), MSG_ERR);
+				goto FAILED_EIXT;
+            }
+        }
+        */
+
+        if (!DownloadBinFile())
+        {
+            //FwUpdateMessage(LS(IDS_GTXXX_DOWNLOAD_BIN_FAILED), MSG_ERR);
+            UpdateFinish();
+            return false;
+        }
+
+        if (!UpdateFinish())
+        {
+            //FwUpdateMessage(LS(IDS_GTXXX_RESET_FAILED), MSG_ERR);
+            return false;
+        }
+
+        return true;
+    }
+
+    //---------------------------------------------------------------------------------------------------------------------------//
+
     @Override
     protected void onDestroy() {
         super.onDestroy();

+ 1 - 1
app/src/main/res/values-en/strings.xml

@@ -107,7 +107,7 @@
     <string name="companyaddr">Address:Room 2008, Chuangxingda Business Building, No.36 Liuxian 3rd Road, Baoan District, Shenzhen</string>
     <string name="telephonenum">Telephone:186 8896 1937</string>
     <string name="emailaddr">Email:max@wingcool.cn</string>
-    <string name="version">APK Version:v3.0.2_20230509-Debug Version</string>
+    <string name="version">APK Version:v3.0.3_20230515-Debug Version</string>
 
     <!-- other -->
     <string name="app_name">WingCoolAPK</string>

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -107,7 +107,7 @@
     <string name="companyaddr">地址:深圳市宝安区留仙三路 36 号创兴达商务大厦 2008 室</string>
     <string name="telephonenum">电话:186 8896 1937</string>
     <string name="emailaddr">邮箱:max@wingcool.cn</string>
-    <string name="version">APK版本:v3.0.2_20230509-debug版本</string>
+    <string name="version">APK版本:v3.0.3_20230515-debug版本</string>
 
     <!-- other -->
     <string name="app_name">WingCoolAPK</string>