forked from ramapcsx2/gbs-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSDManager.h
280 lines (273 loc) · 7.48 KB
/
OSDManager.h
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
#ifndef OSD_MANAGER_H_
#define OSD_MANAGER_H_
#include "tv5725.h"
#define MENU_WIDTH 131
#define MENU_HEIGHT 19
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
typedef TV5725<GBS_ADDR> GBS;
struct OSDMenuConfig
{
uint8_t barLength;
uint8_t barActiveLength;
bool onChange;
bool inc;
};
typedef bool (*OSDHanlder)(OSDMenuConfig &config);
bool osdBrightness(OSDMenuConfig &config);
bool osdContrast(OSDMenuConfig &config);
bool osdAutoGain(OSDMenuConfig &config);
bool osdScanlines(OSDMenuConfig &config);
bool osdLineFilter(OSDMenuConfig &config);
bool osdMoveX(OSDMenuConfig &config);
bool osdMoveY(OSDMenuConfig &config);
bool osdScaleY(OSDMenuConfig &config);
bool osdScaleX(OSDMenuConfig &config);
void initOSD();
enum class OSDIcon {
BRIGHTNESS,
CONTRAST,
HUE,
VOLUME,
MOVE_Y,
MOVE_X,
SCALE_Y,
SCALE_X,
};
enum OSDColor {
OSD_BLACk = 0,
OSD_BLUE,
OSD_GREEN,
OSD_CYAN,
OSD_RED,
OSD_MAGENTA,
OSD_YELLOW,
OSD_WHITE
};
enum class OSDNav {
IDLE = 0,
UP,
DOWN,
LEFT,
RIGHT,
ENTER,
MENU,
BACK
};
typedef TV5725<GBS_ADDR> GBS;
class OSDManager
{
private:
enum class OSDIconValue {
BRIGHTNESS = 0x1, // 4'b0001
CONTRAST = 0x2, // 4'b0010
HUE = 0x3, // 4'b0011
VOLUME = 0x4, // 4'b0100
UP_DOWN = 0x8, // 4'b1000
LEFT_RIGHT = 0x9, // 4'b1001
VERTICAL = 0xA, // 4'b1010
HORIZONTAL = 0xB // 4'b1011
};
enum class OSDState {
OFF,
MAIN,
SUB,
};
uint8_t cursor;
uint8_t curVal;
uint8_t curMax;
OSDHanlder handlers[8];
OSDState state;
bool displayInColumn;
void rstOn()
{
GBS::OSD_SW_RESET::write(true);
}
void rstOff()
{
GBS::OSD_SW_RESET::write(false);
}
uint8_t iconToRegValue(OSDIcon icon)
{
OSDIconValue values[] = {
OSDIconValue::BRIGHTNESS,
OSDIconValue::CONTRAST,
OSDIconValue::HUE,
OSDIconValue::VOLUME,
OSDIconValue::UP_DOWN,
OSDIconValue::LEFT_RIGHT,
OSDIconValue::VERTICAL,
OSDIconValue::HORIZONTAL};
return (uint8_t)values[(uint8_t)icon];
}
uint8_t iconToRegValue(uint8_t icon)
{
return iconToRegValue((OSDIcon)(icon));
}
public:
OSDManager()
{
memset(&this->handlers, 0, sizeof(this->handlers));
}
uint8 preset;
void registerIcon(OSDIcon icon, OSDHanlder handler)
{
this->handlers[(uint8_t)icon] = handler;
}
void tick(OSDNav nav)
{
if (nav == OSDNav::IDLE) {
return;
}
if (nav == OSDNav::MENU) {
if (state == OSDState::OFF) {
menuOn();
} else {
menuOff();
}
return;
}
if (nav == OSDNav::BACK) {
if (state == OSDState::MAIN) {
menuOff();
} else if (state == OSDState::SUB) {
menuOff();
menuOn();
}
return;
}
if (nav == OSDNav::ENTER) {
if (state == OSDState::MAIN) {
enter();
} else if (state == OSDState::SUB) {
menuOff();
menuOn();
} else {
menuOn();
}
return;
}
if (nav == OSDNav::RIGHT) {
if (state == OSDState::MAIN) {
next();
} else if (state == OSDState::SUB) {
submit(true);
}
}
if (nav == OSDNav::LEFT) {
if (state == OSDState::MAIN) {
prev();
} else if (state == OSDState::SUB) {
submit(false);
}
}
}
void resetPosition()
{
auto x_start = GBS::VDS_DIS_HB_SP::read();
auto x_stop = GBS::VDS_DIS_HB_ST::read();
auto y_stop = GBS::VDS_DIS_VB_ST::read();
auto width = x_stop - x_start;
auto x_zoom = GBS::OSD_ZOOM_5X;
auto y_zoom = GBS::OSD_ZOOM_4X;
switch (preset) {
case 1: // 480p
x_zoom = GBS::OSD_ZOOM_7X;
y_zoom = GBS::OSD_ZOOM_2X;
break;
case 5: // 1080p
x_zoom = GBS::OSD_ZOOM_3X;
y_zoom = GBS::OSD_ZOOM_8X;
break;
default:
break;
}
uint8_t x = (x_start + width / 2 - (x_zoom * MENU_WIDTH) / 2) >> 3;
uint8_t y = (y_stop - 64 - y_zoom * MENU_HEIGHT) >> 3;
GBS::OSD_MENU_DISP_STYLE::write(1);
GBS::OSD_MENU_HORI_START::write(x);
GBS::OSD_MENU_VER_START::write(y);
GBS::OSD_HORIZONTAL_ZOOM::write(x_zoom);
GBS::OSD_VERTICAL_ZOOM::write(y_zoom);
GBS::OSD_MENU_BAR_BORD_COR::write(OSD_BLUE);
GBS::OSD_MENU_BAR_FONT_BGCOR::write(OSD_YELLOW);
GBS::OSD_MENU_BAR_FONT_FORCOR::write(OSD_RED);
GBS::OSD_MENU_SEL_BGCOR::write(OSD_GREEN);
GBS::OSD_MENU_SEL_FORCOR::write(OSD_BLACk);
}
void menuOn()
{
rstOff();
GBS::OSD_COMMAND_FINISH::write(false);
resetPosition();
// GBS::OSD_YCBCR_RGB_FORMAT::write(false);
GBS::OSD_MENU_ICON_SEL::write(iconToRegValue(cursor));
GBS::OSD_DISP_EN::write(true);
GBS::OSD_MENU_EN::write(true);
GBS::OSD_COMMAND_FINISH::write(true);
state = OSDState::MAIN;
}
void menuOff()
{
GBS::OSD_COMMAND_FINISH::write(false);
GBS::OSD_MENU_MOD_SEL::write(0);
GBS::OSD_DISP_EN::write(false);
GBS::OSD_MENU_EN::write(false);
state = OSDState::OFF;
GBS::OSD_COMMAND_FINISH::write(true);
rstOn();
}
void updateCursor()
{
GBS::OSD_COMMAND_FINISH::write(false);
GBS::OSD_MENU_ICON_SEL::write(iconToRegValue(cursor));
GBS::OSD_COMMAND_FINISH::write(true);
}
void next()
{
auto old = cursor;
do {
cursor = (cursor + 1) % 8;
} while (handlers[cursor] == nullptr && cursor != old);
updateCursor();
}
void prev()
{
auto old = cursor;
do {
cursor = cursor == 0 ? 7 : (cursor - 1) % 8;
} while (handlers[cursor] == nullptr && cursor != old);
updateCursor();
}
void enter()
{
GBS::OSD_COMMAND_FINISH::write(false);
OSDMenuConfig config;
config.onChange = false;
bool shouldEnter = (*handlers[cursor])(config);
if (shouldEnter) {
state = OSDState::SUB;
uint8_t active = 128.0 / config.barLength * config.barActiveLength;
GBS::OSD_MENU_MOD_SEL::write(iconToRegValue(cursor));
GBS::OSD_BAR_LENGTH::write(128);
GBS::OSD_BAR_FOREGROUND_VALUE::write(active);
GBS::OSD_MENU_BAR_FONT_FORCOR::write(OSD_WHITE);
GBS::OSD_MENU_BAR_FONT_BGCOR::write(OSD_BLACk);
}
GBS::OSD_COMMAND_FINISH::write(true);
}
void submit(bool inc)
{
GBS::OSD_COMMAND_FINISH::write(false);
OSDMenuConfig config;
config.inc = inc;
config.onChange = true;
(*handlers[cursor])(config);
GBS::OSD_MENU_MOD_SEL::write(iconToRegValue(cursor));
uint8_t active = 128 / config.barLength * config.barActiveLength;
GBS::OSD_BAR_LENGTH::write(128);
GBS::OSD_BAR_FOREGROUND_VALUE::write(active);
GBS::OSD_COMMAND_FINISH::write(true);
}
};
#endif