1 | /** |
---|
2 | ****************************************************************************** |
---|
3 | * @file stm32f7xx_hal_dcmi.c |
---|
4 | * @author MCD Application Team |
---|
5 | * @version V1.0.1 |
---|
6 | * @date 25-June-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 "stm32f7xx_hal.h" |
---|
95 | |
---|
96 | /** @addtogroup STM32F7xx_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 | /* Private typedef -----------------------------------------------------------*/ |
---|
107 | /* Private define ------------------------------------------------------------*/ |
---|
108 | #define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* 1s */ |
---|
109 | /* Private macro -------------------------------------------------------------*/ |
---|
110 | /* Private variables ---------------------------------------------------------*/ |
---|
111 | /* Private function prototypes -----------------------------------------------*/ |
---|
112 | static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma); |
---|
113 | static void DCMI_DMAError(DMA_HandleTypeDef *hdma); |
---|
114 | |
---|
115 | /* Exported functions --------------------------------------------------------*/ |
---|
116 | |
---|
117 | /** @defgroup DCMI_Exported_Functions DCMI Exported Functions |
---|
118 | * @{ |
---|
119 | */ |
---|
120 | |
---|
121 | /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions |
---|
122 | * @brief Initialization and Configuration functions |
---|
123 | * |
---|
124 | @verbatim |
---|
125 | =============================================================================== |
---|
126 | ##### Initialization and Configuration functions ##### |
---|
127 | =============================================================================== |
---|
128 | [..] This section provides functions allowing to: |
---|
129 | (+) Initialize and configure the DCMI |
---|
130 | (+) De-initialize the DCMI |
---|
131 | |
---|
132 | @endverbatim |
---|
133 | * @{ |
---|
134 | */ |
---|
135 | |
---|
136 | /** |
---|
137 | * @brief Initializes the DCMI according to the specified |
---|
138 | * parameters in the DCMI_InitTypeDef and create the associated handle. |
---|
139 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
140 | * the configuration information for DCMI. |
---|
141 | * @retval HAL status |
---|
142 | */ |
---|
143 | __weak HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi) |
---|
144 | { |
---|
145 | /* Check the DCMI peripheral state */ |
---|
146 | if(hdcmi == NULL) |
---|
147 | { |
---|
148 | return HAL_ERROR; |
---|
149 | } |
---|
150 | |
---|
151 | /* Check function parameters */ |
---|
152 | assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance)); |
---|
153 | assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode)); |
---|
154 | assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity)); |
---|
155 | assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity)); |
---|
156 | assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity)); |
---|
157 | assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate)); |
---|
158 | assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode)); |
---|
159 | assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode)); |
---|
160 | |
---|
161 | if(hdcmi->State == HAL_DCMI_STATE_RESET) |
---|
162 | { |
---|
163 | /* Allocate lock resource and initialize it */ |
---|
164 | hdcmi->Lock = HAL_UNLOCKED; |
---|
165 | /* Init the low level hardware */ |
---|
166 | HAL_DCMI_MspInit(hdcmi); |
---|
167 | } |
---|
168 | |
---|
169 | /* Change the DCMI state */ |
---|
170 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
171 | |
---|
172 | /* Set DCMI parameters */ |
---|
173 | /* Configures the HS, VS, DE and PC polarity */ |
---|
174 | hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | |
---|
175 | DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | |
---|
176 | DCMI_CR_ESS); |
---|
177 | hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \ |
---|
178 | hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \ |
---|
179 | hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \ |
---|
180 | hdcmi->Init.JPEGMode); |
---|
181 | |
---|
182 | if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED) |
---|
183 | { |
---|
184 | DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | |
---|
185 | ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)| |
---|
186 | ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) | |
---|
187 | ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24)); |
---|
188 | } |
---|
189 | |
---|
190 | /* Enable the Line interrupt */ |
---|
191 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE); |
---|
192 | |
---|
193 | /* Enable the VSYNC interrupt */ |
---|
194 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC); |
---|
195 | |
---|
196 | /* Enable the Frame capture complete interrupt */ |
---|
197 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME); |
---|
198 | |
---|
199 | /* Enable the Synchronization error interrupt */ |
---|
200 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR); |
---|
201 | |
---|
202 | /* Enable the Overflow interrupt */ |
---|
203 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF); |
---|
204 | |
---|
205 | /* Enable DCMI by setting DCMIEN bit */ |
---|
206 | __HAL_DCMI_ENABLE(hdcmi); |
---|
207 | |
---|
208 | /* Update error code */ |
---|
209 | hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; |
---|
210 | |
---|
211 | /* Initialize the DCMI state*/ |
---|
212 | hdcmi->State = HAL_DCMI_STATE_READY; |
---|
213 | |
---|
214 | return HAL_OK; |
---|
215 | } |
---|
216 | |
---|
217 | /** |
---|
218 | * @brief Deinitializes the DCMI peripheral registers to their default reset |
---|
219 | * values. |
---|
220 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
221 | * the configuration information for DCMI. |
---|
222 | * @retval HAL status |
---|
223 | */ |
---|
224 | |
---|
225 | HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi) |
---|
226 | { |
---|
227 | /* DeInit the low level hardware */ |
---|
228 | HAL_DCMI_MspDeInit(hdcmi); |
---|
229 | |
---|
230 | /* Update error code */ |
---|
231 | hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; |
---|
232 | |
---|
233 | /* Initialize the DCMI state*/ |
---|
234 | hdcmi->State = HAL_DCMI_STATE_RESET; |
---|
235 | |
---|
236 | /* Release Lock */ |
---|
237 | __HAL_UNLOCK(hdcmi); |
---|
238 | |
---|
239 | return HAL_OK; |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * @brief Initializes the DCMI MSP. |
---|
244 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
245 | * the configuration information for DCMI. |
---|
246 | * @retval None |
---|
247 | */ |
---|
248 | __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) |
---|
249 | { |
---|
250 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
251 | the HAL_DCMI_MspInit could be implemented in the user file |
---|
252 | */ |
---|
253 | } |
---|
254 | |
---|
255 | /** |
---|
256 | * @brief DeInitializes the DCMI MSP. |
---|
257 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
258 | * the configuration information for DCMI. |
---|
259 | * @retval None |
---|
260 | */ |
---|
261 | __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi) |
---|
262 | { |
---|
263 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
264 | the HAL_DCMI_MspDeInit could be implemented in the user file |
---|
265 | */ |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * @} |
---|
270 | */ |
---|
271 | /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions |
---|
272 | * @brief IO operation functions |
---|
273 | * |
---|
274 | @verbatim |
---|
275 | =============================================================================== |
---|
276 | ##### IO operation functions ##### |
---|
277 | =============================================================================== |
---|
278 | [..] This section provides functions allowing to: |
---|
279 | (+) Configure destination address and data length and |
---|
280 | Enables DCMI DMA request and enables DCMI capture |
---|
281 | (+) Stop the DCMI capture. |
---|
282 | (+) Handles DCMI interrupt request. |
---|
283 | |
---|
284 | @endverbatim |
---|
285 | * @{ |
---|
286 | */ |
---|
287 | |
---|
288 | /** |
---|
289 | * @brief Enables DCMI DMA request and enables DCMI capture |
---|
290 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
291 | * the configuration information for DCMI. |
---|
292 | * @param DCMI_Mode: DCMI capture mode snapshot or continuous grab. |
---|
293 | * @param pData: The destination memory Buffer address (LCD Frame buffer). |
---|
294 | * @param Length: The length of capture to be transferred. |
---|
295 | * @retval HAL status |
---|
296 | */ |
---|
297 | HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef* hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length) |
---|
298 | { |
---|
299 | /* Initialize the second memory address */ |
---|
300 | uint32_t SecondMemAddress = 0; |
---|
301 | |
---|
302 | /* Check function parameters */ |
---|
303 | assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode)); |
---|
304 | |
---|
305 | /* Process Locked */ |
---|
306 | __HAL_LOCK(hdcmi); |
---|
307 | |
---|
308 | /* Lock the DCMI peripheral state */ |
---|
309 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
310 | |
---|
311 | /* Check the parameters */ |
---|
312 | assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode)); |
---|
313 | |
---|
314 | /* Configure the DCMI Mode */ |
---|
315 | hdcmi->Instance->CR &= ~(DCMI_CR_CM); |
---|
316 | hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode); |
---|
317 | |
---|
318 | /* Set the DMA memory0 conversion complete callback */ |
---|
319 | hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAConvCplt; |
---|
320 | |
---|
321 | /* Set the DMA error callback */ |
---|
322 | hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError; |
---|
323 | |
---|
324 | if(Length <= 0xFFFF) |
---|
325 | { |
---|
326 | /* Enable the DMA Stream */ |
---|
327 | HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length); |
---|
328 | } |
---|
329 | else /* DCMI_DOUBLE_BUFFER Mode */ |
---|
330 | { |
---|
331 | /* Set the DMA memory1 conversion complete callback */ |
---|
332 | hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAConvCplt; |
---|
333 | |
---|
334 | /* Initialize transfer parameters */ |
---|
335 | hdcmi->XferCount = 1; |
---|
336 | hdcmi->XferSize = Length; |
---|
337 | hdcmi->pBuffPtr = pData; |
---|
338 | |
---|
339 | /* Get the number of buffer */ |
---|
340 | while(hdcmi->XferSize > 0xFFFF) |
---|
341 | { |
---|
342 | hdcmi->XferSize = (hdcmi->XferSize/2); |
---|
343 | hdcmi->XferCount = hdcmi->XferCount*2; |
---|
344 | } |
---|
345 | |
---|
346 | /* Update DCMI counter and transfer number*/ |
---|
347 | hdcmi->XferCount = (hdcmi->XferCount - 2); |
---|
348 | hdcmi->XferTransferNumber = hdcmi->XferCount; |
---|
349 | |
---|
350 | /* Update second memory address */ |
---|
351 | SecondMemAddress = (uint32_t)(pData + (4*hdcmi->XferSize)); |
---|
352 | |
---|
353 | /* Start DMA multi buffer transfer */ |
---|
354 | HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize); |
---|
355 | } |
---|
356 | |
---|
357 | /* Enable Capture */ |
---|
358 | DCMI->CR |= DCMI_CR_CAPTURE; |
---|
359 | |
---|
360 | /* Return function status */ |
---|
361 | return HAL_OK; |
---|
362 | } |
---|
363 | |
---|
364 | /** |
---|
365 | * @brief Disable DCMI DMA request and Disable DCMI capture |
---|
366 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
367 | * the configuration information for DCMI. |
---|
368 | * @retval HAL status |
---|
369 | */ |
---|
370 | HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef* hdcmi) |
---|
371 | { |
---|
372 | uint32_t tickstart = 0; |
---|
373 | |
---|
374 | /* Lock the DCMI peripheral state */ |
---|
375 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
376 | |
---|
377 | __HAL_DCMI_DISABLE(hdcmi); |
---|
378 | |
---|
379 | /* Disable Capture */ |
---|
380 | DCMI->CR &= ~(DCMI_CR_CAPTURE); |
---|
381 | |
---|
382 | /* Get tick */ |
---|
383 | tickstart = HAL_GetTick(); |
---|
384 | |
---|
385 | /* Check if the DCMI capture effectively disabled */ |
---|
386 | while((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0) |
---|
387 | { |
---|
388 | if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DCMI_STOP) |
---|
389 | { |
---|
390 | /* Process Unlocked */ |
---|
391 | __HAL_UNLOCK(hdcmi); |
---|
392 | |
---|
393 | /* Update error code */ |
---|
394 | hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT; |
---|
395 | |
---|
396 | /* Change DCMI state */ |
---|
397 | hdcmi->State = HAL_DCMI_STATE_TIMEOUT; |
---|
398 | |
---|
399 | return HAL_TIMEOUT; |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | /* Disable the DMA */ |
---|
404 | HAL_DMA_Abort(hdcmi->DMA_Handle); |
---|
405 | |
---|
406 | /* Update error code */ |
---|
407 | hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE; |
---|
408 | |
---|
409 | /* Change DCMI state */ |
---|
410 | hdcmi->State = HAL_DCMI_STATE_READY; |
---|
411 | |
---|
412 | /* Process Unlocked */ |
---|
413 | __HAL_UNLOCK(hdcmi); |
---|
414 | |
---|
415 | /* Return function status */ |
---|
416 | return HAL_OK; |
---|
417 | } |
---|
418 | |
---|
419 | /** |
---|
420 | * @brief Handles DCMI interrupt request. |
---|
421 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
422 | * the configuration information for the DCMI. |
---|
423 | * @retval None |
---|
424 | */ |
---|
425 | void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi) |
---|
426 | { |
---|
427 | /* Synchronization error interrupt management *******************************/ |
---|
428 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_ERRRI) != RESET) |
---|
429 | { |
---|
430 | if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_ERR) != RESET) |
---|
431 | { |
---|
432 | /* Disable the Synchronization error interrupt */ |
---|
433 | __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_ERR); |
---|
434 | |
---|
435 | /* Clear the Synchronization error flag */ |
---|
436 | __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI); |
---|
437 | |
---|
438 | /* Update error code */ |
---|
439 | hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC; |
---|
440 | |
---|
441 | /* Change DCMI state */ |
---|
442 | hdcmi->State = HAL_DCMI_STATE_ERROR; |
---|
443 | |
---|
444 | /* Process Unlocked */ |
---|
445 | __HAL_UNLOCK(hdcmi); |
---|
446 | |
---|
447 | /* Abort the DMA Transfer */ |
---|
448 | HAL_DMA_Abort(hdcmi->DMA_Handle); |
---|
449 | |
---|
450 | /* Synchronization error Callback */ |
---|
451 | HAL_DCMI_ErrorCallback(hdcmi); |
---|
452 | } |
---|
453 | } |
---|
454 | /* Overflow interrupt management ********************************************/ |
---|
455 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_OVFRI) != RESET) |
---|
456 | { |
---|
457 | if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_OVF) != RESET) |
---|
458 | { |
---|
459 | /* Disable the Overflow interrupt */ |
---|
460 | __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_OVF); |
---|
461 | |
---|
462 | /* Clear the Overflow flag */ |
---|
463 | __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVFRI); |
---|
464 | |
---|
465 | /* Update error code */ |
---|
466 | hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVF; |
---|
467 | |
---|
468 | /* Change DCMI state */ |
---|
469 | hdcmi->State = HAL_DCMI_STATE_ERROR; |
---|
470 | |
---|
471 | /* Process Unlocked */ |
---|
472 | __HAL_UNLOCK(hdcmi); |
---|
473 | |
---|
474 | /* Abort the DMA Transfer */ |
---|
475 | HAL_DMA_Abort(hdcmi->DMA_Handle); |
---|
476 | |
---|
477 | /* Overflow Callback */ |
---|
478 | HAL_DCMI_ErrorCallback(hdcmi); |
---|
479 | } |
---|
480 | } |
---|
481 | /* Line Interrupt management ************************************************/ |
---|
482 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_LINERI) != RESET) |
---|
483 | { |
---|
484 | if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_LINE) != RESET) |
---|
485 | { |
---|
486 | /* Clear the Line interrupt flag */ |
---|
487 | __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI); |
---|
488 | |
---|
489 | /* Process Unlocked */ |
---|
490 | __HAL_UNLOCK(hdcmi); |
---|
491 | |
---|
492 | /* Line interrupt Callback */ |
---|
493 | HAL_DCMI_LineEventCallback(hdcmi); |
---|
494 | } |
---|
495 | } |
---|
496 | /* VSYNC interrupt management ***********************************************/ |
---|
497 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_VSYNCRI) != RESET) |
---|
498 | { |
---|
499 | if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_VSYNC) != RESET) |
---|
500 | { |
---|
501 | /* Disable the VSYNC interrupt */ |
---|
502 | __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_VSYNC); |
---|
503 | |
---|
504 | /* Clear the VSYNC flag */ |
---|
505 | __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI); |
---|
506 | |
---|
507 | /* Process Unlocked */ |
---|
508 | __HAL_UNLOCK(hdcmi); |
---|
509 | |
---|
510 | /* VSYNC Callback */ |
---|
511 | HAL_DCMI_VsyncEventCallback(hdcmi); |
---|
512 | } |
---|
513 | } |
---|
514 | /* End of Frame interrupt management ****************************************/ |
---|
515 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET) |
---|
516 | { |
---|
517 | if(__HAL_DCMI_GET_IT_SOURCE(hdcmi, DCMI_IT_FRAME) != RESET) |
---|
518 | { |
---|
519 | /* Disable the End of Frame interrupt */ |
---|
520 | __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME); |
---|
521 | |
---|
522 | /* Clear the End of Frame flag */ |
---|
523 | __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI); |
---|
524 | |
---|
525 | /* Process Unlocked */ |
---|
526 | __HAL_UNLOCK(hdcmi); |
---|
527 | |
---|
528 | /* End of Frame Callback */ |
---|
529 | HAL_DCMI_FrameEventCallback(hdcmi); |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | /** |
---|
535 | * @brief Error DCMI callback. |
---|
536 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
537 | * the configuration information for DCMI. |
---|
538 | * @retval None |
---|
539 | */ |
---|
540 | __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi) |
---|
541 | { |
---|
542 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
543 | the HAL_DCMI_ErrorCallback could be implemented in the user file |
---|
544 | */ |
---|
545 | } |
---|
546 | |
---|
547 | /** |
---|
548 | * @brief Line Event callback. |
---|
549 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
550 | * the configuration information for DCMI. |
---|
551 | * @retval None |
---|
552 | */ |
---|
553 | __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi) |
---|
554 | { |
---|
555 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
556 | the HAL_DCMI_LineEventCallback could be implemented in the user file |
---|
557 | */ |
---|
558 | } |
---|
559 | |
---|
560 | /** |
---|
561 | * @brief VSYNC Event callback. |
---|
562 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
563 | * the configuration information for DCMI. |
---|
564 | * @retval None |
---|
565 | */ |
---|
566 | __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi) |
---|
567 | { |
---|
568 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
569 | the HAL_DCMI_VsyncEventCallback could be implemented in the user file |
---|
570 | */ |
---|
571 | } |
---|
572 | |
---|
573 | /** |
---|
574 | * @brief Frame Event callback. |
---|
575 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
576 | * the configuration information for DCMI. |
---|
577 | * @retval None |
---|
578 | */ |
---|
579 | __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) |
---|
580 | { |
---|
581 | /* NOTE : This function Should not be modified, when the callback is needed, |
---|
582 | the HAL_DCMI_FrameEventCallback could be implemented in the user file |
---|
583 | */ |
---|
584 | } |
---|
585 | |
---|
586 | /** |
---|
587 | * @} |
---|
588 | */ |
---|
589 | |
---|
590 | /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions |
---|
591 | * @brief Peripheral Control functions |
---|
592 | * |
---|
593 | @verbatim |
---|
594 | =============================================================================== |
---|
595 | ##### Peripheral Control functions ##### |
---|
596 | =============================================================================== |
---|
597 | [..] This section provides functions allowing to: |
---|
598 | (+) Configure the CROP feature. |
---|
599 | (+) Enable/Disable the CROP feature. |
---|
600 | (+) Enable/Disable the JPEG feature. |
---|
601 | |
---|
602 | @endverbatim |
---|
603 | * @{ |
---|
604 | */ |
---|
605 | |
---|
606 | /** |
---|
607 | * @brief Configure the DCMI CROP coordinate. |
---|
608 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
609 | * the configuration information for DCMI. |
---|
610 | * @param YSize: DCMI Line number |
---|
611 | * @param XSize: DCMI Pixel per line |
---|
612 | * @param X0: DCMI window X offset |
---|
613 | * @param Y0: DCMI window Y offset |
---|
614 | * @retval HAL status |
---|
615 | */ |
---|
616 | HAL_StatusTypeDef HAL_DCMI_ConfigCROP(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize) |
---|
617 | { |
---|
618 | /* Process Locked */ |
---|
619 | __HAL_LOCK(hdcmi); |
---|
620 | |
---|
621 | /* Lock the DCMI peripheral state */ |
---|
622 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
623 | |
---|
624 | /* Check the parameters */ |
---|
625 | assert_param(IS_DCMI_WINDOW_COORDINATE(X0)); |
---|
626 | assert_param(IS_DCMI_WINDOW_HEIGHT(Y0)); |
---|
627 | assert_param(IS_DCMI_WINDOW_COORDINATE(XSize)); |
---|
628 | assert_param(IS_DCMI_WINDOW_COORDINATE(YSize)); |
---|
629 | |
---|
630 | /* Configure CROP */ |
---|
631 | DCMI->CWSIZER = (XSize | (YSize << 16)); |
---|
632 | DCMI->CWSTRTR = (X0 | (Y0 << 16)); |
---|
633 | |
---|
634 | /* Initialize the DCMI state*/ |
---|
635 | hdcmi->State = HAL_DCMI_STATE_READY; |
---|
636 | |
---|
637 | /* Process Unlocked */ |
---|
638 | __HAL_UNLOCK(hdcmi); |
---|
639 | |
---|
640 | return HAL_OK; |
---|
641 | } |
---|
642 | |
---|
643 | /** |
---|
644 | * @brief Disable the Crop feature. |
---|
645 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
646 | * the configuration information for DCMI. |
---|
647 | * @retval HAL status |
---|
648 | */ |
---|
649 | HAL_StatusTypeDef HAL_DCMI_DisableCROP(DCMI_HandleTypeDef *hdcmi) |
---|
650 | { |
---|
651 | /* Process Locked */ |
---|
652 | __HAL_LOCK(hdcmi); |
---|
653 | |
---|
654 | /* Lock the DCMI peripheral state */ |
---|
655 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
656 | |
---|
657 | /* Disable DCMI Crop feature */ |
---|
658 | DCMI->CR &= ~(uint32_t)DCMI_CR_CROP; |
---|
659 | |
---|
660 | /* Change the DCMI state*/ |
---|
661 | hdcmi->State = HAL_DCMI_STATE_READY; |
---|
662 | |
---|
663 | /* Process Unlocked */ |
---|
664 | __HAL_UNLOCK(hdcmi); |
---|
665 | |
---|
666 | return HAL_OK; |
---|
667 | } |
---|
668 | |
---|
669 | /** |
---|
670 | * @brief Enable the Crop feature. |
---|
671 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
672 | * the configuration information for DCMI. |
---|
673 | * @retval HAL status |
---|
674 | */ |
---|
675 | HAL_StatusTypeDef HAL_DCMI_EnableCROP(DCMI_HandleTypeDef *hdcmi) |
---|
676 | { |
---|
677 | /* Process Locked */ |
---|
678 | __HAL_LOCK(hdcmi); |
---|
679 | |
---|
680 | /* Lock the DCMI peripheral state */ |
---|
681 | hdcmi->State = HAL_DCMI_STATE_BUSY; |
---|
682 | |
---|
683 | /* Enable DCMI Crop feature */ |
---|
684 | DCMI->CR |= (uint32_t)DCMI_CR_CROP; |
---|
685 | |
---|
686 | /* Change the DCMI state*/ |
---|
687 | hdcmi->State = HAL_DCMI_STATE_READY; |
---|
688 | |
---|
689 | /* Process Unlocked */ |
---|
690 | __HAL_UNLOCK(hdcmi); |
---|
691 | |
---|
692 | return HAL_OK; |
---|
693 | } |
---|
694 | |
---|
695 | /** |
---|
696 | * @} |
---|
697 | */ |
---|
698 | |
---|
699 | /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions |
---|
700 | * @brief Peripheral State functions |
---|
701 | * |
---|
702 | @verbatim |
---|
703 | =============================================================================== |
---|
704 | ##### Peripheral State and Errors functions ##### |
---|
705 | =============================================================================== |
---|
706 | [..] |
---|
707 | This subsection provides functions allowing to |
---|
708 | (+) Check the DCMI state. |
---|
709 | (+) Get the specific DCMI error flag. |
---|
710 | |
---|
711 | @endverbatim |
---|
712 | * @{ |
---|
713 | */ |
---|
714 | |
---|
715 | /** |
---|
716 | * @brief Return the DCMI state |
---|
717 | * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains |
---|
718 | * the configuration information for DCMI. |
---|
719 | * @retval HAL state |
---|
720 | */ |
---|
721 | HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi) |
---|
722 | { |
---|
723 | return hdcmi->State; |
---|
724 | } |
---|
725 | |
---|
726 | /** |
---|
727 | * @brief Return the DCMI error code |
---|
728 | * @param hdcmi : pointer to a DCMI_HandleTypeDef structure that contains |
---|
729 | * the configuration information for DCMI. |
---|
730 | * @retval DCMI Error Code |
---|
731 | */ |
---|
732 | uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi) |
---|
733 | { |
---|
734 | return hdcmi->ErrorCode; |
---|
735 | } |
---|
736 | |
---|
737 | /** |
---|
738 | * @} |
---|
739 | */ |
---|
740 | /* Private functions ---------------------------------------------------------*/ |
---|
741 | /** @defgroup DCMI_Private_Functions DCMI Private Functions |
---|
742 | * @{ |
---|
743 | */ |
---|
744 | /** |
---|
745 | * @brief DMA conversion complete callback. |
---|
746 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
---|
747 | * the configuration information for the specified DMA module. |
---|
748 | * @retval None |
---|
749 | */ |
---|
750 | static void DCMI_DMAConvCplt(DMA_HandleTypeDef *hdma) |
---|
751 | { |
---|
752 | uint32_t tmp = 0; |
---|
753 | |
---|
754 | DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
---|
755 | hdcmi->State= HAL_DCMI_STATE_READY; |
---|
756 | |
---|
757 | if(hdcmi->XferCount != 0) |
---|
758 | { |
---|
759 | /* Update memory 0 address location */ |
---|
760 | tmp = ((hdcmi->DMA_Handle->Instance->CR) & DMA_SxCR_CT); |
---|
761 | if(((hdcmi->XferCount % 2) == 0) && (tmp != 0)) |
---|
762 | { |
---|
763 | tmp = hdcmi->DMA_Handle->Instance->M0AR; |
---|
764 | HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY0); |
---|
765 | hdcmi->XferCount--; |
---|
766 | } |
---|
767 | /* Update memory 1 address location */ |
---|
768 | else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0) |
---|
769 | { |
---|
770 | tmp = hdcmi->DMA_Handle->Instance->M1AR; |
---|
771 | HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8*hdcmi->XferSize)), MEMORY1); |
---|
772 | hdcmi->XferCount--; |
---|
773 | } |
---|
774 | } |
---|
775 | /* Update memory 0 address location */ |
---|
776 | else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) != 0) |
---|
777 | { |
---|
778 | hdcmi->DMA_Handle->Instance->M0AR = hdcmi->pBuffPtr; |
---|
779 | } |
---|
780 | /* Update memory 1 address location */ |
---|
781 | else if((hdcmi->DMA_Handle->Instance->CR & DMA_SxCR_CT) == 0) |
---|
782 | { |
---|
783 | tmp = hdcmi->pBuffPtr; |
---|
784 | hdcmi->DMA_Handle->Instance->M1AR = (tmp + (4*hdcmi->XferSize)); |
---|
785 | hdcmi->XferCount = hdcmi->XferTransferNumber; |
---|
786 | } |
---|
787 | |
---|
788 | if(__HAL_DCMI_GET_FLAG(hdcmi, DCMI_FLAG_FRAMERI) != RESET) |
---|
789 | { |
---|
790 | /* Process Unlocked */ |
---|
791 | __HAL_UNLOCK(hdcmi); |
---|
792 | |
---|
793 | /* FRAME Callback */ |
---|
794 | HAL_DCMI_FrameEventCallback(hdcmi); |
---|
795 | } |
---|
796 | } |
---|
797 | |
---|
798 | /** |
---|
799 | * @brief DMA error callback |
---|
800 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
---|
801 | * the configuration information for the specified DMA module. |
---|
802 | * @retval None |
---|
803 | */ |
---|
804 | static void DCMI_DMAError(DMA_HandleTypeDef *hdma) |
---|
805 | { |
---|
806 | DCMI_HandleTypeDef* hdcmi = ( DCMI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
---|
807 | hdcmi->State= HAL_DCMI_STATE_READY; |
---|
808 | HAL_DCMI_ErrorCallback(hdcmi); |
---|
809 | } |
---|
810 | |
---|
811 | /** |
---|
812 | * @} |
---|
813 | */ |
---|
814 | |
---|
815 | /** |
---|
816 | * @} |
---|
817 | */ |
---|
818 | #endif /* HAL_DCMI_MODULE_ENABLED */ |
---|
819 | /** |
---|
820 | * @} |
---|
821 | */ |
---|
822 | |
---|
823 | /** |
---|
824 | * @} |
---|
825 | */ |
---|
826 | |
---|
827 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
---|