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