001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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