forked from danyaPostfactum/RTD2662
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Mode.c
executable file
·2973 lines (2605 loc) · 89 KB
/
Mode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//----------------------------------------------------------------------------------------------------
// ID Code : Mode.c No.0002
// Update Note :
//
//----------------------------------------------------------------------------------------------------
#define __MODE__
#include "Core\Header\Include.h"
unsigned char code HDMI_ModeMap[] =
{
0, 1, 2, 2, 3, 4,
1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 5, 2,
2, 3, 4, 1, 1, 1,
1, 1, 1, 1, 1, 2,
2, 5, 5, 5, 5
};
//--------------------------------------------------
// Description : Mode handler, the main control flow
// Input Value : None
// Output Value : None
//--------------------------------------------------
void CModeHandler(void)
{
if (CPowerHandler())
{
ucCurrState = GET_POWERSTATUS() ? _INITIAL_STATE : _PWOFF_STATE;
}
switch (ucCurrState)
{
case _PWOFF_STATE:
ucCurrState = GET_POWERSTATUS() ? _INITIAL_STATE : _PWOFF_STATE;
break;
#if(_OSD_TYPE == _OSD007)
case _SOURCE_CHANGE_STATE:
//CPowerLightPowerOff();
CTimerDelayXms(20);
break;
#endif
case _INITIAL_STATE:
if (bSourceVideo())
{
CVideoInitial();
}
SET_FIRST_SHOW_NOTE();
ucCurrState = _SEARCH_STATE;
#if(_LOGO_ENABLE)
#if(_OSD_TYPE == _OSD003)
CModeSetFreeRun();
CDrawLogo(0x03);
CPowerPanelOn();
CPowerLightPowerOn();
CPattenChange();
#endif
#endif
if(GET_FIRST_LOADFONT() == _TRUE)
{
CLR_FIRST_LOADFONT();
COsdDispFirstTimeLoadFont();
#if(_OSD_TYPE == _OSD002)
g_ucMenuItemIndex = _MENU_NONE;
#endif
}
if (_GET_INPUT_SOURCE() == _SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI)
{
CShowNote();//ucOsdEventMsg = _DO_SHOW_NOTE;
CPowerPanelOn();
if (GET_LIGHTPOWERSTATUS() == _OFF)
{
CPowerLightPowerOn();
}
}
break;
case _SEARCH_STATE:
#if(AUDIO_TYPE == _AUDIO_SC7313)
CInitSoundChannel(_GET_INPUT_SOURCE());
#endif
case _ACTIVE_STATE:
case _NOSIGNAL_STATE:
case _NOSUPPORT_STATE:
case _SLEEP_STATE:
switch (_GET_INPUT_SOURCE())
{
case _SOURCE_YPBPR:
case _SOURCE_VGA:
case _SOURCE_DVI:
case _SOURCE_HDMI:
CSyncProcess();
break;
#if(_VIDEO_SUPPORT == _ON)
case _SOURCE_VIDEO_AV:
case _SOURCE_VIDEO_SV:
case _SOURCE_VIDEO_TV:
CVideoProcess();
break;
#endif
case _SOURCE_NONE: // Don't need to do anything
break;
default:
break;
}
break;
default:
while(_TRUE);
}
}
//--------------------------------------------------
// Description : Check measure ready process
// Input Value : None
// Output Value : Return _TRUE if measure finished, _FALSE if timeout
//--------------------------------------------------
bit CModeMeasureReady(void)
{
CScalerSetBit(_SYNC_SELECT_47, ~_BIT0, 0x00);
CAdjustSyncProcessorMeasureStart();
if (CTimerPollingEventProc(60, CMiscModeMeasurePollingEvent))
{
return _TRUE;
}
else
{
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT5, 0x00);
return _FALSE;
}
}
/**
* CSyncMeasureSyncType
* Get measure data and convert into system information
* @param <none>
* @return {_TRUE if success, _FALSE if the measurement result is out of range}
*
*/
bit CModeMeasureData(void)
{
if(_GET_INPUT_SOURCE() == _SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI)
{
CScalerSetBit(_SYNC_SELECT_47, ~_BIT6, _BIT6);
CScalerSetBit(_SYNC_CTRL_49, ~_BIT2, _BIT2);
}
// Read measurement status bit
CScalerRead(_MEAS_HS_PERIOD_H_52, 3, &pData[8], _AUTOINC);//
if((bit)(pData[8] & _BIT4) || (bit)(pData[10] & _BIT4) || (bit)(pData[10] & _BIT5))
{
return _FALSE;
}
// Pop up measurement result
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
if(CTimerPollingEventProc(60, CMiscMeasureResultPOPPollingEvent))
{
CScalerSetBit(_MEAS_HS_VS_HI_SEL_58, ~_BIT0, 0x00);
CScalerRead(_MEAS_HS_PERIOD_H_52, 6, &pData[8], _AUTOINC);
// Calculate measurement result
((WORD *)pData)[0] = ((pData[8] & 0x1f) << 8) | pData[9];
((WORD *)pData)[1] = ((pData[10] & 0x1f) << 8) | pData[11];
((WORD *)pData)[2] = ((pData[12] & 0xf0) << 4) | pData[13];
if((((WORD *)pData)[0] >= 0x07ff) || (((WORD *)pData)[1] >= 0x07ff) || (((WORD *)pData)[0] == 0) || (((WORD *)pData)[1] == 0))
{
// The measurement result is out of range
return _FALSE;
}
else
{
// Store measurement results in global system variable
stModeInfo.Polarity = (pData[10] & 0xc0) >> 6;
stModeInfo.IHCount = ((WORD *) pData)[0];
stModeInfo.IHFreq = (WORD) ((DWORD) _RTD_XTAL * 10 * 2 / stModeInfo.IHCount);
stModeInfo.IHFreq = (stModeInfo.IHFreq >> 1) + (stModeInfo.IHFreq & 0x01);
stModeInfo.IVTotal = ((WORD *) pData)[1];
stModeInfo.IVFreq = (WORD)((DWORD) (stModeInfo.IHFreq) * 1000 * 2 / stModeInfo.IVTotal);
stModeInfo.IVFreq = (stModeInfo.IVFreq >> 1) + (stModeInfo.IVFreq & 0x01);
stModeInfo.IHSyncPulseCount = ((WORD *) pData)[2];
if((_GET_INPUT_SOURCE()==_SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI) && (ucCurrState==_SEARCH_STATE)) //for philips dvd player(dvp5965k) hdmi timing
CTimerDelayXms(40);
return _TRUE;
}
}
else
return _FALSE;
}
//----------------------------------------------------------------------------------------------------
// Mode Detect Functions
//----------------------------------------------------------------------------------------------------
/**
* CModeDetect
* mode detect according to the input port
* @param <none>
* @return {TRUE if sync type is identified;FALSE if no sync}
*
*/
//--------------------------------------------------
// Description : Mode detect process
// Input Value : None
// Output Value : Return _TRUE if we get a stable mode
//--------------------------------------------------
bit CModeDetect(void)
{
switch (_GET_INPUT_SOURCE())
{
case _SOURCE_VGA:
#if(_TMDS_SUPPORT == _ON)
case _SOURCE_DVI:
#endif
#if(_YPBPR_SUPPORT == _ON)
case _SOURCE_YPBPR:
#endif
case _SOURCE_HDMI:
if (CModeDetectCommon())
return _TRUE;
break;
}
return _FALSE;
}
/**
* CModeDetect
* Mode detect process for VGA and DVI
* first decide if mode is exist,then decide if the signal is stable
* if there is nosignal but it is stable,also return TRUE
* @param <none>
* @return {_TRUE if there is a stable mode;_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Mode detect process for VGA and DVI
// Input Value : None
// Output Value : Return _TRUE if we get a stable mode
//--------------------------------------------------
bit CModeDetectCommon(void)
{
BYTE modetemp = _MODE_NOSIGNAL;
BYTE polaritytemp;
WORD hcount, vtotal;
if (CModeMeasureReady())
{
polaritytemp = stModeInfo.Polarity;
hcount = stModeInfo.IHCount;
vtotal = stModeInfo.IVTotal;
// Get measure results and decide " modetemp = _MODE_NOSIGNAL/_MODE_NOSUPPORT/_MODE_EXIST "
if (CModeMeasureData())
{
CSyncModifyPolarityVGA();
stModeInfo.ModeCurr = _MODE_NOSIGNAL;
if (abs(stModeInfo.IHCount - hcount) <= 1)
stModeInfo.IHCount = hcount;
if (abs(stModeInfo.IVTotal - vtotal) <= 2)
stModeInfo.IVTotal = vtotal;
if ((stModeInfo.IHCount != hcount) ||(stModeInfo.IVTotal != vtotal) || (stModeInfo.Polarity != polaritytemp))
{
modetemp = _MODE_NOSIGNAL;
}
else
{
if ((stModeInfo.IHFreq < Panel[ucPanelSelect]->HSyncMinFreq) ||(stModeInfo.IHFreq > Panel[ucPanelSelect]->HSyncMaxFreq) ||
(stModeInfo.IVFreq < Panel[ucPanelSelect]->VSyncMinFreq) ||(stModeInfo.IVFreq > Panel[ucPanelSelect]->VSyncMaxFreq))
{
modetemp = _MODE_NOSUPPORT;
}
else
{
modetemp = _MODE_EXIST;
}
}
}
else
{
modetemp = _MODE_NOSIGNAL;
}
// Wait mode stable and decide the mode type for current source
if (modetemp != ucModeFound)
{
ucModeFound = modetemp;
ucEvent1 = _INACTIVE_COUNTDOWN_EVENT;
CLR_MODESTABLE();
CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);
return _FALSE;
}
else
{
CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);
if (GET_MODESTABLE())
{
if (ucModeFound == _MODE_EXIST)
{
CModeInterlaceCheck();//v003_interlace_check
stModeInfo.ModeCurr = CModeSearchDisplayMode();
}
else
{
stModeInfo.ModeCurr = ucModeFound;
}
return _TRUE;
}
else
{
return _FALSE;
}
}
}
else
{
return _FALSE;
}
}
/**
* CModeIsChange
* Check if mode is changed
* check the current mode compare with the previous mode
* @param <none>
* @return {_TRUE if mode is changed;_FALSE if not}
*
*/
bit CModeIsChange(void)
{
BYTE polaritytemp;
WORD hcount, vtotal;
polaritytemp = stModeInfo.Polarity;
hcount = stModeInfo.IHCount;
vtotal = stModeInfo.IVTotal;
if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
{
if(CScalerGetBit(_HSYNC_TYPE_DETECTION_FLAG_4E, _BIT6 | _BIT5))
return _TRUE;
}
//DebugPrintf("\nMMD.1.%c",0x20);
if(CModeMeasureData())
{
if(abs(stModeInfo.IHCount - hcount) <= 1)
stModeInfo.IHCount = hcount;
if(abs(stModeInfo.IVTotal - vtotal) <= 2)
stModeInfo.IVTotal = vtotal;
if((stModeInfo.IHCount != hcount) || (stModeInfo.IVTotal != vtotal) || (stModeInfo.Polarity != polaritytemp))
return _TRUE;
else
return _FALSE;
}
else
return _TRUE;
}
/**
* CModeSearchDisplayMode
* Search display mode according to the input source
* called only by CModeDetectCommon
* @param <none>
* @return {_TRUE if there is a stable mode;_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Search display mode process
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchDisplayMode(void)
{
BYTE modetemp;
switch (_GET_INPUT_SOURCE())
{
case _SOURCE_VGA:
modetemp = CModeSearchModeVGA();
break;
#if(_YPBPR_SUPPORT == _ON)
case _SOURCE_YPBPR:
modetemp = CYPbPrSearchMode();
break;
#endif
#if((_TMDS_SUPPORT == _ON) || (_HDMI_SUPPORT == _ON))
case _SOURCE_DVI:
case _SOURCE_HDMI:
modetemp = CModeSearchModeDVI();
break;
#endif
}
return modetemp;
}
/**
* CModeSearchModeVGA
* Search mode for VGA from preset mode to user mode
* called only by CModeSearchDisplayMode
* @param <none>
* @return {_TRUE if there is a stable mode;_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Search mode for VGA
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchModeVGA(void)
{
BYTE modecnt;
SET_MODE_SEARCH_TYPE(_PRESET_MODE_TYPE); ///!set preset mode type
for (modecnt = 0; modecnt < _MAX_PRESET_MODE; modecnt++)
{
if (CModeComparePresetModeVGA(modecnt))
{
if( (modecnt != _MODE_640x400_85HZ) &&
(modecnt != _MODE_720x400_85HZ) &&
(modecnt != _MODE_640x400_70HZ) &&
(modecnt != _MODE_720x400_70HZ) )
{
return modecnt;
}
}
}
modecnt = CModeSearchAcceptiveModeVGA();
if(modecnt==_MODE_640x400_85HZ || modecnt==_MODE_720x400_85HZ)
{
if((BYTE)(GET_MODESELECT_TYPE())==0)
return _MODE_640x400_85HZ;
else
return _MODE_720x400_85HZ;
}
else if(modecnt==_MODE_640x400_70HZ || modecnt==_MODE_720x400_70HZ)
{
if((BYTE)(GET_MODESELECT_TYPE())==0)
return _MODE_640x400_70HZ;
else
return _MODE_720x400_70HZ;
}
if ((modecnt == _MODE_NOSIGNAL) || (modecnt == _MODE_NOSUPPORT))
return modecnt; ///!the returned number is the index in the preset mode
SET_MODE_SEARCH_TYPE(_USER_MODE_TYPE); ///!set user mode type
modecnt = CModeCheckFIFOModeVGA(modecnt); ///!the returned number is the index in the FIFO mode
return modecnt;
}
/**
* CModeComparePresetModeVGA
* Compare the identified mode with preset VGA mode in preset table
* called only by CModeSearchDisplayMode
* @param <BYTE ucModeCnt> {mode number of preset mode in table}
* @return {_TRUE if the input mode number is correspondence to the input mode,_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Compare preset VGA mode
// Input Value : Mode number
// Output Value : Return _TRUE if the input mode number is correspondence
//--------------------------------------------------
bit CModeComparePresetModeVGA(BYTE ucModeCnt)
{
BYTE polarity, polaritytemp;
polarity = (stModeInfo.Polarity & ~_BIT0) | ((bit)CScalerGetBit(_STABLE_PERIOD_H_50, _BIT6) ? 0x00 : _BIT0);
if(abs(stModeInfo.IVFreq - tINPUTMODE_PRESET_TABLE[ucModeCnt].IVFreq) > tINPUTMODE_PRESET_TABLE[ucModeCnt].IVFreqTolerance)
return _FALSE;
if(abs(stModeInfo.IHFreq - tINPUTMODE_PRESET_TABLE[ucModeCnt].IHFreq) > tINPUTMODE_PRESET_TABLE[ucModeCnt].IHFreqTolerance)
return _FALSE;
if(abs(stModeInfo.IVTotal - tINPUTMODE_PRESET_TABLE[ucModeCnt].IVTotal) > 4)//v003
return _FALSE;
if ((bit) (polarity & _BIT0))
{
if ((bit) (polarity & _BIT1))
polaritytemp = _SYNC_HP_VP;
else
polaritytemp = _SYNC_HP_VN;
}
else
{
if ((bit) (polarity & _BIT1))
polaritytemp = _SYNC_HN_VP;
else
polaritytemp = _SYNC_HN_VN;
}
if ((polaritytemp & tINPUTMODE_PRESET_TABLE[ucModeCnt].PolarityFlag) ==0x00)
return _FALSE;
return _TRUE;
}
/**
* CModeSearchAcceptiveModeVGA
* decide an acceptive mode by comparing the identified mode with preset VGA mode in preset table
* do this when the input mode is not the very same preset mode in the table
* @param <none>
* @return {mode number of an acceptive mode in the table}
*
*/
//--------------------------------------------------
// Description : Search an acceptive mode
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchAcceptiveModeVGA(void)
{
BYTE acceptivemode = _MODE_NOSUPPORT;
//DebugPrintf("\n stModeInfo.IHFreq_H %x",(stModeInfo.IHFreq & 0xff00 )>>8);
//DebugPrintf("\n stModeInfo.IHFreq_L %x",stModeInfo.IHFreq);
if (stModeInfo.IVTotal < 420)
{
}
else if (stModeInfo.IVTotal < 488) // 720x400 Mode : Vertical Line < 488
{
if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_720x400_70HZ;
else if (stModeInfo.IVFreq < 790)
{
if((BYTE)(GET_MODESELECT_TYPE())==0)
acceptivemode = _MODE_640x400_70HZ;
else
acceptivemode = _MODE_720x400_70HZ;
}
else
{
if((BYTE)(GET_MODESELECT_TYPE())==0)
acceptivemode = _MODE_640x400_85HZ;
else
acceptivemode = _MODE_720x400_85HZ;
//acceptivemode = _MODE_720x400_85HZ;
}
}
else if (stModeInfo.IVTotal < 610) // 640x480 Mode : 488 <= Vertical Line < 610
{
if (stModeInfo.IVFreq < 640)
acceptivemode = _MODE_640x480_60HZ;
else if (stModeInfo.IVFreq < 690)
acceptivemode = _MODE_640x480_66HZ;
else if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_640x480_72HZ;
else if (stModeInfo.IVFreq < 790)
acceptivemode = _MODE_640x480_75HZ;
else
acceptivemode = _MODE_640x480_85HZ;
}
else if (stModeInfo.IVTotal < 660) // 800x600 Mode : 610 <= Vertical Line < 660
{
if (stModeInfo.IVFreq < 580)
acceptivemode = _MODE_800x600_56HZ;
else if (stModeInfo.IVFreq < 660)
acceptivemode = _MODE_800x600_60HZ;
else if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_800x600_72HZ;
else if (stModeInfo.IVFreq < 790)
acceptivemode = _MODE_800x600_75HZ;
else
acceptivemode = _MODE_800x600_85HZ;
}
else if (stModeInfo.IVTotal < 732) // 832x624 Mode : 660 <= Vertical Line < 732
{
if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_800x600_72HZ;
else
acceptivemode = _MODE_NOSUPPORT;//_MODE_832x624_75HZ;//20080114
}
else if (stModeInfo.IVTotal < 780) // 1280x720 Mode : 732 <= Vertical Line < 780
{
if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_1280x720_60HZ;
else
acceptivemode = _MODE_1280x720_75HZ;
}
else if (stModeInfo.IVTotal < 881) // 1024x768 Mode : 780 <= Vertical Line < 881
{
if (stModeInfo.IVFreq < 650)
//acceptivemode = _MODE_1024x768_60HZ;
acceptivemode = _MODE_1280x768_60HZ;
else if (stModeInfo.IVFreq < 730)
acceptivemode = _MODE_1024x768_70HZ;
else if (stModeInfo.IVFreq < 790)
acceptivemode = _MODE_1024x768_75HZ;
else
acceptivemode = _MODE_1024x768_85HZ;
}
else if (stModeInfo.IVTotal < 932) // 1152x864/870 Mode : 881 <= Vertical Line < 932
{
if ((stModeInfo.IHFreq > 679) && (stModeInfo.IHFreq < 697))
acceptivemode = _MODE_1152x870_75HZ;
else
{
if (stModeInfo.IVFreq < 650)
acceptivemode = _MODE_1152x864_60HZ;
else if (stModeInfo.IVFreq < 740)
acceptivemode = _MODE_1152x864_70HZ;
else if (stModeInfo.IVFreq < 790)
acceptivemode = _MODE_1152x864_75HZ;
else
acceptivemode = _MODE_1152x864_85HZ;
}
}
else if (stModeInfo.IVTotal < 975)
{
if(stModeInfo.IVFreq < 660)
acceptivemode = _MODE_1440x900_60HZ;
else if(stModeInfo.IVFreq < 700)
acceptivemode = _MODE_1152x900_66HZ;
else if(stModeInfo.IVFreq < 760 && stModeInfo.IVFreq > 730)
acceptivemode = _MODE_1440x900_75HZ;
else if(stModeInfo.IVFreq < 790 && stModeInfo.IVFreq > 740)
acceptivemode = _MODE_1152x900_76HZ;
}
else if (stModeInfo.IVTotal < 1040)
{
if (stModeInfo.IVFreq < 650)
acceptivemode = _MODE_1280x960_60HZ;
else
acceptivemode = _MODE_1280x960_75HZ;
}
else if(stModeInfo.IVTotal < 1087) // 1280x1024 Mode : 1040 <= Vertical Line < 1087
{
if (stModeInfo.IVFreq < 680)
{
acceptivemode = _MODE_1280x1024_60HZ;//Confuse mode between 1280x1024_60HZ and 1680x1050_60HZ_BR
//eric 20070626 mark by constomer
//if((stModeInfo.IHFreq > 630) &&(stModeInfo.IHFreq < 638)) // chroma #3603 RB1280x1024
// acceptivemode =_MODE_NOSUPPORT;
//acceptivemode = _MODE_1680x1050_60HZ_BR;
}
else if (stModeInfo.IVFreq < 720)
acceptivemode = _MODE_1280x1024_70HZ;
else if (stModeInfo.IVFreq < 780)
acceptivemode = _MODE_1280x1024_75HZ;
else
acceptivemode = _MODE_1280x1024_85HZ;
}
else if(stModeInfo.IVTotal < 1110) // 1680x1050 Mode : 1087 <= Vertical Line < 1110
{
if(stModeInfo.IVFreq < 640)
acceptivemode = _MODE_1680x1050_60HZ;
else
acceptivemode = _MODE_1680x1050_75HZ;
//eric 20070626 mark by constomer
//if((stModeInfo.IHFreq > 940) &&(stModeInfo.IHFreq < 948)) // chroma #3584,3558
// acceptivemode = _MODE_NOSUPPORT;
}
else if(stModeInfo.IVTotal < 1200) // 1920x1080 Mode : 1110 <= Vertical Line < 1200
{
acceptivemode = _MODE_1920x1080_60HZ;
//eric 20070626 mark by constomer
//if((stModeInfo.IHFreq > 554) &&(stModeInfo.IHFreq < 562)) // chroma #3559,3585
// acceptivemode = _MODE_NOSUPPORT;
}
else if(stModeInfo.IVTotal < 1300) // 1600x1200 Mode : 1200 <= Vertical Line < 1300
{
if(stModeInfo.IVFreq < 630)
acceptivemode = _MODE_1600x1200_60HZ;//Confuse mode between 1600x1200 and 1920x1200
else if(stModeInfo.IVFreq < 680)
acceptivemode = _MODE_1600x1200_65HZ;
else if(stModeInfo.IVFreq < 720)
acceptivemode = _MODE_1600x1200_70HZ;
else if(stModeInfo.IVFreq < 780)
acceptivemode = _MODE_1600x1200_75HZ;
else
acceptivemode = _MODE_1600x1200_85HZ;
}
return acceptivemode;
}
/**
* CModeCheckFIFOModeVGA
* Check FIFO mode data if there is the same mode already in eeprom
* if not, then save the mode data to the eeprom and return the index of the FIFO data
* @param <BYTE ucModeCnt> {index returned from acceptive mode}
* @return {mode number of an acceptive mode in the table}
*
*/
//--------------------------------------------------
// Description : Check FIFO mode for VGA
// Input Value : Mode number
// Output Value : FIFO mode number
//--------------------------------------------------
BYTE CModeCheckFIFOModeVGA(BYTE ucModeCnt)
{
BYTE cnt0, cnt1;
StructModeUserFIFODataType stFIFOModeTemp;
for (cnt0 = 0; cnt0 < 4; cnt0++)
{
CEepromLoadUserFIFOModeData(cnt0, pData);
for (cnt1 = 0; cnt1 < 4; cnt1++)
{
if (CModeCompareFIFOModeVGA(cnt1, ucModeCnt) == _TRUE)
{
return (cnt0 * 4 + cnt1);
}
}
}
if (stSystemData.UserFIFOMode >= 15)
stSystemData.UserFIFOMode = 0;
else
stSystemData.UserFIFOMode++;
stFIFOModeTemp.ModeNum = ucModeCnt;
stFIFOModeTemp.IHFreq = stModeInfo.IHFreq;
stFIFOModeTemp.IVFreq = stModeInfo.IVFreq;
CEepromSaveUserFIFOModeData(stFIFOModeTemp);
stModeUserData.FirstAuto = 0;
stModeUserData.HPosition = tINPUTMODE_PRESET_TABLE[ucModeCnt].IHStartPos;
stModeUserData.VPosition = tINPUTMODE_PRESET_TABLE[ucModeCnt].IVStartPos;
stModeUserData.Clock = tINPUTMODE_PRESET_TABLE[ucModeCnt].IHTotal;
stModeUserData.Phase = 0;
CEepromSaveModeData(stSystemData.UserFIFOMode);
CEepromSaveSystemData();
return stSystemData.UserFIFOMode;
}
/**
* CModeCompareFIFOModeVGA
* Compare mode in FIFO memory
* @param <BYTE ucNum> {mode index of the 16 mode}
* @param <BYTE ucModeCnt> {mode number of an acceptive mode in the table}
* @return {_TRUE if Vfreq and Hfreq are in range,_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Compare mode in FIFO memory
// Input Value : Mode number and FIFO mode number
// Output Value : _TRUE if both are correspondence
//--------------------------------------------------
bit CModeCompareFIFOModeVGA(BYTE ucNum, BYTE ucModeCnt)
{
StructModeUserFIFODataType stFIFOModeTemp;
stFIFOModeTemp.ModeNum = (pData[ucNum * 4]);
stFIFOModeTemp.IHFreq = ((WORD) (pData[ucNum * 4 + 1] & 0x0f) << 8) | pData[ucNum * 4 + 2];
stFIFOModeTemp.IVFreq = ((WORD) (pData[ucNum * 4 + 1] & 0xf0) << 4) | pData[ucNum * 4 + 3];
if (stFIFOModeTemp.ModeNum != ucModeCnt)
return _FALSE;
if (abs(stModeInfo.IVFreq - stFIFOModeTemp.IVFreq) >
tINPUTMODE_PRESET_TABLE[ucModeCnt].IVFreqTolerance)
return _FALSE;
if (abs(stModeInfo.IHFreq - stFIFOModeTemp.IHFreq) >
tINPUTMODE_PRESET_TABLE[ucModeCnt].IHFreqTolerance)
return _FALSE;
return _TRUE;
}
/**
* CModeSearchModeDVI
* Search mode in the preset table for DVI
* @param <BYTE ucModeCnt> {mode number of the preset table}
* @return {mode number}
*
*/
//--------------------------------------------------
// Description : Search mode for DVI
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
#if((_TMDS_SUPPORT == _ON) || (_HDMI_SUPPORT == _ON))
BYTE CModeSearchModeDVI(void)
{
BYTE modecnt = 0;
CScalerSetBit(_SYNC_SELECT_47, ~_BIT0, _BIT0);
CAdjustSyncProcessorMeasureStart();
if (CTimerPollingEventProc(60, CMiscModeMeasurePollingEvent))
{
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
CScalerSetBit(_MEAS_HS_VS_HI_SEL_58, ~_BIT0, 0x00);
CScalerRead(_MEAS_HS_PERIOD_H_52, 6, &pData[8], _AUTOINC);
((WORD *) pData)[0] = ((WORD) (pData[8] & 0x1f) << 8) | pData[9];
((WORD *) pData)[1] = ((WORD) (pData[10] & 0x1f) << 8) | pData[11];
((WORD *) pData)[2] = ((WORD) (pData[12] & 0xf0) << 4) | pData[13];
if ( (((WORD *) pData)[0] >= 0x0fff) ||
(((WORD *) pData)[1] >= 0x0fff) ||
(((WORD *) pData)[0] == 0) ||
(((WORD *) pData)[1] == 0) ||
(bit) (pData[10] & _BIT5) )
{
modecnt = _MODE_NOSUPPORT;
}
else
{
// Save IH_TOTAL
stModeInfo.IHTotal = ((WORD *) pData)[0] + 1;
// Save input data enable width and height
stModeInfo.IVHeight = ((WORD *) pData)[1] + 1;
stModeInfo.IHWidth = ((WORD *) pData)[2] + 1;
//DebugPrintf("\n stModeInfo.IHWidth=%x",(BYTE)(stModeInfo.IHWidth>>8));
//DebugPrintf(",%x",(BYTE)(stModeInfo.IHWidth));
//DebugPrintf("\n stModeInfo.IVHeight=%x",(BYTE)(stModeInfo.IVHeight>>8));
//DebugPrintf(",%x",(BYTE)(stModeInfo.IVHeight));
#if(_HDMI_SUPPORT == _ON)
// For width = 2880
if((stModeInfo.IHWidth > 2048))
{
stModeInfo.IHWidth = stModeInfo.IHWidth / 2;
stModeInfo.IHTotal = stModeInfo.IHTotal / 2;
CScalerPageSelect(_PAGE2);
CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, 0x50, 0xf0, 0x09);
CScalerSetDataPortBit(_P2_HDMI_ADDR_PORT_C9, 0x51, 0xfb, 0x00);
}
#endif
for (modecnt = 0; modecnt < _MAX_PRESET_MODE; modecnt++)
{
if (CModeCompareModeDVI(modecnt))
{
break;
}
}
}
}
else
{
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT5, 0x00);
modecnt = _MODE_NOSUPPORT;
}
CScalerSetBit(_SYNC_SELECT_47, ~_BIT0, 0x00);
// We don't support input image less than 240 active lines
if(stModeInfo.IVHeight < 240)//cyc:for minimum resolution 720x480i
modecnt = _MODE_NOSUPPORT;
// If no mode found, set to mode 0
else if (modecnt >= _MAX_PRESET_MODE)
modecnt = 0;
// We don't support input image large than 2048 active pixel
if((stModeInfo.IHWidth > 2048))
modecnt = _MODE_NOSUPPORT;
if (modecnt < _MAX_PRESET_MODE)
{
if (modecnt)
{
if (modecnt == _MODE_1920x1080_60HZ)
{
bLED1 = _LED_ON;
bLED2 = _LED_OFF;
}
else
{
bLED1 = _LED_OFF;
bLED2 = _LED_ON;
}
}
else
{
bLED1 = _LED_OFF;
bLED2 = _LED_OFF;
}
}
else
{
bLED1 = _LED_ON;
bLED2 = _LED_ON;
}
return modecnt;
}
/**
* CModeCompareModeDVI
* Compare mode in the preset table for DVI
* @param <BYTE ucModeCnt> {mode number of the preset table}
* @return {_TRUE if the input mode number is correspondence to the input mode,_FALSE if not}
*
*/
//--------------------------------------------------
// Description : Compare mode for DVI
// Input Value : Mode number
// Output Value : Retrun _TRUE if it's correspondence
//--------------------------------------------------
bit CModeCompareModeDVI(BYTE ucModeCnt)
{
if (stModeInfo.IHWidth != tINPUTMODE_PRESET_TABLE[ucModeCnt].IHWidth)
return _FALSE;
if (stModeInfo.IVHeight != tINPUTMODE_PRESET_TABLE[ucModeCnt].IVHeight)
return _FALSE;
if (abs(stModeInfo.IVFreq - tINPUTMODE_PRESET_TABLE[ucModeCnt].IVFreq) >
tINPUTMODE_PRESET_TABLE[ucModeCnt].IVFreqTolerance)
return _FALSE;
return _TRUE;
}
#endif // #if((_TMDS_SUPPORT == _ON) || (_HDMI_SUPPORT == _ON))
//----------------------------------------------------------------------------------------------------
// Mode Display Functions
//----------------------------------------------------------------------------------------------------
/**
* CModeDisplayActiveMode
* mode setup according to the source
* Display active mode process
* @param <none>
* @return {none}
*
*/
bit CModeDisplayActiveMode(void)
{
// added by ghyu
//COsdFxDisableOsd();
//CTimerReactiveTimerEvent(SEC(1), COsdFxEnableOsd);
switch (_GET_INPUT_SOURCE())
{
case _SOURCE_VGA:
return CModeSetupModeVGA();
#if(_YPBPR_SUPPORT == _ON)
case _SOURCE_YPBPR:
return CYPbPrSetupMode();
#endif
#if((_TMDS_SUPPORT == _ON) || (_HDMI_SUPPORT == _ON))
case _SOURCE_DVI:
case _SOURCE_HDMI:
return CModeSetupModeDVI();
#endif
}
}
/**
* CModeSetupModeVGA
* Setup VGA display
* Display active mode process
* @param <none>
* @return {none}
*
*/
//--------------------------------------------------
// Description : Setup VGA mode
// Input Value : None
// Output Value : None
//--------------------------------------------------
bit CModeSetupModeVGA(void)
{
BYTE option = 0;
//DebugPrintf("\n CModeSetupModeVGA %c",0x20);
// Get information from mode table, such as IHTotal, IHStartPos, IHWidth, IVStartPos, IVHeight.
CModeGetModeTableInfo();
// Start up settings of VGA mode.
CModeStartUpVGA();
// Get scaling option, Capture window setup, Scaling setup, Display setup
CModeSetupDisplay();
// Load mode user data from eeprom