觸摸檢測到按鍵按下調用流程 :TSL_Action -> TSL_SCKEY_P1_Acquisition() -> TSL_IO_Acquisition() -> TSL_SCKey_Process() -> TSL_SCKey_DetectedTreatment() ,其中TSL_Action ()和TSL_SCKey_Process() 還有其他的狀態變化和處理。
TSL_IO_Acquisition() 函數爲充放電時間檢測函數,其中最重要的變量應該是充放電時間和檢測到超過預設範圍的次數,函數外部會用到,分別爲FinalMeasurementValue和RejectionCounter。
void TSL_IO_SW_Burst_Wait_Vil(void)//只看IAR編譯器的內容
{
#if defined(_COSMIC_)
......
#elif defined(_IAR_)
__asm("ld a, S:AcquisitionBitMask"); //將AcquisitionBitMask放到a中
__asm("ldw x, S:sTouchIO"); // 將sTouchIO放到x中 裝載字(16位)
__asm("incw x"); //增加一個字
// Loop = 1 + 1 + 2 + 2 + 2 cycles = 8 cycles
__asm("WaitForVil:");
// To be sure that the loop last 8 cycles the first instruction must be a 1-byte instruction
// This is to be sure it is fully fetched in 1 cycle. The second instruction must be shorter than 4 bytes.
// If this not the case, the code must be aligned.
__asm("bcp a, (x)"); // 1 cycles 邏輯比較
__asm("jreq ??EndWaitForVil"); //跳轉到EndWaitForVil處
__asm("ldw y, TIMACQ_CNTR"); // 2 cycles; hw counter also used for timeout ...
__asm("cpw y, #0x0E00"); // 2 cycles; Timeout compare 字數值比較
__asm("jrult ??WaitForVil");
__asm("EndWaitForVil:");
#else //_RAISONANCE_
......
#endif
}
這個函數的大概意思是說檢測對應管腳的電平,直到相同電平或者超時跳出,FinalMeasurementValue中裝的應該就是TIMACQ_CNTR計數器的值(不知道是否正確,請大神指正)
注:
觸摸方案的設計摘要:http://download.csdn.net/detail/wr1040982587/9697492
觸摸方案的簡單工程:http://download.csdn.net/detail/wr1040982587/9697482
有需要可以下載參考下!