The screen shows a small GUI to choose the video standard, plus an RGB color bar test and a circle to check the aspect ratio. The selected settings are saved in NVS and restored at the next boot.
The bottom of the screen shows free memory and the current resolution.
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#include "freertos/FreeRTOS.h"
30#include "freertos/task.h"
31#include "esp_system.h"
33#include "devdrivers/cvbsgenerator.h"
34
35
36#define VIDEOOUT_GPIO GPIO_NUM_25
37
38
40
41
44
45
46
47
48static const char * PREF_MODE = "Mode";
49static const char * PREF_MONO = "Mono";
50static const char * PREF_HRATE = "HRate";
51
52
53
54
55#define MODES_DEFAULT 1
56#define MONO_DEFAULT 0
57#define HRATE_DEFAULT 2
58
59
60
61
62
63static const char * MODES_DESC[] = { "Interlaced PAL-B",
64 "Progressive PAL-B",
65 "Interlaced NTSC-M",
66 "Progressive NTSC-M",
67 "Interlaced PAL-B Wide",
68 "Progressive PAL-B Wide",
69 "Interlaced NTSC-M Wide",
70 "Progressive NTSC-M Wide",
71 "Progressive NTSC-M Ext",
72 };
73
74static const char * MODES_STD[] = { "I-PAL-B",
75 "P-PAL-B",
76 "I-NTSC-M",
77 "P-NTSC-M",
78 "I-PAL-B-WIDE",
79 "P-PAL-B-WIDE",
80 "I-NTSC-M-WIDE",
81 "P-NTSC-M-WIDE",
82 "P-NTSC-M-EXT",
83 };
84
85
86
87
88
89enum { STYLE_NONE, STYLE_LABEL, STYLE_STATICLABEL, STYLE_BUTTON, STYLE_COMBOBOX, STYLE_CHECKBOX };
90
91#define BACKGROUND_COLOR RGB888(0, 0, 0)
92
93#define COLORBARS_HEIGHT 30
94#define CIRCLE_SIZE 80
95
97 void setStyle(
uiObject *
object, uint32_t styleClassID) {
98 switch (styleClassID) {
99 case STYLE_LABEL:
100 ((
uiLabel*)
object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
101 ((
uiLabel*)
object)->labelStyle().textColor =
RGB888(255, 255, 255);
102 break;
103 case STYLE_STATICLABEL:
104 ((
uiStaticLabel*)
object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
106 break;
107 case STYLE_BUTTON:
108 ((
uiButton*)
object)->windowStyle().borderColor =
RGB888(128, 128, 128);
109 ((
uiButton*)
object)->buttonStyle().backgroundColor =
RGB888(0, 255, 0);
110 break;
111 case STYLE_COMBOBOX:
113 ((
uiComboBox*)
object)->windowStyle().borderSize = 1;
114 break;
115 case STYLE_CHECKBOX:
117 ((
uiCheckBox*)
object)->checkBoxStyle().mouseOverForegroundColor =
RGB888(0, 0, 0);
118 ((
uiCheckBox*)
object)->checkBoxStyle().mouseOverBackgroundColor =
RGB888(0, 255, 0);
119 break;
120 }
121 }
122} dialogStyle;
123
124
125
126
127
128struct MyApp :
public uiApp {
129
130 uiComboBox * modeComboBox;
131 uiCheckBox * monoCheckbox;
132 uiComboBox * hrateComboBox;
133
134 void init() {
135
136 setStyle(&dialogStyle);
137
138
139 rootWindow()->frameStyle().backgroundColor = BACKGROUND_COLOR;
140
141
142
143
144 rootWindow()->onPaint = [&]() {
145 auto cv = canvas();
146 cv->selectFont(&fabgl::FONT_SLANT_8x14);
147 cv->setPenColor(RGB888(0, 128, 255));
148 cv->drawText(2, 5, "Composite Video Test - fabgl.com");
149
150 cv->selectFont(&fabgl::FONT_std_12);
151 cv->setPenColor(RGB888(255, 128, 0));
152 cv->drawText(2, 19, "2019/22 by Fabrizio Di Vittorio");
153
154
155 auto w = cv->getWidth();
156 auto h = cv->getHeight();
157 cv->drawText(2, h - COLORBARS_HEIGHT - 15, "RGB Colors Test");
158 cv->setBrushColor(Color::BrightRed);
159 cv->fillRectangle(0, h - COLORBARS_HEIGHT, w / 3, h - 1);
160 cv->setBrushColor(Color::BrightGreen);
161 cv->fillRectangle(w / 3, h - COLORBARS_HEIGHT, w * 2 / 3, h - 1);
162 cv->setBrushColor(Color::BrightBlue);
163 cv->fillRectangle(w * 2 / 3, h - COLORBARS_HEIGHT, w - 1, h - 1);
164
165
166 int cx = w - CIRCLE_SIZE / 2 - 1;
167 int cy = h - COLORBARS_HEIGHT - CIRCLE_SIZE / 2 - 1;
168 cv->setPenColor(Color::BrightYellow);
169 cv->drawText(cx - CIRCLE_SIZE / 2 + 2, cy - 3, "Aspect Ratio Test");
170 cv->setBrushColor(Color::BrightWhite);
171 cv->drawEllipse(cx, cy, CIRCLE_SIZE, CIRCLE_SIZE);
172 };
173
174
175 new uiStaticLabel(rootWindow(),
"Mode", Point(2, 60),
true, STYLE_STATICLABEL);
176 modeComboBox =
new uiComboBox(rootWindow(), Point(40, 58), Size(140, 20), 80,
true, STYLE_COMBOBOX);
177 modeComboBox->
items().append(MODES_DESC,
sizeof(MODES_DESC) /
sizeof(
char*));
179
180
181 new uiStaticLabel(rootWindow(),
"B/W", Point(2, 88),
true, STYLE_STATICLABEL);
182 monoCheckbox =
new uiCheckBox(rootWindow(), Point(40, 85), Size(16, 20), uiCheckBoxKind::CheckBox,
true, STYLE_CHECKBOX);
186 };
187
188
189 new uiStaticLabel(rootWindow(),
"H. Rate", Point(103, 88),
true, STYLE_STATICLABEL);
190 hrateComboBox =
new uiComboBox(rootWindow(), Point(145, 84), Size(35, 20), 55,
true, STYLE_COMBOBOX);
191 hrateComboBox->
items().appendSepList(
"x1,x2,x3",
',');
193
194
195 auto applyButton =
new uiButton(rootWindow(),
"Apply", Point(40, 117), Size(80, 20), uiButtonKind::Button,
true, STYLE_BUTTON);
196 applyButton->onClick = [&]() {
197 apply();
198 };
199
200
201 auto infoLabel =
new uiLabel(rootWindow(),
"", Point(2, rootWindow()->clientSize().height - COLORBARS_HEIGHT * 2), Size(0, 0),
true, STYLE_LABEL);
202 infoLabel->setTextFmt(
"Free Mem: %d KiB Resolution: %d x %d", heap_caps_get_free_size(MALLOC_CAP_32BIT) / 1024, DisplayController.
getViewPortWidth(), DisplayController.
getViewPortHeight());
203
204 }
205
206 static int getMode() {
207 return preferences.getInt(PREF_MODE, MODES_DEFAULT);
208 }
209
210 static bool getMonochromatic() {
211 return preferences.getInt(PREF_MONO, MONO_DEFAULT);
212 }
213
214 static int getHRate() {
215 return preferences.getInt(PREF_HRATE, HRATE_DEFAULT);
216 }
217
218 void apply() {
219 bool reboot = modeComboBox->
selectedItem() != getMode() ||
221
222 preferences.putInt(PREF_MODE, modeComboBox->
selectedItem());
223 preferences.putInt(PREF_MONO, monoCheckbox->
checked());
224 preferences.putInt(PREF_HRATE, hrateComboBox->
selectedItem() + 1);
225
226 if (reboot)
227 esp_restart();
228 }
229
230
231} app;
232
233
234
235void setup()
236{
237
238 preferences.
begin(
"CVBS",
false);
239
240 PS2Controller.
begin(PS2Preset::KeyboardPort0_MousePort1, KbdMode::GenerateVirtualKeys);
241
242 DisplayController.begin(VIDEOOUT_GPIO);
243
244 auto mode = MyApp::getMode();
245
246 DisplayController.setHorizontalRate(MyApp::getHRate());
248
249 DisplayController.setResolution(MODES_STD[mode]);
250
251}
252
253
254#if FABGLIB_CVBSCONTROLLER_PERFORMANCE_CHECK
255namespace fabgl {
256 extern volatile uint64_t s_cvbsctrlcycles;
257}
258using fabgl::s_cvbsctrlcycles;
259#endif
260
261
262void loop()
263{
264 app.runAsync(&DisplayController, 2000);
265
266 #if FABGLIB_CVBSCONTROLLER_PERFORMANCE_CHECK
267 uint32_t s1 = 0;
268 while (true) {
269 printf("%lld / %d (%d%%)\n", s_cvbsctrlcycles, fabgl::getCycleCount() - s1, (int)((double)s_cvbsctrlcycles/240000000*100));
270 s_cvbsctrlcycles = 0;
271 s1 = fabgl::getCycleCount();
272 vTaskDelay(pdMS_TO_TICKS(1000));
273 }
274 #else
275 vTaskDelete(NULL);
276 #endif
277
278
279}
280
281
282extern "C" void app_main()
283{
284 setup();
285 while (true)
286 loop();
287}
bool begin(char const *name, bool readOnly=false)
Opens the specified namespace.
Simple key/value storage in non-volatile flash (NVS).
int getViewPortHeight()
Determines the height of the viewport.
int getViewPortWidth()
Determines the width of the viewport.
void setMonochrome(bool value)
Enables or disables monochrome output (no color burst).
Composite video (PAL/NTSC) bitmapped display controller with 16 colors.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes the PS/2 device controller.
int selectedItem()
Represents currently selected item.
void selectItem(int index)
Selects an item.
Represents the whole application base class.
void setChecked(bool value)
Sets current checkbox or radiobutton checked status.
bool checked()
Determines whether the checkbox or radiobutton is checked.
Delegate onChange
Change event delegate.
uiCheckBox(uiWindow *parent, const Point &pos, const Size &size, uiCheckBoxKind kind=uiCheckBoxKind::CheckBox, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
Represents a checkbox or a radiobutton.
StringList & items()
A list of strings representing items of the combobox.
uiComboBox(uiWindow *parent, const Point &pos, const Size &size, int listHeight, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
This is a combination of a listbox and a single-line editable textbox.
uiLabel(uiWindow *parent, char const *text, const Point &pos, const Size &size=Size(0, 0), bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
A label is a static text UI element.
Base class of all UI elements like windows and controls.
uiStaticLabel(uiWindow *parent, char const *text, const Point &pos, bool visible=true, uint32_t styleClassID=0)
Creates an instance of the object.
A staticlabel is a light version of uiLabel (text must be static). uiStaticLabel has lower memory foo...
Single include file of the FabGL library.
Represents a 24-bit RGB color.
Base class for application styles.