2 ******************************************************************************
3 * @file stm32f4xx_hal_dcmi.c
4 * @author MCD Application Team
7 * @brief DCMI HAL module driver
8 * This file provides firmware functions to manage the following
9 * functionalities of the Digital Camera Interface (DCMI) peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral Control functions
13 * + Peripheral State and Error functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 The sequence below describes how to use this driver to capture image
21 from a camera module connected to the DCMI Interface.
22 This sequence does not take into account the configuration of the
23 camera module, which should be made before to configure and enable
24 the DCMI to capture images.
26 (#) Program the required configuration through following parameters:
27 horizontal and vertical polarity, pixel clock polarity, Capture Rate,
28 Synchronization Mode, code of the frame delimiter and data width
29 using HAL_DCMI_Init() function.
31 (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR
32 register to the destination memory buffer.
34 (#) Program the required configuration through following parameters:
35 DCMI mode, destination memory Buffer address and the data length
36 and enable capture using HAL_DCMI_Start_DMA() function.
38 (#) Optionally, configure and Enable the CROP feature to select a rectangular
39 window from the received image using HAL_DCMI_ConfigCrop()
40 and HAL_DCMI_EnableCROP() functions
42 (#) The capture can be stopped using HAL_DCMI_Stop() function.
44 (#) To control DCMI state you can use the function HAL_DCMI_GetState().
46 *** DCMI HAL driver macros list ***
47 =============================================
49 Below the list of most used macros in DCMI HAL driver.
51 (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
52 (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
53 (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
54 (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
55 (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
56 (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
57 (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
60 (@) You can refer to the DCMI HAL driver header file for more useful macros
63 ******************************************************************************
66 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
68 * Redistribution and use in source and binary forms, with or without modification,
69 * are permitted provided that the following conditions are met:
70 * 1. Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * 3. Neither the name of STMicroelectronics nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90 ******************************************************************************
93 /* Includes ------------------------------------------------------------------*/
94 #include "stm32f4xx_hal.h"
96 /** @addtogroup STM32F4xx_HAL_Driver
99 /** @defgroup DCMI DCMI
100 * @brief DCMI HAL module driver
104 #ifdef HAL_DCMI_MODULE_ENABLED
106 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\
107 defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\
109 /* Private typedef -----------------------------------------------------------*/
110 /* Private define ------------------------------------------------------------*/
111 #define HAL_TIMEOUT_DCMI_STOP 14U /* Set timeout to 1s */
112 /* Private macro -------------------------------------------------------------*/
113 /* Private variables ---------------------------------------------------------*/
114 /* Private function prototypes -----------------------------------------------*/
115 static void DCMI_DMAXferCplt(DMA_HandleTypeDef
*hdma
);
116 static void DCMI_DMAError(DMA_HandleTypeDef
*hdma
);
118 /* Exported functions --------------------------------------------------------*/
120 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
124 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
125 * @brief Initialization and Configuration functions
128 ===============================================================================
129 ##### Initialization and Configuration functions #####
130 ===============================================================================
131 [..] This section provides functions allowing to:
132 (+) Initialize and configure the DCMI
133 (+) De-initialize the DCMI
140 * @brief Initializes the DCMI according to the specified
141 * parameters in the DCMI_InitTypeDef and create the associated handle.
142 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
143 * the configuration information for DCMI.
146 __weak HAL_StatusTypeDef
HAL_DCMI_Init(DCMI_HandleTypeDef
*hdcmi
)
148 /* Check the DCMI peripheral state */
154 /* Check function parameters */
155 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi
->Instance
));
156 assert_param(IS_DCMI_PCKPOLARITY(hdcmi
->Init
.PCKPolarity
));
157 assert_param(IS_DCMI_VSPOLARITY(hdcmi
->Init
.VSPolarity
));
158 assert_param(IS_DCMI_HSPOLARITY(hdcmi
->Init
.HSPolarity
));
159 assert_param(IS_DCMI_SYNCHRO(hdcmi
->Init
.SynchroMode
));
160 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi
->Init
.CaptureRate
));
161 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi
->Init
.ExtendedDataMode
));
162 assert_param(IS_DCMI_MODE_JPEG(hdcmi
->Init
.JPEGMode
));
164 if(hdcmi
->State
== HAL_DCMI_STATE_RESET
)
166 /* Allocate lock resource and initialize it */
167 hdcmi
->Lock
= HAL_UNLOCKED
;
168 /* Init the low level hardware */
169 HAL_DCMI_MspInit(hdcmi
);
172 /* Change the DCMI state */
173 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
175 /* Set DCMI parameters */
176 /* Configures the HS, VS, DE and PC polarity */
177 hdcmi
->Instance
->CR
&= ~(DCMI_CR_PCKPOL
| DCMI_CR_HSPOL
| DCMI_CR_VSPOL
| DCMI_CR_EDM_0
|
178 DCMI_CR_EDM_1
| DCMI_CR_FCRC_0
| DCMI_CR_FCRC_1
| DCMI_CR_JPEG
|
180 hdcmi
->Instance
->CR
|= (uint32_t)(hdcmi
->Init
.SynchroMode
| hdcmi
->Init
.CaptureRate
| \
181 hdcmi
->Init
.VSPolarity
| hdcmi
->Init
.HSPolarity
| \
182 hdcmi
->Init
.PCKPolarity
| hdcmi
->Init
.ExtendedDataMode
| \
183 hdcmi
->Init
.JPEGMode
);
185 if(hdcmi
->Init
.SynchroMode
== DCMI_SYNCHRO_EMBEDDED
)
187 hdcmi
->Instance
->ESCR
= (((uint32_t)hdcmi
->Init
.SyncroCode
.FrameStartCode
) |
188 ((uint32_t)hdcmi
->Init
.SyncroCode
.LineStartCode
<< DCMI_POSITION_ESCR_LSC
)|
189 ((uint32_t)hdcmi
->Init
.SyncroCode
.LineEndCode
<< DCMI_POSITION_ESCR_LEC
) |
190 ((uint32_t)hdcmi
->Init
.SyncroCode
.FrameEndCode
<< DCMI_POSITION_ESCR_FEC
));
193 /* Enable the Line, Vsync, Error and Overrun interrupts */
194 __HAL_DCMI_ENABLE_IT(hdcmi
, DCMI_IT_LINE
| DCMI_IT_VSYNC
| DCMI_IT_ERR
| DCMI_IT_OVR
);
196 /* Update error code */
197 hdcmi
->ErrorCode
= HAL_DCMI_ERROR_NONE
;
199 /* Initialize the DCMI state*/
200 hdcmi
->State
= HAL_DCMI_STATE_READY
;
206 * @brief Deinitializes the DCMI peripheral registers to their default reset
208 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
209 * the configuration information for DCMI.
213 HAL_StatusTypeDef
HAL_DCMI_DeInit(DCMI_HandleTypeDef
*hdcmi
)
215 /* DeInit the low level hardware */
216 HAL_DCMI_MspDeInit(hdcmi
);
218 /* Update error code */
219 hdcmi
->ErrorCode
= HAL_DCMI_ERROR_NONE
;
221 /* Initialize the DCMI state*/
222 hdcmi
->State
= HAL_DCMI_STATE_RESET
;
231 * @brief Initializes the DCMI MSP.
232 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
233 * the configuration information for DCMI.
236 __weak
void HAL_DCMI_MspInit(DCMI_HandleTypeDef
* hdcmi
)
238 /* Prevent unused argument(s) compilation warning */
240 /* NOTE : This function Should not be modified, when the callback is needed,
241 the HAL_DCMI_MspInit could be implemented in the user file
246 * @brief DeInitializes the DCMI MSP.
247 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
248 * the configuration information for DCMI.
251 __weak
void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef
* hdcmi
)
253 /* Prevent unused argument(s) compilation warning */
255 /* NOTE : This function Should not be modified, when the callback is needed,
256 the HAL_DCMI_MspDeInit could be implemented in the user file
263 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
264 * @brief IO operation functions
267 ===============================================================================
268 ##### IO operation functions #####
269 ===============================================================================
270 [..] This section provides functions allowing to:
271 (+) Configure destination address and data length and
272 Enables DCMI DMA request and enables DCMI capture
273 (+) Stop the DCMI capture.
274 (+) Handles DCMI interrupt request.
281 * @brief Enables DCMI DMA request and enables DCMI capture
282 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
283 * the configuration information for DCMI.
284 * @param DCMI_Mode: DCMI capture mode snapshot or continuous grab.
285 * @param pData: The destination memory Buffer address (LCD Frame buffer).
286 * @param Length: The length of capture to be transferred.
289 HAL_StatusTypeDef
HAL_DCMI_Start_DMA(DCMI_HandleTypeDef
* hdcmi
, uint32_t DCMI_Mode
, uint32_t pData
, uint32_t Length
)
291 /* Initialize the second memory address */
292 uint32_t SecondMemAddress
= 0U;
294 /* Check function parameters */
295 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode
));
300 /* Lock the DCMI peripheral state */
301 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
303 /* Enable DCMI by setting DCMIEN bit */
304 __HAL_DCMI_ENABLE(hdcmi
);
306 /* Configure the DCMI Mode */
307 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CM
);
308 hdcmi
->Instance
->CR
|= (uint32_t)(DCMI_Mode
);
310 /* Set the DMA memory0 conversion complete callback */
311 hdcmi
->DMA_Handle
->XferCpltCallback
= DCMI_DMAXferCplt
;
313 /* Set the DMA error callback */
314 hdcmi
->DMA_Handle
->XferErrorCallback
= DCMI_DMAError
;
316 /* Set the dma abort callback */
317 hdcmi
->DMA_Handle
->XferAbortCallback
= NULL
;
319 /* Reset transfer counters value */
320 hdcmi
->XferCount
= 0U;
321 hdcmi
->XferTransferNumber
= 0U;
323 if(Length
<= 0xFFFFU
)
325 /* Enable the DMA Stream */
326 HAL_DMA_Start_IT(hdcmi
->DMA_Handle
, (uint32_t)&hdcmi
->Instance
->DR
, (uint32_t)pData
, Length
);
328 else /* DCMI_DOUBLE_BUFFER Mode */
330 /* Set the DMA memory1 conversion complete callback */
331 hdcmi
->DMA_Handle
->XferM1CpltCallback
= DCMI_DMAXferCplt
;
333 /* Initialize transfer parameters */
334 hdcmi
->XferCount
= 1U;
335 hdcmi
->XferSize
= Length
;
336 hdcmi
->pBuffPtr
= pData
;
338 /* Get the number of buffer */
339 while(hdcmi
->XferSize
> 0xFFFFU
)
341 hdcmi
->XferSize
= (hdcmi
->XferSize
/2U);
342 hdcmi
->XferCount
= hdcmi
->XferCount
*2U;
345 /* Update DCMI counter and transfer number*/
346 hdcmi
->XferCount
= (hdcmi
->XferCount
- 2U);
347 hdcmi
->XferTransferNumber
= hdcmi
->XferCount
;
349 /* Update second memory address */
350 SecondMemAddress
= (uint32_t)(pData
+ (4U*hdcmi
->XferSize
));
352 /* Start DMA multi buffer transfer */
353 HAL_DMAEx_MultiBufferStart_IT(hdcmi
->DMA_Handle
, (uint32_t)&hdcmi
->Instance
->DR
, (uint32_t)pData
, SecondMemAddress
, hdcmi
->XferSize
);
357 hdcmi
->Instance
->CR
|= DCMI_CR_CAPTURE
;
362 /* Return function status */
367 * @brief Disable DCMI DMA request and Disable DCMI capture
368 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
369 * the configuration information for DCMI.
372 HAL_StatusTypeDef
HAL_DCMI_Stop(DCMI_HandleTypeDef
* hdcmi
)
374 __IO
uint32_t count
= SystemCoreClock
/ HAL_TIMEOUT_DCMI_STOP
;
375 HAL_StatusTypeDef status
= HAL_OK
;
380 /* Lock the DCMI peripheral state */
381 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
383 /* Disable Capture */
384 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CAPTURE
);
386 /* Check if the DCMI capture effectively disabled */
391 /* Update error code */
392 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_TIMEOUT
;
394 status
= HAL_TIMEOUT
;
397 while((hdcmi
->Instance
->CR
& DCMI_CR_CAPTURE
) != 0U);
399 /* Disable the DCMI */
400 __HAL_DCMI_DISABLE(hdcmi
);
402 /* Disable the DMA */
403 HAL_DMA_Abort(hdcmi
->DMA_Handle
);
405 /* Update error code */
406 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_NONE
;
408 /* Change DCMI state */
409 hdcmi
->State
= HAL_DCMI_STATE_READY
;
411 /* Process Unlocked */
414 /* Return function status */
419 * @brief Suspend DCMI capture
420 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
421 * the configuration information for DCMI.
424 HAL_StatusTypeDef
HAL_DCMI_Suspend(DCMI_HandleTypeDef
* hdcmi
)
426 __IO
uint32_t count
= SystemCoreClock
/ HAL_TIMEOUT_DCMI_STOP
;
427 HAL_StatusTypeDef status
= HAL_OK
;
432 if(hdcmi
->State
== HAL_DCMI_STATE_BUSY
)
434 /* Change DCMI state */
435 hdcmi
->State
= HAL_DCMI_STATE_SUSPENDED
;
437 /* Disable Capture */
438 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CAPTURE
);
440 /* Check if the DCMI capture effectively disabled */
445 /* Update error code */
446 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_TIMEOUT
;
448 /* Change DCMI state */
449 hdcmi
->State
= HAL_DCMI_STATE_READY
;
451 status
= HAL_TIMEOUT
;
455 while((hdcmi
->Instance
->CR
& DCMI_CR_CAPTURE
) != 0);
457 /* Process Unlocked */
460 /* Return function status */
465 * @brief Resume DCMI capture
466 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
467 * the configuration information for DCMI.
470 HAL_StatusTypeDef
HAL_DCMI_Resume(DCMI_HandleTypeDef
* hdcmi
)
475 if(hdcmi
->State
== HAL_DCMI_STATE_SUSPENDED
)
477 /* Change DCMI state */
478 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
480 /* Disable Capture */
481 hdcmi
->Instance
->CR
|= DCMI_CR_CAPTURE
;
483 /* Process Unlocked */
486 /* Return function status */
491 * @brief Handles DCMI interrupt request.
492 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
493 * the configuration information for the DCMI.
496 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef
*hdcmi
)
498 uint32_t isr_value
= READ_REG(hdcmi
->Instance
->MISR
);
500 /* Synchronization error interrupt management *******************************/
501 if((isr_value
& DCMI_FLAG_ERRRI
) == DCMI_FLAG_ERRRI
)
503 /* Clear the Synchronization error flag */
504 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_ERRRI
);
506 /* Update error code */
507 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_SYNC
;
509 /* Change DCMI state */
510 hdcmi
->State
= HAL_DCMI_STATE_ERROR
;
512 /* Set the synchronization error callback */
513 hdcmi
->DMA_Handle
->XferAbortCallback
= DCMI_DMAError
;
515 /* Abort the DMA Transfer */
516 HAL_DMA_Abort_IT(hdcmi
->DMA_Handle
);
518 /* Overflow interrupt management ********************************************/
519 if((isr_value
& DCMI_FLAG_OVRRI
) == DCMI_FLAG_OVRRI
)
521 /* Clear the Overflow flag */
522 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_OVRRI
);
524 /* Update error code */
525 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_OVR
;
527 /* Change DCMI state */
528 hdcmi
->State
= HAL_DCMI_STATE_ERROR
;
530 /* Set the overflow callback */
531 hdcmi
->DMA_Handle
->XferAbortCallback
= DCMI_DMAError
;
533 /* Abort the DMA Transfer */
534 HAL_DMA_Abort_IT(hdcmi
->DMA_Handle
);
536 /* Line Interrupt management ************************************************/
537 if((isr_value
& DCMI_FLAG_LINERI
) == DCMI_FLAG_LINERI
)
539 /* Clear the Line interrupt flag */
540 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_LINERI
);
542 /* Line interrupt Callback */
543 HAL_DCMI_LineEventCallback(hdcmi
);
545 /* VSYNC interrupt management ***********************************************/
546 if((isr_value
& DCMI_FLAG_VSYNCRI
) == DCMI_FLAG_VSYNCRI
)
548 /* Clear the VSYNC flag */
549 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_VSYNCRI
);
552 HAL_DCMI_VsyncEventCallback(hdcmi
);
554 /* FRAME interrupt management ***********************************************/
555 if((isr_value
& DCMI_FLAG_FRAMERI
) == DCMI_FLAG_FRAMERI
)
557 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
558 if((hdcmi
->Instance
->CR
& DCMI_CR_CM
) == DCMI_MODE_SNAPSHOT
)
560 /* Disable the Line, Vsync, Error and Overrun interrupts */
561 __HAL_DCMI_DISABLE_IT(hdcmi
, DCMI_IT_LINE
| DCMI_IT_VSYNC
| DCMI_IT_ERR
| DCMI_IT_OVR
);
564 /* Disable the Frame interrupt */
565 __HAL_DCMI_DISABLE_IT(hdcmi
, DCMI_IT_FRAME
);
568 HAL_DCMI_FrameEventCallback(hdcmi
);
573 * @brief Error DCMI callback.
574 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
575 * the configuration information for DCMI.
578 __weak
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef
*hdcmi
)
580 /* Prevent unused argument(s) compilation warning */
582 /* NOTE : This function Should not be modified, when the callback is needed,
583 the HAL_DCMI_ErrorCallback could be implemented in the user file
588 * @brief Line Event callback.
589 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
590 * the configuration information for DCMI.
593 __weak
void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef
*hdcmi
)
595 /* Prevent unused argument(s) compilation warning */
597 /* NOTE : This function Should not be modified, when the callback is needed,
598 the HAL_DCMI_LineEventCallback could be implemented in the user file
603 * @brief VSYNC Event callback.
604 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
605 * the configuration information for DCMI.
608 __weak
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef
*hdcmi
)
610 /* Prevent unused argument(s) compilation warning */
612 /* NOTE : This function Should not be modified, when the callback is needed,
613 the HAL_DCMI_VsyncEventCallback could be implemented in the user file
618 * @brief Frame Event callback.
619 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
620 * the configuration information for DCMI.
623 __weak
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef
*hdcmi
)
625 /* Prevent unused argument(s) compilation warning */
627 /* NOTE : This function Should not be modified, when the callback is needed,
628 the HAL_DCMI_FrameEventCallback could be implemented in the user file
636 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
637 * @brief Peripheral Control functions
640 ===============================================================================
641 ##### Peripheral Control functions #####
642 ===============================================================================
643 [..] This section provides functions allowing to:
644 (+) Configure the CROP feature.
645 (+) Enable/Disable the CROP feature.
652 * @brief Configure the DCMI CROP coordinate.
653 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
654 * the configuration information for DCMI.
655 * @param X0: DCMI window X offset
656 * @param Y0: DCMI window Y offset
657 * @param XSize: DCMI Pixel per line
658 * @param YSize: DCMI Line number
661 HAL_StatusTypeDef
HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef
*hdcmi
, uint32_t X0
, uint32_t Y0
, uint32_t XSize
, uint32_t YSize
)
666 /* Lock the DCMI peripheral state */
667 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
669 /* Check the parameters */
670 assert_param(IS_DCMI_WINDOW_COORDINATE(X0
));
671 assert_param(IS_DCMI_WINDOW_COORDINATE(YSize
));
672 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize
));
673 assert_param(IS_DCMI_WINDOW_HEIGHT(Y0
));
676 hdcmi
->Instance
->CWSIZER
= (XSize
| (YSize
<< DCMI_POSITION_CWSIZE_VLINE
));
677 hdcmi
->Instance
->CWSTRTR
= (X0
| (Y0
<< DCMI_POSITION_CWSTRT_VST
));
679 /* Initialize the DCMI state*/
680 hdcmi
->State
= HAL_DCMI_STATE_READY
;
682 /* Process Unlocked */
689 * @brief Disable the Crop feature.
690 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
691 * the configuration information for DCMI.
694 HAL_StatusTypeDef
HAL_DCMI_DisableCrop(DCMI_HandleTypeDef
*hdcmi
)
699 /* Lock the DCMI peripheral state */
700 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
702 /* Disable DCMI Crop feature */
703 hdcmi
->Instance
->CR
&= ~(uint32_t)DCMI_CR_CROP
;
705 /* Change the DCMI state*/
706 hdcmi
->State
= HAL_DCMI_STATE_READY
;
708 /* Process Unlocked */
715 * @brief Enable the Crop feature.
716 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
717 * the configuration information for DCMI.
720 HAL_StatusTypeDef
HAL_DCMI_EnableCrop(DCMI_HandleTypeDef
*hdcmi
)
725 /* Lock the DCMI peripheral state */
726 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
728 /* Enable DCMI Crop feature */
729 hdcmi
->Instance
->CR
|= (uint32_t)DCMI_CR_CROP
;
731 /* Change the DCMI state*/
732 hdcmi
->State
= HAL_DCMI_STATE_READY
;
734 /* Process Unlocked */
744 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
745 * @brief Peripheral State functions
748 ===============================================================================
749 ##### Peripheral State and Errors functions #####
750 ===============================================================================
752 This subsection provides functions allowing to
753 (+) Check the DCMI state.
754 (+) Get the specific DCMI error flag.
761 * @brief Return the DCMI state
762 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
763 * the configuration information for DCMI.
766 HAL_DCMI_StateTypeDef
HAL_DCMI_GetState(DCMI_HandleTypeDef
*hdcmi
)
772 * @brief Return the DCMI error code
773 * @param hdcmi : pointer to a DCMI_HandleTypeDef structure that contains
774 * the configuration information for DCMI.
775 * @retval DCMI Error Code
777 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef
*hdcmi
)
779 return hdcmi
->ErrorCode
;
786 /* Private functions ---------------------------------------------------------*/
787 /** @defgroup DCMI_Private_Functions DCMI Private Functions
792 * @brief DMA conversion complete callback.
793 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
794 * the configuration information for the specified DMA module.
797 static void DCMI_DMAXferCplt(DMA_HandleTypeDef
*hdma
)
801 DCMI_HandleTypeDef
* hdcmi
= ( DCMI_HandleTypeDef
* )((DMA_HandleTypeDef
* )hdma
)->Parent
;
803 if(hdcmi
->XferCount
!= 0U)
805 /* Update memory 0 address location */
806 tmp
= ((hdcmi
->DMA_Handle
->Instance
->CR
) & DMA_SxCR_CT
);
807 if(((hdcmi
->XferCount
% 2U) == 0U) && (tmp
!= 0U))
809 tmp
= hdcmi
->DMA_Handle
->Instance
->M0AR
;
810 HAL_DMAEx_ChangeMemory(hdcmi
->DMA_Handle
, (tmp
+ (8U*hdcmi
->XferSize
)), MEMORY0
);
813 /* Update memory 1 address location */
814 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) == 0U)
816 tmp
= hdcmi
->DMA_Handle
->Instance
->M1AR
;
817 HAL_DMAEx_ChangeMemory(hdcmi
->DMA_Handle
, (tmp
+ (8U*hdcmi
->XferSize
)), MEMORY1
);
821 /* Update memory 0 address location */
822 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) != 0U)
824 hdcmi
->DMA_Handle
->Instance
->M0AR
= hdcmi
->pBuffPtr
;
826 /* Update memory 1 address location */
827 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) == 0U)
829 tmp
= hdcmi
->pBuffPtr
;
830 hdcmi
->DMA_Handle
->Instance
->M1AR
= (tmp
+ (4U*hdcmi
->XferSize
));
831 hdcmi
->XferCount
= hdcmi
->XferTransferNumber
;
834 /* Check if the frame is transferred */
835 if(hdcmi
->XferCount
== hdcmi
->XferTransferNumber
)
837 /* Enable the Frame interrupt */
838 __HAL_DCMI_ENABLE_IT(hdcmi
, DCMI_IT_FRAME
);
840 /* When snapshot mode, set dcmi state to ready */
841 if((hdcmi
->Instance
->CR
& DCMI_CR_CM
) == DCMI_MODE_SNAPSHOT
)
843 hdcmi
->State
= HAL_DCMI_STATE_READY
;
849 * @brief DMA error callback
850 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
851 * the configuration information for the specified DMA module.
854 static void DCMI_DMAError(DMA_HandleTypeDef
*hdma
)
856 DCMI_HandleTypeDef
* hdcmi
= ( DCMI_HandleTypeDef
* )((DMA_HandleTypeDef
* )hdma
)->Parent
;
858 if(hdcmi
->DMA_Handle
->ErrorCode
!= HAL_DMA_ERROR_FE
)
860 /* Initialize the DCMI state*/
861 hdcmi
->State
= HAL_DCMI_STATE_READY
;
864 /* DCMI error Callback */
865 HAL_DCMI_ErrorCallback(hdcmi
);
875 #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
876 STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
878 #endif /* HAL_DCMI_MODULE_ENABLED */
887 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/