C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 1   


C51 COMPILER V9.02, COMPILATION OF MODULE TS_SEVICE
OBJECT MODULE PLACED IN .\hex\ts_sevice.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE TS_Lib\Sources\ts_sevice.c OMF2 ROM(COMPACT) OPTIMIZE(9,SIZE) BROWSE DEB
                    -UG PRINT(.\lst\ts_sevice.lst) OBJECT(.\hex\ts_sevice.obj)

line level    source

   1          #ifndef TS_SERVICE_C
   2          #define TS_SERVICE_C
   3          /*********************************************************************************************************
             -************/
   4          #include "ca51f_config.h"
   5          #include "includes\ca51f2sfr.h"
   6          #include "includes\ca51f2xsfr.h"
   7          #include "includes\gpiodef_f2.h"
   8          #include "Library\includes\uart.h"
   9          /*********************************************************************************************************
             -************/
  10          #include "TS_Lib\Includes\ts_def.h"
  11          #include "TS_Lib\Includes\ts_api.h"
  12          #include "TS_Lib\Includes\ts_service.h"           
  13          /*********************************************************************************************************
             -************/
  14          code unsigned char *pXSFR[]=
  15          {
  16                  &P70F,
  17                  &P67F,
  18                  &P66F,
  19                  &P37F,
  20                  &P36F,
  21                  &P33F,
  22                  &P32F,
  23                  &P47F,
  24                  &P46F,
  25                  &P45F,
  26                  &P44F,
  27                  &P43F,
  28                  &P42F,
  29                  &P41F,
  30                  &P40F,
  31                  &P34F,
  32                  &P35F,
  33                  &P56F,
  34                  &P50F,
  35                  &P51F,
  36                  &P52F,
  37                  &P53F,
  38                  &P54F,
  39                  &P55F,
  40          };
  41          void TS_IO_init(void)
  42          {
  43   1              unsigned char i;
  44   1              unsigned char *pPinS;
  45   1              GPIO_Init(P57F,P57_CAP_SETTING);
  46   1              for(i = 0; i < TS_Cnt; i++)
  47   1              {
  48   2                      pPinS = pXSFR[TS_CH[i]];
  49   2                      *pPinS = 4;
  50   2              }
  51   1      }
