FabGL
ESP32 Display Controller and Graphics Library
vgatextcontroller.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019-2020 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #pragma once
24 
25 
33 #include <stdint.h>
34 #include <stddef.h>
35 
36 #include "rom/lldesc.h"
37 #include "driver/gpio.h"
38 
39 #include "fabglconf.h"
40 #include "fabutils.h"
41 #include "devdrivers/swgenerator.h"
43 #include "fonts/font_8x14.h"
44 
45 
46 namespace fabgl {
47 
48 
49 #define VGATextController_CHARWIDTH 8 // max 8
50 #define VGATextController_CHARWIDTHBYTES ((VGATextController_CHARWIDTH + 7) / 8)
51 #define VGATextController_CHARHEIGHT 14
52 #define VGATextController_COLUMNS 80
53 #define VGATextController_ROWS 34
54 #define VGATextController_WIDTH 640
55 #define VGATextController_HEIGHT 480
56 
57 #define VGATextController_MODELINE VGA_640x480_60Hz
58 
59 
60 
61 
62 
63 
84 
85 public:
86 
89 
106  void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
107 
127  void begin(gpio_num_t red1GPIO, gpio_num_t red0GPIO, gpio_num_t green1GPIO, gpio_num_t green0GPIO, gpio_num_t blue1GPIO, gpio_num_t blue0GPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
128 
139  void begin();
140 
146  void setResolution(char const * modeline = nullptr, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
147 
153  void setTextMap(uint32_t const * map, int rows);
154 
161  void adjustMapSize(int * columns, int * rows);
162 
163  int getColumns() { return VGATextController_COLUMNS; }
164  int getRows() { return VGATextController_ROWS; }
165 
166  void enableCursor(bool value) { m_cursorEnabled = value; }
167  void setCursorPos(int row, int col) { m_cursorRow = row; m_cursorCol = col; m_cursorCounter = 0; }
168  void setCursorSpeed(int value) { m_cursorSpeed = value; }
169  void setCursorForeground(Color value);
170  void setCursorBackground(Color value);
171 
172 
173 private:
174 
175  void setResolution(VGATimings const& timings);
176  void init(gpio_num_t VSyncGPIO);
177  void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
178  void freeBuffers();
179 
180  void fillDMABuffers();
181  uint8_t packHVSync(bool HSync, bool VSync);
182  uint8_t preparePixelWithSync(RGB222 rgb, bool HSync, bool VSync);
183 
184  uint8_t IRAM_ATTR preparePixel(RGB222 rgb) { return m_HVSync | (rgb.B << VGA_BLUE_BIT) | (rgb.G << VGA_GREEN_BIT) | (rgb.R << VGA_RED_BIT); }
185 
186  static void ISRHandler(void * arg);
187 
188 
189  static volatile int s_scanLine;
190  static uint32_t s_blankPatternDWord;
191  static uint32_t * s_fgbgPattern;
192  static int s_textRow;
193  static bool s_upperRow;
194  static lldesc_t volatile * s_frameResetDesc;
195 
196  VGATimings m_timings;
197 
198  GPIOStream m_GPIOStream;
199  int m_bitsPerChannel; // 1 = 8 colors, 2 = 64 colors, set by begin()
200  lldesc_t volatile * m_DMABuffers;
201  int m_DMABuffersCount;
202 
203  uint32_t * m_lines;
204 
205  int m_rows;
206 
207  volatile uint8_t * m_blankLine; // for vertical porch lines
208  volatile uint8_t * m_syncLine; // for vertical sync lines
209 
210  intr_handle_t m_isr_handle;
211 
212  // contains H and V signals for visible line
213  volatile uint8_t m_HVSync;
214 
215  uint8_t * m_charData;
216  uint32_t const * m_map;
217 
218  // cursor props
219  bool m_cursorEnabled;
220  int m_cursorCounter; // trip from -m_cursorSpeed to +m_cursorSpeed (>= cursor is visible)
221  int m_cursorSpeed;
222  int m_cursorRow;
223  int m_cursorCol;
224  uint8_t m_cursorForeground;
225  uint8_t m_cursorBackground;
226 
227 };
228 
229 
230 
231 }
Represents the VGA text-only controller.
void begin()
This is the 64 colors (8 GPIOs) initializer using default pinout.
This file contains fabgl::GPIOStream definition.
Color
This enum defines named colors.
void adjustMapSize(int *columns, int *rows)
Adjust columns and rows to the controller limits.
This file contains fabgl::VGAController definition.
void setResolution(char const *modeline=nullptr, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets fixed resolution.
Specifies the VGA timings. This is a modeline decoded.
This file contains some utility classes and functions.
Definition: canvas.cpp:31
This file contains FabGL library configuration settings, like number of supported colors...
Represents a 6 bit RGB color.
Represents the base abstract class for textual display controllers.
void setTextMap(uint32_t const *map, int rows)
Sets text map to display.