33#include "freertos/FreeRTOS.h"
34#include "freertos/task.h"
36#include "soc/i2s_struct.h"
37#include "soc/i2s_reg.h"
38#include "driver/periph_ctrl.h"
40#include "esp_spi_flash.h"
41#include "esp_heap_caps.h"
49#pragma GCC optimize ("O2")
62VGADirectController * VGADirectController::s_instance =
nullptr;
63volatile int VGADirectController::s_scanLine;
64lldesc_t
volatile * VGADirectController::s_frameResetDesc;
65bool VGADirectController::s_VSync;
66lldesc_t
volatile * * VGADirectController::s_DMALines =
nullptr;
73 m_drawScanlineCallback(nullptr),
80void VGADirectController::init()
82 VGABaseController::init();
83 m_doubleBufferOverDMA =
false;
87void VGADirectController::allocateViewPort()
89 m_lines = (uint8_t**) heap_caps_malloc(
sizeof(uint8_t*) * m_linesCount, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
90 m_lines[0] = (uint8_t*) heap_caps_malloc(m_viewPortWidth * m_linesCount, MALLOC_CAP_DMA);
91 for (
int i = 1; i < m_linesCount; ++i)
92 m_lines[i] = m_lines[0] + i * m_viewPortWidth;
93 s_DMALines =
new lldesc_t
volatile *[m_viewPortHeight];
97void VGADirectController::freeViewPort()
99 VGABaseController::freeViewPort();
101 heap_caps_free((
void*)m_lines[0]);
102 heap_caps_free((
void*)m_lines);
108void VGADirectController::setResolution(VGATimings
const& timings,
int viewPortWidth,
int viewPortHeight,
bool doubleBuffered)
111 if (!m_drawScanlineCallback)
114 VGABaseController::setResolution(timings, viewPortWidth, viewPortHeight, doubleBuffered);
129 if (m_isr_handle ==
nullptr) {
132 I2S1.int_clr.val = 0xFFFFFFFF;
133 I2S1.int_ena.out_eof = 1;
138void VGADirectController::onSetupDMABuffer(lldesc_t
volatile * buffer,
bool isStartOfVertFrontPorch,
int scan,
bool isVisible,
int visibleRow)
141 s_DMALines[visibleRow] = buffer;
143 buffer->buf = (uint8_t *) m_lines[visibleRow % m_linesCount];
146 if ((scan == 0 && (visibleRow % (m_linesCount / 2)) == 0)) {
148 s_frameResetDesc = buffer;
157 s_DMALines[scanline]->buf = lineBuffer;
163 return s_DMALines[scanline]->buf;
169 return m_lines[scanline % m_linesCount];
173void VGADirectController::setPixelAt(PixelDesc
const & pixelDesc,
Rect & updateRect)
178void VGADirectController::absDrawLine(
int X1,
int Y1,
int X2,
int Y2, RGB888 color)
183void VGADirectController::rawFillRow(
int y,
int x1,
int x2, RGB888 color)
188void VGADirectController::rawFillRow(
int y,
int x1,
int x2, uint8_t colorIndex)
193void VGADirectController::rawInvertRow(
int y,
int x1,
int x2)
198void VGADirectController::rawCopyRow(
int x1,
int x2,
int srcY,
int dstY)
203void VGADirectController::swapRows(
int yA,
int yB,
int x1,
int x2)
208void VGADirectController::drawEllipse(Size
const & size, Rect & updateRect)
213void VGADirectController::clear(Rect & updateRect)
218void VGADirectController::VScroll(
int scroll, Rect & updateRect)
223void VGADirectController::HScroll(
int scroll, Rect & updateRect)
228void VGADirectController::drawGlyph(Glyph
const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect)
233void VGADirectController::invertRect(Rect
const & rect, Rect & updateRect)
238void VGADirectController::swapFGBG(Rect
const & rect, Rect & updateRect)
243void VGADirectController::copyRect(Rect
const & source, Rect & updateRect)
248void VGADirectController::readScreen(Rect
const & rect, RGB888 * destBuf)
253void VGADirectController::rawDrawBitmap_Native(
int destX,
int destY, Bitmap
const * bitmap,
int X1,
int Y1,
int XCount,
int YCount)
258void VGADirectController::rawDrawBitmap_Mask(
int destX,
int destY, Bitmap
const * bitmap,
void * saveBackground,
int X1,
int Y1,
int XCount,
int YCount)
263void VGADirectController::rawDrawBitmap_RGBA2222(
int destX,
int destY, Bitmap
const * bitmap,
void * saveBackground,
int X1,
int Y1,
int XCount,
int YCount)
268void VGADirectController::rawDrawBitmap_RGBA8888(
int destX,
int destY, Bitmap
const * bitmap,
void * saveBackground,
int X1,
int Y1,
int XCount,
int YCount)
273void IRAM_ATTR VGADirectController::ISRHandler(
void * arg)
275 #if FABGLIB_VGAXCONTROLLER_PERFORMANCE_CHECK
276 auto s1 = getCycleCount();
279 if (I2S1.int_st.out_eof) {
283 auto viewPortHeight = ctrl->m_viewPortHeight;
285 auto desc = (
volatile lldesc_t*) I2S1.out_eof_des_addr;
287 if (desc == s_frameResetDesc) {
292 int linesCount = ctrl->m_linesCount;
293 int scanLine = (s_scanLine + linesCount / 2) % viewPortHeight;
295 const auto lineIndex = scanLine & (linesCount - 1);
297 ctrl->m_drawScanlineCallback(ctrl->m_drawScanlineArg, (uint8_t*)(ctrl->m_lines[lineIndex]), scanLine);
299 s_scanLine += linesCount / 2;
301 if (s_scanLine >= viewPortHeight)
306 #if FABGLIB_VGAXCONTROLLER_PERFORMANCE_CHECK
307 s_vgapalctrlcycles += getCycleCount() - s1;
310 I2S1.int_clr.val = I2S1.int_st.val;
void run()
Begins to call the callback function and to display video frames.
void setScanlineBuffer(int scanline, uint8_t volatile *lineBuffer)
Sets a scanline buffer.
uint8_t volatile * getDefaultScanlineBuffer(int scanline)
Gets default scanline buffer.
VGADirectController(bool autoRun=true)
Initializes a new instance of VGADirectController.
uint8_t volatile * getScanlineBuffer(int scanline)
Gets current scanline buffer.
#define FABGLIB_VIDEO_CPUINTENSIVE_TASKS_CORE
This file contains some utility classes and functions.
This file contains fabgl::GPIOStream definition.
This file contains fabgl::VGADirectController definition.