Merge pull request #2338 from openmv/hardware_crop_fix

imlib: Fix framebuffer_get_buffer_size().
This commit is contained in:
Ibrahim Abdelkader 2024-07-31 19:25:58 +02:00 committed by GitHub
commit 47489bfa22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 17 additions and 3 deletions

View File

@ -201,6 +201,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_H9_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_H10_DCMI)

View File

@ -198,6 +198,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM3_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK1Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_C6_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_C7_DCMI)

View File

@ -210,6 +210,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_H9_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_H10_DCMI)

View File

@ -71,6 +71,7 @@
#define OMV_CSI_TIM_CHANNEL (TIM_CHANNEL_1)
#define OMV_CSI_TIM_CLK_ENABLE() __TIM1_CLK_ENABLE()
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_RESET_PIN (GPIO_PIN_10)
#define OMV_CSI_RESET_PORT (GPIOA)

View File

@ -125,6 +125,7 @@
#define OMV_CSI_TIM_CLK_ENABLE() __TIM1_CLK_ENABLE()
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_C6_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_C7_DCMI)

View File

@ -124,6 +124,7 @@
#define OMV_CSI_TIM_CLK_ENABLE() __TIM1_CLK_ENABLE()
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_C6_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_C7_DCMI)

View File

@ -202,6 +202,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_C6_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_C7_DCMI)

View File

@ -227,6 +227,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_A9_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_A10_DCMI)

View File

@ -210,6 +210,7 @@
#define OMV_CSI_TIM_CLK_DISABLE() __TIM1_CLK_DISABLE()
#define OMV_CSI_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq()
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_C6_DCMI)
#define OMV_CSI_D1_PIN (&omv_pin_C7_DCMI)

View File

@ -204,6 +204,7 @@
#define OMV_CSI_XCLK_FREQUENCY (12000000)
#define OMV_CSI_DMA_MEMCPY_ENABLE (1)
#define OMV_CSI_HW_SWAP_ENABLE (1)
#define OMV_CSI_HW_CROP_ENABLE (1)
#define OMV_CSI_D0_PIN (&omv_pin_DCMI_D0)
#define OMV_CSI_D1_PIN (&omv_pin_DCMI_D1)

View File

@ -245,15 +245,18 @@ uint32_t framebuffer_get_buffer_size() {
// With only 1 vbuffer it's fine to allow the frame buffer size to change given fb_alloc().
size = framebuffer_raw_buffer_size();
} else {
// Whatever the raw size was when the number of buffers were set is locked in...
// Whatever the raw size was when the number of buffers were set is locked in.
size = framebuffer->raw_buffer_size;
}
// Remove the size of the state header plus alignment padding.
size -= sizeof(vbuffer_t);
// Do we have an estimate on the frame size with multiple buffers? If so, we can reduce the
// RAM each buffer takes up giving some space back to fb_alloc().
#if (OMV_CSI_HW_CROP_ENABLE == 1)
// If the frame size is set, the memory for each buffer can be reduced,
// freeing up space for fb_alloc(). Note that this can only be done if
// the camera interface supports hardware cropping, i.e., the actual
// frame size will match the specified window size.
if ((framebuffer->n_buffers != 1) && framebuffer->u && framebuffer->v) {
// Typically a framebuffer will not need more than u*v*2 bytes.
uint32_t size_guess = framebuffer->u * framebuffer->v * 2;
@ -262,6 +265,7 @@ uint32_t framebuffer_get_buffer_size() {
// Limit the frame buffer size.
size = IM_MIN(size, size_guess);
}
#endif
// Needs to be a multiple of FRAMEBUFFER_ALIGNMENT for DMA transfers...
return FB_ALIGN_SIZE_ROUND_DOWN(size);