23 #ifndef _VGACONTROLLER_H_INCLUDED 24 #define _VGACONTROLLER_H_INCLUDED 39 #include "rom/lldesc.h" 86 enum class Primitive {
143 #if VGAHAS_INVERTRECT 161 #if VGAHAS_READWRITERAWDATA 218 RGB_t(uint8_t red, uint8_t green, uint8_t blue) :
R(red),
G(green),
B(blue) { }
219 void operator = (
const RGB_t& c)
volatile {
R = c.R;
G = c.G;
B = c.B; }
237 Rect_t(int16_t X1_, int16_t Y1_, int16_t X2_, int16_t Y2_) {
X1 = X1_;
Y1 = Y1_;
X2 = X2_;
Y2 = Y2_; }
238 void operator = (
const Rect_t& c)
volatile {
X1 = c.X1;
Y1 = c.Y1;
X2 = c.X2;
Y2 = c.Y2; }
252 void operator = (
const Point_t & c)
volatile {
X = c.
X;
Y = c.
Y; }
263 void operator = (
const Size_t & c)
volatile { width = c.width; height = c.height; }
277 uint8_t
const * data;
279 void operator = (
const Glyph_t & c)
volatile { X = c.X; Y = c.Y; width = c.width; height = c.height; data = c.data; }
294 void operator = (
const RawData_t & c)
volatile { X = c.X; Y = c.Y; width = c.width; height = c.height; data = c.data; }
315 void operator = (
const GlyphOptions_t & c)
volatile { value = c.value; }
316 GlyphOptions_t & FillBackground(
bool value) {
fillBackground = value;
return *
this; }
317 GlyphOptions_t & Bold(
bool value) {
bold = value;
return *
this; }
318 GlyphOptions_t & Italic(
bool value) {
italic = value;
return *
this; }
319 GlyphOptions_t & Underline(
bool value) {
underline = value;
return *
this; }
320 GlyphOptions_t & DoubleWidth(uint8_t value) {
doubleWidth = value;
return *
this; }
321 GlyphOptions_t & Invert(uint8_t value) {
invert = value;
return *
this; }
330 uint8_t swapFGBG : 1;
337 #define VGAGREENBIT 2 339 #define VGAHSYNCBIT 6 340 #define VGAVSYNCBIT 7 349 #define VGAMAPINDEXBIT 0 350 #define VGAMAPBGCOLORBIT 8 351 #define VGAMAPFGCOLORBIT 12 352 #define VGAMAPOPTIONSBIT 16 353 #define VGAGLYPHMAPITEM_MAKE(index, bgColor, fgColor, options) (((uint32_t)(index) << VGAMAPINDEXBIT) | ((uint32_t)(bgColor) << VGAMAPBGCOLORBIT) | ((uint32_t)(fgColor) << VGAMAPFGCOLORBIT) | ((uint32_t)((options).value) << VGAMAPOPTIONSBIT)) 354 inline uint8_t VGAGLYPHMAPITEM_GETINDEX(uint32_t
const volatile * mapItem) {
return *mapItem >> VGAMAPINDEXBIT & 0xFF; }
355 inline Color VGAGLYPHMAPITEM_GETBGCOLOR(uint32_t
const volatile * mapItem) {
return (Color)(*mapItem >> VGAMAPBGCOLORBIT & 0x0F); }
356 inline Color VGAGLYPHMAPITEM_GETFGCOLOR(uint32_t
const volatile * mapItem) {
return (Color)(*mapItem >> VGAMAPFGCOLORBIT & 0x0F); }
357 inline GlyphOptions_t VGAGLYPHMAPITEM_GETOPTIONS(uint32_t
const volatile * mapItem) {
return (GlyphOptions_t){.value = (uint16_t)(*mapItem >> VGAMAPOPTIONSBIT & 0xFFFF)}; }
358 inline void VGAGLYPHMAPITEM_SETOPTIONS(uint32_t
volatile * mapItem, GlyphOptions_t
const & options) { *mapItem = (*mapItem & ~((uint32_t)0xFFFF << VGAMAPOPTIONSBIT)) | ((uint32_t)(options.value) << VGAMAPOPTIONSBIT); }
361 struct GlyphsBuffer_t {
362 uint16_t glyphsWidth;
363 uint16_t glyphsHeight;
364 uint8_t
const * glyphsData;
369 void operator = (
const GlyphsBuffer_t & c)
volatile { glyphsWidth = c.glyphsWidth;
370 glyphsHeight = c.glyphsHeight;
371 glyphsData = c.glyphsData;
378 struct GlyphsBufferRenderInfo_t {
381 GlyphsBuffer_t
const * glyphsBuffer;
394 GlyphOptions_t glyphOptions;
396 PaintOptions_t paintOptions;
397 GlyphsBufferRenderInfo_t glyphsBufferRenderInfo;
404 struct PaintState_t {
408 GlyphOptions_t glyphOptions;
409 PaintOptions_t paintOptions;
410 Rect_t scrollingRegion;
413 void operator = (
const PaintState_t & c)
volatile {
414 penColor = c.penColor;
415 brushColor = c.brushColor;
416 position = c.position;
417 glyphOptions = c.glyphOptions;
418 paintOptions = c.paintOptions;
419 scrollingRegion = c.scrollingRegion;
462 void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
481 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);
517 void setResolution(
char const * modeline,
int viewPortWidth = -1,
int viewPortHeight = -1);
520 Timings_t * getResolutionTimings() {
return &m_timings; }
552 void addPrimitive(Primitive_t
const & primitive);
553 void primitivesExecutionWait();
606 void moveScreen(int16_t offsetX, int16_t offsetY);
610 void init(gpio_num_t VSyncGPIO);
612 uint8_t preparePixel(
RGB_t rgb,
bool HSync =
false,
bool VSync =
false);
615 void fillHorizBuffers(int16_t offsetX);
616 void fillVertBuffers(int16_t offsetY);
617 int fill(uint8_t
volatile * buffer,
int startPos,
int length, uint8_t red, uint8_t green, uint8_t blue,
bool hsync,
bool vsync);
618 void allocateViewPort();
620 uint32_t calcRequiredDMABuffersCount(uint32_t viewPortHeight);
622 void execPrimitive(Primitive_t
const & prim);
624 void execSetPixel(
Point_t const & position);
625 void execLineTo(
Point_t const & position);
626 void execFillRect(
Rect_t const & rect);
627 void execFillEllipse(
Size_t const & size);
628 void execDrawEllipse(
Size_t const & size);
630 void execVScroll(int16_t scroll);
631 void execHScroll(int16_t scroll);
633 void execInvertRect(
Rect_t const & rect);
634 void execCopyRect(
Rect_t const & source);
635 void execSwapFGBG(
Rect_t const & rect);
636 void execReadRawData(
RawData_t const & rawData);
637 void execWriteRawData(
RawData_t const & rawData);
638 void execRenderGlyphsBuffer(GlyphsBufferRenderInfo_t
const & glyphsBufferRenderInfo);
640 void clearRow(
int row);
642 static void VSyncInterrupt();
644 static void setupGPIO(gpio_num_t gpio,
int bit, gpio_mode_t mode);
647 bool setDMABuffersCount(
int buffersCount);
648 void setDMABuffer(
int index,
void volatile * address,
int length);
649 void volatile * getDMABuffer(
int index,
int * length);
651 uint8_t m_bitsPerChannel;
653 uint16_t m_linesCount;
654 volatile uint16_t m_maxVSyncTicks;
658 volatile uint8_t * m_HBlankLine_withVSync;
659 volatile uint8_t * m_HBlankLine;
660 uint16_t m_HLineSize;
662 volatile uint16_t m_viewPortCol;
663 volatile uint16_t m_viewPortRow;
664 volatile uint16_t m_viewPortWidth;
665 volatile uint16_t m_viewPortHeight;
666 volatile uint8_t * * m_viewPort;
669 volatile QueueHandle_t m_execQueue;
670 PaintState_t m_paintState;
672 lldesc_t
volatile * m_DMABuffers;
673 int m_DMABuffersCount;
674 gpio_num_t m_VSyncGPIO;
675 int m_VSyncInterruptSuspended;
676 bool m_backgroundPrimitiveExecutionEnabled;
681 inline bool operator==(RGB_t
const& lhs, RGB_t
const& rhs)
683 return lhs.R == rhs.R && lhs.G == rhs.G && lhs.B == rhs.B;
687 inline bool operator!=(RGB_t
const& lhs, RGB_t
const& rhs)
689 return lhs.R != rhs.R || lhs.G != rhs.G || lhs.B == rhs.B;
693 template <
typename T>
void swap(T & v1, T & v2)
uint16_t invert
Definition: VGAController.h:307
Represents a glyph position, size and binary data.
Definition: VGAController.h:272
int getScreenWidth()
Returns the screen width in pixels.
Definition: VGAController.h:525
#define VGAVIEWPORTMEMORYPOOLCOUNT
Definition: VGAConf.h:122
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
This is the 8 colors (5 GPIOs) initializer.
Definition: VGAController.cpp:118
Color
This enum defines named colors.
Definition: VGAController.h:184
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
Definition: VGAController.cpp:644
int getScreenHeight()
Returns the screen height in pixels.
Definition: VGAController.h:530
uint16_t VSyncPulse
Definition: VGAController.h:72
bool doubleScan
Definition: VGAController.h:76
Specifies the VGA timings. This is a modeline decoded.
Definition: VGAController.h:63
uint16_t userOpt1
Definition: VGAController.h:311
int16_t X2
Definition: VGAController.h:233
uint8_t R
Definition: VGAController.h:212
int16_t X1
Definition: VGAController.h:231
int16_t Y1
Definition: VGAController.h:232
uint16_t reduceLuminosity
Definition: VGAController.h:305
void processPrimitives()
Draws immediately all primitives in the queue.
Definition: VGAController.cpp:670
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1)
Sets current resolution using linux-like modeline.
Definition: VGAController.cpp:248
void moveScreen(int16_t offsetX, int16_t offsetY)
Moves screen by specified horizontal and vertical offset.
Definition: VGAController.cpp:532
This file contains ESP32VGA library configuration settings, like number of supported colors...
int16_t Y
Definition: VGAController.h:250
Definition: VGACanvas.cpp:29
uint16_t HFrontPorch
Definition: VGAController.h:67
Specifies general paint options.
Definition: VGAController.h:329
uint16_t VVisibleArea
Definition: VGAController.h:70
uint16_t fillBackground
Definition: VGAController.h:303
int16_t X
Definition: VGAController.h:249
int getViewPortWidth()
Returns horizontal size of the viewport.
Definition: VGAController.h:545
Represents a bidimensional size.
Definition: VGAController.h:259
int getViewPortCol()
Returns horizontal position of the viewport (in case viewport width is less than screen width)...
Definition: VGAController.h:535
void operator=(const PaintOptions_t &c) volatile
Definition: VGAController.h:332
Represents the VGA controller.
Definition: VGAController.h:445
int16_t Y2
Definition: VGAController.h:234
uint16_t HVisibleArea
Definition: VGAController.h:66
ScreenBlock HStartingBlock
Definition: VGAController.h:77
char HSyncLogic
Definition: VGAController.h:74
char label[16]
Definition: VGAController.h:64
int getViewPortHeight()
Returns vertical size of the viewport.
Definition: VGAController.h:550
Specifies various glyph painting options.
Definition: VGAController.h:301
Represents an RGB color.
Definition: VGAController.h:211
uint16_t HBackPorch
Definition: VGAController.h:69
Represents a rectangle.
Definition: VGAController.h:230
uint16_t HSyncPulse
Definition: VGAController.h:68
uint16_t bold
Definition: VGAController.h:304
uint8_t getBitsPerChannel()
Gets number of bits allocated for each channel.
Definition: VGAController.h:490
uint16_t VFrontPorch
Definition: VGAController.h:71
char VSyncLogic
Definition: VGAController.h:75
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
Definition: VGAController.cpp:633
Represents the coordinate of a point.
Definition: VGAController.h:248
uint8_t G
Definition: VGAController.h:213
uint32_t frequency
Definition: VGAController.h:65
int getViewPortRow()
Returns vertical position of the viewport (in case viewport height is less than screen height)...
Definition: VGAController.h:540
uint16_t VBackPorch
Definition: VGAController.h:73
void enableBackgroundPrimitiveExecution(bool value)
Enables or disables drawings inside vertical retracing time.
Definition: VGAController.cpp:615
uint16_t doubleWidth
Definition: VGAController.h:310
Represents a region of raw screen buffer.
Definition: VGAController.h:287
uint16_t blank
Definition: VGAController.h:308
uint16_t italic
Definition: VGAController.h:306
ScreenBlock
Definition: VGAController.h:54
uint8_t B
Definition: VGAController.h:214
uint16_t underline
Definition: VGAController.h:309