C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 1   


C51 COMPILER V9.02, COMPILATION OF MODULE TS_API
OBJECT MODULE PLACED IN .\hex\ts_api.obj
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE TS_Lib\Sources\ts_api.c OMF2 ROM(COMPACT) OPTIMIZE(9,SIZE) BROWSE DEBUG PRI
                    -NT(.\lst\ts_api.lst) OBJECT(.\hex\ts_api.obj)

line level    source

   1          #ifndef _TK_API_C_
   2          #define _TK_API_C_
   3          
   4          /*********************************************************************************************************
             -************/
   5          #include "ca51f_config.h"
   6          #include "includes\ca51f2sfr.h"
   7          #include "includes\ca51f2xsfr.h"
   8          #include "includes\gpiodef_f2.h"
   9          
  10          #include "Library\Includes\rtc.h"               
  11          #include "Library\Includes\system_clock.h"              
  12          #include "Library\includes\uart.h"
  13          #include "includes\system.h"
  14          #include "Library\includes\adc.h"
  15          #include "Library\includes\delay.h"
  16          #include <intrins.h>
  17          /*********************************************************************************************************
             -************/
  18          #include "TS_Lib\Includes\ts_configuration.h"
  19          #include "TS_Lib\Includes\ts_def.h"
  20          #include "TS_Lib\Includes\ts_api.h"
  21          #include "TS_Lib\Includes\ts_service.h" 
  22          /*********************************************************************************************************
             -************/
  23          void Debug_init(void);
  24          void Debug_ParamLoad(void);
  25          
  26          #if SUPPORT_KEY
  27          code unsigned int TS_KEY_CH_INFO_SEQ[][2]=
  28          {
  29                  KEY_SEQ
  30          };
  31          #endif
  32          #if SUPPORT_WHEEL_SLIDER
  33          code unsigned char TS_WHEEL_SLIDER_CH_SEQ[]=
  34          {
  35          #if (WHEEL_SLIDER_COUNT > 0)
  36                  WHEEL_SLIDER0_SEQ,
  37          #endif
  38          #if (WHEEL_SLIDER_COUNT > 1)
  39                  WHEEL_SLIDER1_SEQ,
  40          #endif
  41          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_SLIDER2_SEQ,
              #endif
  44          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_SLIDER3_SEQ
              #endif
  47          };
  48          code unsigned char WHEEL_SLIDER0_MAX_MIN_TAB[]={WHEEL_SLIDER0_CH_MIN_RATE};
  49          #if (WHEEL_SLIDER_COUNT > 1)
  50          code unsigned char WHEEL_SLIDER1_MAX_MIN_TAB[]={WHEEL_SLIDER1_CH_MIN_RATE};
  51          #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 2   

  52          #if (WHEEL_SLIDER_COUNT > 2)
              code unsigned char WHEEL_SLIDER2_MAX_MIN_TAB[]={WHEEL_SLIDER2_CH_MIN_RATE};
              #endif
  55          #if (WHEEL_SLIDER_COUNT > 3)
              code unsigned char WHEEL_SLIDER3_MAX_MIN_TAB[]={WHEEL_SLIDER3_CH_MIN_RATE};
              #endif
  58          code unsigned char *WHEEL_SLIDER_MIN_RATE[]=
  59          {
  60                  WHEEL_SLIDER0_MAX_MIN_TAB,
  61          #if (WHEEL_SLIDER_COUNT > 1)
  62                  WHEEL_SLIDER1_MAX_MIN_TAB,
  63          #endif
  64          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_SLIDER2_MAX_MIN_TAB,
              #endif
  67          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_SLIDER3_MAX_MIN_TAB,
              #endif
  70          };
  71          code unsigned char WHEEL_SLIDER_TOUCH_THD[]=
  72          {
  73                  WHEEL_SLIDER0_TOUCH_THD,
  74          #if (WHEEL_SLIDER_COUNT > 1)
  75                  WHEEL_SLIDER1_TOUCH_THD,
  76          #endif
  77          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_SLIDER2_TOUCH_THD,
              #endif
  80          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_SLIDER3_TOUCH_THD,
              #endif  
  83          };
  84          code unsigned char SLIDER_CH_COUNT[]=
  85          {
  86                  WHEEL_SLIDER0_CH_COUNT,
  87          #if (WHEEL_SLIDER_COUNT > 1)
  88                  WHEEL_SLIDER1_CH_COUNT,
  89          #endif
  90          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_SLIDER2_CH_COUNT,
              #endif  
  93          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_SLIDER3_CH_COUNT,
              #endif  
  96          };
  97          code unsigned char WHEEL_OR_SLIDER_DEF[]=
  98          {
  99                  WHEEL_OR_SLIDER_DEF0,
 100          #if (WHEEL_SLIDER_COUNT > 1)
 101                  WHEEL_OR_SLIDER_DEF1,
 102          #endif
 103          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_OR_SLIDER_DEF2,
              #endif  
 106          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_OR_SLIDER_DEF3,
              #endif  
 109          };
 110          code unsigned char WHEEL_SLIDER_NOISE_THD[]=
 111          {
 112                  WHEEL_SLIDER0_NOISE_THD,
 113          #if (WHEEL_SLIDER_COUNT > 1)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 3   

 114                  WHEEL_SLIDER1_NOISE_THD,
 115          #endif
 116          #if (WHEEL_SLIDER_COUNT > 2)
                      WHEEL_SLIDER2_NOISE_THD,
              #endif  
 119          #if (WHEEL_SLIDER_COUNT > 3)
                      WHEEL_SLIDER3_NOISE_THD,
              #endif  
 122          };
 123          #else
              code unsigned char TS_WHEEL_SLIDER_CH_SEQ[]={0};
              code unsigned char *WHEEL_SLIDER_MIN_RATE[]={0};
              code unsigned char WHEEL_SLIDER_TOUCH_THD[]={0};
              code unsigned char SLIDER_CH_COUNT[]={0};
              code unsigned char WHEEL_OR_SLIDER_DEF[]={0};
              code unsigned char WHEEL_SLIDER_NOISE_THD[]={0};
              #endif  
 131          #if SUPPORT_KEY 
 132          code TYPE_SN MASK_TAB[]=
 133          {
 134                  0x000001,
 135          #if (KEY_CH_COUNT > 1)
 136                  0x000002,
 137          #endif
 138          #if (KEY_CH_COUNT > 2)
                      0x000004,
              #endif
 141          #if (KEY_CH_COUNT > 3)
                      0x000008,
              #endif
 144          #if (KEY_CH_COUNT > 4)
                      0x000010,
              #endif
 147          #if (KEY_CH_COUNT > 5)
                      0x000020,
              #endif
 150          #if (KEY_CH_COUNT > 6)
                      0x000040,
              #endif
 153          #if (KEY_CH_COUNT > 7)
                      0x000080,
              #endif
 156          #if (KEY_CH_COUNT > 8)
                      0x000100,
              #endif
 159          #if (KEY_CH_COUNT > 9)
                      0x000200,
              #endif
 162          #if (KEY_CH_COUNT > 10)
                      0x000400,
              #endif
 165          #if (KEY_CH_COUNT > 11)
                      0x000800,
              #endif
 168          #if (KEY_CH_COUNT > 12)
                      0x001000,
              #endif
 171          #if (KEY_CH_COUNT > 13)
                      0x002000,
              #endif
 174          #if (KEY_CH_COUNT > 14)
                      0x004000,
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 4   

              #endif
 177          #if (KEY_CH_COUNT > 15)
                      0x008000,
              #endif
 180          #if (KEY_CH_COUNT > 16)
                      0x010000,
              #endif
 183          #if (KEY_CH_COUNT > 17)
                      0x020000,
              #endif
 186          #if (KEY_CH_COUNT > 18)
                      0x040000,
              #endif
 189          #if (KEY_CH_COUNT > 19)
                      0x080000,
              #endif
 192          #if (KEY_CH_COUNT > 20)
                      0x100000,
              #endif
 195          #if (KEY_CH_COUNT > 21)
                      0x200000,
              #endif
 198          #if (KEY_CH_COUNT > 22)
                      0x400000,
              #endif
 201          #if (KEY_CH_COUNT > 23)
                      0x800000,
              #endif
 204          
 205          };
 206          code unsigned char AREA_CONFIRM_TIME_TAB[]=
 207          {
 208                  FINGER_TOUCH_CONFIRM_TIME,
 209                  AREA_PNOISE_PLUS_CONFIRM_TIME,
 210                  AREA_PNOISE_CONFIRM_TIME,
 211                  AREA_NNOISE_CONFIRM_TIME,
 212                  AREA_OVERLOW_CONFIRM_TIME,
 213          };
 214          #else
              code unsigned char AREA_CONFIRM_TIME_TAB[1]={0};
              code unsigned long int MASK_TAB[1]={0};
              #endif
 218          void TS_MS_ISR (void)
 219          {
 220   1              static unsigned char xdata ms_cnt = 0;
 221   1              unsigned char i;
 222   1       
 223   1              ms_cnt++;
 224   1              if(ms_cnt >= 4)
 225   1              {
 226   2                      ms_cnt = 0;
 227   2                      for(i = 0; i < TS_Cnt; i++)
 228   2                      {
 229   3                              if(TS_AreaConfirmTimer[i])
 230   3                              {
 231   4                                      TS_AreaConfirmTimer[i]--;
 232   4                              }
 233   3                      }
 234   2      #if SUPPORT_WHEEL_SLIDER        
 235   2                      for(i = 0; i < WHEEL_SLIDER_COUNT; i++)
 236   2                      {
 237   3                              if(TSWheelSlider_TouchConfirmTimer[i])
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 5   

 238   3                              {
 239   4                                      TSWheelSlider_TouchConfirmTimer[i]--;
 240   4                              }
 241   3                      }
 242   2      #endif
 243   2      #if SUPPORT_KEY
 244   2      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                              if(PanalCoverJudgeTimer) PanalCoverJudgeTimer--;
              #endif
 247   2      #endif
 248   2      #if SUPPORT_KEY
 249   2      #if ANTI_SPEAKER_EN
                              if(RefChDataTimer) RefChDataTimer--;
              #endif
 252   2      #endif
 253   2              }       
 254   1      }
 255          void TS_HS_ISR (void)
 256          {
 257   1      #if SUPPORT_KEY
 258   1      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 259   1              unsigned char i;
 260   1      #endif
 261   1      #elif SUPPORT_WHEEL_SLIDER
              #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
                      unsigned char i;
              #endif
              #endif
 266   1              TS_HalfSecCnt++;
 267   1      #if SUPPORT_TOUCH_SLEEP_MODE
                      if(TS_SleepMode)
                      {
                              return;
                      }
              #endif
 273   1      #if SUPPORT_KEY
 274   1      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 275   1              for(i = 0; i < KEY_CH_COUNT; i++)
 276   1              {
 277   2                      if(TSKey_LongTouchLimitTimer[i])
 278   2                      {
 279   3                              TSKey_LongTouchLimitTimer[i]--;
 280   3                      }
 281   2              }               
 282   1      #endif
 283   1      #endif
 284   1      #if SUPPORT_WHEEL_SLIDER        
 285   1      #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
 286   1              for(i = 0; i < WHEEL_SLIDER_COUNT; i++)
 287   1              {
 288   2                      if(TSWheelSlider_LongTouchLimitTimer[i])
 289   2                      {
 290   3                              TSWheelSlider_LongTouchLimitTimer[i]--;
 291   3                      }
 292   2              }
 293   1      #endif
 294   1      #endif
 295   1              if(EnterStopScanTimer)
 296   1              {
 297   2                      EnterStopScanTimer--;
 298   2              }       
 299   1      }
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 6   

 300          void TS_ISR (void)
 301          {       
 302   1              unsigned char index_copy,i;
 303   1              WORD_UNION TS_Data[6];
 304   1              if(TLFLG & (TLERR|TLKOV|TLLOV))
 305   1              {
 306   2                      TLFLG |= TLERR|TLKOV|TLLOV;
 307   2              }
 308   1              index_copy = INDEX;
 309   1              for(i = 0; i < 6; i++)
 310   1              {
 311   2                      if(TKIF & (1<<i))
 312   2                      {
 313   3                              TKIF = (1<<i);  
 314   3                              INDEX = i;
 315   3                              TS_Data[i].bVal[0] = TKMSH;
 316   3                              TS_Data[i].bVal[1] = TKMSL;
 317   3                      }
 318   2              }
 319   1              for(i = 0; i < 6; i++)
 320   1              {
 321   2      #if (TS_ACQ_TIMES == 1)
 322   2                      TS_RawData[TS_Index+i] = TS_Data[i].wVal;
 323   2      #else
                              TS_DataSum[TS_Index+i] += TS_Data[i].wVal;      
              #endif          
 326   2                      if(TS_Index+i == TS_Cnt)
 327   2                      {                       
 328   3                              break;
 329   3                      }       
 330   2              }
 331   1              if(TS_Index+6 > TS_Cnt)
 332   1              {
 333   2      #if (TS_ACQ_TIMES == 1)
 334   2                      TS_CycleScanDoneFlag = 1;       
 335   2      #else
                              TS_Acq_Counter++;
                              if(TS_Acq_Counter >= TS_ACQ_TIMES)
                              {
                                      for(i = 0; i < TS_Cnt+1; i++)
                                      {
                                              TS_RawData[i] = TS_DataSum[i];
                                              TS_DataSum[i] = 0;
                                      }
                                      TS_CycleScanDoneFlag = 1;               
                                      TS_Acq_Counter = 0;
                              }       
              #endif          
 348   2                      TS_Index = 0;
 349   2              }
 350   1              else 
 351   1              {
 352   2                      TS_Index += 6;
 353   2              }
 354   1              TS_ScanStart(); 
 355   1              if(TS_HalfSecCnt) TS_HalfSecCnt--;
 356   1              if(MainLoopCnt1 != MainLoopCnt2)
 357   1              {
 358   2                      MainLoopCnt2 = MainLoopCnt1;
 359   2                      WDFLG = 0xA5;
 360   2              }
 361   1              INDEX = index_copy;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 7   

 362   1      }
 363          void TS_DataFiltering(void)
 364          {
 365   1              unsigned char i;
 366   1      #if (FILTER_COUNT > 1)
 367   1              unsigned char j;
 368   1              unsigned int DataSum,DataMax,DataMin;
 369   1      #endif
 370   1              for(i = 0; i < TS_Cnt+1; i++)
 371   1              {
 372   2      #if (FILTER_COUNT == 1)
                              TS_PostData[i] = TS_RawData[i];
              #else
 375   2                      TS_FilterPosIdx[i]++;
 376   2                      if(TS_FilterPosIdx[i] >= FILTER_COUNT) 
 377   2                      {
 378   3                              TS_FilterPosIdx[i] = 0;
 379   3                      }
 380   2                      INT3EN = 0;
 381   2                      TS_FilterBuf[i][TS_FilterPosIdx[i]] = TS_RawData[i];
 382   2                      INT3EN = 1; 
 383   2                      
 384   2                      DataSum = 0;
 385   2                      DataMax = 0;
 386   2                      DataMin = 0xFFFF;
 387   2                      for(j = 0; j < FILTER_COUNT; j++)
 388   2                      {
 389   3                              DataSum += TS_FilterBuf[i][j];
 390   3      #if (FILTER_COUNT > 2)
 391   3                              if(TS_FilterBuf[i][j] > DataMax)
 392   3                              {
 393   4                                      DataMax = TS_FilterBuf[i][j];
 394   4                              }
 395   3                              if(TS_FilterBuf[i][j] < DataMin)
 396   3                              {
 397   4                                      DataMin = TS_FilterBuf[i][j];
 398   4                              }
 399   3      #endif
 400   3                      }
 401   2      #if (FILTER_COUNT == 2)
                              TS_PostData[i] = (DataSum)/(FILTER_COUNT);      
              #else
 404   2                      TS_PostData[i] = (DataSum - DataMax - DataMin)/(FILTER_COUNT-2);        
 405   2      #endif
 406   2      #endif          
 407   2              }               
 408   1      }
 409          #if SUPPORT_KEY
 410          #if ANTI_SPEAKER_EN
              bit TS_RefChAbnormalJudge(void)
              {
                      unsigned int ref_value,crt_value,delta;
                      
                      if(RefChDataBufIdx == (REF_CH_DATA_BUF_SIZE-1)) 
                      {
                              ref_value = RefChDataBuf[0];
                      }
                      else
                      {
                              ref_value = RefChDataBuf[RefChDataBufIdx + 1];
                      }
                      crt_value = TS_PostData[OPENED_TS_COUNT];
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 8   

                      if(ref_value > crt_value)
                      {
                              delta = ref_value - crt_value;
                      }
                      else
                      {
                              delta = crt_value - ref_value;
                      }
                      if(delta >= REF_CH_ABNORMAL_THD)                        
                      {
                              return 1;
                      }
                      else
                      {
                              return 0;
                      }
              }
              void TS_RefChCheck(void)
              {
                      if(!RefChDataTimer)
                      {
                              RefChDataTimer = 3;
                              RefChDataBufIdx++;
                              if(RefChDataBufIdx >= REF_CH_DATA_BUF_SIZE)
                              {
                                      RefChDataBufIdx = 0;
                              }
                              RefChDataBuf[RefChDataBufIdx] = TS_PostData[OPENED_TS_COUNT];
                      }       
              }
              #endif
 455          #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
              unsigned char GetSensAutoTrimRefCH(unsigned int *baseLine)
              {
                      unsigned char i,idx;
                      unsigned int min = 0xffff;
                      for(i = 0; i < TS_Cnt; i++)
                      {
                              if(baseLine[i] < min)
                              {
                                      min = baseLine[i];
                                      idx = i;
                              }
                      }
                      return idx;
              }
              #endif
 471          #endif
 472          void TS_RunInit(void)
 473          {
 474   1              unsigned char i,j;
 475   1              static unsigned char TS_ScanTimes=0;
 476   1      #if (POWER_ON_WAIT_TK_STABLE_EN)
                      static unsigned char TS_Init_Step_Sub;
                      int TS_Noise_Threshold;
              #endif
 480   1              if(TS_Init_Step == 0)
 481   1              {
 482   2      #if (TS_ACQ_TIMES > 1)
                              for(i = 0; i < TS_Cnt; i++)
                              {       
                                      TS_DataSum[i] = 0;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 9   

                              }
                              TS_Acq_Counter = 0;
              #endif
 489   2                      TS_CycleScanDoneFlag = 0;
 490   2                      TS_HalfSecCnt = 0;
 491   2                      TS_Index = 0;
 492   2                      TS_ScanStart(); 
 493   2      #if POWER_ON_WAIT_TK_STABLE_EN
                              TS_Init_Step = 1;               
                              TS_Init_Step_Sub = 0;
                              TS_ScanTimes = 5;
              #else
 498   2                      TS_Init_Step = 2;
 499   2                      TS_ScanTimes = 50;                      
 500   2      #endif
 501   2              }
 502   1      #if POWER_ON_WAIT_TK_STABLE_EN
                      else if(TS_Init_Step == 1)
                      {
                              if(TS_CycleScanDoneFlag)
                              {
                                      TS_CycleScanDoneFlag = 0;
                                      MainLoopCnt1 = MainLoopCnt2 + 1;
                                      if(TS_Init_Step_Sub == 0)
                                      {
                                              if(--TS_ScanTimes)
                                              {                               
                                                      return;
                                              }
                                              for(i = 0; i < TS_Cnt+1; i++)
                                              {
                                                      TS_PostData[i] = TS_RawData[i];
                                              }
                                              TS_Init_Step_Sub = 1;
                                              TS_AreaConfirmTimer[0] = 40;
                                      }                       
                                      else if(TS_Init_Step_Sub == 1)
                                      {
                                              if(!TS_AreaConfirmTimer[0])
                                              {
                                                      int delta;
                                                      for(i = 0; i < TS_Cnt; i++)
                                                      {
                                                              delta = (int)TS_PostData[i] - (int)TS_RawData[i];
                                                      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
                                                              if(i < KEY_CH_COUNT)
                                                              {
                                                                      TS_Noise_Threshold = (int)(TS_KEY_CH_INFO_SEQ[i][1]/2);
                                                              }
                                                              else
                                                              {
                                                                      TS_Noise_Threshold = (int)(WHEEL_SLIDER0_TOUCH_THD/2);
                                                              }
                                                      #elif SUPPORT_KEY
                                                              TS_Noise_Threshold = (int)(TS_KEY_CH_INFO_SEQ[i][1]/2);                         
                                                      #elif SUPPORT_WHEEL_SLIDER
                                                              TS_Noise_Threshold = (int)(WHEEL_SLIDER0_TOUCH_THD/2);
                                                      #endif
                                                              if((delta > TS_Noise_Threshold) || (delta < -TS_Noise_Threshold))
                                                              {
                                                                      TS_Init_Step_Sub = 0;
                                                                      return;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 10  

                                                              }
                                                      }                       
                                                      TS_Init_Step = 2;
                                                      TS_ScanTimes = 10;      
                                              }
                                      }
                              }
                      }
              #endif
 557   1              else if(TS_Init_Step == 2)
 558   1              {
 559   2                      if(TS_CycleScanDoneFlag)
 560   2                      {
 561   3                              TS_CycleScanDoneFlag = 0;
 562   3                              if(--TS_ScanTimes)
 563   3                              {                               
 564   4                                      return;
 565   4                              }
 566   3                              for(i = 0; i < TS_Cnt+1; i++)
 567   3                              {       
 568   4                                      for(j = 0; j < FILTER_COUNT; j++)
 569   4                                      {
 570   5                                              TS_FilterBuf[i][j] = TS_RawData[i];
 571   5                                      }
 572   4                                      TS_FilterPosIdx[i] = 0;
 573   4                                      
 574   4                                      if(i == TS_Cnt) break;
 575   4                                      TS_BaseLineData[i] = TS_RawData[i];                     
 576   4                                      TS_FirstAreaData[i] = TS_RawData[i]; 
 577   4      #if SUPPORT_KEY
 578   4      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                              TS_PostData2[i] = TS_RawData[i];
              #endif                                  
 581   4      #if TK_BASE_TRIM_WHILE_KEY_PRESSED
 582   4                                      RefChDataBak[i] = TS_RawData[OPENED_TS_COUNT];
 583   4                                      TS_BaseLineDataBak[i] = TS_BaseLineData[i];
 584   4      #endif                                  
 585   4      #endif                          
 586   4      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
 587   4                                      if(i < KEY_CH_COUNT)
 588   4                                      {
 589   5                                              TSKey_FingerThd[i] = TS_KEY_CH_INFO_SEQ[i][1];
 590   5                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);
 591   5                                      }
 592   4                                      else
 593   4                                      {
 594   5                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
 595   5                                      }
 596   4      #elif SUPPORT_KEY
                                              TSKey_FingerThd[i] = TS_KEY_CH_INFO_SEQ[i][1];
                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);                          
              #elif SUPPORT_WHEEL_SLIDER
                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
              #endif
 602   4                              }       
 603   3      #if SUPPORT_KEY
 604   3      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                      SensAutoTrimRefCH = GetSensAutoTrimRefCH(TS_BaseLineData);
              #endif
 607   3      #if ANTI_SPEAKER_EN
                                      for(i = 0; i < REF_CH_DATA_BUF_SIZE; i++)
                                      {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 11  

                                              RefChDataBuf[i] = TS_PostData[OPENED_TS_COUNT];
                                      }
                                      RefChDataBufIdx = 0;
              #endif          
 614   3      #endif                  
 615   3      #if (DEBUG)
                                      Debug_ParamLoad();
              #endif          
 618   3                              TS_State = TS_DEAL;     
 619   3                      }
 620   2              }
 621   1      }
 622          #if SUPPORT_KEY
 623          #if SUPPORT_ANTI_WATER_FUNCTION
              unsigned char AntiWaterModeGetMaxDeltaCh(void)
              {
                      unsigned char i;
                      unsigned long int CalcTemp1;
                      unsigned int CalcTemp2,CalcTemp3;
                      int Delta;
                      int max_delta;
                      char max_index;
                      max_delta = 0;
                      for(i = 0; i < KEY_CH_COUNT; i++)
                      {
                              if(i == 0)
                              {
                                      Delta = (int)TS_BaseLineData[i] - (int)TS_PostData[i];
                              }
                              else
                              {
                                      CalcTemp1 =     (unsigned long int)TS_PostData[i] * (unsigned long int)TS_BaseLineData[0];
                                      CalcTemp2 =     (unsigned int)(CalcTemp1/TS_BaseLineData[i]);
                                      CalcTemp3 =     TS_PostData[i] + TS_BaseLineData[0] - CalcTemp2;
                                      CalcTemp2 =     (unsigned int)(CalcTemp1/CalcTemp3);    
                                      Delta           =       (int)TS_BaseLineData[0] - (int)CalcTemp2;                                               
                              }
                              if(max_delta < Delta)
                              {
                                      max_delta = Delta;
                                      max_index = i;
                              }
                      }
                      return max_index;
              }
              #endif
 656          #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
              int GetTouchDiffer(unsigned int touchData,unsigned int touchBase,unsigned int baseRef)
              {
                      unsigned long int CalcTemp1;
                      unsigned int CalcTemp2,CalcTemp3;
                      int Delta;
              
                      CalcTemp1 =     (unsigned long int)touchData * (unsigned long int)baseRef;
                      CalcTemp2 =     (unsigned int)(CalcTemp1/touchBase);
                      CalcTemp3 =     touchData + baseRef - CalcTemp2;
                      CalcTemp2 =     (unsigned int)(CalcTemp1/CalcTemp3);    
                      Delta           =       (int)baseRef - (int)CalcTemp2;                                          
              
                      return Delta;
              }
              #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 12  

 672          void TSKey_DataDeal(void)
 673          {
 674   1              unsigned char i;
 675   1              unsigned char  TouchArea,NowArea;               
 676   1      
 677   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      unsigned char PanalToggleCount = 0;
              #endif
 680   1              for(i = 0; i < KEY_CH_COUNT; i++)
 681   1              {       
 682   2      #if SUPPORT_ANTI_WATER_FUNCTION
                              if(KeyPressedFlag)
                              {
                                      if(PressedKeyIndex != i)
                                      {
              #if TK_BASE_TRIM_WHILE_KEY_PRESSED                                      
                                              TS_BaseLineData[i] = ((unsigned long int)TS_BaseLineDataBak[i]*TS_PostData[OPENED_TS_COUNT])/RefChData
             -Bak[i];
              #endif          
                                              TS_FirstAreaData[i] = TS_BaseLineData[i];
                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
                                              continue;               
                                      }
                              }
              #endif
 696   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              if(SensAutoTrimRefCH == i)
                              {
                                      TS_PostData2[i] = TS_PostData[i];
                              }
                              else
                              {
                                      TS_PostData2[i] = (int)TS_BaseLineData[i] - GetTouchDiffer(TS_PostData[i],TS_BaseLineData[i],TS_BaseLin
             -eData[SensAutoTrimRefCH]);
                              }
              #endif
 706   2                      TouchArea = TS_GetDataArea(i,TS_FirstAreaData[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[
             -i]));
 707   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              NowArea   = TS_GetDataArea(i,TS_PostData2[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[i]))
             -;
              #else
 710   2                      NowArea   = TS_GetDataArea(i,TS_PostData[i],TSKey_NoiseThreshold[i],(bit)(PreKeysFlagSN & MASK_TAB[i]));
 711   2      #endif
 712   2                      
 713   2                      if((NowArea != AREA_PNOISE)&&(NowArea != AREA_NNOISE))
 714   2                      {
 715   3                              TS_StableFlag = 0;              
 716   3                      }
 717   2      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                              if((NowArea == AREA_PNOISE_PLUS) || (NowArea == AREA_FINGER_TOUCH))
                              {
                                      PanalToggleCount++;
                              }
              #endif
 723   2                      if(TouchArea == AREA_FINGER_TOUCH)
 724   2                      {
 725   3                              if(NowArea == AREA_FINGER_TOUCH)
 726   3                              {
 727   4                                      if(!(PreKeysFlagSN & MASK_TAB[i]))
 728   4                                      {
 729   5                                              if(!TS_AreaConfirmTimer[i])
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 13  

 730   5                                              {               
 731   6                                                      PreKeysFlagSN |= MASK_TAB[i];           
 732   6      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 733   6                                                      TSKey_LongTouchLimitTimer[i] = FINGER_LONG_TOUCH_TIME_LIMIT;
 734   6      #endif
 735   6                                                      TS_AreaConfirmTimer[i] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;     
 736   6                                              }
 737   5                                      }
 738   4                                      else
 739   4                                      {       
 740   5      #if SUPPORT_ANTI_WATER_FUNCTION         
                                                      if(i != AntiWaterModeGetMaxDeltaCh())
                                                      {
                                                              goto ANTI_WATER_MODE_KEY_RELEASE;
                                                      }
              #endif
 746   5      #if TK_BASE_TRIM_WHILE_KEY_PRESSED                                      
 747   5                                              TS_BaseLineData[i] = ((unsigned long int)TS_BaseLineDataBak[i]*TS_PostData[OPENED_TS_COUNT])/RefChDat
             -aBak[i];
 748   5      #endif          
 749   5                                              TS_AreaConfirmTimer[i] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;
 750   5      #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
 751   5                                              if(!TSKey_LongTouchLimitTimer[i])
 752   5                                              {
 753   6                                                      PreKeysFlagSN &= ~MASK_TAB[i];
 754   6                                                      TS_FirstAreaData[i] = TS_PostData[i];
 755   6                                                      TS_BaseLineData[i]      = TS_PostData[i];
 756   6                                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
 757   6      #if SUPPORT_ANTI_WATER_FUNCTION
                                                              KeyPressedFlag = 0;
                                                              break;
              #endif                                          
 761   6                                              }                                                       
 762   5      #endif                                  
 763   5                                      }                               
 764   4                              }
 765   3                              else
 766   3                              {
 767   4                                      if(PreKeysFlagSN & MASK_TAB[i]) 
 768   4                                      {
 769   5                                              if(!TS_AreaConfirmTimer[i])
 770   5                                              {
 771   6      #if SUPPORT_ANTI_WATER_FUNCTION
              ANTI_WATER_MODE_KEY_RELEASE:                                            
                                                              KeyPressedFlag = 0;
              #endif
 775   6                                                      PreKeysFlagSN &= ~MASK_TAB[i];
 776   6      
 777   6                                                      TS_FirstAreaData[i] = TS_BaseLineData[i];
 778   6                                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);
 779   6      #if SUPPORT_ANTI_WATER_FUNCTION
                                                              break;
              #endif
 782   6                                              }                                       
 783   5                                      }                       
 784   4                                      else
 785   4                                      {
 786   5      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                                      TS_FirstAreaData[i] = TS_PostData2[i];
              #else
 789   5                                              TS_FirstAreaData[i] = TS_PostData[i];
 790   5      #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 14  

 791   5                                              TS_AreaConfirmTimerSet(i,NowArea);
 792   5                                      }       
 793   4                              }       
 794   3                              continue;                                               
 795   3                      }       
 796   2                      else
 797   2                      {
 798   3                              if(NowArea == AREA_FINGER_TOUCH)
 799   3                              {
 800   4      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                              TS_FirstAreaData[i] = TS_PostData2[i];
              #else
 803   4                                      TS_FirstAreaData[i] = TS_PostData[i];
 804   4      #endif
 805   4                                      TS_AreaConfirmTimerSet(i,AREA_FINGER_TOUCH);
 806   4                                      continue;               
 807   4                              }       
 808   3                              else                    
 809   3                              {
 810   4                                      if(PreKeysFlagSN & MASK_TAB[i]) 
 811   4                                      {
 812   5                                              PreKeysFlagSN &= ~MASK_TAB[i];
 813   5                                              TS_FirstAreaData[i] = TS_BaseLineData[i];
 814   5                                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);                          
 815   5                                      }
 816   4                              }
 817   3                      }
 818   2                      if(PreKeysFlagSN != 0) 
 819   2                      {
 820   3                              TS_FirstAreaData[i] = TS_BaseLineData[i];
 821   3                              TS_AreaConfirmTimerSet(i,AREA_PNOISE);          
 822   3                              continue;                       
 823   3                      }
 824   2      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                              if(TS_AreaDeviateDetection(TS_FirstAreaData[i],TS_PostData2[i],TSKey_NoiseThreshold[i]))           //ÅÐ¶ÏÆ«²îÊÇ
             -·ñÔÚÔÊÐí·¶Î§ÄÚ
              #else
 827   2                      if(TS_AreaDeviateDetection(TS_FirstAreaData[i],TS_PostData[i],TSKey_NoiseThreshold[i]))    //ÅÐ¶ÏÆ«²îÊÇ·
             -ñÔÚÔÊÐí·¶Î§ÄÚ
 828   2      #endif
 829   2                      {       
 830   3                              if(!TS_AreaConfirmTimer[i])
 831   3                              {
 832   4                                      TS_FirstAreaData[i] = TS_PostData[i];
 833   4                                      TS_BaseLineData[i]      = TS_PostData[i];
 834   4      #if TK_BASE_TRIM_WHILE_KEY_PRESSED
 835   4                                      RefChDataBak[i] = TS_PostData[OPENED_TS_COUNT];
 836   4                                      TS_BaseLineDataBak[i] = TS_BaseLineData[i];
 837   4      #endif                          
 838   4                                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);  
 839   4                              }       
 840   3                      }
 841   2                      else
 842   2                      {
 843   3      #if TOUCH_SENSITIVITY_AUTO_BALANCE_EN
                                      TS_FirstAreaData[i] = TS_PostData2[i];  
              #else
 846   3                              TS_FirstAreaData[i] = TS_PostData[i];   
 847   3      #endif
 848   3                              TS_AreaConfirmTimerSet(i,NowArea);              
 849   3                      }
 850   2              }               
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 15  

 851   1      #if SUPPORT_ANTI_WATER_FUNCTION
                      if(KeysFlagSN == 0)
                      {
                              if(PreKeysFlagSN != 0)
                              {
                                      PressedKeyIndex = AntiWaterModeGetMaxDeltaCh();
                                      PreKeysFlagSN = MASK_TAB[PressedKeyIndex];
              #if (FINGER_LONG_TOUCH_TIME_LIMIT > 0)
                                      TSKey_LongTouchLimitTimer[PressedKeyIndex] = FINGER_LONG_TOUCH_TIME_LIMIT;
              #endif
                                      TS_AreaConfirmTimer[PressedKeyIndex] = FINGER_TOUCH_RELEASE_CONFIRM_TIME;       
                                      KeyPressedFlag = 1;
                              }
                      }
              #endif
 866   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      if(!PanalCoverJudgeFlag)
                      {
                              if(PreKeysFlagSN != 0)
                              {
                                      if(KeysFlagSN == 0)
                                      {
                                              PanalCoverJudgeFlag = 1;
                                              PanalCoverJudgeTimer = PANAL_COVER_JUDGE_TIME;          
                                      }
                                      else
                                      {
                                      #if ANTI_SPEAKER_EN
                                              if((PanalToggleCount >= JUDGE_TK_NUM)||(TS_RefChAbnormalJudge()))
                                      #else
                                              if((PanalToggleCount >= JUDGE_TK_NUM))
                                      #endif
                                              {
                                                      PreKeysFlagSN = 0;
                                                      PanalCoverJudgeFlag = 0;
                                                      TS_BaseLineForceUpdate();
                                              }
                                              KeysFlagSN  = PreKeysFlagSN;
                                      }
                              }
                              else
                              {
                                      KeysFlagSN  = PreKeysFlagSN;
                              }
                      }
                      else
                      {
                              if(!PanalCoverJudgeTimer)
                              {
                                      PanalCoverJudgeFlag = 0;
                                      KeysFlagSN = PreKeysFlagSN;
                              }
                              else
                              {
                              #if ANTI_SPEAKER_EN
                                      if((PanalToggleCount >= JUDGE_TK_NUM)||(TS_RefChAbnormalJudge()))
                              #else
                                      if((PanalToggleCount >= JUDGE_TK_NUM))
                              #endif          
                                      {
                                              PreKeysFlagSN = 0;
                                              PanalCoverJudgeFlag = 0;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 16  

                                              TS_BaseLineForceUpdate();
                                      }                       
                              }
                      }
              #else
 918   1      #if ANTI_SPEAKER_EN
                      if((PreKeysFlagSN != 0)&&(KeysFlagSN == 0))
                      {
                              if(TS_RefChAbnormalJudge())
                              {
                                      PreKeysFlagSN = 0;
                                      
              #if SUPPORT_ANTI_WATER_FUNCTION
                                      KeyPressedFlag = 0;
              #endif
                                      TS_BaseLineForceUpdate();               
                              }
                      }
              #endif
 932   1              KeysFlagSN  = PreKeysFlagSN;
 933   1      
 934   1      #endif
 935   1              if(KeysFlagSN != 0) 
 936   1              {
 937   2                      ActiveTouchType = 1;
 938   2              }
 939   1              else
 940   1              {
 941   2                      ActiveTouchType = 0;
 942   2              }
 943   1      }
 944          #endif
 945          #if SUPPORT_WHEEL_SLIDER
 946          void TS_WheelSliderDeal(void)
 947          {
 948   1              unsigned char num,i;
 949   1              unsigned int   Delta,Position;
 950   1              bit WheelSliderTogFlag = 0;
 951   1              TS_BaseCh = KEY_CH_COUNT; 
 952   1              if(!W_S_RefChSet)
 953   1              {
 954   2                      W_S_RefChSet = 1;               
 955   2                      SetWheelSliderRefCh(WHEEL_SLIDER_COUNT,KEY_CH_COUNT);
 956   2              }
 957   1              TS_BaseCh = KEY_CH_COUNT; 
 958   1              for(num = 0; num < WHEEL_SLIDER_COUNT; num++)
 959   1              {
 960   2      #if PRINT_WHEEL_SLIDER_DATA_EN
                              if(num == PRINT_WHEEL_SLIDER_NUM)
                              {
                                      TK_Debug_UartPutChar(0xaa);
                                      for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
                                      {                                               
                                              if(TS_BaseLineData[i] > TS_PostData[i])
                                              {
                                                      Delta = (int)TS_BaseLineData[i] - (int)TS_PostData[i];  
                                              }
                                              else
                                              {
                                                      Delta = 0;
                                              }                                               
                                              TK_Debug_UartPutChar(i);
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 17  

                                              TK_Debug_UartPutChar(TS_PostData[i]>>8);
                                              TK_Debug_UartPutChar(TS_PostData[i]);                   
                                              TK_Debug_UartPutChar(TS_BaseLineData[i]>>8);
                                              TK_Debug_UartPutChar(TS_BaseLineData[i]);       
                                              TK_Debug_UartPutChar(Delta>>8); 
                                              TK_Debug_UartPutChar(Delta);                                                            
                                      }                               
                              }
              #endif
 984   2                      if((ActiveWheelSliderNum != num) && (ActiveWheelSliderNum != 0xFF))
 985   2                      {
 986   3                              TS_BaseCh += SLIDER_CH_COUNT[num];
 987   3                              continue;
 988   3                      }
 989   2                      Position = WheelSliderTouchJudge(num);
 990   2                      if(Position != -1)
 991   2                      {
 992   3                              TS_StableFlag = 0;
 993   3                      }
 994   2                      if(WheelSliderState[num] == WHEEL_SLIDER_NO_TOUCH)
 995   2                      {
 996   3                              if(!WheelSliderTouchFlag[num])
 997   3                              {
 998   4                                      if(Position != -1)
 999   4                                      {
1000   5                                              WheelSliderTouchFlag[num] = 1;  
1001   5                                              TSWheelSlider_TouchConfirmTimer[num] = WHEEL_SLIDER_TOUCH_CONFIRM_TIME;                         
1002   5                                      }
1003   4                                      else
1004   4                                      {
1005   5                                              for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
1006   5                                              {                                               
1007   6                                                      if(TS_FirstAreaData[i] > TS_PostData[i]) 
1008   6                                                      {
1009   7                                                              Delta   = TS_FirstAreaData[i] - TS_PostData[i];
1010   7                                                      }
1011   6                                                      else
1012   6                                                      {
1013   7                                                              Delta   = TS_PostData[i] - TS_FirstAreaData[i];
1014   7                                                      }                                       
1015   6                                                      if(Delta <= WHEEL_SLIDER_NOISE_THD[num]) 
1016   6                                                      {
1017   7                                                              if(!TS_AreaConfirmTimer[i])
1018   7                                                              {
1019   8                                                                      TS_FirstAreaData[i] = TS_PostData[i];
1020   8                                                                      TS_BaseLineData[i]      = TS_PostData[i];
1021   8                                                                      TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
1022   8                                                              }                                                       
1023   7                                                      }
1024   6                                                      else
1025   6                                                      {
1026   7                                                              TS_FirstAreaData[i] = TS_PostData[i];
1027   7                                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
1028   7                                                      }
1029   6                                              }
1030   5                                      }                       
1031   4                              }       
1032   3                              else
1033   3                              {       
1034   4                                      if(Position != -1)
1035   4                                      {
1036   5                                              if(!TSWheelSlider_TouchConfirmTimer[num])
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 18  

1037   5                                              {
1038   6                                                      WheelSliderState[num] = WHEEL_SLIDER_TOUCH;     
1039   6                                                      ActiveWheelSliderNum = num;
1040   6      #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
1041   6                                                      TSWheelSlider_LongTouchLimitTimer[num] = WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT;
1042   6      #endif
1043   6                                              }       
1044   5                                      }
1045   4                                      else
1046   4                                      {
1047   5                                              WheelSliderTouchFlag[num] = 0;
1048   5                                              for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
1049   5                                              {
1050   6                                                      TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
1051   6                                              }
1052   5                                      }
1053   4                              }                               
1054   3                      }
1055   2                      else if(WheelSliderState[num] == WHEEL_SLIDER_TOUCH)
1056   2                      {               
1057   3      #if (WHEEL_SLIDER_LONG_TOUCH_TIME_LIMIT > 0)
1058   3                              if(!TSWheelSlider_LongTouchLimitTimer[num])
1059   3                              {
1060   4                                      for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
1061   4                                      {
1062   5                                              TS_FirstAreaData[i] = TS_PostData[i];
1063   5                                              TS_BaseLineData[i]      = TS_PostData[i];
1064   5                                      }
1065   4                                      WheelSliderTouchFlag[num] = 0;
1066   4                                      goto WHEEL_SLIDER_RELEASE;
1067   4                              }
1068   3      #endif
1069   3                              if(WheelSliderTouchFlag[num])
1070   3                              {
1071   4                                      if(Position == -1)      
1072   4                                      {
1073   5                                              WheelSliderTouchFlag[num] = 0;
1074   5                                              TSWheelSlider_TouchConfirmTimer[num] = WHEEL_SLIDER_TOUCH_RELEASE_CONFIRM_TIME;         
1075   5                                      }
1076   4                              }
1077   3                              else                                             
1078   3                              {
1079   4                                      if(Position == -1)      
1080   4                                      {
1081   5                                              if(!TSWheelSlider_TouchConfirmTimer[num])
1082   5                                              {
1083   6      WHEEL_SLIDER_RELEASE:
1084   6                                                      WheelSliderState[num] = WHEEL_SLIDER_NO_TOUCH;  
1085   6                                                      WheelSliderCapRateFilter[num] = 0;
1086   6                                                      WheelSliderPosition[num] = -1;
1087   6                                                      ActiveWheelSliderNum = 0xFF;
1088   6                                                      for(i = TS_BaseCh; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++)
1089   6                                                      {
1090   7                                                              TS_AreaConfirmTimer[i] = WHEEL_SLIDER_BASELINE_UPDATE_TIME;
1091   7                                                      }
1092   6                                              }
1093   5                                      }
1094   4                                      else
1095   4                                      {
1096   5                                              WheelSliderTouchFlag[num] = 1;                          
1097   5                                      }
1098   4                              }               
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 19  

1099   3                      }               
1100   2                      if(WheelSliderState[num] == WHEEL_SLIDER_TOUCH)
1101   2                      {
1102   3                              if(Position != -1)
1103   3                              {
1104   4                                      WheelSliderPosition[num] = Position;
1105   4                              }       
1106   3      #if PRINT_WHEEL_SLIDER_POSITION_EN
                                      TK_Debug_UartPutChar(num + 0x30);       
                                      TK_Debug_UartPutChar(' ');
                                      
                                      TK_Debug_UartPutChar(WheelSliderPosition[num]/100+0x30);                
                                      TK_Debug_UartPutChar((WheelSliderPosition[num]%100)/10+0x30);           
                                      TK_Debug_UartPutChar((WheelSliderPosition[num]%10)+0x30);       
              
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');     
              #endif
1117   3      #if PRINT_WHEEL_SLIDER_RATE_EN
                                      if(num == PRINT_WHEEL_SLIDER_NUM)
                                      {
                                              unsigned char DeltaRate;
                                              DeltaRate = WheelSliderCapRateFilter[num]/4;
                                              TK_Debug_UartPutChar(WheelSliderMaxIdx[num] + 0x30);    
                                              TK_Debug_UartPutChar(' ');
                                              
                                              TK_Debug_UartPutChar(DeltaRate/100+0x30);               
                                              TK_Debug_UartPutChar((DeltaRate%100)/10+0x30);          
                                              TK_Debug_UartPutChar((DeltaRate%10)+0x30);      
                                              TK_Debug_UartPutChar('\r');     
                                              TK_Debug_UartPutChar('\n');                                     
                                      }
              
              #endif
1133   3                      }
1134   2                      else
1135   2                      {
1136   3                              WheelSliderPosition[num] = -1;
1137   3                      }
1138   2                      if(WheelSliderPosition[num] != -1)
1139   2                      {
1140   3                              WheelSliderTogFlag = 1;
1141   3                      }
1142   2                      TS_BaseCh += SLIDER_CH_COUNT[num];
1143   2              }
1144   1              if(WheelSliderTogFlag)
1145   1              {
1146   2                      ActiveTouchType = 2;
1147   2              }
1148   1              else
1149   1              {
1150   2                      ActiveTouchType = 0;
1151   2              }
1152   1      }
1153          #endif  
1154          void TS_init(void)
1155          {
1156   1              unsigned char i,ch_idx;
1157   1      #if (DEBUG)
                      Debug_init();
              #endif
1160   1      
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 20  

1161   1              TS_Cnt          = OPENED_TS_COUNT;
1162   1              ch_idx = 0;
1163   1              for(i = 0;i < OPENED_TS_COUNT; i++)
1164   1              {
1165   2      #if (SUPPORT_KEY && SUPPORT_WHEEL_SLIDER)
1166   2                      if(i < KEY_CH_COUNT)
1167   2                      {
1168   3                              TS_CH[ch_idx++] = TS_KEY_CH_INFO_SEQ[i][0];
1169   3                              TSKey_NoiseThreshold[i] = (int)(((unsigned long int)TS_KEY_CH_INFO_SEQ[i][1]*TK_NOISE_THD_RATE)/100);
1170   3                      }
1171   2                      else
1172   2                      {
1173   3                              TS_CH[ch_idx++] = TS_WHEEL_SLIDER_CH_SEQ[i-KEY_CH_COUNT];
1174   3                      }
1175   2      #elif SUPPORT_KEY
                              TS_CH[ch_idx++] = TS_KEY_CH_INFO_SEQ[i][0];
                              TSKey_NoiseThreshold[i] = (int)(((unsigned long int)TS_KEY_CH_INFO_SEQ[i][1]*TK_NOISE_THD_RATE)/100);
              #elif SUPPORT_WHEEL_SLIDER
                              TS_CH[ch_idx++] = TS_WHEEL_SLIDER_CH_SEQ[i];
              #endif
1181   2              }
1182   1              
1183   1      #if (RTC_CLK_SELECT == IRCL)
1184   1              CKCON |= ILCKE;
1185   1              CKSEL |= RTCKS(1);
1186   1      #elif (RTC_CLK_SELECT == XOSCL) 
                      CKCON |= XLCKE;
                      while(!(CKCON & XLSTA));
              #endif
1190   1      
1191   1              RTCON = RTCE(1) | MSE(1) | HSE(1) | SCE(0) | MCE(0) | HCE(0);
1192   1              RTMSS = 0;
1193   1              
1194   1              INT8EN = 1;                     
1195   1              
1196   1              TS_IO_init();
1197   1              
1198   1              
1199   1              TKCFG = TKDIV(TKDIV_VAL)|TKTMS(TKTMS_VAL);              
1200   1      #if (TK_CHARGE_REF_SELECT == SOURCE_VDD)
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(VRS_VAL);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               
              #elif (TK_CHARGE_REF_SELECT == SOURCE_INNER) 
1204   1              TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(0);
1205   1              TKPWC = TKPC(TK_PC_VAL)|VDS(VDS_VAL)|VIRS(VIRS_VAL)|TKPWS(1)|TKCVS(1);          
1206   1      #endif
1207   1              
1208   1              INT3EN = 1; 
1209   1              
1210   1              TS_CycleScanDoneFlag = 0;
1211   1      #if SUPPORT_KEY
1212   1              KeysFlagSN = 0;
1213   1              PreKeysFlagSN = 0;
1214   1      #endif  
1215   1              ActiveTouchType = 0;
1216   1      #if SUPPORT_KEY
1217   1      #if SUPPORT_COVER_PANAL_AFTER_POWERON
                      PanalCoverJudgeFlag = 0;
              #endif
1220   1      #endif
1221   1      #if SUPPORT_TOUCH_SLEEP_MODE
                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 21  

                      TS_SleepEn = 1;
                      TS_SleepMode = 0;
              #endif
1226   1      #if SUPPORT_WHEEL_SLIDER
1227   1              W_S_RefChSet = 0;
1228   1              for(i = 0; i < WHEEL_SLIDER_COUNT; i++)
1229   1              {
1230   2                      WheelSliderState[i] = WHEEL_SLIDER_NO_TOUCH;
1231   2                      WheelSliderTouchFlag[i] = 0;
1232   2                      WheelSliderPosition[i] = -1;
1233   2                      WheelSliderCapRateFilter[i] = 0;                
1234   2              }
1235   1              ActiveWheelSliderNum = 0xFF;
1236   1      #endif
1237   1              TS_State = TS_INIT;
1238   1              TS_Init_Step = 0;
1239   1      #if SUPPORT_KEY
1240   1      #if ANTI_SPEAKER_EN     
                      RefChDataTimer = 0;
              #endif
1243   1      #endif
1244   1              MainLoopCnt1 = MainLoopCnt2 = 0;
1245   1              Feed_Wdt_Flag = 0xA5;
1246   1      #if SUPPORT_KEY 
1247   1      #if GENERATE_TS_KEY_EN
1248   1              TK_State = TK_STATE_RELEASE;
1249   1              TS_Key = 0;
1250   1      #endif
1251   1      #endif
1252   1      }
1253          
1254          void TS_Action(void)
1255          {       
1256   1              switch(TS_State)
1257   1              {
1258   2                      case TS_INIT:
1259   2                              TS_RunInit();                   
1260   2                              break;
1261   2                      case TS_DEAL:           
1262   2                              if(TS_CycleScanDoneFlag)
1263   2                              {                       
1264   3                                      TS_CycleScanDoneFlag = 0;               
1265   3      #if SUPPORT_KEY
1266   3      #if ANTI_SPEAKER_EN
                                              TS_RefChCheck();
              #endif
1269   3      #endif
1270   3                                      TS_DataFiltering();
1271   3                                      TS_StableFlag = 1;
1272   3      #if SUPPORT_KEY 
1273   3                                      if(ActiveTouchType != 2)
1274   3                                      {
1275   4                                              TSKey_DataDeal();       
1276   4                                      }
1277   3      #endif
1278   3                                      Feed_Wdt_Flag |= 0xA5;
1279   3                                      MainLoopCnt1 = MainLoopCnt2 + 1;
1280   3      #if (DEBUG)
                                              Debug_ParamLoad();
              #endif          
1283   3      #if SUPPORT_WHEEL_SLIDER
1284   3                                      if(ActiveTouchType != 1)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 22  

1285   3                                      {
1286   4                                              TS_WheelSliderDeal();
1287   4                                      }
1288   3      #endif                          
1289   3      #if SUPPORT_TOUCH_SLEEP_MODE
                                              if(!TS_StableFlag || !TS_SleepEn || (PCON & BIT2))      // ÔÚ·ÂÕæÄ£Ê½²»½øÈëSTOPÄ£Ê½
                                              {
                                                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
                                              }                       
                                              if(!EnterStopScanTimer&&TS_SleepEn)
                                              {
              #if ENTER_SLEEP_PRINT_EN
                                                      TK_Debug_UartPutChar('s');      
                                                      TK_Debug_UartPutChar('l');      
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('p');      
                                                      TK_Debug_UartPutChar('\r');     
                                                      TK_Debug_UartPutChar('\n');             
                                                      Delay_ms(1);
              #endif
                                                      TS_EnterSleepMode();            
              #if ENTER_SLEEP_PRINT_EN                                        
                                                      TK_Debug_UartPutChar('e');      
                                                      TK_Debug_UartPutChar('x');      
                                                      TK_Debug_UartPutChar('i');      
                                                      TK_Debug_UartPutChar('t');      
                                                      TK_Debug_UartPutChar('\r');     
                                                      TK_Debug_UartPutChar('\n');             
              #endif
                                              }
              #endif                                                                          
1317   3                              }
1318   2                              if(TS_HalfSecCnt >= 5)
1319   2                              {
1320   3                                      TKCON = 0;
1321   3                                      TKIF = 0x3F;
1322   3                                      TS_init();
1323   3                              }
1324   2                              break;
1325   2                      default:
1326   2                              break;
1327   2              }
1328   1      
1329   1      #if SUPPORT_KEY 
1330   1      #if GENERATE_TS_KEY_EN
1331   1              TS_GetKey();
1332   1      #endif
1333   1      #endif
1334   1      }
1335          #if SUPPORT_TOUCH_SLEEP_MODE
              void TS_SleepScanStart(void)
              {       
                      unsigned char i;        
                      for(i = 0; i < 6; i++)                                  
                      {
                              INDEX = i;
                              if(TS_Index + i < TS_Cnt)
                              {
                                      TKCHS = MPOL(0) | NPOL(1) | TKCHS((TS_CH[TS_Index+i])+1); 
                              }
                              else
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 23  

                              {
                                      TKCHS = 0; 
                              }
                      }
                      TKCON |= TKST(1);       
              }
              
              #if (TS_SLEEP_MODE_DEBUG)
              void Uart_Debug_THD(unsigned char ch, unsigned int val, unsigned int pval, unsigned int nval)
              {
              //      ËµÃ÷£º´®¿Ú´òÓ¡µÄÊýÖµÎª¶ÔÓ¦Í¨µÀÊÖÖ¸°´ÏÂºóµÄ´¥ÃþÊý¾Ý±ä»¯Á¿£¨²îÖµ£©£¬´¥ÃþÊý¾Ý±ä»¯Á¿´óÓÚÉèÖÃµÄÃÅÏÞÖµÊ±£¬ÍË³
             -öÊ¡µçÄ£Ê½        
                      if((val <= pval)||(val >= nval))
                      {
                              if(val <= pval)
                              {
                                      #ifdef PRINT_EN
                                      uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(pval-val));
                                      #endif
                              }
                              if(val >= nval)
                              {
                                      #ifdef PRINT_EN
                                      uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(val-nval));
                                      #endif
                              }
                      }       
                      else
                      {
                              #ifdef PRINT_EN
                              uart_printf("TS_CH%d = %3d   ",(int)TS_CH[ch],(int)(0));
                              #endif
                      }
                      if(ch == (TS_Cnt-1))
                      {
                              #ifdef PRINT_EN
                              uart_printf("\n");
                              #endif
                      }
              }
              #endif
              
              #if SET_THRESHOLD_EACH_CHANNEL
              code unsigned char TS_KEY_SLEEP_THD[OPENED_TS_COUNT] = SLEEP_CH_THD_SEQ;
              #endif
              void TS_EnterSleepMode(void)
              {
              //Ê¡µçÄ£Ê½²ÎÊýÅäÖÃ
                      #define STOP_TKDIV_VAL                  0
                      #define STOP_TKTMS_VAL                  15              //·ÅµçÊ±¼ä
                      #define STOP_VRS_VAL                    7               //±È½ÏÆ÷ãÐÖµ    
                      unsigned char TS_SampleComplete = 0,i;
                      unsigned int xdata WakeUp_PThdVal[OPENED_TS_COUNT];
                      unsigned int xdata WakeUp_NThdVal[OPENED_TS_COUNT];     
                      WORD_UNION TS_Data;
                      
              #if (!TS_SLEEP_MODE_DEBUG)      
                      Sys_Clk_Set_TFRC();
                      #if (SYSCLK_SRC == PLL)
                      PLLCON = 0;
                      #endif  
              #endif
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 24  

                      
                      TKCON = 0;
                      TKIF = 0x3F;
                      
                      TS_SleepMode = 1;
                      
                      RTCON &=  ~(MSE(1) | HSE(1));
                      RTCIF = RTC_MF | RTC_HF;        
                      
                      TKCON = (TKCON&0xF8) | VRS(STOP_VRS_VAL);
                      TKCON &= ~TKIE(1);
                      TKCFG = TKDIV(STOP_TKDIV_VAL)|TKTMS(STOP_TKTMS_VAL);            
              
              #if (OPENED_TS_COUNT%6 == 0)
                      TKMTS = (SLEEP_MODE_SCAN_INTERVAL_TIME*6)/(OPENED_TS_COUNT);
              #else
                      TKMTS = (SLEEP_MODE_SCAN_INTERVAL_TIME)/((OPENED_TS_COUNT/6)+1);
              #endif
                      
                      TKPWC = TKPC(1)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               //Ê¡µçÉèÎªVDD³äµç
                      
              #if (!TS_SLEEP_MODE_DEBUG)      
                      LVDCON = 0;             
                      I2CCON = 0;
                      CKCON = 0;
                      MECON |= BIT6;  
                      PWCON = (PWCON&0xF0)|0x07;      
              #endif
              
                      TS_Index = 0;
                      TS_SleepScanStart();
                      WDFLG = 0xA5;
                      
                      RTCON |= HSE(1);
                      
                      while(1)
                      {
                      #if (!TS_SLEEP_MODE_DEBUG)              
                              if(TS_SampleComplete)
                              {
                                      CKCON &= ~TFCKE;                
                              #if (RTC_CLK_SELECT == IRCL)
                                      CKSEL = (CKSEL&0xF8) | CKSEL_IRCL;      //ÏµÍ³Ê±ÖÓÇÐ»»µ½IRCL    
                              #elif (RTC_CLK_SELECT == XOSCL) 
                                      CKSEL = (CKSEL&0xF8) | CKSEL_XOSCL;     //ÇÐ»»ÏµÍ³Ê±ÖÓµ½XOSCL   
                              #endif  
                                      EA = 0;
                                      PCON = (PCON&0x84) | 0x02;
                                      _nop_();
                                      _nop_();
                                      _nop_();
                                      CKCON |= TFCKE;                                         //Ê¹ÄÜTFRCÊ±ÖÓ
                                      CKSEL = (CKSEL&0xF8) | CKSEL_TFRC;      //ÇÐ»»ÏµÍ³Ê±ÖÓµ½TFRC            
                                      EA = 1;
                              }
                      #endif
                              if(TS_HalfSecCnt >= 5)
                              {
                                      break;
                              }
                              if(TKIF != 0)
                              {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 25  

                                      if(TS_HalfSecCnt) TS_HalfSecCnt--;
                                      for(i = 0; i < 6; i++)
                                      {
                                              if(TKIF & (1<<i))
                                              {
                                                      TKIF = (1<<i);  
                                                      INDEX = i;
                                                      TS_Data.bVal[0] = TKMSH;
                                                      TS_Data.bVal[1] = TKMSL;
              
                                                      if(TS_SampleComplete == 0)
                                                      {
                                                      #if SET_THRESHOLD_EACH_CHANNEL
                                                              WakeUp_PThdVal[TS_Index+i] = TS_Data.wVal - TS_KEY_SLEEP_THD[TS_Index+i];
                                                              WakeUp_NThdVal[TS_Index+i] = TS_Data.wVal + TS_KEY_SLEEP_THD[TS_Index+i];
                                                      #else
                                                              WakeUp_PThdVal[TS_Index+i] = TS_Data.wVal - SLEEP_TOUTH_THD;
                                                              WakeUp_NThdVal[TS_Index+i] = TS_Data.wVal + SLEEP_TOUTH_THD;
                                                      #endif
                                                      }
                                                      else 
                                                      {
                                                      #if (TS_SLEEP_MODE_DEBUG)
                                                              Uart_Debug_THD(TS_Index+i,TS_Data.wVal,WakeUp_PThdVal[TS_Index+i],WakeUp_NThdVal[TS_Index+i]);
                                                              continue;               //Ê¡µçÄ£Ê½´¥Ãþµ÷ÊÔ£¬²»ÍË³öÊ¡µçÄ£Ê½¡£ÔÚµ÷ÊÔ½áÊøÇë¹Ø±Õµ÷ÊÔ
                                                      #endif  
                                                              
                                                              if((TS_Data.wVal <= WakeUp_PThdVal[TS_Index+i])||(TS_Data.wVal >= WakeUp_NThdVal[TS_Index+i]))
                                                              {
                                                                      goto SLEEP_EXIT;                        
                                                              }
                                                      }
                                              }
                                      }
                                      if(TS_Index+6 < TS_Cnt)
                                      {
                                              TS_Index += 6;
                                      }
                                      else 
                                      {
                                              TS_Index = 0;
                                              if(TS_SampleComplete == 0)
                                              {
                                                      TS_SampleComplete = 1;                          
                                                      TKCON |= TMEN(1);                                       
                                              }
                                      }
                                      TS_SleepScanStart();    
                                      WDFLG = 0xA5;
                              }
                      /*
                              ÔÚ´¥ÃþÊ¡µçÄ£Ê½ÏÂ£¬ÈôÒªÏìÓ¦Íâ²¿ÖÐ¶Ï£¬ÓÃ»§ÐèÔÚ½øÈë´¥ÃþÊ¡µçÄ£Ê½Ö®Ç°×ÔÐÐ¿ªÆô¶ÔÓ¦
                              µÄÍâ²¿ÖÐ¶Ï¡£ÈôÐèÍË³ö¸ÃÊ¡µçÄ£Ê½£¬ÓÃ»§½öÐèÔÚÊ¡µçº¯ÊýÑ­»·ÄÚÌí¼ÓÌõ¼þÅÐ¶Ï£¬Ìø³öÑ­
                              »·±ã¿É¡£ÍË³ö´¥ÃþÊ¡µçÄ£Ê½ºó£¬ÐèÇå³ýÅÐ¶Ï±êÖ¾£¬²¢¸ù¾Ý²úÆ·µÄÊµ¼Ê×´¿ö¾ö¶¨ÊÇ·ñÒª¹Ø
                              ±ÕÍâ²¿ÖÐ¶Ï¡£ÒÔÍâ²¿ÖÐ¶Ï0ÎªÀý£º¶¨Òå±äÁ¿int_flag£¬¸Ã±äÁ¿ÔÚINT0ÖÐ¶Ï·þÎñ³ÌÐòÀïÖÃ1£¬
                              ÍË³öÊ¡µçÄ£Ê½ºóint_flagÒªÖÃ0¡£
                              if(int_flag == 1)
                              {
                                      goto SLEEP_EXIT;
                              }
                      */      
                      }
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 26  

              SLEEP_EXIT:
                      TKCON = 0;
                      TKIF = 0x3F;
                      PWCON = (PWCON&0xF0)|0x0D;      
              #if (SYSCLK_SRC == PLL)
                      Sys_Clk_Set_PLL(PLL_Multiple);
              #elif (SYSCLK_SRC == IRCH)      
                      Sys_Clk_Set_IRCH();
              #endif
              
                      TKCFG = TKDIV(TKDIV_VAL)|TKTMS(TKTMS_VAL);              
              #if (TK_CHARGE_REF_SELECT == SOURCE_VDD)
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(VRS_VAL);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(0)|VIRS(0)|TKPWS(0)|TKCVS(0);               
              #elif (TK_CHARGE_REF_SELECT == SOURCE_INNER) 
                      TKCON = TKST(0)|TKIE(1)|TMEN(0)|TWKE(0)|VRS(0);
                      TKPWC = TKPC(TK_PC_VAL)|VDS(VDS_VAL)|VIRS(VIRS_VAL)|TKPWS(1)|TKCVS(1);          
              #endif
              
                      RTCON |= HSE(1)|MSE(1);
                      TS_Index = 0;
                      TS_ScanStart();
                      EnterStopScanTimer = ENTER_STOP_MODE_TIME;
                      TS_SleepMode = 0;
              #ifdef LVD_RST_ENABLE
                      LVDCON = 0xE1;  //ÉèÖÃLVD¸´Î»µçÑ¹Îª2V
              #endif                                                  
              }
              #endif
