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

📄 mode_detect.c

📁 TFT 17 2523+mtv512显示器源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	((unsigned int *)Data)[0]   = (unsigned long)64 * DV_ACT_STA_POS * usIPV_ACT_LEN / usDispLen;

    if (ucOption & 0x01)
    {
	    Calculate_IVS2DVS_Delay(2,5,((unsigned int*)Data)[0]);  // V scale-up. Target 2.5~2.6 IHS delay

    }
    else
    {
#if (FULL_LINE_BUFFER)
        Calculate_IVS2DVS_Delay(3,8,((unsigned int*)Data)[0]);  // V no scale-up. Target 3.8~4.0 IHS delay
#else
        if (ucOption & 0x02)
        {
		    // V scale-down            
		    Calculate_IVS2DVS_Delay(2,6,((unsigned int*)Data)[0]);   // V scale-down. Target 2.5~2.6 IHS delay
		}
        else
        {

            Calculate_IVS2DVS_Delay(1,9,((unsigned int*)Data)[0]);                  // V no scale-up. Target 1.9 IHS delay
        }

#endif
    }

#if (FULL_LINE_BUFFER)
    // Turn on full-line buffer when no V scale-up
    RTDSetBit(OP_CRC_CTRL_68, 0xfc, (ucOption & 0x01) ? 0x00 : 0x02);
#else
    RTDSetBit(OP_CRC_CTRL_68, 0xfc, 0x00);
#endif

    // Set ucDV_Delay
    RTDSetByte(IV_DV_LINES_38, ucDV_Delay);

	RTDSetByte(STATUS0_01, 0x00);  // Clear status
    RTDSetByte(STATUS1_1F, 0x00);  // Clear status

    // Switch to FrameSync 1 mode and enable display
//    if (PANEL_OFF == bPANEL_PWR)
//        RTDSetByte(VDIS_CTRL_20, 0x29 | DISP_BIT | DISPLAY_PORT);
//    else
//        RTDSetByte(VDIS_CTRL_20, 0x2b | DISP_BIT | DISPLAY_PORT);

    // Input Run Enable
    RTDSetBit(VGIP_CTRL_04, 0xff, 0x01);

}

