📄 keypad.c
字号:
//---------------------------------------------------------------------------
// Terawins Inc. Company Confidential Strictly Private
//
// $Archive: Keypad.c $
// $Revision: 0.01 $
// $Author: jwang $
// $Date: 2002/06/19 23:49:23 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 2002 (c) Terawins Inc.
// This is an unpublished work.
// --------------------------------------------------------------------------
#include "reg51.h"
#include "common.h"
#include "System.h"
#include "Struct.h"
#include "Keypad.h"
#include "TW10xReg.h"
#include "OSDDraw.h"
#include "OSDCtrl.h"
#include "TwoWire.h"
#include "Display.h"
#include "T101_Util.h"
extern void CVBS_S1(void);
extern void CVBS_S2(void);
extern void CVBS_S3(void);
extern void CVBS_S4(void);
extern void SVideo_S(void);
#ifdef T515
void switch_T515(uCHAR);
#endif
#ifdef TIMER0
extern void Timer0Reset(void);
extern void Timer0Stop(void);
extern void Timer0Start(void);
#endif
static bit FLAG_SOURCE_WAY;
extern bit m_bKyPowerOn;
extern uWORD code ucaZoomDataP0_NTSC[];
extern uCHAR SignalDefine; // add by Sherman 06'02'23
typedef struct tag_sKEYPAD_FLD
{
uCHAR cAddress; // Address of field
uCHAR cMask; // Mask for field after shifted right
uCHAR cFlagsShift; // Flags & Shift byte:
// [7] Type: 1=external, 0=internal
// [6] Polarity: 1=high true, 0=low true
// [4] Shift direction: 1=left, 0=right
// [2:0] Shift to Right Justify
} sKEYPADFLD;
#define nKEYFLDS 1
sKEYPADFLD code sKeyFlds={
//PORT MASK FLAGS/SHIFT
KEYPORT2, 0x1c, 0x00
};
uCHAR idata m_cCurreKey;
uCHAR idata m_cPreKey;
uWORD idata m_wAccelPollCnt;
uCHAR idata m_cItem;
extern uCHAR idata m_cTV_Num;
extern bit m_bTV_Num_Bits;
extern bit m_bFactryReady;
extern bit m_bFactryMode;
extern uCHAR m_cFactryCnt;
extern bit m_bRelease;
extern bit m_bChipPowerOn;
extern bit m_bKyBlocked;
extern uCHAR idata m_cOSDEvent;
extern uCHAR idata m_cOSDFunc;
extern uCHAR idata m_cOSDMenu;
extern uCHAR idata m_cSource;
//extern uCHAR idata m_cSource_AA;
//extern uCHAR idata m_cSource_BB;
extern uWORD idata m_wBuff[3];
extern uCHAR idata m_cBuff[5];
extern uDWORD m_dwBuff[2];
extern uCHAR idata m_cScaleratio;
extern uWORD m_wHRes;
extern uWORD m_wVRes;
extern uWORD idata m_wVTotal;
extern uCHAR idata m_cStandard;
extern uCHAR idata m_cChroma;
extern bit comp_key;
static uCHAR idata FLAG_LCD;
extern bit FLAG_I2C;
void kyKeypadInit(void)
{
m_wAccelPollCnt=0;
m_cCurreKey=m_cPreKey=0xFF;
m_cOSDEvent=0;
m_cOSDFunc=0;
m_cOSDMenu=idNULLMENU;
m_cItem=1;
}
void kyKeypad(void)
{
if(kyKeypadScan())
{
Timer0Reset();
kyFindFunc();
}
else
m_cPreKey=m_cCurreKey;
}
/************add the code by tom for then the handback is 0 force power on ************/
#if 0
void FORCE_POWER_ON(void)
{
// static uCHAR OLD_SOURCE;
static bit flag_aa;
static bit flag_bb;
if((!HB_EN)&&(flag_aa==0))
{
flag_aa=1;
// if(flag_bb==0)
// {
// flag_bb=1;
// m_cSource=OLD_SOURCE;
I2CWriteByte(EEPVIDEOBLOCK, idVIDEO_SOURCE_INDEX,m_cSource);
//POWER_ON_InITial_AA();
m_bChipPowerOn=1;
//m_bKyPowerOn=0;
//}
}
else
{
if ((flag_aa)&&(HB_EN))
{
flag_aa=0;
//if( flag_bb)
// {
LED_RED = 0;
// m_cSource=OLD_SOURCE;
flag_bb=0;
m_bKyPowerOn=0;
//}
}
}
/**************the end****************************************/
}
#endif
uCHAR fMenuOpen=0;
void PowerBkLt(void)
{
I2CWriteByte(0x50, 0xe3, I2CReadByte(0x50, 0xe3)^0x20);
twdDelay(100);
OSDDisable();
}
bit kyKeypadScan(void)
{
uCHAR cTemp;
while(1)
{
cTemp=ReadPort();
m_cCurreKey=sKeyFlds.cMask&(0xFF-cTemp);
/*
m_cCurreKey=TRANS_KEY(m_cCurreKey);
if(m_cCurreKey==kyMENU)
{
if(!comp_key)
{
m_cCurreKey=kyMENU;
comp_key=1;
}
else
{
m_cCurreKey=KEY_UP;
}
}
*/
#if 1
if(m_cCurreKey==kySOURCE || m_cCurreKey==kyMENU ||( m_cCurreKey==kyDECREASE&&fMenuOpen==0))
{
if(!m_bRelease)
{
m_bRelease=1;
if((m_cCurreKey==kyDECREASE)&&(fMenuOpen==0))
PowerBkLt();
return 1;
}
}
else
{
m_bRelease=0;
if(m_cCurreKey){
if((m_cCurreKey==kyDECREASE)&&(fMenuOpen==0))
PowerBkLt();
return 1;
}
if(!m_cCurreKey) //no key pressed
return 0;
}
#else
/*
if(m_cCurreKey==m_cPreKey)
return 0;
else
return 1;
*/
m_bRelease=0;
if(m_cCurreKey)
return 1;
if(!m_cCurreKey) //no key pressed
return 0;
#endif
}
}
#if 0
uCHAR TRANS_KEY(uCHAR KEY_A)
{
static char Temp_key;
static char CurreKey;
//static bit h;
CurreKey=KEY_A;
#if 1
if(CurreKey==0x00)
{
/*
if(h)
{
if(Temp_key==kyPOWER)
{
Temp_key=0x00;
}
}
*/
CurreKey=Temp_key;
//h=0;
Temp_key=0x00;
}
else
{
if(CurreKey==Temp_key)
{
/*
if(Temp_key==kyPOWER)
{
CurreKey=0x00;
}
else
*/
// {
/*
if (Temp_key==kySOURCE)
{
if(m_wTimer0Cnt_AA<=800)
{
h=1;
CurreKey=kyPOWER;
}
else
{
CurreKey=0x00;
}
}
else
{
CurreKey=0x00;
}
*/
CurreKey=0x00;
//}
}
else
if(CurreKey)
{
if(CurreKey==kyINCREASE)
{
CurreKey=kyINCREASE;
twdDelay(50);
}
else if(CurreKey==kyDECREASE)
{
CurreKey= kyDECREASE;
twdDelay(50);
}
else
{
Temp_key=CurreKey;
CurreKey=0x00;
}
// Timer0Start();
//tom Timer0Start_AA();
// Timer0Stop_AA();
}
}
#endif
return CurreKey;
}
#endif
void kyFindFunc(void)
{
#if 1
if(m_cCurreKey==m_cPreKey)
{
if((m_cCurreKey==kyDECREASE)||(m_cCurreKey==kyINCREASE))
{
if(kyFindEvent())
{
if(m_cOSDEvent!=FUNCOUNT)
OSDEventMgr();
m_cPreKey=m_cCurreKey;
m_wAccelPollCnt=0;
kyIncPollCount();
}
}
else
{
if(!kyIncPollCount())
{
if(kyFindEvent())
OSDEventMgr();
}
}
}
else
{
if(kyFindEvent())
{
if(m_cOSDEvent!=FUNCOUNT)
OSDEventMgr();
m_cPreKey=m_cCurreKey;
m_wAccelPollCnt=0;
kyIncPollCount();
}
}
#else
kyFindEvent();
#endif
}
uCHAR ReadPort(void)
{
uCHAR cKey;
switch(sKeyFlds.cAddress){
case 0: cKey=P0; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -