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

📄 msvd.c

📁 MST726驱动TFT屏程序,源代码!很好的资料
💻 C
📖 第 1 页 / 共 4 页
字号:
    //msWriteByte( BK0_00, REG_BANK2_VD );

    ucVCRCnt = msVDGetVCRFoundCounter();

    /*
    if( g_ucMSVDDebug2&MSVD_CTL2_FLAG_VCR )
    {
        if( ucVCRCnt == 0x0F )
            printf("[%x]",ucVCRCnt);
        else
            printf(" %x ",ucVCRCnt);
    }
    */

    if( g_bVDVCRHandler_VCRMode )
    {
        if( ucVCRCnt == 0x0F )
        {
            if( g_wVDVCRHandler_Grade < 150 )
                g_wVDVCRHandler_Grade ++;
        }
        else if( ucVCRCnt == 0x0D )
            g_wVDVCRHandler_Grade -= 2;
        else if( ucVCRCnt < 0x0D )
            g_wVDVCRHandler_Grade -= 10;

        if( g_wVDVCRHandler_Grade <= 10 )
        {
            g_bVDVCRHandler_VCRMode = 0;
            putstr("\r\nNot VCR mode");
        }
    }
    else
    {
        if( ucVCRCnt == 0x0F )
            g_wVDVCRHandler_Grade += 2;
        else if( ucVCRCnt <= 0x0E )
            g_wVDVCRHandler_Grade = 0;

        if( g_wVDVCRHandler_Grade >= 150 )
        {
            g_bVDVCRHandler_VCRMode = 1;
            putstr("\r\nVCR mode");
        }
    }

    //msWriteByte( BK0_00, ucBank );
}
#endif

void Fsm_ResetHandle(void)
{
        if(g_VdInfo.wVideoStatus&VD_HSYNC_LOCKED&&g_bVDColorBurstHandler_LastColorBurstStatus&&g_VdInfo.ucVideoSystem!=SIG_SECAM)
        {
    	    if(msDSP_Std_GetPhaseError()>0x60&&msDSP_Std_GetNoiseMag()<0x20)
    	    {
        	    ++g_ucPhaseErrorDetectCounter;
                if(g_ucPhaseErrorDetectCounter>5)
                    {
                        g_ucPhaseErrorDetectCounter=0;
                        msVD_FSM_Reset();
                    }
    	    }
            else
            {
                g_ucPhaseErrorDetectCounter=0;
            }
        }
        else
        {
            g_ucPhaseErrorDetectCounter=0;
        }
}


//#define VD_FORCE_AUTO       0
//#define VD_FORCE_PAL        1   // 443 50Hz
//#define VD_FORCE_NTSC_443   2   // 443 60Hz
//#define VD_FORCE_PAL_358    3   // 358 ( 60Hz -> PAL_M, 50Hz -> PAL_NC )
//#define VD_FORCE_NTSC       4   // 358 60Hz
//#define VD_FORCE_SECAM      5   // 428 50Hz

void msVDForceSystem( BYTE ucSystem )
{
    g_ucMSVDForceSystem = ucSystem;
}

#if( ENABLE_HSYNC_HANDLER )
void msVDHSyncHandlerReset(void)
{
    BYTE ucBank;

    ucBank = msReadByte( BK0_00_REGBK);
    msWriteByte( BK0_00_REGBK, REG_BANK2_VD );

    msWriteBit( BK2_4E_BK_WINDOW1, 0, _BIT7 ); // Use defalut Back-Porch window center position

    msWriteByte( BK0_00_REGBK, ucBank );
}
void msVDHSyncHandler(void)
{
    BYTE ucBank;

    if( g_ucVDHSyncHandler_Timer )
        return;

    g_ucVDHSyncHandler_Timer = 0xFF;


    ucBank = msReadByte( BK0_00_REGBK);
    msWriteByte( BK0_00_REGBK, REG_BANK2_VD );

    if( (g_VdInfo.ucVideoSystem == SIG_NTSC) && (msVDDSPReadByte( DSP_3A ) > 85) )
    {
        if( !(msReadByte( BK2_4E_BK_WINDOW1)&_BIT7) )
        {
            msWriteBit( BK2_4E_BK_WINDOW1, 1, _BIT7 );
            msWriteByte( BK2_4F_BK_WINDOW2, 0x76 ); // Right shift Back-Porch window center position
        }
    }
    else
    {
        if( (msReadByte( BK2_4E_BK_WINDOW1)&_BIT7) )
        {
            msWriteBit( BK2_4E_BK_WINDOW1, 0, _BIT7 ); // Use defalut Back-Porch window center position        }
        }
    }

    msWriteByte( BK0_00_REGBK, ucBank );
}
#endif

