2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_dcmi.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-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
16 ==============================================================================
\r
17 ##### How to use this driver #####
\r
18 ==============================================================================
\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
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
31 (#) Configure the DMA2_Stream1 channel1 to transfer Data from DCMI DR
\r
32 register to the destination memory buffer.
\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
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
42 (#) The capture can be stopped using HAL_DCMI_Stop() function.
\r
44 (#) To control DCMI state you can use the function HAL_DCMI_GetState().
\r
46 *** DCMI HAL driver macros list ***
\r
47 =============================================
\r
49 Below the list of most used macros in DCMI HAL driver.
\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
60 (@) You can refer to the DCMI HAL driver header file for more useful macros
\r
63 ******************************************************************************
\r
66 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\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
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
90 ******************************************************************************
\r
93 /* Includes ------------------------------------------------------------------*/
\r
94 #include "stm32f7xx_hal.h"
\r
96 /** @addtogroup STM32F7xx_HAL_Driver
\r
99 /** @defgroup DCMI DCMI
\r
100 * @brief DCMI HAL module driver
\r
104 #ifdef HAL_DCMI_MODULE_ENABLED
\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
115 /* Exported functions --------------------------------------------------------*/
\r
117 /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
\r
121 /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
\r
122 * @brief Initialization and Configuration functions
\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
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
143 __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
\r
145 /* Check the DCMI peripheral state */
\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
161 if(hdcmi->State == HAL_DCMI_STATE_RESET)
\r
163 /* Init the low level hardware */
\r
164 HAL_DCMI_MspInit(hdcmi);
\r
167 /* Change the DCMI state */
\r
168 hdcmi->State = HAL_DCMI_STATE_BUSY;
\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
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
180 if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
\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
188 /* Enable the Line interrupt */
\r
189 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE);
\r
191 /* Enable the VSYNC interrupt */
\r
192 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC);
\r
194 /* Enable the Frame capture complete interrupt */
\r
195 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
\r
197 /* Enable the Synchronization error interrupt */
\r
198 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR);
\r
200 /* Enable the Overflow interrupt */
\r
201 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF);
\r
203 /* Enable DCMI by setting DCMIEN bit */
\r
204 __HAL_DCMI_ENABLE(hdcmi);
\r
206 /* Update error code */
\r
207 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
\r
209 /* Initialize the DCMI state*/
\r
210 hdcmi->State = HAL_DCMI_STATE_READY;
\r
216 * @brief Deinitializes the DCMI peripheral registers to their default reset
\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
223 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
\r
225 /* DeInit the low level hardware */
\r
226 HAL_DCMI_MspDeInit(hdcmi);
\r
228 /* Update error code */
\r
229 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
\r
231 /* Initialize the DCMI state*/
\r
232 hdcmi->State = HAL_DCMI_STATE_RESET;
\r
235 __HAL_UNLOCK(hdcmi);
\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
246 __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
\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
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
259 __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
\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
269 /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
\r
270 * @brief IO operation functions
\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
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
295 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
\r
297 /* Initialize the second memory address */
\r
298 uint32_t SecondMemAddress = 0;
\r
300 /* Check function parameters */
\r
301 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
\r
303 /* Process Locked */
\r
306 /* Lock the DCMI peripheral state */
\r
307 hdcmi->State = HAL_DCMI_STATE_BUSY;
\r
309 /* Check the parameters */
\r
310 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
\r
312 /* Configure the DCMI Mode */
\r
313 hdcmi->Instance->CR &= ~(DCMI_CR_CM);
\r
314 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
\r
316 /* Set the DMA memory0 conversion complete callback */
\r
317 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAConvCplt;
\r
319 /* Set the DMA error callback */
\r
320 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
\r
322 if(Length <= 0xFFFF)
\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
327 else /* DCMI_DOUBLE_BUFFER Mode */
\r
329 /* Set the DMA memory1 conversion complete callback */
\r
330 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAConvCplt;
\r
332 /* Initialize transfer parameters */
\r
333 hdcmi->XferCount = 1;
\r
334 hdcmi->XferSize = Length;
\r
335 hdcmi->pBuffPtr = pData;
\r
337 /* Get the number of buffer */
\r
338 while(hdcmi->XferSize > 0xFFFF)
\r
340 hdcmi->XferSize = (hdcmi->XferSize/2);
\r
341 hdcmi->XferCount = hdcmi->XferCount*2;
\r
344 /* Update DCMI counter and transfer number*/
\r
345 hdcmi->XferCount = (hdcmi->XferCount - 2);
\r
346 hdcmi->XferTransferNumber = hdcmi->XferCount;
\r
348 /* Update second memory address */
\r
349 SecondMemAddress = (uint32_t)(pData + (4*hdcmi->XferSize));
\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
355 /* Enable Capture */
\r
356 DCMI->CR |= DCMI_CR_CAPTURE;
\r
358 /* Return function status */
\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
368 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
\r
370 uint32_t tickstart = 0;
\r
372 /* Lock the DCMI peripheral state */
\r
373 hdcmi->State = HAL_DCMI_STATE_BUSY;
\r
375 __HAL_DCMI_DISABLE(hdcmi);
\r
377 /* Disable Capture */
\r
378 DCMI->CR &= ~(DCMI_CR_CAPTURE);
\r
381 tickstart = HAL_GetTick();
\r
383 /* Check if the DCMI capture effectively disabled */
\r
384 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0)
\r
386 if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DCMI_STOP)
\r
388 /* Process Unlocked */
\r
389 __HAL_UNLOCK(hdcmi);
\r
391 /* Update error code */
\r
392 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
\r
394 /* Change DCMI state */
\r
395 hdcmi->State = HAL_DCMI_STATE_TIMEOUT;
\r
397 return HAL_TIMEOUT;
\r
401 /* Disable the DMA */
\r
402 HAL_DMA_Abort(hdcmi->DMA_Handle);
\r
404 /* Update error code */
\r
405 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
\r
407 /* Change DCMI state */
\r
408 hdcmi->State = HAL_DCMI_STATE_READY;
\r
410 /* Process Unlocked */
\r
411 __HAL_UNLOCK(hdcmi);
\r
413 /* Return function status */
\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
423 void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
\r
425 /* Synchronization error interrupt management *******************************/
\r
426 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_ERRRI) != RESET)
\r
428 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_ERR) != RESET)
\r
430 /* Disable the Synchronization error interrupt */
\r
431 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_ERR);
\r
433 /* Clear the Synchronization error flag */
\r
434 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
\r
436 /* Update error code */
\r
437 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
\r
439 /* Change DCMI state */
\r
440 hdcmi->State = HAL_DCMI_STATE_ERROR;
\r
442 /* Process Unlocked */
\r
443 __HAL_UNLOCK(hdcmi);
\r
445 /* Abort the DMA Transfer */
\r
446 HAL_DMA_Abort(hdcmi->DMA_Handle);
\r
448 /* Synchronization error Callback */
\r
449 HAL_DCMI_ErrorCallback(hdcmi);
\r
452 /* Overflow interrupt management ********************************************/
\r
453 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_OVFRI) != RESET)
\r
455 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_OVF) != RESET)
\r
457 /* Disable the Overflow interrupt */
\r
458 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_OVF);
\r
460 /* Clear the Overflow flag */
\r
461 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVFRI);
\r
463 /* Update error code */
\r
464 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVF;
\r
466 /* Change DCMI state */
\r
467 hdcmi->State = HAL_DCMI_STATE_ERROR;
\r
469 /* Process Unlocked */
\r
470 __HAL_UNLOCK(hdcmi);
\r
472 /* Abort the DMA Transfer */
\r
473 HAL_DMA_Abort(hdcmi->DMA_Handle);
\r
475 /* Overflow Callback */
\r
476 HAL_DCMI_ErrorCallback(hdcmi);
\r
479 /* Line Interrupt management ************************************************/
\r
480 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_LINERI) != RESET)
\r
482 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_LINE) != RESET)
\r
484 /* Clear the Line interrupt flag */
\r
485 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
\r
487 /* Process Unlocked */
\r
488 __HAL_UNLOCK(hdcmi);
\r
490 /* Line interrupt Callback */
\r
491 HAL_DCMI_LineEventCallback(hdcmi);
\r
494 /* VSYNC interrupt management ***********************************************/
\r
495 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_VSYNCRI) != RESET)
\r
497 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_VSYNC) != RESET)
\r
499 /* Disable the VSYNC interrupt */
\r
500 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_VSYNC);
\r
502 /* Clear the VSYNC flag */
\r
503 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
\r
505 /* Process Unlocked */
\r
506 __HAL_UNLOCK(hdcmi);
\r
508 /* VSYNC Callback */
\r
509 HAL_DCMI_VsyncEventCallback(hdcmi);
\r
512 /* End of Frame interrupt management ****************************************/
\r
513 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)
\r
515 if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_FRAME) != RESET)
\r
517 /* Disable the End of Frame interrupt */
\r
518 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
\r
520 /* Clear the End of Frame flag */
\r
521 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
\r
523 /* Process Unlocked */
\r
524 __HAL_UNLOCK(hdcmi);
\r
526 /* End of Frame Callback */
\r
527 HAL_DCMI_FrameEventCallback(hdcmi);
\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
538 __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
\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
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
551 __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
\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
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
564 __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
\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
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
577 __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
\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
588 /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
\r
589 * @brief Peripheral Control functions
\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
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
614 HAL_StatusTypeDef HAL_DCMI_ConfigCROP(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
\r
616 /* Process Locked */
\r
619 /* Lock the DCMI peripheral state */
\r
620 hdcmi->State = HAL_DCMI_STATE_BUSY;
\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
628 /* Configure CROP */
\r
629 DCMI->CWSIZER = (XSize | (YSize << 16));
\r
630 DCMI->CWSTRTR = (X0 | (Y0 << 16));
\r
632 /* Initialize the DCMI state*/
\r
633 hdcmi->State = HAL_DCMI_STATE_READY;
\r
635 /* Process Unlocked */
\r
636 __HAL_UNLOCK(hdcmi);
\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
647 HAL_StatusTypeDef HAL_DCMI_DisableCROP(DCMI_HandleTypeDef *hdcmi)
\r
649 /* Process Locked */
\r
652 /* Lock the DCMI peripheral state */
\r
653 hdcmi->State = HAL_DCMI_STATE_BUSY;
\r
655 /* Disable DCMI Crop feature */
\r
656 DCMI->CR &= ~(uint32_t)DCMI_CR_CROP;
\r
658 /* Change the DCMI state*/
\r
659 hdcmi->State = HAL_DCMI_STATE_READY;
\r
661 /* Process Unlocked */
\r
662 __HAL_UNLOCK(hdcmi);
\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
673 HAL_StatusTypeDef HAL_DCMI_EnableCROP(DCMI_HandleTypeDef *hdcmi)
\r
675 /* Process Locked */
\r
678 /* Lock the DCMI peripheral state */
\r
679 hdcmi->State = HAL_DCMI_STATE_BUSY;
\r
681 /* Enable DCMI Crop feature */
\r
682 DCMI->CR |= (uint32_t)DCMI_CR_CROP;
\r
684 /* Change the DCMI state*/
\r
685 hdcmi->State = HAL_DCMI_STATE_READY;
\r
687 /* Process Unlocked */
\r
688 __HAL_UNLOCK(hdcmi);
\r
697 /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
\r
698 * @brief Peripheral State functions
\r
701 ===============================================================================
\r
702 ##### Peripheral State and Errors functions #####
\r
703 ===============================================================================
\r
705 This subsection provides functions allowing to
\r
706 (+) Check the DCMI state.
\r
707 (+) Get the specific DCMI error flag.
\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
719 HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
\r
721 return hdcmi->State;
\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
730 uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
\r
732 return hdcmi->ErrorCode;
\r
738 /* Private functions ---------------------------------------------------------*/
\r
739 /** @defgroup DCMI_Private_Functions DCMI Private Functions
\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
748 static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma)
\r
752 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
753 hdcmi->State= HAL_DCMI_STATE_READY;
\r
755 if(hdcmi->XferCount != 0)
\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
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
765 /* Update memory 1 address location */
\r
766 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)
\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
773 /* Update memory 0 address location */
\r
774 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0)
\r
776 hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
\r
778 /* Update memory 1 address location */
\r
779 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0)
\r
781 tmp = hdcmi->pBuffPtr;
\r
782 hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4*hdcmi->XferSize));
\r
783 hdcmi->XferCount = hdcmi->XferTransferNumber;
\r
786 if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET)
\r
788 /* Process Unlocked */
\r
789 __HAL_UNLOCK(hdcmi);
\r
791 /* FRAME Callback */
\r
792 HAL_DCMI_FrameEventCallback(hdcmi);
\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
802 static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
\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
816 #endif /* HAL_DCMI_MODULE_ENABLED */
\r
825 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r