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

📄 drvtvencoder.c

📁 mstar 776 开发的车载dvd
💻 C
📖 第 1 页 / 共 5 页
字号:
/// @param  u16Hstart \b IN: horianotal starting postion
/// @param  u16Hend   \b IN: horianotal ending postion
/// @param  u16Vstart \b IN: vertical starting postion
/// @param  u16Vend   \b IN: vertical ending postion
/// @return none
//------------------------------------------------------------------------------
void _MDrv_VE_Set_Window(U16 u16Hstart, U16 u16Hend, U16 u16Vstart, U16 u16Vend)
{
    MsWriteVEReg(BK_VE_SRC(0x12), u16Hstart);
    MsWriteVEReg(BK_VE_SRC(0x13), u16Hend);
    MsWriteVEReg(BK_VE_SRC(0x14), u16Vstart);
    MsWriteVEReg(BK_VE_SRC(0x15), u16Vend);
    MSG_DRV_VE(printf("---VE_Set_Window Hstart: %x, Hend : %x, Vstart: %x, Vend: %x\n",u16Hstart,u16Hend,u16Vstart,u16Vend););
}


//------------------------------------------------------------------------------
/// set ADC CVBS buffer out
///
/// @param  bEnable \b IN : Enable/Disable ADC CVBS buffer
/// @param  enInputPortType \b IN : input port type of source
/// @return
//------------------------------------------------------------------------------
// Need to Refine
void _MDrv_VE_Set_ADC_BuffOut(BOOLEAN bEnable, EN_INPUT_PORT_TYPE enInputPortType)
{
    U8 u8Ymux, u8Cmux;
    U8 u8Adc38L;
    U8 u8Adc39L;
    U8 u8Adc39H;
    U8 u8Adc3AL;
    U8 u8Adc3BH;

    MDrv_WriteByte (BK_ADC_ATOP_38_L, 0x70); // init video input

    u8Adc3AL = 0x00;
    u8Adc3BH = 0x00;

    if(bEnable)
    {

        switch(enInputPortType)
        {
        case INPUT_PORT_MS_DTV:
        case INPUT_PORT_ADC_RGB:
        case INPUT_PORT_ADC_YPBPR:
        case INPUT_PORT_ADC_HDMI:
        case INPUT_PORT_EXTERNAL_VD:
            u8Adc38L = 0x5C; // 0x10; // 0x5C;
            u8Adc39L = 0x0B;
            u8Adc39H = 0x0B;
            break;

        case INPUT_PORT_MS_CVBS0:
        case INPUT_PORT_MS_CVBS1:
        case INPUT_PORT_MS_CVBS2:
        case INPUT_PORT_MS_CVBS3:
            u8Ymux = MDrv_ReadByte(BK_ADC_ATOP_02_L) & 0x0F;
            u8Cmux = (MDrv_ReadByte(BK_ADC_ATOP_02_L)>>4) & 0x0F;
            u8Adc38L = 0x14; // 0x3C;
            u8Adc39L = (u8Ymux<<4)|u8Ymux;
            u8Adc39H = (u8Cmux<<4)|u8Cmux;
            u8Adc3AL = 0x03;
            u8Adc3BH = 0x0A;
            break;

        #if(ENABLE_SCART_VIDEO)
        case INPUT_PORT_AV_SCART0:
            u8Ymux = MDrv_ReadByte(BK_ADC_ATOP_02_L) & 0x0F;
            u8Cmux = (MDrv_ReadByte(BK_ADC_ATOP_02_L)>>4) & 0x0F;
            u8Adc38L = 0x14; // 0x3C;
            u8Adc39L = (u8Ymux<<4)|u8Ymux;
            u8Adc39H = (u8Cmux<<4)|u8Cmux;
            u8Adc3AL = 0x03;
            u8Adc3BH = 0x0A;
            break;
        #endif

        case INPUT_PORT_MS_SV0:
            u8Ymux = MDrv_ReadByte(BK_ADC_ATOP_02_L) & 0x0F;
            u8Cmux = (MDrv_ReadByte(BK_ADC_ATOP_02_L)>>4) & 0x0F;
            u8Adc38L = 0x5C;
            u8Adc39L = (u8Ymux<<4)|u8Ymux;
            u8Adc39H = (u8Cmux<<4)|u8Cmux;
            break;

        default:
            u8Adc38L = 0x0F;
            u8Adc39L = 0x00;
            u8Adc39H = 0x00;
            break;
        }
    }
    else
    {
        u8Adc38L = 0x0F;
        u8Adc39L = 0x00;
        u8Adc39H = 0x00;
    }

    MDrv_WriteByte(BK_ADC_ATOP_38_L, u8Adc38L);
    MDrv_WriteByte(BK_ADC_ATOP_39_L, u8Adc39L);
    MDrv_WriteByte(BK_ADC_ATOP_39_H, u8Adc39H);
    MDrv_WriteByte(BK_ADC_ATOP_3A_L, u8Adc3AL);
    MDrv_WriteByte(BK_ADC_ATOP_3B_H, u8Adc3BH);
}