void Display_VGA_Set(void)
{
    unsigned char   Wait_Time_Cnt;
//	unsigned char   ucI_Corr0,ucI_Corr1;


    Initial_Mode();
	Sharpness();

    if((usIPH_ACT_WID == 1280) && (DISP_SIZE == DISP_1280x1024) && (stGUD1.FILTER == 0x02))
         RTDSetBit(SCALE_CTRL_15, 0xff, 0x01);   // Turn on H scale-up
    

    PowerDown_ADC();
    //Device_Power(ADC_POWER,OFF);

    // Set user's ADC gain and offset settings
    SetADC_GainOffset();

    Set_Gamma();
    Set_Dithering();
    Set_Bright_Contrast();
//    Sharpness();

    Load_MUD(ucMode_Curr);      // Read mode default settings from 24C04

    // For jitter adjust
    ucPE_Level      = 0;
//    ucPE_Count      = 0;

    // Check Clock
    if (28 > stMUD.CLOCK || 228 < stMUD.CLOCK)      stMUD.CLOCK = 128;

    
    // Update Clock Twice
    Set_Clock();
// Calculate the P correction and I correction according to the CE value
    Delay_Xms(6);
	
    if(ucCE_Value ==  0)
    {
       RTDRead(I_CODE_MB_CA,1,N_INC);
	   RTDSetByte(I_CODE_MB_CA, 0x0d);
	   Delay_Xms(4);
	   RTDRead(PLL_CALIBRATION_CE,1,N_INC);
	   ucP_Corr = (unsigned char)((unsigned int)(Data[0] * 200) >> (29 - P_Code));
	   ucCE_Value = Data[0];  //CE value  

	}

	if(ucI_Code == 0)
	   Adjust_I_Code();
    
	
    Set_Clock();


    // Check Phase
//    stMUD.PHASE &= 0x7c;    // Phase 0~31

    // Update Phase
//    Set_Phase(stMUD.PHASE);

    ucH_Max_Margin  = 128 + 50;
    ucH_Min_Margin  = 128 - 50;
	
	//Read the usIPH_ACT_STA offset
    I2CRead(ADDR_EROM1,(ucMode_Curr - 1),0x01);
	if(Data[0] > 228)
	   Data[0] = 0;

    usIPH_ACT_STA   = (Data[0] & 0x80) ? usIPH_ACT_STA - 50 - (Data[0] - 0x80) : usIPH_ACT_STA + Data[0] - 50;
        
    Data[0] = 5;
    Data[1] = Y_INC;
    Data[2] = IPH_ACT_STA_06;
    Data[3] = (unsigned char)usIPH_ACT_STA;
    Data[4] = (unsigned char)(usIPH_ACT_STA >> 8);
    Data[5] = 0;    
    RTDWrite(Data);

    // Check H-Position
    if (ucH_Max_Margin < stMUD.H_POSITION)
        stMUD.H_POSITION    = ucH_Max_Margin;
    else if (ucH_Min_Margin > stMUD.H_POSITION)
        stMUD.H_POSITION    = ucH_Min_Margin;

    // Update H-Position
    Set_H_Position();

       // Check Phase
    stMUD.PHASE &= 0x7c;    // Phase 0~31

    // Update Phase
    Set_Phase(stMUD.PHASE);

    // Start auto-tracking function once
    RTDSetByte(AUTO_ADJ_CTRL_7F, 0x01);
    Delay_Xms(40);

    // Force to stop auto-tracking function
    RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
    Delay_Xms(40);

    // Measure actual number of scan line in each frame
    Data[0]     = 14;
    Data[1]     = Y_INC;
    Data[2]     = H_BND_STA_L_75;
    Data[3]     = 0x00;
    Data[4]     = 0xff;
    Data[5]     = 0x07;
    Data[6]     = 0x00;
    Data[7]     = 0x00;
    Data[8]     = 0x00;
    Data[9]     = 0x00;
    Data[10]    = 0x00;
    Data[11]    = 0x00;
    Data[12]    = 0x00;
    Data[13]    = 0x01;
    Data[14]    = 0;
    RTDWrite(Data);

    Wait_Time_Cnt  = 60;    // Tracking timeout 60ms        
    do
    {   
        Delay_Xms(1);
        RTDRead(AUTO_ADJ_CTRL_7F, 0x01, N_INC);
    }
    while ((Data[0] & 0x01) && (--Wait_Time_Cnt));

    RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
    
    if (Wait_Time_Cnt)
    {
        RTDRead(VER_START_80, 0x04, Y_INC);
        Data[0] = Data[3] & 0x0f;
        Data[1] = Data[2];

        usVer_End   = (usVsync < ((unsigned int *)Data)[0]) ? ((unsigned int *)Data)[0] : usVsync;
    }
    else
    {
        usVer_End   = usVsync;
    }

    // Update to reasonable usIPV_ACT_STA for user mode
    if (MODE_USER720x400 <= ucMode_Curr)
    {
        ((unsigned int *)Data)[0]   = usVer_End - VGA_Mode[ucMode_Curr][2];

        if (254 < ((unsigned int *)Data)[0] + ucDV_Delay)   ((unsigned int *)Data)[0]   = 254 - ucDV_Delay;

        usIPV_ACT_STA   += ((unsigned int *)Data)[0];
        ucDV_Delay      += ((unsigned int *)Data)[0];
    }

    // Set the ucV_Min_Margin/ucV_Max_Margin
    ucV_Min_Margin  = (128 < usIPV_ACT_STA) ? 0 : 128 - usIPV_ACT_STA + 1;

    if ((128 - 50) > ucV_Min_Margin)    ucV_Min_Margin  = 128 - 50;

    ((unsigned int *)Data)[0]   = (usVer_End + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);

    ucV_Max_Margin  = (((unsigned int *)Data)[0] > 0x00ff) ? 0xff : ((unsigned int *)Data)[0];

    // Check ucV_Min_Margin/ucV_Max_Margin :
    // ucDV_Delay can only range from 0 to 254
    // Original Formula :
    // 128 - ucV_Min_Margin >= ucDV_Delay
    // ucV_Max_Margin - 128 >= 254 - ucDV_Delay

    if ((unsigned int)128 > ((unsigned int)ucV_Min_Margin + ucDV_Delay))    ucV_Min_Margin  = 128 - ucDV_Delay;
    if ((unsigned int)382 < ((unsigned int)ucV_Max_Margin + ucDV_Delay))    ucV_Max_Margin  = 382 - ucDV_Delay;

    if ((128 + 50) < ucV_Max_Margin)    ucV_Max_Margin  = 128 + 50;

    // Check V-Position
    if (ucV_Min_Margin > stMUD.V_POSITION)
        stMUD.V_POSITION    = ucV_Min_Margin;
    else if ((unsigned int)256 - ucV_Min_Margin < stMUD.V_POSITION)
        stMUD.V_POSITION    = (unsigned int)256 - ucV_Min_Margin;

    // Update V-Position
    Set_V_Position();

    // Re-calculate actual refresh rate
    ((unsigned long *)Data)[0]  = (unsigned long)usHsync * usVer_End;
    ucRefresh   = (unsigned long)49152000 / ((unsigned long *)Data)[0];
    ucRefresh   = (ucRefresh & 0x01) ? ((ucRefresh + 1) >> 1) : (ucRefresh >> 1);
    
	if(ucRefresh > V_OVERSPEC_FREQ)
	    bOverSpec = _TRUE;

	if((unsigned int)24576/usHsync > H_OVERSPEC_FREQ)
	    bOverSpec = _TRUE;

    Data[0] = Frame_Sync();

    if (1 == Data[0])
    {
       Delay_Xms(10);
       Data[0] = Frame_Sync();     // Fail. Try again	   	  
    }

    bFrameSync      = Data[0] ? 0 : 1;              // 0 : fail, 1 : pass
    ucSyncErrorCnt  = 0;

    RTDSetBit(OVL_CTRL_6D,0x3f,0x00);
    RTDSetByte(BGCOLOR_CONTROL_6C,0x00);
	RTDSetBit(OVL_CTRL_6D,0x3f,0x40);
    RTDSetByte(BGCOLOR_CONTROL_6C,0x00);
	RTDSetBit(OVL_CTRL_6D,0x3f,0x80);
    RTDSetByte(BGCOLOR_CONTROL_6C,0x00);

//    RTDSetBit(VDIS_CTRL_20, 0x5f, DHS_MASK);        // Normal display
      RTDSetBit(VDIS_CTRL_20, 0x7f, 0x20 | DHS_MASK);        // Normal display

#if(AS_PLL_NONLOCK)
   if(bFrameSync)
        RTDSetBit(ODD_CTRL_8E,0xdf,0x20);
#endif

    //anson 05_0314
    ucfrist = (ucMode_Curr - 1 ) / 8 ;
    I2CRead(ADDR_EROM1, ucfrist , 1);
    ucfrist = ucMode_Curr - (ucfrist*8) ;
    ucfrist  = Data[0] >> (ucfrist-1) ;
    ucfrist  = ucfrist & 0x01;
    stGUD1.OSD_INPUT = stGUD1.OSD_INPUT | 0x20; //First Time Into This Mode


}

