]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_dcmi.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_dcmi.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_dcmi.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    24-March-2015\r
7   * @brief   DCMI HAL module driver\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the Digital Camera Interface (DCMI) peripheral:\r
10   *           + Initialization and de-initialization functions\r
11   *           + IO operation functions\r
12   *           + Peripheral Control functions \r
13   *           + Peripheral State and Error functions  \r
14   *           \r
15   @verbatim\r
16   ==============================================================================\r
17                         ##### How to use this driver #####\r
18   ==============================================================================\r
19   [..]\r
20       The sequence below describes how to use this driver to capture image\r
21       from a camera module connected to the DCMI Interface.\r
22       This sequence does not take into account the configuration of the\r
23       camera module, which should be made before to configure and enable\r
24       the DCMI to capture images.\r
25 \r
26     (#) Program the required configuration through following parameters:\r
27         horizontal and vertical polarity, pixel clock polarity, Capture Rate,\r
28         Synchronization Mode, code of the frame delimiter and data width \r
29         using HAL_DCMI_Init() function.\r
30 \r
31     (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR\r
32         register to the destination memory buffer.\r
33 \r
34     (#) Program the required configuration through following parameters:\r
35         DCMI mode, destination memory Buffer address and the data length \r
36         and enable capture using HAL_DCMI_Start_DMA() function.\r
37 \r
38     (#) Optionally, configure and Enable the CROP feature to select a rectangular\r
39         window from the received image using HAL_DCMI_ConfigCrop() \r
40         and HAL_DCMI_EnableCROP() functions\r
41 \r
42     (#) The capture can be stopped using HAL_DCMI_Stop() function.\r
43 \r
44     (#) To control DCMI state you can use the function HAL_DCMI_GetState().\r
45 \r
46      *** DCMI HAL driver macros list ***\r
47      ============================================= \r
48      [..]\r
49        Below the list of most used macros in DCMI HAL driver.\r
50        \r
51       (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.\r
52       (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.\r
53       (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.\r
54       (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.\r
55       (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.\r
56       (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.\r
57       (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.\r
58  \r
59      [..] \r
60        (@) You can refer to the DCMI HAL driver header file for more useful macros\r
61       \r
62   @endverbatim\r
63   ******************************************************************************\r
64   * @attention\r
65   *\r
66   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
67   *\r
68   * Redistribution and use in source and binary forms, with or without modification,\r
69   * are permitted provided that the following conditions are met:\r
70   *   1. Redistributions of source code must retain the above copyright notice,\r
71   *      this list of conditions and the following disclaimer.\r
72   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
73   *      this list of conditions and the following disclaimer in the documentation\r
74   *      and/or other materials provided with the distribution.\r
75   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
76   *      may be used to endorse or promote products derived from this software\r
77   *      without specific prior written permission.\r
78   *\r
79   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
80   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
81   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
82   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
83   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
84   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
85   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
86   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
87   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
88   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
89   *\r
90   ******************************************************************************\r
91   */ \r
92 \r
93 /* Includes ------------------------------------------------------------------*/\r
94 #include "stm32f7xx_hal.h"\r
95 \r
96 /** @addtogroup STM32F7xx_HAL_Driver\r
97   * @{\r
98   */\r
99 /** @defgroup DCMI DCMI\r
100   * @brief DCMI HAL module driver\r
101   * @{\r
102   */\r
103 \r
104 #ifdef HAL_DCMI_MODULE_ENABLED\r
105 \r
106 /* Private typedef -----------------------------------------------------------*/\r
107 /* Private define ------------------------------------------------------------*/\r
108 #define HAL_TIMEOUT_DCMI_STOP    ((uint32_t)1000)  /* 1s  */\r
109 /* Private macro -------------------------------------------------------------*/\r
110 /* Private variables ---------------------------------------------------------*/\r
111 /* Private function prototypes -----------------------------------------------*/\r
112 static void       DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma);\r
113 static void       DCMI_DMAError(DMA_HandleTypeDef *hdma);\r
114 \r
115 /* Exported functions --------------------------------------------------------*/\r
116 \r
117 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions\r
118   * @{\r
119   */\r
120 \r
121 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions\r
122  *  @brief   Initialization and Configuration functions\r
123  *\r
124 @verbatim   \r
125  ===============================================================================\r
126                 ##### Initialization and Configuration functions #####\r
127  ===============================================================================  \r
128     [..]  This section provides functions allowing to:\r
129       (+) Initialize and configure the DCMI\r
130       (+) De-initialize the DCMI \r
131 \r
132 @endverbatim\r
133   * @{\r
134   */\r
135   \r
136 /**\r
137   * @brief  Initializes the DCMI according to the specified\r
138   *         parameters in the DCMI_InitTypeDef and create the associated handle.\r
139   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
140   *                the configuration information for DCMI.\r
141   * @retval HAL status\r
142   */\r
143 __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)\r
144 {     \r
145   /* Check the DCMI peripheral state */\r
146   if(hdcmi == NULL)\r
147   {\r
148      return HAL_ERROR;\r
149   }\r
150   \r
151   /* Check function parameters */\r
152   assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));\r
153   assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));  \r
154   assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));\r
155   assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));\r
156   assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));\r
157   assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));\r
158   assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));\r
159   assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));\r
160 \r
161   if(hdcmi->State == HAL_DCMI_STATE_RESET)\r
162   {\r
163     /* Init the low level hardware */\r
164     HAL_DCMI_MspInit(hdcmi);\r
165   } \r
166   \r
167   /* Change the DCMI state */\r
168   hdcmi->State = HAL_DCMI_STATE_BUSY; \r
169 \r
170   /* Set DCMI parameters */\r
171   /* Configures the HS, VS, DE and PC polarity */\r
172   hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL  | DCMI_CR_VSPOL  | DCMI_CR_EDM_0 |\r
173                            DCMI_CR_EDM_1  | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG  |\r
174                            DCMI_CR_ESS);\r
175   hdcmi->Instance->CR |=  (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \\r
176                                      hdcmi->Init.VSPolarity  | hdcmi->Init.HSPolarity  | \\r
177                                      hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \\r
178                                      hdcmi->Init.JPEGMode);\r
179 \r
180   if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)\r
181   {\r
182     DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode)    |\r
183                   ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)|\r
184                   ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) |\r
185                   ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24));\r
186   }\r
187 \r
188   /* Enable the Line interrupt */\r
189   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE);\r
190 \r
191   /* Enable the VSYNC interrupt */\r
192   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC);\r
193 \r
194   /* Enable the Frame capture complete interrupt */\r
195   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);\r
196 \r
197   /* Enable the Synchronization error interrupt */\r
198   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR);\r
199 \r
200   /* Enable the Overflow interrupt */\r
201   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF);\r
202 \r
203   /* Enable DCMI by setting DCMIEN bit */\r
204   __HAL_DCMI_ENABLE(hdcmi);\r
205 \r
206   /* Update error code */\r
207   hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;\r
208   \r
209   /* Initialize the DCMI state*/\r
210   hdcmi->State  = HAL_DCMI_STATE_READY;\r
211 \r
212   return HAL_OK;\r
213 }\r
214 \r
215 /**\r
216   * @brief  Deinitializes the DCMI peripheral registers to their default reset\r
217   *         values.\r
218   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
219   *                the configuration information for DCMI.\r
220   * @retval HAL status\r
221   */\r
222 \r
223 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)\r
224 {\r
225   /* DeInit the low level hardware */\r
226   HAL_DCMI_MspDeInit(hdcmi);\r
227 \r
228   /* Update error code */\r
229   hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;\r
230 \r
231   /* Initialize the DCMI state*/\r
232   hdcmi->State = HAL_DCMI_STATE_RESET;\r
233 \r
234   /* Release Lock */\r
235   __HAL_UNLOCK(hdcmi);\r
236 \r
237   return HAL_OK;\r
238 }\r
239 \r
240 /**\r
241   * @brief  Initializes the DCMI MSP.\r
242   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
243   *                the configuration information for DCMI.\r
244   * @retval None\r
245   */\r
246 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)\r
247 {\r
248   /* NOTE : This function Should not be modified, when the callback is needed,\r
249             the HAL_DCMI_MspInit could be implemented in the user file\r
250    */ \r
251 }\r
252 \r
253 /**\r
254   * @brief  DeInitializes the DCMI MSP.\r
255   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
256   *                the configuration information for DCMI.\r
257   * @retval None\r
258   */\r
259 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)\r
260 {\r
261   /* NOTE : This function Should not be modified, when the callback is needed,\r
262             the HAL_DCMI_MspDeInit could be implemented in the user file\r
263    */\r
264 }\r
265 \r
266 /**\r
267   * @}\r
268   */\r
269 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions \r
270  *  @brief   IO operation functions  \r
271  *\r
272 @verbatim   \r
273  ===============================================================================\r
274                       #####  IO operation functions  #####\r
275  ===============================================================================  \r
276     [..]  This section provides functions allowing to:\r
277       (+) Configure destination address and data length and \r
278           Enables DCMI DMA request and enables DCMI capture\r
279       (+) Stop the DCMI capture.\r
280       (+) Handles DCMI interrupt request.\r
281 \r
282 @endverbatim\r
283   * @{\r
284   */\r
285 \r
286 /**\r
287   * @brief  Enables DCMI DMA request and enables DCMI capture  \r
288   * @param  hdcmi:     pointer to a DCMI_HandleTypeDef structure that contains\r
289   *                    the configuration information for DCMI.\r
290   * @param  DCMI_Mode: DCMI capture mode snapshot or continuous grab.\r
291   * @param  pData:     The destination memory Buffer address (LCD Frame buffer).\r
292   * @param  Length:    The length of capture to be transferred.\r
293   * @retval HAL status\r
294   */\r
295 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)\r
296 {  \r
297   /* Initialize the second memory address */\r
298   uint32_t SecondMemAddress = 0;\r
299 \r
300   /* Check function parameters */\r
301   assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));\r
302 \r
303   /* Process Locked */\r
304   __HAL_LOCK(hdcmi);\r
305 \r
306   /* Lock the DCMI peripheral state */\r
307   hdcmi->State = HAL_DCMI_STATE_BUSY;\r
308 \r
309   /* Check the parameters */\r
310   assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));\r
311 \r
312   /* Configure the DCMI Mode */\r
313   hdcmi->Instance->CR &= ~(DCMI_CR_CM);\r
314   hdcmi->Instance->CR |=  (uint32_t)(DCMI_Mode);\r
315 \r
316   /* Set the DMA memory0 conversion complete callback */\r
317   hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAConvCplt;\r
318 \r
319   /* Set the DMA error callback */\r
320   hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;\r
321 \r
322   if(Length <= 0xFFFF)\r
323   {\r
324     /* Enable the DMA Stream */\r
325     HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);\r
326   }\r
327   else /* DCMI_DOUBLE_BUFFER Mode */\r
328   {\r
329     /* Set the DMA memory1 conversion complete callback */\r
330     hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAConvCplt; \r
331 \r
332     /* Initialize transfer parameters */\r
333     hdcmi->XferCount = 1;\r
334     hdcmi->XferSize = Length;\r
335     hdcmi->pBuffPtr = pData;\r
336       \r
337     /* Get the number of buffer */\r
338     while(hdcmi->XferSize > 0xFFFF)\r
339     {\r
340       hdcmi->XferSize = (hdcmi->XferSize/2);\r
341       hdcmi->XferCount = hdcmi->XferCount*2;\r
342     }\r
343 \r
344     /* Update DCMI counter  and transfer number*/\r
345     hdcmi->XferCount = (hdcmi->XferCount - 2);\r
346     hdcmi->XferTransferNumber = hdcmi->XferCount;\r
347 \r
348     /* Update second memory address */\r
349     SecondMemAddress = (uint32_t)(pData + (4*hdcmi->XferSize));\r
350 \r
351     /* Start DMA multi buffer transfer */\r
352     HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);\r
353   }\r
354 \r
355   /* Enable Capture */\r
356   DCMI->CR |= DCMI_CR_CAPTURE;\r
357 \r
358   /* Return function status */\r
359   return HAL_OK;\r
360 }\r
361 \r
362 /**\r
363   * @brief  Disable DCMI DMA request and Disable DCMI capture  \r
364   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
365   *                the configuration information for DCMI. \r
366   * @retval HAL status     \r
367   */\r
368 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)\r
369 {\r
370   uint32_t tickstart = 0;\r
371 \r
372   /* Lock the DCMI peripheral state */\r
373   hdcmi->State = HAL_DCMI_STATE_BUSY;\r
374 \r
375   __HAL_DCMI_DISABLE(hdcmi);\r
376 \r
377   /* Disable Capture */\r
378   DCMI->CR &= ~(DCMI_CR_CAPTURE);\r
379 \r
380   /* Get tick */\r
381   tickstart = HAL_GetTick();\r
382 \r
383   /* Check if the DCMI capture effectively disabled */\r
384   while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0)\r
385   {\r
386     if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DCMI_STOP)\r
387     {\r
388       /* Process Unlocked */\r
389       __HAL_UNLOCK(hdcmi);\r
390       \r
391       /* Update error code */\r
392       hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;\r
393       \r
394       /* Change DCMI state */\r
395       hdcmi->State = HAL_DCMI_STATE_TIMEOUT;\r
396       \r
397       return HAL_TIMEOUT;\r
398     }\r
399   }\r
400 \r
401   /* Disable the DMA */\r
402   HAL_DMA_Abort(hdcmi->DMA_Handle);\r
403 \r
404   /* Update error code */\r
405   hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;\r
406 \r
407   /* Change DCMI state */\r
408   hdcmi->State = HAL_DCMI_STATE_READY;\r
409 \r
410   /* Process Unlocked */\r
411   __HAL_UNLOCK(hdcmi);\r
412 \r
413   /* Return function status */\r
414   return HAL_OK;\r
415 }\r
416 \r
417 /**\r
418   * @brief  Handles DCMI interrupt request.\r
419   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
420   *                the configuration information for the DCMI.\r
421   * @retval None\r
422   */\r
423 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)\r
424 {  \r
425   /* Synchronization error interrupt management *******************************/\r
426   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_ERRRI) != RESET)\r
427   {\r
428     if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_ERR) != RESET)\r
429     {\r
430       /* Disable the Synchronization error interrupt */\r
431       __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_ERR); \r
432 \r
433       /* Clear the Synchronization error flag */\r
434       __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);\r
435 \r
436       /* Update error code */\r
437       hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;\r
438 \r
439       /* Change DCMI state */\r
440       hdcmi->State = HAL_DCMI_STATE_ERROR;\r
441 \r
442       /* Process Unlocked */\r
443       __HAL_UNLOCK(hdcmi);\r
444 \r
445       /* Abort the DMA Transfer */\r
446       HAL_DMA_Abort(hdcmi->DMA_Handle);\r
447       \r
448       /* Synchronization error Callback */\r
449       HAL_DCMI_ErrorCallback(hdcmi);\r
450     }\r
451   }\r
452   /* Overflow interrupt management ********************************************/\r
453   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_OVFRI) != RESET) \r
454   {\r
455     if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_OVF) != RESET)\r
456     {\r
457       /* Disable the Overflow interrupt */\r
458       __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_OVF);\r
459 \r
460       /* Clear the Overflow flag */\r
461       __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVFRI);\r
462 \r
463       /* Update error code */\r
464       hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVF;\r
465 \r
466       /* Change DCMI state */\r
467       hdcmi->State = HAL_DCMI_STATE_ERROR;\r
468 \r
469       /* Process Unlocked */\r
470       __HAL_UNLOCK(hdcmi);\r
471 \r
472       /* Abort the DMA Transfer */\r
473       HAL_DMA_Abort(hdcmi->DMA_Handle);\r
474 \r
475       /* Overflow Callback */\r
476       HAL_DCMI_ErrorCallback(hdcmi);\r
477     }\r
478   }\r
479   /* Line Interrupt management ************************************************/\r
480   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_LINERI) != RESET)\r
481   {\r
482     if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_LINE) != RESET)\r
483     {\r
484       /* Clear the Line interrupt flag */  \r
485       __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);\r
486 \r
487       /* Process Unlocked */\r
488       __HAL_UNLOCK(hdcmi);\r
489 \r
490       /* Line interrupt Callback */\r
491       HAL_DCMI_LineEventCallback(hdcmi);\r
492     }\r
493   }\r
494   /* VSYNC interrupt management ***********************************************/\r
495   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_VSYNCRI) != RESET)\r
496   {\r
497     if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_VSYNC) != RESET)\r
498     {\r
499       /* Disable the VSYNC interrupt */\r
500       __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_VSYNC);   \r
501 \r
502       /* Clear the VSYNC flag */\r
503       __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);\r
504 \r
505       /* Process Unlocked */\r
506       __HAL_UNLOCK(hdcmi);\r
507 \r
508       /* VSYNC Callback */\r
509       HAL_DCMI_VsyncEventCallback(hdcmi);\r
510     }\r
511   }\r
512   /* End of Frame interrupt management ****************************************/\r
513   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)\r
514   {\r
515     if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_FRAME) != RESET)\r
516     {\r
517       /* Disable the End of Frame interrupt */\r
518       __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);\r
519 \r
520       /* Clear the End of Frame flag */\r
521       __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);\r
522 \r
523       /* Process Unlocked */\r
524       __HAL_UNLOCK(hdcmi);\r
525 \r
526       /* End of Frame Callback */\r
527       HAL_DCMI_FrameEventCallback(hdcmi);\r
528     }\r
529   }\r
530 }\r
531 \r
532 /**\r
533   * @brief  Error DCMI callback.\r
534   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
535   *                the configuration information for DCMI.\r
536   * @retval None\r
537   */\r
538 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)\r
539 {\r
540   /* NOTE : This function Should not be modified, when the callback is needed,\r
541             the HAL_DCMI_ErrorCallback could be implemented in the user file\r
542    */\r
543 }\r
544 \r
545 /**\r
546   * @brief  Line Event callback.\r
547   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
548   *                the configuration information for DCMI.\r
549   * @retval None\r
550   */\r
551 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)\r
552 {\r
553   /* NOTE : This function Should not be modified, when the callback is needed,\r
554             the HAL_DCMI_LineEventCallback could be implemented in the user file\r
555    */\r
556 }\r
557 \r
558 /**\r
559   * @brief  VSYNC Event callback.\r
560   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
561   *                the configuration information for DCMI.\r
562   * @retval None\r
563   */\r
564 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)\r
565 {\r
566   /* NOTE : This function Should not be modified, when the callback is needed,\r
567             the HAL_DCMI_VsyncEventCallback could be implemented in the user file\r
568    */\r
569 }\r
570 \r
571 /**\r
572   * @brief  Frame Event callback.\r
573   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
574   *                the configuration information for DCMI.\r
575   * @retval None\r
576   */\r
577 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)\r
578 {\r
579   /* NOTE : This function Should not be modified, when the callback is needed,\r
580             the HAL_DCMI_FrameEventCallback could be implemented in the user file\r
581    */\r
582 }\r
583 \r
584 /**\r
585   * @}\r
586   */\r
587 \r
588 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions\r
589  *  @brief    Peripheral Control functions \r
590  *\r
591 @verbatim   \r
592  ===============================================================================\r
593                     ##### Peripheral Control functions #####\r
594  ===============================================================================  \r
595 [..]  This section provides functions allowing to:\r
596       (+) Configure the CROP feature.\r
597       (+) Enable/Disable the CROP feature.\r
598                         (+) Enable/Disable the JPEG feature.\r
599 \r
600 @endverbatim\r
601   * @{\r
602   */\r
603 \r
604 /**\r
605   * @brief  Configure the DCMI CROP coordinate.\r
606   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
607   *                the configuration information for DCMI.\r
608   * @param  YSize: DCMI Line number\r
609   * @param  XSize: DCMI Pixel per line\r
610   * @param  X0:    DCMI window X offset\r
611   * @param  Y0:    DCMI window Y offset\r
612   * @retval HAL status\r
613   */\r
614 HAL_StatusTypeDef HAL_DCMI_ConfigCROP(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)\r
615 {\r
616   /* Process Locked */\r
617   __HAL_LOCK(hdcmi);\r
618 \r
619   /* Lock the DCMI peripheral state */\r
620   hdcmi->State = HAL_DCMI_STATE_BUSY;\r
621 \r
622   /* Check the parameters */\r
623   assert_param(IS_DCMI_WINDOW_COORDINATE(X0));\r
624   assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));\r
625   assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));\r
626   assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));\r
627         \r
628   /* Configure CROP */\r
629   DCMI->CWSIZER = (XSize | (YSize << 16));\r
630   DCMI->CWSTRTR = (X0 | (Y0 << 16));\r
631 \r
632   /* Initialize the DCMI state*/\r
633   hdcmi->State  = HAL_DCMI_STATE_READY;\r
634 \r
635   /* Process Unlocked */\r
636   __HAL_UNLOCK(hdcmi);\r
637 \r
638   return HAL_OK;\r
639 }\r
640 \r
641 /**\r
642   * @brief  Disable the Crop feature.\r
643   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
644   *                the configuration information for DCMI.\r
645   * @retval HAL status\r
646   */\r
647 HAL_StatusTypeDef HAL_DCMI_DisableCROP(DCMI_HandleTypeDef *hdcmi)\r
648 {\r
649   /* Process Locked */\r
650   __HAL_LOCK(hdcmi);\r
651 \r
652   /* Lock the DCMI peripheral state */\r
653   hdcmi->State = HAL_DCMI_STATE_BUSY;\r
654 \r
655   /* Disable DCMI Crop feature */\r
656   DCMI->CR &= ~(uint32_t)DCMI_CR_CROP;  \r
657 \r
658   /* Change the DCMI state*/\r
659   hdcmi->State = HAL_DCMI_STATE_READY;   \r
660 \r
661   /* Process Unlocked */\r
662   __HAL_UNLOCK(hdcmi);\r
663 \r
664   return HAL_OK;  \r
665 }\r
666 \r
667 /**\r
668   * @brief  Enable the Crop feature.\r
669   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
670   *                the configuration information for DCMI.\r
671   * @retval HAL status\r
672   */\r
673 HAL_StatusTypeDef HAL_DCMI_EnableCROP(DCMI_HandleTypeDef *hdcmi)\r
674 {\r
675   /* Process Locked */\r
676   __HAL_LOCK(hdcmi);\r
677 \r
678   /* Lock the DCMI peripheral state */\r
679   hdcmi->State = HAL_DCMI_STATE_BUSY;\r
680 \r
681   /* Enable DCMI Crop feature */\r
682   DCMI->CR |= (uint32_t)DCMI_CR_CROP;\r
683 \r
684   /* Change the DCMI state*/\r
685   hdcmi->State = HAL_DCMI_STATE_READY;\r
686 \r
687   /* Process Unlocked */\r
688   __HAL_UNLOCK(hdcmi);\r
689 \r
690   return HAL_OK;  \r
691 }\r
692 \r
693 /**\r
694   * @}\r
695   */\r
696 \r
697 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions\r
698  *  @brief    Peripheral State functions \r
699  *\r
700 @verbatim   \r
701  ===============================================================================\r
702                ##### Peripheral State and Errors functions #####\r
703  ===============================================================================  \r
704     [..]\r
705     This subsection provides functions allowing to\r
706       (+) Check the DCMI state.\r
707       (+) Get the specific DCMI error flag.  \r
708 \r
709 @endverbatim\r
710   * @{\r
711   */ \r
712 \r
713 /**\r
714   * @brief  Return the DCMI state\r
715   * @param  hdcmi: pointer to a DCMI_HandleTypeDef structure that contains\r
716   *                the configuration information for DCMI.\r
717   * @retval HAL state\r
718   */\r
719 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)  \r
720 {\r
721   return hdcmi->State;\r
722 }\r
723 \r
724 /**\r
725 * @brief  Return the DCMI error code\r
726 * @param  hdcmi : pointer to a DCMI_HandleTypeDef structure that contains\r
727   *               the configuration information for DCMI.\r
728 * @retval DCMI Error Code\r
729 */\r
730 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)\r
731 {\r
732   return hdcmi->ErrorCode;\r
733 }\r
734 \r
735 /**\r
736   * @}\r
737   */\r
738 /* Private functions ---------------------------------------------------------*/\r
739 /** @defgroup DCMI_Private_Functions DCMI Private Functions\r
740   * @{\r
741   */\r
742   /**\r
743   * @brief  DMA conversion complete callback. \r
744   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains\r
745   *                the configuration information for the specified DMA module.\r
746   * @retval None\r
747   */\r
748 static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma)\r
749 {\r
750   uint32_t tmp = 0;\r
751  \r
752   DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;\r
753   hdcmi->State= HAL_DCMI_STATE_READY;\r
754 \r
755   if(hdcmi->XferCount != 0)\r
756   {\r
757     /* Update memory 0 address location */\r
758     tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);\r
759     if(((hdcmi->XferCount % 2) == 0) && (tmp != 0))\r
760     {\r
761       tmp = hdcmi->DMA_Handle->Instance->M0AR;\r
762       HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY0);\r
763       hdcmi->XferCount--;\r
764     }\r
765     /* Update memory 1 address location */\r
766     else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)\r
767     {\r
768       tmp = hdcmi->DMA_Handle->Instance->M1AR;\r
769       HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY1);\r
770       hdcmi->XferCount--;\r
771     }\r
772   }\r
773   /* Update memory 0 address location */\r
774   else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0)\r
775   {\r
776     hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;\r
777   }\r
778   /* Update memory 1 address location */\r
779   else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)\r
780   {\r
781     tmp = hdcmi->pBuffPtr;\r
782     hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4*hdcmi->XferSize));\r
783     hdcmi->XferCount = hdcmi->XferTransferNumber;\r
784   }\r
785 \r
786   if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)\r
787   {\r
788     /* Process Unlocked */\r
789     __HAL_UNLOCK(hdcmi);\r
790 \r
791     /* FRAME Callback */\r
792     HAL_DCMI_FrameEventCallback(hdcmi);\r
793   }\r
794 }\r
795 \r
796 /**\r
797   * @brief  DMA error callback \r
798   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains\r
799   *                the configuration information for the specified DMA module.\r
800   * @retval None\r
801   */\r
802 static void DCMI_DMAError(DMA_HandleTypeDef *hdma)\r
803 {\r
804     DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;     \r
805     hdcmi->State= HAL_DCMI_STATE_READY;\r
806     HAL_DCMI_ErrorCallback(hdcmi);\r
807 }\r
808 \r
809 /**\r
810   * @}\r
811   */\r
812   \r
813 /**\r
814   * @}\r
815   */\r
816 #endif /* HAL_DCMI_MODULE_ENABLED */\r
817 /**\r
818   * @}\r
819   */\r
820 \r
821 /**\r
822   * @}\r
823   */\r
824 \r
825 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r