📄 lcd_main.c
字号:
{
bStable = (ucMode_Curr == ucMode_Found) ? 1 : 0; // bStable must be cleared when mode changed
ucMode_Curr = ucMode_Found;
ucMode_Times = NO_MODE_TIMES - 2;
usOSD_Timer = 1020;
if (MODE_NOSIGNAL == ucMode_Curr)
{
if (SYNC_CS == ucSync_Type) // CS->SS
{
RTDCodeW(VGA_SET_SS);
bVpole_Curr = 1;
bHpole_Curr = 1;
ucSync_Type = SYNC_SS;
}
else if (SYNC_SS == ucSync_Type) // SS->SOG
{
RTDCodeW(VGA_SET_SOG);
bVpole_Curr = 1;
bHpole_Curr = 1;
ucSync_Type = SYNC_SOG;
}
else // SOG->CS
{
RTDCodeW(VGA_SET_CS);
bVpole_Curr = 1;
bHpole_Curr = 1;
ucSync_Type = SYNC_CS;
}
}
}
}
else
{
if (ucMode_Found != ucMode_Temp)
{
ucMode_Times = 1;
ucMode_Found = ucMode_Temp;
#if(SOURCE_AUTO_SCAN == FALSE)
// To prevent from mistaking CS (with VS) for SS, we check SYNC type once when finding a mode in SS.
if (SYNC_SS == ucSync_Type)
{
RTDSetByte(SYNC_CTRL_4B, 0x55);
RTDSetByte(SYNC_POR_4C, 0x22);
m = (MODE_DETECT_FREQ + 1) * 20;
do
{
Delay_Xms(1);
RTDRead(SYNC_POR_4C, 0x05, Y_INC);
}
while ((Data[0] & 0x02) && (--m));
Data[5] = Data[3];
Data[4] = Data[4] & 0x87;
Data[3] = Data[1];
Data[2] = Data[2] & 0x8f;
if ((0 == ((unsigned int *)Data)[1]) || (0x07ff <= ((unsigned int *)Data)[1]) ||
(0 == ((unsigned int *)Data)[2]) || (0x07ff <= ((unsigned int *)Data)[2]) ||
(0 == m))
{
ucSync_Type = SYNC_SS;
RTDSetByte(SYNC_CTRL_4B, 0x14);
}
else
{
ucSync_Type = SYNC_CS;
RTDCodeW(VGA_SET_CS);
bVpole_Curr = 1;
bHpole_Curr = 1;
}
}
else if (SYNC_SOG == ucSync_Type)
{
RTDSetByte(SYNC_CTRL_4B, 0x14);
Delay_Xms(8);
RTDSetByte(SYNC_POR_4C, 0x00);
RTDSetByte(SYNC_POR_4C, 0x02);
m = (MODE_DETECT_FREQ + 1) * 20;
do
{
Delay_Xms(1);
RTDRead(SYNC_POR_4C, 0x05, Y_INC);
}
while ((Data[0] & 0x02) && (--m));
Data[5] = Data[3];
Data[4] = Data[4] & 0x87;
Data[3] = Data[1];
Data[2] = Data[2] & 0x8f;
if ((0 == ((unsigned int *)Data)[1]) || (0x07ff <= ((unsigned int *)Data)[1]) ||
(0 == ((unsigned int *)Data)[2]) || (0x07ff <= ((unsigned int *)Data)[2]) ||
(0 == m))
{
ucSync_Type = SYNC_SOG;
RTDSetByte(SYNC_CTRL_4B, 0x57);
//RTDCodeW(VGA_SET_SOG);
//RTDSetByte(VGIP_SIGINV_05, 0x40);
Delay_Xms(8);
//To avoid the 1600x1200@60Hz measurement can't stable,
//So set measure command once, then clear it
RTDSetByte(SYNC_POR_4C, 0x32);
Delay_Xms(20);
RTDSetByte(SYNC_POR_4C, 0x00);
}
else
{
ucSync_Type = SYNC_SS;
RTDCodeW(VGA_SET_SS);
bVpole_Curr = 1;
bHpole_Curr = 1;
}
}
#endif
}
else
{
if (VGA_SEARCH_TIMES > ucMode_Times)
{
ucMode_Times ++;
}
else
{
bLIGHT_PWR = LIGHT_OFF; // Turn off BackLight for reset display
RTDSetByte(HOSTCTRL_02, 0x40); // Wake RTD up
RTDCodeW(OSD_Reset); // Clear OSD
ucMode_Curr = ucMode_Found; // Supported mode found
ucMode_Times = 0; // Reset mode timer
bStable = 0; // bStable must be cleared when mode changed
Display_VGA_Set(); // Set VGA Mode registers
if(Auto_mode)
Auto_Balance();
#if (RTDDEBUG)
if (ucMode_PrevAct == ucMode_Curr)
{
if (0xff > ucMode_QuitCnt) ucMode_QuitCnt += 1;
}
else
{
ucMode_PrevAct = ucMode_Curr;
ucMode_QuitCnt = 0;
ucDebug = 0;
}
#endif
}
}
}
}
//------------------- Check VGA Mode -------------------//
void Check_VGA_Mode(void)
{
RTDRead(SYNC_POR_4C, 0x05, Y_INC);
if (Data[0] & 0x02)
{
RTDSetByte(SYNC_POR_4C, 0x20); // Input signal time-out. Reset sync-processor
ucMode_Found = MODE_NOSUPPORT;
}
else
{
bVpole_Curr = (bit)(Data[0] & 0x08); // Current usVsync polarity
bHpole_Curr = (bit)(Data[0] & 0x04); // Current usHsync polarity
Data[5] = Data[3];
Data[4] = Data[4] & 0x87;
Data[3] = Data[1];
Data[2] = Data[2] & 0x8f;
usHsync = ((unsigned int *)Data)[1]; // Current usHsync timing
usVsync = ((unsigned int *)Data)[2]; // Current usVsync timing
// Polarity must be correct
if ((bVpole_Curr != bVpole_Prev) || (bHpole_Curr != bHpole_Prev))
{
RTDRead(VGIP_SIGINV_05, 0x01, N_INC);
Data[0] &= 0xd7; // HS_RAW & VS positive
if (!bHpole_Curr) Data[0] |= 0x20;
if (!bVpole_Curr && SYNC_SS == ucSync_Type) Data[0] |= 0x08; // Seperate sync
RTDSetByte(VGIP_SIGINV_05, Data[0]);
ucMode_Found = MODE_NOSUPPORT;
}
else
{
if (0x07ff <= usHsync || 0x07ff <= usVsync || 0 == usHsync || 0 == usVsync) // Check overflow
{
ucMode_Found = MODE_NOSUPPORT;
}
else
{
if ((usHsync < (usStdHS - 1)) || (usHsync > (usStdHS + 3)) ||
(usVsync < (usStdVS - 1)) || (usVsync > (usStdVS + 3)))
{
ucMode_Found = MODE_NOSUPPORT;
}
else
{
ucMode_Found = ucMode_Curr;
}
}
}
}
if (MODE_NOSUPPORT == ucMode_Found)
{
Reset_Mode();
}
else
{
bStable = 1; // Set bStable to 1 when signal timing is stable.
LED_GREEN = 0X00;
LED_RED = 0X01;
#if(AS_NON_FRAMESYNC)
RTDSetByte(STATUS0_01, 0x00); // Clear status
RTDSetByte(STATUS1_1F, 0x00); // Clear status
if(bFrameSync)
RTDSetBit(ODD_CTRL_8E,0xef,0x10);
#endif
}
}
/////////////////////////////////////////////////////////
//------------------ Detect DVI Mode ----------------//
/////////////////////////////////////////////////////////
void Detect_DVI_Mode(void)
{
#if(TMDS_ENABLE)
unsigned char ucMode_Temp, m;
RTDRead(SYNC_POR_4C, 0x05, Y_INC);
if (Data[0] & 0x02)
{
RTDSetByte(SYNC_POR_4C, 0x00); // Input signal time-out. Reset sync-processor
ucMode_Temp = MODE_NOSIGNAL;
}
else
{
usStdHS = usHsync; // Save previous usHsync in usStdHS
usStdVS = usVsync; // Save previous usVsync in usStdVS
bVpole_Curr = (bit)(Data[0] & 0x08); // Save current usVsync polarity
bHpole_Curr = (bit)(Data[0] & 0x04); // Save current usHsync polarity
Data[5] = Data[3];
Data[4] = Data[4] & 0x87;
Data[3] = Data[1];
Data[2] = Data[2] & 0x8f;
usHsync = ((unsigned int *)Data)[1]; // Current usHsync timing
usVsync = ((unsigned int *)Data)[2]; // Current usVsync timing
// Calculate Vertical Refresh Rate
// Original Formula :
// ucRefresh = 24.576M / (usHsync * usVsync)
// Use Data[0~3] as a temporary long variable
((unsigned long *)Data)[0] = (unsigned long)usHsync * usVsync;
ucRefresh = (unsigned long)49152000 / ((unsigned long *)Data)[0];
ucRefresh = (ucRefresh & 0x01) ? ((ucRefresh + 1) >> 1) : (ucRefresh >> 1);
// Treat small change of usHsync/usVsync as no change
if (usStdHS <= usHsync && (usStdHS + 2) >= usHsync) usHsync = usStdHS;
if (usStdVS <= usVsync && (usStdVS + 2) >= usVsync) usVsync = usStdVS;
// Set correct polarity
if ((bVpole_Curr != bVpole_Prev) || (bHpole_Curr != bHpole_Prev))
{
RTDRead(VGIP_SIGINV_05, 0x01, N_INC);
Data[0] &= 0xf3; // VS & HS positive
if (!bVpole_Curr) Data[0] |= 0x08;
if (!bHpole_Curr) Data[0] |= 0x04;
RTDSetByte(VGIP_SIGINV_05, Data[0]);
}
if (0x07ff <= usHsync || 0x07ff <= usVsync || 0 == usHsync || 0 == usVsync)
{
ucMode_Temp = MODE_NOSIGNAL; // Treat overflow as no signal
}
else
{
ucMode_Temp = MODE_NOSUPPORT;
// Search for Standard Mode
m = MODE_1600x1200x60HZ;
do
{
if ((usHsync > VGA_Mode[m][0]) && (usHsync < VGA_Mode[m][1]))
{
if ((usVsync >= VGA_Mode[m][2]) && (usVsync <= VGA_Mode[m][3]))
{
ucMode_Temp = m; // Support mode
}
}
}
while ((0 != --m) && (MODE_NOSUPPORT == ucMode_Temp));
if (MODE_NOSUPPORT == ucMode_Temp)
{
// Search for User Mode
m = MODE_USER1600x1200;
do
{
if ((usHsync >= VGA_Mode[m][0]) && (usHsync <= VGA_Mode[m][1]))
{
if ((usVsync >= VGA_Mode[m][2]) && (usVsync <= VGA_Mode[m][3]))
{
ucMode_Temp = m; // Support User Mode
}
}
}
while ((MODE_USER720x400 <= --m) && (MODE_NOSUPPORT == ucMode_Temp));
}
if (48 > ucRefresh || MAX_RATE < ucRefresh)
ucMode_Temp = MODE_NOSUPPORT; // We don't support vertical refresh rate lower than 50Hz
else
ucMode_Temp = Seek_DVI_Mode(ucMode_Temp); // Seek mode in according to data enable width and height
}
}
//-------------Check result--------------
if (MODE_NOSUPPORT == ucMode_Temp || MODE_NOSIGNAL == ucMode_Temp) // No Detect
{
if (MODE_NOSUPPORT != ucMode_Found && MODE_NOSIGNAL != ucMode_Found) ucMode_Times = 0;
ucMode_Found = ucMode_Temp;
if (NO_MODE_TIMES > ucMode_Times)
{
ucMode_Times ++;
}
else
{
bStable = (ucMode_Curr == ucMode_Found) ? 1 : 0; // bStable must be cleared when mode changed
ucMode_Curr = ucMode_Found;
ucMode_Times = NO_MODE_TIMES - 2;
}
}
else
{
if (ucMode_Found != ucMode_Temp)
{
ucMode_Times = 1;
ucMode_Found = ucMode_Temp;
}
else
{
if (DVI_SEARCH_TIMES > ucMode_Times)
{
ucMode_Times ++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -