?? input.c
字號:
// *****************************************************************************
// input.cpp INPUT module is used to receive input codes from IR and transfer
// these codes as meaningful values.
// Now it supports two kinds of remote control transmitter :
// Philip SA3010 & NEC PD6122G. Users can use them by "#define
// IR_NEC" or not !
// -----------------------------------------------------------------------------
// Copyright (c) 1996, Cheertek Corp. All rights reserved.
// *****************************************************************************
//#include <intrins.h>
#include "winav.h"
#include "input.h"
// Chuan0.83a, 908 SW IR use INT5 (Temporal Solution)
#if !defined(CHIP_W9928) && !defined(W99132_IR)
sbit btIR = P1 ^ 7; // INT5
#else
sbit btIR = P3 ^ 2; // INT0
#endif
extern DWORD data __dwCountSystem;
extern BYTE data __bISRKey;
// ** TCH1.00b; begin... Total reserve 128 byte (From FF80h-FFFFh/ each bank)
// ** TCH1.72; The code will move to ISR Module as INPUT does not locate in Comon-Bank more.
/*
// [1st] 16 bytes is dummy and conflict w/ Decoder IO.
BYTE code aDummy [16]= {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
// [2nd] 8 bytes is reserved
BYTE code aReserved [8]= {
0, 0, 0, 0, 0, 0, 0, 0
};
// [3rd] 8 bytes is useful
BYTE code aBINData [8]= {
'W', 'B', DECODER_SYSTEM, 0, 0, 0, SW_VERSION, SW_MINOR_VERSION
};
*/ // ** TCH1.72; end...
// [4th] 96 bytes are IR Mapping Table.
// ** TCH1.00b; end...
#include "ir.h"
// wyc.277a-2
// ***********************************************************************
// Function : INPUT_VolumeButtom
// Description : Input VolumeButtom Status
// Arguments : NONE
// Return : input key
// Side Effect :
// ***********************************************************************
#pragma NOAREGS
BYTE INPUT_VolumeButtom(BYTE Status)
{
BYTE bKey; //current volume up/down
if((Status & 0x02)==0x02)
bKey = KEY_VOL_DOWN ;
else
bKey = KEY_VOL_UP ;
return bKey ;
}
// ***********************************************************************
// Function : INPUT_RemoteScan
// Description : Read remote controller input
// Arguments : NONE
// Return : input key
// Side Effect :
// ***********************************************************************
#pragma NOAREGS
BYTE INPUT_RemoteScan(void)
{
BYTE bKey; //current received IR key
// wyc1.10, HKC updated code.
#ifdef IR_CODE_CONTINUE // 1.08 KCHong, support H/W IR repeat mode
#ifdef W99132_IR
extern BYTE bIRContinue;
extern DWORD __dwTimeISRKeyPrev;
// wyc1.20, update HKC and XuLi code for IR continue related code.
#ifdef CHECK_IR_CUSTOMER_CODE // 1.10 KCHong, support custom code in repeat mode.
IRCON= 0x0b;
#else
IRCON= 0x09;
#endif
if(bIRContinue)
{
if(bIRContinue>1)
{
bIRContinue--;
__dwTimeISRKeyPrev=__dwCountSystem;
return KEY_NO_KEY;
}
}
else
{
bIRContinue=6;
}
#endif
#endif
#ifdef W99132_IR
return (aIRMap[IRBUF]);
#else
bKey = _RemoteDetect(); // get IR input
return (bKey);
#endif // W99132_IR
/*
static BYTE bPrevKey= KEY_NO_KEY; // the previous input key
static DWORD gdwRemoteTime=0;
BYTE bKey; //current received IR key
bKey = _RemoteDetect(); // get IR input
if ( bKey != KEY_NO_KEY )
{
if ( bKey == bPrevKey )
{
// same key code within 250 msec
if ( (__dwCountSystem - gdwRemoteTime) < COUNT_250_MSEC )
bKey = KEY_NO_KEY;
}
gdwRemoteTime = __dwCountSystem;
}
if ( bKey != KEY_NO_KEY )
bPrevKey = bKey;
return (bKey);
*/
}
// ***********************************************************************
// Function : Delay100us
// Description : delay 100 us each time is called
// can be modified for different CPU speed
// ***********************************************************************
#pragma NOAREGS
void Delay100us(void)
{
BYTE data c;
// ** TCH2.33; begin...
#if CPU_SPEED == CPU_36M
c = 116;
#endif
#if CPU_SPEED == CPU_33M
c = 106;
#endif
#if CPU_SPEED == CPU_30M
c = 96;
#endif
// ** TCH2.33; end...
// Chuan2.80p, Turbo 51 need remeasure the value.
#if CPU_SPEED == CPU_27M
c = 87; // Chuan0.84p, Add T~=100uS for 27MHZ CPU
#endif
#if CPU_SPEED == CPU_24M
c = 77; // T~=100uS for 24MHZ CPU
#endif
#if CPU_SPEED == CPU_16M
c = 49; // LJY0.83, T~=100uS for 16MHZ CPU
#endif
#if CPU_SPEED == CPU_12M
c = 41; // T~=100uS for 12MHZ CPU
#endif
while (c-- != 0);
}
// ***********************************************************************
// Function : _RemoteDetect
// Description : Detect the input IR code
// Philip IR MSB first
// Philip = start bit(1.5) + control bit (1) + system bit( 5)+command(6)
// NEC = leader code+ customer(8) +customer'(8)+data(8) +data'(8)
// NEC IR LSB first
// Return : input Key
// Side Effect :
// ***********************************************************************
#ifndef W99132_IR
#pragma NOAREGS
BYTE _RemoteDetect(void)
{
#ifndef IR_NEC // for philip SAA3010
BYTE data bCount, i;
BYTE data bCode;
BIT sbBit;
//---- check start bit => 1.5 bits, logic 1 (signal pattern : low, high, low) ----
for (bCount=0; !btIR; bCount++) Delay100us();
if ((bCount < 10) || (bCount > 12)) return (KEY_NO_KEY); // start bit error
for (bCount=0; (btIR)&&(bCount<10); bCount++) Delay100us();
if ((bCount < 4) || (bCount > 7)) return (KEY_NO_KEY); // start bit error
//---- check control bit => 1 bit, maybe logic 1 or logic 0 ----
for (bCount=10; bCount!=0; bCount--) Delay100us(); //delay 1ms first, then check control bit=1 or 0
if (btIR) // control bit=0
{
for (bCount=0; (btIR)&&(bCount<10); bCount++) Delay100us();
if ((bCount < 6) || (bCount > 8)) return (KEY_NO_KEY); // control bit error
for (bCount=14-bCount; bCount!=0; bCount--) Delay100us();
}
else // control bit=1
{
// for (bCount=0; !btIR; bCount++) Delay100us();// without noise
for (bCount=0; ; bCount++) // bCount=0,1: continue to wait for high
{ // bCount=3,4,5 : error
Delay100us(); // bCount=6,7,8,9 : correct range
if (btIR && (bCount>1)) break;
} // bCount=2 : skip and looked as correct code
if (bCount == 2) // skip noise
{
for (i=0; i<6; i++) Delay100us();
bCount=9;
}
else
if ((bCount < 6) || (bCount > 9)) return (KEY_NO_KEY); // controal bit error
for (bCount=14-bCount; bCount!=0; bCount--) Delay100us();
}
// adjust the timing offset that result from btIR detection
// cross the boundary between two bits
for (bCount=2; bCount!=0; bCount--) Delay100us();
//---- read system code => 5 bits ----( each bit is 1.68 ms )
bCode = 0;
for (i=0; i<5; i++)
{
bCode <<= 1;
sbBit = btIR; // system bit
for (bCount=8; bCount!=0; bCount--) Delay100us(); // about 0.84ms
if (btIR != !sbBit)
{
btIR= 1; // test
return (KEY_NO_KEY); // system bit error
}
if (!sbBit) bCode |= 0x01;
for (bCount=8; bCount!=0; bCount--) Delay100us(); // about 0.84ms
}
#ifdef CHECK_IR_CUSTOMER_CODE
if (bCode != CUSTOMER_CODE )
return KEY_NO_KEY; // system code error
#endif // CHECK_IR_CUSTOMER_CODE
//---- read data code => 6 bits ----
bCode = 0;
for (i=0; i<6; i++)
{
bCode <<= 1;
sbBit = btIR; // command bit
for (bCount=8; bCount!=0; bCount--) Delay100us(); // about 0.84ms
if (btIR != !sbBit) return (KEY_NO_KEY); // command bit error
if (!sbBit) bCode |= 0x01;
for (bCount=8; bCount!=0; bCount--) Delay100us(); // about 0.84ms
}
#else // NEC IR , LSB first
static gbCodeKeep=KEY_NO_KEY;
static DWORD dwPreKeyTime=NULL;
// BYTE data bCount, i, j;
// BYTE data aCodes[4];
// BYTE data bByte;
BYTE IDATA bCount, i, j;
BYTE aCodes[4];
BYTE IDATA bByte;
// ********** Leader signal (low 9ms + high 4.5 ms) **********
for (bCount=0; !btIR; bCount++) Delay100us(); //Leader signal low = 9ms
// ** TCH1.60a-2; if ((bCount < 87) || (bCount > 93)) return KEY_NO_KEY;
// For Lucky Panel, will record 86. Suppose < 85 is safer
if ((bCount < 85) || (bCount > 93)) return KEY_NO_KEY;
for (bCount=0; (btIR)&&(bCount<54) ; bCount++) Delay100us(); //Leader signal high = 4.5ms
if ((bCount < 40) || (bCount > 48)) // outside high 4.5 range
{ // consider same key is pressed
#ifdef IR_CODE_CONTINUE
// if input the same key, only leader code is sent
// low (9ms) , high (2.25), low (0.56)
if ((bCount>=19) && (bCount<=24) ) // key remain pressed
for (bCount=0; !btIR ; bCount++) Delay100us();
if ((bCount>=4) && (bCount<=7))
{
// to prevent the case that when the code are lost
// leader+code+leader+leader + New key(leader+code(x))
// in the case should not return the prev. key.
if ( (__dwCountSystem-dwPreKeyTime) > COUNT_250_MSEC )
{
// if the host process key too long
// must reset the time for continue key
// but it will cause the "code lost" key return prev. key
// But if reset time
// the code continue will fail
// dwPreKeyTime=__dwCountSystem;
return KEY_NO_KEY;
}
dwPreKeyTime=__dwCountSystem;
return gbCodeKeep ; // return the previous input key
}
#endif
return KEY_NO_KEY;
}
// *********** Read Code *************
// logic 0 = low (0.56) + high (0.56)
// logic 1= low (0.56) + high (1.68)
for (i=0; i<4; i++)
{
bByte = 0;
for (j=0; j<8; j++)
{
for (bCount=0; (!btIR); bCount++) Delay100us(); //bypass low signal at INT0
for (bCount=0; (btIR)&&(bCount<30) ; bCount++) Delay100us();
if (bCount == 0)
{
j--;
continue; // maybe signal noise
}
bByte >>= 1; // shift right one bit
if (bCount >= 9) // bit=0 => bCount<9; bit=1 => bCount>9
{ // > 0.9 ms==> logic 1
// else ==> logic 0
if (bCount >= 30) return KEY_NO_KEY; // bCount>30 => error
bByte |= 0x80;
}
}
aCodes[i] = bByte;
}
#ifdef _SHOW_IR_MAP
{
extern BYTE _bIRMap [], _bIRGet;
for ( i= 0; i< 4; i++ )
{
_bIRMap [i]= aCodes [i];
}
_bIRGet= TRUE;
}
#endif // _SHOW_IR_MAP
#ifdef CHECK_IR_CUSTOMER_CODE
if ( aCodes[0] != CUSTOMER_CODE )
return KEY_NO_KEY; // system code error
if ( aCodes[1] != CUSTOMER_CODE1 )
return KEY_NO_KEY; // system code error
#endif // CHECK_IR_CUSTOMER_CODE
if ((aCodes[0]==0) && (aCodes[1]==0) &&
(aCodes[2]==0) && (aCodes[3]==0)) // key remain pressed, only leader code sent
{
return gbCodeKeep;
}
else
{
// each bit of aCodes[2] will be invert of aCodes[3]
if (aCodes[2] == ~aCodes[3])
{
gbCodeKeep = aIRMap[aCodes[2]];
dwPreKeyTime=__dwCountSystem;
return gbCodeKeep;
}
else
return KEY_NO_KEY;
}
#endif
}
#endif // W99132_IR
#ifdef W99132_IR
//#########################################
void CPU132_InitIR()
{
/// IRCON // enable remote control(bit 0)
// enable custom code check(bit 1)
// enable repeat code interrupt(bit 3)
// (Bit5:Bit4) Philips (0:1), NEC (0:0), SANYO (1:0)
// IRFREQ=83; //for 27Mhz oscillator
// Micky1.10-2, due to PLLR modify from 399 to 360MHz
// ** TCH2.33; #if MPEG_PLL >= PLL_399MHZ // ** TCH2.33; from "==" to ">="
IRFREQ= 128- ( (20L *(DWORD)CPU_SPEED/ 1000) / 12 ); // TCH; 0.34 follow W99132 spec.
// ** TCH2.33; #elif MPEG_PLL == PLL_360MHZ
// wyc1.21, set 78 for 360MHz by Brian's suggestions.
// ** TCH2.33; IRFREQ= 78;
// ** TCH2.33; #endif
#ifndef IR_NEC // for philip SAA3010
#ifdef CHECK_IR_CUSTOMER_CODE
CCODEL= CUSTOMER_CODE1; // ** TCH0.37;
CCODEH= CUSTOMER_CODE; // ** TCH0.37;
IRCON= 0x13; // ** 0.20; enable check
#else
IRCON= 0x11;
#endif // CHECK_IR_CUSTOMER_CODE
#else // for NEC IR
#ifdef CHECK_IR_CUSTOMER_CODE
CCODEL= CUSTOMER_CODE1; // ** TCH0.37;
CCODEH= CUSTOMER_CODE; // ** TCH0.37;
IRCON= 0x03; // ** 0.20; enable check
#else
IRCON= 0x01;
#endif // CHECK_IR_CUSTOMER_CODE
#endif
}
/*
void CPU132_EnableIR(char bEnable)
{
}
char CPU132_GetFirstCustomerCode()
{
return(0);
}
char CPU132_GetSecondCustomerCode()
{
return(0);
}
char CPU132_GetDataCode()
{
return(0);
}
*/
#endif // W99132_IR
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -