⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tv.c

📁 RTD2662板卡源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "Core\Header\Include.h"

BYTE idata ucTVType             = 0;//_NORMAL_TV_TYPE;
#if(_VIDEO_TV_SUPPORT)
bit bChangeChannel              = 0;
BYTE xdata ucPrevChannel        = 0;
WORD xdata ucCurrentInputNumber = 0;
BYTE xdata ucCurrentInputState  = 0;
BYTE xdata ucAudioState         = 1;
BYTE xdata ucAddrIfPllDM        = _ADDR_IfPllDM;

#if(_SLEEP_FUNC)
bit bTimerOnScreen            = 0;
WORD data ucMinuteCount       = 0;
BYTE data ucAutoPowerDownTime = 0xFF;
bit bTimerFirstShow			  = 0;
#endif

#if(_IF_PLL_DE_CHIP == _IF_PLL_DE_1338)
bit bFM = 0;
#endif

WORD CLoadChannelFreq(const BYTE ucCurrentChannel);
void CSaveChannelFreq(const WORD iFreq, const BYTE ucCurrentChannel);



//==========================================================================
//                       CGetTVEepromAddr
//==========================================================================
BYTE CGetTVEepromAddr(const BYTE ucCurrentChannel)
{
    BYTE ucEeprom_Addr;

#if(_FM_DEVICE)
    if (bFM)
       ucEeprom_Addr = _TV_FREQ_EEPROM_ADDR0;
    else
#endif
    ucEeprom_Addr = (_TV_FREQ_EP0_TV_NUMBER < ucCurrentChannel) ? _TV_FREQ_EEPROM_ADDR1 : _TV_FREQ_EEPROM_ADDR0;

    return ucEeprom_Addr;
}

//==========================================================================
//                      CGetTVStartAddr
//==========================================================================
BYTE CGetTVStartAddr(const BYTE ucCurrentChannel)
{
    BYTE ucStart_Addr;

#if(_FM_DEVICE)
    if (bFM)
        ucStart_Addr = _FM_START_ADDR + (ucCurrentChannel * 2);
    else
#endif
    ucStart_Addr = (_TV_FREQ_EP0_TV_NUMBER < ucCurrentChannel) ? ((ucCurrentChannel - (_TV_FREQ_EP0_TV_NUMBER+1)) * 2)
                                                : (_TV_FREQ_EP_START_ADDR0 + (ucCurrentChannel * 2));

    return ucStart_Addr;
}

//==========================================================================
//                      CDetectTVSignalType
//==========================================================================
BYTE CDetectTVSignalType(void)
{
    BYTE ucTemp;

    for(ucTemp = 0; ucTemp < 4; ucTemp++)
    {
        if (gmi_CModeLocked())  // Horizontal Lock
             return 1;

        CTimerDelayXms(50);
    }

    // No video detected or h/v sync not locked
     return 0;  
}

//============================================================
//                    CLoadChannelSkip
//Output: Channel skip     0 --> no skip     1 --> skip
//============================================================
bit CLoadChannelSkip(const BYTE ucCurrentChannel)
{
    CI2cRead(CGetTVEepromAddr(ucCurrentChannel), CGetTVStartAddr(ucCurrentChannel)+1, LENGTH(1), pData);  // eric 0223

    if (pData[0] & 0x80)  // Channel skip
        return 1;
    else         // No skip
        return 0;
}

//============================================================
//                    CSaveChannelSkip
//============================================================
void CSaveChannelSkip(const bit bSkip, const BYTE ucCurrentChannel)
{
    WORD iFreq = CLoadChannelFreq(ucCurrentChannel);

    if (bSkip)
       CSaveChannelFreq((iFreq & 0x7fff) | 0x8000, ucCurrentChannel);
    else
       CSaveChannelFreq(iFreq & 0x7fff, ucCurrentChannel);
}

//============================================================
//Output: Channel freq
//============================================================
WORD CLoadChannelFreq(const BYTE ucCurrentChannel)
{
    WORD freq = 0;

    CI2cRead(CGetTVEepromAddr(ucCurrentChannel), CGetTVStartAddr(ucCurrentChannel), LENGTH(2), pData);  // eric 0223
    pData[1] &= 0x7f;

    freq = (256*pData[1]) + pData[0];

    if (_MAX_FREQ < freq)
        freq = _MAX_FREQ;
    else if(_MIN_FREQ > freq)
        freq = _MIN_FREQ;

    return freq;
}

//==========================================================================
//                         CSaveChannelFreq
//==========================================================================
void CSaveChannelFreq(const WORD iFreq, const BYTE ucCurrentChannel)
{
    pData[0] = iFreq & 0xff;
    pData[1] = (iFreq >> 8) & 0xff;
    CI2cWrite(CGetTVEepromAddr(ucCurrentChannel), CGetTVStartAddr(ucCurrentChannel), LENGTH(2), pData);  // eric 0223
}

//============================================================
//Output: Channel color type
//============================================================
BYTE CLoadChannelColorType(const BYTE ucCurrentChannel)
{ 
#if(_VIDEO_TV_SUPPORT)          
#if(_FM_DEVICE)
    if (bFM)
       return ucTVType;
#endif
#endif

    CI2cRead(_TV_SYSTEM_EEPROM_ADDR, _TV_SYSTEM_START_ADDR+ucCurrentChannel, LENGTH(1), pData);    // Read current channel sound and tv system
    pData[0] = pData[0] >> 4; // tv type

    if (_MAX_TV_TYPE < pData[0] || 0 == pData[0])
        pData[0] = _NORMAL_TV_TYPE; // Set to normal PAL I 
    
    return pData[0];
}