C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 2   

  52          void TS_ScanStart(void)
  53          {       
  54   1              unsigned char i,j;      
  55   1              for(i = 0; i < 6; i++)                                  
  56   1              {
  57   2                      if(TS_Index + i >= TS_Cnt)
  58   2                      {
  59   3                              INDEX = i;
  60   3                              TKCHS = MPOL(0) | NPOL(1) | TKCHS(25);
  61   3                              for(j = i+1; j < 6; j++)
  62   3                              {
  63   4                                      INDEX = j;
  64   4                                      TKCHS = MPOL(0) | NPOL(1) | TKCHS(0);   
  65   4                              }
  66   3                              break;
  67   3                      }
  68   2                      INDEX = i;
  69   2                      TKCHS = MPOL(0) | NPOL(1) | TKCHS((TS_CH[TS_Index+i])+1); 
  70   2              }
  71   1              TKCON |= TKST(1);       
  72   1      }
  73          unsigned char TS_GetDataArea(unsigned char ts_ch,unsigned int ts_data,int NoiseThd,bit key_pressed_flag)
  74          {
  75   1              int Delta;
  76   1              int FingerThd;
  77   1              
  78   1              Delta           = (int)TS_BaseLineData[ts_ch] - (int)ts_data;
  79   1              FingerThd = TSKey_FingerThd[ts_ch];             
  80   1              
  81   1              if(key_pressed_flag)
  82   1              {
  83   2                      FingerThd = (FingerThd*9)/10;   
  84   2              }
  85   1              
  86   1              if(Delta >= FingerThd)                  return AREA_FINGER_TOUCH; 
  87   1              else if(Delta > NoiseThd)               return AREA_PNOISE_PLUS; 
  88   1              else if(Delta >= 0)                                     return AREA_PNOISE;
  89   1              else if(Delta >= -NoiseThd) return AREA_NNOISE;
  90   1              else                                                                                            return AREA_OVER_LOW;
  91   1      }
  92          unsigned char TS_AreaDeviateDetection(unsigned int cmp_data,unsigned int real_data,int range)
  93          {       
  94   1              int Delta;
  95   1              Delta   = (int)cmp_data - (int)real_data;
  96   1              if((Delta <= range) && (Delta >= -range))
  97   1              {
  98   2                      return 1;
  99   2              }
 100   1              else
 101   1              {
 102   2                      return 0;       
 103   2              }               
 104   1      }
 105          void TS_BaseLineForceUpdate(void)
 106          {
 107   1              unsigned char i;
 108   1      
 109   1              for(i = 0; i < TS_Cnt; i++)
 110   1              {
 111   2                      TS_FirstAreaData[i] = TS_PostData[i];
 112   2                      TS_BaseLineData[i]      = TS_PostData[i];
 113   2                      TS_AreaConfirmTimerSet(i,AREA_PNOISE);                                          
C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 3   

 114   2              }       
 115   1      }
 116          
 117          void TS_AreaConfirmTimerSet(unsigned char ts_ch, unsigned char area)
 118          {
 119   1              TS_AreaConfirmTimer[ts_ch] = AREA_CONFIRM_TIME_TAB[area];
 120   1      }
 121          void SetWheelSliderRefCh(unsigned char SliderNum,unsigned char Key_Cnt)
 122          {
 123   1              unsigned char num,i,j;
 124   1              unsigned int MinVal;
 125   1              TS_BaseCh = Key_Cnt; 
 126   1              for(num = 0; num < SliderNum; num++)
 127   1              {
 128   2                      MinVal = 0xFFFF;
 129   2                      for(i = TS_BaseCh,j=0; i < TS_BaseCh + SLIDER_CH_COUNT[num]; i++,j++)
 130   2                      {
 131   3                              if(TS_BaseLineData[i] < MinVal)
 132   3                              {
 133   4                                      WheelSliderRefCh[num] = j;
 134   4                                      MinVal = TS_BaseLineData[i];
 135   4                              }
 136   3                      }
 137   2                      TS_BaseCh += SLIDER_CH_COUNT[num];
 138   2              }       
 139   1      }
 140          #define WHEEL_SLIDER_POSITION_FILTER_COUNT                              4                       
 141          int WheelSliderTouchJudge(unsigned char num)
 142          {
 143   1              unsigned char i;
 144   1              unsigned long int CalcTemp1;
 145   1              unsigned int CalcTemp2,CalcTemp3;
 146   1              unsigned char DeltaRate;
 147   1              int  Delta;
 148   1              unsigned int  MaxDelta1,MaxDelta2/*,MaxDelta3*/;
 149   1              unsigned char Maxidx1,Maxidx2/*,Maxidx3*/;
 150   1              int Position,PosOffset;
 151   1              unsigned char   *pMinRate;
 152   1              
 153   1              pMinRate = WHEEL_SLIDER_MIN_RATE[num];
 154   1              MaxDelta1 = MaxDelta2 = /*MaxDelta3 =*/ 0;
 155   1      
 156   1              for(i = 0; i < SLIDER_CH_COUNT[num]; i++)       
 157   1              {       
 158   2                      if(i == WheelSliderRefCh[num])  
 159   2                      {
 160   3                              Delta                   =       (int)TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - (int)TS_PostData[TS_BaseCh + Wheel
             -SliderRefCh[num]];    
 161   3                      }
 162   2                      else
 163   2                      {
 164   3                              CalcTemp1 =     (unsigned long int)TS_PostData[TS_BaseCh + i] * (unsigned long int)TS_BaseLineData[TS_Base
             -Ch + WheelSliderRefCh[num]];
 165   3                              CalcTemp2 =     (unsigned int)(CalcTemp1/TS_BaseLineData[TS_BaseCh + i]);
 166   3                              CalcTemp3 =     TS_PostData[TS_BaseCh + i] + TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - CalcTemp
             -2;
 167   3                              CalcTemp2 =     (unsigned int)(CalcTemp1/CalcTemp3);    
 168   3                              Delta           =       (int)TS_BaseLineData[TS_BaseCh + WheelSliderRefCh[num]] - (int)CalcTemp2;                                       
 169   3                      }
 170   2                      if(Delta < 0) Delta = 0;
 171   2              
 172   2                      
C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 4   

 173   2                      if(Delta > MaxDelta1)
 174   2                      {
 175   3      //                      Maxidx3 = Maxidx2;      MaxDelta3 = MaxDelta2;
 176   3                              Maxidx2 = Maxidx1;      MaxDelta2 = MaxDelta1;
 177   3                              Maxidx1 = i;                            MaxDelta1 = Delta;
 178   3                      }
 179   2                      else if(Delta > MaxDelta2)
 180   2                      {
 181   3      //                      Maxidx3 = Maxidx2;      MaxDelta3 = MaxDelta2;
 182   3                              Maxidx2 = i;                            MaxDelta2 = Delta;
 183   3                      }
 184   2      //              else if(Delta > MaxDelta3)
 185   2      //              {
 186   2      //                      Maxidx3 = i;                            MaxDelta3 = Delta;
 187   2      //              }
 188   2              }
 189   1              if((WHEEL_OR_SLIDER_DEF[num] == SLIDER)&&((Maxidx1 == 0)||(Maxidx1 == (SLIDER_CH_COUNT[num]-1))))
 190   1              {
 191   2                      if((MaxDelta1) < (WHEEL_SLIDER_TOUCH_THD[num]>>1))
 192   2                      {
 193   3                              return -1;
 194   3                      }
 195   2              }
 196   1              else
 197   1              {
 198   2                      if((MaxDelta1 + MaxDelta2) < WHEEL_SLIDER_TOUCH_THD[num])
 199   2                      {
 200   3                              return -1;
 201   3                      }               
 202   2              }
 203   1      
 204   1              Delta = MaxDelta1 - (WHEEL_SLIDER_TOUCH_THD[num]>>1);
 205   1              DeltaRate = (Delta*10)/MaxDelta1;
 206   1              if(DeltaRate > 31) DeltaRate = 31;
 207   1              
 208   1              CalcTemp2 = ((unsigned int)WHEEL_SLIDER_TOUCH_THD[num]*(32-DeltaRate))>>6;
 209   1              
 210   1              MaxDelta1 += CalcTemp2;
 211   1              MaxDelta2 += CalcTemp2;         
 212   1      
 213   1              DeltaRate = ((unsigned int)MaxDelta2<<7)/MaxDelta1;
 214   1              if(WheelSliderCapRateFilter[num] == 0)
 215   1              {
 216   2                      WheelSliderCapRateFilter[num] = DeltaRate*WHEEL_SLIDER_POSITION_FILTER_COUNT;
 217   2              }
 218   1              else
 219   1              {
 220   2                      WheelSliderCapRateFilter[num] -= WheelSliderCapRateFilter[num]/WHEEL_SLIDER_POSITION_FILTER_COUNT;
 221   2                      WheelSliderCapRateFilter[num] += DeltaRate;     
 222   2              }
 223   1              DeltaRate = WheelSliderCapRateFilter[num]/WHEEL_SLIDER_POSITION_FILTER_COUNT;
 224   1              WheelSliderMaxIdx[num] = Maxidx1;
 225   1              
 226   1      
 227   1              if(WHEEL_OR_SLIDER_DEF[num] == SLIDER)
 228   1              {
 229   2                      Position = Maxidx1*64;
 230   2                      if(Maxidx1 == 0)
 231   2                      {
 232   3                              if(DeltaRate < pMinRate[0])
 233   3                              {
 234   4                                      DeltaRate = pMinRate[0];
C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 5   

 235   4                              }
 236   3                              Position = ((DeltaRate - pMinRate[0])*32)/(128-pMinRate[0]);
 237   3                      }
 238   2                      else if(Maxidx1 == (SLIDER_CH_COUNT[num]-1))
 239   2                      {
 240   3                              if(DeltaRate < pMinRate[SLIDER_CH_COUNT[num]-1])
 241   3                              {
 242   4                                      DeltaRate = pMinRate[SLIDER_CH_COUNT[num]-1];
 243   4                              }
 244   3                              Position -= ((DeltaRate - pMinRate[SLIDER_CH_COUNT[num]-1])*32)/(128-pMinRate[SLIDER_CH_COUNT[num]-1]);
 245   3                      }
 246   2                      else
 247   2                      {
 248   3                              if(DeltaRate < pMinRate[Maxidx1]) DeltaRate = pMinRate[Maxidx1];
 249   3                              PosOffset = ((DeltaRate - pMinRate[Maxidx1])*32)/(128-pMinRate[Maxidx1]);
 250   3                              if(Maxidx1 < Maxidx2)
 251   3                              {
 252   4                                      Position += PosOffset;
 253   4                              }
 254   3                              else
 255   3                              {
 256   4                                      Position -= PosOffset;
 257   4                              }
 258   3                      }
 259   2      
 260   2              }
 261   1              else if(WHEEL_OR_SLIDER_DEF[num] == WHEEL)
 262   1              {
 263   2                      bit dir_flag;
 264   2                      Position = Maxidx1*64;
 265   2                      if(DeltaRate < pMinRate[Maxidx1]) DeltaRate = pMinRate[Maxidx1];
 266   2                      PosOffset = ((DeltaRate - pMinRate[Maxidx1])*32)/(128-pMinRate[Maxidx1]);
 267   2                      
 268   2                      if((Maxidx1 == 0) && (Maxidx2 == (SLIDER_CH_COUNT[num]-1))) dir_flag = 0;
 269   2                      else if((Maxidx1 == (SLIDER_CH_COUNT[num]-1)) && (Maxidx2 == 0)) dir_flag = 1;
 270   2                      else if(Maxidx1 < Maxidx2) dir_flag = 1;
 271   2                      else dir_flag = 0;
 272   2                      
 273   2                      if(dir_flag)
 274   2                      {
 275   3                              Position += PosOffset;
 276   3                      }
 277   2                      else
 278   2                      {
 279   3                              if(Position == 0)
 280   3                              {
 281   4                                      Position = SLIDER_CH_COUNT[num]*64-1;
 282   4                              }
 283   3                              Position -= PosOffset;
 284   3                      }
 285   2      
 286   2              }
 287   1              return Position;
 288   1      }
 289          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1517    ----
   CONSTANT SIZE    =     72    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
C51 COMPILER V9.02   TS_SEVICE                                                             09/29/2022 13:06:11 PAGE 6   

   DATA SIZE        =   ----      30
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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