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