//------------------------------------------------------------------------------
/// Initiate VE
///
/// @param  none
/// @return none
//------------------------------------------------------------------------------
// initiate video encoder
void MDrv_VE_Init(void)
{
    MsWriteVEReg(BK_VE_SRC(0x01), LOPART(VE_MIU_BASE)); //
    MsWriteVEReg(BK_VE_SRC(0x02), HIPART(VE_MIU_BASE)); // VE base address


    //MsWriteVEReg(BK_VE_SRC(0x03), 0x0000); // TTX base address
    //MsWriteVEReg(BK_VE_SRC(0x04), 0x0000); //
    //MsWriteVEReg(BK_VE_SRC(0x05), 0x0000); // VBI base address

    MDrv_WriteByte(BK_CHIPTOP_19_H, 0x80);
    MDrv_WriteByteMask(L_BK_VE_ENC(0x03),0x00,0x10);

    // read FIFO control
    MDrv_WriteByte(L_BK_VE_SRC(0x32),0X30);
    MDrv_WriteByte(L_BK_VE_SRC(0x37),0X0b);
    MDrv_WriteByte(H_BK_VE_SRC(0x37),0X0c);

    // initial TTX VBI
    MsWriteVEReg(BK_VE_SRC(0x06),0);
    MsWriteVEReg(BK_VE_SRC(0x43),(MDrv_Read2Byte(BK_VE_SRC(0x43))&0xff00)|0x0039);
    MsWriteVEReg(BK_VE_SRC(0x08),(MDrv_Read2Byte(BK_VE_SRC(0x08))&0x00ff)|0xfb00);
    MsWriteVEReg(BK_VE_SRC(0x46),(MDrv_Read2Byte(BK_VE_SRC(0x46))&0xff00)|0x0003);
    MDrv_WriteByte(BK_VE_ENC(0x07), 0x00);
    MsWriteVEReg(BK_VE_SRC(0x00),MDrv_Read2Byte(BK_VE_SRC(0x00))|0x0008);

    if (CHIP_FAMILY_TYPE == CHIP_FAMILY_S3P)
    {
       MDrv_WriteByte(L_BK_VE_SRC(0x44),0xf0);
       MDrv_WriteByteMask(BK_VE_SRC(0x46),0xd0,0xf0);
    }

    g_VEInfo.bUse_ADC_BuffOut = TRUE;
}


//------------------------------------------------------------------------------
/// set the output destination of video encoder
///
///              None SCART CVBS SVIDEO YPbPr
///       None    O     O     O     O     O
///       SCART   O     -     X     X     X
///        CVBS   O     X     -     O     O
///     S_VIDEO   O     X     O     -     X
///       YPbPr   O     X     O     X     -
///
/// @param  -pSwitchInfo \b IN/OUT: the information of switching output destination of TV encodeer
/// @return None
//------------------------------------------------------------------------------
void MDrv_VE_SwitchOuputDest(PMS_SWITCH_VE_DEST_INFO pSwitchInfo)
{
    // check the combination is valid
    MS_VE_OUTPUT_DEST_TYPE out0, out1;

    if(pSwitchInfo->u8DestIdx != 0 ||
       pSwitchInfo->OutputDstType != MS_VE_DEST_CVBS)
    {
        pSwitchInfo->Status = MS_VE_SWITCH_DST_INVALID_PARAM;
        MSG_DRV_VE(printf("---VE:unsupported output device\n"););
        return;
    }

    if(pSwitchInfo->OutputDstType >= MS_VE_DEST_NUM)
    {
        MSG_DRV_VE(printf("---VE:unsupported output device\n"););
        pSwitchInfo->Status = MS_VE_SWITCH_DST_INVALID_PARAM;
    }
    else
    {
        g_VEInfo.OutputDestType[pSwitchInfo->u8DestIdx] = pSwitchInfo->OutputDstType;

        out0 = g_VEInfo.OutputDestType[0];
        out1 = g_VEInfo.OutputDestType[1];

        if(VE_OUT_MATCH_TBL[out0][out1].bValid == TRUE)
        {
            pSwitchInfo->Status = MS_VE_SWITCH_DST_SUCCESS;
            MDrv_WriteByteMask(BK_VE_ENC(0x40), VE_OUT_MATCH_TBL[out0][out1].u8DACType, _BIT1|_BIT0);

            _MDrv_VE_Set_ColorConvert(g_VEInfo.VideoSystem, g_VEInfo.u8DACType);
        }
        else
        {
            pSwitchInfo->Status = MS_VE_SWITCH_DST_INVALID_COMBINATION;
        }
    }
}


