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