#if( ENABLE_PAL_SWITCH_HANDLER )
#define PAL_SWITCH_AUTO         0
#define PAL_SWITCH_FORCE_PAL    1
#define PAL_SWITCH_FORCE_NTSC   2

void msVDPalSwitchCtl( BYTE ucCtl )
{
    BYTE ucBank;

    if(VD_Type==MARIA2_B)
        return;

    ucBank = msReadByte( BK0_00_REGBK);
    msWriteByte( BK0_00_REGBK, REG_BANK2_VD );

    if( ucCtl == PAL_SWITCH_AUTO )
    {
        msWriteByteMask(BK2_21_APLL_CTRL2, 0x00, 0x06); // Auto detect PAL/NTSC
    }
    else if( ucCtl == PAL_SWITCH_FORCE_PAL )
    {
        msWriteByteMask(BK2_21_APLL_CTRL2, 0x06, 0x06); // Force PAL
    }
    else if( ucCtl == PAL_SWITCH_FORCE_NTSC )
    {
        msWriteByteMask(BK2_21_APLL_CTRL2, 0x04, 0x06); // Force NTSC
    }

    msWriteByte( BK0_00_REGBK, ucBank );
}

void msVDPalSwitchHandlerReset(void)
{
    msVDPalSwitchCtl( PAL_SWITCH_AUTO );
    g_ucPalSwitchHandler_Timer = 250;
}

void msVDPalSwitchHandler(void)
{
    BYTE ucPalSwitchForceCtl = PAL_SWITCH_AUTO;
    WORD wStatus;
    WORD wVDModeDetectMask = (VD_HSYNC_LOCKED|VD_VSYNC_50HZ|VD_FSC_TYPE|VD_RESET_ON);

    if( g_ucPalSwitchHandler_Timer )
        return;
    g_ucPalSwitchHandler_Timer = 100;

    if( ( g_VdInfo.ucVideoSystem == SIG_PAL_60 )
      ||( g_VdInfo.ucVideoSystem ==SIG_NTSC_443 )
      )
    {
        wVDModeDetectMask |= VD_PAL_SWITCH;
    }

    wStatus = msVDGetSyncStatus();

    if( (wStatus&VD_HSYNC_LOCKED)   // Has signal
      &&((wStatus&wVDModeDetectMask) == (g_VdInfo.wVideoStatus&wVDModeDetectMask))
      &&(msDSP_Std_GetNoiseMag() > 0x10) // Noisy signal
      )
    {
        switch( g_VdInfo.ucVideoSystem )
        {
            case SIG_SECAM:
            case SIG_PAL:
            case SIG_PAL_NC:
        #if( ENABLE_SW_DETECT_COLOR_STD )
            case SIG_PAL_M:
            case SIG_PAL_60:
		if(VD_Type>=MARIA2_E)
        #endif
                ucPalSwitchForceCtl = PAL_SWITCH_FORCE_PAL;
                break;
        #if( ENABLE_SW_DETECT_COLOR_STD )
            case SIG_NTSC:
            case SIG_NTSC_443:
            default:
		if(VD_Type>=MARIA2_E)
                ucPalSwitchForceCtl = PAL_SWITCH_FORCE_NTSC;
                break;
        #endif
        }
        msVDPalSwitchCtl( ucPalSwitchForceCtl );
    }
    else // No sync or Sync unstable or clean signal
    {
        msVDPalSwitchCtl( PAL_SWITCH_AUTO );
        g_ucPalSwitchHandler_Timer = 255;
    }
}
#endif

typedef enum _DplSel
{
    DPL_SEL_FAST,
    DPL_SEL_NORMAL,
    DPL_SEL_NORMAL2,
    DPL_SEL_NOISY,
    DPL_SEL_VCR,
    DPL_SEL_SYNC_50,
    DPL_SEL_SYNC_20,
    DPL_SEL_NO_COLOR,
    DPL_SEL_NUMS
} EnuDplSel;


code BYTE tDplCoef[DPL_SEL_NUMS][2] =
{   //   K1      K2
    {   0x30,   0x65    },  // DPL_SEL_FAST,
    {   0x2B,   0x40    },  // DPL_SEL_NORMAL,
    {   0x2B,   0x40    },  // DPL_SEL_NORMAL2, noise > 0x10
    {   0x2B,   0x40    },  // DPL_SEL_NOISY,
    {   0x34,   0x2C    },  // DPL_SEL_VCR,
    {   0x1A,   0x35    },  // DPL_SEL_SYNC_50,
    {   0x10,   0x10    },  // DPL_SEL_SYNC_20
    {   0x01,   0x02    },  // DPL_SEL_NO_COLOR
};

