ESP32VGA
ESP32 VGA Controller and Graphics Library
Public Member Functions | List of all members
ESP32VGA::VGAControllerClass Class Reference

Represents the VGA controller. More...

#include <VGAController.h>

Public Member Functions

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. More...
 
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)
 This is the 64 colors (8 GPIOs) initializer. More...
 
uint8_t getBitsPerChannel ()
 Gets number of bits allocated for each channel. More...
 
void setResolution (char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1)
 Sets current resolution using linux-like modeline. More...
 
int getScreenWidth ()
 Returns the screen width in pixels.
 
int getScreenHeight ()
 Returns the screen height in pixels.
 
int getViewPortCol ()
 Returns horizontal position of the viewport (in case viewport width is less than screen width).
 
int getViewPortRow ()
 Returns vertical position of the viewport (in case viewport height is less than screen height).
 
int getViewPortWidth ()
 Returns horizontal size of the viewport.
 
int getViewPortHeight ()
 Returns vertical size of the viewport.
 
void enableBackgroundPrimitiveExecution (bool value)
 Enables or disables drawings inside vertical retracing time. More...
 
void suspendBackgroundPrimitiveExecution ()
 Suspends drawings. More...
 
void resumeBackgroundPrimitiveExecution ()
 Resumes drawings after suspendBackgroundPrimitiveExecution(). More...
 
void processPrimitives ()
 Draws immediately all primitives in the queue. More...
 
void moveScreen (int16_t offsetX, int16_t offsetY)
 Moves screen by specified horizontal and vertical offset. More...
 

Detailed Description

Represents the VGA controller.

Use this class to set screen resolution and to associate VGA signals to ESP32 GPIO outputs.

This example initializes VGA Controller with 8 colors (5 GPIOs used) and 640x350 resolution:

// Assign GPIO22 to Red, GPIO21 to Green, GPIO19 to Blue, GPIO18 to HSync and GPIO5 to VSync
VGAController.begin(GPIO_NUM_22, GPIO_NUM_21, GPIO_NUM_19, GPIO_NUM_18, GPIO_NUM_5);

// Set 640x350@70Hz resolution
VGAController.setResolution(VGA_640x350_70Hz);

This example initializes VGA Controller with 64 colors (8 GPIOs used) and 640x350 resolution:

// Assign GPIO22 and GPIO_NUM_21 to Red, GPIO_NUM_19 and GPIO_NUM_18 to Green, GPIO_NUM_5 and GPIO_NUM_4 to Blue, GPIO_NUM_23 to HSync and GPIO_NUM_15 to VSync
VGAController.begin(GPIO_NUM_22, GPIO_NUM_21, GPIO_NUM_19, GPIO_NUM_18, GPIO_NUM_5, GPIO_NUM_4, GPIO_NUM_23, GPIO_NUM_15);

// Set 640x350@70Hz resolution
VGAController.setResolution(VGA_640x350_70Hz);

Member Function Documentation

◆ begin() [1/2]

void ESP32VGA::VGAControllerClass::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.

One GPIO per channel, plus horizontal and vertical sync signals.

Parameters
redGPIOGPIO to use for red channel.
greenGPIOGPIO to use for green channel.
blueGPIOGPIO to use for blue channel.
HSyncGPIOGPIO to use for horizontal sync signal.
VSyncGPIOGPIO to use for vertical sync signal.
// Use GPIO 22 for red, GPIO 21 for green, GPIO 19 for blue, GPIO 18 for HSync and GPIO 5 for VSync
VGAController.begin(GPIO_NUM_22, GPIO_NUM_21, GPIO_NUM_19, GPIO_NUM_18, GPIO_NUM_5);

◆ begin() [2/2]

void ESP32VGA::VGAControllerClass::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 
)

This is the 64 colors (8 GPIOs) initializer.

Two GPIOs per channel, plus horizontal and vertical sync signals.

Parameters
red1GPIOGPIO to use for red channel, MSB bit.
red0GPIOGPIO to use for red channel, LSB bit.
green1GPIOGPIO to use for green channel, MSB bit.
green0GPIOGPIO to use for green channel, LSB bit.
blue1GPIOGPIO to use for blue channel, MSB bit.
blue0GPIOGPIO to use for blue channel, LSB bit.
HSyncGPIOGPIO to use for horizontal sync signal.
VSyncGPIOGPIO to use for vertical sync signal.

// Use GPIO 22-21 for red, GPIO 19-18 for green, GPIO 5-4 for blue, GPIO 23 for HSync and GPIO 15 for VSync VGAController.begin(GPIO_NUM_22, GPIO_NUM_21, GPIO_NUM_19, GPIO_NUM_18, GPIO_NUM_5, GPIO_NUM_4, GPIO_NUM_23, GPIO_NUM_15);

◆ enableBackgroundPrimitiveExecution()

void ESP32VGA::VGAControllerClass::enableBackgroundPrimitiveExecution ( bool  value)

Enables or disables drawings inside vertical retracing time.

When vertical retracing occurs (on Vertical Sync) an interrupt is trigged. Inside this interrupt primitives like line, circles, glyphs, etc.. are painted. This method can disable (or reenable) this behavior, making drawing instantaneous. Flickering may occur when drawings are executed out of retracing time. When background executing is disabled the queue is emptied executing all pending primitives.

Parameters
valueWhen true drawings are done during vertical retracing, when false drawings are executed instantly.

◆ getBitsPerChannel()

uint8_t ESP32VGA::VGAControllerClass::getBitsPerChannel ( )
inline

Gets number of bits allocated for each channel.

Number of bits depends by which begin() initializer has been called.

Returns
1 (8 colors) or 2 (64 colors).

◆ moveScreen()

void ESP32VGA::VGAControllerClass::moveScreen ( int16_t  offsetX,
int16_t  offsetY 
)

Moves screen by specified horizontal and vertical offset.

Screen moving is performed changing horizontal and vertical Front and Back porchs.

Parameters
offsetXHorizontal offset in pixels. < 0 goes left, > 0 goes right.
offsetYVertical offset in pixels. < 0 goes up, > 0 goes down.

Example:

// Move screen 4 pixels right, 1 pixel left
VGAController.moveScreen(4, -1);

◆ processPrimitives()

void IRAM_ATTR ESP32VGA::VGAControllerClass::processPrimitives ( )

Draws immediately all primitives in the queue.

Draws all primitives before they are processed in the vertical sync interrupt. May generate flickering because don't care of vertical sync.

◆ resumeBackgroundPrimitiveExecution()

void ESP32VGA::VGAControllerClass::resumeBackgroundPrimitiveExecution ( )

Resumes drawings after suspendBackgroundPrimitiveExecution().

Resumes drawings enabling vertical sync interrupt.

◆ setResolution()

void ESP32VGA::VGAControllerClass::setResolution ( char const *  modeline,
int  viewPortWidth = -1,
int  viewPortHeight = -1 
)

Sets current resolution using linux-like modeline.

Modeline must have following syntax (non case sensitive):

"label" clock_mhz hdisp hsyncstart hsyncend htotal vdisp vsyncstart vsyncend vtotal (+HSync | -HSync) (+VSync | -VSync) [DoubleScan] [FrontPorchBegins | SyncBegins | BackPorchBegins | VisibleBegins]

In VGAConf.h there are macros with some predefined modelines for common resolutions.

Parameters
modelineLinux-like modeline as specified above.
viewPortWidthHorizontal viewport size in pixels. If less than zero (-1) it is sized to modeline visible area width.
viewPortHeightVertical viewport size in pixels. If less then zero (-1) it is sized to maximum allocable.

Example:

// Use predefined modeline for 640x480@60Hz
VGAController.setResolution(VGA_640x480_60Hz);

// The same of above using modeline string
VGAController.setResolution("\"640x480@60Hz\" 25.175 640 656 752 800 480 490 492 525 -HSync -VSync");

// Set 640x382@60Hz but limit the viewport to 640x350
VGAController.setResolution(VGA_640x382_60Hz, 640, 350);

◆ suspendBackgroundPrimitiveExecution()

void ESP32VGA::VGAControllerClass::suspendBackgroundPrimitiveExecution ( )

Suspends drawings.

Suspends drawings disabling vertical sync interrupt. After call to suspendBackgroundPrimitiveExecution() adding new primitives may cause a deadlock. To avoid it a call to "processPrimitives()" should be performed very often. This method maintains a counter so can be nested.


The documentation for this class was generated from the following files: