comparison Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_dcmi.c @ 38:5f11787b4f42

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