📄 main.c
字号:
/*****************************************************************************/
/* */
/* TW880x Demo Board Techwell,Inc */
/* */
/* CPU : Winbond 78E62BP-40 */
/* LANGUAGE : Tasking C / Keil C */
/* PROGRAMMER : Jooyeon Lee / Harry Han */
/* */
/*****************************************************************************/
/* See 'Release.txt' for firmware revision history */
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "main.h"
#include "tw88.h"
#include "i2c.h"
#include "adc.h"
#include "osdbasic.h"
#include "dispinfo.h"
#include "etc_eep.h"
#include "measure.h"
#include "Printf.h"
#include "audio.h"
#include "osdmenu.h"
#include "pc_eep.h"
#include "KeyRemo.h"
#include "Monitor.h"
#include "CPU.h"
#include "rgbmix.h"
#include "panel.h"
#ifdef SUPPORT_TV
#include "Tuner.h"
#endif
#include "measure.h" // Hans
void Loader(BYTE);
#ifdef SUPPORT_GAMMA
extern CODE BYTE GammaRed[];
extern CODE BYTE GammaBlue[];
extern CODE BYTE GammaGreen[];
#endif
extern DATA WORD tic_pc;
extern IDATA BYTE cSourceState; // Hans
extern IDATA BYTE PcMode;
IDATA BYTE InputSelection;
// IDATA BYTE InputSelectionInx = 0;
/// bit PcDetectFlag = 1;
// bit PowerMode = ON;
IDATA WORD IVF;
IDATA DWORD IHF;
IDATA BYTE VInputStd;
bit Range4Coarse=0, AutoDetect=1;
BYTE VInputStdDetectMode;
BYTE CheckBuf;
CODE struct struct_IdName struct_InputSelection[]={
{ UNKNOWN , "" }, //don't remove or change this.
{ COMPOSITE , "CVBS" }, //don't remove or change this.
// you can change the order of the followings
#ifdef SUPPORT_SVIDEO
{ SVIDEO , "S-Video" },
#endif
#ifdef SUPPORT_COMPONENT
{ COMPONENT , "Component" },
#endif
#ifdef SUPPORT_DTV
{ DTV , "DTV-SOG" },
#endif
#ifdef SUPPORT_TV
{ TV , "TV " },
#endif
#ifdef SUPPORT_PC
{ PC , "PC-HV"},
#endif
#ifdef SUPPORT_DIGITALVGA
{ DIGITALVGA , "DVI" },
#endif
{0 , ""}, //don't remove or change this.
};
CODE struct struct_IdName struct_VInputStd[]={
{ UNKNOWN , "" }, //don't remove or change this.
{ NTSC, "NTSC"}, //don't remove or change this.
#ifdef SUPPORT_PAL
{ PAL, "PAL"},
#endif
#ifdef SUPPORT_SECAM
{ SECAM, "SECAM"},
#endif
#ifdef SUPPORT_PALM
{ PALM, "PALM"},
#endif
#ifdef SUPPORT_PALN
{ PALN, "PALN"},
#endif
#ifdef SUPPORT_PAL60
{ PAL60, "PAL60"},
#endif
#ifdef SUPPORT_NTSC4
{ NTSC4, "NTSC4.43"},
#endif
{0 , ""}, //don't remove or change this.
};
//===================== OSD ===================================================
WORD OSDLastKeyInTime; // in ms
//===================== Button Key ============================================
//================= Etc. ======================================================
#ifdef WIDE_SCREEN
BYTE WideScreenMode;
#endif
BYTE DebugLevel;
bit Flag4AutoPanelRegs = 0;
bit I2CAutoIncFlagOn = 0;
#ifdef SUPPORT_COMPONENT
IDATA BYTE ComponentMode;
#endif
extern BYTE TVInputSel;
#ifdef NO_INITIALIZE
bit NoInitAccess=0;
#endif
#ifdef INTERNAL_MCU
extern WORD TW88IRQ;
#endif
bit DisplayInputHold = 0;
//////////////////////////////////////////////////////////////////////////////
//=============================================================================
// Prompt
//=============================================================================
#ifdef SUPPORT_GAMMA
#include "Gamma.c"
void DownLoadGamma(void)
{
// Red
WriteI2C(TW88I2CAddress, 0xf0, 0xe8|1 );
WriteI2C(TW88I2CAddress, 0xf1, 0x00); // Start Address
WriteI2C(TW88I2CAddress, 0xf2, GammaRed[0]); //
WriteI2Cn(TW88I2CAddress, 0xf2, &GammaRed[1], 255);
// Blue
WriteI2C(TW88I2CAddress, 0xf0, 0xe8|2 );
WriteI2C(TW88I2CAddress, 0xf1, 0x00); // Start Address
WriteI2C(TW88I2CAddress, 0xf2, GammaGreen[0]); //
WriteI2Cn(TW88I2CAddress, 0xf2, &GammaGreen[1], 255);
// Red
WriteI2C(TW88I2CAddress, 0xf0, 0xe8|3 );
WriteI2C(TW88I2CAddress, 0xf1, 0x00); // Start Address
WriteI2C(TW88I2CAddress, 0xf2, GammaBlue[0]); //
WriteI2Cn(TW88I2CAddress, 0xf2, &GammaBlue[1], 255);
}
#endif
void I2CDeviceInitialize( CODE_P BYTE *RegSet)
{
int cnt=0;
BYTE addr, index, val;
addr = *RegSet;
#ifdef DEBUG_TW88
dPrintf("\r\nI2C address : %02x", (WORD)addr);
#endif
cnt = *(RegSet+1);
RegSet+=2;
while (( RegSet[0] != 0xFF ) || ( RegSet[1]!= 0xFF )) { // 0xff, 0xff is end of data
index = *RegSet;
val = *(RegSet+1);
WriteI2C(addr, index, val);
#ifdef DEBUG_TW88
dPrintf("\r\n addr=%02x index=%02x val=%02x", (WORD)addr, (WORD)index, (WORD)val );
#endif
RegSet+=2;
}
WriteTW88(0xff, 0x00); // set page 0
}
extern CODE struct RegisterInfo UserRange;
extern CODE struct RegisterInfo VideoContrastRange;
extern CODE struct RegisterInfo VideoBrightnessRange;
extern CODE struct RegisterInfo VideoSaturationRange;
extern CODE struct RegisterInfo VideoHueRange;
extern CODE struct RegisterInfo VideoSharpnessRange;
extern CODE struct RegisterInfo DigitalVideoSaturationRange;
#ifdef ADD_ANALOGPANEL
BYTE IsAnalogOn(void)
{
if(DIP_PANEL_SWITCH==0) return 1;
else return 0;
}
#endif
/*********************************/
BYTE IsNoInput(void)
{
if( ReadDecoder(CSTATUS) & 0x80 ) return 1;
return 0;
}
#ifdef ID_CHECK_BY_FW
BYTE Is50Hz(void)
{
if( ReadDecoder(CSTATUS) & 0x01 ) return 1;
return 0;
}
BYTE Slock(void)
{
if( ReadDecoder(CSTATUS) & 0x20 ) return 1;
return 0;
}
#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;
}
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)
{
#ifdef DEBUG
BYTE i;
#endif
if( InputSelection==newsel ) return;
DisplayInputHold = 0; // Refresh Input info.
ClearOSDInfo();
//PanelMute(1);
InputSelection = newsel;
cSourceState = ssInputSetup; // start input setup
#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
}
void PowerOff(void)
{
dPuts("\r\n++(PowerOff)__");
// PowerMode = OFF;
AudioOff();
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 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 ;
}
//=============================================================================
//
//=============================================================================
void main_loop(void)
{
//---------------------------------------------------------------
// Main Loop
//---------------------------------------------------------------
while(1) {
//-------------- Check Serial Port -----------------
#ifdef SERIAL
while( RS_ready() )
Monitor(); // for new monitor functions
#endif // SERIAL
//-------------- Check Key in --------------------------
if( !CheckKeyIn() ) break; // POWEROFF
//-------------- Check Remote Controller ---------------
if( !CheckRemo() ) break; // POWEROFF
//-------------- Check OSD timer -----------------------
CheckAndClearOSD();
//-------------- Check OFF timer -----------------------
if( OKSleepTime() ) break;
SourceProcess(); // Hans
}
}
void main(void)
{
//TW88HWReset = 0; //TW88 HW reset by port pin, internal MCU no meaning
InitCPU();
SetMonAddress(TW88I2CAddress);
InitVars();
InitTechwell();
while(1) {
main_loop(); //exit when power off
PowerOff();
WaitPowerOn();
ChangeInput( GetInputSelectionEE() );
}
}
#if defined SUPPORT_TV
BYTE WantToStopTVScan(void)
{
BYTE AutoKey=0, ret=0, _RemoDataCode=0;
ret = GetKey(1);
if( ret == MENUKEY ) {
//Printf("\r\n(WantToStopTVScan) Pushed Menu Key!!");
return 1;
}
if( !ret )
ret = IsRemoDataReady(&_RemoDataCode, &AutoKey);
if( _RemoDataCode==REMO_MENU ) ret = 1;
else ret = 0;
#if defined DEBUG_KEYREMO || defined DEBUG_TV
dPrintf("\r\n(WantToStopTVScan) ret:0x%x, RemoDataCode:0x%x", (WORD)ret, (WORD)_RemoDataCode);
#endif
return ret;
}
void ChangeVInputStdDetectMode(BYTE val)
{
#ifndef WIDE_SCREEN
BYTE cIndex;
DWORD scale;
#endif
VInputStdDetectMode = val;
SaveVInputStdDetectModeEE(val);
if( VInputStdDetectMode ==AUTO )
SetAutoDetectStd();
else {
SetVInputStd(val);
ClearAutoDetectStd(val-1);
}
#ifdef PAL_TV
SetTVIFStd(IF_I);
if (VInputStdDetectMode == AUTO || VInputStdDetectMode == PAL ||
VInputStdDetectMode == SECAM || VInputStdDetectMode == PALN)
PcMode = EE_YPbPr_576I;
else
PcMode = EE_YPbPr_480I;
#ifdef WIDE_SCREEN
Set4WideScreen(GetWideModeEE());
#else
cIndex = FindDecodeSettingIndex(PcMode);
// scaler config
scale = DecoderFormat[cIndex].ScaleWidth; // scale = (65536 * hactive + panel.hative / 2) / panel.hative
scale *= 0x10000L;
scale += PanelData.HActive / 2;
scale /= PanelData.HActive;
XScale2(scale);
#ifdef DEBUG
dPrintf("\r\nH scale: %xh - %xh", (WORD)(scale>>8), (WORD)(scale & 0xff));
#endif
scale = DecoderFormat[cIndex].ScaleHeight; // scale = (65536 * vactive + panel.vative / 2) / panel.vative
scale *= 0x10000L;
scale += PanelData.VActive / 2;
scale /= PanelData.VActive;
YScale2(scale);
#ifdef DEBUG
dPrintf("\r\nV scale: %xh - %xh", (WORD)(scale>>8), (WORD)(scale & 0xff));
#endif
#endif
#endif
}
#endif //SUPPORT_TV
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -