2 ******************************************************************************
3 * @file stm32f4xx_hal_dcmi.c
4 * @author MCD Application Team
7 * @brief DCMI HAL module driver
8 * This file provides firmware functions to manage the following
9 * functionalities of the Digital Camera Interface (DCMI) peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral Control functions
13 * + Peripheral State and Error functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 The sequence below describes how to use this driver to capture image
21 from a camera module connected to the DCMI Interface.
22 This sequence does not take into account the configuration of the
23 camera module, which should be made before to configure and enable
24 the DCMI to capture images.
26 (#) Program the required configuration through following parameters:
27 horizontal and vertical polarity, pixel clock polarity, Capture Rate,
28 Synchronization Mode, code of the frame delimiter and data width
29 using HAL_DCMI_Init() function.
31 (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR
32 register to the destination memory buffer.
34 (#) Program the required configuration through following parameters:
35 DCMI mode, destination memory Buffer address and the data length
36 and enable capture using HAL_DCMI_Start_DMA() function.
38 (#) Optionally, configure and Enable the CROP feature to select a rectangular
39 window from the received image using HAL_DCMI_ConfigCrop()
40 and HAL_DCMI_EnableCROP() functions
42 (#) The capture can be stopped using HAL_DCMI_Stop() function.
44 (#) To control DCMI state you can use the function HAL_DCMI_GetState().
46 *** DCMI HAL driver macros list ***
47 =============================================
49 Below the list of most used macros in DCMI HAL driver.
51 (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
52 (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
53 (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
54 (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
55 (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
56 (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
57 (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
60 (@) You can refer to the DCMI HAL driver header file for more useful macros
63 ******************************************************************************
66 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
68 * Redistribution and use in source and binary forms, with or without modification,
69 * are permitted provided that the following conditions are met:
70 * 1. Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * 3. Neither the name of STMicroelectronics nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90 ******************************************************************************
93 /* Includes ------------------------------------------------------------------*/
94 #include "stm32f4xx_hal.h"
96 /** @addtogroup STM32F4xx_HAL_Driver
100 * @brief DCMI HAL module driver
104 #ifdef HAL_DCMI_MODULE_ENABLED
106 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
107 /* Private typedef -----------------------------------------------------------*/
108 /* Private define ------------------------------------------------------------*/
109 #define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* 1s */
110 /* Private macro -------------------------------------------------------------*/
111 /* Private variables ---------------------------------------------------------*/
112 /* Private function prototypes -----------------------------------------------*/
113 static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma);
114 static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
116 /* Private functions ---------------------------------------------------------*/
118 /** @defgroup DCMI_Private_Functions
122 /** @defgroup DCMI_Group1 Initialization and Configuration functions
123 * @brief Initialization and Configuration functions
126 ===============================================================================
127 ##### Initialization and Configuration functions #####
128 ===============================================================================
129 [..] This section provides functions allowing to:
130 (+) Initialize and configure the DCMI
131 (+) De-initialize the DCMI
138 * @brief Initializes the DCMI according to the specified
139 * parameters in the DCMI_InitTypeDef and create the associated handle.
140 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
141 * the configuration information for DCMI.
144 HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
146 /* Check the DCMI peripheral state */
147 if(hdcmi == HAL_NULL)
152 /* Check function parameters */
153 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
154 assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
155 assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
156 assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
157 assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
158 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
159 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
160 assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
162 if(hdcmi->State == HAL_DCMI_STATE_RESET)
164 /* Init the low level hardware */
165 HAL_DCMI_MspInit(hdcmi);
168 /* Change the DCMI state */
169 hdcmi->State = HAL_DCMI_STATE_BUSY;
171 /* Configures the HS, VS, DE and PC polarity */
172 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |
173 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |
175 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
176 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
177 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
178 hdcmi->Init.JPEGMode);
180 if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
182 DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
183 ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)|
184 ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) |
185 ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24));
188 /* Enable the Line interrupt */
189 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE);
191 /* Enable the VSYNC interrupt */
192 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC);
194 /* Enable the Frame capture complete interrupt */
195 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
197 /* Enable the Synchronization error interrupt */
198 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR);
200 /* Enable the Overflow interrupt */
201 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF);
203 /* Enable DCMI by setting DCMIEN bit */
204 __HAL_DCMI_ENABLE(hdcmi);
206 /* Update error code */
207 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
209 /* Initialize the DCMI state*/
210 hdcmi->State = HAL_DCMI_STATE_READY;
216 * @brief Deinitializes the DCMI peripheral registers to their default reset
218 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
219 * the configuration information for DCMI.
223 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
225 /* DeInit the low level hardware */
226 HAL_DCMI_MspDeInit(hdcmi);
228 /* Update error code */
229 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
231 /* Initialize the DCMI state*/
232 hdcmi->State = HAL_DCMI_STATE_RESET;
241 * @brief Initializes the DCMI MSP.
242 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
243 * the configuration information for DCMI.
246 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
248 /* NOTE : This function Should not be modified, when the callback is needed,
249 the HAL_DCMI_MspInit could be implemented in the user file
254 * @brief DeInitializes the DCMI MSP.
255 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
256 * the configuration information for DCMI.
259 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
261 /* NOTE : This function Should not be modified, when the callback is needed,
262 the HAL_DCMI_MspDeInit could be implemented in the user file
269 /** @defgroup DCMI_Group2 IO operation functions
270 * @brief IO operation functions
273 ===============================================================================
274 ##### IO operation functions #####
275 ===============================================================================
276 [..] This section provides functions allowing to:
277 (+) Configure destination address and data length and
278 Enables DCMI DMA request and enables DCMI capture
279 (+) Stop the DCMI capture.
280 (+) Handles DCMI interrupt request.
287 * @brief Enables DCMI DMA request and enables DCMI capture
288 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
289 * the configuration information for DCMI.
290 * @param DCMI_Mode: DCMI capture mode snapshot or continuous grab.
291 * @param pData: The destination memory Buffer address (LCD Frame buffer).
292 * @param Length: The length of capture to be transferred.
295 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
297 /* Initialise the second memory address */
298 uint32_t SecondMemAddress = 0;
300 /* Check function parameters */
301 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
306 /* Lock the DCMI peripheral state */
307 hdcmi->State = HAL_DCMI_STATE_BUSY;
309 /* Check the parameters */
310 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
312 /* Configure the DCMI Mode */
313 hdcmi->Instance->CR &= ~(DCMI_CR_CM);
314 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
316 /* Set the DMA memory0 conversion complete callback */
317 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAConvCplt;
319 /* Set the DMA error callback */
320 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
324 /* Enable the DMA Stream */
325 HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
327 else /* DCMI_DOUBLE_BUFFER Mode */
329 /* Set the DMA memory1 conversion complete callback */
330 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAConvCplt;
332 /* Initialise transfer parameters */
333 hdcmi->XferCount = 1;
334 hdcmi->XferSize = Length;
335 hdcmi->pBuffPtr = pData;
337 /* Get the number of buffer */
338 while(hdcmi->XferSize > 0xFFFF)
340 hdcmi->XferSize = (hdcmi->XferSize/2);
341 hdcmi->XferCount = hdcmi->XferCount*2;
344 /* Update DCMI counter and transfer number*/
345 hdcmi->XferCount = (hdcmi->XferCount - 2);
346 hdcmi->XferTransferNumber = hdcmi->XferCount;
348 /* Update second memory address */
349 SecondMemAddress = (uint32_t)(pData + (4*hdcmi->XferSize));
351 /* Start DMA multi buffer transfer */
352 HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
356 DCMI->CR |= DCMI_CR_CAPTURE;
358 /* Return function status */
363 * @brief Disable DCMI DMA request and Disable DCMI capture
364 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
365 * the configuration information for DCMI.
368 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
370 uint32_t tickstart = 0;
372 /* Lock the DCMI peripheral state */
373 hdcmi->State = HAL_DCMI_STATE_BUSY;
375 __HAL_DCMI_DISABLE(hdcmi);
377 /* Disable Capture */
378 DCMI->CR &= ~(DCMI_CR_CAPTURE);
381 tickstart = HAL_GetTick();
383 /* Check if the DCMI capture effectively disabled */
384 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0)
386 if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DCMI_STOP)
388 /* Process Unlocked */
391 /* Update error code */
392 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
394 /* Change DCMI state */
395 hdcmi->State = HAL_DCMI_STATE_TIMEOUT;
401 /* Disable the DMA */
402 HAL_DMA_Abort(hdcmi->DMA_Handle);
404 /* Update error code */
405 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
407 /* Change DCMI state */
408 hdcmi->State = HAL_DCMI_STATE_READY;
410 /* Process Unlocked */
413 /* Return function status */
418 * @brief Handles DCMI interrupt request.
419 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
420 * the configuration information for the DCMI.
423 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
425 /* Synchronization error interrupt management *******************************/
426 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_ERRRI) != RESET)
428 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_ERR) != RESET)
430 /* Disable the Synchronization error interrupt */
431 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_ERR);
433 /* Clear the Synchronization error flag */
434 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
436 /* Update error code */
437 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
439 /* Change DCMI state */
440 hdcmi->State = HAL_DCMI_STATE_ERROR;
442 /* Process Unlocked */
445 /* Abort the DMA Transfer */
446 HAL_DMA_Abort(hdcmi->DMA_Handle);
448 /* Synchronization error Callback */
449 HAL_DCMI_ErrorCallback(hdcmi);
452 /* Overflow interrupt management ********************************************/
453 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_OVFRI) != RESET)
455 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_OVF) != RESET)
457 /* Disable the Overflow interrupt */
458 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_OVF);
460 /* Clear the Overflow flag */
461 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVFRI);
463 /* Update error code */
464 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVF;
466 /* Change DCMI state */
467 hdcmi->State = HAL_DCMI_STATE_ERROR;
469 /* Process Unlocked */
472 /* Abort the DMA Transfer */
473 HAL_DMA_Abort(hdcmi->DMA_Handle);
475 /* Overflow Callback */
476 HAL_DCMI_ErrorCallback(hdcmi);
479 /* Line Interrupt management ************************************************/
480 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_LINERI) != RESET)
482 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_LINE) != RESET)
484 /* Clear the Line interrupt flag */
485 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
487 /* Process Unlocked */
490 /* Line interrupt Callback */
491 HAL_DCMI_LineEventCallback(hdcmi);
494 /* VSYNC interrupt management ***********************************************/
495 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_VSYNCRI) != RESET)
497 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_VSYNC) != RESET)
499 /* Disable the VSYNC interrupt */
500 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_VSYNC);
502 /* Clear the VSYNC flag */
503 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
505 /* Process Unlocked */
509 HAL_DCMI_VsyncEventCallback(hdcmi);
512 /* End of Frame interrupt management ****************************************/
513 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)
515 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_FRAME) != RESET)
517 /* Disable the End of Frame interrupt */
518 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
520 /* Clear the End of Frame flag */
521 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
523 /* Process Unlocked */
526 /* End of Frame Callback */
527 HAL_DCMI_FrameEventCallback(hdcmi);
533 * @brief Error DCMI callback.
534 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
535 * the configuration information for DCMI.
538 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
540 /* NOTE : This function Should not be modified, when the callback is needed,
541 the HAL_DCMI_ErrorCallback could be implemented in the user file
546 * @brief Line Event callback.
547 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
548 * the configuration information for DCMI.
551 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
553 /* NOTE : This function Should not be modified, when the callback is needed,
554 the HAL_DCMI_LineEventCallback could be implemented in the user file
559 * @brief VSYNC Event callback.
560 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
561 * the configuration information for DCMI.
564 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
566 /* NOTE : This function Should not be modified, when the callback is needed,
567 the HAL_DCMI_VsyncEventCallback could be implemented in the user file
572 * @brief Frame Event callback.
573 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
574 * the configuration information for DCMI.
577 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
579 /* NOTE : This function Should not be modified, when the callback is needed,
580 the HAL_DCMI_FrameEventCallback could be implemented in the user file
588 /** @defgroup DCMI_Group3 Peripheral Control functions
589 * @brief Peripheral Control functions
592 ===============================================================================
593 ##### Peripheral Control functions #####
594 ===============================================================================
595 [..] This section provides functions allowing to:
596 (+) Configure the CROP feature.
597 (+) Enable/Disable the CROP feature.
604 * @brief Configure the DCMI CROP coordinate.
605 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
606 * the configuration information for DCMI.
607 * @param YSize: DCMI Line number
608 * @param XSize: DCMI Pixel per line
609 * @param X0: DCMI window X offset
610 * @param Y0: DCMI window Y offset
613 HAL_StatusTypeDef HAL_DCMI_ConfigCROP(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
618 /* Lock the DCMI peripheral state */
619 hdcmi->State = HAL_DCMI_STATE_BUSY;
621 /* Check the parameters */
622 assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
623 assert_param(IS_DCMI_WINDOW_COORDINATE(Y0));
624 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
625 assert_param(IS_DCMI_WINDOW_HEIGHT(YSize));
628 DCMI->CWSIZER = (XSize | (YSize << 16));
629 DCMI->CWSTRTR = (X0 | (Y0 << 16));
631 /* Initialize the DCMI state*/
632 hdcmi->State = HAL_DCMI_STATE_READY;
634 /* Process Unlocked */
641 * @brief Disable the Crop feature.
642 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
643 * the configuration information for DCMI.
646 HAL_StatusTypeDef HAL_DCMI_DisableCROP(DCMI_HandleTypeDef *hdcmi)
651 /* Lock the DCMI peripheral state */
652 hdcmi->State = HAL_DCMI_STATE_BUSY;
654 /* Disable DCMI Crop feature */
655 DCMI->CR &= ~(uint32_t)DCMI_CR_CROP;
657 /* Change the DCMI state*/
658 hdcmi->State = HAL_DCMI_STATE_READY;
660 /* Process Unlocked */
667 * @brief Enable the Crop feature.
668 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
669 * the configuration information for DCMI.
672 HAL_StatusTypeDef HAL_DCMI_EnableCROP(DCMI_HandleTypeDef *hdcmi)
677 /* Lock the DCMI peripheral state */
678 hdcmi->State = HAL_DCMI_STATE_BUSY;
680 /* Enable DCMI Crop feature */
681 DCMI->CR |= (uint32_t)DCMI_CR_CROP;
683 /* Change the DCMI state*/
684 hdcmi->State = HAL_DCMI_STATE_READY;
686 /* Process Unlocked */
696 /** @defgroup DCMI_Group4 Peripheral State functions
697 * @brief Peripheral State functions
700 ===============================================================================
701 ##### Peripheral State and Errors functions #####
702 ===============================================================================
704 This subsection provides functions allowing to
705 (+) Check the DCMI state.
706 (+) Get the specific DCMI error flag.
713 * @brief Return the DCMI state
714 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
715 * the configuration information for DCMI.
718 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
724 * @brief Return the DCMI error code
725 * @param hdcmi : pointer to a DCMI_HandleTypeDef structure that contains
726 * the configuration information for DCMI.
727 * @retval DCMI Error Code
729 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
731 return hdcmi->ErrorCode;
739 * @brief DMA conversion complete callback.
740 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
741 * the configuration information for the specified DMA module.
744 static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma)
748 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
749 hdcmi->State= HAL_DCMI_STATE_READY;
751 if(hdcmi->XferCount != 0)
753 /* Update memory 0 address location */
754 tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);
755 if(((hdcmi->XferCount % 2) == 0) && (tmp != 0))
757 tmp = hdcmi->DMA_Handle->Instance->M0AR;
758 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY0);
761 /* Update memory 1 address location */
762 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)
764 tmp = hdcmi->DMA_Handle->Instance->M1AR;
765 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY1);
769 /* Update memory 0 address location */
770 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0)
772 hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
774 /* Update memory 1 address location */
775 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)
777 tmp = hdcmi->pBuffPtr;
778 hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4*hdcmi->XferSize));
779 hdcmi->XferCount = hdcmi->XferTransferNumber;
782 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)
784 /* Process Unlocked */
788 HAL_DCMI_FrameEventCallback(hdcmi);
793 * @brief DMA error callback
794 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
795 * the configuration information for the specified DMA module.
798 static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
800 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
801 hdcmi->State= HAL_DCMI_STATE_READY;
802 HAL_DCMI_ErrorCallback(hdcmi);
808 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
809 #endif /* HAL_DCMI_MODULE_ENABLED */
818 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/