![]() |
|
|||
File indexing completed on 2025-05-11 08:23:07
0001 /** 0002 ****************************************************************************** 0003 * @file stm32h7xx_hal_dcmi.c 0004 * @author MCD Application Team 0005 * @brief DCMI HAL module driver 0006 * This file provides firmware functions to manage the following 0007 * functionalities of the Digital Camera Interface (DCMI) peripheral: 0008 * + Initialization and de-initialization functions 0009 * + IO operation functions 0010 * + Peripheral Control functions 0011 * + Peripheral State and Error functions 0012 * 0013 ****************************************************************************** 0014 * @attention 0015 * 0016 * Copyright (c) 2017 STMicroelectronics. 0017 * All rights reserved. 0018 * 0019 * This software is licensed under terms that can be found in the LICENSE file 0020 * in the root directory of this software component. 0021 * If no LICENSE file comes with this software, it is provided AS-IS. 0022 * 0023 ****************************************************************************** 0024 @verbatim 0025 ============================================================================== 0026 ##### How to use this driver ##### 0027 ============================================================================== 0028 [..] 0029 The sequence below describes how to use this driver to capture image 0030 from a camera module connected to the DCMI Interface. 0031 This sequence does not take into account the configuration of the 0032 camera module, which should be made before to configure and enable 0033 the DCMI to capture images. 0034 0035 (#) Program the required configuration through following parameters: 0036 horizontal and vertical polarity, pixel clock polarity, Capture Rate, 0037 Synchronization Mode, code of the frame delimiter and data width 0038 using HAL_DCMI_Init() function. 0039 0040 (#) Configure the selected DMA stream to transfer Data from DCMI DR 0041 register to the destination memory buffer. 0042 0043 (#) Program the required configuration through following parameters: 0044 DCMI mode, destination memory Buffer address and the data length 0045 and enable capture using HAL_DCMI_Start_DMA() function. 0046 0047 (#) Optionally, configure and Enable the CROP feature to select a rectangular 0048 window from the received image using HAL_DCMI_ConfigCrop() 0049 and HAL_DCMI_EnableCrop() functions 0050 0051 (#) The capture can be stopped using HAL_DCMI_Stop() function. 0052 0053 (#) To control DCMI state you can use the function HAL_DCMI_GetState(). 0054 0055 *** Callback registration *** 0056 ============================================= 0057 0058 The compilation flag USE_HAL_DCMI_REGISTER_CALLBACKS when set to 1 0059 allows the user to configure dynamically the driver callbacks. 0060 Use Functions HAL_DCMI_RegisterCallback() to register an interrupt callback. 0061 0062 Function HAL_DCMI_RegisterCallback() allows to register following callbacks: 0063 (+) LineEventCallback : callback for DCMI line event. 0064 (+) FrameEventCallback : callback for DCMI Frame event. 0065 (+) VsyncEventCallback : callback for DCMI Vsync event. 0066 (+) ErrorCallback : callback for error detection. 0067 (+) MspInitCallback : callback for Msp Init. 0068 (+) MspDeInitCallback : callback for Msp DeInit. 0069 This function takes as parameters the HAL peripheral handle, the Callback ID 0070 and a pointer to the user callback function. 0071 0072 Use function HAL_DCMI_UnRegisterCallback to reset a callback to the default weak function. 0073 HAL_DCMI_UnRegisterCallback takes as parameters the HAL peripheral handle and the Callback ID. 0074 This function allows to reset following callbacks: 0075 (+) LineEventCallback : callback for DCMI line event. 0076 (+) FrameEventCallback : callback for DCMI Frame event. 0077 (+) VsyncEventCallback : callback for DCMI Vsync event. 0078 (+) ErrorCallback : callback for error detection. 0079 (+) MspInitCallback : callback for Msp Init. 0080 (+) MspDeInitCallback : callback for Msp DeInit. 0081 0082 By default, after the HAL_DCMI_Init() and when the state is HAL_DCMI_STATE_RESET 0083 all callbacks are set to the corresponding weak functions: 0084 examples HAL_DCMI_LineEventCallback(), HAL_DCMI_FrameEventCallback(). 0085 Exception done for MspInit and MspDeInit functions that are 0086 reset to the legacy weak functions in the HAL_DCMI_Init()/ HAL_DCMI_DeInit() only when 0087 these callbacks are null (not registered beforehand). 0088 If MspInit or MspDeInit are not null, the HAL_DCMI_Init()/ HAL_DCMI_DeInit() 0089 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. 0090 0091 Callbacks can be registered/unregistered in HAL_DCMI_STATE_READY state only. 0092 Exception done MspInit/MspDeInit functions that can be registered/unregistered 0093 in HAL_DCMI_STATE_READY or HAL_DCMI_STATE_RESET state, 0094 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 0095 In that case first register the MspInit/MspDeInit user callbacks 0096 using HAL_DCMI_RegisterCallback() before calling HAL_DCMI_DeInit() or HAL_DCMI_Init() function. 0097 0098 When the compilation flag USE_HAL_DCMI_REGISTER_CALLBACKS is set to 0 or 0099 not defined, the callback registration feature is not available and all callbacks 0100 are set to the corresponding weak functions. 0101 0102 *** DCMI HAL driver macros list *** 0103 ============================================= 0104 [..] 0105 Below the list of most used macros in DCMI HAL driver. 0106 0107 (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral. 0108 (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral. 0109 (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags. 0110 (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags. 0111 (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts. 0112 (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts. 0113 (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not. 0114 0115 [..] 0116 (@) You can refer to the DCMI HAL driver header file for more useful macros 0117 0118 @endverbatim 0119 */ 0120 0121 /* Includes ------------------------------------------------------------------*/ 0122 #include "stm32h7xx_hal.h" 0123 0124 /** @addtogroup STM32H7xx_HAL_Driver 0125 * @{ 0126 */ 0127 /** @defgroup DCMI DCMI 0128 * @ingroup RTEMSBSPsARMSTM32H7 0129 * @brief DCMI HAL module driver 0130 * @{ 0131 */ 0132 0133 #ifdef HAL_DCMI_MODULE_ENABLED 0134 #if defined (DCMI) 0135 0136 /* Private typedef -----------------------------------------------------------*/ 0137 /* Private define ------------------------------------------------------------*/ 0138 /** @addtogroup DCMI_Private_Defines 0139 * @{ 0140 */ 0141 #define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* Set timeout to 1s */ 0142 /** 0143 * @} 0144 */ 0145 /* Private macro -------------------------------------------------------------*/ 0146 /* Private variables ---------------------------------------------------------*/ 0147 /* Private function prototypes -----------------------------------------------*/ 0148 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma); 0149 static void DCMI_DMAError(DMA_HandleTypeDef *hdma); 0150 0151 /* Exported functions --------------------------------------------------------*/ 0152 0153 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions 0154 * @ingroup RTEMSBSPsARMSTM32H7 0155 * @{ 0156 */ 0157 0158 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions 0159 * @ingroup RTEMSBSPsARMSTM32H7 0160 * @brief Initialization and Configuration functions 0161 * 0162 @verbatim 0163 =============================================================================== 0164 ##### Initialization and Configuration functions ##### 0165 =============================================================================== 0166 [..] This section provides functions allowing to: 0167 (+) Initialize and configure the DCMI 0168 (+) De-initialize the DCMI 0169 0170 @endverbatim 0171 * @{ 0172 */ 0173 0174 /** 0175 * @brief Initializes the DCMI according to the specified 0176 * parameters in the DCMI_InitTypeDef and create the associated handle. 0177 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0178 * the configuration information for DCMI. 0179 * @retval HAL status 0180 */ 0181 HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi) 0182 { 0183 /* Check the DCMI peripheral state */ 0184 if (hdcmi == NULL) 0185 { 0186 return HAL_ERROR; 0187 } 0188 0189 /* Check function parameters */ 0190 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance)); 0191 assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity)); 0192 assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity)); 0193 assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity)); 0194 assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode)); 0195 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate)); 0196 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode)); 0197 assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode)); 0198 0199 assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode)); 0200 assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart)); 0201 assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode)); 0202 assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart)); 0203 0204 if (hdcmi->State == HAL_DCMI_STATE_RESET) 0205 { 0206 /* Init the DCMI Callback settings */ 0207 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0208 /* Reset callback pointers to the weak predefined callbacks */ 0209 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */ 0210 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */ 0211 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */ 0212 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */ 0213 0214 if (hdcmi->MspInitCallback == NULL) 0215 { 0216 /* Legacy weak MspInit Callback */ 0217 hdcmi->MspInitCallback = HAL_DCMI_MspInit; 0218 } 0219 /* Initialize the low level hardware (MSP) */ 0220 hdcmi->MspInitCallback(hdcmi); 0221 #else 0222 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ 0223 HAL_DCMI_MspInit(hdcmi); 0224 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */ 0225 } 0226 0227 /* Change the DCMI state */ 0228 hdcmi->State = HAL_DCMI_STATE_BUSY; 0229 0230 if (hdcmi->Init.ExtendedDataMode != DCMI_EXTEND_DATA_8B) 0231 { 0232 /* Byte select mode must be programmed to the reset value if the extended mode 0233 is not set to 8-bit data capture on every pixel clock */ 0234 hdcmi->Init.ByteSelectMode = DCMI_BSM_ALL; 0235 } 0236 /* Configures the HS, VS, DE and PC polarity */ 0237 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | \ 0238 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | \ 0239 DCMI_CR_ESS | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS | \ 0240 DCMI_CR_LSM | DCMI_CR_OELS); 0241 0242 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \ 0243 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \ 0244 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \ 0245 hdcmi->Init.JPEGMode | hdcmi->Init.ByteSelectMode | \ 0246 hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode | \ 0247 hdcmi->Init.LineSelectStart); 0248 0249 if (hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED) 0250 { 0251 hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | \ 0252 ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_ESCR_LSC_Pos) | \ 0253 ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_ESCR_LEC_Pos) | \ 0254 ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_ESCR_FEC_Pos)); 0255 0256 } 0257 0258 /* Enable the Line, Vsync, Error and Overrun interrupts */ 0259 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR); 0260 0261 /* Update error code */ 0262 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; 0263 0264 /* Initialize the DCMI state*/ 0265 hdcmi->State = HAL_DCMI_STATE_READY; 0266 0267 return HAL_OK; 0268 } 0269 0270 /** 0271 * @brief Deinitializes the DCMI peripheral registers to their default reset 0272 * values. 0273 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0274 * the configuration information for DCMI. 0275 * @retval HAL status 0276 */ 0277 0278 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi) 0279 { 0280 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0281 if (hdcmi->MspDeInitCallback == NULL) 0282 { 0283 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit; 0284 } 0285 /* De-Initialize the low level hardware (MSP) */ 0286 hdcmi->MspDeInitCallback(hdcmi); 0287 #else 0288 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ 0289 HAL_DCMI_MspDeInit(hdcmi); 0290 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */ 0291 0292 /* Update error code */ 0293 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; 0294 0295 /* Initialize the DCMI state*/ 0296 hdcmi->State = HAL_DCMI_STATE_RESET; 0297 0298 /* Release Lock */ 0299 __HAL_UNLOCK(hdcmi); 0300 0301 return HAL_OK; 0302 } 0303 0304 /** 0305 * @brief Initializes the DCMI MSP. 0306 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0307 * the configuration information for DCMI. 0308 * @retval None 0309 */ 0310 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi) 0311 { 0312 /* Prevent unused argument(s) compilation warning */ 0313 UNUSED(hdcmi); 0314 0315 /* NOTE : This function Should not be modified, when the callback is needed, 0316 the HAL_DCMI_MspInit could be implemented in the user file 0317 */ 0318 } 0319 0320 /** 0321 * @brief DeInitializes the DCMI MSP. 0322 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0323 * the configuration information for DCMI. 0324 * @retval None 0325 */ 0326 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef *hdcmi) 0327 { 0328 /* Prevent unused argument(s) compilation warning */ 0329 UNUSED(hdcmi); 0330 0331 /* NOTE : This function Should not be modified, when the callback is needed, 0332 the HAL_DCMI_MspDeInit could be implemented in the user file 0333 */ 0334 } 0335 0336 /** 0337 * @} 0338 */ 0339 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions 0340 * @ingroup RTEMSBSPsARMSTM32H7 0341 * @brief IO operation functions 0342 * 0343 @verbatim 0344 =============================================================================== 0345 ##### IO operation functions ##### 0346 =============================================================================== 0347 [..] This section provides functions allowing to: 0348 (+) Configure destination address and data length and 0349 Enables DCMI DMA request and enables DCMI capture 0350 (+) Stop the DCMI capture. 0351 (+) Handles DCMI interrupt request. 0352 0353 @endverbatim 0354 * @{ 0355 */ 0356 0357 /** 0358 * @brief Enables DCMI DMA request and enables DCMI capture 0359 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0360 * the configuration information for DCMI. 0361 * @param DCMI_Mode DCMI capture mode snapshot or continuous grab. 0362 * @param pData The destination memory Buffer address (LCD Frame buffer). 0363 * @param Length The length of capture to be transferred. 0364 * @retval HAL status 0365 */ 0366 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef *hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length) 0367 { 0368 /* Initialize the second memory address */ 0369 uint32_t SecondMemAddress; 0370 0371 /* Check function parameters */ 0372 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode)); 0373 0374 /* Process Locked */ 0375 __HAL_LOCK(hdcmi); 0376 0377 /* Lock the DCMI peripheral state */ 0378 hdcmi->State = HAL_DCMI_STATE_BUSY; 0379 0380 /* Enable DCMI by setting DCMIEN bit */ 0381 __HAL_DCMI_ENABLE(hdcmi); 0382 0383 /* Configure the DCMI Mode */ 0384 hdcmi->Instance->CR &= ~(DCMI_CR_CM); 0385 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode); 0386 0387 /* Set the DMA memory0 conversion complete callback */ 0388 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt; 0389 0390 /* Set the DMA error callback */ 0391 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError; 0392 0393 /* Set the dma abort callback */ 0394 hdcmi->DMA_Handle->XferAbortCallback = NULL; 0395 0396 /* Reset transfer counters value */ 0397 hdcmi->XferCount = 0; 0398 hdcmi->XferTransferNumber = 0; 0399 hdcmi->XferSize = 0; 0400 hdcmi->pBuffPtr = 0; 0401 0402 if (Length <= 0xFFFFU) 0403 { 0404 /* Enable the DMA Stream */ 0405 if (HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length) != HAL_OK) 0406 { 0407 /* Set Error Code */ 0408 hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA; 0409 /* Change DCMI state */ 0410 hdcmi->State = HAL_DCMI_STATE_READY; 0411 /* Release Lock */ 0412 __HAL_UNLOCK(hdcmi); 0413 /* Return function status */ 0414 return HAL_ERROR; 0415 } 0416 } 0417 else /* DCMI_DOUBLE_BUFFER Mode */ 0418 { 0419 /* Set the DMA memory1 conversion complete callback */ 0420 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt; 0421 0422 /* Initialize transfer parameters */ 0423 hdcmi->XferCount = 1; 0424 hdcmi->XferSize = Length; 0425 hdcmi->pBuffPtr = pData; 0426 0427 /* Get the number of buffer */ 0428 while (hdcmi->XferSize > 0xFFFFU) 0429 { 0430 hdcmi->XferSize = (hdcmi->XferSize / 2U); 0431 hdcmi->XferCount = hdcmi->XferCount * 2U; 0432 } 0433 0434 /* Update DCMI counter and transfer number*/ 0435 hdcmi->XferCount = (hdcmi->XferCount - 2U); 0436 hdcmi->XferTransferNumber = hdcmi->XferCount; 0437 0438 /* Update second memory address */ 0439 SecondMemAddress = (uint32_t)(pData + (4U * hdcmi->XferSize)); 0440 0441 /* Start DMA multi buffer transfer */ 0442 if (HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize) != HAL_OK) 0443 { 0444 /* Set Error Code */ 0445 hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA; 0446 /* Change DCMI state */ 0447 hdcmi->State = HAL_DCMI_STATE_READY; 0448 /* Release Lock */ 0449 __HAL_UNLOCK(hdcmi); 0450 /* Return function status */ 0451 return HAL_ERROR; 0452 } 0453 } 0454 0455 /* Enable Capture */ 0456 hdcmi->Instance->CR |= DCMI_CR_CAPTURE; 0457 0458 /* Release Lock */ 0459 __HAL_UNLOCK(hdcmi); 0460 0461 /* Return function status */ 0462 return HAL_OK; 0463 } 0464 0465 /** 0466 * @brief Disable DCMI DMA request and Disable DCMI capture 0467 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0468 * the configuration information for DCMI. 0469 * @retval HAL status 0470 */ 0471 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef *hdcmi) 0472 { 0473 uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U); 0474 HAL_StatusTypeDef status = HAL_OK; 0475 0476 /* Process locked */ 0477 __HAL_LOCK(hdcmi); 0478 0479 /* Lock the DCMI peripheral state */ 0480 hdcmi->State = HAL_DCMI_STATE_BUSY; 0481 0482 /* Disable Capture */ 0483 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE); 0484 0485 /* Check if the DCMI capture effectively disabled */ 0486 do 0487 { 0488 count-- ; 0489 if (count == 0U) 0490 { 0491 /* Update error code */ 0492 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT; 0493 0494 status = HAL_TIMEOUT; 0495 break; 0496 } 0497 } 0498 while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U); 0499 0500 /* Disable the DCMI */ 0501 __HAL_DCMI_DISABLE(hdcmi); 0502 0503 /* Disable the DMA */ 0504 (void)HAL_DMA_Abort(hdcmi->DMA_Handle); 0505 0506 /* Update error code */ 0507 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE; 0508 0509 /* Change DCMI state */ 0510 hdcmi->State = HAL_DCMI_STATE_READY; 0511 0512 /* Process Unlocked */ 0513 __HAL_UNLOCK(hdcmi); 0514 0515 /* Return function status */ 0516 return status; 0517 } 0518 0519 /** 0520 * @brief Suspend DCMI capture 0521 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0522 * the configuration information for DCMI. 0523 * @retval HAL status 0524 */ 0525 HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef *hdcmi) 0526 { 0527 uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U); 0528 HAL_StatusTypeDef status = HAL_OK; 0529 0530 /* Process locked */ 0531 __HAL_LOCK(hdcmi); 0532 0533 if (hdcmi->State == HAL_DCMI_STATE_BUSY) 0534 { 0535 /* Change DCMI state */ 0536 hdcmi->State = HAL_DCMI_STATE_SUSPENDED; 0537 0538 /* Disable Capture */ 0539 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE); 0540 0541 /* Check if the DCMI capture effectively disabled */ 0542 do 0543 { 0544 count-- ; 0545 if (count == 0U) 0546 { 0547 /* Update error code */ 0548 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT; 0549 0550 /* Change DCMI state */ 0551 hdcmi->State = HAL_DCMI_STATE_READY; 0552 0553 status = HAL_TIMEOUT; 0554 break; 0555 } 0556 } 0557 while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U); 0558 } 0559 /* Process Unlocked */ 0560 __HAL_UNLOCK(hdcmi); 0561 0562 /* Return function status */ 0563 return status; 0564 } 0565 0566 /** 0567 * @brief Resume DCMI capture 0568 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0569 * the configuration information for DCMI. 0570 * @retval HAL status 0571 */ 0572 HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef *hdcmi) 0573 { 0574 /* Process locked */ 0575 __HAL_LOCK(hdcmi); 0576 0577 if (hdcmi->State == HAL_DCMI_STATE_SUSPENDED) 0578 { 0579 /* Change DCMI state */ 0580 hdcmi->State = HAL_DCMI_STATE_BUSY; 0581 0582 /* Enable Capture */ 0583 hdcmi->Instance->CR |= DCMI_CR_CAPTURE; 0584 } 0585 /* Process Unlocked */ 0586 __HAL_UNLOCK(hdcmi); 0587 0588 /* Return function status */ 0589 return HAL_OK; 0590 } 0591 0592 /** 0593 * @brief Handles DCMI interrupt request. 0594 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0595 * the configuration information for the DCMI. 0596 * @retval None 0597 */ 0598 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi) 0599 { 0600 uint32_t isr_value = READ_REG(hdcmi->Instance->MISR); 0601 0602 /* Synchronization error interrupt management *******************************/ 0603 if ((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI) 0604 { 0605 /* Clear the Synchronization error flag */ 0606 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI); 0607 0608 /* Update error code */ 0609 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC; 0610 0611 /* Change DCMI state */ 0612 hdcmi->State = HAL_DCMI_STATE_ERROR; 0613 0614 /* Set the synchronization error callback */ 0615 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError; 0616 0617 /* Abort the DMA Transfer */ 0618 (void)HAL_DMA_Abort_IT(hdcmi->DMA_Handle); 0619 } 0620 /* Overflow interrupt management ********************************************/ 0621 if ((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI) 0622 { 0623 /* Clear the Overflow flag */ 0624 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI); 0625 0626 /* Update error code */ 0627 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR; 0628 0629 /* Change DCMI state */ 0630 hdcmi->State = HAL_DCMI_STATE_ERROR; 0631 0632 /* Set the overflow callback */ 0633 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError; 0634 0635 /* Abort the DMA Transfer */ 0636 (void)HAL_DMA_Abort_IT(hdcmi->DMA_Handle); 0637 } 0638 /* Line Interrupt management ************************************************/ 0639 if ((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI) 0640 { 0641 /* Clear the Line interrupt flag */ 0642 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI); 0643 0644 /* Line interrupt Callback */ 0645 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0646 /*Call registered DCMI line event callback*/ 0647 hdcmi->LineEventCallback(hdcmi); 0648 #else 0649 HAL_DCMI_LineEventCallback(hdcmi); 0650 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */ 0651 } 0652 /* VSYNC interrupt management ***********************************************/ 0653 if ((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI) 0654 { 0655 /* Clear the VSYNC flag */ 0656 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI); 0657 0658 /* VSYNC Callback */ 0659 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0660 /*Call registered DCMI vsync event callback*/ 0661 hdcmi->VsyncEventCallback(hdcmi); 0662 #else 0663 HAL_DCMI_VsyncEventCallback(hdcmi); 0664 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */ 0665 } 0666 /* FRAME interrupt management ***********************************************/ 0667 if ((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI) 0668 { 0669 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */ 0670 if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT) 0671 { 0672 /* Disable the Line, Vsync, Error and Overrun interrupts */ 0673 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR); 0674 } 0675 0676 /* Disable the Frame interrupt */ 0677 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME); 0678 0679 /* Clear the End of Frame flag */ 0680 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI); 0681 0682 /* Frame Callback */ 0683 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0684 /*Call registered DCMI frame event callback*/ 0685 hdcmi->FrameEventCallback(hdcmi); 0686 #else 0687 HAL_DCMI_FrameEventCallback(hdcmi); 0688 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */ 0689 } 0690 } 0691 0692 /** 0693 * @brief Error DCMI callback. 0694 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0695 * the configuration information for DCMI. 0696 * @retval None 0697 */ 0698 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi) 0699 { 0700 /* Prevent unused argument(s) compilation warning */ 0701 UNUSED(hdcmi); 0702 0703 /* NOTE : This function Should not be modified, when the callback is needed, 0704 the HAL_DCMI_ErrorCallback could be implemented in the user file 0705 */ 0706 } 0707 0708 /** 0709 * @brief Line Event callback. 0710 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0711 * the configuration information for DCMI. 0712 * @retval None 0713 */ 0714 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi) 0715 { 0716 /* Prevent unused argument(s) compilation warning */ 0717 UNUSED(hdcmi); 0718 /* NOTE : This function Should not be modified, when the callback is needed, 0719 the HAL_DCMI_LineEventCallback could be implemented in the user file 0720 */ 0721 } 0722 0723 /** 0724 * @brief VSYNC Event callback. 0725 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0726 * the configuration information for DCMI. 0727 * @retval None 0728 */ 0729 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi) 0730 { 0731 /* Prevent unused argument(s) compilation warning */ 0732 UNUSED(hdcmi); 0733 0734 /* NOTE : This function Should not be modified, when the callback is needed, 0735 the HAL_DCMI_VsyncEventCallback could be implemented in the user file 0736 */ 0737 } 0738 0739 /** 0740 * @brief Frame Event callback. 0741 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0742 * the configuration information for DCMI. 0743 * @retval None 0744 */ 0745 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) 0746 { 0747 /* Prevent unused argument(s) compilation warning */ 0748 UNUSED(hdcmi); 0749 0750 /* NOTE : This function Should not be modified, when the callback is needed, 0751 the HAL_DCMI_FrameEventCallback could be implemented in the user file 0752 */ 0753 } 0754 0755 /** 0756 * @} 0757 */ 0758 0759 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions 0760 * @ingroup RTEMSBSPsARMSTM32H7 0761 * @brief Peripheral Control functions 0762 * 0763 @verbatim 0764 =============================================================================== 0765 ##### Peripheral Control functions ##### 0766 =============================================================================== 0767 [..] This section provides functions allowing to: 0768 (+) Configure the CROP feature. 0769 (+) Enable/Disable the CROP feature. 0770 (+) Set embedded synchronization delimiters unmasks. 0771 0772 @endverbatim 0773 * @{ 0774 */ 0775 0776 /** 0777 * @brief Configure the DCMI CROP coordinate. 0778 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0779 * the configuration information for DCMI. 0780 * @param YSize DCMI Line number 0781 * @param XSize DCMI Pixel per line 0782 * @param X0 DCMI window X offset 0783 * @param Y0 DCMI window Y offset 0784 * @retval HAL status 0785 */ 0786 HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize) 0787 { 0788 /* Process Locked */ 0789 __HAL_LOCK(hdcmi); 0790 0791 /* Lock the DCMI peripheral state */ 0792 hdcmi->State = HAL_DCMI_STATE_BUSY; 0793 0794 /* Check the parameters */ 0795 assert_param(IS_DCMI_WINDOW_COORDINATE(X0)); 0796 assert_param(IS_DCMI_WINDOW_HEIGHT(Y0)); 0797 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize)); 0798 assert_param(IS_DCMI_WINDOW_COORDINATE(YSize)); 0799 0800 /* Configure CROP */ 0801 hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_CWSIZE_VLINE_Pos)); 0802 hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_CWSTRT_VST_Pos)); 0803 0804 /* Initialize the DCMI state*/ 0805 hdcmi->State = HAL_DCMI_STATE_READY; 0806 0807 /* Process Unlocked */ 0808 __HAL_UNLOCK(hdcmi); 0809 0810 return HAL_OK; 0811 } 0812 0813 /** 0814 * @brief Disable the Crop feature. 0815 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0816 * the configuration information for DCMI. 0817 * @retval HAL status 0818 */ 0819 HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi) 0820 { 0821 /* Process Locked */ 0822 __HAL_LOCK(hdcmi); 0823 0824 /* Lock the DCMI peripheral state */ 0825 hdcmi->State = HAL_DCMI_STATE_BUSY; 0826 0827 /* Disable DCMI Crop feature */ 0828 hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP; 0829 0830 /* Change the DCMI state*/ 0831 hdcmi->State = HAL_DCMI_STATE_READY; 0832 0833 /* Process Unlocked */ 0834 __HAL_UNLOCK(hdcmi); 0835 0836 return HAL_OK; 0837 } 0838 0839 /** 0840 * @brief Enable the Crop feature. 0841 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0842 * the configuration information for DCMI. 0843 * @retval HAL status 0844 */ 0845 HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi) 0846 { 0847 /* Process Locked */ 0848 __HAL_LOCK(hdcmi); 0849 0850 /* Lock the DCMI peripheral state */ 0851 hdcmi->State = HAL_DCMI_STATE_BUSY; 0852 0853 /* Enable DCMI Crop feature */ 0854 hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP; 0855 0856 /* Change the DCMI state*/ 0857 hdcmi->State = HAL_DCMI_STATE_READY; 0858 0859 /* Process Unlocked */ 0860 __HAL_UNLOCK(hdcmi); 0861 0862 return HAL_OK; 0863 } 0864 0865 /** 0866 * @brief Set embedded synchronization delimiters unmasks. 0867 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0868 * the configuration information for DCMI. 0869 * @param SyncUnmask pointer to a DCMI_SyncUnmaskTypeDef structure that contains 0870 * the embedded synchronization delimiters unmasks. 0871 * @retval HAL status 0872 */ 0873 HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask) 0874 { 0875 /* Process Locked */ 0876 __HAL_LOCK(hdcmi); 0877 0878 /* Lock the DCMI peripheral state */ 0879 hdcmi->State = HAL_DCMI_STATE_BUSY; 0880 0881 /* Write DCMI embedded synchronization unmask register */ 0882 hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) | \ 0883 ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos) | \ 0884 ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos) | \ 0885 ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos)); 0886 0887 /* Change the DCMI state*/ 0888 hdcmi->State = HAL_DCMI_STATE_READY; 0889 0890 /* Process Unlocked */ 0891 __HAL_UNLOCK(hdcmi); 0892 0893 return HAL_OK; 0894 } 0895 0896 /** 0897 * @} 0898 */ 0899 0900 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions 0901 * @ingroup RTEMSBSPsARMSTM32H7 0902 * @brief Peripheral State functions 0903 * 0904 @verbatim 0905 =============================================================================== 0906 ##### Peripheral State and Errors functions ##### 0907 =============================================================================== 0908 [..] 0909 This subsection provides functions allowing to 0910 (+) Check the DCMI state. 0911 (+) Get the specific DCMI error flag. 0912 0913 @endverbatim 0914 * @{ 0915 */ 0916 0917 /** 0918 * @brief Return the DCMI state 0919 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0920 * the configuration information for DCMI. 0921 * @retval HAL state 0922 */ 0923 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi) 0924 { 0925 return hdcmi->State; 0926 } 0927 0928 /** 0929 * @brief Return the DCMI error code 0930 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 0931 * the configuration information for DCMI. 0932 * @retval DCMI Error Code 0933 */ 0934 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi) 0935 { 0936 return hdcmi->ErrorCode; 0937 } 0938 0939 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 0940 /** 0941 * @brief Register a User DCMI Callback 0942 * To be used instead of the weak predefined callback 0943 * @param hdcmi DCMI handle 0944 * @param CallbackID ID of the callback to be registered 0945 * This parameter can be one of the following values: 0946 * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID 0947 * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID 0948 * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID 0949 * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID 0950 * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID 0951 * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID 0952 * @param pCallback pointer to the Callback function 0953 * @retval HAL status 0954 */ 0955 HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback) 0956 { 0957 HAL_StatusTypeDef status = HAL_OK; 0958 0959 if (pCallback == NULL) 0960 { 0961 /* update the error code */ 0962 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 0963 /* update return status */ 0964 status = HAL_ERROR; 0965 } 0966 else 0967 { 0968 if (hdcmi->State == HAL_DCMI_STATE_READY) 0969 { 0970 switch (CallbackID) 0971 { 0972 case HAL_DCMI_FRAME_EVENT_CB_ID : 0973 hdcmi->FrameEventCallback = pCallback; 0974 break; 0975 0976 case HAL_DCMI_VSYNC_EVENT_CB_ID : 0977 hdcmi->VsyncEventCallback = pCallback; 0978 break; 0979 0980 case HAL_DCMI_LINE_EVENT_CB_ID : 0981 hdcmi->LineEventCallback = pCallback; 0982 break; 0983 0984 case HAL_DCMI_ERROR_CB_ID : 0985 hdcmi->ErrorCallback = pCallback; 0986 break; 0987 0988 case HAL_DCMI_MSPINIT_CB_ID : 0989 hdcmi->MspInitCallback = pCallback; 0990 break; 0991 0992 case HAL_DCMI_MSPDEINIT_CB_ID : 0993 hdcmi->MspDeInitCallback = pCallback; 0994 break; 0995 0996 default : 0997 /* Return error status */ 0998 status = HAL_ERROR; 0999 break; 1000 } 1001 } 1002 else if (hdcmi->State == HAL_DCMI_STATE_RESET) 1003 { 1004 switch (CallbackID) 1005 { 1006 case HAL_DCMI_MSPINIT_CB_ID : 1007 hdcmi->MspInitCallback = pCallback; 1008 break; 1009 1010 case HAL_DCMI_MSPDEINIT_CB_ID : 1011 hdcmi->MspDeInitCallback = pCallback; 1012 break; 1013 1014 default : 1015 /* update the error code */ 1016 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 1017 /* update return status */ 1018 status = HAL_ERROR; 1019 break; 1020 } 1021 } 1022 else 1023 { 1024 /* update the error code */ 1025 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 1026 /* update return status */ 1027 status = HAL_ERROR; 1028 } 1029 } 1030 1031 return status; 1032 } 1033 1034 /** 1035 * @brief Unregister a DCMI Callback 1036 * DCMI callback is redirected to the weak predefined callback 1037 * @param hdcmi DCMI handle 1038 * @param CallbackID ID of the callback to be registered 1039 * This parameter can be one of the following values: 1040 * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID 1041 * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID 1042 * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID 1043 * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID 1044 * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID 1045 * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID 1046 * @retval HAL status 1047 */ 1048 HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID) 1049 { 1050 HAL_StatusTypeDef status = HAL_OK; 1051 1052 if (hdcmi->State == HAL_DCMI_STATE_READY) 1053 { 1054 switch (CallbackID) 1055 { 1056 case HAL_DCMI_FRAME_EVENT_CB_ID : 1057 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */ 1058 break; 1059 1060 case HAL_DCMI_VSYNC_EVENT_CB_ID : 1061 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */ 1062 break; 1063 1064 case HAL_DCMI_LINE_EVENT_CB_ID : 1065 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */ 1066 break; 1067 1068 case HAL_DCMI_ERROR_CB_ID : 1069 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */ 1070 break; 1071 1072 case HAL_DCMI_MSPINIT_CB_ID : 1073 hdcmi->MspInitCallback = HAL_DCMI_MspInit; 1074 break; 1075 1076 case HAL_DCMI_MSPDEINIT_CB_ID : 1077 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit; 1078 break; 1079 1080 default : 1081 /* update the error code */ 1082 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 1083 /* update return status */ 1084 status = HAL_ERROR; 1085 break; 1086 } 1087 } 1088 else if (hdcmi->State == HAL_DCMI_STATE_RESET) 1089 { 1090 switch (CallbackID) 1091 { 1092 case HAL_DCMI_MSPINIT_CB_ID : 1093 hdcmi->MspInitCallback = HAL_DCMI_MspInit; 1094 break; 1095 1096 case HAL_DCMI_MSPDEINIT_CB_ID : 1097 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit; 1098 break; 1099 1100 default : 1101 /* update the error code */ 1102 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 1103 /* update return status */ 1104 status = HAL_ERROR; 1105 break; 1106 } 1107 } 1108 else 1109 { 1110 /* update the error code */ 1111 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK; 1112 /* update return status */ 1113 status = HAL_ERROR; 1114 } 1115 1116 return status; 1117 } 1118 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */ 1119 1120 /** 1121 * @} 1122 */ 1123 1124 /** 1125 * @} 1126 */ 1127 /* Private functions ---------------------------------------------------------*/ 1128 /** @defgroup DCMI_Private_Functions DCMI Private Functions 1129 * @ingroup RTEMSBSPsARMSTM32H7 1130 * @{ 1131 */ 1132 /** 1133 * @brief DMA conversion complete callback. 1134 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 1135 * the configuration information for the specified DMA module. 1136 * @retval None 1137 */ 1138 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma) 1139 { 1140 uint32_t tmp ; 1141 1142 DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 1143 1144 if (hdcmi->XferCount != 0U) 1145 { 1146 /* Update memory 0 address location */ 1147 tmp = ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR) & DMA_SxCR_CT); 1148 if (((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U)) 1149 { 1150 tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR; 1151 (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY0); 1152 hdcmi->XferCount--; 1153 } 1154 /* Update memory 1 address location */ 1155 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U) 1156 { 1157 tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR; 1158 (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY1); 1159 hdcmi->XferCount--; 1160 } 1161 else 1162 { 1163 /* Nothing to do */ 1164 } 1165 } 1166 /* Update memory 0 address location */ 1167 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) != 0U) 1168 { 1169 ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR = hdcmi->pBuffPtr; 1170 } 1171 /* Update memory 1 address location */ 1172 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U) 1173 { 1174 tmp = hdcmi->pBuffPtr; 1175 ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR = (tmp + (4U * hdcmi->XferSize)); 1176 hdcmi->XferCount = hdcmi->XferTransferNumber; 1177 } 1178 else 1179 { 1180 /* Nothing to do */ 1181 } 1182 1183 /* Check if the frame is transferred */ 1184 if (hdcmi->XferCount == hdcmi->XferTransferNumber) 1185 { 1186 /* Enable the Frame interrupt */ 1187 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME); 1188 1189 /* When snapshot mode, set dcmi state to ready */ 1190 if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT) 1191 { 1192 hdcmi->State = HAL_DCMI_STATE_READY; 1193 } 1194 } 1195 } 1196 1197 /** 1198 * @brief DMA error callback 1199 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 1200 * the configuration information for the specified DMA module. 1201 * @retval None 1202 */ 1203 static void DCMI_DMAError(DMA_HandleTypeDef *hdma) 1204 { 1205 DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 1206 1207 if (hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE) 1208 { 1209 /* Initialize the DCMI state*/ 1210 hdcmi->State = HAL_DCMI_STATE_READY; 1211 1212 /* Set DCMI Error Code */ 1213 hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA; 1214 } 1215 1216 /* DCMI error Callback */ 1217 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1) 1218 /*Call registered DCMI error callback*/ 1219 hdcmi->ErrorCallback(hdcmi); 1220 #else 1221 HAL_DCMI_ErrorCallback(hdcmi); 1222 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */ 1223 } 1224 1225 /** 1226 * @} 1227 */ 1228 1229 #endif /* DCMI */ 1230 #endif /* HAL_DCMI_MODULE_ENABLED */ 1231 /** 1232 * @} 1233 */ 1234 1235 /** 1236 * @} 1237 */ 1238
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |