STM32F4xx_HAL_Driver  1.8.3
stm32f4xx_hal_dcmi.c
Go to the documentation of this file.
1 
124 /* Includes ------------------------------------------------------------------*/
125 #include "stm32f4xx_hal.h"
126 
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 -----------------------------------------------*/
146 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
147 static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
148 
149 /* Exported functions --------------------------------------------------------*/
150 
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 */
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  HAL_DCMI_MspInit(hdcmi);
219  }
220 
221  /* Change the DCMI state */
222  hdcmi->State = HAL_DCMI_STATE_BUSY;
223 
224  /* Set DCMI parameters */
225  /* Configures the HS, VS, DE and PC polarity */
226  hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |
227  DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |
228  DCMI_CR_ESS);
229  hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
230  hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
231  hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
232  hdcmi->Init.JPEGMode);
233 
234  if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
235  {
236  hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
237  ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
238  ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
239  ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
240  }
241 
242  /* Enable the Line, Vsync, Error and Overrun interrupts */
243  __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
244 
245  /* Update error code */
246  hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
247 
248  /* Initialize the DCMI state*/
249  hdcmi->State = HAL_DCMI_STATE_READY;
250 
251  return HAL_OK;
252 }
253 
262 HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
263 {
264 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
265  if(hdcmi->MspDeInitCallback == NULL)
266  {
268  }
269  /* De-Initialize the low level hardware (MSP) */
270  hdcmi->MspDeInitCallback(hdcmi);
271 #else
272  /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
273  HAL_DCMI_MspDeInit(hdcmi);
274 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
275 
276  /* Update error code */
277  hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
278 
279  /* Initialize the DCMI state*/
280  hdcmi->State = HAL_DCMI_STATE_RESET;
281 
282  /* Release Lock */
283  __HAL_UNLOCK(hdcmi);
284 
285  return HAL_OK;
286 }
287 
295 {
296  /* Prevent unused argument(s) compilation warning */
297  UNUSED(hdcmi);
298  /* NOTE : This function Should not be modified, when the callback is needed,
299  the HAL_DCMI_MspInit could be implemented in the user file
300  */
301 }
302 
310 {
311  /* Prevent unused argument(s) compilation warning */
312  UNUSED(hdcmi);
313  /* NOTE : This function Should not be modified, when the callback is needed,
314  the HAL_DCMI_MspDeInit could be implemented in the user file
315  */
316 }
317 
347 HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
348 {
349  /* Initialize the second memory address */
350  uint32_t SecondMemAddress = 0U;
351 
352  /* Check function parameters */
353  assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
354 
355  /* Process Locked */
356  __HAL_LOCK(hdcmi);
357 
358  /* Lock the DCMI peripheral state */
359  hdcmi->State = HAL_DCMI_STATE_BUSY;
360 
361  /* Enable DCMI by setting DCMIEN bit */
362  __HAL_DCMI_ENABLE(hdcmi);
363 
364  /* Configure the DCMI Mode */
365  hdcmi->Instance->CR &= ~(DCMI_CR_CM);
366  hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
367 
368  /* Set the DMA memory0 conversion complete callback */
369  hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
370 
371  /* Set the DMA error callback */
372  hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
373 
374  /* Set the dma abort callback */
375  hdcmi->DMA_Handle->XferAbortCallback = NULL;
376 
377  /* Reset transfer counters value */
378  hdcmi->XferCount = 0U;
379  hdcmi->XferTransferNumber = 0U;
380 
381  if(Length <= 0xFFFFU)
382  {
383  /* Enable the DMA Stream */
384  HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length);
385  }
386  else /* DCMI_DOUBLE_BUFFER Mode */
387  {
388  /* Set the DMA memory1 conversion complete callback */
389  hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
390 
391  /* Initialize transfer parameters */
392  hdcmi->XferCount = 1U;
393  hdcmi->XferSize = Length;
394  hdcmi->pBuffPtr = pData;
395 
396  /* Get the number of buffer */
397  while(hdcmi->XferSize > 0xFFFFU)
398  {
399  hdcmi->XferSize = (hdcmi->XferSize/2U);
400  hdcmi->XferCount = hdcmi->XferCount*2U;
401  }
402 
403  /* Update DCMI counter and transfer number*/
404  hdcmi->XferCount = (hdcmi->XferCount - 2U);
405  hdcmi->XferTransferNumber = hdcmi->XferCount;
406 
407  /* Update second memory address */
408  SecondMemAddress = (uint32_t)(pData + (4U*hdcmi->XferSize));
409 
410  /* Start DMA multi buffer transfer */
411  HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize);
412  }
413 
414  /* Enable Capture */
415  hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
416 
417  /* Release Lock */
418  __HAL_UNLOCK(hdcmi);
419 
420  /* Return function status */
421  return HAL_OK;
422 }
423 
430 HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi)
431 {
432  __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
433  HAL_StatusTypeDef status = HAL_OK;
434 
435  /* Process locked */
436  __HAL_LOCK(hdcmi);
437 
438  /* Lock the DCMI peripheral state */
439  hdcmi->State = HAL_DCMI_STATE_BUSY;
440 
441  /* Disable Capture */
442  hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
443 
444  /* Check if the DCMI capture effectively disabled */
445  do
446  {
447  if (count-- == 0U)
448  {
449  /* Update error code */
450  hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
451 
452  status = HAL_TIMEOUT;
453  break;
454  }
455  }
456  while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
457 
458  /* Disable the DCMI */
459  __HAL_DCMI_DISABLE(hdcmi);
460 
461  /* Disable the DMA */
462  HAL_DMA_Abort(hdcmi->DMA_Handle);
463 
464  /* Update error code */
465  hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
466 
467  /* Change DCMI state */
468  hdcmi->State = HAL_DCMI_STATE_READY;
469 
470  /* Process Unlocked */
471  __HAL_UNLOCK(hdcmi);
472 
473  /* Return function status */
474  return status;
475 }
476 
483 HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef* hdcmi)
484 {
485  __IO uint32_t count = SystemCoreClock / HAL_TIMEOUT_DCMI_STOP;
486  HAL_StatusTypeDef status = HAL_OK;
487 
488  /* Process locked */
489  __HAL_LOCK(hdcmi);
490 
491  if(hdcmi->State == HAL_DCMI_STATE_BUSY)
492  {
493  /* Change DCMI state */
495 
496  /* Disable Capture */
497  hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
498 
499  /* Check if the DCMI capture effectively disabled */
500  do
501  {
502  if (count-- == 0U)
503  {
504  /* Update error code */
505  hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
506 
507  /* Change DCMI state */
508  hdcmi->State = HAL_DCMI_STATE_READY;
509 
510  status = HAL_TIMEOUT;
511  break;
512  }
513  }
514  while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0);
515  }
516  /* Process Unlocked */
517  __HAL_UNLOCK(hdcmi);
518 
519  /* Return function status */
520  return status;
521 }
522 
529 HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef* hdcmi)
530 {
531  /* Process locked */
532  __HAL_LOCK(hdcmi);
533 
534  if(hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
535  {
536  /* Change DCMI state */
537  hdcmi->State = HAL_DCMI_STATE_BUSY;
538 
539  /* Disable Capture */
540  hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
541  }
542  /* Process Unlocked */
543  __HAL_UNLOCK(hdcmi);
544 
545  /* Return function status */
546  return HAL_OK;
547 }
548 
556 {
557  uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
558 
559  /* Synchronization error interrupt management *******************************/
560  if((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
561  {
562  /* Clear the Synchronization error flag */
563  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
564 
565  /* Update error code */
566  hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
567 
568  /* Change DCMI state */
569  hdcmi->State = HAL_DCMI_STATE_ERROR;
570 
571  /* Set the synchronization error callback */
572  hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
573 
574  /* Abort the DMA Transfer */
576  }
577  /* Overflow interrupt management ********************************************/
578  if((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
579  {
580  /* Clear the Overflow flag */
581  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
582 
583  /* Update error code */
584  hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
585 
586  /* Change DCMI state */
587  hdcmi->State = HAL_DCMI_STATE_ERROR;
588 
589  /* Set the overflow callback */
590  hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
591 
592  /* Abort the DMA Transfer */
594  }
595  /* Line Interrupt management ************************************************/
596  if((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
597  {
598  /* Clear the Line interrupt flag */
599  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
600 
601  /* Line interrupt Callback */
602 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
603  /*Call registered DCMI line event callback*/
604  hdcmi->LineEventCallback(hdcmi);
605 #else
607 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
608  }
609  /* VSYNC interrupt management ***********************************************/
610  if((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
611  {
612  /* Clear the VSYNC flag */
613  __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
614 
615  /* VSYNC Callback */
616 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
617  /*Call registered DCMI vsync event callback*/
618  hdcmi->VsyncEventCallback(hdcmi);
619 #else
621 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
622  }
623  /* FRAME interrupt management ***********************************************/
624  if((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
625  {
626  /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
627  if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
628  {
629  /* Disable the Line, Vsync, Error and Overrun interrupts */
630  __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
631  }
632 
633  /* Disable the Frame interrupt */
634  __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
635 
636  /* Frame Callback */
637 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
638  /*Call registered DCMI frame event callback*/
639  hdcmi->FrameEventCallback(hdcmi);
640 #else
642 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
643  }
644 }
645 
653 {
654  /* Prevent unused argument(s) compilation warning */
655  UNUSED(hdcmi);
656  /* NOTE : This function Should not be modified, when the callback is needed,
657  the HAL_DCMI_ErrorCallback could be implemented in the user file
658  */
659 }
660 
668 {
669  /* Prevent unused argument(s) compilation warning */
670  UNUSED(hdcmi);
671  /* NOTE : This function Should not be modified, when the callback is needed,
672  the HAL_DCMI_LineEventCallback could be implemented in the user file
673  */
674 }
675 
683 {
684  /* Prevent unused argument(s) compilation warning */
685  UNUSED(hdcmi);
686  /* NOTE : This function Should not be modified, when the callback is needed,
687  the HAL_DCMI_VsyncEventCallback could be implemented in the user file
688  */
689 }
690 
698 {
699  /* Prevent unused argument(s) compilation warning */
700  UNUSED(hdcmi);
701  /* NOTE : This function Should not be modified, when the callback is needed,
702  the HAL_DCMI_FrameEventCallback could be implemented in the user file
703  */
704 }
705 
735 HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
736 {
737  /* Process Locked */
738  __HAL_LOCK(hdcmi);
739 
740  /* Lock the DCMI peripheral state */
741  hdcmi->State = HAL_DCMI_STATE_BUSY;
742 
743  /* Check the parameters */
744  assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
745  assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
746  assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
747  assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
748 
749  /* Configure CROP */
750  hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_POSITION_CWSIZE_VLINE));
751  hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_POSITION_CWSTRT_VST));
752 
753  /* Initialize the DCMI state*/
754  hdcmi->State = HAL_DCMI_STATE_READY;
755 
756  /* Process Unlocked */
757  __HAL_UNLOCK(hdcmi);
758 
759  return HAL_OK;
760 }
761 
768 HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
769 {
770  /* Process Locked */
771  __HAL_LOCK(hdcmi);
772 
773  /* Lock the DCMI peripheral state */
774  hdcmi->State = HAL_DCMI_STATE_BUSY;
775 
776  /* Disable DCMI Crop feature */
777  hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
778 
779  /* Change the DCMI state*/
780  hdcmi->State = HAL_DCMI_STATE_READY;
781 
782  /* Process Unlocked */
783  __HAL_UNLOCK(hdcmi);
784 
785  return HAL_OK;
786 }
787 
794 HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
795 {
796  /* Process Locked */
797  __HAL_LOCK(hdcmi);
798 
799  /* Lock the DCMI peripheral state */
800  hdcmi->State = HAL_DCMI_STATE_BUSY;
801 
802  /* Enable DCMI Crop feature */
803  hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
804 
805  /* Change the DCMI state*/
806  hdcmi->State = HAL_DCMI_STATE_READY;
807 
808  /* Process Unlocked */
809  __HAL_UNLOCK(hdcmi);
810 
811  return HAL_OK;
812 }
813 
822 HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
823 {
824  /* Process Locked */
825  __HAL_LOCK(hdcmi);
826 
827  /* Lock the DCMI peripheral state */
828  hdcmi->State = HAL_DCMI_STATE_BUSY;
829 
830  /* Write DCMI embedded synchronization unmask register */
831  hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) |\
832  ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos)|\
833  ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos)|\
834  ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
835 
836  /* Change the DCMI state*/
837  hdcmi->State = HAL_DCMI_STATE_READY;
838 
839  /* Process Unlocked */
840  __HAL_UNLOCK(hdcmi);
841 
842  return HAL_OK;
843 }
844 
872 {
873  return hdcmi->State;
874 }
875 
883 {
884  return hdcmi->ErrorCode;
885 }
886 
887 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
896 HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
897 {
898  HAL_StatusTypeDef status = HAL_OK;
899 
900  if(pCallback == NULL)
901  {
902  /* update the error code */
903  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
904  /* update return status */
905  status = HAL_ERROR;
906  }
907  else
908  {
909  if(hdcmi->State == HAL_DCMI_STATE_READY)
910  {
911  switch (CallbackID)
912  {
914  hdcmi->FrameEventCallback = pCallback;
915  break;
916 
918  hdcmi->VsyncEventCallback = pCallback;
919  break;
920 
922  hdcmi->LineEventCallback = pCallback;
923  break;
924 
925  case HAL_DCMI_ERROR_CB_ID :
926  hdcmi->ErrorCallback = pCallback;
927  break;
928 
930  hdcmi->MspInitCallback = pCallback;
931  break;
932 
934  hdcmi->MspDeInitCallback = pCallback;
935  break;
936 
937  default :
938  /* Return error status */
939  status = HAL_ERROR;
940  break;
941  }
942  }
943  else if(hdcmi->State == HAL_DCMI_STATE_RESET)
944  {
945  switch (CallbackID)
946  {
948  hdcmi->MspInitCallback = pCallback;
949  break;
950 
952  hdcmi->MspDeInitCallback = pCallback;
953  break;
954 
955  default :
956  /* update the error code */
957  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
958  /* update return status */
959  status = HAL_ERROR;
960  break;
961  }
962  }
963  else
964  {
965  /* update the error code */
966  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
967  /* update return status */
968  status = HAL_ERROR;
969  }
970  }
971 
972  return status;
973 }
974 
982 {
983  HAL_StatusTypeDef status = HAL_OK;
984 
985  if(hdcmi->State == HAL_DCMI_STATE_READY)
986  {
987  switch (CallbackID)
988  {
990  hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
991  break;
992 
994  hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
995  break;
996 
998  hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
999  break;
1000 
1001  case HAL_DCMI_ERROR_CB_ID :
1002  hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
1003  break;
1004 
1005  case HAL_DCMI_MSPINIT_CB_ID :
1007  break;
1008 
1011  break;
1012 
1013  default :
1014  /* update the error code */
1015  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1016  /* update return status */
1017  status = HAL_ERROR;
1018  break;
1019  }
1020  }
1021  else if(hdcmi->State == HAL_DCMI_STATE_RESET)
1022  {
1023  switch (CallbackID)
1024  {
1025  case HAL_DCMI_MSPINIT_CB_ID :
1027  break;
1028 
1031  break;
1032 
1033  default :
1034  /* update the error code */
1035  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1036  /* update return status */
1037  status = HAL_ERROR;
1038  break;
1039  }
1040  }
1041  else
1042  {
1043  /* update the error code */
1044  hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1045  /* update return status */
1046  status = HAL_ERROR;
1047  }
1048 
1049  return status;
1050 }
1051 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1052 
1056 /* Private functions ---------------------------------------------------------*/
1067 static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
1068 {
1069  uint32_t tmp = 0U;
1070 
1071  DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1072 
1073  if(hdcmi->XferCount != 0U)
1074  {
1075  /* Update memory 0 address location */
1076  tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT);
1077  if(((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
1078  {
1079  tmp = hdcmi->DMA_Handle->Instance->M0AR;
1080  HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY0);
1081  hdcmi->XferCount--;
1082  }
1083  /* Update memory 1 address location */
1084  else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1085  {
1086  tmp = hdcmi->DMA_Handle->Instance->M1AR;
1087  HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U*hdcmi->XferSize)), MEMORY1);
1088  hdcmi->XferCount--;
1089  }
1090  }
1091  /* Update memory 0 address location */
1092  else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0U)
1093  {
1094  hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr;
1095  }
1096  /* Update memory 1 address location */
1097  else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0U)
1098  {
1099  tmp = hdcmi->pBuffPtr;
1100  hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4U*hdcmi->XferSize));
1101  hdcmi->XferCount = hdcmi->XferTransferNumber;
1102  }
1103 
1104  /* Check if the frame is transferred */
1105  if(hdcmi->XferCount == hdcmi->XferTransferNumber)
1106  {
1107  /* Enable the Frame interrupt */
1108  __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
1109 
1110  /* When snapshot mode, set dcmi state to ready */
1111  if((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
1112  {
1113  hdcmi->State= HAL_DCMI_STATE_READY;
1114  }
1115  }
1116 }
1117 
1124 static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
1125 {
1126  DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1127 
1128  if(hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
1129  {
1130  /* Initialize the DCMI state*/
1131  hdcmi->State = HAL_DCMI_STATE_READY;
1132  }
1133 
1134  /* DCMI error Callback */
1135 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
1136  /*Call registered DCMI error callback*/
1137  hdcmi->ErrorCallback(hdcmi);
1138 #else
1139  HAL_DCMI_ErrorCallback(hdcmi);
1140 #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1141 
1142 }
1143 
1151 #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
1152  STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\
1153  STM32F479xx */
1154 #endif /* HAL_DCMI_MODULE_ENABLED */
void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi)
Initializes the DCMI MSP.
void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef *hdcmi)
DeInitializes the DCMI MSP.
HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
Deinitializes the DCMI peripheral registers to their default reset values.
HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
Initializes the DCMI according to the specified parameters in the DCMI_InitTypeDef and create the ass...
void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
Handles DCMI interrupt request.
void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
Line Event callback.
HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef *hdcmi)
Disable DCMI DMA request and Disable DCMI capture.
void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
VSYNC Event callback.
HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef *hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
Enables DCMI DMA request and enables DCMI capture.
HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef *hdcmi)
Resume DCMI capture
void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
Error DCMI callback.
void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
Frame Event callback.
HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef *hdcmi)
Suspend DCMI capture
HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
Enable the Crop feature.
HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
Configure the DCMI CROP coordinate.
HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
Set embedded synchronization delimiters unmasks.
HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
Disable the Crop feature.
uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
Return the DCMI error code.
HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
DCMI Callback registering.
HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
DCMI Callback Unregistering.
HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
Return the DCMI state.
HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory)
Change the memory0 or memory1 address on the fly.
HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength)
Starts the multi_buffer DMA Transfer with interrupt enabled.
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer.
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
This file contains all the functions prototypes for the HAL module driver.
HAL_DCMI_CallbackIDTypeDef
@ HAL_DCMI_LINE_EVENT_CB_ID
@ HAL_DCMI_FRAME_EVENT_CB_ID
@ HAL_DCMI_ERROR_CB_ID
@ HAL_DCMI_MSPDEINIT_CB_ID
@ HAL_DCMI_MSPINIT_CB_ID
@ HAL_DCMI_VSYNC_EVENT_CB_ID
HAL_DCMI_StateTypeDef
HAL DCMI State structures definition.
@ HAL_DCMI_STATE_RESET
@ HAL_DCMI_STATE_READY
@ HAL_DCMI_STATE_SUSPENDED
@ HAL_DCMI_STATE_ERROR
@ HAL_DCMI_STATE_BUSY
DCMI_CodesInitTypeDef SyncroCode
DCMI handle Structure definition.
void(* VsyncEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
DMA_HandleTypeDef * DMA_Handle
void(* FrameEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void(* LineEventCallback)(struct __DCMI_HandleTypeDef *hdcmi)
DCMI_InitTypeDef Init
void(* MspInitCallback)(struct __DCMI_HandleTypeDef *hdcmi)
__IO HAL_DCMI_StateTypeDef State
void(* ErrorCallback)(struct __DCMI_HandleTypeDef *hdcmi)
void(* MspDeInitCallback)(struct __DCMI_HandleTypeDef *hdcmi)
DMA handle Structure definition.
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_Stream_TypeDef * Instance
void(* XferM1CpltCallback)(struct __DMA_HandleTypeDef *hdma)