33#include "freertos/FreeRTOS.h"
34#include "freertos/task.h"
37#include "devdrivers/cvbsgenerator.h"
41#pragma GCC optimize ("O2")
47CVBSBaseController::CVBSBaseController()
53void CVBSBaseController::init()
55 CurrentVideoMode::set(VideoMode::CVBS);
56 m_primitiveProcessingSuspended = 1;
58 m_viewPortMemoryPool =
nullptr;
62void CVBSBaseController::begin(gpio_num_t videoGPIO)
65 m_CVBSGenerator.setVideoGPIO(videoGPIO);
69void CVBSBaseController::begin()
75void CVBSBaseController::end()
77 m_CVBSGenerator.stop();
81void CVBSBaseController::freeViewPort()
83 if (m_viewPortMemoryPool) {
84 for (
auto poolPtr = m_viewPortMemoryPool; *poolPtr; ++poolPtr)
85 heap_caps_free((
void*) *poolPtr);
86 heap_caps_free(m_viewPortMemoryPool);
87 m_viewPortMemoryPool =
nullptr;
90 heap_caps_free(m_viewPort);
93 if (isDoubleBuffered())
94 heap_caps_free(m_viewPortVisible);
95 m_viewPortVisible =
nullptr;
102void CVBSBaseController::suspendBackgroundPrimitiveExecution()
104 ++m_primitiveProcessingSuspended;
110void CVBSBaseController::resumeBackgroundPrimitiveExecution()
112 m_primitiveProcessingSuspended = tmax(0, m_primitiveProcessingSuspended - 1);
116void CVBSBaseController::setResolution(
char const * modeline,
int viewPortWidth,
int viewPortHeight,
bool doubleBuffered)
118 auto params = CVBSGenerator::getParamsFromDesc(modeline);
120 setResolution(params, viewPortWidth, viewPortHeight);
124void CVBSBaseController::setResolution(CVBSParams
const * params,
int viewPortWidth,
int viewPortHeight,
bool doubleBuffered)
129 m_CVBSGenerator.setup(params);
131 m_viewPortWidth = viewPortWidth < 0 ? m_CVBSGenerator.visibleSamples() : viewPortWidth;
132 m_viewPortHeight = viewPortHeight < 0 ? m_CVBSGenerator.visibleLines() * m_CVBSGenerator.params()->interlaceFactor : viewPortHeight;
135 m_viewPortWidth /= m_horizontalRate;
138 setScreenSize(m_viewPortWidth, m_viewPortHeight);
140 setDoubleBuffered(doubleBuffered);
155void CVBSBaseController::run()
157 m_CVBSGenerator.run();
163void CVBSBaseController::allocateViewPort(uint32_t allocCaps,
int rowlen)
167 int remainingLines = m_viewPortHeight;
168 m_viewPortHeight = 0;
170 if (isDoubleBuffered())
176 int largestBlock = heap_caps_get_largest_free_block(allocCaps);
180 m_viewPortMemoryPool[poolsCount] = (uint8_t*) heap_caps_malloc(linesCount[poolsCount] * rowlen, allocCaps);
181 if (m_viewPortMemoryPool[poolsCount] ==
nullptr)
183 remainingLines -= linesCount[poolsCount];
184 m_viewPortHeight += linesCount[poolsCount];
187 m_viewPortMemoryPool[poolsCount] =
nullptr;
190 if (isDoubleBuffered()) {
191 m_viewPortHeight /= 2;
192 m_viewPortVisible = (
volatile uint8_t * *) heap_caps_malloc(
sizeof(uint8_t*) * m_viewPortHeight, MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
194 m_viewPort = (
volatile uint8_t * *) heap_caps_malloc(
sizeof(uint8_t*) * m_viewPortHeight, MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
195 if (!isDoubleBuffered())
196 m_viewPortVisible = m_viewPort;
197 for (
int p = 0, l = 0; p < poolsCount; ++p) {
198 uint8_t * pool = m_viewPortMemoryPool[p];
199 for (
int i = 0; i < linesCount[p]; ++i) {
200 if (l + i < m_viewPortHeight)
201 m_viewPort[l + i] = pool;
203 m_viewPortVisible[l + i - m_viewPortHeight] = pool;
211void IRAM_ATTR CVBSBaseController::swapBuffers()
213 tswap(m_viewPort, m_viewPortVisible);
This file contains fabgl::CVBSBaseController definition.
#define FABGLIB_VIEWPORT_MEMORY_POOL_COUNT
#define FABGLIB_MINFREELARGESTBLOCK
This file contains some utility classes and functions.