Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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