common: Use the new framebuffer API.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-07-15 21:05:08 +02:00
parent 9030b4b8dd
commit af711cfc90
3 changed files with 24 additions and 18 deletions

View File

@ -65,7 +65,7 @@ void fb_alloc_init0() {
uint32_t fb_avail() { uint32_t fb_avail() {
framebuffer_t *fb = framebuffer_get(0); framebuffer_t *fb = framebuffer_get(0);
uint32_t temp = pointer - framebuffer_get_buffers_end(fb) - sizeof(uint32_t); uint32_t temp = pointer - framebuffer_pool_end(fb) - sizeof(uint32_t);
return (temp < sizeof(uint32_t)) ? 0 : temp; return (temp < sizeof(uint32_t)) ? 0 : temp;
} }
@ -74,7 +74,7 @@ void fb_alloc_mark() {
char *new_pointer = pointer - sizeof(uint32_t); char *new_pointer = pointer - sizeof(uint32_t);
// Check if allocation overwrites the framebuffer pixels // Check if allocation overwrites the framebuffer pixels
if (new_pointer < framebuffer_get_buffers_end(fb)) { if (new_pointer < framebuffer_pool_end(fb)) {
nlr_jump(MP_OBJ_TO_PTR(mp_obj_new_exception_msg(&mp_type_MemoryError, nlr_jump(MP_OBJ_TO_PTR(mp_obj_new_exception_msg(&mp_type_MemoryError,
MP_ERROR_TEXT("Out of fast frame buffer stack memory")))); MP_ERROR_TEXT("Out of fast frame buffer stack memory"))));
} }
@ -154,7 +154,7 @@ void *fb_alloc(uint32_t size, int hints) {
char *new_pointer = result - sizeof(uint32_t); char *new_pointer = result - sizeof(uint32_t);
// Check if allocation overwrites the framebuffer pixels // Check if allocation overwrites the framebuffer pixels
if (new_pointer < framebuffer_get_buffers_end(fb)) { if (new_pointer < framebuffer_pool_end(fb)) {
fb_alloc_fail(); fb_alloc_fail();
} }
@ -199,7 +199,7 @@ void *fb_alloc0(uint32_t size, int hints) {
void *fb_alloc_all(uint32_t *size, int hints) { void *fb_alloc_all(uint32_t *size, int hints) {
framebuffer_t *fb = framebuffer_get(0); framebuffer_t *fb = framebuffer_get(0);
uint32_t temp = pointer - framebuffer_get_buffers_end(fb) - sizeof(uint32_t); uint32_t temp = pointer - framebuffer_pool_end(fb) - sizeof(uint32_t);
if (temp < sizeof(uint32_t)) { if (temp < sizeof(uint32_t)) {
*size = 0; *size = 0;

View File

@ -260,12 +260,8 @@ __weak int omv_csi_abort(omv_csi_t *csi, bool fifo_flush, bool in_irq) {
csi->last_frame_ms = 0; csi->last_frame_ms = 0;
csi->last_frame_ms_valid = false; csi->last_frame_ms_valid = false;
if (csi->fb) { if (csi->fb && fifo_flush && !csi->disable_full_flush) {
if (fifo_flush) { framebuffer_flush(csi->fb);
framebuffer_flush_buffers(csi->fb, true);
} else if (!csi->disable_full_flush) {
framebuffer_flush_buffers(csi->fb, false);
}
} }
#if defined(OMV_CSI_FSYNC_PIN) #if defined(OMV_CSI_FSYNC_PIN)
@ -353,7 +349,7 @@ __weak int omv_csi_reset(omv_csi_t *csi, bool hard) {
} }
// Reset framebuffers // Reset framebuffers
framebuffer_flush_buffers(csi->fb, true); framebuffer_flush(csi->fb);
return 0; return 0;
} }
@ -774,7 +770,7 @@ __weak int omv_csi_set_pixformat(omv_csi_t *csi, pixformat_t pixformat) {
csi->fb->pixfmt = PIXFORMAT_INVALID; csi->fb->pixfmt = PIXFORMAT_INVALID;
// Auto-adjust the number of frame buffers. // Auto-adjust the number of frame buffers.
omv_csi_set_framebuffers(csi, -1); omv_csi_set_framebuffers(csi, -1, false);
// Reconfigure the hardware if needed. // Reconfigure the hardware if needed.
return omv_csi_config(csi, OMV_CSI_CONFIG_PIXFORMAT); return omv_csi_config(csi, OMV_CSI_CONFIG_PIXFORMAT);
@ -818,7 +814,7 @@ __weak int omv_csi_set_framesize(omv_csi_t *csi, omv_csi_framesize_t framesize)
csi->fb->pixfmt = PIXFORMAT_INVALID; csi->fb->pixfmt = PIXFORMAT_INVALID;
// Auto-adjust the number of frame buffers. // Auto-adjust the number of frame buffers.
omv_csi_set_framebuffers(csi, -1); omv_csi_set_framebuffers(csi, -1, false);
// Reconfigure the hardware if needed. // Reconfigure the hardware if needed.
return omv_csi_config(csi, OMV_CSI_CONFIG_FRAMESIZE); return omv_csi_config(csi, OMV_CSI_CONFIG_FRAMESIZE);
@ -932,7 +928,7 @@ __weak int omv_csi_set_windowing(omv_csi_t *csi, int x, int y, int w, int h) {
csi->fb->pixfmt = PIXFORMAT_INVALID; csi->fb->pixfmt = PIXFORMAT_INVALID;
// Auto-adjust the number of frame buffers. // Auto-adjust the number of frame buffers.
omv_csi_set_framebuffers(csi, -1); omv_csi_set_framebuffers(csi, -1, false);
// Reconfigure the hardware if needed. // Reconfigure the hardware if needed.
return omv_csi_config(csi, OMV_CSI_CONFIG_WINDOWING); return omv_csi_config(csi, OMV_CSI_CONFIG_WINDOWING);
@ -1256,7 +1252,7 @@ __weak bool omv_csi_get_auto_rotation(omv_csi_t *csi) {
return csi->auto_rotation; return csi->auto_rotation;
} }
__weak int omv_csi_set_framebuffers(omv_csi_t *csi, int count) { __weak int omv_csi_set_framebuffers(omv_csi_t *csi, size_t count, bool expand) {
// Disable any ongoing frame capture. // Disable any ongoing frame capture.
omv_csi_abort(csi, true, false); omv_csi_abort(csi, true, false);
@ -1275,7 +1271,17 @@ __weak int omv_csi_set_framebuffers(omv_csi_t *csi, int count) {
// Otherwise, use the real frame size. // Otherwise, use the real frame size.
csi->fb->frame_size = resolution[csi->framesize][0] * resolution[csi->framesize][1] * 2; csi->fb->frame_size = resolution[csi->framesize][0] * resolution[csi->framesize][1] * 2;
#endif #endif
return framebuffer_set_buffers(csi->fb, count);
if (count == -1) {
for (size_t i=3; i>0; i--) {
if (!framebuffer_resize(csi->fb, i, expand)) {
return 0;
}
}
return -1;
}
return framebuffer_resize(csi->fb, count, expand);
} }
__weak int omv_csi_set_special_effect(omv_csi_t *csi, omv_csi_sde_t sde) { __weak int omv_csi_set_special_effect(omv_csi_t *csi, omv_csi_sde_t sde) {
@ -1443,7 +1449,7 @@ __weak int omv_csi_auto_crop_framebuffer(omv_csi_t *csi) {
} }
// Auto-adjust the number of frame buffers. // Auto-adjust the number of frame buffers.
omv_csi_set_framebuffers(csi, -1); omv_csi_set_framebuffers(csi, -1, false);
return 0; return 0;
} }

View File

@ -550,7 +550,7 @@ int omv_csi_set_auto_rotation(omv_csi_t *csi, bool enable);
bool omv_csi_get_auto_rotation(omv_csi_t *csi); bool omv_csi_get_auto_rotation(omv_csi_t *csi);
// Set the number of virtual frame buffers. // Set the number of virtual frame buffers.
int omv_csi_set_framebuffers(omv_csi_t *csi, int count); int omv_csi_set_framebuffers(omv_csi_t *csi, size_t count, bool expand);
// Drop the next frame to match the current frame rate. // Drop the next frame to match the current frame rate.
void omv_csi_throttle_framerate(omv_csi_t *csi); void omv_csi_throttle_framerate(omv_csi_t *csi);