STM32F479xx HAL User Manual
stm32f4xx_hal_dcmi_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_dcmi_ex.c
00004   * @author  MCD Application Team
00005   * @brief   DCMI Extension HAL module driver
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of DCMI extension peripheral:
00008   *           + Extension features functions
00009   *
00010   @verbatim
00011   ==============================================================================
00012                ##### DCMI peripheral extension features  #####
00013   ==============================================================================
00014 
00015   [..] Comparing to other previous devices, the DCMI interface for STM32F446xx
00016        devices contains the following additional features :
00017 
00018        (+) Support of Black and White cameras
00019 
00020                      ##### How to use this driver #####
00021   ==============================================================================
00022   [..] This driver provides functions to manage the Black and White feature
00023 
00024   @endverbatim
00025   ******************************************************************************
00026   * @attention
00027   *
00028   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00029   * All rights reserved.</center></h2>
00030   *
00031   * This software component is licensed by ST under BSD 3-Clause license,
00032   * the "License"; You may not use this file except in compliance with the
00033   * License. You may obtain a copy of the License at:
00034   *                        opensource.org/licenses/BSD-3-Clause
00035   *
00036   ******************************************************************************
00037   */
00038 
00039 /* Includes ------------------------------------------------------------------*/
00040 #include "stm32f4xx_hal.h"
00041 
00042 /** @addtogroup STM32F4xx_HAL_Driver
00043   * @{
00044   */
00045 /** @defgroup DCMIEx DCMIEx
00046   * @brief DCMI Extended HAL module driver
00047   * @{
00048   */
00049 
00050 #ifdef HAL_DCMI_MODULE_ENABLED
00051 
00052 #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\
00053     defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00054 /* Private typedef -----------------------------------------------------------*/
00055 /* Private define ------------------------------------------------------------*/
00056 /* Private macro -------------------------------------------------------------*/
00057 /* Private variables ---------------------------------------------------------*/
00058 /* Private function prototypes -----------------------------------------------*/
00059 /* Exported functions --------------------------------------------------------*/
00060 
00061 /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
00062   * @{
00063   */
00064 
00065 /**
00066   * @}
00067   */
00068 
00069 /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
00070   * @{
00071   */
00072 
00073 /**
00074   * @brief  Initializes the DCMI according to the specified
00075   *         parameters in the DCMI_InitTypeDef and create the associated handle.
00076   * @param  hdcmi pointer to a DCMI_HandleTypeDef structure that contains
00077   *                the configuration information for DCMI.
00078   * @retval HAL status
00079   */
00080 HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
00081 {
00082   /* Check the DCMI peripheral state */
00083   if(hdcmi == NULL)
00084   {
00085      return HAL_ERROR;
00086   }
00087 
00088   /* Check function parameters */
00089   assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
00090   assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
00091   assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
00092   assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
00093   assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
00094   assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
00095   assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
00096   assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
00097 #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00098   assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
00099   assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
00100   assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
00101   assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
00102 #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
00103   if(hdcmi->State == HAL_DCMI_STATE_RESET)
00104   {
00105     /* Allocate lock resource and initialize it */
00106     hdcmi->Lock = HAL_UNLOCKED;
00107     /* Init the low level hardware */
00108   /* Init the DCMI Callback settings */
00109 #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
00110     hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback  */
00111     hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback  */
00112     hdcmi->LineEventCallback  = HAL_DCMI_LineEventCallback;  /* Legacy weak LineEventCallback   */
00113     hdcmi->ErrorCallback      = HAL_DCMI_ErrorCallback;      /* Legacy weak ErrorCallback       */
00114 
00115     if(hdcmi->MspInitCallback == NULL)
00116     {
00117       /* Legacy weak MspInit Callback        */
00118       hdcmi->MspInitCallback = HAL_DCMI_MspInit;
00119     }
00120     /* Initialize the low level hardware (MSP) */
00121     hdcmi->MspInitCallback(hdcmi);
00122 #else
00123     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
00124     HAL_DCMI_MspInit(hdcmi);
00125 #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
00126     HAL_DCMI_MspInit(hdcmi);
00127   }
00128 
00129   /* Change the DCMI state */
00130   hdcmi->State = HAL_DCMI_STATE_BUSY;
00131                           /* Configures the HS, VS, DE and PC polarity */
00132   hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL  | DCMI_CR_VSPOL  | DCMI_CR_EDM_0 |\
00133                            DCMI_CR_EDM_1  | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG  |\
00134                            DCMI_CR_ESS
00135 #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00136                            | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
00137                            DCMI_CR_LSM | DCMI_CR_OELS
00138 #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
00139                            );
00140   hdcmi->Instance->CR |=  (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
00141                                      hdcmi->Init.VSPolarity  | hdcmi->Init.HSPolarity  |\
00142                                      hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
00143                                      hdcmi->Init.JPEGMode
00144 #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
00145                                      | hdcmi->Init.ByteSelectMode |\
00146                                      hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
00147                                      hdcmi->Init.LineSelectStart
00148 #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
00149                                      );
00150   if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
00151   {
00152     hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode)    |
00153                              ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
00154                              ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
00155                              ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
00156 
00157   }
00158 
00159   /* Enable the Line, Vsync, Error and Overrun interrupts */
00160   __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
00161 
00162   /* Update error code */
00163   hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
00164 
00165   /* Initialize the DCMI state*/
00166   hdcmi->State  = HAL_DCMI_STATE_READY;
00167 
00168   return HAL_OK;
00169 }
00170 
00171 /**
00172   * @}
00173   */
00174 #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\
00175           STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
00176 #endif /* HAL_DCMI_MODULE_ENABLED */
00177 /**
00178   * @}
00179   */
00180 
00181 /**
00182   * @}
00183   */
00184 
00185 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/