void msVDAFECHandler(void)
{
    BYTE ucBank;
    BYTE ucDplSel = DPL_SEL_NORMAL;

//    if( g_ucAFECHnadler_Timer )
//        return;
//    g_ucAFECHnadler_Timer = 50;

    ucBank = msReadByte( BK0_00_REGBK );

	if( VD_AGC_GetSyncMag() < 130 ) // 50%
	{
	    if( VD_AGC_GetSyncMag() < 50 ) // 20%
			ucDplSel = DPL_SEL_SYNC_20;
          else
			ucDplSel = DPL_SEL_SYNC_50;
	}
	else
	{
	       WORD wCurSyncStatus = msVDGetSyncStatus();
              if( (wCurSyncStatus&VD_MODE_DETECT_MASK) != (g_VdInfo.wVideoStatus&VD_MODE_DETECT_MASK) )// Sync change
              {
                ucDplSel = DPL_SEL_FAST;
              }
		else if( bNoisy_Det )
		{
    		ucDplSel = DPL_SEL_NOISY;
		}
    #if( ENABLE_VCR_HANDLER )
		else if( g_bVDVCRHandler_VCRMode )
		{
    		ucDplSel = DPL_SEL_VCR;
		}
    #endif
		else
		{
		    if( g_ucAFECHnadler_LaseDplSel == DPL_SEL_NORMAL2 )
		    {
                if( msDSP_Std_GetNoiseMag() < 0x0D )
                    ucDplSel = DPL_SEL_NORMAL;
		    }
		    else
		    {
                if( msDSP_Std_GetNoiseMag() >= 0x10 )
                    ucDplSel = DPL_SEL_NORMAL2;
                else
                    ucDplSel = DPL_SEL_NORMAL;
		    }
		}
	}

	msWriteByte( BK0_00_REGBK, REG_BANK2_VD );
	msWriteByte( BK2_A0_DPL_K1_FORCE, tDplCoef[ucDplSel][0]|_BIT7 );
    msWriteByte( BK2_A1_DPL_K2_FORCE, tDplCoef[ucDplSel][1] );

    msWriteByte( BK0_00_REGBK, ucBank );
}


void msVideoAGCHandle(void)
{
#if RM_EEPROM_TYPE<RM_TYPE_SST512
    BYTE TempAGCValue;
    BYTE TempNoiseValue=msDSP_Std_GetNoiseMag();

    if(TempNoiseValue>=10)
      return;

    TempAGCValue =(VD_AGC_GetCurGain()>>8);

    if(TempAGCValue==g_VideoSetting.videoAGC)
        {
            g_ucLastVideoAGC=g_VideoSetting.videoAGC;
            g_ucVideoAGCCount=0;
        }
    else
        {
            if(TempAGCValue==g_ucLastVideoAGC)
                g_ucVideoAGCCount++;
            else
                {
                    g_ucLastVideoAGC=TempAGCValue;
                    g_ucVideoAGCCount=0;
                }
        }

    if(g_ucVideoAGCCount>50)
        {
            g_ucVideoAGCCount=0;
            if((TempAGCValue>=5)&&(TempAGCValue<=12))
                {
                    g_VideoSetting.videoAGC=TempAGCValue;
                    SaveVideoSetting();
                }
        }
#endif
}
#if (ENABLE_DDC2BI)
void msVDDSPWrite2Bytes(BYTE ucAddr, WORD wData)
{
bit bET0 = ET0;
ET0 = 0;
  	msWriteByte( BK2_07, ucAddr );
       msWriteByte( BK2_08, wData );
  	msWriteByte( BK2_07, ucAddr+1 );
       msWriteByte( BK2_08, wData>>8 );
ET0 = bET0;
}
BYTE XDATA g_ucCheckDSPVSYNCCount;
void CheckDSPVSYNC(void)
{
BYTE ucBank,DSP90_Value;
      if(g_ucCheckDSPVSYNCCount--)
	  	return;

      g_ucCheckDSPVSYNCCount=5;
      ucBank = msReadByte( BK0_00_REGBK );


      msWriteByte( BK0_00_REGBK, REG_BANK2_VD );
      DSP90_Value=msVDDSPReadByte( 0x90 );

      while(DSP90_Value!=0x12)
        {
            Delay1ms(2);
	     msVDDSPWrite2Bytes(0x86, 0x0008);
            msVDDSPWrite2Bytes(0x88, 0x0008);
            msVDDSPWrite2Bytes(0x8c, 0x0009);
            msVDDSPWrite2Bytes(0x8E, 0x0009);
	     msVDDSPWrite2Bytes(0x90, 0x0012);
            msVDDSPWrite2Bytes(0x92, 0x0012);
            Delay1ms(1);
            DSP90_Value=msVDDSPReadByte( 0x90 );
        }

       msWriteByte( BK0_00_REGBK, ucBank );
}
#endif