//==========================================================================
//                           CSaveChannelColorType
//==========================================================================
void CSaveChannelColorType(const BYTE ucCurrentChannel, const BYTE TVType)
{
#if(_FM_DEVICE)
    if (bFM)
       return;
#endif

    pData[0] = (TVType << 4) | (CLoadChannelSoundType(ucCurrentChannel));
    CI2cWrite(_TV_SYSTEM_EEPROM_ADDR, _TV_SYSTEM_START_ADDR+ucCurrentChannel, LENGTH(1), pData);
}

//============================================================
//Output: Channel sound type
//============================================================
BYTE CLoadChannelSoundType(const BYTE ucCurrentChannel)
{
    CI2cRead(_TV_SYSTEM_EEPROM_ADDR, _TV_SYSTEM_START_ADDR+ucCurrentChannel, LENGTH(1), pData);    // Read current channel sound and tv system
    pData[0] = pData[0] & 0x03; // sound type

  //  if (_MAX_TV_SOUND_TYPE_NUM < pData[0])
    //    pData[0] = 1;  // Set to normal: 6.0M

    return pData[0];
}
  
//==========================================================================
//                          CSaveChannelSoundType
//==========================================================================
void CSaveChannelSoundType(const BYTE ucCurrentChannel, const BYTE ucSoundType)
{
    pData[0] = (CLoadChannelColorType(ucCurrentChannel) << 4) | ucSoundType;
    CI2cWrite(_TV_SYSTEM_EEPROM_ADDR, _TV_SYSTEM_START_ADDR+ucCurrentChannel, LENGTH(1), pData);
}  

//==========================================================================
//                          CSaveChannelData
//==========================================================================
void CSaveChannelData(const WORD iFreq, const BYTE ucSound, const BYTE ucChannelNumber)
{
    CSaveChannelFreq(iFreq, ucChannelNumber);
    CTimerDelayXms(4);

#if(_FM_DEVICE)
    if (bFM)
       return;
#endif

    // Save sound and tv system
    pData[0] = (ucTVType<<4) | (ucSound & 0x03);
    CI2cWrite(_TV_SYSTEM_EEPROM_ADDR, _TV_SYSTEM_START_ADDR+ucChannelNumber, LENGTH(1), pData);
    CTimerDelayXms(4);
}

//==========================================================================
//                           CloadMaxChannelNumber
//==========================================================================
BYTE CloadMaxChannelNumber(void)
{
#if(_FM_DEVICE)
    if (bFM)
        return _FM_MAX_CHANNEL;
#endif

#if(_CHANGE_CHANNEL_MTD == _CHANGE_CHANNEL_M2)
    return _MAX_CHANNEL_COUNT;
#else

    CI2cRead(_TV_MAX_CHANNEL_EEPROM_ADDR, _MAX_CHANNEL_ADDR, LENGTH(1), pData);    // Read search max channel
    if (_MAX_CHANNEL_COUNT < pData[0])
    {
        // Save search channel number
        pData[0] = 0;
        CI2cWrite(_TV_MAX_CHANNEL_EEPROM_ADDR, _MAX_CHANNEL_ADDR, 1, pData);

        pData[0] = 0;//_MAX_CHANNEL_COUNT;
    }

    return pData[0];
#endif
}
      

//==========================================================================
//                        CModeResetTVMode
//==========================================================================
void CModeResetTVMode(void)  // eric 1130 add for change tv channel bug
{ 
 //   CPowerLightPowerOff();
	// force to background
    CAdjustBackgroundColor(0x00, 0x00, 0x00);     
	CScalerSetBit(_VDISP_CTRL_28, 0xf7, _BIT5);	// Display output is forced to the background color,and free run
	CTimerWaitForEvent(_EVENT_DEN_STOP);	          
	CAdjustDisableWatchDog(_WD_ALL);			// Disable watch dog
	CScalerSetByte(_HOST_CTRL_01, 0x40);
	CScalerSetBit(_VGIP_CTRL_10, ~(_BIT1 | _BIT0), 0x00);
	CScalerSetByte(_VGIP_SIGINV_11, 0x00);
    CScalerSetByte(_VGIP_DELAY_CTRL_12, 0x00); //731301	
    CScalerPageSelect(_PAGE2);
	CScalerSetBit(_P2_Z0_CALIBRATION_CTRL_AC, ~_BIT6, _BIT6); //V305 modify    
    CScalerPageSelect(_PAGE2);
	CScalerSetByte(_P2_TMDS_OUTPUT_CTRL_A6, 0x78);		//Auto Output Disable
	CScalerSetByte(_P2_POWER_ON_OFF_CTRL_A7, 0x0F);	//Input Channel ctrl by auto func(Manual)                
	CModeAutoMeasureOff();						// Disable auto measure
	CMiscClearStatusRegister();
    ucSearchCount  = 1;
    bChangeChannel = 1;
	
    ucCurrState  = _SEARCH_STATE;                  
}                                                        

//==========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -