📄 main.c
字号:
}
break;
//--------------------------------------------------------------------------------------
case SECAM:
if( !Is50Hz() )
{
std = NTSC;
changed = 1;
check_cnt = 0;
secam_cnt = 0;
}
if( !(ReadTW88(0x30) & 0x80) ) secam_cnt++;
if( ++check_cnt>=10*10 )
{
#ifdef DEBUG_DECODER
dPrintf("%4d", secam_cnt);
#endif
if( secam_cnt<=7*10 )
{
std = PAL;
changed = 1;
}
check_cnt = 0;
secam_cnt = 0;
}
break;
default:
break;
}
if( changed )
{
SetVInputStd( std );
InitVideoData(std);
DisplayInput();
switch( std )
{
case NTSC: WriteDecoder(STD, 0x08); break;
case PAL: WriteDecoder(STD, 0x09); break;
case SECAM: WriteDecoder(STD, 0x0a); break;
}
#ifdef DEBUG_DECODER
dPrintf("\r\n-------> Source changed %d", (WORD)VInputStd);
#endif
delay(99);
}
#else // not ID_CHECK_BY_FW
BYTE std1, std, cnt=0, trycnt=0, ChangedNoinput;
// LJY101002
// Algorithm I
//if( InputSelection == TV ) return;
if( InputSelection == COMPONENT ) return;
if( ( InputSelection == TV ) && (VInputStdDetectMode != AUTO) ) return;
//if( VInputStdDetectMode==AUTO ) {
std1 = NOINPUT;
while(1)
{ // keep checking until it's stable.(check cnt)
std = DetectDecoderInput();
trycnt++;
if( trycnt>= 200 ) // so many try, but unstable
break;
if( std!=UNKNOWN && std!=VInputStd )
{
//changed!!
if( std == std1 ) // same as previous one.
cnt++;
else
{ // ooh.. different from previous one.
cnt = 0;
std1 = std;
}
if( cnt >= 2) { //100 ) {
LCDPowerOFF();
if( std == NOINPUT )
{ //some input->NOINPUT
SetVInputStd( std );
ChangedNoinput = 1; // Diaplay Input Information for no signal.
}
else if( VInputStd==NOINPUT )
{ //NOINPUT->some input
SetVInputStd( std );
InitVideoData(std);
ChangedNoinput = 0; // Diaplay Input Information for no signal.
}
else { //some input1->some input2
// LCDPowerOFF();
//PanelMute(1);
SetVInputStd( std );
InitVideoData(std);
delay(50);
// LCDPowerON(0);
ChangedNoinput = 0; // Diaplay Input Information for no signal.
}
LCDPowerON(0);
DisplayInput();
DisplayInputHold = ChangedNoinput;
break;
}
}
else
{
if( std == NOINPUT ) // NOINPUT->NOINPUT
DisplayInputHold = 1; // Hold input information in no signal.
else
DisplayInputHold = 0; // clear
break;
}
}
//}
#endif // ID_CHECK_BY_FW
}
BYTE ReadVInputSTD(void)
{
BYTE std;
if( IsNoInput() ) return 1; // Noinput!!
std = ReadDecoder(0x1c) & 0xf0;
if( std & 0x80 ) return 1; // Detection in progress..
else
return ((( std & 0x70 ) >> 4 ) + 1 );
}
BYTE GetVInputStdInx(void)
{
BYTE i, std;
std = ReadVInputSTD();
switch( std )
{
case NTSC4:
case PALM:
case PAL60:
case NTSC: IVF = 60; IHF = 15723; break; // 15734
case SECAM:
case PALN:
case PAL: IVF = 50; IHF = 15723; break; // 15625
default: IVF = 0; IHF = 0; break;
}
for(i=0; ; i++)
{
if( struct_VInputStd[i].Id ==std )
return i;
if( struct_VInputStd[i].Id ==0 )
break;
}
return 0;
}
#ifdef WIDE_SCREEN
BYTE GetVInputStd(void)
{
return VInputStd;
}
#endif
void SetVInputStd(BYTE newd)
{
VInputStd = newd;
#ifdef DEBUG
ePrintf("\r\n(SetVInputStd) VInputStd:(%s)", struct_VInputStd[GetVInputStdInx()].Name);
#endif
switch( VInputStd )
{
#ifdef SUPPORT_NTSC4
case NTSC4:
#endif
#ifdef SUPPORT_PALM
case PALM:
#endif
#ifdef SUPPORT_PAL60
case PAL60:
#endif
case NTSC: IVF = 60; IHF = 15723; break; // 15734
#ifdef SUPPORT_SECAM
case SECAM:
#endif
#ifdef SUPPORT_PALN
case PALN:
#endif
#ifdef SUPPORT_PAL
case PAL: IVF = 50; IHF = 15723; break; // 15625
#endif
default: IVF = 0; IHF = 0; break;
}
}
BYTE GetInputSelection(void)
{
return InputSelection;
}
BYTE GetNextInputSelection(void)
{
BYTE i;
for (i=1; ;i++)
if( struct_InputSelection[i].Id==InputSelection ) break;
i++;
if( struct_InputSelection[i].Id == 0 ) i=1;
return struct_InputSelection[i].Id;
}
void PowerDown_XTAL(bit flag)
{
if( flag ) P3_7 = 1;
else P3_7 = 0;
}
void ChangeInput(BYTE newsel)
{
extern CODE struct _PCMDATA PCMDATA[];
#ifdef DEBUG
BYTE i;
#endif
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
BYTE ret;
#endif
if( InputSelection==newsel ) return;
DisplayInputHold = 0; // Refresh Input info.
ClearOSDInfo();
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
if( (newsel == DTV) || (newsel == PC) )
{
LCDPowerOFF();//PanelMute(1);
}
else
#endif // SUPPORT_PC || SUPPORT_DTV
LCDPowerOFF();
// PanelMute(1);
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
if( (InputSelection == DTV) || (InputSelection == PC) )
{
DPMSmodeON();
}
#endif // SUPPORT_PC || SUPPORT_DTV
InputSelection = newsel;
#ifdef DEBUG
for (i=1; ;i++)
if( struct_InputSelection[i].Id==InputSelection ) break;
Printf("\r\n ->->->->->->->->->->-> Changed Input: %s(%02x)", struct_InputSelection[i].Name, (WORD)InputSelection);
#endif
#ifdef SUPPORT_TELETEXT
if( IsTeleTextOn() ) TeleTextONOFF();
#endif // SUPPORT_TELETEXT
InitVideoData(VInputStd);
switch(InputSelection)
{
case COMPOSITE: COMPOSITEInput();
ExtAudio();
break;
#ifdef SUPPORT_SVIDEO
case SVIDEO: SVIDEOInput();
ExtAudio();
break;
#endif
#ifdef SUPPORT_COMPONENT
case COMPONENT:
COMPONENTInput();
ExtAudio();
break;
#endif
#ifdef SUPPORT_TV
case TV: TVInput();
TunerAudio();
GetFirstChannel();
break;
#endif
#ifdef SUPPORT_PC
case PC:
AVGAInput(); // RGB HV
AutoPHPCalDisable();
#ifdef TW9908
WriteDecoder(OPFORM, 0x66); // Decoder tri-state
#endif
//SelectADCmux(PC);
PCAudio();
tic_pc = 0;
ret = DetectAndSetForVGAInput(1);
break;
#endif
#ifdef SUPPORT_DTV
case DTV:
DTVInput();
AutoPHPCalDisable();
ExtAudio();
tic_pc = 0;
ret = DetectAndSetForVGAInput(1);
break;
#endif
}
SaveInputSelectionEE(InputSelection); // HHY 1.31
//#ifdef WIDE_SCREEN
// WideScreenMode = WIDESCREEN_WIDE;
//#endif
//InitOSDMenu(); // Standby OSD Menu
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
if( InputSelection==PC || InputSelection==DTV ) {
if( ret==TRUE ) {
//DisplayInput();
LCDPowerON(0);
}
}
else
#endif
{
DisplayInput();
#ifdef SUPPORT_COMPONENT
if( InputSelection == COMPONENT ){
//delay(30);
ComponentMode = 0xff;
CheckDecoderComponent();
}
#endif
if( InputSelection != COMPONENT ) {
delay(30);
CheckDecoderInput();
}
//----- Check DIP Switch ---------------
CheckDipSwitch();
//DisplayInput();
LCDPowerON(0);
}
}
void PowerLED(BYTE flag)
{
if( flag==ON ) {
P0_4 = 0;
P0_5 = 0;
dPuts("\r\n(PowerLED)-ON");
}
else {
P0_4 = 1;
P0_5 = 0;
dPuts("\r\n(PowerLED)-OFF");
}
}
void PowerOff(void)
{
dPuts("\r\n++(PowerOff)__");
// PowerMode = OFF;
AudioOff();
#ifdef SUPPORT_TELETEXT
if( IsTeleTextOn() ) TeleTextONOFF();
#endif // SUPPORT_TELETEXT
ClearOSDInfo();
LCDPowerOFF();
PowerLED(OFF);
}
void WaitPowerOn(void)
{
BYTE ikey;
BYTE AutoKey, _RemoDataCode;
while(1)
{
if( (ikey = GetKey(0)) )
{
#ifdef POWERKEY
if( ikey==POWERKEY )
break; //poweron
#endif
}
if( IsRemoDataReady(&_RemoDataCode, &AutoKey) )
{
if( _RemoDataCode==REMO_STANDBY && !AutoKey ) //POWERON
break; //poweron
}
/* #ifdef SUPPORT_TV
if( OKWakeupTime() ) {
ChangeTVChannel( WakeupPR );
break; //poweron
}
#endif
*/ }
#ifdef DEBUG_MAIN
dPuts("\r\n++(PowerOn)__");
#endif
// PowerMode = ON;
PowerLED(ON);
AudioOn(); //SetMSPVol();
LCDPowerON(0);
}
void SetOSDLastKeyInTime(void)
{
OSDLastKeyInTime = GetTime_ms();
}
WORD GetOSDLastKeyInTime(void)
{
return OSDLastKeyInTime ;
}
//=============================================================================
//
//=============================================================================
#ifdef SUPPORT_PATTERN
CODE BYTE PATTERN[7][] = {
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0xff, 0x65,0x00, 0x66,0x00, 0x67,0xff, 0x68,0x00, 0x69,0x00, 0xff,0xff}, // Red
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0x00, 0x65,0xff, 0x66,0x00, 0x67,0x00, 0x68,0xff, 0x69,0x00, 0xff,0xff}, // Green
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0x00, 0x65,0x00, 0x66,0xff, 0x67,0x00, 0x68,0x00, 0x69,0xff, 0xff,0xff}, // Blue
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0xff, 0x65,0xff, 0x66,0xff, 0x67,0xff, 0x68,0xff, 0x69,0xff, 0xff,0xff}, // White
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0x00, 0x65,0x00, 0x66,0x00, 0x67,0xff, 0x68,0xff, 0x69,0xff, 0xff,0xff}, // Gray
{TW88I2CAddress,7, 0x61,0x5f, 0x64,0x00, 0x65,0x00, 0x66,0x00, 0x67,0x00, 0x68,0x00, 0x69,0x00, 0xff,0xff}, // Black
{TW88I2CAddress,7, 0x61,0x00, 0x64,0xc0, 0x65,0xc0, 0x66,0xc0, 0x67,0x88, 0x68,0x88, 0x69,0x88, 0xff,0xff} // Gray scale
};
#endif // SUPPORT_PATTERN
void CheckSpecialMode(void)
{
BYTE i;
i = GetKey(0);
switch( i ) {
case MENUKEY:
Puts("\r\n---- Menu Key is pressed -> Enter Special Mode( To Composite )");
SaveInputSelectionEE(COMPOSITE);
DebugLevel = 0;
/// PcDetectFlag = 0;
break;
}
}
#ifdef SUPPORT_KRS_OSDDEMO
#include "udfont_Krs.c"
#include "OsdInitTable_KRS.c"
#define MaxFontUdFont 174
#define COLORFONT_START 0x3a
void DownloadUDFont_Only(void)
{
BYTE i;
WriteTW88(TW88_MULTISTART, COLORFONT_START); // Set Color Font Start Address.
for(i=0; i< NO_UDFONT && i<= MaxFontUdFont ; i++) {
DownloadFont(i, RAMFONTDATA_KRS[i]);
}
}
void Change_OSDColorLookup_KRS(void)
{
BYTE i,j,dt;
for(j=0; j<2; j++)
{
for(i=0; i<8; i++)
{
dt = ReadTW88(0x9c);
dt &= 0xf0;
WriteTW88(0x9c, i+j*8);
WriteTW88(0x9d, OSD_Color_LookUp_Data_Table_KRS[j][i]);
}
}
}
#endif
//=============================================================================
//
//=============================================================================
void main_init (void)
{
extern CODE BYTE *OutOfRangeStr[] ;
BYTE ikey;
WORD rev;
#ifdef SUPPORT_PC
BYTE i;
#endif
WriteTW88(0xff, 0x10); // Disable I2C auto increase mode
PowerLED(ON);
EnableRemoconInt();
ikey = ResetMSP();
if( ikey ) {
Printf("\r\nError on resetting MSP:0x%02x", (WORD)ikey);
}
rev = GetFWRevEE();
Printf("\r\nPrev.FW:%04x", rev);
if( GetFWRevEE()!=FWVER ) { // exist EEPROM
SaveFWRevEE(FWVER);
Printf("\r\nCurr.FW:%04x", GetFWRevEE());
}
//---------- if FW version is not matched, initialize EEPROM data -----------
if( GetFWRevEE()==FWVER ) { // exist EEPROM
if( rev != FWVER ) { //
SaveDebugLevelEE(DebugLevel);
Printf("\r\nNew DebugLevel:%02x", (WORD)DebugLevel);
SaveInputSelectionEE(COMPOSITE);
ClearBasicEE();
#ifdef SUPPORT_PC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -