Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/Arduino_Video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static struct display_buffer_descriptor desc = {
.frame_incomplete = false
};
uint16_t *buffer = nullptr;
static uint8_t *framebuffer_base = nullptr;
#endif

Arduino_Video::Arduino_Video(int width, int height, DisplayShield &shield)
Expand Down Expand Up @@ -117,8 +118,8 @@ int Arduino_Video::begin() {
#endif

display_get_capabilities(display_dev, &display_caps);
_width = display_caps.y_resolution;
_height = display_caps.x_resolution;
_width = _rotated ? display_caps.y_resolution : display_caps.x_resolution;
_height = _rotated ? display_caps.x_resolution : display_caps.y_resolution;

printk("- Capabilities:\n");
printk(" x_resolution = %u, y_resolution = %u\n, supported_pixel_formats = %u\n"
Expand All @@ -127,19 +128,27 @@ int Arduino_Video::begin() {
display_caps.supported_pixel_formats, display_caps.current_pixel_format,
display_caps.current_orientation);

display_blanking_off(display_dev);

void *ptrFB = display_get_framebuffer(display_dev);
if (ptrFB == nullptr) {
printk("Memory display allocation failed!");
while (1) {}
}
// Cast the void pointer to an int pointer to use it
buffer = static_cast<uint16_t *>(ptrFB);
if (framebuffer_base == nullptr) {
framebuffer_base = static_cast<uint8_t *>(ptrFB);
}

display_blanking_on(display_dev);
if (display_caps.current_pixel_format == PIXEL_FORMAT_RGB_565) {
memset(framebuffer_base, 0, CONFIG_STM32_LTDC_FB_NUM * display_caps.x_resolution *
display_caps.y_resolution * sizeof(uint16_t));
}
display_blanking_off(display_dev);

setFrameDesc(width(), height(), width(), (width() * height() * sizeof(uint16_t)));
setFrameDesc(display_caps.x_resolution, display_caps.y_resolution,
display_caps.x_resolution,
display_caps.x_resolution * display_caps.y_resolution * sizeof(uint16_t));
#else
/* Video controller/bridge init */
int err_code = _shield->init(_edidMode);
Expand Down Expand Up @@ -357,6 +366,22 @@ void *Arduino_Video::getFramebuffer() {
}

#if defined(ARDUINO_GIGA) && defined(__ZEPHYR__)
void *Arduino_Video::getDrawBuffer() {
if (framebuffer_base == nullptr || display_caps.current_pixel_format != PIXEL_FORMAT_RGB_565) {
return nullptr;
}

uint8_t *front = static_cast<uint8_t *>(display_get_framebuffer(display_dev));
size_t bytes = display_caps.x_resolution * display_caps.y_resolution * sizeof(uint16_t);
for (int i = 0; i < CONFIG_STM32_LTDC_FB_NUM; i++) {
uint8_t *candidate = framebuffer_base + i * bytes;
if (candidate != front) {
return candidate;
}
}
return front;
}

void Arduino_Video::setFrameDesc(uint16_t w, uint16_t h, uint16_t pitch, uint32_t buf_size) {
desc.buf_size = buf_size;
desc.width = w; /** Number of pixels between consecutive rows in the data buffer */
Expand Down
10 changes: 10 additions & 0 deletions src/Arduino_Video.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ class Arduino_Video
void *getFramebuffer();

#if defined(__ZEPHYR__)
/**
* @brief Get a native RGB565 buffer for drawing, or nullptr if unavailable.
*
* Uses a non-displayed driver buffer when available, otherwise the displayed
* buffer (which may tear). Present it with drawBuffer(0, 0, buf).
* Buffer coordinates are native panel coordinates, without logical rotation.
* The pointer is owned by the driver and must not be freed.
*/
void *getDrawBuffer();

/**
* @brief Set the frame descriptor for the display.
*
Expand Down
Loading