📄 input.c
字号:
#include "winav.h"#include "aploader.h"#include "ctkav.h"#include "int_gbl.h"#include "input.h"#include "ir.h"#include "utl.h"#include "cc.h"volatile BYTE __bISRKey = KEY_NO_KEY; IR_INFO _IRInfo;#if (IR_CODE_TYPE == SW_RC5 || IR_CODE_TYPE == SW_NEC)BYTE bIRCheck = 0;#endif // #if (IR_CODE_TYPE == SW_RC5 || IR_CODE_TYPE == SW_NEC)//hwtan1209 begin, for fine tune SW IR receiving#if (IR_CODE_TYPE == SW_KONKA)BYTE bIRStep = 0; // hwtan1123BYTE bDataCode = 0; //wx.051123BYTE bIRFlag = 0; // 1: has one IR key input 0: noneBYTE bFallingFlag = 0; // BYTE bPrevEdge = 0xff;BYTE bIRCheck = 0; // hwtan1213testWORD IR_code[19]; // hwtan1209#endif // #if (IR_CODE_TYPE == SW_KONKA)BYTE _bKeyGet;BYTE _bISRKeyPrev = KEY_NO_KEY; BYTE _bCustomerCode = 0;BYTE _bCustomerCode1 = 0;// LLY2.36, keep current IR check mode.BYTE _bIRCheckMode=IR_CHECK_MODE_INT;// LLY2.36, keep previous IR repeat flagBYTE _bPreRepeatFlag=1;DWORD _dwTimeISRKeyPrev = 0;DWORD _dwTimeISRKeyPrev2 = 0;extern PAP_INFO_ADDITIONAL AP_Info_Additional;#ifdef SUPPORT_GAME_IR#ifdef IR_CODE_TYPE #undef IR_CODE_TYPE #define IR_CODE_TYPE HW_NEC#endif // #ifdef IR_CODE_TYPEBYTE _blGameIRMode = FALSE;volatile WORD __wISRGameKey = 0x0000;#endif // #ifdef SUPPORT_GAME_IR// LLY2.38, keep IR working mode when power down.#if (IR_CODE_TYPE != HW_NEC)#define KEEP_IR_WORKING_MODE_WHEN_POWERDOWN#endif // #if (IR_CODE_TYPE == HW_NEC)VOID _ResetIR(VOID); #if (PLATFORM == ECOS_OS)VOID ISR_IRSaveClearStatus( VOID ){// =============================================================================#if (IR_CODE_TYPE == SW_RC5) #define FULL_WINDOW_TIME (178) #define MAX_TIME (FULL_WINDOW_TIME) #define HALT_WINDOW_TIME ((FULL_WINDOW_TIME + 1) / 2) #define GAP ((FULL_WINDOW_TIME + 2) / 4) #define GREAT(x, y) ((x) > ((y) + (GAP))) #define LESS(x, y) ((x) < ((y) - (GAP))) #define EQUAL(x, y) ((!GREAT((x), (y))) && (!LESS((x), (y)))) #define IR_STATUS_RISING (0x10) #define IR_STATUS_FALLING (0x20) #define IR_STATUS_WIN_BEGIN (0x40) static BYTE bBitCnt = 0, bPrevIRStatus; static WORD wIRCode; BYTE bIRStatus; WORD wIRTime; bIRStatus = REG_PLAT_IR_STATUS; if(bIRStatus & 0x10) { wIRTime = REG_PLAT_IR_COUNTER >> 16; } else { wIRTime = REG_PLAT_IR_COUNTER; } do { if(((bIRStatus & bPrevIRStatus) & 0x30) == 0) // edge rising or falling must be alternative { if(EQUAL(wIRTime, HALT_WINDOW_TIME)) { if(!(bPrevIRStatus & IR_STATUS_WIN_BEGIN)) { bIRStatus |= IR_STATUS_WIN_BEGIN; wIRCode |= ((bIRStatus & IR_STATUS_RISING) ? 0 : 1) << bBitCnt; ++bBitCnt; } break; } else if(EQUAL(wIRTime, FULL_WINDOW_TIME)) { if(!(bPrevIRStatus & IR_STATUS_WIN_BEGIN)) { wIRCode |= ((bIRStatus & IR_STATUS_RISING) ? 1 : 0) << bBitCnt; ++bBitCnt; break; } } } // begin of code or error status wIRCode = bBitCnt = 1; } while(0); bPrevIRStatus = bIRStatus; if(bBitCnt >= 14) { if(((wIRCode >> 3) & 0x1f) == CUSTOMER_CODE) { DWORD dwTimeISRKey = OS_GetSysTimer(); if((dwTimeISRKey - _dwTimeISRKeyPrev) >= COUNT_200_MSEC) { BYTE bIRDataCode = wIRCode >> 8; _bKeyGet = bIRDataCode < _IRInfo.bIRMapSize ? _IRInfo.aIRMap[bIRDataCode] : KEY_NO_KEY; bIRCheck = !((dwTimeISRKey - _dwTimeISRKeyPrev) < COUNT_300_MSEC); _dwTimeISRKeyPrev = dwTimeISRKey; __pINTDSRRoutine[INT_NO10][__dwINTDSRCounter[INT_NO10] ++] = DSR_IR; } } wIRCode = bBitCnt = 0; } return;#endif // #if (IR_CODE_TYPE == SW_RC5)// =============================================================================// =============================================================================#if (IR_CODE_TYPE == SW_KONKA) WORD wIRTemp; DWORD dwTimeISRKey; // hwtan1213 //***********************************************// the waveform of Konka IR is below:// ___ // | | | leader code: 3ms high + 3ms low// | |___|// _// || |// ||__| "0" : 0.5ms high + 1.5ms low// _// || |// ||____| "1" : 0.5ms high + 2.5ms low//*********************************************** if (bIRFlag) return; // if DSR is processing , do nothing if (!bIRStep) // 0 : just begin receive IR { wIRTemp =LOWORD(REG_PLAT_IR_COUNTER); if (wIRTemp<320 && wIRTemp >280) // high 3ms means the valid leader code bIRStep = 1; } else if (bIRStep==1) // 1: check the leader code's low 3ms { wIRTemp = HIWORD(REG_PLAT_IR_COUNTER); if (wIRTemp<320 && wIRTemp >280) // low 3ms match 300 bIRStep++; // begine receive IR else bIRStep = 0; // if the leader code is invalid, its noise, reset the step to 0 } else // receive the customer/data/sync code { wIRTemp = HIWORD(REG_PLAT_IR_COUNTER); // only focus on the low level 1.5ms for 0, 2.5ms for 1 if (wIRTemp > 130 && wIRTemp < 270) // its valid data bit: 0 or 1 { bIRStep ++; IR_code[bIRStep] = wIRTemp; } else if (wIRTemp > 330 && wIRTemp < 420) // the sync bit, low lenght = 4ms, means one IR key finish { if (bIRStep == 18) // 2bit leader + 8 bit customer code + 8bit data code = 18 { bIRStep ++; // 19 is a flag, means one IR key finish, let DSR_IR parse the data in IR_Code[] to get key dwTimeISRKey = OS_GetSysTimer(); // get current time if ( (dwTimeISRKey- _dwTimeISRKeyPrev) < COUNT_200_MSEC ) bIRCheck = 0; // for repeat IR key, do not receive it else bIRCheck = 1; _dwTimeISRKeyPrev = dwTimeISRKey; } } } __pINTDSRRoutine[INT_NO10][__dwINTDSRCounter[INT_NO10] ++] = DSR_IR;#endif // #if (IR_CODE_TYPE == SW_KONKA)// =============================================================================// =============================================================================#if (IR_CODE_TYPE == SW_NEC) #define IR_STATUS_RISING (0x10) #define IR_STATUS_FALLING (0x20) static BYTE bState = 0; static BYTE bBitCnt = 0; static DWORD dwIRCode; BYTE bIRStatus; WORD wIRTime; bIRStatus = REG_PLAT_IR_STATUS; wIRTime = REG_PLAT_IR_COUNTER >> ((bIRStatus & IR_STATUS_RISING)? 16: 0); if((bIRStatus & IR_STATUS_FALLING) && wIRTime > 800) { bState = 2; } else { switch(bState) {/* case 0: // wait for rising (L >= 25ms) if((bIRStatus & IR_STATUS_RISING) && wIRTime > 2500) { ++bState; } break; case 1: // wait for falling (H == 9ms) if((bIRStatus & IR_STATUS_FALLING) && wIRTime > 800 && wIRTime < 1000) { ++bState; } else { bState = 0; } break;*/ case 2: // wait for rising (L = 4.5ms for normal, L = 2.25ms for repeat) if((bIRStatus & IR_STATUS_RISING) && wIRTime > 112 && wIRTime < 563) { if(wIRTime > 337) { ++bState; bBitCnt = 0; // prepare for bit receiving } else { bState = 5; // code completed for repeat } } else { bState = 0; } break; case 3: // wait for falling (H = 0.56ms) if((bIRStatus & IR_STATUS_FALLING) && wIRTime > 28 && wIRTime < 84) { ++bState; } else { bState = 0; } break; case 4: // wait for rising (L = 0.56ms for '0', L = 1.69ms for '1') if((bIRStatus & IR_STATUS_RISING) && wIRTime < 225) { dwIRCode = (dwIRCode >> 1) | ((wIRTime > 112) << 31); if(++bBitCnt < 32) { --bState; } else { ++bState; } } else { bState = 0; } break; case 5: // code completed for normal and repeat if(bBitCnt >= 32 && (dwIRCode & 0xffff) == (CUSTOMER_CODE | (CUSTOMER_CODE1 << 8))) { DWORD dwTimeISRKey = OS_GetSysTimer(); if((dwTimeISRKey - _dwTimeISRKeyPrev) >= COUNT_200_MSEC) { BYTE bIRDataCode = dwIRCode >> 16; bIRCheck = !((dwTimeISRKey - _dwTimeISRKeyPrev) < (COUNT_250_MSEC + COUNT_300_MSEC) / 2); _dwTimeISRKeyPrev = dwTimeISRKey; _bKeyGet = bIRDataCode < _IRInfo.bIRMapSize ? _IRInfo.aIRMap[bIRDataCode] : KEY_NO_KEY; __pINTDSRRoutine[INT_NO10][__dwINTDSRCounter[INT_NO10] ++] = DSR_IR; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -