STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_hal_dcmi.c
Go to the documentation of this file.
1
123
124/* Includes ------------------------------------------------------------------*/
125#include "stm32f4xx_hal.h"
126
134
135#ifdef HAL_DCMI_MODULE_ENABLED
136
137#if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\
138 defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\
139 defined(STM32F479xx)
140/* Private typedef -----------------------------------------------------------*/
141/* Private define ------------------------------------------------------------*/
142#define HAL_TIMEOUT_DCMI_STOP 14U /* Set timeout to 1s */
143/* Private macro -------------------------------------------------------------*/
144/* Private variables ---------------------------------------------------------*/
145/* Private function prototypes -----------------------------------------------*/
146static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
147static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
148
149/* Exported functions --------------------------------------------------------*/
150
154
169
177__weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
178{
179 /* Check the DCMI peripheral state */
180 if(hdcmi == NULL)
181 {
182 return HAL_ERROR;
183 }
184
185 /* Check function parameters */
186 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
187 assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
188 assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
189 assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
190 assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
191 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
192 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
193 assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
194
195 if(hdcmi->State == HAL_DCMI_STATE_RESET)
196 {
197 /* Allocate lock resource and initialize it */
198 hdcmi->Lock = HAL_UNLOCKED;
199 /* Init the low level hardware */
200 /* Init the DCMI Callback settings */
201#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
202 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
203 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
204 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
205 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
206
207 if(hdcmi->MspInitCallback == NULL)
208 {
209 /* Legacy weak MspInit Callback */
210 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
211 }
212 /* Initialize the low level hardware (MSP) */
213 hdcmi->MspInitCallback(hdcmi);
214#else
215 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
216 HAL_DCMI_MspInit(hdcmi);
217#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
218 }
219
220 /* Change the DCMI state */
221 hdcmi->State = HAL_DCMI_STATE_BUSY;
222
223 /* Set DCMI parameters */
224 /* Configures the HS, VS, DE and PC polarity */
225 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |
226 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |
227 DCMI_CR_ESS);
228 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
229 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
230 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
231 hdcmi->Init.JPEGMode);
232
233 if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
234 {
235 hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
236 ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
237 ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
238 ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
239 }
240
241 /* Enable the Line, Vsync, Error and Overrun interrupts */
242 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
243
244 /* Update error code */
245 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
246
247 /* Initialize the DCMI state*/
248 hdcmi->State = HAL_DCMI_STATE_READY;
249
250 return HAL_OK;
251}
252
260
261HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
262{
263#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
264 if(hdcmi->MspDeInitCallback == NULL)
265 {
266 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
267 }
268 /* De-Initialize the low level hardware (MSP) */
269 hdcmi->MspDeInitCallback(hdcmi);
270#else
271 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
272 HAL_DCMI_MspDeInit(hdcmi);
273#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
274
275 /* Update error code */
276 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
277
278 /* Initialize the DCMI state*/
279 hdcmi->State = HAL_DCMI_STATE_RESET;
280
281 /* Release Lock */
282 __HAL_UNLOCK(hdcmi);
283
284 return HAL_OK;
285}
286
293__weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
294{
295 /* Prevent unused argument(s) compilation warning */
296 UNUSED(hdcmi);
297 /* NOTE : This function Should not be modified, when the callback is needed,
298 the HAL_DCMI_MspInit could be implemented in the user file
299 */
300}
301
308__weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
309{
310 /* Prevent unused argument(s) compilation warning */
311 UNUSED(hdcmi);
312 /* NOTE : This function Should not be modified, when the callback is needed,
313 the HAL_DCMI_MspDeInit could be implemented in the user file
314 */
315}
316
336
346HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
347{
348 HAL_StatusTypeDef status;
349
350 /* Initialize the second memory address */
351 uint32_t SecondMemAddress = 0U;
352
353 /* Check function parameters */
354 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
355
356 /* Process Locked */
357 __HAL_LOCK(hdcmi);
358
359 /* Lock the DCMI peripheral state */
360 hdcmi->State = HAL_DCMI_STATE_BUSY;
361
362 /* Enable DCMI by setting DCMIEN bit */
363 __HAL_DCMI_ENABLE(hdcmi);
364
365 /* Configure the DCMI Mode */
366 hdcmi->Instance->CR &= ~(DCMI_CR_CM);
367 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
368
369 /* Set the DMA memory0 conversion complete callback */
370 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
371
372 /* Set the DMA error callback */
373 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
374
375 /* Set the dma abort callback */
376 hdcmi->DMA_Handle->XferAbortCallback = NULL;
377
378 /* Reset transfer counters value */
379 hdcmi->XferCount = 0U;
380 hdcmi->XferTransferNumber = 0U;
381
382 if(Length <= 0xFFFFU)
383 {
384 /* Enable the DMA Stream */
385 status = HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
386 }
387 else /* DCMI_DOUBLE_BUFFER Mode */
388 {
389 /* Set the DMA memory1 conversion complete callback */
390 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
391
392 /* Initialize transfer parameters */
393 hdcmi->XferCount = 1U;
394 hdcmi->XferSize = Length;
395 hdcmi->pBuffPtr = pData;
396
397 /* Get the number of buffer */
398 while(hdcmi->XferSize > 0xFFFFU)
399 {
400 hdcmi->XferSize = (hdcmi->XferSize/2U);
401 hdcmi->XferCount = hdcmi->XferCount*2U;
402 }
403
404 /* Update DCMI counter and transfer number*/
405 hdcmi->XferCount = (hdcmi->XferCount - 2U);
406 hdcmi->XferTransferNumber = hdcmi->XferCount;
407
408 /* Update second memory address */
409 SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize));
410
411 /* Start DMA multi buffer transfer */
412 status = HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
413 }
414
415 /* Enable Capture */
416 hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
417
418 /* Release Lock */
419 __HAL_UNLOCK(hdcmi);
420
421 /* Return function status */
422 return status;
423}
424
431HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
432{
433 __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
434 HAL_StatusTypeDef status = HAL_OK;
435
436 /* Process locked */
437 __HAL_LOCK(hdcmi);
438
439 /* Lock the DCMI peripheral state */
440 hdcmi->State = HAL_DCMI_STATE_BUSY;
441
442 /* Disable Capture */
443 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
444
445 /* Check if the DCMI capture effectively disabled */
446 do
447 {
448 if (count-- == 0U)
449 {
450 /* Update error code */
451 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
452
453 status = HAL_TIMEOUT;
454 break;
455 }
456 }
457 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
458
459 /* Disable the DCMI */
460 __HAL_DCMI_DISABLE(hdcmi);
461
462 /* Disable the DMA */
463 HAL_DMA_Abort(hdcmi->DMA_Handle);
464
465 /* Update error code */
466 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
467
468 /* Change DCMI state */
469 hdcmi->State = HAL_DCMI_STATE_READY;
470
471 /* Process Unlocked */
472 __HAL_UNLOCK(hdcmi);
473
474 /* Return function status */
475 return status;
476}
477
484HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
485{
486 __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
487 HAL_StatusTypeDef status = HAL_OK;
488
489 /* Process locked */
490 __HAL_LOCK(hdcmi);
491
492 if(hdcmi->State == HAL_DCMI_STATE_BUSY)
493 {
494 /* Change DCMI state */
495 hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
496
497 /* Disable Capture */
498 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
499
500 /* Check if the DCMI capture effectively disabled */
501 do
502 {
503 if (count-- == 0U)
504 {
505 /* Update error code */
506 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
507
508 /* Change DCMI state */
509 hdcmi->State = HAL_DCMI_STATE_READY;
510
511 status = HAL_TIMEOUT;
512 break;
513 }
514 }
515 while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
516 }
517 /* Process Unlocked */
518 __HAL_UNLOCK(hdcmi);
519
520 /* Return function status */
521 return status;
522}
523
530HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi)
531{
532 /* Process locked */
533 __HAL_LOCK(hdcmi);
534
535 if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
536 {
537 /* Change DCMI state */
538 hdcmi->State = HAL_DCMI_STATE_BUSY;
539
540 /* Disable Capture */
541 hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
542 }
543 /* Process Unlocked */
544 __HAL_UNLOCK(hdcmi);
545
546 /* Return function status */
547 return HAL_OK;
548}
549
556void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
557{
558 uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
559
560 /* Synchronization error interrupt management *******************************/
561 if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
562 {
563 /* Clear the Synchronization error flag */
564 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
565
566 /* Update error code */
567 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
568
569 /* Change DCMI state */
570 hdcmi->State = HAL_DCMI_STATE_ERROR;
571
572 /* Set the synchronization error callback */
573 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
574
575 /* Abort the DMA Transfer */
576 if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
577 {
578 DCMI_DMAError(hdcmi->DMA_Handle);
579 }
580 }
581 /* Overflow interrupt management ********************************************/
582 if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
583 {
584 /* Clear the Overflow flag */
585 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
586
587 /* Update error code */
588 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
589
590 /* Change DCMI state */
591 hdcmi->State = HAL_DCMI_STATE_ERROR;
592
593 /* Set the overflow callback */
594 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
595
596 /* Abort the DMA Transfer */
597 if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
598 {
599 DCMI_DMAError(hdcmi->DMA_Handle);
600 }
601 }
602 /* Line Interrupt management ************************************************/
603 if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
604 {
605 /* Clear the Line interrupt flag */
606 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
607
608 /* Line interrupt Callback */
609#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
610 /*Call registered DCMI line event callback*/
611 hdcmi->LineEventCallback(hdcmi);
612#else
613 HAL_DCMI_LineEventCallback(hdcmi);
614#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
615 }
616 /* VSYNC interrupt management ***********************************************/
617 if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
618 {
619 /* Clear the VSYNC flag */
620 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
621
622 /* VSYNC Callback */
623#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
624 /*Call registered DCMI vsync event callback*/
625 hdcmi->VsyncEventCallback(hdcmi);
626#else
627 HAL_DCMI_VsyncEventCallback(hdcmi);
628#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
629 }
630 /* FRAME interrupt management ***********************************************/
631 if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
632 {
633 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
634 if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
635 {
636 /* Disable the Line, Vsync, Error and Overrun interrupts */
637 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
638 }
639
640 /* Disable the Frame interrupt */
641 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
642
643 /* Frame Callback */
644#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
645 /*Call registered DCMI frame event callback*/
646 hdcmi->FrameEventCallback(hdcmi);
647#else
648 HAL_DCMI_FrameEventCallback(hdcmi);
649#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
650 }
651}
652
659__weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
660{
661 /* Prevent unused argument(s) compilation warning */
662 UNUSED(hdcmi);
663 /* NOTE : This function Should not be modified, when the callback is needed,
664 the HAL_DCMI_ErrorCallback could be implemented in the user file
665 */
666}
667
674__weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
675{
676 /* Prevent unused argument(s) compilation warning */
677 UNUSED(hdcmi);
678 /* NOTE : This function Should not be modified, when the callback is needed,
679 the HAL_DCMI_LineEventCallback could be implemented in the user file
680 */
681}
682
689__weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
690{
691 /* Prevent unused argument(s) compilation warning */
692 UNUSED(hdcmi);
693 /* NOTE : This function Should not be modified, when the callback is needed,
694 the HAL_DCMI_VsyncEventCallback could be implemented in the user file
695 */
696}
697
704__weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
705{
706 /* Prevent unused argument(s) compilation warning */
707 UNUSED(hdcmi);
708 /* NOTE : This function Should not be modified, when the callback is needed,
709 the HAL_DCMI_FrameEventCallback could be implemented in the user file
710 */
711}
712
716
731
742HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
743{
744 /* Process Locked */
745 __HAL_LOCK(hdcmi);
746
747 /* Lock the DCMI peripheral state */
748 hdcmi->State = HAL_DCMI_STATE_BUSY;
749
750 /* Check the parameters */
751 assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
752 assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
753 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
754 assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
755
756 /* Configure CROP */
757 hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE));
758 hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST));
759
760 /* Initialize the DCMI state*/
761 hdcmi->State = HAL_DCMI_STATE_READY;
762
763 /* Process Unlocked */
764 __HAL_UNLOCK(hdcmi);
765
766 return HAL_OK;
767}
768
775HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
776{
777 /* Process Locked */
778 __HAL_LOCK(hdcmi);
779
780 /* Lock the DCMI peripheral state */
781 hdcmi->State = HAL_DCMI_STATE_BUSY;
782
783 /* Disable DCMI Crop feature */
784 hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
785
786 /* Change the DCMI state*/
787 hdcmi->State = HAL_DCMI_STATE_READY;
788
789 /* Process Unlocked */
790 __HAL_UNLOCK(hdcmi);
791
792 return HAL_OK;
793}
794
801HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
802{
803 /* Process Locked */
804 __HAL_LOCK(hdcmi);
805
806 /* Lock the DCMI peripheral state */
807 hdcmi->State = HAL_DCMI_STATE_BUSY;
808
809 /* Enable DCMI Crop feature */
810 hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
811
812 /* Change the DCMI state*/
813 hdcmi->State = HAL_DCMI_STATE_READY;
814
815 /* Process Unlocked */
816 __HAL_UNLOCK(hdcmi);
817
818 return HAL_OK;
819}
820
829HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
830{
831 /* Process Locked */
832 __HAL_LOCK(hdcmi);
833
834 /* Lock the DCMI peripheral state */
835 hdcmi->State = HAL_DCMI_STATE_BUSY;
836
837 /* Write DCMI embedded synchronization unmask register */
838 hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) |\
839 ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos)|\
840 ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos)|\
841 ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
842
843 /* Change the DCMI state*/
844 hdcmi->State = HAL_DCMI_STATE_READY;
845
846 /* Process Unlocked */
847 __HAL_UNLOCK(hdcmi);
848
849 return HAL_OK;
850}
851
855
871
878HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
879{
880 return hdcmi->State;
881}
882
889uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
890{
891 return hdcmi->ErrorCode;
892}
893
894#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
903HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
904{
905 HAL_StatusTypeDef status = HAL_OK;
906
907 if(pCallback == NULL)
908 {
909 /* update the error code */
910 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
911 /* update return status */
912 status = HAL_ERROR;
913 }
914 else
915 {
916 if(hdcmi->State == HAL_DCMI_STATE_READY)
917 {
918 switch (CallbackID)
919 {
920 case HAL_DCMI_FRAME_EVENT_CB_ID :
921 hdcmi->FrameEventCallback = pCallback;
922 break;
923
924 case HAL_DCMI_VSYNC_EVENT_CB_ID :
925 hdcmi->VsyncEventCallback = pCallback;
926 break;
927
928 case HAL_DCMI_LINE_EVENT_CB_ID :
929 hdcmi->LineEventCallback = pCallback;
930 break;
931
932 case HAL_DCMI_ERROR_CB_ID :
933 hdcmi->ErrorCallback = pCallback;
934 break;
935
936 case HAL_DCMI_MSPINIT_CB_ID :
937 hdcmi->MspInitCallback = pCallback;
938 break;
939
940 case HAL_DCMI_MSPDEINIT_CB_ID :
941 hdcmi->MspDeInitCallback = pCallback;
942 break;
943
944 default :
945 /* Return error status */
946 status = HAL_ERROR;
947 break;
948 }
949 }
950 else if(hdcmi->State == HAL_DCMI_STATE_RESET)
951 {
952 switch (CallbackID)
953 {
954 case HAL_DCMI_MSPINIT_CB_ID :
955 hdcmi->MspInitCallback = pCallback;
956 break;
957
958 case HAL_DCMI_MSPDEINIT_CB_ID :
959 hdcmi->MspDeInitCallback = pCallback;
960 break;
961
962 default :
963 /* update the error code */
964 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
965 /* update return status */
966 status = HAL_ERROR;
967 break;
968 }
969 }
970 else
971 {
972 /* update the error code */
973 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
974 /* update return status */
975 status = HAL_ERROR;
976 }
977 }
978
979 return status;
980}
981
988HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
989{
990 HAL_StatusTypeDef status = HAL_OK;
991
992 if(hdcmi->State == HAL_DCMI_STATE_READY)
993 {
994 switch (CallbackID)
995 {
996 case HAL_DCMI_FRAME_EVENT_CB_ID :
997 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
998 break;
999
1000 case HAL_DCMI_VSYNC_EVENT_CB_ID :
1001 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
1002 break;
1003
1004 case HAL_DCMI_LINE_EVENT_CB_ID :
1005 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
1006 break;
1007
1008 case HAL_DCMI_ERROR_CB_ID :
1009 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
1010 break;
1011
1012 case HAL_DCMI_MSPINIT_CB_ID :
1013 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1014 break;
1015
1016 case HAL_DCMI_MSPDEINIT_CB_ID :
1017 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1018 break;
1019
1020 default :
1021 /* update the error code */
1022 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1023 /* update return status */
1024 status = HAL_ERROR;
1025 break;
1026 }
1027 }
1028 else if(hdcmi->State == HAL_DCMI_STATE_RESET)
1029 {
1030 switch (CallbackID)
1031 {
1032 case HAL_DCMI_MSPINIT_CB_ID :
1033 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1034 break;
1035
1036 case HAL_DCMI_MSPDEINIT_CB_ID :
1037 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1038 break;
1039
1040 default :
1041 /* update the error code */
1042 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1043 /* update return status */
1044 status = HAL_ERROR;
1045 break;
1046 }
1047 }
1048 else
1049 {
1050 /* update the error code */
1051 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1052 /* update return status */
1053 status = HAL_ERROR;
1054 }
1055
1056 return status;
1057}
1058#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1059
1063/* Private functions ---------------------------------------------------------*/
1067
1074static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
1075{
1076 uint32_t tmp = 0U;
1077
1078 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1079
1080 if(hdcmi->XferCount != 0U)
1081 {
1082 /* Update memory 0 address location */
1083 tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);
1084 if(((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
1085 {
1086 tmp = hdcmi->DMA_Handle->Instance->M0AR;
1087 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY0);
1088 hdcmi->XferCount--;
1089 }
1090 /* Update memory 1 address location */
1091 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1092 {
1093 tmp = hdcmi->DMA_Handle->Instance->M1AR;
1094 HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY1);
1095 hdcmi->XferCount--;
1096 }
1097 }
1098 /* Update memory 0 address location */
1099 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0U)
1100 {
1101 hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
1102 }
1103 /* Update memory 1 address location */
1104 else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1105 {
1106 tmp = hdcmi->pBuffPtr;
1107 hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4U*hdcmi->XferSize));
1108 hdcmi->XferCount = hdcmi->XferTransferNumber;
1109 }
1110
1111 /* Check if the frame is transferred */
1112 if(hdcmi->XferCount == hdcmi->XferTransferNumber)
1113 {
1114 /* Enable the Frame interrupt */
1115 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
1116
1117 /* When snapshot mode, set dcmi state to ready */
1118 if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
1119 {
1120 hdcmi->State= HAL_DCMI_STATE_READY;
1121 }
1122 }
1123}
1124
1131static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
1132{
1133 DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1134
1135 if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
1136 {
1137 /* Initialize the DCMI state*/
1138 hdcmi->State = HAL_DCMI_STATE_READY;
1139 }
1140
1141 /* DCMI error Callback */
1142#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1143 /*Call registered DCMI error callback*/
1144 hdcmi->ErrorCallback(hdcmi);
1145#else
1146 HAL_DCMI_ErrorCallback(hdcmi);
1147#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1148
1149}
1150
1154
1158#endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
1159 STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
1160 STM32F479xx */
1161#endif /* HAL_DCMI_MODULE_ENABLED */
1165
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
#define HAL_DMA_ERROR_FE
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
#define __HAL_UNLOCK(__HANDLE__)
@ HAL_UNLOCKED
#define __HAL_LOCK(__HANDLE__)