//------------------------------------------------------------------------------
/// set the input source of video encoder
///
/// @param  -pSwitchInfo \b IN/OUT: the information of switching input destination of TV encodeer
/// @return None
//------------------------------------------------------------------------------
void MDrv_VE_SwitchInputSrc(PMS_SWITCH_VE_SRC_INFO pSwitchInfo)
{
    BOOLEAN bRGBIn = FALSE;
    BOOLEAN bCCIR656In = FALSE;

    if(pSwitchInfo->InputSrcType != MS_VE_SRC_SCALER &&
       pSwitchInfo->InputSrcType != MS_VE_SRC_MAIN &&
       pSwitchInfo->InputSrcType != MS_VE_SRC_SUB)
    {
        g_VEInfo.InputSrcType = MS_VE_SRC_NONE;
        pSwitchInfo->Status = MS_VE_SWITCH_SRC_INVALID_PARAM;
        MSG_DRV_VE(printf("VE:Invalid Input parameter\n"););
        return;
    }

    if(pSwitchInfo->InputSrcType == MS_VE_SRC_SCALER)
    {
        g_VEInfo.InputSrcType = MS_VE_SRC_SCALER;
        pSwitchInfo->Status = MS_VE_SWITCH_SRC_SUCCESS;
        MSG_DRV_VE(printf("VE:scaler input source in for setop_box\n"););
    }

    if(pSwitchInfo->InputSrcType == MS_VE_SRC_MAIN ||
       pSwitchInfo->InputSrcType == MS_VE_SRC_SUB)
    {
        if(stSystemInfo.enInputSourceType == INPUT_SOURCE_NONE ||
           stSystemInfo.enInputSourceType == INPUT_SOURCE_YPBPR)
        {
            g_VEInfo.InputSrcType = MS_VE_SRC_MAIN;
            pSwitchInfo->Status = MS_VE_SWITCH_SRC_SUCCESS;
            //printf("VE support bypass DTV signal for TTX,2007/04/10\n");
            //g_VEInfo.InputSrcType = MS_VE_SRC_NONE;
            //pSwitchInfo->Status = MS_VE_SWITCH_SRC_FAIL;
            //MSG_DRV_VE(printf("VE:unsupported input source\n"););
            //return;
        }
    }


    g_VEInfo.InputSrcType = pSwitchInfo->InputSrcType;
    MDrv_Write2Byte(L_BK_VE_SRC(0x11), 0x0080); //default VE Hardware debug mode

    if(pSwitchInfo->InputSrcType == MS_VE_SRC_SCALER)
    {
        g_VEInfo.bDEmode = TRUE;
        MDrv_WriteRegBit(L_BK_VE_SRC(0x5A), _ENABLE, _BIT0); // enable scaler in
        MsWriteVEReg(L_BK_VE_ENC(0x03E), 0x00E6); // start pixnum
        MsWriteVEReg(L_BK_VE_ENC(0x03F), 0x0017); // start linenum
        MsWriteVEReg(H_BK_VE_ENC(0x03F), 0x0004); // start linenum
        if(g_VEInfo.bUse_ADC_BuffOut)
           _MDrv_VE_Set_ADC_BuffOut(_ENABLE, INPUT_PORT_MS_DTV);
    }
    else
    {
        switch(stSystemInfo.enInputPortType)
        {
        case INPUT_PORT_ADC_RGB:
            bRGBIn = TRUE;
            g_VEInfo.bDEmode = FALSE;
            break;

        case INPUT_PORT_ADC_HDMI:
            bRGBIn = TRUE;
            g_VEInfo.bDEmode = TRUE;
            break;

        case INPUT_PORT_ADC_YPBPR:
            g_VEInfo.bDEmode = FALSE;
            MDrv_WriteByteMask(BK_VE_SRC(0x10), 0x00, _BIT5|_BIT4); // YCbCr in
            MDrv_WriteRegBit(BK_VE_SRC(0x7E), 1, _BIT4);  // source sync from scaler
            MDrv_WriteByte(BK_VE_SRC(0x41), 0x17); //let YPbPr show all image
            break;

        case INPUT_PORT_MS_CCIR656:
            bCCIR656In = TRUE;
            g_VEInfo.bDEmode = TRUE;
            break;

        case INPUT_PORT_MS_DTV:
            /*if(stSystemInfo.enInputSourceType == INPUT_SOURCE_JPEG)
                g_VEInfo.bDEmode = TRUE;
            else*/
                g_VEInfo.bDEmode = TRUE;

            /*if(pSwitchInfo->ptiming->u16Height == 576) //544x576
                {
                    if(pSwitchInfo->ptiming->u16Width ==544)
                         g_VEInfo.bDEmode = FALSE; //544x576 needs fine tune by hand
            }*/
                MDrv_WriteByte(L_BK_VE_SRC(0x41), 0x12);// set the sync polarity
            break;

        default:
            g_VEInfo.bDEmode = FALSE;
            break;
        }

        MDrv_WriteRegBit(L_BK_VE_SRC(0x10), bRGBIn, _BIT6); // enable RGB in

        if(bCCIR656In)
            MDrv_WriteByteMask(L_BK_VE_SRC(0x10), _BIT4, _BIT5|_BIT4); // video source isCCIR656
        else
            MDrv_WriteByteMask(L_BK_VE_SRC(0x10), 0, _BIT5|_BIT4); // video source is YCbCr

        _MDrv_VE_Set_IPMux(stSystemInfo.enInputPortType);

        if(g_VEInfo.bUse_ADC_BuffOut)
        {
            if(pSwitchInfo->InputSrcType == MS_VE_SRC_SCALER)
                _MDrv_VE_Set_ADC_BuffOut(_ENABLE, INPUT_PORT_MS_DTV);
            else
                _MDrv_VE_Set_ADC_BuffOut(_ENABLE, stSystemInfo.enInputPortType);
        }

        if(g_SrcInfo.u8DisplayStatus & DISPLAYWINDOW_INTERLACE)
            MDrv_WriteRegBit(L_BK_VE_SRC(0x10), 1, _BIT0);
        else
            MDrv_WriteRegBit(L_BK_VE_SRC(0x10), 0, _BIT0);

        MDrv_WriteRegBit(L_BK_VE_SRC(0x5A), _DISABLE, _BIT0);// disable scaler in

    }

    _MDrv_VE_Get_Window(pSwitchInfo->ptiming);

    if(bCCIR656In)
        _MDrv_VE_Set_Window(0x000, 0x7FF, 0x10, 0xFF);
    else if(g_VEInfo.bDEmode)
        _MDrv_VE_Set_Window(0x000, 0x7FF, 0x000, 0x7FF);
    else
    {
        if(pSwitchInfo->ptiming->u16Width ==544)
        {
            _MDrv_VE_Set_Window(0x0158, 0x7FF, 0x000, 0x7FF);  //544x576 needs fine tune by hand
        }
        else
        {
        _MDrv_VE_Set_Window(g_VEInfo.TuneWin.u16H_DisStart,
                            g_VEInfo.TuneWin.u16H_DisEnd,
                            g_VEInfo.TuneWin.u16V_DisStart,
                            g_VEInfo.TuneWin.u16V_DisEnd);
        }
    }


    pSwitchInfo->Status = MS_VE_SWITCH_SRC_SUCCESS;

}


//------------------------------------------------------------------------------
/// control the output of video encoder

⌨️ 快捷键说明

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