Porch and sync changes keep the total line (or frame) length constant, so the refresh rate does not change.
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#include "freertos/FreeRTOS.h"
28#include "freertos/task.h"
30
31
32
34
35#include "esp_chip_info.h"
36
37
38static int chipRevision()
39{
40 esp_chip_info_t info;
41 esp_chip_info(&info);
42 return info.revision;
43}
44
45
46const char * PresetResolutions[] = {
48 VGA_320x200_60HzD,
90};
91
92
93
94int currentResolution = 24;
95int moveX = 0;
96int moveY = 0;
97int shrinkX = 0;
98int shrinkY = 0;
99
100
102
103
104
105void printHelp()
106{
107 printf("Modeline studio\n");
108 printf("Chip Revision: %d Chip Frequency: %d MHz\n\n", chipRevision(), (int) fabgl::getCPUFrequencyMHz());
109 printf(
"%s\n", VGAController.getResolutionTimings()->
label);
110 printf("\nScreen move:\n");
111 printf(" w = Move Up z = Move Down a = Move Left s = Move Right\n");
112 printf("Screen shrink:\n");
113 printf(" n = Dec Horiz N = Inc Horiz m = Dec Vert M = Inc Vert\n");
114 printf("Resolutions:\n");
115 printf(" + = Next resolution - = Prev resolution x = Restore modeline\n");
116 printf("Modeline change:\n");
117 printf(" Just insert a modline. Example: \"640x350@70Hz\" 25.175 640 656 752 800 350 366 462 510 -HSync -VSync\n");
119 printf(" e = Decrease horiz. Front Porch E = Increase horiz. Front Porch\n");
120 printf(" r = Decrease horiz. Sync Pulse R = Increase horiz. Sync Pulse\n");
121 printf(" t = Decrease horiz. Bach Porch T = Increase horiz. Back Porch\n");
122 printf(" y = Decrease vert. Front Porch Y = Increase vert. Front Porch\n");
123 printf(" u = Decrease vert. Sync Pulse U = Increase vert. Sync Pulse\n");
124 printf(" i = Decrease vert. Bach Porch I = Increase vert. Back Porch\n");
125
126 printf(" o = Decrease frequency by 5KHz O = Increase frequency by 5KHz\n");
127 printf(" . = Change horiz. signals order\n");
128 printf("Various:\n");
129 printf(" h = Print This help\n\n");
130}
131
132
133void printInfo()
134{
135 auto t = VGAController.getResolutionTimings();
136 printf("Modeline \"%s\" %2.8g %d %d %d %d %d %d %d %d %cHSync %cVSync %s %s\n",
137 t->label,
138 t->frequency / 1000000.0,
139 t->HVisibleArea,
140 t->HVisibleArea + t->HFrontPorch,
141 t->HVisibleArea + t->HFrontPorch + t->HSyncPulse,
142 t->HVisibleArea + t->HFrontPorch + t->HSyncPulse + t->HBackPorch,
143 t->VVisibleArea,
144 t->VVisibleArea + t->VFrontPorch,
145 t->VVisibleArea + t->VFrontPorch + t->VSyncPulse,
146 t->VVisibleArea + t->VFrontPorch + t->VSyncPulse + t->VBackPorch,
147 t->HSyncLogic, t->VSyncLogic,
148 t->scanCount == 2 ? "DoubleScan" : "",
149 t->HStartingBlock == VGAScanStart::FrontPorch ? "FrontPorchBegins" :
150 (t->HStartingBlock == VGAScanStart::Sync ? "SyncBegins" :
151 (t->HStartingBlock == VGAScanStart::BackPorch ? "BackPorchBegins" : "VisibleBegins")));
152
153
154
155 if (moveX || moveY)
156 printf("moveScreen(%d, %d)\n", moveX, moveY);
157 if (shrinkX || shrinkY)
158 printf("shrinkScreen(%d, %d)\n", shrinkX, shrinkY);
161 printf("Free memory (total, min, largest): %d, %d, %d\n\n", heap_caps_get_free_size(MALLOC_CAP_32BIT),
162 heap_caps_get_minimum_free_size(MALLOC_CAP_32BIT),
163 heap_caps_get_largest_free_block(MALLOC_CAP_32BIT));
164}
165
166
167void updateScreen()
168{
169 Canvas cv(&VGAController);
170 cv.setPenColor(Color::White);
171 cv.setBrushColor(Color::Black);
172 cv.clear();
173 cv.fillRectangle(0, 0, cv.getWidth() - 1, cv.getHeight() - 1);
174 cv.drawRectangle(0, 0, cv.getWidth() - 1, cv.getHeight() - 1);
175
176 cv.selectFont(&fabgl::FONT_8x8);
177 cv.setGlyphOptions(
GlyphOptions().FillBackground(
true).DoubleWidth(1));
178 cv.drawText(40, 20, VGAController.getResolutionTimings()->
label);
179
182 cv.drawTextFmt(40, 60, "Viewport Size : %d x %d", cv.getWidth(), cv.getHeight());
183 cv.drawText(40, 80, "Commands (More on UART):");
184 cv.drawText(40, 100, " w = Move Up z = Move Down");
185 cv.drawText(40, 120, " a = Move Left s = Move Right");
186 cv.drawText(40, 140, " + = Next Resolution");
187 cv.drawRectangle(35, 15, 310, 155);
188}
189
190
191
192void setup()
193{
195
196
197
198 vTaskDelay(pdMS_TO_TICKS(500));
199
200 VGAController.
begin();
201 VGAController.setResolution(PresetResolutions[currentResolution]);
202 updateScreen();
203 printHelp();
204 printInfo();
205}
206
207
208void loop()
209{
211
212 if (Console.available() > 0) {
213 char c = Console.read();
214 switch (c) {
215 case 'h':
216 printHelp();
217 break;
218 case 'w':
219 --moveY;
221 printInfo();
222 break;
223 case 'z':
224 ++moveY;
226 printInfo();
227 break;
228 case 'a':
229 --moveX;
231 printInfo();
232 break;
233 case 's':
234 ++moveX;
236 printInfo();
237 break;
238 case 'x':
239 moveX = moveY = shrinkX = shrinkY = 0;
240 VGAController.setResolution(PresetResolutions[currentResolution]);
241 updateScreen();
242 printInfo();
243 break;
244 case '+':
245 case '-':
246 moveX = moveY = shrinkX = shrinkY = 0;
247 currentResolution = (c == '+' ? currentResolution + 1 : currentResolution - 1);
248 if (currentResolution == sizeof(PresetResolutions) / sizeof(const char *))
249 currentResolution = 0;
250 if (currentResolution < 0)
251 currentResolution = sizeof(PresetResolutions) / sizeof(const char *) - 1;
252 VGAController.setResolution(PresetResolutions[currentResolution]);
253 updateScreen();
254 printInfo();
255 break;
256 case '"':
257 {
258 moveX = moveY = shrinkX = shrinkY = 0;
259
260 char modeline[128] = "\"";
261 uint8_t ch;
262 int len = 1;
263 while (len <
sizeof(modeline) - 1 && Console.
readBytes(&ch, 1) == 1 && ch !=
'\n')
264 modeline[len++] = ch;
265 modeline[len] = 0;
266 VGAController.setResolution(modeline);
267 updateScreen();
268 printInfo();
269 break;
270 }
272 case 'e':
273 case 'E':
274 t = *VGAController.getResolutionTimings();
277 VGAController.setResolution(t);
278 updateScreen();
279 printInfo();
280 break;
281 case 'r':
282 case 'R':
283 t = *VGAController.getResolutionTimings();
286 VGAController.setResolution(t);
287 updateScreen();
288 printInfo();
289 break;
290 case 't':
291 case 'T':
292 t = *VGAController.getResolutionTimings();
295 VGAController.setResolution(t);
296 updateScreen();
297 printInfo();
298 break;
299 case 'y':
300 case 'Y':
301 t = *VGAController.getResolutionTimings();
304 VGAController.setResolution(t);
305 updateScreen();
306 printInfo();
307 break;
308 case 'u':
309 case 'U':
310 t = *VGAController.getResolutionTimings();
313 VGAController.setResolution(t);
314 updateScreen();
315 printInfo();
316 break;
317 case 'i':
318 case 'I':
319 t = *VGAController.getResolutionTimings();
322 VGAController.setResolution(t);
323 updateScreen();
324 printInfo();
325 break;
326
327 case 'o':
328 case 'O':
329 t = *VGAController.getResolutionTimings();
331 VGAController.setResolution(t);
332 updateScreen();
333 printInfo();
334 break;
335 case '.':
336 t = *VGAController.getResolutionTimings();
338 case VGAScanStart::FrontPorch:
340 break;
341 case VGAScanStart::Sync:
343 break;
344 case VGAScanStart::BackPorch:
346 break;
347 case VGAScanStart::VisibleArea:
349 break;
350 }
351 VGAController.setResolution(t);
352 updateScreen();
353 printInfo();
354 break;
355 case 'n':
356 ++shrinkX;
358 updateScreen();
359 printInfo();
360 break;
361 case 'N':
362 --shrinkX;
364 updateScreen();
365 printInfo();
366 break;
367 case 'm':
368 ++shrinkY;
370 updateScreen();
371 printInfo();
372 break;
373 case 'M':
374 --shrinkY;
376 updateScreen();
377 printInfo();
378 break;
379 }
380 }
381}
382
383
384extern "C" void app_main()
385{
386 setup();
387 while (true)
388 loop();
389}
Provides a set of drawing methods.
int getScreenHeight()
Determines the screen height in pixels.
int getViewPortHeight()
Determines the height of the viewport.
int getViewPortWidth()
Determines the width of the viewport.
int getScreenWidth()
Determines the screen width in pixels.
bool begin(int port=0, int baud=0, int rxPin=-1, int txPin=-1, int rxBufferSize=1024, int txBufferSize=0)
Initializes the UART.
A Stream implemented on top of the ESP-IDF UART driver.
VGA bitmapped display controller with 2 colors.
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
Initializer for 8 colors (5 GPIOs).
void shrinkScreen(int shrinkX, int shrinkY)
Shrinks or expands the screen by the specified horizontal and vertical amounts.
void moveScreen(int offsetX, int offsetY)
Moves the screen by the specified horizontal and vertical offsets.
Single include file of the FabGL library.
#define VGA_640x480_60HzAlt1
#define SVGA_800x600_56Hz
#define SVGA_800x300_60Hz
#define SVGA_800x600_60Hz
#define VESA_640x350_85Hz
#define SVGA_1024x768_60Hz
#define SVGA_960x540_60Hz
#define VGA_720x348_50HzD
#define SVGA_1280x768_50Hz
#define SVGA_1280x720_60Hz
#define VGA_640x200_60HzD
#define VESA_768x576_60Hz
#define QVGA_320x240_60Hz
#define VESA_720x400_85Hz
#define SVGA_1280x600_60Hz
#define VGA_640x480_60HzD
#define VESA_640x480_75Hz
#define VGA_640x350_70HzAlt1
#define SVGA_1280x720_60HzAlt1
#define SVGA_1024x768_75Hz
#define SVGA_1024x768_70Hz
size_t readBytes(uint8_t *buffer, size_t length)
Reads up to length bytes, waiting until all bytes have been received or the timeout expires.
VGAScanStart HStartingBlock
Specifies the VGA timings (a decoded modeline).
Specifies glyph painting options.