38 #include "rom/lldesc.h" 39 #include "driver/gpio.h" 41 #include "freertos/FreeRTOS.h" 42 #include "freertos/queue.h" 59 #define SYNC_MASK ((1 << HSYNC_BIT) | (1 << VSYNC_BIT)) 67 #define PIXELINROW(row, X) (row[(X) ^ 2]) 70 #define PIXEL(X, Y) PIXELINROW(m_viewPort[(Y)], X) 262 RGB() :
R(0),
G(0),
B(0) { }
264 RGB(uint8_t red, uint8_t green, uint8_t blue) :
R(red),
G(green),
B(blue) { }
268 inline bool operator==(RGB
const& lhs, RGB
const& rhs)
270 return lhs.R == rhs.R && lhs.G == rhs.G && lhs.B == rhs.B;
274 inline bool operator!=(RGB
const& lhs, RGB
const& rhs)
276 return lhs.R != rhs.R || lhs.G != rhs.G || lhs.B == rhs.B;
294 Glyph(
int X_,
int Y_,
int width_,
int height_, uint8_t
const * data_) :
X(X_),
Y(Y_),
width(width_),
height(height_),
data(data_) { }
344 #define GLYPHMAP_INDEX_BIT 0 345 #define GLYPHMAP_BGCOLOR_BIT 8 346 #define GLYPHMAP_FGCOLOR_BIT 12 347 #define GLYPHMAP_OPTIONS_BIT 16 348 #define GLYPHMAP_ITEM_MAKE(index, bgColor, fgColor, options) (((uint32_t)(index) << GLYPHMAP_INDEX_BIT) | ((uint32_t)(bgColor) << GLYPHMAP_BGCOLOR_BIT) | ((uint32_t)(fgColor) << GLYPHMAP_FGCOLOR_BIT) | ((uint32_t)((options).value) << GLYPHMAP_OPTIONS_BIT)) 349 inline uint8_t glyphMapItem_getIndex(uint32_t
const volatile * mapItem) {
return *mapItem >> GLYPHMAP_INDEX_BIT & 0xFF; }
350 inline Color glyphMapItem_getBGColor(uint32_t
const volatile * mapItem) {
return (
Color)(*mapItem >> GLYPHMAP_BGCOLOR_BIT & 0x0F); }
351 inline Color glyphMapItem_getFGColor(uint32_t
const volatile * mapItem) {
return (
Color)(*mapItem >> GLYPHMAP_FGCOLOR_BIT & 0x0F); }
352 inline GlyphOptions glyphMapItem_getOptions(uint32_t
const volatile * mapItem) {
return (GlyphOptions){.value = (uint16_t)(*mapItem >> GLYPHMAP_OPTIONS_BIT & 0xFFFF)}; }
353 inline void glyphMapItem_setOptions(uint32_t
volatile * mapItem, GlyphOptions
const & options) { *mapItem = (*mapItem & ~((uint32_t)0xFFFF << GLYPHMAP_OPTIONS_BIT)) | ((uint32_t)(options.value) << GLYPHMAP_OPTIONS_BIT); }
355 struct GlyphsBuffer {
357 int16_t glyphsHeight;
358 uint8_t
const * glyphsData;
365 struct GlyphsBufferRenderInfo {
368 GlyphsBuffer
const * glyphsBuffer;
370 GlyphsBufferRenderInfo(
int itemX_,
int itemY_, GlyphsBuffer
const * glyphsBuffer_) : itemX(itemX_), itemY(itemY_), glyphsBuffer(glyphsBuffer_) { }
392 Bitmap(
int width_,
int height_,
void const * data_,
bool copy =
false);
393 Bitmap(
int width_,
int height_,
void const * data_,
int bitsPerPixel,
RGB foregroundColor,
bool copy =
false);
398 struct BitmapDrawingInfo {
401 Bitmap
const * bitmap;
403 BitmapDrawingInfo(
int X_,
int Y_, Bitmap
const * bitmap_) : X(X_), Y(Y_), bitmap(bitmap_) { }
443 struct QuadTreeObject;
459 int16_t currentFrame;
462 int16_t savedBackgroundWidth;
463 int16_t savedBackgroundHeight;
464 uint8_t * savedBackground;
465 QuadTreeObject * collisionDetectorObject;
472 uint8_t allowDraw: 1;
477 Bitmap const * getFrame() {
return frames ? frames[currentFrame] :
nullptr; }
478 int getFrameIndex() {
return currentFrame; }
479 void nextFrame() { ++currentFrame;
if (currentFrame >= framesCount) currentFrame = 0; }
480 Sprite * setFrame(
int frame) { currentFrame = frame;
return this; }
484 int getWidth() {
return frames[currentFrame]->
width; }
485 int getHeight() {
return frames[currentFrame]->
height; }
486 void allocRequiredBackgroundBuffer();
487 Sprite * move(
int offsetX,
int offsetY,
bool wrapAround =
true);
488 Sprite * moveTo(
int x,
int y);
493 Point const * points;
524 GlyphOptions glyphOptions;
525 PaintOptions paintOptions;
526 GlyphsBufferRenderInfo glyphsBufferRenderInfo;
527 BitmapDrawingInfo bitmapDrawingInfo;
540 GlyphOptions glyphOptions;
541 PaintOptions paintOptions;
542 Rect scrollingRegion;
545 Rect absClippingRect;
590 void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
611 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);
661 void setResolution(
char const * modeline,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
663 void setResolution(
Timings const& timings,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
665 Timings * getResolutionTimings() {
return &m_timings; }
709 void addPrimitive(Primitive
const & primitive);
711 void primitivesExecutionWait();
735 bool backgroundPrimitiveTimeoutEnabled() {
return m_backgroundPrimitiveTimeoutEnabled; }
816 template <
typename T>
955 void setRawPixel(
int x,
int y, uint8_t rgb) { PIXEL(x, y) = rgb; }
974 void init(gpio_num_t VSyncGPIO);
976 uint8_t packHVSync(
bool HSync =
false,
bool VSync =
false);
977 uint8_t preparePixel(
RGB rgb,
bool HSync =
false,
bool VSync =
false);
980 void fillHorizBuffers(
int offsetX);
981 void fillVertBuffers(
int offsetY);
982 int fill(uint8_t
volatile * buffer,
int startPos,
int length, uint8_t red, uint8_t green, uint8_t blue,
bool hsync,
bool vsync);
983 void allocateViewPort();
985 int calcRequiredDMABuffersCount(
int viewPortHeight);
987 void execPrimitive(Primitive
const & prim);
989 void execSetPixel(
Point const & position);
990 void execSetPixelAt(PixelDesc
const & pixelDesc);
991 void execLineTo(
Point const & position);
992 void execFillRect(
Rect const & rect);
993 void execDrawRect(
Rect const & rect);
994 void execFillEllipse(
Size const & size);
995 void execDrawEllipse(
Size const & size);
997 void execVScroll(
int scroll);
998 void execHScroll(
int scroll);
1002 void execInvertRect(
Rect const & rect);
1003 void execCopyRect(
Rect const & source);
1004 void execSwapFGBG(
Rect const & rect);
1005 void execRenderGlyphsBuffer(GlyphsBufferRenderInfo
const & glyphsBufferRenderInfo);
1006 void execDrawBitmap(BitmapDrawingInfo
const & bitmapDrawingInfo);
1007 void execSwapBuffers();
1008 void execDrawPath(Path
const & path);
1009 void execFillPath(Path
const & path);
1011 void updateAbsoluteClippingRect();
1013 void drawBitmap(
int destX,
int destY,
Bitmap const * bitmap, uint8_t * saveBackground,
bool ignoreClippingRect);
1015 void fillRow(
int y,
int x1,
int x2, uint8_t pattern);
1016 void swapRows(
int yA,
int yB,
int x1,
int x2);
1018 void drawLine(
int X1,
int Y1,
int X2,
int Y2, uint8_t pattern);
1025 static void VSyncInterrupt();
1027 static void setupGPIO(gpio_num_t gpio,
int bit, gpio_mode_t mode);
1030 bool setDMABuffersCount(
int buffersCount);
1031 void setDMABufferBlank(
int index,
void volatile * address,
int length);
1032 void setDMABufferView(
int index,
int row,
int scan,
volatile uint8_t * * viewPort,
bool onVisibleDMA);
1033 void setDMABufferView(
int index,
int row,
int scan);
1034 void volatile * getDMABuffer(
int index,
int * length);
1036 int m_bitsPerChannel;
1038 int16_t m_linesCount;
1039 volatile int16_t m_maxVSyncISRTime;
1043 volatile uint8_t * m_HBlankLine_withVSync;
1044 volatile uint8_t * m_HBlankLine;
1045 int16_t m_HLineSize;
1047 bool m_doubleBuffered;
1049 volatile int16_t m_viewPortCol;
1050 volatile int16_t m_viewPortRow;
1051 volatile int16_t m_viewPortWidth;
1052 volatile int16_t m_viewPortHeight;
1056 volatile uint8_t * * m_viewPort;
1057 volatile uint8_t * * m_viewPortVisible;
1061 volatile QueueHandle_t m_execQueue;
1062 PaintState m_paintState;
1066 lldesc_t
volatile * m_DMABuffersHead;
1067 lldesc_t
volatile * m_DMABuffers;
1068 lldesc_t
volatile * m_DMABuffersVisible;
1070 int m_DMABuffersCount;
1072 gpio_num_t m_VSyncGPIO;
1073 int m_VSyncInterruptSuspended;
1074 bool m_backgroundPrimitiveExecutionEnabled;
1075 volatile bool m_backgroundPrimitiveTimeoutEnabled;
1081 bool m_spritesHidden;
1085 int16_t m_mouseHotspotX;
1086 int16_t m_mouseHotspotY;
Definition: vgacontroller.h:422
int16_t height
Definition: vgacontroller.h:387
uint16_t blank
Definition: vgacontroller.h:309
Definition: vgacontroller.h:411
Definition: vgacontroller.h:412
Defines a cursor.
Definition: vgacontroller.h:436
Represents an RGB color.
Definition: vgacontroller.h:257
Definition: vgacontroller.h:240
void enableBackgroundPrimitiveTimeout(bool value)
Enables or disables execution time limitation inside vertical retracing interrupt.
Definition: vgacontroller.h:733
uint8_t R
Definition: vgacontroller.h:258
Represents a sprite.
Definition: vgacontroller.h:454
Definition: vgacontroller.h:231
Definition: vgacontroller.h:243
int getViewPortWidth()
Determines horizontal size of the viewport.
Definition: vgacontroller.h:700
Definition: vgacontroller.h:237
Definition: vgacontroller.h:246
int getViewPortHeight()
Determines vertical size of the viewport.
Definition: vgacontroller.h:707
uint16_t italic
Definition: vgacontroller.h:307
Color
This enum defines named colors.
Definition: vgacontroller.h:230
Definition: vgacontroller.h:236
int getViewPortRow()
Determines vertical position of the viewport.
Definition: vgacontroller.h:693
void setMouseCursorPos(int X, int Y)
Sets mouse cursor position.
Definition: vgacontroller.cpp:2242
void processPrimitives()
Draws immediately all primitives in the queue.
Definition: vgacontroller.cpp:788
GlyphOptions & Bold(bool value)
Helper method to set or reset bold.
Definition: vgacontroller.h:321
void shrinkScreen(int shrinkX, int shrinkY)
Reduces or expands screen size by the specified horizontal and vertical offset.
Definition: vgacontroller.cpp:581
uint8_t createRawPixel(RGB rgb)
Creates a raw pixel to use with VGAControllerClass.setRawPixel.
Definition: vgacontroller.h:939
GlyphOptions & FillBackground(bool value)
Helper method to set or reset fillBackground.
Definition: vgacontroller.h:318
Definition: vgacontroller.h:234
int16_t width
Definition: vgacontroller.h:386
Definition: vgacontroller.h:235
int16_t HSyncPulse
Definition: vgacontroller.h:91
Definition: vgacontroller.h:81
uint8_t NOT
Definition: vgacontroller.h:503
uint16_t invert
Definition: vgacontroller.h:308
uint8_t const * data
Definition: vgacontroller.h:291
uint8_t const * data
Definition: vgacontroller.h:388
uint8_t * getScanline(int y)
Gets a raw scanline pointer.
Definition: vgacontroller.h:970
GlyphOptions & Invert(uint8_t value)
Helper method to set or reset foreground and background swapping.
Definition: vgacontroller.h:333
uint16_t doubleWidth
Definition: vgacontroller.h:311
int frequency
Definition: vgacontroller.h:88
int getViewPortCol()
Determines horizontal position of the viewport.
Definition: vgacontroller.h:686
void setMouseCursor(Cursor const *cursor)
Sets mouse cursor and make it visible.
Definition: vgacontroller.cpp:2213
Definition: vgacontroller.h:424
void moveScreen(int offsetX, int offsetY)
Moves screen by specified horizontal and vertical offset.
Definition: vgacontroller.cpp:572
Definition: vgacontroller.h:78
Definition: vgacontroller.h:79
void begin()
This is the 64 colors (8 GPIOs) initializer using default pinout.
Definition: vgacontroller.cpp:156
void enableBackgroundPrimitiveExecution(bool value)
Enables or disables drawings inside vertical retracing time.
Definition: vgacontroller.cpp:732
ScreenBlock
Represents one of the four blocks of horizontal or vertical line.
Definition: vgacontroller.h:77
Represents a glyph position, size and binary data.
Definition: vgacontroller.h:286
Definition: vgacontroller.h:427
GlyphOptions & Underline(bool value)
Helper method to set or reset underlined.
Definition: vgacontroller.h:327
Represents the coordinate of a point.
Definition: fabutils.h:125
Represents an image with 64 colors image and transparency.
Definition: vgacontroller.h:385
Definition: vgacontroller.h:242
Definition: vgacontroller.h:238
This file contains some utility classes and functions.
int16_t VSyncPulse
Definition: vgacontroller.h:95
Definition: canvas.cpp:47
CursorName
This enum defines a set of predefined mouse cursors.
Definition: vgacontroller.h:410
Definition: vgacontroller.h:233
uint16_t bold
Definition: vgacontroller.h:305
char VSyncLogic
Definition: vgacontroller.h:98
int16_t hotspotX
Definition: vgacontroller.h:437
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets current resolution using linux-like modeline.
Definition: vgacontroller.cpp:267
int16_t HBackPorch
Definition: vgacontroller.h:92
Represents the VGA controller.
Definition: vgacontroller.h:570
Specifies various glyph painting options.
Definition: vgacontroller.h:302
Represents a rectangle.
Definition: fabutils.h:158
uint8_t getBitsPerChannel()
Gets number of bits allocated for each channel.
Definition: vgacontroller.h:632
ScreenBlock HStartingBlock
Definition: vgacontroller.h:101
GlyphOptions & Italic(bool value)
Helper method to set or reset italic.
Definition: vgacontroller.h:324
Definition: vgacontroller.h:239
Definition: vgacontroller.h:413
void refreshSprites()
Forces the sprites to be updated.
Definition: vgacontroller.cpp:2034
char HSyncLogic
Definition: vgacontroller.h:97
void setSprites(T *sprites, int count)
Sets the list of active sprites.
Definition: vgacontroller.h:817
int16_t X
Definition: vgacontroller.h:287
Definition: vgacontroller.h:414
Definition: vgacontroller.h:416
int16_t HFrontPorch
Definition: vgacontroller.h:90
int16_t VVisibleArea
Definition: vgacontroller.h:93
Definition: vgacontroller.h:429
void removeSprites()
Empties the list of active sprites.
Definition: vgacontroller.h:826
int16_t width
Definition: vgacontroller.h:289
This file contains FabGL library configuration settings, like number of supported colors...
uint8_t scanCount
Definition: vgacontroller.h:99
int16_t VFrontPorch
Definition: vgacontroller.h:94
int getScreenHeight()
Determines the screen height in pixels.
Definition: vgacontroller.h:679
Definition: vgacontroller.h:80
Represents a bidimensional size.
Definition: fabutils.h:143
Definition: vgacontroller.h:425
int getScreenWidth()
Determines the screen width in pixels.
Definition: vgacontroller.h:672
void setRawPixel(int x, int y, uint8_t rgb)
Sets a raw pixel prepared using VGAControllerClass.createRawPixel.
Definition: vgacontroller.h:955
void readScreen(Rect const &rect, RGB *destBuf)
Reads pixels inside the specified rectangle.
Definition: vgacontroller.cpp:1918
Definition: vgacontroller.h:232
GlyphOptions & DoubleWidth(uint8_t value)
Helper method to set or reset doubleWidth.
Definition: vgacontroller.h:330
int16_t Y
Definition: vgacontroller.h:288
Definition: vgacontroller.h:428
Specifies the VGA timings. This is a modeline decoded.
Definition: vgacontroller.h:86
Definition: vgacontroller.h:244
uint16_t fillBackground
Definition: vgacontroller.h:304
uint8_t multiScanBlack
Definition: vgacontroller.h:100
uint8_t B
Definition: vgacontroller.h:260
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
Definition: vgacontroller.cpp:750
uint16_t reduceLuminosity
Definition: vgacontroller.h:306
Definition: vgacontroller.h:245
uint16_t userOpt2
Definition: vgacontroller.h:313
Definition: vgacontroller.h:415
uint8_t G
Definition: vgacontroller.h:259
Definition: vgacontroller.h:423
Definition: vgacontroller.h:241
Definition: vgacontroller.h:417
Definition: vgacontroller.h:426
uint16_t userOpt1
Definition: vgacontroller.h:312
#define FABGLIB_VIEWPORT_MEMORY_POOL_COUNT
Definition: fabglconf.h:111
Definition: vgacontroller.h:420
Definition: vgacontroller.h:421
void writeScreen(Rect const &rect, RGB *srcBuf)
Writes pixels inside the specified rectangle.
Definition: vgacontroller.cpp:1930
uint16_t underline
Definition: vgacontroller.h:310
int16_t VBackPorch
Definition: vgacontroller.h:96
Specifies general paint options.
Definition: vgacontroller.h:501
char label[22]
Definition: vgacontroller.h:87
int16_t HVisibleArea
Definition: vgacontroller.h:89
uint8_t swapFGBG
Definition: vgacontroller.h:502
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
Definition: vgacontroller.cpp:760
Bitmap bitmap
Definition: vgacontroller.h:439
Definition: vgacontroller.h:419
int16_t height
Definition: vgacontroller.h:290
bool dataAllocated
Definition: vgacontroller.h:389
bool isDoubleBuffered()
Determines whether VGAControllerClass is on double buffered mode.
Definition: vgacontroller.h:843
Definition: vgacontroller.h:418
int16_t hotspotY
Definition: vgacontroller.h:438