STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_dcmi.c 00004 * @author MCD Application Team 00005 * @brief DCMI HAL module driver 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Digital Camera Interface (DCMI) peripheral: 00008 * + Initialization and de-initialization functions 00009 * + IO operation functions 00010 * + Peripheral Control functions 00011 * + Peripheral State and Error functions 00012 * 00013 @verbatim 00014 ============================================================================== 00015 ##### How to use this driver ##### 00016 ============================================================================== 00017 [..] 00018 The sequence below describes how to use this driver to capture image 00019 from a camera module connected to the DCMI Interface. 00020 This sequence does not take into account the configuration of the 00021 camera module, which should be made before to configure and enable 00022 the DCMI to capture images. 00023 00024 (#) Program the required configuration through following parameters: 00025 horizontal and vertical polarity, pixel clock polarity, Capture Rate, 00026 Synchronization Mode, code of the frame delimiter and data width 00027 using HAL_DCMI_Init() function. 00028 00029 (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR 00030 register to the destination memory buffer. 00031 00032 (#) Program the required configuration through following parameters: 00033 DCMI mode, destination memory Buffer address and the data length 00034 and enable capture using HAL_DCMI_Start_DMA() function. 00035 00036 (#) Optionally, configure and Enable the CROP feature to select a rectangular 00037 window from the received image using HAL_DCMI_ConfigCrop() 00038 and HAL_DCMI_EnableCROP() functions 00039 00040 (#) The capture can be stopped using HAL_DCMI_Stop() function. 00041 00042 (#) To control DCMI state you can use the function HAL_DCMI_GetState(). 00043 00044 *** DCMI HAL driver macros list *** 00045 ============================================= 00046 [..] 00047 Below the list of most used macros in DCMI HAL driver. 00048 00049 (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral. 00050 (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral. 00051 (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags. 00052 (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags. 00053 (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts. 00054 (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts. 00055 (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not. 00056 00057 [..] 00058 (@) You can refer to the DCMI HAL driver header file for more useful macros 00059 00060 @endverbatim 00061 ****************************************************************************** 00062 * @attention 00063 * 00064 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00065 * 00066 * Redistribution and use in source and binary forms, with or without modification, 00067 * are permitted provided that the following conditions are met: 00068 * 1. Redistributions of source code must retain the above copyright notice, 00069 * this list of conditions and the following disclaimer. 00070 * 2. Redistributions in binary form must reproduce the above copyright notice, 00071 * this list of conditions and the following disclaimer in the documentation 00072 * and/or other materials provided with the distribution. 00073 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00074 * may be used to endorse or promote products derived from this software 00075 * without specific prior written permission. 00076 * 00077 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00078 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00079 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00080 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00081 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00082 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00083 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00084 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00085 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00086 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00087 * 00088 ****************************************************************************** 00089 */ 00090 00091 /* Includes ------------------------------------------------------------------*/ 00092 #include "stm32f4xx_hal.h" 00093 00094 /** @addtogroup STM32F4xx_HAL_Driver 00095 * @{ 00096 */ 00097 /** @defgroup DCMI DCMI 00098 * @brief DCMI HAL module driver 00099 * @{ 00100 */ 00101 00102 #ifdef HAL_DCMI_MODULE_ENABLED 00103 00104 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\ 00105 defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\ 00106 defined(STM32F479xx) 00107 /* Private typedef -----------------------------------------------------------*/ 00108 /* Private define ------------------------------------------------------------*/ 00109 #define HAL_TIMEOUT_DCMI_STOP 14U /* Set timeout to 1s */ 00110 /* Private macro -------------------------------------------------------------*/ 00111 /* Private variables ---------------------------------------------------------*/ 00112 /* Private function prototypes -----------------------------------------------*/ 00113 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma); 00114 static void DCMI_DMAError(DMA_HandleTypeDef *hdma); 00115 00116 /* Exported functions --------------------------------------------------------*/ 00117 00118 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions 00119 * @{ 00120 */ 00121 00122 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions 00123 * @brief Initialization and Configuration functions 00124 * 00125 @verbatim 00126 =============================================================================== 00127 ##### Initialization and Configuration functions ##### 00128 =============================================================================== 00129 [..] This section provides functions allowing to: 00130 (+) Initialize and configure the DCMI 00131 (+) De-initialize the DCMI 00132 00133 @endverbatim 00134 * @{ 00135 */ 00136 00137 /** 00138 * @brief Initializes the DCMI according to the specified 00139 * parameters in the DCMI_InitTypeDef and create the associated handle. 00140 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00141 * the configuration information for DCMI. 00142 * @retval HAL status 00143 */ 00144 __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi) 00145 { 00146 /* Check the DCMI peripheral state */ 00147 if(hdcmi == NULL) 00148 { 00149 return HAL_ERROR; 00150 } 00151 00152 /* Check function parameters */ 00153 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance)); 00154 assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity)); 00155 assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity)); 00156 assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity)); 00157 assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode)); 00158 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate)); 00159 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode)); 00160 assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode)); 00161 00162 if(hdcmi->State == HAL_DCMI_STATE_RESET) 00163 { 00164 /* Allocate lock resource and initialize it */ 00165 hdcmi->Lock = HAL_UNLOCKED; 00166 /* Init the low level hardware */ 00167 HAL_DCMI_MspInit(hdcmi); 00168 } 00169 00170 /* Change the DCMI state */ 00171 hdcmi->State = HAL_DCMI_STATE_BUSY; 00172 00173 /* Set DCMI parameters */ 00174 /* Configures the HS, VS, DE and PC polarity */ 00175 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | 00176 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | 00177 DCMI_CR_ESS); 00178 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \ 00179 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \ 00180 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \ 00181 hdcmi->Init.JPEGMode); 00182 00183 if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED) 00184 { 00185 hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | 00186 ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)| 00187 ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) | 00188 ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC)); 00189 } 00190 00191 /* Enable the Line, Vsync, Error and Overrun interrupts */ 00192 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR); 00193 00194 /* Update error code */ 00195 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; 00196 00197 /* Initialize the DCMI state*/ 00198 hdcmi->State = HAL_DCMI_STATE_READY; 00199 00200 return HAL_OK; 00201 } 00202 00203 /** 00204 * @brief Deinitializes the DCMI peripheral registers to their default reset 00205 * values. 00206 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00207 * the configuration information for DCMI. 00208 * @retval HAL status 00209 */ 00210 00211 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi) 00212 { 00213 /* DeInit the low level hardware */ 00214 HAL_DCMI_MspDeInit(hdcmi); 00215 00216 /* Update error code */ 00217 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; 00218 00219 /* Initialize the DCMI state*/ 00220 hdcmi->State = HAL_DCMI_STATE_RESET; 00221 00222 /* Release Lock */ 00223 __HAL_UNLOCK(hdcmi); 00224 00225 return HAL_OK; 00226 } 00227 00228 /** 00229 * @brief Initializes the DCMI MSP. 00230 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00231 * the configuration information for DCMI. 00232 * @retval None 00233 */ 00234 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) 00235 { 00236 /* Prevent unused argument(s) compilation warning */ 00237 UNUSED(hdcmi); 00238 /* NOTE : This function Should not be modified, when the callback is needed, 00239 the HAL_DCMI_MspInit could be implemented in the user file 00240 */ 00241 } 00242 00243 /** 00244 * @brief DeInitializes the DCMI MSP. 00245 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00246 * the configuration information for DCMI. 00247 * @retval None 00248 */ 00249 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi) 00250 { 00251 /* Prevent unused argument(s) compilation warning */ 00252 UNUSED(hdcmi); 00253 /* NOTE : This function Should not be modified, when the callback is needed, 00254 the HAL_DCMI_MspDeInit could be implemented in the user file 00255 */ 00256 } 00257 00258 /** 00259 * @} 00260 */ 00261 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions 00262 * @brief IO operation functions 00263 * 00264 @verbatim 00265 =============================================================================== 00266 ##### IO operation functions ##### 00267 =============================================================================== 00268 [..] This section provides functions allowing to: 00269 (+) Configure destination address and data length and 00270 Enables DCMI DMA request and enables DCMI capture 00271 (+) Stop the DCMI capture. 00272 (+) Handles DCMI interrupt request. 00273 00274 @endverbatim 00275 * @{ 00276 */ 00277 00278 /** 00279 * @brief Enables DCMI DMA request and enables DCMI capture 00280 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00281 * the configuration information for DCMI. 00282 * @param DCMI_Mode DCMI capture mode snapshot or continuous grab. 00283 * @param pData The destination memory Buffer address (LCD Frame buffer). 00284 * @param Length The length of capture to be transferred. 00285 * @retval HAL status 00286 */ 00287 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length) 00288 { 00289 /* Initialize the second memory address */ 00290 uint32_t SecondMemAddress = 0U; 00291 00292 /* Check function parameters */ 00293 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode)); 00294 00295 /* Process Locked */ 00296 __HAL_LOCK(hdcmi); 00297 00298 /* Lock the DCMI peripheral state */ 00299 hdcmi->State = HAL_DCMI_STATE_BUSY; 00300 00301 /* Enable DCMI by setting DCMIEN bit */ 00302 __HAL_DCMI_ENABLE(hdcmi); 00303 00304 /* Configure the DCMI Mode */ 00305 hdcmi->Instance->CR &= ~(DCMI_CR_CM); 00306 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode); 00307 00308 /* Set the DMA memory0 conversion complete callback */ 00309 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt; 00310 00311 /* Set the DMA error callback */ 00312 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError; 00313 00314 /* Set the dma abort callback */ 00315 hdcmi->DMA_Handle->XferAbortCallback = NULL; 00316 00317 /* Reset transfer counters value */ 00318 hdcmi->XferCount = 0U; 00319 hdcmi->XferTransferNumber = 0U; 00320 00321 if(Length <= 0xFFFFU) 00322 { 00323 /* Enable the DMA Stream */ 00324 HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length); 00325 } 00326 else /* DCMI_DOUBLE_BUFFER Mode */ 00327 { 00328 /* Set the DMA memory1 conversion complete callback */ 00329 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt; 00330 00331 /* Initialize transfer parameters */ 00332 hdcmi->XferCount = 1U; 00333 hdcmi->XferSize = Length; 00334 hdcmi->pBuffPtr = pData; 00335 00336 /* Get the number of buffer */ 00337 while(hdcmi->XferSize > 0xFFFFU) 00338 { 00339 hdcmi->XferSize = (hdcmi->XferSize/2U); 00340 hdcmi->XferCount = hdcmi->XferCount*2U; 00341 } 00342 00343 /* Update DCMI counter and transfer number*/ 00344 hdcmi->XferCount = (hdcmi->XferCount - 2U); 00345 hdcmi->XferTransferNumber = hdcmi->XferCount; 00346 00347 /* Update second memory address */ 00348 SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize)); 00349 00350 /* Start DMA multi buffer transfer */ 00351 HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize); 00352 } 00353 00354 /* Enable Capture */ 00355 hdcmi->Instance->CR |= DCMI_CR_CAPTURE; 00356 00357 /* Release Lock */ 00358 __HAL_UNLOCK(hdcmi); 00359 00360 /* Return function status */ 00361 return HAL_OK; 00362 } 00363 00364 /** 00365 * @brief Disable DCMI DMA request and Disable DCMI capture 00366 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00367 * the configuration information for DCMI. 00368 * @retval HAL status 00369 */ 00370 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi) 00371 { 00372 __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP; 00373 HAL_StatusTypeDef status = HAL_OK; 00374 00375 /* Process locked */ 00376 __HAL_LOCK(hdcmi); 00377 00378 /* Lock the DCMI peripheral state */ 00379 hdcmi->State = HAL_DCMI_STATE_BUSY; 00380 00381 /* Disable Capture */ 00382 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE); 00383 00384 /* Check if the DCMI capture effectively disabled */ 00385 do 00386 { 00387 if (count-- == 0U) 00388 { 00389 /* Update error code */ 00390 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT; 00391 00392 status = HAL_TIMEOUT; 00393 } 00394 } 00395 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U); 00396 00397 /* Disable the DCMI */ 00398 __HAL_DCMI_DISABLE(hdcmi); 00399 00400 /* Disable the DMA */ 00401 HAL_DMA_Abort(hdcmi->DMA_Handle); 00402 00403 /* Update error code */ 00404 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE; 00405 00406 /* Change DCMI state */ 00407 hdcmi->State = HAL_DCMI_STATE_READY; 00408 00409 /* Process Unlocked */ 00410 __HAL_UNLOCK(hdcmi); 00411 00412 /* Return function status */ 00413 return status; 00414 } 00415 00416 /** 00417 * @brief Suspend DCMI capture 00418 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00419 * the configuration information for DCMI. 00420 * @retval HAL status 00421 */ 00422 HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi) 00423 { 00424 __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP; 00425 HAL_StatusTypeDef status = HAL_OK; 00426 00427 /* Process locked */ 00428 __HAL_LOCK(hdcmi); 00429 00430 if(hdcmi->State == HAL_DCMI_STATE_BUSY) 00431 { 00432 /* Change DCMI state */ 00433 hdcmi->State = HAL_DCMI_STATE_SUSPENDED; 00434 00435 /* Disable Capture */ 00436 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE); 00437 00438 /* Check if the DCMI capture effectively disabled */ 00439 do 00440 { 00441 if (count-- == 0U) 00442 { 00443 /* Update error code */ 00444 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT; 00445 00446 /* Change DCMI state */ 00447 hdcmi->State = HAL_DCMI_STATE_READY; 00448 00449 status = HAL_TIMEOUT; 00450 break; 00451 } 00452 } 00453 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0); 00454 } 00455 /* Process Unlocked */ 00456 __HAL_UNLOCK(hdcmi); 00457 00458 /* Return function status */ 00459 return status; 00460 } 00461 00462 /** 00463 * @brief Resume DCMI capture 00464 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00465 * the configuration information for DCMI. 00466 * @retval HAL status 00467 */ 00468 HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi) 00469 { 00470 /* Process locked */ 00471 __HAL_LOCK(hdcmi); 00472 00473 if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED) 00474 { 00475 /* Change DCMI state */ 00476 hdcmi->State = HAL_DCMI_STATE_BUSY; 00477 00478 /* Disable Capture */ 00479 hdcmi->Instance->CR |= DCMI_CR_CAPTURE; 00480 } 00481 /* Process Unlocked */ 00482 __HAL_UNLOCK(hdcmi); 00483 00484 /* Return function status */ 00485 return HAL_OK; 00486 } 00487 00488 /** 00489 * @brief Handles DCMI interrupt request. 00490 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00491 * the configuration information for the DCMI. 00492 * @retval None 00493 */ 00494 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi) 00495 { 00496 uint32_t isr_value = READ_REG(hdcmi->Instance->MISR); 00497 00498 /* Synchronization error interrupt management *******************************/ 00499 if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI) 00500 { 00501 /* Clear the Synchronization error flag */ 00502 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI); 00503 00504 /* Update error code */ 00505 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC; 00506 00507 /* Change DCMI state */ 00508 hdcmi->State = HAL_DCMI_STATE_ERROR; 00509 00510 /* Set the synchronization error callback */ 00511 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError; 00512 00513 /* Abort the DMA Transfer */ 00514 HAL_DMA_Abort_IT(hdcmi->DMA_Handle); 00515 } 00516 /* Overflow interrupt management ********************************************/ 00517 if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI) 00518 { 00519 /* Clear the Overflow flag */ 00520 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI); 00521 00522 /* Update error code */ 00523 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR; 00524 00525 /* Change DCMI state */ 00526 hdcmi->State = HAL_DCMI_STATE_ERROR; 00527 00528 /* Set the overflow callback */ 00529 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError; 00530 00531 /* Abort the DMA Transfer */ 00532 HAL_DMA_Abort_IT(hdcmi->DMA_Handle); 00533 } 00534 /* Line Interrupt management ************************************************/ 00535 if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI) 00536 { 00537 /* Clear the Line interrupt flag */ 00538 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI); 00539 00540 /* Line interrupt Callback */ 00541 HAL_DCMI_LineEventCallback(hdcmi); 00542 } 00543 /* VSYNC interrupt management ***********************************************/ 00544 if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI) 00545 { 00546 /* Clear the VSYNC flag */ 00547 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI); 00548 00549 /* VSYNC Callback */ 00550 HAL_DCMI_VsyncEventCallback(hdcmi); 00551 } 00552 /* FRAME interrupt management ***********************************************/ 00553 if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI) 00554 { 00555 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */ 00556 if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT) 00557 { 00558 /* Disable the Line, Vsync, Error and Overrun interrupts */ 00559 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR); 00560 } 00561 00562 /* Disable the Frame interrupt */ 00563 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME); 00564 00565 /* Frame Callback */ 00566 HAL_DCMI_FrameEventCallback(hdcmi); 00567 } 00568 } 00569 00570 /** 00571 * @brief Error DCMI callback. 00572 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00573 * the configuration information for DCMI. 00574 * @retval None 00575 */ 00576 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi) 00577 { 00578 /* Prevent unused argument(s) compilation warning */ 00579 UNUSED(hdcmi); 00580 /* NOTE : This function Should not be modified, when the callback is needed, 00581 the HAL_DCMI_ErrorCallback could be implemented in the user file 00582 */ 00583 } 00584 00585 /** 00586 * @brief Line Event callback. 00587 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00588 * the configuration information for DCMI. 00589 * @retval None 00590 */ 00591 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi) 00592 { 00593 /* Prevent unused argument(s) compilation warning */ 00594 UNUSED(hdcmi); 00595 /* NOTE : This function Should not be modified, when the callback is needed, 00596 the HAL_DCMI_LineEventCallback could be implemented in the user file 00597 */ 00598 } 00599 00600 /** 00601 * @brief VSYNC Event callback. 00602 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00603 * the configuration information for DCMI. 00604 * @retval None 00605 */ 00606 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi) 00607 { 00608 /* Prevent unused argument(s) compilation warning */ 00609 UNUSED(hdcmi); 00610 /* NOTE : This function Should not be modified, when the callback is needed, 00611 the HAL_DCMI_VsyncEventCallback could be implemented in the user file 00612 */ 00613 } 00614 00615 /** 00616 * @brief Frame Event callback. 00617 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00618 * the configuration information for DCMI. 00619 * @retval None 00620 */ 00621 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) 00622 { 00623 /* Prevent unused argument(s) compilation warning */ 00624 UNUSED(hdcmi); 00625 /* NOTE : This function Should not be modified, when the callback is needed, 00626 the HAL_DCMI_FrameEventCallback could be implemented in the user file 00627 */ 00628 } 00629 00630 /** 00631 * @} 00632 */ 00633 00634 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions 00635 * @brief Peripheral Control functions 00636 * 00637 @verbatim 00638 =============================================================================== 00639 ##### Peripheral Control functions ##### 00640 =============================================================================== 00641 [..] This section provides functions allowing to: 00642 (+) Configure the CROP feature. 00643 (+) Enable/Disable the CROP feature. 00644 00645 @endverbatim 00646 * @{ 00647 */ 00648 00649 /** 00650 * @brief Configure the DCMI CROP coordinate. 00651 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00652 * the configuration information for DCMI. 00653 * @param X0 DCMI window X offset 00654 * @param Y0 DCMI window Y offset 00655 * @param XSize DCMI Pixel per line 00656 * @param YSize DCMI Line number 00657 * @retval HAL status 00658 */ 00659 HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize) 00660 { 00661 /* Process Locked */ 00662 __HAL_LOCK(hdcmi); 00663 00664 /* Lock the DCMI peripheral state */ 00665 hdcmi->State = HAL_DCMI_STATE_BUSY; 00666 00667 /* Check the parameters */ 00668 assert_param(IS_DCMI_WINDOW_COORDINATE(X0)); 00669 assert_param(IS_DCMI_WINDOW_COORDINATE(YSize)); 00670 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize)); 00671 assert_param(IS_DCMI_WINDOW_HEIGHT(Y0)); 00672 00673 /* Configure CROP */ 00674 hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE)); 00675 hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST)); 00676 00677 /* Initialize the DCMI state*/ 00678 hdcmi->State = HAL_DCMI_STATE_READY; 00679 00680 /* Process Unlocked */ 00681 __HAL_UNLOCK(hdcmi); 00682 00683 return HAL_OK; 00684 } 00685 00686 /** 00687 * @brief Disable the Crop feature. 00688 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00689 * the configuration information for DCMI. 00690 * @retval HAL status 00691 */ 00692 HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi) 00693 { 00694 /* Process Locked */ 00695 __HAL_LOCK(hdcmi); 00696 00697 /* Lock the DCMI peripheral state */ 00698 hdcmi->State = HAL_DCMI_STATE_BUSY; 00699 00700 /* Disable DCMI Crop feature */ 00701 hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP; 00702 00703 /* Change the DCMI state*/ 00704 hdcmi->State = HAL_DCMI_STATE_READY; 00705 00706 /* Process Unlocked */ 00707 __HAL_UNLOCK(hdcmi); 00708 00709 return HAL_OK; 00710 } 00711 00712 /** 00713 * @brief Enable the Crop feature. 00714 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00715 * the configuration information for DCMI. 00716 * @retval HAL status 00717 */ 00718 HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi) 00719 { 00720 /* Process Locked */ 00721 __HAL_LOCK(hdcmi); 00722 00723 /* Lock the DCMI peripheral state */ 00724 hdcmi->State = HAL_DCMI_STATE_BUSY; 00725 00726 /* Enable DCMI Crop feature */ 00727 hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP; 00728 00729 /* Change the DCMI state*/ 00730 hdcmi->State = HAL_DCMI_STATE_READY; 00731 00732 /* Process Unlocked */ 00733 __HAL_UNLOCK(hdcmi); 00734 00735 return HAL_OK; 00736 } 00737 00738 /** 00739 * @} 00740 */ 00741 00742 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions 00743 * @brief Peripheral State functions 00744 * 00745 @verbatim 00746 =============================================================================== 00747 ##### Peripheral State and Errors functions ##### 00748 =============================================================================== 00749 [..] 00750 This subsection provides functions allowing to 00751 (+) Check the DCMI state. 00752 (+) Get the specific DCMI error flag. 00753 00754 @endverbatim 00755 * @{ 00756 */ 00757 00758 /** 00759 * @brief Return the DCMI state 00760 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00761 * the configuration information for DCMI. 00762 * @retval HAL state 00763 */ 00764 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi) 00765 { 00766 return hdcmi->State; 00767 } 00768 00769 /** 00770 * @brief Return the DCMI error code 00771 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 00772 * the configuration information for DCMI. 00773 * @retval DCMI Error Code 00774 */ 00775 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi) 00776 { 00777 return hdcmi->ErrorCode; 00778 } 00779 00780 /** 00781 * @} 00782 */ 00783 00784 /* Private functions ---------------------------------------------------------*/ 00785 /** @defgroup DCMI_Private_Functions DCMI Private Functions 00786 * @{ 00787 */ 00788 00789 /** 00790 * @brief DMA conversion complete callback. 00791 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00792 * the configuration information for the specified DMA module. 00793 * @retval None 00794 */ 00795 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma) 00796 { 00797 uint32_t tmp = 0U; 00798 00799 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; 00800 00801 if(hdcmi->XferCount != 0U) 00802 { 00803 /* Update memory 0 address location */ 00804 tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT); 00805 if(((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U)) 00806 { 00807 tmp = hdcmi->DMA_Handle->Instance->M0AR; 00808 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY0); 00809 hdcmi->XferCount--; 00810 } 00811 /* Update memory 1 address location */ 00812 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U) 00813 { 00814 tmp = hdcmi->DMA_Handle->Instance->M1AR; 00815 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY1); 00816 hdcmi->XferCount--; 00817 } 00818 } 00819 /* Update memory 0 address location */ 00820 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0U) 00821 { 00822 hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr; 00823 } 00824 /* Update memory 1 address location */ 00825 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U) 00826 { 00827 tmp = hdcmi->pBuffPtr; 00828 hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4U*hdcmi->XferSize)); 00829 hdcmi->XferCount = hdcmi->XferTransferNumber; 00830 } 00831 00832 /* Check if the frame is transferred */ 00833 if(hdcmi->XferCount == hdcmi->XferTransferNumber) 00834 { 00835 /* Enable the Frame interrupt */ 00836 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME); 00837 00838 /* When snapshot mode, set dcmi state to ready */ 00839 if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT) 00840 { 00841 hdcmi->State= HAL_DCMI_STATE_READY; 00842 } 00843 } 00844 } 00845 00846 /** 00847 * @brief DMA error callback 00848 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 00849 * the configuration information for the specified DMA module. 00850 * @retval None 00851 */ 00852 static void DCMI_DMAError(DMA_HandleTypeDef *hdma) 00853 { 00854 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; 00855 00856 if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE) 00857 { 00858 /* Initialize the DCMI state*/ 00859 hdcmi->State = HAL_DCMI_STATE_READY; 00860 } 00861 00862 /* DCMI error Callback */ 00863 HAL_DCMI_ErrorCallback(hdcmi); 00864 } 00865 00866 /** 00867 * @} 00868 */ 00869 00870 /** 00871 * @} 00872 */ 00873 #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\ 00874 STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\ 00875 STM32F479xx */ 00876 #endif /* HAL_DCMI_MODULE_ENABLED */ 00877 /** 00878 * @} 00879 */ 00880 00881 /** 00882 * @} 00883 */ 00884 00885 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/