#if( ENABLE_SW_DETECT_COLOR_STD )
void msVDDetectColorStdInit(void)
{
    g_ucVD_ColorStd = DSP_COLOR_UNKNOWN;
    g_ucVD_ColorStdNew = DSP_COLOR_UNKNOWN;
    g_ucVD_ColorStdChangeCounter = 0;
    g_ucVD_ColorStdCounter = 0;
    g_ucVD_ColorStdCounter_Unknown = 0;
    g_ucVD_ColorStdCounter_Ntsc = 0;
    g_ucVD_ColorStdCounter_Pal = 0;
}
void msVDDetectColorStd(void)
{
    BYTE ucBank = msReadByte( BK0_00_REGBK);
    BYTE ucBackupBK2_04;
    BYTE ucBurstPhaseDiff;


    if( msDSP_Std_GetBurstMag() < 0x18 )
        return;

    msWriteByte( BK0_00_REGBK, REG_BANK2_VD );
    ucBackupBK2_04 = msReadByte( BK2_04 );

    msWriteByte( BK2_04, 0x23 );
    ucBurstPhaseDiff = msReadByte( BK2_01 );

    g_ucVD_ColorStdCounter ++;
    if( (ucBurstPhaseDiff < 32)||(ucBurstPhaseDiff > 0xDF) )
        g_ucVD_ColorStdCounter_Ntsc ++;
    else if( (ucBurstPhaseDiff < 0x60)||(ucBurstPhaseDiff > 0x9F) )
        g_ucVD_ColorStdCounter_Pal ++;
    else
        g_ucVD_ColorStdCounter_Unknown ++;

    if( g_ucVD_ColorStdCounter >= COLOR_STD_COUNT_MAX )
    {
        g_ucVD_ColorStdCounter = 0;
        g_ucVD_ColorStdNew = g_ucVD_ColorStd;

        if( (g_ucVD_ColorStdCounter_Unknown > g_ucVD_ColorStdCounter_Ntsc)
          &&(g_ucVD_ColorStdCounter_Unknown > g_ucVD_ColorStdCounter_Pal)
          )
        {
            g_ucVD_ColorStdNew = DSP_COLOR_UNKNOWN;
        }
        else
        {
            if( g_ucVD_ColorStdCounter_Ntsc > (COLOR_STD_COUNT_MAX/2 + 1) )
            {
                g_ucVD_ColorStdNew = DSP_COLOR_NTSC;
            }
            else if( g_ucVD_ColorStdCounter_Pal > (COLOR_STD_COUNT_MAX/2 + 1) )
            {
                g_ucVD_ColorStdNew = DSP_COLOR_PAL;
            }
        }

//        if( g_dspDebugInfoIdx < 0x40 )
//        {
//            g_dspDebugInfo[g_dspDebugInfoIdx+0] = g_ucVD_ColorStd;
//            g_dspDebugInfo[g_dspDebugInfoIdx+1] = g_ucVD_ColorStdCounter_Ntsc;
//            g_dspDebugInfo[g_dspDebugInfoIdx+2] = g_ucVD_ColorStdCounter_Pal;
//            g_dspDebugInfo[g_dspDebugInfoIdx+3] = g_ucVD_ColorStdCounter_Unknown;
//            g_dspDebugInfo[g_dspDebugInfoIdx+4] = g_ucVD_ColorStdNew;
//            g_dspDebugInfoIdx += 8;
//        }

        if( g_ucVD_ColorStdNew != g_ucVD_ColorStd )
        {
            g_ucVD_ColorStdChangeCounter ++;
            if( g_ucVD_ColorStdChangeCounter > 2 )
            {
                g_ucVD_ColorStdChangeCounter = 0;
                g_ucVD_ColorStd = g_ucVD_ColorStdNew;
            }
        }
        else
            g_ucVD_ColorStdChangeCounter = 0;

    #if( ENABLE_DEBUG_SW_DETECT_COLOR_STD )
        g_ucVD_ColorStdCounterL_Unknown = g_ucVD_ColorStdCounter_Unknown;
        g_ucVD_ColorStdCounterL_Ntsc = g_ucVD_ColorStdCounter_Ntsc;
        g_ucVD_ColorStdCounterL_Pal = g_ucVD_ColorStdCounter_Pal;
    #endif
        g_ucVD_ColorStdCounter_Unknown = 0;
        g_ucVD_ColorStdCounter_Ntsc = 0;
        g_ucVD_ColorStdCounter_Pal = 0;
    }

    msWriteByte( BK2_04, ucBackupBK2_04 );
    msWriteByte( BK0_00_REGBK, ucBank );
}
#endif


⌨️ 快捷键说明

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