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 //#define VGATextController_PERFORMANCE_CHECK
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);
147 
153  void setTextMap(uint32_t const * map, int rows);
154 
161  void adjustMapSize(int * columns, int * rows);
162 
163  int getScreenWidth() { return m_timings.HVisibleArea; }
164  int getScreenHeight() { return m_timings.VVisibleArea; }
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 
176 private:
177 
178  void setResolution(VGATimings const& timings);
179  void init(gpio_num_t VSyncGPIO);
180  void setupGPIO(gpio_num_t gpio, int bit, gpio_mode_t mode);
181  void freeBuffers();
182 
183  void fillDMABuffers();
184  uint8_t packHVSync(bool HSync, bool VSync);
185  uint8_t preparePixelWithSync(RGB222 rgb, bool HSync, bool VSync);
186 
187  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); }
188 
189  static void I2SInterrupt(void * arg);
190 
191 
192  static volatile int s_scanLine;
193  static uint32_t s_blankPatternDWord;
194  static uint32_t * s_fgbgPattern;
195  static int s_textRow;
196  static bool s_upperRow;
197  static lldesc_t volatile * s_frameResetDesc;
198 
199  VGATimings m_timings;
200 
201  GPIOStream m_GPIOStream;
202  int m_bitsPerChannel; // 1 = 8 colors, 2 = 64 colors, set by begin()
203  lldesc_t volatile * m_DMABuffers;
204  int m_DMABuffersCount;
205 
206  uint32_t * m_lines;
207 
208  int m_rows;
209 
210  volatile uint8_t * m_blankLine; // for vertical porch lines
211  volatile uint8_t * m_syncLine; // for vertical sync lines
212 
213  intr_handle_t m_isr_handle;
214 
215  // contains H and V signals for visible line
216  volatile uint8_t m_HVSync;
217 
218  uint8_t * m_charData;
219  uint32_t const * m_map;
220 
221  // cursor props
222  bool m_cursorEnabled;
223  int m_cursorCounter; // trip from -m_cursorSpeed to +m_cursorSpeed (>= cursor is visible)
224  int m_cursorSpeed;
225  int m_cursorRow;
226  int m_cursorCol;
227  uint8_t m_cursorForeground;
228  uint8_t m_cursorBackground;
229 
230 };
231 
232 
233 
234 }
void adjustMapSize(int *columns, int *rows)
Adjust columns and rows to the controller limits.
Definition: vgatextcontroller.cpp:67
Represents the VGA text-only controller.
Definition: vgatextcontroller.h:83
int getScreenHeight()
Determines the screen height in pixels.
Definition: vgatextcontroller.h:164
void setTextMap(uint32_t const *map, int rows)
Sets text map to display.
Definition: vgatextcontroller.cpp:57
int16_t VVisibleArea
Definition: vgacontroller.h:96
Color
This enum defines named colors.
Definition: displaycontroller.h:198
void setResolution(char const *modeline=nullptr)
Sets fixed resolution.
Definition: vgatextcontroller.cpp:151
This file contains fabgl::GPIOStream definition.
This file contains fabgl::VGAController definition.
This file contains some utility classes and functions.
Definition: canvas.cpp:31
This file contains FabGL library configuration settings, like number of supported colors...
int getScreenWidth()
Determines the screen width in pixels.
Definition: vgatextcontroller.h:163
Represents the base abstract class for textual display controllers.
Definition: displaycontroller.h:679
void begin()
This is the 64 colors (8 GPIOs) initializer using default pinout.
Definition: vgatextcontroller.cpp:125
int16_t HVisibleArea
Definition: vgacontroller.h:92