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.
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 
47 
48 namespace fabgl {
49 
50 
51 #define VGATextController_WIDTH 640
52 #define VGATextController_HEIGHT 480
53 #define VGATextController_MODELINE VGA_640x480_60Hz
54 
55 
56 
57 
58 
59 
80 
81 public:
82 
85 
102  void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
103 
123  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);
124 
135  void begin();
136 
142  void setResolution(char const * modeline = nullptr, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
143 
149  void setTextMap(uint32_t const * map, int rows);
150 
157  void adjustMapSize(int * columns, int * rows);
158 
159  int getColumns() { return s_columns; }
160  int getRows() { return s_rows; }
161  int colorsCount() { return 16; }
162 
163  void enableCursor(bool value) { m_cursorEnabled = value; }
164  void setCursorPos(int row, int col) { m_cursorRow = row; m_cursorCol = col; m_cursorCounter = 0; }
165  void setCursorSpeed(int value) { m_cursorSpeed = value; }
166  void setCursorForeground(Color value);
167  void setCursorBackground(Color value);
168 
185  void setFont(FontInfo const * value);
186 
187  FontInfo const * getFont() { return m_font; }
188 
189 private:
190 
191  void setResolution(VGATimings const& timings);
192  void init(gpio_num_t VSyncGPIO);
193  void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
194  void freeBuffers();
195 
196  void fillDMABuffers();
197  uint8_t packHVSync(bool HSync, bool VSync);
198  uint8_t preparePixelWithSync(RGB222 rgb, bool HSync, bool VSync);
199 
200  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); }
201 
202  static void ISRHandler(void * arg);
203 
204 
205  static volatile int s_scanLine;
206  static uint32_t s_blankPatternDWord;
207  static uint32_t * s_fgbgPattern;
208  static int s_textRow;
209  static bool s_upperRow;
210  static lldesc_t volatile * s_frameResetDesc;
211  static int16_t s_charWidthInBytes;
212  static int16_t s_charHeight;
213  static int16_t s_columns;
214  static int16_t s_rows;
215 
216  VGATimings m_timings;
217 
218  GPIOStream m_GPIOStream;
219  int m_bitsPerChannel; // 1 = 8 colors, 2 = 64 colors, set by begin()
220  lldesc_t volatile * m_DMABuffers;
221  int m_DMABuffersCount;
222 
223  uint32_t * m_lines;
224 
225  int m_rows;
226 
227  volatile uint8_t * m_blankLine; // for vertical porch lines
228  volatile uint8_t * m_syncLine; // for vertical sync lines
229 
230  intr_handle_t m_isr_handle;
231 
232  // contains H and V signals for visible line
233  volatile uint8_t m_HVSync;
234 
235  uint8_t * m_charData;
236  uint32_t const * m_map;
237 
238  // cursor props
239  bool m_cursorEnabled;
240  int m_cursorCounter; // trip from -m_cursorSpeed to +m_cursorSpeed (>= cursor is visible)
241  int m_cursorSpeed;
242  int m_cursorRow;
243  int m_cursorCol;
244  uint8_t m_cursorForeground;
245  uint8_t m_cursorBackground;
246  FontInfo const * m_font;
247 
248 };
249 
250 
251 
252 }
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)
Adjusts columns and rows to the controller limits.
int colorsCount()
Determines number of colors this display can provide.
This file contains fabgl::VGAController definition.
void setResolution(char const *modeline=nullptr, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets fixed resolution.
This file contains some utility classes and functions.
Definition: canvas.cpp:36
This file contains FabGL library configuration settings, like number of supported colors...
void setFont(FontInfo const *value)
Sets font.
Represents the base abstract class for textual display controllers.
void setTextMap(uint32_t const *map, int rows)
Sets text map to display.