void Display_DVI_Set(void)
{
#if(TMDS_ENABLE)
    unsigned char   Wait_Time_Cnt;

    Initial_Mode();

    // Set the ucV_Min_Margin/ucV_Max_Margin
    ucV_Min_Margin  = (128 < usIPV_ACT_STA) ? 0 : 128 - usIPV_ACT_STA + 1;

    // Use Data[8],Data[9] as a temporary 16-bit variable.
    ((unsigned int *)Data)[4]   = (usVsync + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);

    ucV_Max_Margin  = (0x00ff <  ((unsigned int *)Data)[4]) ? 0xff :  ((unsigned int *)Data)[4];

    // Check ucV_Min_Margin/ucV_Max_Margin :
    // ucDV_Delay can only range from 0 to 254
    // Original Formula :
    // 128 - ucV_Min_Margin <= ucDV_Delay
    // ucV_Max_Margin - 128 <= 254 - ucDV_Delay

    if ((unsigned int)128 > ((unsigned int)ucV_Min_Margin + ucDV_Delay))    ucV_Min_Margin  = 128 - ucDV_Delay;
    if ((unsigned int)382 < ((unsigned int)ucV_Max_Margin + ucDV_Delay))    ucV_Max_Margin  = 382 - ucDV_Delay;

    // Read mode default settings from 24C04
    Load_MUD(ucMode_Curr);

    Set_Gamma();
    Set_Dithering();
    Set_Bright_Contrast();
    Sharpness();

    // Issac :
    // RTD controller can support both digital mode and analog mode to capture input image data.
    // In digital mode, input image data is captured according to input data enable (IDEN) signal;
    // In analog mode, input image data is captured according to capture window settings;
    // Although can support both of them, I always use analog mode to capture input image in this F/W.
    // Because RTD controller can measure the position and size of IDEN signal, we can just set our
    // capture window to be the same size and position as IDEN.

    Data[0]     = 14;
    Data[1]     = Y_INC;
    Data[2]     = H_BND_STA_L_75;
    Data[3]     = 0x02;
    Data[4]     = usADC_Clock - 2;
    Data[5]     = (usADC_Clock - 2) >> 8;
    Data[6]     = 0x02;
    Data[7]     = usVsync - 2;
    Data[8]     = (usVsync - 2) >> 8;
    Data[9]     = 0;
    Data[10]    = 0;
    Data[11]    = 0;
    Data[12]    = 0;
    Data[13]    = 0x81;     // Measure IDEN position
    Data[14]    = 0;


    RTDWrite(Data);

    Wait_Time_Cnt  = 60;    // Tracking timeout 60ms        
    do
    {   
        Delay_Xms(1);
        RTDRead(AUTO_ADJ_CTRL_7F, 0x01, N_INC);
    }
    while ((Data[0] & 0x01) && (--Wait_Time_Cnt));
    
    if (0 == Wait_Time_Cnt)
    {
        RTDSetByte(AUTO_ADJ_CTRL_7F, 0x00);
        Reset_Mode();
    }
    else
    {
        // Read IDEN position information
        RTDRead(VER_START_80, 0x08, Y_INC);
        
        // IDEN horizontal Start
        usIPH_ACT_STA   = (unsigned int)Data[4] + ((unsigned int)Data[5] << 8) - 2;

        // IDEN vertical Start
        ((unsigned int *)Data)[0]   = (unsigned int)Data[0] + ((unsigned int)Data[1] << 8) - 1;

        if (((unsigned int *)Data)[0] > (usIPV_ACT_STA + ucV_Max_Margin - 0x80))
        {
            ((unsigned int *)Data)[1]   = (usVsync + 128 - 2) - (usIPV_ACT_STA + usIPV_ACT_LEN);    // Actual V max. Margin

            ucDV_Delay      = (unsigned char)((unsigned int)ucDV_Delay + ucV_Max_Margin - 0x80);
            usIPV_ACT_STA   = usIPV_ACT_STA + ucV_Max_Margin - 0x80;

            if (ucV_Max_Margin < ((unsigned int *)Data)[1])
            {
                // We have to increase IVS delay to fix ucV_Max_Margin
                if ((((unsigned int *)Data)[1] - ucV_Max_Margin) >= (((unsigned int *)Data)[0] - usIPV_ACT_STA))
                    ((unsigned int *)Data)[1]   = ((unsigned int *)Data)[0] - usIPV_ACT_STA + PROGRAM_VDELAY;
                else
                    ((unsigned int *)Data)[1]   = usIPV_ACT_STA + ((unsigned int *)Data)[1] - ucV_Max_Margin + PROGRAM_VDELAY;

                if (126 < ((unsigned int *)Data)[1])    ((unsigned int *)Data)[1]  = 126;

                RTDSetByte(IVS_DELAY_8C, 0x80 | ((unsigned int *)Data)[1]);
            }
        }
        else if (((unsigned int *)Data)[0] < (usIPV_ACT_STA + ucV_Min_Margin - 0x80))
        {
            ucDV_Delay      = (unsigned char)((unsigned int)ucDV_Delay + ucV_Min_Margin - 0x80);
            usIPV_ACT_STA   = usIPV_ACT_STA + ucV_Min_Margin - 0x80;

            ((unsigned int *)Data)[1]   = usIPV_ACT_STA - ((unsigned int *)Data)[0];

            // We have to decrease IVS delay to fix ucV_Min_Margin
            if (PROGRAM_VDELAY <= ((unsigned int *)Data)[1])
                RTDSetByte(IVS_DELAY_8C, 0x00);
            else
                RTDSetByte(IVS_DELAY_8C, 0x80 | (PROGRAM_VDELAY - ((unsigned int *)Data)[1]));
        }
        else
        {
            ucDV_Delay      = ((unsigned int *)Data)[0] + ucDV_Delay - usIPV_ACT_STA ;
            usIPV_ACT_STA   = ((unsigned int *)Data)[0];
        }

		RTDRead(TMDS_CORRECTION_FF,0x01,N_INC);

		if(Data[0] & 0x03)
		    usIPH_ACT_STA -= 14;//if TMDS error correction enable, then compensate the IPH_ACT_STA offset.

        Data[0]     = 5;
        Data[1]     = Y_INC;
        Data[2]     = IPH_ACT_STA_06;
        Data[3]     = (unsigned char)(usIPH_ACT_STA

⌨️ 快捷键说明

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