/** * @brief Resumes the Camera capture. * @param None * @retval None */ void BSP_CAMERA_Resume(void) { /* Enable the DCMI */ __HAL_DCMI_ENABLE(&hdcmi_eval); /* Enable the DMA */ __HAL_DMA_ENABLE(hdcmi_eval.DMA_Handle); }
/** * @brief Initializes the DCMI according to the specified * parameters in the DCMI_InitTypeDef and create the associated handle. * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains * the configuration information for DCMI. * @retval HAL status */ HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi) { /* Check the DCMI peripheral state */ if(hdcmi == NULL) { return HAL_ERROR; } /* Check function parameters */ assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance)); assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity)); assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity)); assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity)); assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode)); assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate)); assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode)); assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode)); if(hdcmi->State == HAL_DCMI_STATE_RESET) { /* Init the low level hardware */ HAL_DCMI_MspInit(hdcmi); } /* Change the DCMI state */ hdcmi->State = HAL_DCMI_STATE_BUSY; /* Configures the HS, VS, DE and PC polarity */ hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | DCMI_CR_ESS); hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \ hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \ hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \ hdcmi->Init.JPEGMode); if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED) { DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)| ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) | ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24)); } /* Enable the Line interrupt */ __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE); /* Enable the VSYNC interrupt */ __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC); /* Enable the Frame capture complete interrupt */ __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME); /* Enable the Synchronization error interrupt */ __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR); /* Enable the Overflow interrupt */ __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF); /* Enable DCMI by setting DCMIEN bit */ __HAL_DCMI_ENABLE(hdcmi); /* Update error code */ hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; /* Initialize the DCMI state*/ hdcmi->State = HAL_DCMI_STATE_READY; return HAL_OK; }
/** * @brief Enables DCMI DMA request and enables DCMI capture * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains * the configuration information for DCMI. * @param DCMI_Mode: DCMI capture mode snapshot or continuous grab. * @param pData: The destination memory Buffer address (LCD Frame buffer). * @param Length: The length of capture to be transferred. * @retval HAL status */ HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length) { /* Initialize the second memory address */ uint32_t SecondMemAddress = 0U; /* Check function parameters */ assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode)); /* Process Locked */ __HAL_LOCK(hdcmi); /* Lock the DCMI peripheral state */ hdcmi->State = HAL_DCMI_STATE_BUSY; /* Enable DCMI by setting DCMIEN bit */ __HAL_DCMI_ENABLE(hdcmi); /* Configure the DCMI Mode */ hdcmi->Instance->CR &= ~(DCMI_CR_CM); hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode); /* Set the DMA memory0 conversion complete callback */ hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt; /* Set the DMA error callback */ hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError; /* Set the dma abort callback */ hdcmi->DMA_Handle->XferAbortCallback = NULL; /* Reset transfer counters value */ hdcmi->XferCount = 0; hdcmi->XferTransferNumber = 0; if(Length <= 0xFFFFU) { /* Enable the DMA Stream */ HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length); } else /* DCMI_DOUBLE_BUFFER Mode */ { /* Set the DMA memory1 conversion complete callback */ hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt; /* Initialize transfer parameters */ hdcmi->XferCount = 1U; hdcmi->XferSize = Length; hdcmi->pBuffPtr = pData; /* Get the number of buffer */ while(hdcmi->XferSize > 0xFFFFU) { hdcmi->XferSize = (hdcmi->XferSize/2U); hdcmi->XferCount = hdcmi->XferCount*2U; } /* Update DCMI counter and transfer number*/ hdcmi->XferCount = (hdcmi->XferCount - 2U); hdcmi->XferTransferNumber = hdcmi->XferCount; /* Update second memory address */ SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize)); /* Start DMA multi buffer transfer */ HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize); } /* Enable Capture */ hdcmi->Instance->CR |= DCMI_CR_CAPTURE; /* Release Lock */ __HAL_UNLOCK(hdcmi); /* Return function status */ return HAL_OK; }