comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c @ 128:c78bcbd5deda FlipDisplay

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