Update main.c by inserting some instructions to include the needed variables:
/* USER CODE BEGIN PV */
static CAMERA_Drv_t *Camera_Drv = NULL;
uint32_t CAMERA_FRAME_BUFFER[FRAME_BUFFER_SIZE] __attribute__((aligned(16)));
uint32_t xpos = (800 - 480)/2;
uint32_t ypos = (480 - 272) /2;
uint32_t ImageWidth = 480;
uint32_t ImageHeight = 272;
/* USER CODE END PV */
The function prototypes must also be inserted in the adequate space:
/* USER CODE BEGIN PFP */
static uint32_t OV5640_Config(uint32_t Resolution, uint32_t PixelFormat);
/* USER CODE END PFP */
Update main() function by inserting some functions in the adequate space:
- OV5640_Config allows the configuration of the camera module, the DCMI registers, and the DCMI parameters.
- HAL_DCMIPP_PIPE_Start enables DCMIPP capture on Pipe0 by specifying the destination address and the continuous mode.
/* USER CODE BEGIN 2 */
/* Configure OV5640 camera Module */
if(OV5640_Config(OV5640_R480x272, OV5640_RGB565) != OV5640_OK)
{
/* Camera Module Config KO */
Error_Handler();
}
/* Start Camera w/ continuous Mode */
if(HAL_DCMIPP_PIPE_Start(&phdcmipp, DCMIPP_PIPE0, (uint32_t)CAMERA_FRAME_BUFFER , DCMIPP_MODE_CONTINUOUS) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
Insert the implementation of the new functions (called in the main() function), out of the main function, in the adequate space:
static uint32_t OV5640_Config(uint32_t Resolution, uint32_t PixelFormat)
{
OV5640_IO_t IOCtx;
uint32_t id;
uint32_t ret = OV5640_OK;
static OV5640_Object_t OV5640Obj;
/* Configure the Camera driver */
IOCtx.Address = CAMERA_OV5640_ADDRESS;
IOCtx.Init = BSP_I2C1_Init;
IOCtx.DeInit = BSP_I2C1_DeInit;
IOCtx.ReadReg = BSP_I2C1_ReadReg16;
IOCtx.WriteReg = BSP_I2C1_WriteReg16;
IOCtx.GetTick = BSP_GetTick;
/* Register Bus IO */
If(OV5640_RegisterBusIO (&OV5640Obj, &IOCtx) != OV5640_OK)
{
ret = OV5640_ERROR;
}
/* Read ID */
if(OV5640_ReadID(&OV5640Obj, &id) != OV5640_OK)
{
ret = OV5640_ERROR;
}
if(id == OV5640_ID)
{
/* Initialize the camera Module */
Camera_Drv = (CAMERA_Drv_t *) &OV5640_CAMERA_Driver;
OV5640_DeInit(&OV5640Obj);
if(Camera_Drv->Init(&OV5640Obj, Resolution, PixelFormat) != OV5640_OK)
{
ret = OV5640_ERROR;
}
else if(Camera_Drv->MirrorFlipConfig(&OV5640Obj, OV5640_MIRROR_FLIP_NONE) != OV5640_OK)
{
ret = OV5640_ERROR;
}
}
return ret;
}
void HAL_DCMIPP_PIPE_FrameEventCallback(DCMIPP_HandleTypeDef *pHdcmipp, uint32_t Pipe)
{
/* Assert display enable LCD_DISP_EN pin */
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_15, GPIO_PIN_SET);
if(Pipe == DCMIPP_PIPE0)
{
BSP_LED_Toggle(LD1);
}
}
/* USER CODE END 4 */
At this stage, the user can build, debug, and run the project.