mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
common: Update framebuffer API.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
parent
fbc8d14cda
commit
b1f81f7cdd
@ -64,13 +64,13 @@ void fb_alloc_init0() {
|
||||
}
|
||||
|
||||
uint32_t fb_avail() {
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
uint32_t temp = pointer - framebuffer_pool_end(fb) - sizeof(uint32_t);
|
||||
return (temp < sizeof(uint32_t)) ? 0 : temp;
|
||||
}
|
||||
|
||||
void fb_alloc_mark() {
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
char *new_pointer = pointer - sizeof(uint32_t);
|
||||
|
||||
// Check if allocation overwrites the framebuffer pixels
|
||||
@ -137,7 +137,7 @@ void fb_alloc_free_till_mark_past_mark_permanent() {
|
||||
|
||||
// returns null pointer without error if size==0
|
||||
void *fb_alloc(uint32_t size, int hints) {
|
||||
framebuffer_t *fb = framebuffer_get(0);
|
||||
framebuffer_t *fb = framebuffer_get(FB_MAINFB_ID);
|
||||
|
||||
if (!size) {
|
||||
return NULL;
|
||||
@ -198,7 +198,7 @@ void *fb_alloc0(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(FB_MAINFB_ID);
|
||||
uint32_t temp = pointer - framebuffer_pool_end(fb) - sizeof(uint32_t);
|
||||
|
||||
if (temp < sizeof(uint32_t)) {
|
||||
|
@ -185,7 +185,7 @@ __weak int omv_csi_init() {
|
||||
memset(csi, 0, sizeof(omv_csi_t));
|
||||
csi->i2c = &csi_i2c;
|
||||
csi->clk = &csi_clk;
|
||||
csi->fb = framebuffer_get(-1);
|
||||
csi->fb = framebuffer_get(FB_MAINFB_ID);
|
||||
csi->color_palette = rainbow_table;
|
||||
memcpy(csi->resolution, csi_resolution, sizeof(csi_resolution));
|
||||
omv_csi_ops_init(csi);
|
||||
@ -223,7 +223,7 @@ __weak int omv_csi_init() {
|
||||
}
|
||||
|
||||
// Clear fb_enabled flag.
|
||||
JPEG_FB()->enabled = 0;
|
||||
framebuffer_set_enabled(framebuffer_get(FB_STREAM_ID), false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1282,24 +1282,25 @@ __weak int omv_csi_set_framebuffers(omv_csi_t *csi, size_t count, bool expand) {
|
||||
return OMV_CSI_ERROR_INVALID_FRAMESIZE;
|
||||
}
|
||||
|
||||
// TODO pass this to resize.
|
||||
#if OMV_CSI_HW_CROP_ENABLE
|
||||
// If hardware cropping is supported, use window size.
|
||||
csi->fb->frame_size = csi->fb->u * csi->fb->v * 2;
|
||||
size_t frame_size = csi->fb->u * csi->fb->v * 2;
|
||||
#else
|
||||
// Otherwise, use the real frame size.
|
||||
csi->fb->frame_size = csi->resolution[csi->framesize][0] * csi->resolution[csi->framesize][1] * 2;
|
||||
size_t frame_size = csi->resolution[csi->framesize][0] * csi->resolution[csi->framesize][1] * 2;
|
||||
#endif
|
||||
|
||||
if (count == -1) {
|
||||
for (size_t i=3; i>0; i--) {
|
||||
if (!framebuffer_resize(csi->fb, i, expand)) {
|
||||
if (!framebuffer_resize(csi->fb, i, frame_size, expand)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return framebuffer_resize(csi->fb, count, expand);
|
||||
return framebuffer_resize(csi->fb, count, frame_size, expand);
|
||||
}
|
||||
|
||||
__weak int omv_csi_set_special_effect(omv_csi_t *csi, omv_csi_sde_t sde) {
|
||||
@ -1583,8 +1584,8 @@ __weak int omv_csi_snapshot(omv_csi_t *csi, image_t *image, uint32_t flags) {
|
||||
if (buffer && (buffer->flags & VB_FLAG_USED)) {
|
||||
if (flags & OMV_CSI_FLAG_UPDATE_FB) {
|
||||
image_t tmp;
|
||||
framebuffer_init_image(csi->fb, &tmp);
|
||||
framebuffer_update_jpeg_buffer(&tmp);
|
||||
framebuffer_to_image(csi->fb, &tmp);
|
||||
framebuffer_update_preview(&tmp);
|
||||
}
|
||||
|
||||
// Release the previous buffer from used queue -> free queue.
|
||||
|
@ -168,16 +168,17 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
||||
// Return 0 if FB is locked or not ready.
|
||||
uint32_t buffer[3] = { 0 };
|
||||
// Try to lock FB. If header size == 0 frame is not ready
|
||||
if (mutex_try_lock(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
|
||||
framebuffer_t *fb = framebuffer_get(FB_STREAM_ID);
|
||||
if (mutex_try_lock(&fb->lock, MUTEX_TID_IDE)) {
|
||||
// If header size == 0 frame is not ready
|
||||
if (JPEG_FB()->size == 0) {
|
||||
if (fb->size == 0) {
|
||||
// unlock FB
|
||||
mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE);
|
||||
mutex_unlock(&fb->lock, MUTEX_TID_IDE);
|
||||
} else {
|
||||
// Return header w, h and size/bpp
|
||||
buffer[0] = JPEG_FB()->w;
|
||||
buffer[1] = JPEG_FB()->h;
|
||||
buffer[2] = JPEG_FB()->size;
|
||||
buffer[0] = fb->w;
|
||||
buffer[1] = fb->h;
|
||||
buffer[2] = fb->size;
|
||||
}
|
||||
}
|
||||
cmd = USBDBG_NONE;
|
||||
@ -187,12 +188,13 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
||||
|
||||
case USBDBG_FRAME_DUMP:
|
||||
if (xfer_offs < xfer_size) {
|
||||
write_callback(JPEG_FB()->pixels + xfer_offs, size);
|
||||
framebuffer_t *fb = framebuffer_get(FB_STREAM_ID);
|
||||
write_callback(fb->raw_base + xfer_offs, size);
|
||||
xfer_offs += size;
|
||||
if (xfer_offs == xfer_size) {
|
||||
cmd = USBDBG_NONE;
|
||||
JPEG_FB()->w = 0; JPEG_FB()->h = 0; JPEG_FB()->size = 0;
|
||||
mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE);
|
||||
fb->w = 0; fb->h = 0; fb->size = 0;
|
||||
mutex_unlock(&fb->lock, MUTEX_TID_IDE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -251,20 +253,21 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
||||
#endif // OMV_PROFILER_ENABLE
|
||||
|
||||
// Limit the frames sent over USB to 20Hz.
|
||||
framebuffer_t *fb = framebuffer_get(FB_STREAM_ID);
|
||||
if (check_timeout_ms(last_update_ms, 50) &&
|
||||
mutex_try_lock_fair(&JPEG_FB()->lock, MUTEX_TID_IDE)) {
|
||||
mutex_try_lock_fair(&fb->lock, MUTEX_TID_IDE)) {
|
||||
// If header size == 0 frame is not ready
|
||||
if (JPEG_FB()->size == 0) {
|
||||
if (fb->size == 0) {
|
||||
// unlock FB
|
||||
mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE);
|
||||
mutex_unlock(&fb->lock, MUTEX_TID_IDE);
|
||||
} else {
|
||||
// Set valid frame flag.
|
||||
buffer[0] |= USBDBG_FLAG_FRAMEBUF_LOCKED;
|
||||
|
||||
// Set frame width, height and size/bpp
|
||||
buffer[1] = JPEG_FB()->w;
|
||||
buffer[2] = JPEG_FB()->h;
|
||||
buffer[3] = JPEG_FB()->size;
|
||||
buffer[1] = fb->w;
|
||||
buffer[2] = fb->h;
|
||||
buffer[3] = fb->size;
|
||||
last_update_ms = mp_hal_ticks_ms();
|
||||
}
|
||||
}
|
||||
@ -320,11 +323,14 @@ void usbdbg_data_in(uint32_t size, usbdbg_write_callback_t write_callback) {
|
||||
void usbdbg_data_out(uint32_t size, usbdbg_read_callback_t read_callback) {
|
||||
switch (cmd) {
|
||||
case USBDBG_FB_ENABLE: {
|
||||
read_callback(&(JPEG_FB()->enabled), 4);
|
||||
if (JPEG_FB()->enabled == 0) {
|
||||
uint32_t enabled = 0;
|
||||
framebuffer_t *fb = framebuffer_get(FB_STREAM_ID);
|
||||
read_callback(&enabled, 4);
|
||||
framebuffer_set_enabled(fb, enabled);
|
||||
if (fb->enabled == 0) {
|
||||
// When disabling framebuffer, the IDE might still be holding FB lock.
|
||||
// If the IDE is not the current lock owner, this operation is ignored.
|
||||
mutex_unlock(&JPEG_FB()->lock, MUTEX_TID_IDE);
|
||||
mutex_unlock(&fb->lock, MUTEX_TID_IDE);
|
||||
}
|
||||
cmd = USBDBG_NONE;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user