[303] | 1 | /**
|
---|
| 2 | ******************************************************************************
|
---|
| 3 | * @file stm32f4xx_hal_dcmi_ex.c
|
---|
| 4 | * @author MCD Application Team
|
---|
| 5 | * @version V1.4.1
|
---|
| 6 | * @date 09-October-2015
|
---|
| 7 | * @brief DCMI Extension HAL module driver.
|
---|
| 8 | * This file provides firmware functions to manage the following
|
---|
| 9 | * functionalities of DCMI extension peripheral:
|
---|
| 10 | * + Extension features functions
|
---|
| 11 | *
|
---|
| 12 | @verbatim
|
---|
| 13 | ==============================================================================
|
---|
| 14 | ##### DCMI peripheral extension features #####
|
---|
| 15 | ==============================================================================
|
---|
| 16 |
|
---|
| 17 | [..] Comparing to other previous devices, the DCMI interface for STM32F446xx
|
---|
| 18 | devices contains the following additional features :
|
---|
| 19 |
|
---|
| 20 | (+) Support of Black and White cameras
|
---|
| 21 |
|
---|
| 22 | ##### How to use this driver #####
|
---|
| 23 | ==============================================================================
|
---|
| 24 | [..] This driver provides functions to manage the Black and White feature
|
---|
| 25 |
|
---|
| 26 | @endverbatim
|
---|
| 27 | ******************************************************************************
|
---|
| 28 | * @attention
|
---|
| 29 | *
|
---|
| 30 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
| 31 | *
|
---|
| 32 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 33 | * are permitted provided that the following conditions are met:
|
---|
| 34 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 35 | * this list of conditions and the following disclaimer.
|
---|
| 36 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 37 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 38 | * and/or other materials provided with the distribution.
|
---|
| 39 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
| 40 | * may be used to endorse or promote products derived from this software
|
---|
| 41 | * without specific prior written permission.
|
---|
| 42 | *
|
---|
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 44 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 46 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
| 47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
| 49 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
| 50 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 51 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 53 | *
|
---|
| 54 | ******************************************************************************
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /* Includes ------------------------------------------------------------------*/
|
---|
| 58 | #include "stm32f4xx_hal.h"
|
---|
| 59 |
|
---|
| 60 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
| 61 | * @{
|
---|
| 62 | */
|
---|
| 63 | /** @defgroup DCMIEx DCMIEx
|
---|
| 64 | * @brief DCMI Extended HAL module driver
|
---|
| 65 | * @{
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 | #ifdef HAL_DCMI_MODULE_ENABLED
|
---|
| 69 |
|
---|
| 70 | #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\
|
---|
| 71 | defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
---|
| 72 | /* Private typedef -----------------------------------------------------------*/
|
---|
| 73 | /* Private define ------------------------------------------------------------*/
|
---|
| 74 | /* Private macro -------------------------------------------------------------*/
|
---|
| 75 | /* Private variables ---------------------------------------------------------*/
|
---|
| 76 | /* Private function prototypes -----------------------------------------------*/
|
---|
| 77 | /* Exported functions --------------------------------------------------------*/
|
---|
| 78 |
|
---|
| 79 | /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
|
---|
| 80 | * @{
|
---|
| 81 | */
|
---|
| 82 |
|
---|
| 83 | /** @defgroup DCMIEx_Exported_Functions_Group1 Initialization and Configuration functions
|
---|
| 84 | * @brief Initialization and Configuration functions
|
---|
| 85 | *
|
---|
| 86 | @verbatim
|
---|
| 87 | ===============================================================================
|
---|
| 88 | ##### Initialization and Configuration functions #####
|
---|
| 89 | ===============================================================================
|
---|
| 90 | [..] This section provides functions allowing to:
|
---|
| 91 | (+) Initialize and configure the DCMI
|
---|
| 92 | (+) De-initialize the DCMI
|
---|
| 93 |
|
---|
| 94 | @endverbatim
|
---|
| 95 | * @{
|
---|
| 96 | */
|
---|
| 97 |
|
---|
| 98 | /**
|
---|
| 99 | * @brief Initializes the DCMI according to the specified
|
---|
| 100 | * parameters in the DCMI_InitTypeDef and create the associated handle.
|
---|
| 101 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
|
---|
| 102 | * the configuration information for DCMI.
|
---|
| 103 | * @retval HAL status
|
---|
| 104 | */
|
---|
| 105 | HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
|
---|
| 106 | {
|
---|
| 107 | /* Check the DCMI peripheral state */
|
---|
| 108 | if(hdcmi == NULL)
|
---|
| 109 | {
|
---|
| 110 | return HAL_ERROR;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /* Check function parameters */
|
---|
| 114 | assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
|
---|
| 115 | assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
|
---|
| 116 | assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
|
---|
| 117 | assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
|
---|
| 118 | assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
|
---|
| 119 | assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
|
---|
| 120 | assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
|
---|
| 121 | assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
|
---|
| 122 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
---|
| 123 | assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
|
---|
| 124 | assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
|
---|
| 125 | assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
|
---|
| 126 | assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
|
---|
| 127 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
| 128 | if(hdcmi->State == HAL_DCMI_STATE_RESET)
|
---|
| 129 | {
|
---|
| 130 | /* Init the low level hardware */
|
---|
| 131 | HAL_DCMI_MspInit(hdcmi);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /* Change the DCMI state */
|
---|
| 135 | hdcmi->State = HAL_DCMI_STATE_BUSY;
|
---|
| 136 | /* Configures the HS, VS, DE and PC polarity */
|
---|
| 137 | hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
|
---|
| 138 | DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
|
---|
| 139 | DCMI_CR_ESS
|
---|
| 140 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
---|
| 141 | | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
|
---|
| 142 | DCMI_CR_LSM | DCMI_CR_OELS
|
---|
| 143 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
| 144 | );
|
---|
| 145 | hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
|
---|
| 146 | hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
|
---|
| 147 | hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
|
---|
| 148 | hdcmi->Init.JPEGMode
|
---|
| 149 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
---|
| 150 | | hdcmi->Init.ByteSelectMode |\
|
---|
| 151 | hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
|
---|
| 152 | hdcmi->Init.LineSelectStart
|
---|
| 153 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
| 154 | );
|
---|
| 155 | if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
|
---|
| 156 | {
|
---|
| 157 | DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
|
---|
| 158 | ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)|
|
---|
| 159 | ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) |
|
---|
| 160 | ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24));
|
---|
| 161 |
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | /* Enable the Line interrupt */
|
---|
| 165 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE);
|
---|
| 166 |
|
---|
| 167 | /* Enable the VSYNC interrupt */
|
---|
| 168 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC);
|
---|
| 169 |
|
---|
| 170 | /* Enable the Frame capture complete interrupt */
|
---|
| 171 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
|
---|
| 172 |
|
---|
| 173 | /* Enable the Synchronization error interrupt */
|
---|
| 174 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR);
|
---|
| 175 |
|
---|
| 176 | /* Enable the Overflow interrupt */
|
---|
| 177 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF);
|
---|
| 178 |
|
---|
| 179 | /* Enable DCMI by setting DCMIEN bit */
|
---|
| 180 | __HAL_DCMI_ENABLE(hdcmi);
|
---|
| 181 |
|
---|
| 182 | /* Update error code */
|
---|
| 183 | hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
|
---|
| 184 |
|
---|
| 185 | /* Initialize the DCMI state*/
|
---|
| 186 | hdcmi->State = HAL_DCMI_STATE_READY;
|
---|
| 187 |
|
---|
| 188 | return HAL_OK;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | /**
|
---|
| 193 | * @}
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | /**
|
---|
| 197 | * @}
|
---|
| 198 | */
|
---|
| 199 |
|
---|
| 200 | /**
|
---|
| 201 | * @}
|
---|
| 202 | */
|
---|
| 203 | #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\
|
---|
| 204 | STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
| 205 | #endif /* HAL_DCMI_MODULE_ENABLED */
|
---|
| 206 | /**
|
---|
| 207 | * @}
|
---|
| 208 | */
|
---|
| 209 |
|
---|
| 210 | /**
|
---|
| 211 | * @}
|
---|
| 212 | */
|
---|
| 213 |
|
---|
| 214 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|