1561          /*********************************************************************************************************
             -************/
1562          #if SUPPORT_KEY 
1563          #if GENERATE_TS_KEY_EN
1564          #if GENERATE_DOUBLE_KEY_EN
              typedef struct 
              {       
                      unsigned char   TogKeyNum;
                      unsigned char   TogKeyList[2];
              }
              T_TogKeyInfo;
              #endif
1572          code unsigned char TS_KEY_TAB[]=
1573          {
1574                  K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K20,K21,K22,K23,K24
1575          };
1576          #if GENERATE_DOUBLE_KEY_EN
              void TS_GetTogKeyInfor(T_TogKeyInfo *pKeyInfo)
              {
                      unsigned char i,index;
                      pKeyInfo->TogKeyNum = 0;
                      index = 0;
                      for(i = 0; i < KEY_CH_COUNT; i++)
                      {
                              if(KeysFlagSN & MASK_TAB[i])
                              {
                                      pKeyInfo->TogKeyNum++;
                                      
                                      if(pKeyInfo->TogKeyNum <= 2)
                                      {
                                              pKeyInfo->TogKeyList[index++] = TS_KEY_TAB[i];
                                      }
                              }
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 27  

                      }
              }
              #endif
1596          #if PRINT_TS_KEY_EN
              void Hex2CharPrint(unsigned int integar)
              {
                      unsigned char CharBuf[4];
                      unsigned char i, temp;
                      for(i = 0; i < 4; i++)
                      {
                              temp = (unsigned char)(integar&0x0F);
                              if(temp >= 0x0A)
                              {
                                      CharBuf[i] = (temp - 0x0A) + 'A';
                              }
                              else
                              {
                                      CharBuf[i] = temp + '0';
                              }
                              integar >>= 4;
                      }
                      TK_Debug_UartPutChar('0');      
                      TK_Debug_UartPutChar('x');      
                      TK_Debug_UartPutChar(CharBuf[2]);
                      TK_Debug_UartPutChar(CharBuf[1]);
                      TK_Debug_UartPutChar(CharBuf[0]);
              }
              #endif
1621          void TS_GetKey(void)
1622          {
1623   1              static unsigned int KeyBak;     
1624   1              static bit LongFlag;
1625   1      #if GENERATE_DOUBLE_KEY_EN
                      T_TogKeyInfo KeyInfo;
                      TS_GetTogKeyInfor(&KeyInfo);
              #else
1629   1              static unsigned char KeyidxBak;
1630   1              unsigned char i;
1631   1      #endif
1632   1              TS_Key = 0;     
1633   1              if(TK_State == TK_STATE_RELEASE)
1634   1              {
1635   2      #if GENERATE_DOUBLE_KEY_EN
                              if(KeyInfo.TogKeyNum != 0)
                              {                       
                                      if(KeyInfo.TogKeyNum == 1)
                                      {
                                              KeyBak = (unsigned int)KeyInfo.TogKeyList[0];
                                              TK_State = TK_STATE_SINGLE_KEY_PRESS;                           
                                      }
                                      else if(KeyInfo.TogKeyNum == 2)
                                      {
                                              KeyBak = ((unsigned int)KeyInfo.TogKeyList[0]<<5)|(unsigned int)KeyInfo.TogKeyList[1];
                                              TK_State = TK_STATE_DOUBLE_KEY_PRESS;
                                      }
                                      TS_Key = KeyBak;
                                      LongFlag = 0;
                                      TS_LongKeyTimer = TS_LONG_START_TIME;
                              }
              #else
1653   2                      if(KeysFlagSN != 0)
1654   2                      {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 28  

1655   3                              for(i = 0; i < KEY_CH_COUNT; i++)
1656   3                              {
1657   4                                      if(KeysFlagSN & MASK_TAB[i])
1658   4                                      {
1659   5                                              KeyidxBak = i;
1660   5                                              KeyBak = TS_KEY_TAB[i];
1661   5                                              break;
1662   5                                      }               
1663   4                              }                               
1664   3                              TS_Key = KeyBak;
1665   3                              LongFlag = 0;
1666   3                              TS_LongKeyTimer = TS_LONG_START_TIME;
1667   3                              TK_State = TK_STATE_SINGLE_KEY_PRESS;           
1668   3                      }
1669   2      #endif
1670   2              }
1671   1              else if(TK_State == TK_STATE_SINGLE_KEY_PRESS)
1672   1              {
1673   2      #if GENERATE_DOUBLE_KEY_EN      
                              if(KeyInfo.TogKeyNum == 1)
                              {
                                      if(KeyBak == (unsigned int)KeyInfo.TogKeyList[0])
                                      {
                                              if(!TS_LongKeyTimer)
                                              {
                                                      if(!LongFlag)
                                                      {
                                                              LongFlag = 1;
                                                              TS_Key = KeyBak | KEY_LONG_START;
                                                      }
                                                      else
                                                      {
                                                              TS_Key = KeyBak | KEY_LONG;
                                                      }
                                                      TS_LongKeyTimer = TS_LONG_TIME;
                                              }                               
                                      }
                                      else 
                                      {
                                              if(!LongFlag)
                                              {
                                                      TS_Key = KeyBak | KEY_BREAK;
                                              }
                                              else
                                              {
                                                      TS_Key = KeyBak | KEY_LONG_BREAK;
                                              }
                                              TK_State = TK_STATE_RELEASE;
                                      }
                              }
                              else if(KeyInfo.TogKeyNum == 2)
                              {
                                      KeyBak = ((unsigned int)KeyInfo.TogKeyList[0]<<5) | (unsigned int)KeyInfo.TogKeyList[1];
                                      TK_State = TK_STATE_DOUBLE_KEY_PRESS;
                                      TS_Key = KeyBak;
                                      LongFlag = 0;
                                      TS_LongKeyTimer = TS_LONG_START_TIME;
                              }
                              else if(KeyInfo.TogKeyNum == 0)
                              {
                                      if(!LongFlag)
                                      {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 29  

                                              TS_Key = KeyBak | KEY_BREAK;
                                      }
                                      else
                                      {
                                              TS_Key = KeyBak | KEY_LONG_BREAK;
                                      }
                                      TK_State = TK_STATE_RELEASE;
                              }
              #else
1726   2                      if(KeysFlagSN & MASK_TAB[KeyidxBak])
1727   2                      {
1728   3                                      if(!TS_LongKeyTimer)
1729   3                                      {
1730   4                                              if(!LongFlag)
1731   4                                              {
1732   5                                                      LongFlag = 1;
1733   5                                                      TS_Key = KeyBak | KEY_LONG_START;
1734   5                                              }
1735   4                                              else
1736   4                                              {
1737   5                                                      TS_Key = KeyBak | KEY_LONG;
1738   5                                              }
1739   4                                              TS_LongKeyTimer = TS_LONG_TIME;
1740   4                                      }                                       
1741   3                      }
1742   2                      else
1743   2                      {
1744   3                              if(!LongFlag)
1745   3                              {
1746   4                                      TS_Key = KeyBak | KEY_BREAK;
1747   4                              }
1748   3                              else
1749   3                              {
1750   4                                      TS_Key = KeyBak | KEY_LONG_BREAK;
1751   4                              }
1752   3                              TK_State = TK_STATE_RELEASE;                    
1753   3                      }
1754   2      #endif
1755   2              }
1756   1      #if GENERATE_DOUBLE_KEY_EN      
                      else if(TK_State == TK_STATE_DOUBLE_KEY_PRESS)
                      {
                              if(KeyInfo.TogKeyNum == 2)
                              {
                                      if(KeyBak == ((unsigned int)KeyInfo.TogKeyList[0]<<5)|(unsigned int)KeyInfo.TogKeyList[1])
                                      {
                                              if(!TS_LongKeyTimer)
                                              {
                                                      if(!LongFlag)
                                                      {
                                                              LongFlag = 1;
                                                              TS_Key = KeyBak | KEY_LONG_START;
                                                      }
                                                      else
                                                      {
                                                              TS_Key = KeyBak | KEY_LONG;
                                                      }
                                                      TS_LongKeyTimer = TS_LONG_TIME;
                                              }                                       
                                      }
                              }
                              else if(KeyInfo.TogKeyNum == 0)
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 30  

                              {
                                      if(!LongFlag)
                                      {
                                              TS_Key = KeyBak | KEY_BREAK;
                                      }
                                      else
                                      {
                                              TS_Key = KeyBak | KEY_LONG_BREAK;
                                      }
                                      TK_State = TK_STATE_RELEASE;            
                              }
                      }
              #endif
1792   1      #if PRINT_TS_KEY_EN
                      if(TS_Key != 0)
                      {
                              if((TS_Key & 0xFF00) == 0)
                              {
              #if GENERATE_DOUBLE_KEY_EN      
                                      if(TS_Key > 0x1F)
                                      {
                                              TK_Debug_UartPutChar('d');      
                                              TK_Debug_UartPutChar('o');      
                                              TK_Debug_UartPutChar('u');      
                                              TK_Debug_UartPutChar('b');      
                                              TK_Debug_UartPutChar('l');      
                                              TK_Debug_UartPutChar('e');                      
                                      }
                                      else
                                      {
                                              TK_Debug_UartPutChar('s');      
                                              TK_Debug_UartPutChar('i');      
                                              TK_Debug_UartPutChar('n');      
                                              TK_Debug_UartPutChar('g');      
                                              TK_Debug_UartPutChar('l');      
                                              TK_Debug_UartPutChar('e');              
                                      }
                                      TK_Debug_UartPutChar(' ');      
              #endif
                                      TK_Debug_UartPutChar('k');      
                                      TK_Debug_UartPutChar('e');      
                                      TK_Debug_UartPutChar('y');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('=');      
                                      TK_Debug_UartPutChar(' ');      
                                      Hex2CharPrint(TS_Key);
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');     
                              }
                              else if(TS_Key & KEY_BREAK)
                              {
                                      TK_Debug_UartPutChar('k');      
                                      TK_Debug_UartPutChar('e');      
                                      TK_Debug_UartPutChar('y');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('u');      
                                      TK_Debug_UartPutChar('p');      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                             
                              }
                              else if(TS_Key & KEY_LONG_START)
                              {
C51 COMPILER V9.02   TS_API                                                                12/25/2025 15:34:16 PAGE 31  

                                      TK_Debug_UartPutChar('l');      
                                      TK_Debug_UartPutChar('o');      
                                      TK_Debug_UartPutChar('n');      
                                      TK_Debug_UartPutChar('g');      
                                      TK_Debug_UartPutChar(' ');      
                                      TK_Debug_UartPutChar('s');      
                                      TK_Debug_UartPutChar('t');      
                                      TK_Debug_UartPutChar('a');      
                                      TK_Debug_UartPutChar('r');      
                                      TK_Debug_UartPutChar('t');      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                     
                              }
                              else if(TS_Key & KEY_LONG)
                              {
                                      TK_Debug_UartPutChar('l');      
                                      TK_Debug_UartPutChar('o');      
                                      TK_Debug_UartPutChar('n');      
                                      TK_Debug_UartPutChar('g');      
                                      TK_Debug_UartPutChar('\r');     
                                      TK_Debug_UartPutChar('\n');                     
                              }
                      }
              #endif
1865   1      }
1866          #endif
1867          #endif
1868          /*********************************************************************************************************
             -************/
1869          
1870          /*********************************************************************************************************
             -************/
1871          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2476    ----
   CONSTANT SIZE    =     67    ----
   XDATA SIZE       =    273    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     13      30
   IDATA SIZE       =     12    ----
   BIT SIZE         =      4       1
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
