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 m_primitiveProcessingSuspended = 1;
57 m_viewPortMemoryPool[0] =
nullptr;
61void CVBSBaseController::begin(gpio_num_t videoGPIO)
64 m_CVBSGenerator.setVideoGPIO(videoGPIO);
68void CVBSBaseController::begin()
74void CVBSBaseController::end()
76 m_CVBSGenerator.stop();
80void CVBSBaseController::freeViewPort()
82 for (uint8_t * * poolPtr = m_viewPortMemoryPool; *poolPtr; ++poolPtr) {
83 heap_caps_free((
void*) *poolPtr);
87 heap_caps_free(m_viewPort);
90 if (isDoubleBuffered())
91 heap_caps_free(m_viewPortVisible);
92 m_viewPortVisible =
nullptr;
99void CVBSBaseController::suspendBackgroundPrimitiveExecution()
101 ++m_primitiveProcessingSuspended;
107void CVBSBaseController::resumeBackgroundPrimitiveExecution()
109 m_primitiveProcessingSuspended = tmax(0, m_primitiveProcessingSuspended - 1);
113void CVBSBaseController::setResolution(
char const * modeline,
int viewPortWidth,
int viewPortHeight,
bool doubleBuffered)
115 auto params = CVBSGenerator::getParamsFromDesc(modeline);
117 setResolution(params, viewPortWidth, viewPortHeight);
121void CVBSBaseController::setResolution(CVBSParams
const * params,
int viewPortWidth,
int viewPortHeight,
bool doubleBuffered)
126 m_CVBSGenerator.setup(params);
128 m_viewPortWidth = viewPortWidth < 0 ? m_CVBSGenerator.visibleSamples() : viewPortWidth;
129 m_viewPortHeight = viewPortHeight < 0 ? m_CVBSGenerator.visibleLines() * m_CVBSGenerator.params()->interlaceFactor : viewPortHeight;
132 m_viewPortWidth /= m_horizontalRate;
135 setScreenSize(m_viewPortWidth, m_viewPortHeight);
137 setDoubleBuffered(doubleBuffered);
152void CVBSBaseController::run()
154 m_CVBSGenerator.run();
160void CVBSBaseController::allocateViewPort(uint32_t allocCaps,
int rowlen)
164 int remainingLines = m_viewPortHeight;
165 m_viewPortHeight = 0;
167 if (isDoubleBuffered())
172 int largestBlock = heap_caps_get_largest_free_block(allocCaps);
173 linesCount[poolsCount] = tmin(remainingLines, largestBlock / rowlen);
174 if (linesCount[poolsCount] == 0)
176 m_viewPortMemoryPool[poolsCount] = (uint8_t*) heap_caps_malloc(linesCount[poolsCount] * rowlen, allocCaps);
177 remainingLines -= linesCount[poolsCount];
178 m_viewPortHeight += linesCount[poolsCount];
181 m_viewPortMemoryPool[poolsCount] =
nullptr;
184 if (isDoubleBuffered()) {
185 m_viewPortHeight /= 2;
186 m_viewPortVisible = (
volatile uint8_t * *) heap_caps_malloc(
sizeof(uint8_t*) * m_viewPortHeight, MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
188 m_viewPort = (
volatile uint8_t * *) heap_caps_malloc(
sizeof(uint8_t*) * m_viewPortHeight, MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL);
189 if (!isDoubleBuffered())
190 m_viewPortVisible = m_viewPort;
191 for (
int p = 0, l = 0; p < poolsCount; ++p) {
192 uint8_t * pool = m_viewPortMemoryPool[p];
193 for (
int i = 0; i < linesCount[p]; ++i) {
194 if (l + i < m_viewPortHeight)
195 m_viewPort[l + i] = pool;
197 m_viewPortVisible[l + i - m_viewPortHeight] = pool;
205void IRAM_ATTR CVBSBaseController::swapBuffers()
207 tswap(m_viewPort, m_viewPortVisible);
This file contains fabgl::CVBSBaseController definition.
#define FABGLIB_VIEWPORT_MEMORY_POOL_COUNT
This file contains some utility classes and functions.