42#include "driver/gpio.h"
44#include "freertos/FreeRTOS.h"
45#include "freertos/queue.h"
56#define VGA_GREEN_BIT 2
58#define VGA_HSYNC_BIT 6
59#define VGA_VSYNC_BIT 7
61#define VGA_SYNC_MASK ((1 << VGA_HSYNC_BIT) | (1 << VGA_VSYNC_BIT))
69#define VGA_PIXELINROW(row, X) (row[(X) ^ 2])
72#define VGA_PIXEL(X, Y) VGA_PIXELINROW(m_viewPort[(Y)], X)
73#define VGA_INVERT_PIXEL(X, Y) { auto px = &VGA_PIXEL((X), (Y)); *px = ~(*px ^ VGA_SYNC_MASK); }
81#if FABGLIB_VGAXCONTROLLER_PERFORMANCE_CHECK
82 extern volatile uint64_t s_vgapalctrlcycles;
119class VGABaseController :
public GenericBitmappedDisplayController {
126 VGABaseController(VGABaseController
const&) =
delete;
127 void operator=(VGABaseController
const&) =
delete;
145 void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO);
166 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);
182 static bool convertModelineToTimings(
char const * modeline,
VGATimings * timings);
185 virtual void suspendBackgroundPrimitiveExecution();
188 virtual void resumeBackgroundPrimitiveExecution();
217 void setResolution(
char const * modeline,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
219 virtual void setResolution(
VGATimings const& timings,
int viewPortWidth = -1,
int viewPortHeight = -1,
bool doubleBuffered =
false);
226 int getViewPortCol() {
return m_viewPortCol; }
233 int getViewPortRow() {
return m_viewPortRow; }
248 void moveScreen(
int offsetX,
int offsetY);
264 void shrinkScreen(
int shrinkX,
int shrinkY);
266 VGATimings * getResolutionTimings() {
return &m_timings; }
275 uint8_t getBitsPerChannel() {
return m_bitsPerChannel; }
277 virtual int colorsCount() {
return 1 << (3 * m_bitsPerChannel); }
292 uint8_t * getScanline(
int y) {
return (uint8_t*) m_viewPort[y]; }
306 uint8_t createRawPixel(RGB222 rgb) {
return preparePixel(rgb); }
308 uint8_t createBlankRawPixel() {
return m_HVSync; }
314 static void setupGPIO(gpio_num_t gpio,
int bit, gpio_mode_t mode);
316 void startGPIOStream();
320 virtual void freeViewPort();
324 bool setDMABuffersCount(
int buffersCount);
326 uint8_t packHVSync(
bool HSync,
bool VSync);
328 uint8_t
inline __attribute__((always_inline)) preparePixel(RGB222 rgb) {
return m_HVSync | (rgb.B << VGA_BLUE_BIT) | (rgb.G << VGA_GREEN_BIT) | (rgb.R << VGA_RED_BIT); }
330 uint8_t preparePixelWithSync(RGB222 rgb,
bool HSync,
bool VSync);
332 void fillVertBuffers(
int offsetY);
334 void fillHorizBuffers(
int offsetX);
336 int fill(uint8_t
volatile * buffer,
int startPos,
int length, uint8_t red, uint8_t green, uint8_t blue,
bool hsync,
bool vsync);
338 int calcRequiredDMABuffersCount(
int viewPortHeight);
340 bool isMultiScanBlackLine(
int scan);
342 void setDMABufferBlank(
int index,
void volatile * address,
int length,
int scan,
bool isStartOfVertFrontPorch);
343 void setDMABufferView(
int index,
int row,
int scan,
volatile uint8_t * * viewPort,
bool onVisibleDMA);
344 void setDMABufferView(
int index,
int row,
int scan,
bool isStartOfVertFrontPorch);
346 virtual void onSetupDMABuffer(lldesc_t
volatile * buffer,
bool isStartOfVertFrontPorch,
int scan,
bool isVisible,
int visibleRow) = 0;
348 void volatile * getDMABuffer(
int index,
int * length);
350 void allocateViewPort(uint32_t allocCaps,
int rowlen);
351 virtual void allocateViewPort() = 0;
352 virtual void checkViewPortSize() { };
355 virtual void swapBuffers();
360 volatile uint8_t * * m_viewPort;
361 volatile uint8_t * * m_viewPortVisible;
364 bool m_doubleBufferOverDMA;
366 volatile int m_primitiveProcessingSuspended;
368 intr_handle_t m_isr_handle;
370 VGATimings m_timings;
373 volatile int16_t m_viewPortCol;
374 volatile int16_t m_viewPortRow;
377 volatile uint8_t m_HVSync;
385 int m_bitsPerChannel;
387 GPIOStream m_GPIOStream;
389 lldesc_t
volatile * m_DMABuffers;
390 int m_DMABuffersCount;
394 lldesc_t
volatile * m_DMABuffersHead;
395 lldesc_t
volatile * m_DMABuffersVisible;
399 volatile uint8_t * m_HBlankLine_withVSync;
400 volatile uint8_t * m_HBlankLine;
402 uint8_t * * m_viewPortMemoryPool;
404 int16_t m_rawFrameHeight;
This file contains fabgl::BitmappedDisplayController definition.
This file contains FabGL library configuration settings, like number of supported colors,...
This file contains some utility classes and functions.
VGAScanStart
Represents one of the four blocks of horizontal or vertical line.
VGAScanStart HStartingBlock
Specifies the VGA timings. This is a modeline decoded.
This file contains fabgl::GPIOStream definition.