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

📄 hdmi.c

📁 realtek LCD monitor, TV开发源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************************************************
//  The  Software  is  proprietary,  confidential,  and  valuable to Realtek Semiconductor
//  Corporation  ("Realtek").  All  rights, including but not limited  to  copyrights,
//  patents,  trademarks, trade secrets, mask work rights, and other similar rights and interests,
//  are reserved to Realtek. Without  prior  written  consent  from  Realtek,  copying, reproduction,
//  modification,  distribution,  or  otherwise  is strictly prohibited. The Software  shall  be
//  kept  strictly  in  confidence,  and  shall  not be  disclosed to or otherwise accessed by
//  any third party. @ <2003> - <2008>   The Software is provided "AS IS" without any warranty of any kind,
//  express, implied, statutory or otherwise.
//**********************************************************************************************************
//----------------------------------------------------------------------------------------------------
// ID Code      : Hdmi.c No.0000
// Update Note  :
//----------------------------------------------------------------------------------------------------

#define __HDMI__

#include "Common\Header\Include.h"

//Anderson 071219 for 2545LR, 248xRD, 248xRD
#if(_SCALER_SERIES_TYPE == _RTD2472D_SERIES)


#if((_HDMI_SUPPORT == _ON) || (_TMDS_SUPPORT == _ON))
//--------------------------------------------------
// Description  : Detect DVI/HDMI input format
// Input Value  : None
// Output Value : Return _FALSE if Input Format isn't HDMI, _TRUE while Input Format is HDMI
//--------------------------------------------------
bit CHdmiFormatDetect(void)
{
    CScalerPageSelect(_PAGE2);
    CScalerRead(_P2_HDMI_SR_CB, 1, pData, _NON_AUTOINC);

    if((pData[0] & 0x01) == 0x01)//Input source is the HDMI format.
        return _TRUE;
    else
        return _FALSE;
}
#endif // End of #if((_HDMI_SUPPORT == _ON) || (_TMDS_SUPPORT == _ON))


#if(_HDMI_SUPPORT == _ON)
//--------------------------------------------------
// Description  : Detect Audio Lock status
// Input Value  : None
// Output Value : Return _FALSE if Audio Lock is ok, _TRUE while Audio mislock, FIFO underflow/overflow
//--------------------------------------------------
bit CHdmiAudioFIFODetect(void)
{
    CScalerPageSelect(_PAGE2);
    CScalerRead(_P2_HDMI_SR_CB, 1, pData, _NON_AUTOINC);

    if((pData[0] & 0x06) == 0)
        return _FALSE;

    return _TRUE;
}

//--------------------------------------------------
// Description  : HDMI Video Setting
// Input Value  : None
// Output Value : Return _FALSE if Set_AVMute is true, _TRUE while Video Setting is OK.
//--------------------------------------------------
bit CHdmiVideoSetting(void)
{

    CScalerPageSelect(_PAGE2);
    CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_SCR_00, ~(_BIT3 | _BIT1 | _BIT0), _BIT1);//sephinroth ATC modify//Set HDMI/DVI decide condition  20080710
    CTimerDelayXms(50);

    if(CHdmiFormatDetect())//Input source is the HDMI format.
    {
        SET_HDMIINPUT();

        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_ACRCR_51, ~_BIT2, _BIT2);//Enable Pixel Repetition down sampling auto mode

#if(_HDCP_SUPPORT == _ON)
        CScalerSetDataPortByte(_P2_HDCP_ADDR_PORT_C3, 0x40, 0x93);//Change to HDCP1.1 for HDMI
#endif

        CScalerSetBit(_P2_HDMI_SR_CB, ~(_BIT5 | _BIT3 | _BIT2), _BIT5 | _BIT3 | _BIT2);
        CTimerDelayXms(10);

        //HDMI Video & Audio Part
        if(ucCurrState != _ACTIVE_STATE)
        {
            CScalerRead(_P2_HDMI_SR_CB, 1, pData, _NON_AUTOINC);

            if(!(bit)(pData[0] & 0x40))//For Clear_AVMute
            {
                SET_AVRESUME();//Audio WD can't action, when Set_AVMute happen.
                CAdjustDisableHDMIWatchDog(_WD_SET_AVMUTE_ENABLE);//Disable Set_AVMute Watch Dog
                CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_AVMCR_30, ~_BIT3, _BIT3);//Enable DVI/HDMI video output
                //CAdjustEnableHDMIWatchDog(_WD_SET_AVMUTE_ENABLE);//Enable Set_AVMute Watch Dog //yc 20080401 for quntum data
            }
            else
            {
                CTimerDelayXms(200);//For AV_Mute Delay
                CLR_AVRESUME();
                CLR_HDMIINPUT();
                return _FALSE;
            }
        }

        //HDMI Video Part
//V404 modify Start
/*
        CScalerRead(_P2_HDMI_GPVS_CC, 1, pData, _NON_AUTOINC);
        if(((bit)(pData[0] & 0x01)) || GET_VIDEOMODECHANGE())//For HDMI switch between RGB/YCbCr
        {
            CLR_VIDEOMODECHANGE();
*/
//V404 modify end
            CScalerSetBit(_P2_HDMI_GPVS_CC, ~_BIT0, _BIT0);
            CScalerGetDataPortByte(_P2_HDMI_PSAP_CD, 0x00, 1, pData, _NON_AUTOINC);
            if((pData[0] & 0x23) == 0)//Check BCH data(Package error flag)
            {
                CScalerGetDataPortByte(_P2_HDMI_PSAP_CD, 0x04, 2, pData, _NON_AUTOINC);

                if((bit)(pData[0] & 0x40) != (bit)(pData[0] & 0x20))//For HDMI switch between RGB/YUV
                {
 //Anderson 080422 for FRC Support Start
#if(_FRC_SUPPORT == _ON)
                    CLR_FRCRGBIN();//YUV Input
#endif
                    if((pData[0]&0x20) == 0x20) //422
                    {
//Anderson 071227 for Different Register Mapping Start (Need to Confirm)
#if((_SCALER_TYPE == _RTD2472D) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
//Anderson 20080710 for FRC YUV Mode Start
#if(_FRC_YUV_MODE_SUPPORT == _ON)
                        CScalerSetByte(_V8_YUV_CONVERSION_1F , 0x10);//set audio pin share
                        SET_FRC16BITSIN();
                        CScalerPageSelect(_PAGE5);
                        CScalerSetByte(_P5_SDRF_MN_FIFO_422_SET_E3, 0x02); //Enable FRC 422->444
#else
            CScalerSetByte(_V8_YUV_CONVERSION_1F , 0x18);//enable and interpolation and set audio pin share
#endif // End of #if(_FRC_SUPPORT == _OFF)

#elif(_SCALER_TYPE == _RTD2545LR)

#if(_FRC_YUV_MODE_SUPPORT == _OFF)
                        CScalerSetByte(_V8_YUV_CONVERSION_1F , 0x08);//enable 422->444 and interpolation
#else
                        SET_FRC16BITSIN();
#endif // End of #if(_FRC_YUV_MODE_SUPPORT == _OFF)
//Anderson 20080710 for FRC YUV Mode End
#else
    No Setting !!
#endif // End of #if((_SCALER_TYPE == _RTD2472D) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))

//Anderson 071227 for Different Register Mapping End
//Anderson 080422 for FRC Support End
                        CScalerPageSelect(_PAGE2);
                    }
                    else
                    {
//Anderson 080422 for 2472D, 247xRD, 248xRD Start
#if((_SCALER_TYPE == _RTD2472D) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
                        CScalerSetByte(_V8_YUV_CONVERSION_1F , 0x10); //set audio pin share
#endif
//Anderson 080422 for 2472D, 247xRD, 248xRD End
                        CScalerPageSelect(_PAGE2);
                    }

                    if((pData[1] & 0xc0) != 0xc0)//For HDMI switch between ITU601/ITU709
                    {

                        if((bit)(pData[1] & 0x40))
                        {
                            CScalerCodeW(tHDMI_YPBPR_ITU601);
                        }
                        else
                        {
                            CScalerCodeW(tHDMI_YPBPR_ITU709);
                        }

                    }
                }
                else if(!(bit)(pData[0] & 0x60))
                {
//Anderson 20080710 for FRC YUV Mode Start
#if(_FRC_YUV_MODE_SUPPORT == _ON)
                    SET_FRCRGBIN();//YUV Input
#endif
//Anderson 20080710 for FRC YUV Mode End

//Anderson 080107 update 071227 Settings Start
#if(_SCALER_TYPE == _RTD2472D)
                    CScalerSetByte(_YUV2RGB_CTRL_9C, 0x00);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
                    CScalerSetByte(_YUV_RGB_CTRL_9C, 0x00);
#else
    No Setting !!
#endif // End of #if(_SCALER_TYPE == _RTD2472D)
//Anderson 080107 update 071227 Settings End
}
            }
//        }
    }
    else
    {
        CLR_HDMIINPUT();
        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_ACRCR_51, ~_BIT2, 0x00);//Disable Pixel Repetition down sampling auto mode
        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_VCR_50, ~(_BIT3 | _BIT2 |_BIT1 |_BIT0), 0x00);
        CAdjustDisableHDMIWatchDog(_WD_HDMI_ALL);
        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_AVMCR_30, ~_BIT3, _BIT3);//Enable DVI/HDMI video output
        CScalerSetDataPortByte(_P2_HDCP_ADDR_PORT_C3, 0x40, 0x91);// Change to HDCP1.0 for DVI
//Anderson 080107 update 071227 Settings Start
#if(_SCALER_TYPE == _RTD2472D)
        CScalerSetByte(_YUV2RGB_CTRL_9C, 0x00);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
        CScalerSetByte(_YUV_RGB_CTRL_9C, 0x00);
#else
    No Setting !!
#endif// End of #if(_SCALER_TYPE == _RTD2472D)
//Anderson 080107 update 071227 Settings End
    }

    return _TRUE;
}

//--------------------------------------------------
// Description  : Setting Audio Frequence Mode
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CHdmiAudioFirstTracking(void)
{
    BYTE coeff = 0, s = 0;
    WORD a = 1024, b = 0, m = 0;
    DWORD cts = 0, n = 0, freq = 0;

//cyyeh 20080415
#if(_SCALER_TYPE == _RTD2472D)
    BYTE   o = 1;
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
    BYTE   o = 2;
#else
    No Setting !!
#endif // End of #if(_SCALER_TYPE == _RTD2472D)


    CScalerPageSelect(_PAGE2);
    CScalerRead(_P2_HDMI_SR_CB, 1, pData, _NON_AUTOINC);

    if((CHdmiAudioFIFODetect() || GET_AVRESUME()) && (!(bit)(pData[0] & 0x40)))//For HDMI audio pll setting
    {
        CLR_AVRESUME();

        CAdjustDisableHDMIWatchDog(_WD_AUDIO_FIFO);//Disable Audio Watch Dog
        CScalerSetDataPortByte(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_PSCR_15, 0x00);//Disable FIFO Trend
        CScalerSetDataPortByte(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_CMCR_10, 0x50);//Update Double Buffer
        CScalerSetBit(_P2_HDMI_APC_C8, ~_BIT0, _BIT0);//HDMI Address Auto Increase Enable

        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_ACRCR_51, ~_BIT1, _BIT1);
        CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_NTX1024TR0_28, ~_BIT3, _BIT3);
        CTimerDelayXms(2);

        CScalerGetDataPortByte(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_ACRSR0_52, 5, pData, _NON_AUTOINC);


        cts = ((DWORD)pData[0] << 12) | ((DWORD)pData[1] << 4) | (((DWORD)pData[2] >> 4) & 0x0f);
        n =   (((DWORD)pData[2] & 0x0f) << 16) | ((DWORD)pData[3] << 8) | (DWORD)pData[4];

        CScalerGetDataPortByte(_P2_HDMI_ADDR_PORT_C9, _P2_HDMI_NTX1024TR0_28, 2, pData, _NON_AUTOINC);
        b = (((WORD)pData[0] & 0x07) << 8) | (WORD)pData[1];

        //cyyeh 20080331
        // Fv(Video Freq) = Xtal * a / b ( a = 1024)
        // Fa(Audio Freq) = 128 * Fs(Sampling Freq) = (n/cts) * Fv
        // Getting :   Fs       = (n/cts) * ( Xtal * a / b ) / 128  (in 0.1kHz unit )
        //             Fs(freq) = (DWORD)8 * 2 * 10000 * _RTD_XTAL / cts * n / ((DWORD)b * 1000);


//cyyeh fixed due to the value of freq overflow !!
        freq = (DWORD)8 * 2 * 1000 * _RTD_XTAL / cts  * n / ((DWORD)b * 100);
        freq = (freq >> 1) + (freq & 0x01);

        if((freq >= 318) && (freq <= 322))
        {

            coeff = _AUDIO_MCK_32000;
            freq  = 32000;
            ucAudioRate = 0;
        }
        else if((freq >= 438) && (freq <= 444))
        {

            coeff = _AUDIO_MCK_44100;
            freq  = 44100;
            ucAudioRate = 0;
        }
        else if((freq >= 476) && (freq <= 484))
        {
            coeff = _AUDIO_MCK_48000;
            freq  = 48000;
            ucAudioRate = 0;
        }
        else if((freq >= 877) && (freq <= 887))
        {

            coeff = _AUDIO_MCK_88200;
            freq  = 88200;
            ucAudioRate = 1;
        }
        else if((freq >= 955) && (freq <= 965))
        {
            coeff = _AUDIO_MCK_96000;
            freq  = 96000;
            ucAudioRate = 1;
        }
        else if((freq >= 1754) && (freq <= 1774))
        {

            coeff = _AUDIO_MCK_176400;

⌨️ 快捷键说明

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