Hello
@avst,
The source file Sync.c from Realtek is very long, very complex or seems to cover many types of sync, many type of input signals.
So far, I was able to understand from your suggestions on
january 1st how to auto-detect what type of sync signals through this part of sync.c code
#if(_HSYNC_TYPE_DETECTION == _AUTO_RUN)
/**
* CSyncGetSyncTypeAutoRun
* Get VGA sync type by Hsync Type Detection Auto Run
* @param <none>
* @return {sync type}
*
*/
BYTE CSyncGetSyncTypeAutoRun(void)
{
...............................
CScalerSetBit(_STABLE_MEASURE_4F, ~_BIT0, 0x00);//Measure- Clear
CScalerSetBit(_STABLE_MEASURE_4F, ~_BIT0, _BIT0);//Measure- Start
CTimerDelayXms(5);
if((bit)CScalerGetBit(_HSYNC_TYPE_DETECTION_FLAG_4E, _BIT7))
{// Hsync overflow
return _NO_SYNC_STATE;
}
//eric 20070523 VGA long time wake up
CTimerDelayXms(60);
if(!((bit)CScalerGetBit(_STABLE_MEASURE_4F, _BIT7)))//both polarity and period are stable
return _NO_SYNC_STATE;
CScalerSetBit(_STABLE_MEASURE_4F, ~_BIT1, _BIT1);//Pop up result
// Get stable period
CScalerRead(_STABLE_PERIOD_H_50, 2, pData, _AUTOINC);
((WORD *)pData)[1] = ((pData[0] & 0x07) << 8) | pData[1];
...............
CScalerSetBit(_STABLE_MEASURE_4F, ~_BIT0, 0x00);//stable measure stop
CScalerSetBit(_SYNC_SELECT_47, ~_BIT6, 0x00);
CScalerSetBit(_SYNC_SELECT_47, ~_BIT6, _BIT6); //Enable hsync type detection auto run
if(CTimerPollingEventProc(90, CMiscHsyncTypeAutoRunFlagPollingEvent)) //auto run ready
{
synctemp = (CScalerGetBit(_VSYNC_COUNTER_LEVEL_MSB_4C, 0xff) & 0x70) >> 4;//Measur result
...............................
from which I made below my last code which works detecting if VGA or RGBs or NoInput
int8_t AutoDetectInput(void)
{
uint8_t timeout_i, timeout=90, type_input;
// Reset auto sync detection
ScalerWriteBit(0x4F, 0, 0b0);
ScalerWriteBit(0x4F, 0, 0b1);
delay(5); // wait 5 ms
//check if Hsync is present looking at hsync counter overflow
if(ScalerReadBit(0x4E,7))
{
Serial.println("No Input");
return(-1);
}
else
{
delay(60); // wait another 60 ms
if(ScalerReadBit(0x4F,7)==0)
{
Serial.println("No stable measurement");
return(-2);
}
Serial.println("Signal present");
ScalerWriteBit(0x4F, 1, 0b1); // pop up stable value
}
Serial.print("Stable Hysnc period => ");Serial.println(((ScalerReadByte(0x50) & 0x7) << 8) + ScalerReadByte(0x51),DEC);
ScalerWriteByte(0x4C, (ScalerReadByte(0x4C) & 0xF8) | (ScalerReadByte(0x50) & 0x07));
ScalerWriteByte(0x4D,ScalerReadByte(0x51));
ScalerWriteBit(0x4F, 0, 0b0); // stop stable measure
ScalerWriteBit(0x47, 6, 0b0);
ScalerWriteBit(0x47, 6, 0b1); // enable hysnc type detection auto run
// Polling bit 7 of 0x4C
for (timeout_i = 0; (timeout_i <= timeout) && (ScalerReadBit(0x4C, 7) == 0); timeout_i++)
if (timeout != timeout_i) delay(1); // wait 1 ms
else
{
Serial.println("Time-out hysnc type detection");
return -3;
}
type_input = (ScalerReadByte(0x4C) & 0x70) >> 4;
Serial.print("HSync type detection auto run => ");Serial.println(type_input,BIN);
if(type_input == 0) Serial.println("Not support");
if(type_input == 5) Serial.println("RGBS input");
if(type_input == 6) Serial.println("VGA input");
return type_input;
}
However it only works if either RGBs or VGA signal was initially detected by OpenRTD2662 firmware. If no input signal was detected, the OpenRTD2662 will wait and detect any signal with its own unknown loop. Once entering ISP mode, the DW8051 is halted so we need to generate via the arduino as a Kernel the correct detection loop which means other register programming.