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-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6 
7 * Please contact fdivitto2013@gmail.com if you need a commercial license.
8 
9 
10 * This library and related software is available under GPL v3. Feel free to use FabGL in free software and hardware:
11 
12  FabGL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  FabGL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 
37 #include <stdint.h>
38 #include <stddef.h>
39 
40 #include "driver/gpio.h"
41 
42 #include "fabglconf.h"
43 #include "fabutils.h"
44 #include "devdrivers/swgenerator.h"
46 #include "fonts/font_8x14.h"
47 
48 
49 namespace fabgl {
50 
51 
52 #define VGATextController_CHARWIDTH 8 // max 8
53 #define VGATextController_CHARWIDTHBYTES ((VGATextController_CHARWIDTH + 7) / 8)
54 #define VGATextController_CHARHEIGHT 14
55 #define VGATextController_COLUMNS 80
56 #define VGATextController_ROWS 34
57 #define VGATextController_WIDTH 640
58 #define VGATextController_HEIGHT 480
59 
60 #define VGATextController_MODELINE VGA_640x480_60Hz
61 
62 
63 
64 
65 
66 
87 
88 public:
89 
92 
109  void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
110 
130  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);
131 
142  void begin();
143 
149  void setResolution(char const * modeline = nullptr, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
150 
156  void setTextMap(uint32_t const * map, int rows);
157 
164  void adjustMapSize(int * columns, int * rows);
165 
166  int getColumns() { return VGATextController_COLUMNS; }
167  int getRows() { return VGATextController_ROWS; }
168 
169  void enableCursor(bool value) { m_cursorEnabled = value; }
170  void setCursorPos(int row, int col) { m_cursorRow = row; m_cursorCol = col; m_cursorCounter = 0; }
171  void setCursorSpeed(int value) { m_cursorSpeed = value; }
172  void setCursorForeground(Color value);
173  void setCursorBackground(Color value);
174 
175  FontInfo const * getFont() { return &FONT_8x14; }
176 
177 private:
178 
179  void setResolution(VGATimings const& timings);
180  void init(gpio_num_t VSyncGPIO);
181  void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
182  void freeBuffers();
183 
184  void fillDMABuffers();
185  uint8_t packHVSync(bool HSync, bool VSync);
186  uint8_t preparePixelWithSync(RGB222 rgb, bool HSync, bool VSync);
187 
188  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); }
189 
190  static void ISRHandler(void * arg);
191 
192 
193  static volatile int s_scanLine;
194  static uint32_t s_blankPatternDWord;
195  static uint32_t * s_fgbgPattern;
196  static int s_textRow;
197  static bool s_upperRow;
198  static lldesc_t volatile * s_frameResetDesc;
199 
200  VGATimings m_timings;
201 
202  GPIOStream m_GPIOStream;
203  int m_bitsPerChannel; // 1 = 8 colors, 2 = 64 colors, set by begin()
204  lldesc_t volatile * m_DMABuffers;
205  int m_DMABuffersCount;
206 
207  uint32_t * m_lines;
208 
209  int m_rows;
210 
211  volatile uint8_t * m_blankLine; // for vertical porch lines
212  volatile uint8_t * m_syncLine; // for vertical sync lines
213 
214  intr_handle_t m_isr_handle;
215 
216  // contains H and V signals for visible line
217  volatile uint8_t m_HVSync;
218 
219  uint8_t * m_charData;
220  uint32_t const * m_map;
221 
222  // cursor props
223  bool m_cursorEnabled;
224  int m_cursorCounter; // trip from -m_cursorSpeed to +m_cursorSpeed (>= cursor is visible)
225  int m_cursorSpeed;
226  int m_cursorRow;
227  int m_cursorCol;
228  uint8_t m_cursorForeground;
229  uint8_t m_cursorBackground;
230 
231 };
232 
233 
234 
235 }
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:36
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.