1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_dcmi.c
4   * @author  MCD Application Team
5   * @brief   DCMI HAL module driver
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the Digital Camera Interface (DCMI) peripheral:
8   *           + Initialization and de-initialization functions
9   *           + IO operation functions
10   *           + Peripheral Control functions
11   *           + Peripheral State and Error functions
12   *
13   ******************************************************************************
14   * @attention
15   *
16   * Copyright (c) 2017 STMicroelectronics.
17   * All rights reserved.
18   *
19   * This software is licensed under terms that can be found in the LICENSE file in
20   * the root directory of this software component.
21   * If no LICENSE file comes with this software, it is provided AS-IS.
22   ******************************************************************************
23   @verbatim
24   ==============================================================================
25                         ##### How to use this driver #####
26   ==============================================================================
27   [..]
28       The sequence below describes how to use this driver to capture image
29       from a camera module connected to the DCMI Interface.
30       This sequence does not take into account the configuration of the
31       camera module, which should be made before to configure and enable
32       the DCMI to capture images.
33 
34     (#) Program the required configuration through following parameters:
35         horizontal and vertical polarity, pixel clock polarity, Capture Rate,
36         Synchronization Mode, code of the frame delimiter and data width
37         using HAL_DCMI_Init() function.
38 
39     (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR
40         register to the destination memory buffer.
41 
42     (#) Program the required configuration through following parameters:
43         DCMI mode, destination memory Buffer address and the data length
44         and enable capture using HAL_DCMI_Start_DMA() function.
45 
46     (#) Optionally, configure and Enable the CROP feature to select a rectangular
47         window from the received image using HAL_DCMI_ConfigCrop()
48         and HAL_DCMI_EnableCROP() functions
49 
50     (#) The capture can be stopped using HAL_DCMI_Stop() function.
51 
52     (#) To control DCMI state you can use the function HAL_DCMI_GetState().
53 
54      *** DCMI HAL driver macros list ***
55      =============================================
56      [..]
57        Below the list of most used macros in DCMI HAL driver.
58 
59       (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
60       (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
61       (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
62       (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
63       (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
64       (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
65       (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
66 
67      [..]
68        (@) You can refer to the DCMI HAL driver header file for more useful macros
69 
70     *** Callback registration ***
71     =============================
72 
73     The compilation define USE_HAL_DCMI_REGISTER_CALLBACKS when set to 1
74     allows the user to configure dynamically the driver callbacks.
75     Use functions HAL_DCMI_RegisterCallback() to register a user callback.
76 
77     Function HAL_DCMI_RegisterCallback() allows to register following callbacks:
78       (+) FrameEventCallback : DCMI Frame Event.
79       (+) VsyncEventCallback : DCMI Vsync Event.
80       (+) LineEventCallback  : DCMI Line Event.
81       (+) ErrorCallback      : DCMI error.
82       (+) MspInitCallback    : DCMI MspInit.
83       (+) MspDeInitCallback  : DCMI MspDeInit.
84     This function takes as parameters the HAL peripheral handle, the callback ID
85     and a pointer to the user callback function.
86 
87     Use function HAL_DCMI_UnRegisterCallback() to reset a callback to the default
88     weak (surcharged) function.
89     HAL_DCMI_UnRegisterCallback() takes as parameters the HAL peripheral handle,
90     and the callback ID.
91     This function allows to reset following callbacks:
92       (+) FrameEventCallback : DCMI Frame Event.
93       (+) VsyncEventCallback : DCMI Vsync Event.
94       (+) LineEventCallback  : DCMI Line Event.
95       (+) ErrorCallback      : DCMI error.
96       (+) MspInitCallback    : DCMI MspInit.
97       (+) MspDeInitCallback  : DCMI MspDeInit.
98 
99     By default, after the HAL_DCMI_Init and if the state is HAL_DCMI_STATE_RESET
100     all callbacks are reset to the corresponding legacy weak (surcharged) functions:
101     examples FrameEventCallback(), HAL_DCMI_ErrorCallback().
102     Exception done for MspInit and MspDeInit callbacks that are respectively
103     reset to the legacy weak (surcharged) functions in the HAL_DCMI_Init
104     and  HAL_DCMI_DeInit only when these callbacks are null (not registered beforehand).
105     If not, MspInit or MspDeInit are not null, the HAL_DCMI_Init and HAL_DCMI_DeInit
106     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
107 
108     Callbacks can be registered/unregistered in READY state only.
109     Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
110     in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
111     during the Init/DeInit.
112     In that case first register the MspInit/MspDeInit user callbacks
113     using HAL_DCMI_RegisterCallback before calling HAL_DCMI_DeInit
114     or HAL_DCMI_Init function.
115 
116     When the compilation define USE_HAL_DCMI_REGISTER_CALLBACKS is set to 0 or
117     not defined, the callback registering feature is not available
118     and weak (surcharged) callbacks are used.
119 
120   @endverbatim
121   ******************************************************************************
122   */
123 
124 /* Includes ------------------------------------------------------------------*/
125 #include "stm32f4xx_hal.h"
126 
127 /** @addtogroup STM32F4xx_HAL_Driver
128   * @{
129   */
130 /** @defgroup DCMI DCMI
131   * @brief DCMI HAL module driver
132   * @{
133   */
134 
135 #ifdef HAL_DCMI_MODULE_ENABLED
136 
137 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\
138     defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\
139     defined(STM32F479xx)
140 /* Private typedef -----------------------------------------------------------*/
141 /* Private define ------------------------------------------------------------*/
142 #define HAL_TIMEOUT_DCMI_STOP    14U  /* Set timeout to 1s  */
143 /* Private macro -------------------------------------------------------------*/
144 /* Private variables ---------------------------------------------------------*/
145 /* Private function prototypes -----------------------------------------------*/
146 static void       DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
147 static void       DCMI_DMAError(DMA_HandleTypeDef *hdma);
148 
149 /* Exported functions --------------------------------------------------------*/
150 
151 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
152   * @{
153   */
154 
155 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
156   *  @brief   Initialization and Configuration functions
157   *
158 @verbatim
159  ===============================================================================
160                 ##### Initialization and Configuration functions #####
161  ===============================================================================
162     [..]  This section provides functions allowing to:
163       (+) Initialize and configure the DCMI
164       (+) De-initialize the DCMI
165 
166 @endverbatim
167   * @{
168   */
169 
170 /**
171   * @brief  Initializes the DCMI according to the specified
172   *         parameters in the DCMI_InitTypeDef and create the associated handle.
173   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
174   *                the configuration information for DCMI.
175   * @retval HAL status
176   */
HAL_DCMI_Init(DCMI_HandleTypeDef * hdcmi)177 __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
178 {
179   /* Check the DCMI peripheral state */
180   if(hdcmi == NULL)
181   {
182      return HAL_ERROR;
183   }
184 
185   /* Check function parameters */
186   assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
187   assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
188   assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
189   assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
190   assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
191   assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
192   assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
193   assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
194 
195   if(hdcmi->State == HAL_DCMI_STATE_RESET)
196   {
197     /* Allocate lock resource and initialize it */
198     hdcmi->Lock = HAL_UNLOCKED;
199     /* Init the low level hardware */
200   /* Init the DCMI Callback settings */
201 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
202     hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback  */
203     hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback  */
204     hdcmi->LineEventCallback  = HAL_DCMI_LineEventCallback;  /* Legacy weak LineEventCallback   */
205     hdcmi->ErrorCallback      = HAL_DCMI_ErrorCallback;      /* Legacy weak ErrorCallback       */
206 
207     if(hdcmi->MspInitCallback == NULL)
208     {
209       /* Legacy weak MspInit Callback        */
210       hdcmi->MspInitCallback = HAL_DCMI_MspInit;
211     }
212     /* Initialize the low level hardware (MSP) */
213     hdcmi->MspInitCallback(hdcmi);
214 #else
215     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
216     HAL_DCMI_MspInit(hdcmi);
217 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
218     HAL_DCMI_MspInit(hdcmi);
219   }
220 
221   /* Change the DCMI state */
222   hdcmi->State = HAL_DCMI_STATE_BUSY;
223 
224   /* Set DCMI parameters */
225   /* Configures the HS, VS, DE and PC polarity */
226   hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL  | DCMI_CR_VSPOL  | DCMI_CR_EDM_0 |
227                            DCMI_CR_EDM_1  | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG  |
228                            DCMI_CR_ESS);
229   hdcmi->Instance->CR |=  (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
230                                      hdcmi->Init.VSPolarity  | hdcmi->Init.HSPolarity  | \
231                                      hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
232                                      hdcmi->Init.JPEGMode);
233 
234   if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
235   {
236     hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode)    |
237                              ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
238                              ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
239                              ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
240   }
241 
242   /* Enable the Line, Vsync, Error and Overrun interrupts */
243   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
244 
245   /* Update error code */
246   hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
247 
248   /* Initialize the DCMI state*/
249   hdcmi->State  = HAL_DCMI_STATE_READY;
250 
251   return HAL_OK;
252 }
253 
254 /**
255   * @brief  Deinitializes the DCMI peripheral registers to their default reset
256   *         values.
257   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
258   *                the configuration information for DCMI.
259   * @retval HAL status
260   */
261 
HAL_DCMI_DeInit(DCMI_HandleTypeDef * hdcmi)262 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
263 {
264 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
265   if(hdcmi->MspDeInitCallback == NULL)
266   {
267     hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
268   }
269   /* De-Initialize the low level hardware (MSP) */
270   hdcmi->MspDeInitCallback(hdcmi);
271 #else
272   /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
273   HAL_DCMI_MspDeInit(hdcmi);
274 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
275 
276   /* Update error code */
277   hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
278 
279   /* Initialize the DCMI state*/
280   hdcmi->State = HAL_DCMI_STATE_RESET;
281 
282   /* Release Lock */
283   __HAL_UNLOCK(hdcmi);
284 
285   return HAL_OK;
286 }
287 
288 /**
289   * @brief  Initializes the DCMI MSP.
290   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
291   *                the configuration information for DCMI.
292   * @retval None
293   */
HAL_DCMI_MspInit(DCMI_HandleTypeDef * hdcmi)294 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
295 {
296   /* Prevent unused argument(s) compilation warning */
297   UNUSED(hdcmi);
298   /* NOTE : This function Should not be modified, when the callback is needed,
299             the HAL_DCMI_MspInit could be implemented in the user file
300    */
301 }
302 
303 /**
304   * @brief  DeInitializes the DCMI MSP.
305   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
306   *                the configuration information for DCMI.
307   * @retval None
308   */
HAL_DCMI_MspDeInit(DCMI_HandleTypeDef * hdcmi)309 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
310 {
311   /* Prevent unused argument(s) compilation warning */
312   UNUSED(hdcmi);
313   /* NOTE : This function Should not be modified, when the callback is needed,
314             the HAL_DCMI_MspDeInit could be implemented in the user file
315    */
316 }
317 
318 /**
319   * @}
320   */
321 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
322   *  @brief   IO operation functions
323   *
324 @verbatim
325  ===============================================================================
326                       #####  IO operation functions  #####
327  ===============================================================================
328     [..]  This section provides functions allowing to:
329       (+) Configure destination address and data length and
330           Enables DCMI DMA request and enables DCMI capture
331       (+) Stop the DCMI capture.
332       (+) Handles DCMI interrupt request.
333 
334 @endverbatim
335   * @{
336   */
337 
338 /**
339   * @brief  Enables DCMI DMA request and enables DCMI capture
340   * @param  hdcmi     pointer to a DCMI_HandleTypeDef structure that contains
341   *                    the configuration information for DCMI.
342   * @param  DCMI_Mode DCMI capture mode snapshot or continuous grab.
343   * @param  pData     The destination memory Buffer address (LCD Frame buffer).
344   * @param  Length    The length of capture to be transferred.
345   * @retval HAL status
346   */
HAL_DCMI_Start_DMA(DCMI_HandleTypeDef * hdcmi,uint32_t DCMI_Mode,uint32_t pData,uint32_t Length)347 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
348 {
349   /* Initialize the second memory address */
350   uint32_t SecondMemAddress = 0U;
351 
352   /* Check function parameters */
353   assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
354 
355   /* Process Locked */
356   __HAL_LOCK(hdcmi);
357 
358   /* Lock the DCMI peripheral state */
359   hdcmi->State = HAL_DCMI_STATE_BUSY;
360 
361   /* Enable DCMI by setting DCMIEN bit */
362   __HAL_DCMI_ENABLE(hdcmi);
363 
364   /* Configure the DCMI Mode */
365   hdcmi->Instance->CR &= ~(DCMI_CR_CM);
366   hdcmi->Instance->CR |=  (uint32_t)(DCMI_Mode);
367 
368   /* Set the DMA memory0 conversion complete callback */
369   hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
370 
371   /* Set the DMA error callback */
372   hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
373 
374   /* Set the dma abort callback */
375   hdcmi->DMA_Handle->XferAbortCallback = NULL;
376 
377   /* Reset transfer counters value */
378   hdcmi->XferCount = 0U;
379   hdcmi->XferTransferNumber = 0U;
380 
381   if(Length <= 0xFFFFU)
382   {
383     /* Enable the DMA Stream */
384     HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
385   }
386   else /* DCMI_DOUBLE_BUFFER Mode */
387   {
388     /* Set the DMA memory1 conversion complete callback */
389     hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
390 
391     /* Initialize transfer parameters */
392     hdcmi->XferCount = 1U;
393     hdcmi->XferSize = Length;
394     hdcmi->pBuffPtr = pData;
395 
396     /* Get the number of buffer */
397     while(hdcmi->XferSize > 0xFFFFU)
398     {
399       hdcmi->XferSize = (hdcmi->XferSize/2U);
400       hdcmi->XferCount = hdcmi->XferCount*2U;
401     }
402 
403     /* Update DCMI counter  and transfer number*/
404     hdcmi->XferCount = (hdcmi->XferCount - 2U);
405     hdcmi->XferTransferNumber = hdcmi->XferCount;
406 
407     /* Update second memory address */
408     SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize));
409 
410     /* Start DMA multi buffer transfer */
411     HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
412   }
413 
414   /* Enable Capture */
415   hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
416 
417   /* Release Lock */
418   __HAL_UNLOCK(hdcmi);
419 
420   /* Return function status */
421   return HAL_OK;
422 }
423 
424 /**
425   * @brief  Disable DCMI DMA request and Disable DCMI capture
426   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
427   *                the configuration information for DCMI.
428   * @retval HAL status
429   */
HAL_DCMI_Stop(DCMI_HandleTypeDef * hdcmi)430 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
431 {
432   __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
433   HAL_StatusTypeDef status = HAL_OK;
434 
435   /* Process locked */
436   __HAL_LOCK(hdcmi);
437 
438   /* Lock the DCMI peripheral state */
439   hdcmi->State = HAL_DCMI_STATE_BUSY;
440 
441   /* Disable Capture */
442   hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
443 
444   /* Check if the DCMI capture effectively disabled */
445   do
446   {
447     if (count-- == 0U)
448     {
449       /* Update error code */
450       hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
451 
452       status = HAL_TIMEOUT;
453       break;
454     }
455   }
456   while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
457 
458   /* Disable the DCMI */
459   __HAL_DCMI_DISABLE(hdcmi);
460 
461   /* Disable the DMA */
462   HAL_DMA_Abort(hdcmi->DMA_Handle);
463 
464   /* Update error code */
465   hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
466 
467   /* Change DCMI state */
468   hdcmi->State = HAL_DCMI_STATE_READY;
469 
470   /* Process Unlocked */
471   __HAL_UNLOCK(hdcmi);
472 
473   /* Return function status */
474   return status;
475 }
476 
477 /**
478   * @brief  Suspend DCMI capture
479   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
480   *                the configuration information for DCMI.
481   * @retval HAL status
482   */
HAL_DCMI_Suspend(DCMI_HandleTypeDef * hdcmi)483 HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
484 {
485   __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
486   HAL_StatusTypeDef status = HAL_OK;
487 
488   /* Process locked */
489   __HAL_LOCK(hdcmi);
490 
491   if(hdcmi->State == HAL_DCMI_STATE_BUSY)
492   {
493     /* Change DCMI state */
494     hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
495 
496     /* Disable Capture */
497     hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
498 
499     /* Check if the DCMI capture effectively disabled */
500     do
501     {
502       if (count-- == 0U)
503       {
504         /* Update error code */
505         hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
506 
507         /* Change DCMI state */
508         hdcmi->State = HAL_DCMI_STATE_READY;
509 
510         status = HAL_TIMEOUT;
511         break;
512       }
513     }
514     while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
515   }
516   /* Process Unlocked */
517   __HAL_UNLOCK(hdcmi);
518 
519   /* Return function status */
520   return status;
521 }
522 
523 /**
524   * @brief  Resume DCMI capture
525   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
526   *                the configuration information for DCMI.
527   * @retval HAL status
528   */
HAL_DCMI_Resume(DCMI_HandleTypeDef * hdcmi)529 HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi)
530 {
531   /* Process locked */
532   __HAL_LOCK(hdcmi);
533 
534   if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
535   {
536     /* Change DCMI state */
537     hdcmi->State = HAL_DCMI_STATE_BUSY;
538 
539     /* Disable Capture */
540     hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
541   }
542   /* Process Unlocked */
543   __HAL_UNLOCK(hdcmi);
544 
545   /* Return function status */
546   return HAL_OK;
547 }
548 
549 /**
550   * @brief  Handles DCMI interrupt request.
551   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
552   *                the configuration information for the DCMI.
553   * @retval None
554   */
HAL_DCMI_IRQHandler(DCMI_HandleTypeDef * hdcmi)555 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
556 {
557   uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
558 
559   /* Synchronization error interrupt management *******************************/
560   if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
561   {
562     /* Clear the Synchronization error flag */
563     __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
564 
565     /* Update error code */
566     hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
567 
568     /* Change DCMI state */
569     hdcmi->State = HAL_DCMI_STATE_ERROR;
570 
571     /* Set the synchronization error callback */
572     hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
573 
574     /* Abort the DMA Transfer */
575     HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
576   }
577   /* Overflow interrupt management ********************************************/
578   if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
579   {
580     /* Clear the Overflow flag */
581     __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
582 
583     /* Update error code */
584     hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
585 
586     /* Change DCMI state */
587     hdcmi->State = HAL_DCMI_STATE_ERROR;
588 
589     /* Set the overflow callback */
590     hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
591 
592     /* Abort the DMA Transfer */
593     HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
594   }
595   /* Line Interrupt management ************************************************/
596   if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
597   {
598     /* Clear the Line interrupt flag */
599     __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
600 
601     /* Line interrupt Callback */
602 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
603     /*Call registered DCMI line event callback*/
604     hdcmi->LineEventCallback(hdcmi);
605 #else
606     HAL_DCMI_LineEventCallback(hdcmi);
607 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
608   }
609   /* VSYNC interrupt management ***********************************************/
610   if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
611   {
612     /* Clear the VSYNC flag */
613     __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
614 
615     /* VSYNC Callback */
616 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
617     /*Call registered DCMI vsync event callback*/
618     hdcmi->VsyncEventCallback(hdcmi);
619 #else
620     HAL_DCMI_VsyncEventCallback(hdcmi);
621 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
622   }
623   /* FRAME interrupt management ***********************************************/
624   if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
625   {
626     /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
627     if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
628     {
629       /* Disable the Line, Vsync, Error and Overrun interrupts */
630       __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
631     }
632 
633     /* Disable the Frame interrupt */
634     __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
635 
636     /* Frame Callback */
637 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
638     /*Call registered DCMI frame event callback*/
639     hdcmi->FrameEventCallback(hdcmi);
640 #else
641     HAL_DCMI_FrameEventCallback(hdcmi);
642 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
643   }
644 }
645 
646 /**
647   * @brief  Error DCMI callback.
648   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
649   *                the configuration information for DCMI.
650   * @retval None
651   */
HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef * hdcmi)652 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
653 {
654   /* Prevent unused argument(s) compilation warning */
655   UNUSED(hdcmi);
656   /* NOTE : This function Should not be modified, when the callback is needed,
657             the HAL_DCMI_ErrorCallback could be implemented in the user file
658    */
659 }
660 
661 /**
662   * @brief  Line Event callback.
663   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
664   *                the configuration information for DCMI.
665   * @retval None
666   */
HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef * hdcmi)667 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
668 {
669   /* Prevent unused argument(s) compilation warning */
670   UNUSED(hdcmi);
671   /* NOTE : This function Should not be modified, when the callback is needed,
672             the HAL_DCMI_LineEventCallback could be implemented in the user file
673    */
674 }
675 
676 /**
677   * @brief  VSYNC Event callback.
678   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
679   *                the configuration information for DCMI.
680   * @retval None
681   */
HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef * hdcmi)682 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
683 {
684   /* Prevent unused argument(s) compilation warning */
685   UNUSED(hdcmi);
686   /* NOTE : This function Should not be modified, when the callback is needed,
687             the HAL_DCMI_VsyncEventCallback could be implemented in the user file
688    */
689 }
690 
691 /**
692   * @brief  Frame Event callback.
693   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
694   *                the configuration information for DCMI.
695   * @retval None
696   */
HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef * hdcmi)697 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
698 {
699   /* Prevent unused argument(s) compilation warning */
700   UNUSED(hdcmi);
701   /* NOTE : This function Should not be modified, when the callback is needed,
702             the HAL_DCMI_FrameEventCallback could be implemented in the user file
703    */
704 }
705 
706 /**
707   * @}
708   */
709 
710 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
711   *  @brief    Peripheral Control functions
712   *
713 @verbatim
714  ===============================================================================
715                     ##### Peripheral Control functions #####
716  ===============================================================================
717 [..]  This section provides functions allowing to:
718       (+) Configure the CROP feature.
719       (+) Enable/Disable the CROP feature.
720 
721 @endverbatim
722   * @{
723   */
724 
725 /**
726   * @brief  Configure the DCMI CROP coordinate.
727   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
728   *                the configuration information for DCMI.
729   * @param  X0    DCMI window X offset
730   * @param  Y0    DCMI window Y offset
731   * @param  XSize DCMI Pixel per line
732   * @param  YSize DCMI Line number
733   * @retval HAL status
734   */
HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef * hdcmi,uint32_t X0,uint32_t Y0,uint32_t XSize,uint32_t YSize)735 HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
736 {
737   /* Process Locked */
738   __HAL_LOCK(hdcmi);
739 
740   /* Lock the DCMI peripheral state */
741   hdcmi->State = HAL_DCMI_STATE_BUSY;
742 
743   /* Check the parameters */
744   assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
745   assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
746   assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
747   assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
748 
749   /* Configure CROP */
750   hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE));
751   hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST));
752 
753   /* Initialize the DCMI state*/
754   hdcmi->State  = HAL_DCMI_STATE_READY;
755 
756   /* Process Unlocked */
757   __HAL_UNLOCK(hdcmi);
758 
759   return HAL_OK;
760 }
761 
762 /**
763   * @brief  Disable the Crop feature.
764   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
765   *                the configuration information for DCMI.
766   * @retval HAL status
767   */
HAL_DCMI_DisableCrop(DCMI_HandleTypeDef * hdcmi)768 HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
769 {
770   /* Process Locked */
771   __HAL_LOCK(hdcmi);
772 
773   /* Lock the DCMI peripheral state */
774   hdcmi->State = HAL_DCMI_STATE_BUSY;
775 
776   /* Disable DCMI Crop feature */
777   hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
778 
779   /* Change the DCMI state*/
780   hdcmi->State = HAL_DCMI_STATE_READY;
781 
782   /* Process Unlocked */
783   __HAL_UNLOCK(hdcmi);
784 
785   return HAL_OK;
786 }
787 
788 /**
789   * @brief  Enable the Crop feature.
790   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
791   *                the configuration information for DCMI.
792   * @retval HAL status
793   */
HAL_DCMI_EnableCrop(DCMI_HandleTypeDef * hdcmi)794 HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
795 {
796   /* Process Locked */
797   __HAL_LOCK(hdcmi);
798 
799   /* Lock the DCMI peripheral state */
800   hdcmi->State = HAL_DCMI_STATE_BUSY;
801 
802   /* Enable DCMI Crop feature */
803   hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
804 
805   /* Change the DCMI state*/
806   hdcmi->State = HAL_DCMI_STATE_READY;
807 
808   /* Process Unlocked */
809   __HAL_UNLOCK(hdcmi);
810 
811   return HAL_OK;
812 }
813 
814 /**
815   * @brief  Set embedded synchronization delimiters unmasks.
816   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
817   *               the configuration information for DCMI.
818   * @param  SyncUnmask pointer to a DCMI_SyncUnmaskTypeDef structure that contains
819   *                    the embedded synchronization delimiters unmasks.
820   * @retval HAL status
821   */
HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef * hdcmi,DCMI_SyncUnmaskTypeDef * SyncUnmask)822 HAL_StatusTypeDef  HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
823 {
824   /* Process Locked */
825   __HAL_LOCK(hdcmi);
826 
827   /* Lock the DCMI peripheral state */
828   hdcmi->State = HAL_DCMI_STATE_BUSY;
829 
830   /* Write DCMI embedded synchronization unmask register */
831   hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) |\
832                            ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos)|\
833                            ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos)|\
834                            ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
835 
836   /* Change the DCMI state*/
837   hdcmi->State = HAL_DCMI_STATE_READY;
838 
839   /* Process Unlocked */
840   __HAL_UNLOCK(hdcmi);
841 
842   return HAL_OK;
843 }
844 
845 /**
846   * @}
847   */
848 
849 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
850   *  @brief    Peripheral State functions
851   *
852 @verbatim
853  ===============================================================================
854                ##### Peripheral State and Errors functions #####
855  ===============================================================================
856     [..]
857     This subsection provides functions allowing to
858       (+) Check the DCMI state.
859       (+) Get the specific DCMI error flag.
860 
861 @endverbatim
862   * @{
863   */
864 
865 /**
866   * @brief  Return the DCMI state
867   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
868   *                the configuration information for DCMI.
869   * @retval HAL state
870   */
HAL_DCMI_GetState(DCMI_HandleTypeDef * hdcmi)871 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
872 {
873   return hdcmi->State;
874 }
875 
876 /**
877   * @brief  Return the DCMI error code
878   * @param  hdcmi  pointer to a DCMI_HandleTypeDef structure that contains
879   *               the configuration information for DCMI.
880   * @retval DCMI Error Code
881   */
HAL_DCMI_GetError(DCMI_HandleTypeDef * hdcmi)882 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
883 {
884   return hdcmi->ErrorCode;
885 }
886 
887 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
888 /**
889   * @brief DCMI Callback registering
890   * @param hdcmi        pointer to a DCMI_HandleTypeDef structure that contains
891   *                     the configuration information for DCMI.
892   * @param CallbackID   dcmi Callback ID
893   * @param pCallback    pointer to DCMI_CallbackTypeDef structure
894   * @retval status
895   */
HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef * hdcmi,HAL_DCMI_CallbackIDTypeDef CallbackID,pDCMI_CallbackTypeDef pCallback)896 HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
897 {
898   HAL_StatusTypeDef status = HAL_OK;
899 
900   if(pCallback == NULL)
901   {
902     /* update the error code */
903     hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
904     /* update return status */
905     status = HAL_ERROR;
906   }
907   else
908   {
909     if(hdcmi->State == HAL_DCMI_STATE_READY)
910     {
911       switch (CallbackID)
912       {
913       case HAL_DCMI_FRAME_EVENT_CB_ID :
914         hdcmi->FrameEventCallback = pCallback;
915         break;
916 
917       case HAL_DCMI_VSYNC_EVENT_CB_ID :
918         hdcmi->VsyncEventCallback = pCallback;
919         break;
920 
921       case HAL_DCMI_LINE_EVENT_CB_ID :
922         hdcmi->LineEventCallback = pCallback;
923         break;
924 
925       case HAL_DCMI_ERROR_CB_ID :
926         hdcmi->ErrorCallback = pCallback;
927         break;
928 
929       case HAL_DCMI_MSPINIT_CB_ID :
930         hdcmi->MspInitCallback = pCallback;
931         break;
932 
933       case HAL_DCMI_MSPDEINIT_CB_ID :
934         hdcmi->MspDeInitCallback = pCallback;
935         break;
936 
937       default :
938         /* Return error status */
939         status =  HAL_ERROR;
940         break;
941       }
942     }
943     else if(hdcmi->State == HAL_DCMI_STATE_RESET)
944     {
945       switch (CallbackID)
946       {
947       case HAL_DCMI_MSPINIT_CB_ID :
948         hdcmi->MspInitCallback = pCallback;
949         break;
950 
951       case HAL_DCMI_MSPDEINIT_CB_ID :
952         hdcmi->MspDeInitCallback = pCallback;
953         break;
954 
955       default :
956         /* update the error code */
957         hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
958         /* update return status */
959         status = HAL_ERROR;
960         break;
961       }
962     }
963     else
964     {
965       /* update the error code */
966       hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
967       /* update return status */
968       status = HAL_ERROR;
969     }
970   }
971 
972   return status;
973 }
974 
975 /**
976   * @brief DCMI Callback Unregistering
977   * @param hdcmi       dcmi handle
978   * @param CallbackID  dcmi Callback ID
979   * @retval status
980   */
HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef * hdcmi,HAL_DCMI_CallbackIDTypeDef CallbackID)981 HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
982 {
983   HAL_StatusTypeDef status = HAL_OK;
984 
985   if(hdcmi->State == HAL_DCMI_STATE_READY)
986   {
987     switch (CallbackID)
988     {
989     case HAL_DCMI_FRAME_EVENT_CB_ID :
990       hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback;  /* Legacy weak  FrameEventCallback  */
991       break;
992 
993     case HAL_DCMI_VSYNC_EVENT_CB_ID :
994       hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback;  /* Legacy weak VsyncEventCallback       */
995       break;
996 
997     case HAL_DCMI_LINE_EVENT_CB_ID :
998       hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback;    /* Legacy weak LineEventCallback   */
999       break;
1000 
1001     case HAL_DCMI_ERROR_CB_ID :
1002       hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback;           /* Legacy weak ErrorCallback        */
1003       break;
1004 
1005     case HAL_DCMI_MSPINIT_CB_ID :
1006       hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1007       break;
1008 
1009     case HAL_DCMI_MSPDEINIT_CB_ID :
1010       hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1011       break;
1012 
1013     default :
1014       /* update the error code */
1015       hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1016       /* update return status */
1017       status = HAL_ERROR;
1018       break;
1019     }
1020   }
1021   else if(hdcmi->State == HAL_DCMI_STATE_RESET)
1022   {
1023     switch (CallbackID)
1024     {
1025     case HAL_DCMI_MSPINIT_CB_ID :
1026       hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1027       break;
1028 
1029     case HAL_DCMI_MSPDEINIT_CB_ID :
1030       hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1031       break;
1032 
1033     default :
1034       /* update the error code */
1035       hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1036       /* update return status */
1037       status = HAL_ERROR;
1038       break;
1039     }
1040   }
1041   else
1042   {
1043     /* update the error code */
1044     hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1045     /* update return status */
1046     status = HAL_ERROR;
1047   }
1048 
1049   return status;
1050 }
1051 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1052 
1053 /**
1054   * @}
1055   */
1056 /* Private functions ---------------------------------------------------------*/
1057 /** @defgroup DCMI_Private_Functions DCMI Private Functions
1058   * @{
1059   */
1060 
1061 /**
1062   * @brief  DMA conversion complete callback.
1063   * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
1064   *               the configuration information for the specified DMA module.
1065   * @retval None
1066   */
DCMI_DMAXferCplt(DMA_HandleTypeDef * hdma)1067 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
1068 {
1069   uint32_t tmp = 0U;
1070 
1071   DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1072 
1073   if(hdcmi->XferCount != 0U)
1074   {
1075     /* Update memory 0 address location */
1076     tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);
1077     if(((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
1078     {
1079       tmp = hdcmi->DMA_Handle->Instance->M0AR;
1080       HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY0);
1081       hdcmi->XferCount--;
1082     }
1083     /* Update memory 1 address location */
1084     else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1085     {
1086       tmp = hdcmi->DMA_Handle->Instance->M1AR;
1087       HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY1);
1088       hdcmi->XferCount--;
1089     }
1090   }
1091   /* Update memory 0 address location */
1092   else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0U)
1093   {
1094     hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
1095   }
1096   /* Update memory 1 address location */
1097   else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1098   {
1099     tmp = hdcmi->pBuffPtr;
1100     hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4U*hdcmi->XferSize));
1101     hdcmi->XferCount = hdcmi->XferTransferNumber;
1102   }
1103 
1104   /* Check if the frame is transferred */
1105   if(hdcmi->XferCount == hdcmi->XferTransferNumber)
1106   {
1107     /* Enable the Frame interrupt */
1108     __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
1109 
1110     /* When snapshot mode, set dcmi state to ready */
1111     if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
1112     {
1113       hdcmi->State= HAL_DCMI_STATE_READY;
1114     }
1115   }
1116 }
1117 
1118 /**
1119   * @brief  DMA error callback
1120   * @param  hdma pointer to a DMA_HandleTypeDef structure that contains
1121   *                the configuration information for the specified DMA module.
1122   * @retval None
1123   */
DCMI_DMAError(DMA_HandleTypeDef * hdma)1124 static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
1125 {
1126   DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1127 
1128   if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
1129   {
1130     /* Initialize the DCMI state*/
1131     hdcmi->State = HAL_DCMI_STATE_READY;
1132   }
1133 
1134   /* DCMI error Callback */
1135 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1136     /*Call registered DCMI error callback*/
1137     hdcmi->ErrorCallback(hdcmi);
1138 #else
1139   HAL_DCMI_ErrorCallback(hdcmi);
1140 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1141 
1142 }
1143 
1144 /**
1145   * @}
1146   */
1147 
1148 /**
1149   * @}
1150   */
1151 #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
1152           STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
1153           STM32F479xx */
1154 #endif /* HAL_DCMI_MODULE_ENABLED */
1155 /**
1156   * @}
1157   */
1158 
1159 /**
1160   * @}
1161   */
1162