-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
113 lines (89 loc) · 3.33 KB
/
main.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
#include <stdint.h>
#include <stdio.h>
#include "config/board_config.h"
#include "config/panel_config.h"
#include "config/misc_config.h"
#include "scaler/scaler.h"
#include "scaler/scaler_registers.h"
#include "scaler/scaler_access.h"
#include "scaler/measure.h"
#include "scaler/scaling.h"
#include "peripherals/pins.h"
#include "peripherals/xsfr.h"
#include "peripherals/timer.h"
#include "peripherals/ddc.h"
#include "interfaces/hdmi.h"
#include "osd/osd.h"
#include "osd/osd_ui.h"
void main()
{
# ifdef __SDCC
XSFRWriteByte(WDT_CONTROL, 0x00); // Disable watchdog
InitSysTimer();
EA = 1;
# endif
// Upload EDID to DDC port 1
UploadEDID(1, testEDID);
// Display and backlight power
SetGPIOShare(DISPLAY_POWER_ENABLE_PIN, PUSH_PULL_OUT);
SetGPIO(DISPLAY_POWER_ENABLE_PIN, 1^!DISPLAY_POWER_ACTIVE_LEVEL);
SetGPIOShare(BACKLIGHT_ENABLE_PIN, PUSH_PULL_OUT);
SetGPIO(BACKLIGHT_ENABLE_PIN, 1^!BACKLIGHT_ENABLE_ACTIVE_LEVEL);
// Display mirroring pins
SetGPIOShare(MIRROR_HORIZONTAL_PIN, PUSH_PULL_OUT);
SetGPIOShare(MIRROR_VERTICAL_PIN, PUSH_PULL_OUT);
SetGPIO(MIRROR_HORIZONTAL_PIN, HOR_MIRRROR);
SetGPIO(MIRROR_VERTICAL_PIN, VER_MIRRROR);
InitScaler();
SetOverlayColor(0xff, 0xff, 0x00);
// On screen display example
OSDInit();
char* entries[]= { "scaling", "other" };
OSDCreateMenu("Settings", entries, 2);
SetOverlayColor(0x00, 0xff, 0xff);
// Initialize first TMDS port
InitHDMI(0);
// Measure in digital mode
MeasureSignal(1);
// After digital measure InputMeasData.HSync = HActive - 1, InputMeasData.VTotal = VActive - 1
uint32_t hact = InputMeasData.HSync + 1, vact = InputMeasData.VTotal + 1;
// Scale up and/or down
ScaleUp (hact, vact, PANEL_H_ACTIVE, PANEL_V_ACTIVE);
ScaleDown(hact, vact, PANEL_H_ACTIVE, PANEL_V_ACTIVE);
// Adjust HStart, VStart, HDelay, VDelay if picture is shifted
SetCaptureWindow(0, 0, hact, vact, 1, 1);
SetFIFOWindow(hact, vact);
// Measure in analog mode for Frequencies
MeasureSignal(0);
// Adjust display frequency manualy if picture flickering artifacts present
// Magic formula Fdisplay = DisplayHTotal*InputHFreq*DisplayVActive/InputVActive
SetDPLLFrequncy((PANEL_H_SYNC_WIDTH + PANEL_H_BACK_PORCH + PANEL_H_ACTIVE + PANEL_H_FRONT_PORCH) *
InputMeasData.HFreq / vact * PANEL_V_ACTIVE);
# ifdef __SDCC
while(1);
# else
getchar();
# endif
}
// Leftover junk
/*
#include "alien/struct_.h"
// InitComposite(2);
// InitVGA();
// ScalerWriteByte(S_SYNC_CONTROL, 0x06); // Select ADC Sync, Select SeperateHSync
// SetCaptureWindow(216, 27, 800, 600, 0, 0);
// SetFIFOWindow(1024, 600);
// SetAPLLFrequncy(40000000UL, 1056);
// ScaleUp(800, 600, 1024, 600);
// Magic formula Fdisplay = DisplayHTotal*InputHFreq*DisplayVActive/InputVActive
// ScalerWriteBit(SCALER_CONTROL, 4, 0b1); // Enable Full line buffer ?
#ifndef __SDCC
stModeInfo.IHWidth = 696;
stModeInfo.IHStartPos = 141;
stModeInfo.IHTotal = 858;
stModeInfo.IHFreq = 157;
stModeInfo.IVHeight = 232;
stModeInfo.IVStartPos = 26;
stModeInfo.IVTotal = 300;
stModeInfo.IVFreq = 60;
#endif*/