📄 tirrc5.c.svn-base
字号:
/**
* This code and information is part of Trident DPTV API (TDAPI)
*
* Copyright (C) Trident Multimedia Technologies (Shanghai) Co., Ltd.
* 2002 - 2003 All rights reserved.
*
* This file provides functions for TV or demoboard remote controller.
*
* Revision:
* 24/08/2004 Fixed bugs by Ivan Wen.
* 03/04/2004 Modify RC5 part(decode & repeat) by Max and Joy
* 04/18/2003 Added repeat key support by Archie
* 08/01/2002 Created by Rick, York, Joy and Archie
*
*/
#include "tdefs.h"
#include "tio.h"
#include "tutils.h"
#include "tvkey.h"
#include "tRemote.h"
#include "thilevel.h"
#include "ttimer.h"
#include "tvdebug.h"
/*remote flag*/
static Byte s_ucRemoteFlag = 0;
/*the following two global variables are used by remote routines*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode);
static Gdata struct tagRemoteData
{
Word wRemoteVal; /*store the value of a code*/
Byte ucRemoteBit; /*store the last bit*/
Byte ucRemoteCount; /*used to count shift times and generate s_RemoteData.ucRemoteTemp*/
Byte ucReleaseTimer;
Bool bToogleBit : 1; /*save toogle bit*/
Bool bDetect13Bit : 1; /*detect 13 bit*/
Byte ucPreviousCountVal; /*timer count value of last time*/
Byte ucSystemCode;
Byte ucRemoteCode;
Byte ucOffset;
Byte ucKeyNum;
} s_RemoteData;
static Void tdIRRC51msTimer(Void)
{
s_RemoteData.ucReleaseTimer++;
if (t_RemoteData.wCount == t_RemoteData.wFirstDelay)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode);
t_RemoteData.wCount--;
} else if (t_RemoteData.wCount)
{
t_RemoteData.wCount--;
if (tdTestValBitTrue(s_ucRemoteFlag, _RF_RC_LEADERCODE_))
{
if (t_RemoteData.wCount == 0)
{
tdAddVirtualKey(s_RemoteData.ucRemoteCode /*| _VK_STATUS_DOWN_*/);
tdClearValBit(s_ucRemoteFlag, _RF_RC_LEADERCODE_);
t_RemoteData.wCount = t_RemoteData.wRepeatDelay - 1;
}
}
}
/* After receiving the 13th bit, wait 3ms; */
/* If none another interrupt occurs, invoke the functiton to get the 14th bit(0).*/
if (s_RemoteData.ucReleaseTimer >= 3 && s_RemoteData.bDetect13Bit)
{
tdRemoteCodeDetect(255);
}
}
static Byte tdGetTimeInterval(Byte ucCurrentCountVal)
{
/* when the INT0 interrupt the timer interrupt service */
if (!ucCurrentCountVal)
ucCurrentCountVal = tdLoadInitTimerCount();
#ifdef _TIMERCOUNT_DOWN_
if (ucCurrentCountVal < s_RemoteData.ucPreviousCountVal)
ucCurrentCountVal = s_RemoteData.ucPreviousCountVal - ucCurrentCountVal;
else
ucCurrentCountVal = s_RemoteData.ucPreviousCountVal + tdGetTimerBInterval() - ucCurrentCountVal;
#else
if (ucCurrentCountVal >= s_RemoteData.ucPreviousCountVal)
ucCurrentCountVal = ucCurrentCountVal - s_RemoteData.ucPreviousCountVal;
else
ucCurrentCountVal = ucCurrentCountVal + tdGetTimerBInterval() - s_RemoteData.ucPreviousCountVal;
#endif
return ucCurrentCountVal;
}
static Void tdIRRC5Service(Void)
{
IByte ucRemoteCode;
IByte ucCurrentCountVal;
ucCurrentCountVal = tdGetTimerBCurrentCount();
#ifdef _TIMERCOUNT_DOWN_
if(ucCurrentCountVal > tdLoadInitTimerCount())
#else
if(ucCurrentCountVal < tdLoadInitTimerCount())
#endif
ucCurrentCountVal = tdLoadInitTimerCount();
tdClearInterruptPend();
ucRemoteCode = tdGetTimeInterval(ucCurrentCountVal);
s_RemoteData.ucPreviousCountVal = ucCurrentCountVal;
tdRemoteCodeDetect(ucRemoteCode); /* Analyse remote key */
}
/**
* This function translates the pressed remote key code.
* When user press on the remote controller, the key code
* will store in a global value and let the function RemoteInput()
* return key code.
*
*
* @param ucRemoteCode(I) - the time distance between two pulse
* generated by remote controller
* @return None
* @see tdRemoteService
*/
static Void tdRemoteCodeDetect(Byte ucRemoteCode)
{
IByte ucIndex;
IByte ucRemoteVal;
IByte ucSystemCode;
IByte i;
static Byte s_ucRepeatCnt = 0;
if (s_RemoteData.bDetect13Bit)
{/* the 14th bit */
s_RemoteData.bDetect13Bit = _FALSE_;
tdLeftShift1(s_RemoteData.wRemoteVal);
if (ucRemoteCode >= pRC5Remote->Remote_1B_Min && ucRemoteCode <= pRC5Remote->Remote_1B_Max)
s_RemoteData.wRemoteVal |= 1;
goto lastbit;
}
if (s_RemoteData.ucRemoteCount == 0)
{ /* first time */
firstbit:
s_RemoteData.ucRemoteCount = 1;
s_RemoteData.ucRemoteBit = 1;
s_RemoteData.wRemoteVal = 1;
s_RemoteData.bDetect13Bit = _FALSE_;
return;
} else if ((pRC5Remote->Remote_1B_Min <= ucRemoteCode) && (ucRemoteCode <= pRC5Remote->Remote_1B_Max)) /* 1B time */
{ /* C(i) = C(i - 1) */
tdLeftShift1(s_RemoteData.wRemoteVal);
s_RemoteData.wRemoteVal |= s_RemoteData.ucRemoteBit;
s_RemoteData.ucRemoteCount++;
} else if ((pRC5Remote->Remote_15B_Min <= ucRemoteCode) && (ucRemoteCode <= pRC5Remote->Remote_15B_Max)) /* 1.5B time */
{
tdLeftShift1(s_RemoteData.wRemoteVal);
if (s_RemoteData.ucRemoteBit == 1)
{ /* C(i) = 0, C(i+1) = 0 */
tdLeftShift1(s_RemoteData.wRemoteVal);
s_RemoteData.ucRemoteBit = 0;
s_RemoteData.ucRemoteCount += 2;
} else
{ /* C(i) = 1 */
s_RemoteData.wRemoteVal |= 1;
s_RemoteData.ucRemoteBit = 1;
s_RemoteData.ucRemoteCount++;
}
} else if ((pRC5Remote->Remote_2B_Min <= ucRemoteCode) && (ucRemoteCode <= pRC5Remote->Remote_2B_Max)) /* 2B time */
{ /* C(i) = 0, C(i+1) = 1 */
tdLeftShift1(s_RemoteData.wRemoteVal);
tdLeftShift1(s_RemoteData.wRemoteVal);
s_RemoteData.wRemoteVal |= 1;
s_RemoteData.ucRemoteBit = 1;
s_RemoteData.ucRemoteCount += 2;
}
else
{ /* error */
#ifdef DEBUG_RMT
tvDebugPrint1("ev=%d\n", ucRemoteCode);
#endif
goto firstbit;
}
if (s_RemoteData.ucRemoteCount == 13)
{
s_RemoteData.ucReleaseTimer = 0;
if ((Byte)s_RemoteData.wRemoteVal & 0x01) /* second last bit is 1 */
{
s_RemoteData.bDetect13Bit = _TRUE_;
return;
}
}
if (s_RemoteData.ucRemoteCount >= 14)
{
lastbit:
/*if the second bit is 1, add 0x80 to expend key number. */
ucRemoteVal = ((Byte)s_RemoteData.wRemoteVal & 0x3f) + ((s_RemoteData.wRemoteVal & 0x1000) ? 0x00 : 0x40);
#ifdef DEBUG_RMT
tvDebugPrint1("rmt val=%x\n", s_RemoteData.wRemoteVal);
#endif
ucSystemCode = (Byte)(s_RemoteData.wRemoteVal >> 6) & 0x1F;
if (pRC5Remote->System_Code_Num == 0) /*the protocol hasn't system code*/
{
s_RemoteData.ucOffset = pRC5Remote->RemoteKeySet[0].ucKeySetOffset;
s_RemoteData.ucKeyNum = pRC5Remote->RemoteKeySet[0].ucKeyNum << 1;
}
else
{
for (i = 0; i < pRC5Remote->System_Code_Num; i++)
{
if (pRC5Remote->RemoteKeySet[i].ucSystemCode == ucSystemCode)
break;
}
if (i == pRC5Remote->System_Code_Num)
goto firstbit; //error
else
{
s_RemoteData.ucOffset = pRC5Remote->RemoteKeySet[i].ucKeySetOffset;
s_RemoteData.ucKeyNum = pRC5Remote->RemoteKeySet[i].ucKeyNum << 1;
}
}
ucIndex = 0;
while ((*((RPByte)pRC5Remote + s_RemoteData.ucOffset + ucIndex) != (Byte)(ucRemoteVal)) && (ucIndex < s_RemoteData.ucKeyNum))
ucIndex += 2;
if (ucIndex < s_RemoteData.ucKeyNum)
{
ucIndex = *((RPByte)pRC5Remote + s_RemoteData.ucOffset + ucIndex + 1);
if ((ucIndex == s_RemoteData.ucRemoteCode) && t_RemoteData.wCount)
{
if(s_RemoteData.bToogleBit != ( (s_RemoteData.wRemoteVal & 0x800)?_TRUE_:_FALSE_))
{
if(t_RemoteData.wCount < t_RemoteData.wFirstDelay - t_RemoteData.wRepeatDelay)
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
}
else
{
if (t_RemoteData.wCount < t_RemoteData.wFirstDelay - t_RemoteData.wRepeatDelay)
{
tdSetValBit(s_ucRemoteFlag, _RF_RC_LEADERCODE_); /*set repeat flag*/
t_RemoteData.wCount = 20; /* set the repeat flag immediately */
}
}
} else
{
if(s_RemoteData.bToogleBit != ( (s_RemoteData.wRemoteVal & 0x800)?_TRUE_:_FALSE_))
{
s_ucRepeatCnt = 0;
s_RemoteData.ucRemoteCode = ucIndex;
t_RemoteData.wCount = t_RemoteData.wFirstDelay;
}
else
{ /* value is different, but the toggle bit is same */
tvDebugPrint("3\n");
tdSetValBit(s_ucRemoteFlag, _RF_RC_LEADERCODE_); /*set repeat flag*/
t_RemoteData.wCount = 1; /* set the repeat flag immediately */
}
}
/*save toggle bit*/
s_RemoteData.bToogleBit = (s_RemoteData.wRemoteVal & 0x800)?_TRUE_:_FALSE_;
}
s_RemoteData.ucRemoteCount = 0;
}
}
Code RemoteControllerDriver f_IRRC5Driver =
{
tdIRRC51msTimer, tdIRRC5Service
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -