38 #include "rom/lldesc.h" 39 #include "driver/gpio.h" 41 #include "freertos/FreeRTOS.h" 42 #include "freertos/queue.h" 244 RGB() :
R(0),
G(0),
B(0) { }
246 RGB(uint8_t red, uint8_t green, uint8_t blue) :
R(red),
G(green),
B(blue) { }
250 inline bool operator==(RGB
const& lhs, RGB
const& rhs)
252 return lhs.R == rhs.R && lhs.G == rhs.G && lhs.B == rhs.B;
256 inline bool operator!=(RGB
const& lhs, RGB
const& rhs)
258 return lhs.R != rhs.R || lhs.G != rhs.G || lhs.B == rhs.B;
276 Glyph(
int X_,
int Y_,
int width_,
int height_, uint8_t
const * data_) :
X(X_),
Y(Y_),
width(width_),
height(height_),
data(data_) { }
326 #define GLYPHMAP_INDEX_BIT 0 327 #define GLYPHMAP_BGCOLOR_BIT 8 328 #define GLYPHMAP_FGCOLOR_BIT 12 329 #define GLYPHMAP_OPTIONS_BIT 16 330 #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)) 331 inline uint8_t glyphMapItem_getIndex(uint32_t
const volatile * mapItem) {
return *mapItem >> GLYPHMAP_INDEX_BIT & 0xFF; }
332 inline Color glyphMapItem_getBGColor(uint32_t
const volatile * mapItem) {
return (
Color)(*mapItem >> GLYPHMAP_BGCOLOR_BIT & 0x0F); }
333 inline Color glyphMapItem_getFGColor(uint32_t
const volatile * mapItem) {
return (
Color)(*mapItem >> GLYPHMAP_FGCOLOR_BIT & 0x0F); }
334 inline GlyphOptions glyphMapItem_getOptions(uint32_t
const volatile * mapItem) {
return (GlyphOptions){.value = (uint16_t)(*mapItem >> GLYPHMAP_OPTIONS_BIT & 0xFFFF)}; }
335 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); }
337 struct GlyphsBuffer {
339 int16_t glyphsHeight;
340 uint8_t
const * glyphsData;
347 struct GlyphsBufferRenderInfo {
350 GlyphsBuffer
const * glyphsBuffer;
352 GlyphsBufferRenderInfo(
int itemX_,
int itemY_, GlyphsBuffer
const * glyphsBuffer_) : itemX(itemX_), itemY(itemY_), glyphsBuffer(glyphsBuffer_) { }
374 Bitmap(
int width_,
int height_,
void const * data_,
bool copy =
false);
375 Bitmap(
int width_,
int height_,
void const * data_,
int bitsPerPixel,
RGB foregroundColor,
bool copy =
false);
380 struct BitmapDrawingInfo {
383 Bitmap
const * bitmap;
385 BitmapDrawingInfo(
int X_,
int Y_, Bitmap
const * bitmap_) : X(X_), Y(Y_), bitmap(bitmap_) { }
425 struct QuadTreeObject;
441 int16_t currentFrame;
444 int16_t savedBackgroundWidth;
445 int16_t savedBackgroundHeight;
446 uint8_t * savedBackground;
447 QuadTreeObject * collisionDetectorObject;
454 uint8_t allowDraw: 1;
459 Bitmap const * getFrame() {
return frames ? frames[currentFrame] :
nullptr; }
460 int getFrameIndex() {
return currentFrame; }
461 void nextFrame() { ++currentFrame;
if (currentFrame >= framesCount) currentFrame = 0; }
462 Sprite * setFrame(
int frame) { currentFrame = frame;
return this; }
466 int getWidth() {
return frames[currentFrame]->
width; }
467 int getHeight() {
return frames[currentFrame]->
height; }
468 void allocRequiredBackgroundBuffer();
469 Sprite * move(
int offsetX,
int offsetY,
bool wrapAround =
true);
470 Sprite * moveTo(
int x,
int y);
475 Point const * points;
506 GlyphOptions glyphOptions;
507 PaintOptions paintOptions;
508 GlyphsBufferRenderInfo glyphsBufferRenderInfo;
509 BitmapDrawingInfo bitmapDrawingInfo;
522 GlyphOptions glyphOptions;
523 PaintOptions paintOptions;
524 Rect scrollingRegion;
527 Rect absClippingRect;
572 void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
593 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);
643 void setResolution(
char const * modeline,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
645 void setResolution(
Timings const& timings,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
647 Timings * getResolutionTimings() {
return &m_timings; }
691 void addPrimitive(Primitive
const & primitive);
693 void primitivesExecutionWait();
787 template <
typename T>
900 void init(gpio_num_t VSyncGPIO);
902 uint8_t packHVSync(
bool HSync =
false,
bool VSync =
false);
903 uint8_t preparePixel(
RGB rgb,
bool HSync =
false,
bool VSync =
false);
906 void fillHorizBuffers(
int offsetX);
907 void fillVertBuffers(
int offsetY);
908 int fill(uint8_t
volatile * buffer,
int startPos,
int length, uint8_t red, uint8_t green, uint8_t blue,
bool hsync,
bool vsync);
909 void allocateViewPort();
911 int calcRequiredDMABuffersCount(
int viewPortHeight);
913 void execPrimitive(Primitive
const & prim);
915 void execSetPixel(
Point const & position);
916 void execSetPixelAt(PixelDesc
const & pixelDesc);
917 void execLineTo(
Point const & position);
918 void execFillRect(
Rect const & rect);
919 void execDrawRect(
Rect const & rect);
920 void execFillEllipse(
Size const & size);
921 void execDrawEllipse(
Size const & size);
923 void execVScroll(
int scroll);
924 void execHScroll(
int scroll);
928 void execInvertRect(
Rect const & rect);
929 void execCopyRect(
Rect const & source);
930 void execSwapFGBG(
Rect const & rect);
931 void execRenderGlyphsBuffer(GlyphsBufferRenderInfo
const & glyphsBufferRenderInfo);
932 void execDrawBitmap(BitmapDrawingInfo
const & bitmapDrawingInfo);
933 void execSwapBuffers();
934 void execDrawPath(Path
const & path);
935 void execFillPath(Path
const & path);
937 void updateAbsoluteClippingRect();
939 void drawBitmap(
int destX,
int destY,
Bitmap const * bitmap, uint8_t * saveBackground,
bool ignoreClippingRect);
941 void fillRow(
int y,
int x1,
int x2, uint8_t pattern);
942 void swapRows(
int yA,
int yB,
int x1,
int x2);
944 void drawLine(
int X1,
int Y1,
int X2,
int Y2, uint8_t pattern);
951 static void VSyncInterrupt();
953 static void setupGPIO(gpio_num_t gpio,
int bit, gpio_mode_t mode);
956 bool setDMABuffersCount(
int buffersCount);
957 void setDMABufferBlank(
int index,
void volatile * address,
int length);
958 void setDMABufferView(
int index,
int row,
int scan,
volatile uint8_t * * viewPort,
bool onVisibleDMA);
959 void setDMABufferView(
int index,
int row,
int scan);
960 void volatile * getDMABuffer(
int index,
int * length);
962 int m_bitsPerChannel;
964 int16_t m_linesCount;
965 volatile int16_t m_maxVSyncISRTime;
969 volatile uint8_t * m_HBlankLine_withVSync;
970 volatile uint8_t * m_HBlankLine;
973 bool m_doubleBuffered;
975 volatile int16_t m_viewPortCol;
976 volatile int16_t m_viewPortRow;
977 volatile int16_t m_viewPortWidth;
978 volatile int16_t m_viewPortHeight;
982 volatile uint8_t * * m_viewPort;
983 volatile uint8_t * * m_viewPortVisible;
987 volatile QueueHandle_t m_execQueue;
988 PaintState m_paintState;
992 lldesc_t
volatile * m_DMABuffersHead;
993 lldesc_t
volatile * m_DMABuffers;
994 lldesc_t
volatile * m_DMABuffersVisible;
996 int m_DMABuffersCount;
998 gpio_num_t m_VSyncGPIO;
999 int m_VSyncInterruptSuspended;
1000 bool m_backgroundPrimitiveExecutionEnabled;
1006 bool m_spritesHidden;
1010 int16_t m_mouseHotspotX;
1011 int16_t m_mouseHotspotY;
Definition: vgacontroller.h:404
int16_t height
Definition: vgacontroller.h:369
uint16_t blank
Definition: vgacontroller.h:291
Definition: vgacontroller.h:393
Definition: vgacontroller.h:394
Defines a cursor.
Definition: vgacontroller.h:418
Represents an RGB color.
Definition: vgacontroller.h:239
Definition: vgacontroller.h:222
uint8_t R
Definition: vgacontroller.h:240
Represents a sprite.
Definition: vgacontroller.h:436
Definition: vgacontroller.h:213
Definition: vgacontroller.h:225
int getViewPortWidth()
Determines horizontal size of the viewport.
Definition: vgacontroller.h:682
Definition: vgacontroller.h:219
Definition: vgacontroller.h:228
int getViewPortHeight()
Determines vertical size of the viewport.
Definition: vgacontroller.h:689
uint16_t italic
Definition: vgacontroller.h:289
Color
This enum defines named colors.
Definition: vgacontroller.h:212
Definition: vgacontroller.h:218
int getViewPortRow()
Determines vertical position of the viewport.
Definition: vgacontroller.h:675
void setMouseCursorPos(int X, int Y)
Sets mouse cursor position.
Definition: vgacontroller.cpp:2261
void processPrimitives()
Draws immediately all primitives in the queue.
Definition: vgacontroller.cpp:807
GlyphOptions & Bold(bool value)
Helper method to set or reset bold.
Definition: vgacontroller.h:303
void shrinkScreen(int shrinkX, int shrinkY)
Reduces or expands screen size by the specified horizontal and vertical offset.
Definition: vgacontroller.cpp:600
GlyphOptions & FillBackground(bool value)
Helper method to set or reset fillBackground.
Definition: vgacontroller.h:300
Definition: vgacontroller.h:216
int16_t width
Definition: vgacontroller.h:368
Definition: vgacontroller.h:217
int16_t HSyncPulse
Definition: vgacontroller.h:73
Definition: vgacontroller.h:63
uint8_t NOT
Definition: vgacontroller.h:485
uint16_t invert
Definition: vgacontroller.h:290
uint8_t const * data
Definition: vgacontroller.h:273
uint8_t const * data
Definition: vgacontroller.h:370
GlyphOptions & Invert(uint8_t value)
Helper method to set or reset foreground and background swapping.
Definition: vgacontroller.h:315
uint16_t doubleWidth
Definition: vgacontroller.h:293
int frequency
Definition: vgacontroller.h:70
int getViewPortCol()
Determines horizontal position of the viewport.
Definition: vgacontroller.h:668
void setMouseCursor(Cursor const *cursor)
Sets mouse cursor and make it visible.
Definition: vgacontroller.cpp:2232
Definition: vgacontroller.h:406
void moveScreen(int offsetX, int offsetY)
Moves screen by specified horizontal and vertical offset.
Definition: vgacontroller.cpp:591
Definition: vgacontroller.h:60
Definition: vgacontroller.h:61
void begin()
This is the 64 colors (8 GPIOs) initializer using default pinout.
Definition: vgacontroller.cpp:175
void enableBackgroundPrimitiveExecution(bool value)
Enables or disables drawings inside vertical retracing time.
Definition: vgacontroller.cpp:751
ScreenBlock
Represents one of the four blocks of horizontal or vertical line.
Definition: vgacontroller.h:59
Represents a glyph position, size and binary data.
Definition: vgacontroller.h:268
Definition: vgacontroller.h:409
GlyphOptions & Underline(bool value)
Helper method to set or reset underlined.
Definition: vgacontroller.h:309
Represents the coordinate of a point.
Definition: fabutils.h:125
Represents an image with 64 colors image and transparency.
Definition: vgacontroller.h:367
Definition: vgacontroller.h:224
Definition: vgacontroller.h:220
This file contains some utility classes and functions.
int16_t VSyncPulse
Definition: vgacontroller.h:77
Definition: canvas.cpp:47
CursorName
This enum defines a set of predefined mouse cursors.
Definition: vgacontroller.h:392
Definition: vgacontroller.h:215
uint16_t bold
Definition: vgacontroller.h:287
char VSyncLogic
Definition: vgacontroller.h:80
int16_t hotspotX
Definition: vgacontroller.h:419
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets current resolution using linux-like modeline.
Definition: vgacontroller.cpp:286
int16_t HBackPorch
Definition: vgacontroller.h:74
Represents the VGA controller.
Definition: vgacontroller.h:552
Specifies various glyph painting options.
Definition: vgacontroller.h:284
Represents a rectangle.
Definition: fabutils.h:158
uint8_t getBitsPerChannel()
Gets number of bits allocated for each channel.
Definition: vgacontroller.h:614
ScreenBlock HStartingBlock
Definition: vgacontroller.h:83
GlyphOptions & Italic(bool value)
Helper method to set or reset italic.
Definition: vgacontroller.h:306
Definition: vgacontroller.h:221
Definition: vgacontroller.h:395
void refreshSprites()
Forces the sprites to be updated.
Definition: vgacontroller.cpp:2053
char HSyncLogic
Definition: vgacontroller.h:79
void setSprites(T *sprites, int count)
Sets the list of active sprites.
Definition: vgacontroller.h:788
int16_t X
Definition: vgacontroller.h:269
Definition: vgacontroller.h:396
Definition: vgacontroller.h:398
int16_t HFrontPorch
Definition: vgacontroller.h:72
int16_t VVisibleArea
Definition: vgacontroller.h:75
Definition: vgacontroller.h:411
void removeSprites()
Empties the list of active sprites.
Definition: vgacontroller.h:797
int16_t width
Definition: vgacontroller.h:271
This file contains FabGL library configuration settings, like number of supported colors...
uint8_t scanCount
Definition: vgacontroller.h:81
int16_t VFrontPorch
Definition: vgacontroller.h:76
int getScreenHeight()
Determines the screen height in pixels.
Definition: vgacontroller.h:661
Definition: vgacontroller.h:62
Represents a bidimensional size.
Definition: fabutils.h:143
Definition: vgacontroller.h:407
int getScreenWidth()
Determines the screen width in pixels.
Definition: vgacontroller.h:654
void readScreen(Rect const &rect, RGB *destBuf)
Reads pixels inside the specified rectangle.
Definition: vgacontroller.cpp:1937
Definition: vgacontroller.h:214
GlyphOptions & DoubleWidth(uint8_t value)
Helper method to set or reset doubleWidth.
Definition: vgacontroller.h:312
int16_t Y
Definition: vgacontroller.h:270
Definition: vgacontroller.h:410
Specifies the VGA timings. This is a modeline decoded.
Definition: vgacontroller.h:68
Definition: vgacontroller.h:226
uint16_t fillBackground
Definition: vgacontroller.h:286
uint8_t multiScanBlack
Definition: vgacontroller.h:82
uint8_t B
Definition: vgacontroller.h:242
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
Definition: vgacontroller.cpp:769
uint16_t reduceLuminosity
Definition: vgacontroller.h:288
Definition: vgacontroller.h:227
uint16_t userOpt2
Definition: vgacontroller.h:295
Definition: vgacontroller.h:397
uint8_t G
Definition: vgacontroller.h:241
Definition: vgacontroller.h:405
Definition: vgacontroller.h:223
Definition: vgacontroller.h:399
Definition: vgacontroller.h:408
uint16_t userOpt1
Definition: vgacontroller.h:294
#define FABGLIB_VIEWPORT_MEMORY_POOL_COUNT
Definition: fabglconf.h:111
Definition: vgacontroller.h:402
Definition: vgacontroller.h:403
void writeScreen(Rect const &rect, RGB *srcBuf)
Writes pixels inside the specified rectangle.
Definition: vgacontroller.cpp:1949
uint16_t underline
Definition: vgacontroller.h:292
int16_t VBackPorch
Definition: vgacontroller.h:78
Specifies general paint options.
Definition: vgacontroller.h:483
char label[22]
Definition: vgacontroller.h:69
int16_t HVisibleArea
Definition: vgacontroller.h:71
uint8_t swapFGBG
Definition: vgacontroller.h:484
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
Definition: vgacontroller.cpp:779
Bitmap bitmap
Definition: vgacontroller.h:421
Definition: vgacontroller.h:401
int16_t height
Definition: vgacontroller.h:272
bool dataAllocated
Definition: vgacontroller.h:371
bool isDoubleBuffered()
Determines whether VGAControllerClass is on double buffered mode.
Definition: vgacontroller.h:814
Definition: vgacontroller.h:400
int16_t hotspotY
Definition: vgacontroller.h:420