2 ******************************************************************************
3 * @file stm32f7xx_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) 2016 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 "stm32f7xx_hal.h"
96 /** @addtogroup STM32F7xx_HAL_Driver
99 /** @defgroup DCMI DCMI
100 * @brief DCMI HAL module driver
104 #ifdef HAL_DCMI_MODULE_ENABLED
106 /* Private typedef -----------------------------------------------------------*/
107 /* Private define ------------------------------------------------------------*/
108 #define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* Set timeout to 1s */
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 */
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 */
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
);
123 /* Exported functions --------------------------------------------------------*/
125 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
129 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
130 * @brief Initialization and Configuration functions
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
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.
151 HAL_StatusTypeDef
HAL_DCMI_Init(DCMI_HandleTypeDef
*hdcmi
)
153 /* Check the DCMI peripheral state */
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
));
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
));
174 if(hdcmi
->State
== HAL_DCMI_STATE_RESET
)
176 /* Init the low level hardware */
177 HAL_DCMI_MspInit(hdcmi
);
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
);
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
);
195 if(hdcmi
->Init
.SynchroMode
== DCMI_SYNCHRO_EMBEDDED
)
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
));
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
);
207 /* Update error code */
208 hdcmi
->ErrorCode
= HAL_DCMI_ERROR_NONE
;
210 /* Initialize the DCMI state*/
211 hdcmi
->State
= HAL_DCMI_STATE_READY
;
217 * @brief Deinitializes the DCMI peripheral registers to their default reset
219 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
220 * the configuration information for DCMI.
224 HAL_StatusTypeDef
HAL_DCMI_DeInit(DCMI_HandleTypeDef
*hdcmi
)
226 /* DeInit the low level hardware */
227 HAL_DCMI_MspDeInit(hdcmi
);
229 /* Update error code */
230 hdcmi
->ErrorCode
= HAL_DCMI_ERROR_NONE
;
232 /* Initialize the DCMI state*/
233 hdcmi
->State
= HAL_DCMI_STATE_RESET
;
242 * @brief Initializes the DCMI MSP.
243 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
244 * the configuration information for DCMI.
247 __weak
void HAL_DCMI_MspInit(DCMI_HandleTypeDef
* hdcmi
)
249 /* Prevent unused argument(s) compilation warning */
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
258 * @brief DeInitializes the DCMI MSP.
259 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
260 * the configuration information for DCMI.
263 __weak
void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef
* hdcmi
)
265 /* Prevent unused argument(s) compilation warning */
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
276 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
277 * @brief IO operation functions
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.
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.
302 HAL_StatusTypeDef
HAL_DCMI_Start_DMA(DCMI_HandleTypeDef
* hdcmi
, uint32_t DCMI_Mode
, uint32_t pData
, uint32_t Length
)
304 /* Initialize the second memory address */
305 uint32_t SecondMemAddress
= 0;
307 /* Check function parameters */
308 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode
));
313 /* Lock the DCMI peripheral state */
314 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
316 /* Enable DCMI by setting DCMIEN bit */
317 __HAL_DCMI_ENABLE(hdcmi
);
319 /* Configure the DCMI Mode */
320 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CM
);
321 hdcmi
->Instance
->CR
|= (uint32_t)(DCMI_Mode
);
323 /* Set the DMA memory0 conversion complete callback */
324 hdcmi
->DMA_Handle
->XferCpltCallback
= DCMI_DMAXferCplt
;
326 /* Set the DMA error callback */
327 hdcmi
->DMA_Handle
->XferErrorCallback
= DCMI_DMAError
;
329 /* Set the dma abort callback */
330 hdcmi
->DMA_Handle
->XferAbortCallback
= NULL
;
332 /* Reset transfer counters value */
333 hdcmi
->XferCount
= 0;
334 hdcmi
->XferTransferNumber
= 0;
338 /* Enable the DMA Stream */
339 HAL_DMA_Start_IT(hdcmi
->DMA_Handle
, (uint32_t)&hdcmi
->Instance
->DR
, (uint32_t)pData
, Length
);
341 else /* DCMI_DOUBLE_BUFFER Mode */
343 /* Set the DMA memory1 conversion complete callback */
344 hdcmi
->DMA_Handle
->XferM1CpltCallback
= DCMI_DMAXferCplt
;
346 /* Initialize transfer parameters */
347 hdcmi
->XferCount
= 1;
348 hdcmi
->XferSize
= Length
;
349 hdcmi
->pBuffPtr
= pData
;
351 /* Get the number of buffer */
352 while(hdcmi
->XferSize
> 0xFFFF)
354 hdcmi
->XferSize
= (hdcmi
->XferSize
/2);
355 hdcmi
->XferCount
= hdcmi
->XferCount
*2;
358 /* Update DCMI counter and transfer number*/
359 hdcmi
->XferCount
= (hdcmi
->XferCount
- 2);
360 hdcmi
->XferTransferNumber
= hdcmi
->XferCount
;
362 /* Update second memory address */
363 SecondMemAddress
= (uint32_t)(pData
+ (4*hdcmi
->XferSize
));
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
);
370 hdcmi
->Instance
->CR
|= DCMI_CR_CAPTURE
;
375 /* Return function status */
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.
385 HAL_StatusTypeDef
HAL_DCMI_Stop(DCMI_HandleTypeDef
* hdcmi
)
387 register uint32_t count
= HAL_TIMEOUT_DCMI_STOP
* (SystemCoreClock
/8/1000);
388 HAL_StatusTypeDef status
= HAL_OK
;
393 /* Lock the DCMI peripheral state */
394 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
396 /* Disable Capture */
397 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CAPTURE
);
399 /* Check if the DCMI capture effectively disabled */
404 /* Update error code */
405 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_TIMEOUT
;
407 status
= HAL_TIMEOUT
;
411 while((hdcmi
->Instance
->CR
& DCMI_CR_CAPTURE
) != 0);
413 /* Disable the DCMI */
414 __HAL_DCMI_DISABLE(hdcmi
);
416 /* Disable the DMA */
417 HAL_DMA_Abort(hdcmi
->DMA_Handle
);
419 /* Update error code */
420 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_NONE
;
422 /* Change DCMI state */
423 hdcmi
->State
= HAL_DCMI_STATE_READY
;
425 /* Process Unlocked */
428 /* Return function status */
433 * @brief Suspend DCMI capture
434 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
435 * the configuration information for DCMI.
438 HAL_StatusTypeDef
HAL_DCMI_Suspend(DCMI_HandleTypeDef
* hdcmi
)
440 register uint32_t count
= HAL_TIMEOUT_DCMI_STOP
* (SystemCoreClock
/8/1000);
441 HAL_StatusTypeDef status
= HAL_OK
;
446 if(hdcmi
->State
== HAL_DCMI_STATE_BUSY
)
448 /* Change DCMI state */
449 hdcmi
->State
= HAL_DCMI_STATE_SUSPENDED
;
451 /* Disable Capture */
452 hdcmi
->Instance
->CR
&= ~(DCMI_CR_CAPTURE
);
454 /* Check if the DCMI capture effectively disabled */
459 /* Update error code */
460 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_TIMEOUT
;
462 /* Change DCMI state */
463 hdcmi
->State
= HAL_DCMI_STATE_READY
;
465 status
= HAL_TIMEOUT
;
469 while((hdcmi
->Instance
->CR
& DCMI_CR_CAPTURE
) != 0);
471 /* Process Unlocked */
474 /* Return function status */
479 * @brief Resume DCMI capture
480 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
481 * the configuration information for DCMI.
484 HAL_StatusTypeDef
HAL_DCMI_Resume(DCMI_HandleTypeDef
* hdcmi
)
489 if(hdcmi
->State
== HAL_DCMI_STATE_SUSPENDED
)
491 /* Change DCMI state */
492 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
494 /* Disable Capture */
495 hdcmi
->Instance
->CR
|= DCMI_CR_CAPTURE
;
497 /* Process Unlocked */
500 /* Return function status */
505 * @brief Handles DCMI interrupt request.
506 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
507 * the configuration information for the DCMI.
510 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef
*hdcmi
)
512 uint32_t isr_value
= READ_REG(hdcmi
->Instance
->MISR
);
514 /* Synchronization error interrupt management *******************************/
515 if((isr_value
& DCMI_FLAG_ERRRI
) == DCMI_FLAG_ERRRI
)
517 /* Clear the Synchronization error flag */
518 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_ERRRI
);
520 /* Update error code */
521 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_SYNC
;
523 /* Change DCMI state */
524 hdcmi
->State
= HAL_DCMI_STATE_ERROR
;
526 /* Set the synchronization error callback */
527 hdcmi
->DMA_Handle
->XferAbortCallback
= DCMI_DMAError
;
529 /* Abort the DMA Transfer */
530 HAL_DMA_Abort_IT(hdcmi
->DMA_Handle
);
532 /* Overflow interrupt management ********************************************/
533 if((isr_value
& DCMI_FLAG_OVRRI
) == DCMI_FLAG_OVRRI
)
535 /* Clear the Overflow flag */
536 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_OVRRI
);
538 /* Update error code */
539 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_OVR
;
541 /* Change DCMI state */
542 hdcmi
->State
= HAL_DCMI_STATE_ERROR
;
544 /* Set the overflow callback */
545 hdcmi
->DMA_Handle
->XferAbortCallback
= DCMI_DMAError
;
547 /* Abort the DMA Transfer */
548 HAL_DMA_Abort_IT(hdcmi
->DMA_Handle
);
550 /* Line Interrupt management ************************************************/
551 if((isr_value
& DCMI_FLAG_LINERI
) == DCMI_FLAG_LINERI
)
553 /* Clear the Line interrupt flag */
554 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_LINERI
);
556 /* Line interrupt Callback */
557 HAL_DCMI_LineEventCallback(hdcmi
);
559 /* VSYNC interrupt management ***********************************************/
560 if((isr_value
& DCMI_FLAG_VSYNCRI
) == DCMI_FLAG_VSYNCRI
)
562 /* Clear the VSYNC flag */
563 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_VSYNCRI
);
566 HAL_DCMI_VsyncEventCallback(hdcmi
);
568 /* FRAME interrupt management ***********************************************/
569 if((isr_value
& DCMI_FLAG_FRAMERI
) == DCMI_FLAG_FRAMERI
)
571 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
572 if((hdcmi
->Instance
->CR
& DCMI_CR_CM
) == DCMI_MODE_SNAPSHOT
)
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
);
578 /* Disable the Frame interrupt */
579 __HAL_DCMI_DISABLE_IT(hdcmi
, DCMI_IT_FRAME
);
581 /* Clear the End of Frame flag */
582 __HAL_DCMI_CLEAR_FLAG(hdcmi
, DCMI_FLAG_FRAMERI
);
585 HAL_DCMI_FrameEventCallback(hdcmi
);
590 * @brief Error DCMI callback.
591 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
592 * the configuration information for DCMI.
595 __weak
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef
*hdcmi
)
597 /* Prevent unused argument(s) compilation warning */
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
606 * @brief Line Event callback.
607 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
608 * the configuration information for DCMI.
611 __weak
void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef
*hdcmi
)
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
619 * @brief VSYNC Event callback.
620 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
621 * the configuration information for DCMI.
624 __weak
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef
*hdcmi
)
626 /* Prevent unused argument(s) compilation warning */
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
635 * @brief Frame Event callback.
636 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
637 * the configuration information for DCMI.
640 __weak
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef
*hdcmi
)
642 /* Prevent unused argument(s) compilation warning */
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
654 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
655 * @brief Peripheral Control functions
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.
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
680 HAL_StatusTypeDef
HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef
*hdcmi
, uint32_t X0
, uint32_t Y0
, uint32_t XSize
, uint32_t YSize
)
685 /* Lock the DCMI peripheral state */
686 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
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
));
695 hdcmi
->Instance
->CWSIZER
= (XSize
| (YSize
<< DCMI_POSITION_CWSIZE_VLINE
));
696 hdcmi
->Instance
->CWSTRTR
= (X0
| (Y0
<< DCMI_POSITION_CWSTRT_VST
));
698 /* Initialize the DCMI state*/
699 hdcmi
->State
= HAL_DCMI_STATE_READY
;
701 /* Process Unlocked */
708 * @brief Disable the Crop feature.
709 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
710 * the configuration information for DCMI.
713 HAL_StatusTypeDef
HAL_DCMI_DisableCrop(DCMI_HandleTypeDef
*hdcmi
)
718 /* Lock the DCMI peripheral state */
719 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
721 /* Disable DCMI Crop feature */
722 hdcmi
->Instance
->CR
&= ~(uint32_t)DCMI_CR_CROP
;
724 /* Change the DCMI state*/
725 hdcmi
->State
= HAL_DCMI_STATE_READY
;
727 /* Process Unlocked */
734 * @brief Enable the Crop feature.
735 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
736 * the configuration information for DCMI.
739 HAL_StatusTypeDef
HAL_DCMI_EnableCrop(DCMI_HandleTypeDef
*hdcmi
)
744 /* Lock the DCMI peripheral state */
745 hdcmi
->State
= HAL_DCMI_STATE_BUSY
;
747 /* Enable DCMI Crop feature */
748 hdcmi
->Instance
->CR
|= (uint32_t)DCMI_CR_CROP
;
750 /* Change the DCMI state*/
751 hdcmi
->State
= HAL_DCMI_STATE_READY
;
753 /* Process Unlocked */
763 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
764 * @brief Peripheral State functions
767 ===============================================================================
768 ##### Peripheral State and Errors functions #####
769 ===============================================================================
771 This subsection provides functions allowing to
772 (+) Check the DCMI state.
773 (+) Get the specific DCMI error flag.
780 * @brief Return the DCMI state
781 * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
782 * the configuration information for DCMI.
785 HAL_DCMI_StateTypeDef
HAL_DCMI_GetState(DCMI_HandleTypeDef
*hdcmi
)
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
796 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef
*hdcmi
)
798 return hdcmi
->ErrorCode
;
804 /* Private functions ---------------------------------------------------------*/
805 /** @defgroup DCMI_Private_Functions DCMI Private Functions
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.
814 static void DCMI_DMAXferCplt(DMA_HandleTypeDef
*hdma
)
818 DCMI_HandleTypeDef
* hdcmi
= ( DCMI_HandleTypeDef
* )((DMA_HandleTypeDef
* )hdma
)->Parent
;
820 if(hdcmi
->XferCount
!= 0)
822 /* Update memory 0 address location */
823 tmp
= ((hdcmi
->DMA_Handle
->Instance
->CR
) & DMA_SxCR_CT
);
824 if(((hdcmi
->XferCount
% 2) == 0) && (tmp
!= 0))
826 tmp
= hdcmi
->DMA_Handle
->Instance
->M0AR
;
827 HAL_DMAEx_ChangeMemory(hdcmi
->DMA_Handle
, (tmp
+ (8*hdcmi
->XferSize
)), MEMORY0
);
830 /* Update memory 1 address location */
831 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) == 0)
833 tmp
= hdcmi
->DMA_Handle
->Instance
->M1AR
;
834 HAL_DMAEx_ChangeMemory(hdcmi
->DMA_Handle
, (tmp
+ (8*hdcmi
->XferSize
)), MEMORY1
);
838 /* Update memory 0 address location */
839 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) != 0)
841 hdcmi
->DMA_Handle
->Instance
->M0AR
= hdcmi
->pBuffPtr
;
843 /* Update memory 1 address location */
844 else if((hdcmi
->DMA_Handle
->Instance
->CR
& DMA_SxCR_CT
) == 0)
846 tmp
= hdcmi
->pBuffPtr
;
847 hdcmi
->DMA_Handle
->Instance
->M1AR
= (tmp
+ (4*hdcmi
->XferSize
));
848 hdcmi
->XferCount
= hdcmi
->XferTransferNumber
;
851 /* Check if the frame is transferred */
852 if(hdcmi
->XferCount
== hdcmi
->XferTransferNumber
)
854 /* Enable the Frame interrupt */
855 __HAL_DCMI_ENABLE_IT(hdcmi
, DCMI_IT_FRAME
);
857 /* When snapshot mode, set dcmi state to ready */
858 if((hdcmi
->Instance
->CR
& DCMI_CR_CM
) == DCMI_MODE_SNAPSHOT
)
860 hdcmi
->State
= HAL_DCMI_STATE_READY
;
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.
871 static void DCMI_DMAError(DMA_HandleTypeDef
*hdma
)
873 DCMI_HandleTypeDef
* hdcmi
= ( DCMI_HandleTypeDef
* )((DMA_HandleTypeDef
* )hdma
)->Parent
;
875 if(hdcmi
->DMA_Handle
->ErrorCode
!= HAL_DMA_ERROR_FE
)
877 /* Initialize the DCMI state*/
878 hdcmi
->State
= HAL_DCMI_STATE_READY
;
880 /* Set DCMI Error Code */
881 hdcmi
->ErrorCode
|= HAL_DCMI_ERROR_DMA
;
884 /* DCMI error Callback */
885 HAL_DCMI_ErrorCallback(hdcmi
);
895 #endif /* HAL_DCMI_MODULE_ENABLED */
904 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/