1 /**
2 ******************************************************************************
3 * @file stm32h7rsxx_hal_dcmipp.c
4 * @author MCD Application Team
5 * @brief DCMIPP HAL module driver
6 * This file provides firmware functions to manage the following
7 * functionalities of the DCMIPP (Digital Camera Interface Pixel Pipeline) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral Control functions
11 * + Peripheral State and Error functions
12 *
13 ******************************************************************************
14 * @attention
15 *
16 * Copyright (c) 2022 STMicroelectronics.
17 * All rights reserved.
18 *
19 * This software is licensed under terms that can be found in the LICENSE file
20 * in the root directory of this software component.
21 * If no LICENSE file comes with this software, it is provided AS-IS.
22 *
23 ******************************************************************************
24 @verbatim
25 ==============================================================================
26 ##### How to use this driver #####
27 ==============================================================================
28 [..]
29 The sequence below describes how to use this driver to capture image
30 from a camera module connected to the DCMIPP Interface.
31 This sequence does not take into account the configuration of the
32 camera module, which should be made before to configure and enable
33 the DCMIPP to capture images.
34
35 (#) Program the required configuration through the following parameters:
36 the Format, the VSPolarity,the HSPolarity, the PCKPolarity, the ExtendedDataMode
37 the SynchroMode, the SynchroCodes of the frame delimite, the SwapBits and the SwapCycles
38 using HAL_DCMIPP_Init() and HAL_DCMIPP_SetParallelConfig
39 (#) Program the required configuration through the following parameters:
40 the FrameRate using HAL_DCMIPP_PIPE_Config function.
41
42 *** Interrupt mode IO operation ***
43 ===================================
44 (#) Configure Pipe parameter, destination (one or two) and Capture Mode (Snapshot or Continuous) and enable
45 the capture request using the following functions:
46 HAL_DCMIPP_PIPE_Start() or HAL_DCMIPP_PIPE_DoubleBufferStart().
47
48 (#) Use HAL_DCMIPP_IRQHandler() called under DCMIPP_IRQHandler() interrupt subroutine.
49 (#) At the end of frame capture request HAL_DCMIPP_IRQHandler() function is executed and user can
50 add his own function by customization of function pointer PipeFrameEventCallback (member
51 of DCMIPP handle structure).
52 (#) In case of common error, the HAL_DCMIPP_IRQHandler() function calls the callback
53 ErrorCallback otherwise in case of Pipe error
54 the HAL_DCMIPP_IRQHandler() function calls the callbackPipeErrorCallback.
55
56 (#) The Pipe capture can be suspended and resumed using the following functions
57 HAL_DCMIPP_PIPE_Suspend() and HAL_DCMIPP_PIPE_Resume().
58
59 (#) For Snapshot Mode the capture can be re-enabled using the HAL_DCMIPP_PIPE_EnableCapture();
60
61 (#) Optionally, Program the required configuration through the following parameters:
62 Client, MemoryPageSize, Traffic, MaxOutstandingTransactions, DPREGStart, DPREGEnd
63 and WLRURatio using HAL_DCMIPP_SetIPPlugConfig().
64
65 (#) Optionally, configure and Enable the CROP feature to select a rectangular
66 window from the received image using HAL_DCMIPP_PIPE_SetCropConfig()
67 and HAL_DCMIPP_PIPE_EnableCrop() functions.
68
69 (#) Optionally, configure and Enable the line and bytes decimation features
70 using the following functions HAL_DCMIPP_PIPE_SetLinesDecimationConfig and
71 HAL_DCMIPP_PIPE_SetBytesDecimationConfig.
72
73 (#) Optionally, configure and enable the line event using the function HAL_DCMIPP_PIPE_EnableLineEvent().
74
75 (#) Optionally, configure and enable the Limit event using the function HAL_DCMIPP_PIPE_EnableLimitEvent().
76
77 (#) If needed, reconfigure and change the input pixel format value, the frame rate
78 value, the capture Mode , the destination memory address , the syncunmask values,
79 Multiline value and Limit value using respectively
80 the following functions: HAL_DCMIPP_PIPE_SetInputPixelFormat(), HAL_DCMIPP_PIPE_SetFrameRate(),
81 HAL_DCMIPP_PIPE_SetCaptureMode(), HAL_DCMIPP_PIPE_SetMemoryAddress(), HAL_DCMIPP_SetSyncUnmask(),
82 HAL_DCMIPP_PIPE_EnableLineEvent() and HAL_DCMIPP_PIPE_EnableLimitEvent().
83
84 (#) To read the transferred data counter , use the HAL_DCMIPP_PIPE_GetDataCounter()
85
86 (#) To read and reset the Frame counter of the pipe, use the following functions:
87 HAL_DCMIPP_PIPE_ReadFrameCounter() and HAL_DCMIPP_PIPE_ResetFrameCounter().
88
89 (#) The Pipe capture can be Stopped using HAL_DCMIPP_PIPE_Stop() function.
90
91
92 (#) To control the DCMIPP state, use the following function: HAL_DCMIPP_GetState().
93
94 (#) To control the DCMIPP Pipe state, use the following function: HAL_DCMIPP_PIPE_GetState().
95
96 (#) To read the DCMIPP error code, use the following function: HAL_DCMIPP_GetError().
97
98 *** DCMIPP HAL driver macros list ***
99 =============================================
100 [..]
101 Below the list of most used macros in DCMIPP HAL driver :
102
103 (+) __HAL_DCMIPP_GET_FLAG: Get the DCMIPP pending flags.
104 (+) __HAL_DCMIPP_CLEAR_FLAG: Clear the DCMIPP pending flags.
105 (+) __HAL_DCMIPP_ENABLE_IT: Enable the specified DCMIPP interrupts.
106 (+) __HAL_DCMIPP_DISABLE_IT: Disable the specified DCMIPP interrupts.
107 (+) __HAL_DCMIPP_GET_IT_SOURCE: Check whether the specified DCMIPP interrupt is enabled or not.
108
109 *** Callback registration ***
110 ===================================
111 [..]
112 (#) The compilation define USE_HAL_DCMIPP_REGISTER_CALLBACKS when set to 1
113 allows the user to configure dynamically the driver callbacks.
114 Use function @ref HAL_DCMIPP_RegisterCallback() to register a user callback.
115 Use function @ref HAL_DCMIPP_PIPE_RegisterCallback() to register a user pipe callback.
116
117 (#) Function @ref HAL_DCMIPP_RegisterCallback() allows to register following callbacks:
118 (+) ErrorCallback : callback for Error
119 (+) MspInitCallback : DCMIPP MspInit.
120 (+) MspDeInitCallback : DCMIPP MspDeInit.
121 This function takes as parameters the HAL peripheral handle, the Callback ID
122 and a pointer to the user callback function.
123 (#) Function @ref HAL_DCMIPP_PIPE_RegisterCallback() allows to register following callbacks:
124 (+) PipeFrameEventCallback : callback for Pipe Frame Event.
125 (+) PipeVsyncEventCallback : callback for Pipe Vsync Event.
126 (+) PipeLineEventCallback : callback for Pipe Line Event.
127 (+) PipeLimitEventCallback : callback for Pipe Limit Event.
128 (+) PipeErrorCallback : callback for Pipe Error
129 This function takes as parameters the HAL peripheral handle, the Callback ID
130 and a pointer to the user callback function.
131
132 (#) Use function @ref HAL_DCMIPP_UnRegisterCallback() to reset a callback to the default
133 weak (surcharged) function.
134 @ref HAL_DCMIPP_UnRegisterCallback() takes as parameters the HAL peripheral handle,
135 and the Callback ID.
136 This function allows to reset following callbacks:
137 (+) ErrorCallback : callback for Error
138 (+) MspInitCallback : DCMIPP MspInit.
139 (+) MspDeInitCallback : DCMIPP MspDeInit.
140 (#) Use function @ref HAL_DCMIPP_PIPE_UnRegisterCallback() to reset a pipe callback to the default
141 weak (surcharged) function.
142 @ref HAL_DCMIPP_PIPE_UnRegisterCallback() takes as parameters the HAL peripheral handle,
143 and the Callback ID.
144 This function allows to reset following callbacks:
145 (+) PipeFrameEventCallback : callback for Pipe Frame Event.
146 (+) PipeVsyncEventCallback : callback for Pipe Vsync Event.
147 (+) PipeLineEventCallback : callback for Pipe Line Event.
148 (+) PipeLimitEventCallback : callback for Pipe Limit Event.
149 (+) PipeErrorCallback : callback for Pipe Error
150
151 (#) By default, after the @ref HAL_DCMIPP_Init and if the state is HAL_DCMIPP_STATE_RESET
152 all callbacks are reset to the corresponding legacy weak (surcharged) functions:
153 examples @ref PipeFrameEventCallback(), @ref PipeVsyncEventCallback()
154 Exception done for MspInit and MspDeInit callbacks that are respectively
155 reset to the legacy weak (surcharged) functions in the @ref HAL_DCMIPP_Init
156 and @ref HAL_DCMIPP_DeInit only when these callbacks are null (not registered beforehand)
157 If not, MspInit or MspDeInit are not null, the @ref HAL_DCMIPP_Init and @ref HAL_DCMIPP_DeInit
158 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
159
160 Callbacks can be registered/unregistered in READY state only.
161 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
162 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
163 during the Init/DeInit.
164 In that case first register the MspInit/MspDeInit user callbacks
165 using @ref HAL_DCMIPP_RegisterCallback before calling @ref HAL_DCMIPP_DeInit
166 or @ref HAL_DCMIPP_Init function.
167
168 When The compilation define USE_HAL_DCMIPP_REGISTER_CALLBACKS is set to 0 or
169 not defined, the callback registering feature is not available
170 and weak (surcharged) callbacks are used.
171
172 [..]
173 (@) You can refer to the DCMIPP HAL driver header file for more useful macros
174 @endverbatim
175 ******************************************************************************
176 */
177
178 /* Includes ------------------------------------------------------------------*/
179 #include "stm32h7rsxx_hal.h"
180
181 #ifdef HAL_DCMIPP_MODULE_ENABLED
182 #if defined (DCMIPP)
183
184 /** @addtogroup STM32H7RSxx_HAL_Driver
185 * @{
186 */
187 /** @defgroup DCMIPP DCMIPP
188 * @brief DCMIPP HAL module driver
189 * @{
190 */
191
192 /* Private typedef -----------------------------------------------------------*/
193 /* Private define ------------------------------------------------------------*/
194 /** @defgroup DCMIPP_Private_Constants DCMIPP Private Constants
195 * @{
196 */
197 #define DCMIPP_TIMEOUT 1000U /*!< 1s */
198 /**
199 * @}
200 */
201 /* Private macro -------------------------------------------------------------*/
202 /* Private variables ---------------------------------------------------------*/
203 /* Private function prototypes -----------------------------------------------*/
204 /** @defgroup DCMIPP_Private_Functions DCMIPP Private Functions
205 * @{
206 */
207 static void Pipe_Config(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, const DCMIPP_PipeConfTypeDef *pPipeConfig);
208 static void DCMIPP_SetConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress, uint32_t CaptureMode);
209 static void DCMIPP_SetDBMConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress0,
210 uint32_t DstAddress1, uint32_t CaptureMode);
211 static void DCMIPP_EnableCapture(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe);
212 static HAL_StatusTypeDef DCMIPP_Stop(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe);
213 /**
214 * @}
215 */
216 /* Private functions ---------------------------------------------------------*/
217 /** @defgroup DCMIPP_Private_Functions DCMIPP Private Functions
218 * @{
219 */
220 /**
221 * @brief Configure the selected Pipe
222 * @param hdcmipp Pointer to DCMIPP handle
223 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
224 * @param pPipeConfig pointer to the DCMIPP_PipeConfTypeDef structure that contains
225 * the configuration information for the pipe.
226 * @retval None
227 */
Pipe_Config(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,const DCMIPP_PipeConfTypeDef * pPipeConfig)228 static void Pipe_Config(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, const DCMIPP_PipeConfTypeDef *pPipeConfig)
229 {
230 if (Pipe == DCMIPP_PIPE0)
231 {
232 /* Configure Pipe0 */
233 /* Configure Frame Rate */
234 MODIFY_REG(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_FRATE, pPipeConfig->FrameRate);
235 }
236 }
237 /**
238 * @brief Configure the destination address and capture mode for the selected pipe
239 * @param hdcmipp Pointer to DCMIPP handle
240 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
241 * @param DstAddress Specifies the destination memory address for the captured data.
242 * @param CaptureMode Specifies the capture mode to be set for the pipe.
243 * @retval None
244 */
DCMIPP_SetConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t DstAddress,uint32_t CaptureMode)245 static void DCMIPP_SetConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress, uint32_t CaptureMode)
246 {
247 if (Pipe == DCMIPP_PIPE0)
248 {
249 /* Update the DCMIPP pipe State */
250 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_BUSY;
251
252 /* Set the capture mode */
253 hdcmipp->Instance->P0FCTCR |= CaptureMode;
254
255 /* Set the destination address */
256 WRITE_REG(hdcmipp->Instance->P0PPM0AR1, DstAddress);
257
258 /* Enable all required interrupts lines for the PIPE0 */
259 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_FRAME | DCMIPP_IT_PIPE0_VSYNC | DCMIPP_IT_PIPE0_OVR |
260 DCMIPP_IT_AXI_TRANSFER_ERROR);
261 }
262 }
263 /**
264 * @brief Configure the destination addresses and capture mode for the selected pipe for Double Buffering Mode
265 * @param hdcmipp Pointer to DCMIPP handle
266 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
267 * @param DstAddress0 Specifies the first destination memory address for the captured data.
268 * @param DstAddress1 Specifies the second destination memory address for the captured data.
269 * @param CaptureMode Specifies the capture mode to be set for the pipe.
270 * @retval None
271 */
DCMIPP_SetDBMConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t DstAddress0,uint32_t DstAddress1,uint32_t CaptureMode)272 static void DCMIPP_SetDBMConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress0,
273 uint32_t DstAddress1, uint32_t CaptureMode)
274 {
275 if (Pipe == DCMIPP_PIPE0)
276 {
277 /* Update the DCMIPP pipe State */
278 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_BUSY;
279
280 /* Set the capture mode */
281 hdcmipp->Instance->P0FCTCR |= CaptureMode;
282
283 /* Set the destination address */
284 WRITE_REG(hdcmipp->Instance->P0PPM0AR1, DstAddress0);
285
286 /* Set the second destination address */
287 WRITE_REG(hdcmipp->Instance->P0PPM0AR2, DstAddress1);
288
289 /* Enable Double buffering Mode */
290 SET_BIT(hdcmipp->Instance->P0PPCR, DCMIPP_P0PPCR_DBM);
291
292 /* Enable all required interrupts lines for the Pipe0 */
293 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_FRAME | DCMIPP_IT_PIPE0_VSYNC | DCMIPP_IT_PIPE0_OVR);
294 }
295 }
296 /**
297 * @brief Enable the capture for the specified DCMIPP pipe.
298 * @param hdcmipp Pointer to DCMIPP handle
299 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
300 * @retval None
301 */
DCMIPP_EnableCapture(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)302 static void DCMIPP_EnableCapture(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
303 {
304 if (Pipe == DCMIPP_PIPE0)
305 {
306 /* Activate the Pipe */
307 SET_BIT(hdcmipp->Instance->P0FSCR, DCMIPP_P0FSCR_PIPEN);
308
309 /* Start the capture */
310 SET_BIT(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTREQ);
311 }
312 }
313 /**
314 * @brief Stop the capture for the specified DCMIPP pipe.
315 * @param hdcmipp Pointer to DCMIPP handle
316 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
317 * @retval HAL status
318 */
DCMIPP_Stop(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)319 static HAL_StatusTypeDef DCMIPP_Stop(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
320 {
321 uint32_t tickstart;
322
323 if (Pipe == DCMIPP_PIPE0)
324 {
325 /* Stop the capture */
326 CLEAR_BIT(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTREQ);
327
328 /* Poll CPTACT status till No capture currently active */
329 tickstart = HAL_GetTick();
330 do
331 {
332 if ((HAL_GetTick() - tickstart) > DCMIPP_TIMEOUT)
333 {
334 return HAL_ERROR;
335 }
336 } while ((hdcmipp->Instance->CMSR1 & DCMIPP_CMSR1_P0CPTACT) != 0U);
337
338 /* Disable DBM when enabled */
339 if ((hdcmipp->Instance->P0PPCR & DCMIPP_P0PPCR_DBM) == DCMIPP_P0PPCR_DBM)
340 {
341 CLEAR_BIT(hdcmipp->Instance->P0PPCR, DCMIPP_P0PPCR_DBM);
342 }
343
344 /* Disable the pipe */
345 CLEAR_BIT(hdcmipp->Instance->P0FSCR, DCMIPP_P0FSCR_PIPEN);
346
347 /* Disable all interrupts for this pipe */
348 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_FRAME | DCMIPP_IT_PIPE0_VSYNC | DCMIPP_IT_PIPE0_LINE | \
349 DCMIPP_IT_PIPE0_LIMIT | DCMIPP_IT_PIPE0_OVR);
350
351 }
352
353 return HAL_OK;
354 }
355 /**
356 * @}
357 */
358
359 /* Exported functions --------------------------------------------------------*/
360
361 /** @defgroup DCMIPP_Exported_Functions DCMIPP Exported Functions
362 * @{
363 */
364
365 /** @addtogroup DCMIPP_Initialization_De-Initialization_Functions DCMIPP Initialization De-Initialization Functions
366 * @brief Initialization and De-Initialization Functions
367 * @{
368 */
369
370 /**
371 * @brief Initialize the selected HAL DCMIPP handle and associate a DCMIPP peripheral instance.
372 * @param hdcmipp Pointer to DCMIPP handle
373 * @retval HAL status
374 */
HAL_DCMIPP_Init(DCMIPP_HandleTypeDef * hdcmipp)375 HAL_StatusTypeDef HAL_DCMIPP_Init(DCMIPP_HandleTypeDef *hdcmipp)
376 {
377 uint32_t pipe_index;
378
379 /* Check pointer validity */
380 if (hdcmipp == NULL)
381 {
382 return HAL_ERROR;
383 }
384
385 /* Check function parameters */
386 assert_param(IS_DCMIPP_ALL_INSTANCE(hdcmipp->Instance));
387
388 if (hdcmipp->State == HAL_DCMIPP_STATE_RESET)
389 {
390 /* Init the DCMIPP Callback settings */
391 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
392 /* Reset callback pointers to the weak predefined callbacks */
393 hdcmipp->PIPE_FrameEventCallback = HAL_DCMIPP_PIPE_FrameEventCallback;
394 hdcmipp->PIPE_VsyncEventCallback = HAL_DCMIPP_PIPE_VsyncEventCallback;
395 hdcmipp->PIPE_LineEventCallback = HAL_DCMIPP_PIPE_LineEventCallback;
396 hdcmipp->PIPE_LimitEventCallback = HAL_DCMIPP_PIPE_LimitEventCallback;
397 hdcmipp->PIPE_ErrorCallback = HAL_DCMIPP_PIPE_ErrorCallback;
398 hdcmipp->ErrorCallback = HAL_DCMIPP_ErrorCallback;
399 if (hdcmipp->MspInitCallback == NULL)
400 {
401 /* Legacy weak MspInit Callback */
402 hdcmipp->MspInitCallback = HAL_DCMIPP_MspInit;
403 }
404 /* Initialize the low level hardware (MSP) */
405 hdcmipp->MspInitCallback(hdcmipp);
406 #else
407 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
408 HAL_DCMIPP_MspInit(hdcmipp);
409 #endif /* (USE_HAL_DCMIPP_REGISTER_CALLBACKS) */
410 }
411
412 /* Change the DCMIPP state */
413 hdcmipp->State = HAL_DCMIPP_STATE_BUSY;
414
415 /* Reset DCMIPP Pipe state */
416 for (pipe_index = 0U; pipe_index < DCMIPP_NUM_OF_PIPES; pipe_index++)
417 {
418 hdcmipp->PipeState[pipe_index] = HAL_DCMIPP_PIPE_STATE_RESET;
419 }
420
421 /* Update error code */
422 hdcmipp->ErrorCode = HAL_DCMIPP_ERROR_NONE;
423
424 /* Update the DCMIPP state*/
425 hdcmipp->State = HAL_DCMIPP_STATE_INIT;
426
427 return HAL_OK;
428 }
429
430 /**
431 * @brief De-initializes the DCMIPP peripheral registers to their default reset values.
432 * @param hdcmipp Pointer to DCMIPP handle
433 * @retval HAL status
434 */
HAL_DCMIPP_DeInit(DCMIPP_HandleTypeDef * hdcmipp)435 HAL_StatusTypeDef HAL_DCMIPP_DeInit(DCMIPP_HandleTypeDef *hdcmipp)
436 {
437 uint32_t pipe_index;
438
439 /* Check pointer validity */
440 if (hdcmipp == NULL)
441 {
442 return HAL_ERROR;
443 }
444
445 /* Disable the Parallel Interface */
446 hdcmipp->Instance->PRCR &= ~DCMIPP_PRCR_ENABLE;
447
448 /* Reset flow selection configuration register for the Pipe0 */
449 hdcmipp->Instance->P0FSCR = 0;
450
451 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
452 if (hdcmipp->MspDeInitCallback == NULL)
453 {
454 hdcmipp->MspDeInitCallback = HAL_DCMIPP_MspDeInit;
455 }
456
457 /* DeInit the low level hardware */
458 hdcmipp->MspDeInitCallback(hdcmipp);
459 #else
460 /* DeInit the low level hardware */
461 HAL_DCMIPP_MspDeInit(hdcmipp);
462 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
463
464 /* Update error code */
465 hdcmipp->ErrorCode = HAL_DCMIPP_ERROR_NONE;
466
467 /* Initialize the DCMIPP state*/
468 hdcmipp->State = HAL_DCMIPP_STATE_RESET;
469
470 /* Reset DCMIPP Pipe state */
471 for (pipe_index = 0U; pipe_index < DCMIPP_NUM_OF_PIPES; pipe_index++)
472 {
473 hdcmipp->PipeState[pipe_index] = HAL_DCMIPP_PIPE_STATE_RESET;
474 }
475
476 return HAL_OK;
477 }
478
479 /**
480 * @brief Initializes the DCMIPP MSP.
481 * @param hdcmipp Pointer to DCMIPP handle
482 * @retval None
483 */
HAL_DCMIPP_MspInit(DCMIPP_HandleTypeDef * hdcmipp)484 __weak void HAL_DCMIPP_MspInit(DCMIPP_HandleTypeDef *hdcmipp)
485 {
486 /* Prevent unused argument(s) compilation warning */
487 UNUSED(hdcmipp);
488
489 /* NOTE : This function Should not be modified, when the callback is needed,
490 the HAL_DCMIPP_MspInit could be implemented in the user file
491 */
492 }
493
494 /**
495 * @brief De-Initializes the DCMIPP MSP.
496 * @param hdcmipp Pointer to DCMIPP handle
497 * @retval None
498 */
HAL_DCMIPP_MspDeInit(DCMIPP_HandleTypeDef * hdcmipp)499 __weak void HAL_DCMIPP_MspDeInit(DCMIPP_HandleTypeDef *hdcmipp)
500 {
501 /* Prevent unused argument(s) compilation warning */
502 UNUSED(hdcmipp);
503
504 /* NOTE : This function Should not be modified, when the callback is needed,
505 the HAL_DCMIPP_MspDeInit could be implemented in the user file
506 */
507 }
508 /**
509 * @}
510 */
511
512 /** @defgroup DCMIPP_Configuration_Functions DCMIPP Configuration Functions
513 * @brief Configuration Functions
514 * @{
515 */
516 /**
517 * @brief Configure the DCMIPP Parallel Interface according to the user parameters.
518 * @param hdcmipp Pointer to DCMIPP handle
519 * @param pParallelConfig pointer to DCMIPP_ParallelConfTypeDef that contains
520 * the parallel Interface configuration information for DCMIPP.
521 * @retval HAL status
522 */
HAL_DCMIPP_PARALLEL_SetConfig(DCMIPP_HandleTypeDef * hdcmipp,const DCMIPP_ParallelConfTypeDef * pParallelConfig)523 HAL_StatusTypeDef HAL_DCMIPP_PARALLEL_SetConfig(DCMIPP_HandleTypeDef *hdcmipp,
524 const DCMIPP_ParallelConfTypeDef *pParallelConfig)
525 {
526 uint32_t prcr_reg;
527 uint32_t prescr_reg;
528
529 /* Check parameters */
530 if ((hdcmipp == NULL) || (pParallelConfig == NULL))
531 {
532 return HAL_ERROR;
533 }
534
535 /* Check function parameters */
536 assert_param(IS_DCMIPP_FORMAT(pParallelConfig->Format));
537 assert_param(IS_DCMIPP_VSPOLARITY(pParallelConfig->VSPolarity));
538 assert_param(IS_DCMIPP_HSPOLARITY(pParallelConfig->HSPolarity));
539 assert_param(IS_DCMIPP_PCKPOLARITY(pParallelConfig->PCKPolarity));
540 assert_param(IS_DCMIPP_EXTENDED_DATA_MODE(pParallelConfig->ExtendedDataMode));
541 assert_param(IS_DCMIPP_SYNC_MODE(pParallelConfig->SynchroMode));
542 assert_param(IS_DCMIPP_SWAP_BITS(pParallelConfig->SwapBits));
543 assert_param(IS_DCMIPP_SWAP_CYCLES(pParallelConfig->SwapCycles));
544
545 /* Check DCMIPP state */
546 if (hdcmipp->State != HAL_DCMIPP_STATE_INIT)
547 {
548 return HAL_ERROR;
549 }
550 else
551 {
552 /* Configures the Format, VS, HS, PCK polarity, ExtendedDataMode, SynchronisationMode, Swap Cycles and bits */
553 prcr_reg = ((pParallelConfig->Format) | \
554 (pParallelConfig->VSPolarity) | \
555 (pParallelConfig->HSPolarity) | \
556 (pParallelConfig->PCKPolarity) | \
557 (pParallelConfig->ExtendedDataMode) | \
558 (pParallelConfig->SynchroMode) | \
559 (pParallelConfig->SwapCycles) | \
560 (pParallelConfig->SwapBits));
561
562 WRITE_REG(hdcmipp->Instance->PRCR, prcr_reg);
563
564 if (pParallelConfig->SynchroMode == DCMIPP_SYNCHRO_EMBEDDED)
565 {
566 /* Set Embedded Sync codes */
567 prescr_reg = (((uint32_t)pParallelConfig->SynchroCodes.FrameEndCode << DCMIPP_PRESCR_FEC_Pos) | \
568 ((uint32_t)pParallelConfig->SynchroCodes.LineEndCode << DCMIPP_PRESCR_LEC_Pos) | \
569 ((uint32_t)pParallelConfig->SynchroCodes.FrameStartCode << DCMIPP_PRESCR_FSC_Pos) | \
570 ((uint32_t)pParallelConfig->SynchroCodes.LineStartCode << DCMIPP_PRESCR_LSC_Pos));
571
572 WRITE_REG(hdcmipp->Instance->PRESCR, prescr_reg);
573
574 /* Set Embedded Sync Unmask codes : All codes are unmasked */
575 WRITE_REG(hdcmipp->Instance->PRESUR, 0xFFFFFFFFU);
576 }
577
578 /* Enable the Synchronization error interrupt on parallel interface */
579 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_PARALLEL_SYNC_ERROR);
580
581 /* Enable Parallel interface */
582 SET_BIT(hdcmipp->Instance->PRCR, DCMIPP_PRCR_ENABLE);
583
584 }
585
586 /* Update the DCMIPP state */
587 hdcmipp->State = HAL_DCMIPP_STATE_READY;
588
589 return HAL_OK;
590 }
591
592
593 /**
594 * @brief Configure the pipe according to the user parameters.
595 * @param hdcmipp Pointer to DCMIPP handle
596 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
597 * @param pPipeConfig pointer to pipe configuration structure
598 * @retval HAL status
599 */
HAL_DCMIPP_PIPE_SetConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,const DCMIPP_PipeConfTypeDef * pPipeConfig)600 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
601 const DCMIPP_PipeConfTypeDef *pPipeConfig)
602 {
603 HAL_DCMIPP_PipeStateTypeDef pipe_state;
604
605 /* Check the DCMIPP peripheral handle parameter and pPipeConfig parameter */
606 if ((hdcmipp == NULL) || (pPipeConfig == NULL))
607 {
608 return HAL_ERROR;
609 }
610
611 /* Check the parameters */
612 assert_param(IS_DCMIPP_ALL_INSTANCE(hdcmipp->Instance));
613 assert_param(IS_DCMIPP_PIPE(Pipe));
614 assert_param(IS_DCMIPP_FRAME_RATE(pPipeConfig->FrameRate));
615 /* Get Pipe State */
616 pipe_state = hdcmipp->PipeState[Pipe];
617
618 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
619 {
620 if ((pipe_state == HAL_DCMIPP_PIPE_STATE_RESET) || (pipe_state == HAL_DCMIPP_PIPE_STATE_ERROR))
621 {
622 /* Update the DCMIPP PIPE state */
623 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_BUSY;
624
625 /* Initialize the DCMIPP Pipe registers */
626 Pipe_Config(hdcmipp, Pipe, pPipeConfig);
627
628 /* Update the DCMIPP pipe state */
629 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_READY;
630 }
631 else
632 {
633 return HAL_ERROR;
634 }
635 }
636 else
637 {
638 return HAL_ERROR;
639 }
640
641 return HAL_OK;
642 }
643
644 /**
645 * @brief Configure the DCMIPP AXI master memory IP-Plug.
646 * @param hdcmipp Pointer to DCMIPP handle
647 * @param pIPPlugConfig pointer to IPPLUG configuration structure
648 * @retval HAL status
649 */
HAL_DCMIPP_SetIPPlugConfig(DCMIPP_HandleTypeDef * hdcmipp,const DCMIPP_IPPlugConfTypeDef * pIPPlugConfig)650 HAL_StatusTypeDef HAL_DCMIPP_SetIPPlugConfig(DCMIPP_HandleTypeDef *hdcmipp,
651 const DCMIPP_IPPlugConfTypeDef *pIPPlugConfig)
652 {
653 uint32_t tickstart;
654
655 /* Check handle validity */
656 if ((hdcmipp == NULL) || (pIPPlugConfig == NULL))
657 {
658 return HAL_ERROR;
659 }
660
661 /* Check the parameters */
662 assert_param(IS_DCMIPP_CLIENT(pIPPlugConfig->Client));
663 assert_param(IS_DCMIPP_DPREG_END(pIPPlugConfig->DPREGEnd));
664 assert_param(IS_DCMIPP_DPREG_START(pIPPlugConfig->DPREGStart));
665 assert_param(IS_DCMIPP_MAX_OUTSTANDING_TRANSACTIONS(pIPPlugConfig->MaxOutstandingTransactions));
666 assert_param(IS_DCMIPP_MEMORY_PAGE_SIZE(pIPPlugConfig->MemoryPageSize));
667 assert_param(IS_DCMIPP_TRAFFIC(pIPPlugConfig->Traffic));
668 assert_param(IS_DCMIPP_WLRU_RATIO(pIPPlugConfig->WLRURatio));
669
670
671 if (hdcmipp->State != HAL_DCMIPP_STATE_RESET)
672 {
673 /* Request to lock the IP-Plug, to allow reconfiguration */
674 SET_BIT(hdcmipp->Instance->IPGR2, DCMIPP_IPGR2_PSTART);
675
676 tickstart = HAL_GetTick();
677 do
678 {
679 if ((HAL_GetTick() - tickstart) > DCMIPP_TIMEOUT)
680 {
681 return HAL_ERROR;
682 }
683 } while ((hdcmipp->Instance->IPGR3 & DCMIPP_IPGR3_IDLE) != DCMIPP_IPGR3_IDLE);
684 }
685 else
686 {
687 return HAL_ERROR;
688 }
689
690 /* IP-Plug is currently locked and can be reconfigured */
691
692 /* Set Memory page size */
693 hdcmipp->Instance->IPGR1 = (pIPPlugConfig->MemoryPageSize);
694
695 /* IP-PLUG Client1 configuration */
696 switch (pIPPlugConfig->Client)
697 {
698 case DCMIPP_CLIENT1:
699 {
700 /* Set Traffic : Burst size and Maximum Outstanding transactions */
701 hdcmipp->Instance->IPC1R1 = (pIPPlugConfig->Traffic |
702 (pIPPlugConfig->MaxOutstandingTransactions << DCMIPP_IPC1R1_OTR_Pos));
703
704 /* Set End word and Start Word of the FIFO of the Clientx */
705 hdcmipp->Instance->IPC1R2 = (pIPPlugConfig->WLRURatio << DCMIPP_IPC1R2_WLRU_Pos);
706
707 /* Set End word and Start Word of the FIFO of the Clientx */
708 hdcmipp->Instance->IPC1R3 = ((pIPPlugConfig->DPREGStart << DCMIPP_IPC1R3_DPREGSTART_Pos) |
709 (pIPPlugConfig->DPREGEnd << DCMIPP_IPC1R3_DPREGEND_Pos));
710 break;
711 }
712 default:
713 break;
714 }
715
716 /* No lock requested, IP-Plug runs on demand by background HW */
717 CLEAR_BIT(hdcmipp->Instance->IPGR2, DCMIPP_IPGR2_PSTART);
718
719 /* Enable DCMIPP_IT_AXI_TRANSFER_ERR */
720 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_AXI_TRANSFER_ERROR);
721
722 return HAL_OK;
723 }
724
725 /**
726 * @}
727 */
728
729 /** @addtogroup DCMIPP_IO_operation_Functions DCMIPP IO operation Functions
730 * @brief IO operation functions
731 * @{
732 */
733 /**
734 * @brief Start the DCMIPP capture on the specified pipe
735 * @param hdcmipp Pointer to DCMIPP handle
736 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
737 * @param DstAddress the destination address
738 * @param CaptureMode DCMIPP capture mode for the pipe can be a value from @ref DCMIPP_Capture_Mode.
739 * @retval HAL status
740 */
HAL_DCMIPP_PIPE_Start(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t DstAddress,uint32_t CaptureMode)741 HAL_StatusTypeDef HAL_DCMIPP_PIPE_Start(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress,
742 uint32_t CaptureMode)
743 {
744 assert_param(IS_DCMIPP_PIPE(Pipe));
745 assert_param(IS_DCMIPP_CAPTURE_MODE(CaptureMode));
746
747 /* Check pointer validity */
748 if ((hdcmipp == NULL) || ((DstAddress & 0xFU) != 0U))
749 {
750 return HAL_ERROR;
751 }
752
753 /* Check DCMIPP pipe state */
754 if (hdcmipp->PipeState[Pipe] != HAL_DCMIPP_PIPE_STATE_READY)
755 {
756 return HAL_ERROR;
757 }
758
759 /* Set Capture Mode and Destination address for the selected pipe */
760 DCMIPP_SetConfig(hdcmipp, Pipe, DstAddress, CaptureMode);
761
762 /* Enable Capture for the selected Pipe */
763 DCMIPP_EnableCapture(hdcmipp, Pipe);
764
765 return HAL_OK;
766 }
767
768 /**
769 * @brief Start the DCMIPP capture on the specified pipe with double buffering Mode
770 * @param hdcmipp Pointer to DCMIPP handle
771 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
772 * @param DstAddress0 the first destination address
773 * @param DstAddress1 the second destination address
774 * @param CaptureMode DCMIPP capture mode for the pipe can be a value from @ref DCMIPP_Capture_Mode.
775 * @retval HAL status
776 */
HAL_DCMIPP_PIPE_DoubleBufferStart(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t DstAddress0,uint32_t DstAddress1,uint32_t CaptureMode)777 HAL_StatusTypeDef HAL_DCMIPP_PIPE_DoubleBufferStart(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t DstAddress0,
778 uint32_t DstAddress1, uint32_t CaptureMode)
779 {
780 assert_param(IS_DCMIPP_PIPE(Pipe));
781 assert_param(IS_DCMIPP_CAPTURE_MODE(CaptureMode));
782
783 /* Check pointer validity */
784 if ((hdcmipp == NULL) || ((DstAddress0 & 0xFU) != 0U) || ((DstAddress1 & 0xFU) != 0U))
785 {
786 return HAL_ERROR;
787 }
788
789 /* Check DCMIPP pipe state */
790 if (hdcmipp->PipeState[Pipe] != HAL_DCMIPP_PIPE_STATE_READY)
791 {
792 return HAL_ERROR;
793 }
794
795 /* Set Capture Mode and Destination addresses for the selected pipe */
796 DCMIPP_SetDBMConfig(hdcmipp, Pipe, DstAddress0, DstAddress1, CaptureMode);
797
798 /* Enable Capture for the selected Pipe */
799 DCMIPP_EnableCapture(hdcmipp, Pipe);
800
801 return HAL_OK;
802 }
803
804 /**
805 * @brief Stop DCMIPP capture on the specified pipe
806 * @param hdcmipp Pointer to DCMIPP handle
807 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
808 * @retval HAL status
809 */
HAL_DCMIPP_PIPE_Stop(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)810 HAL_StatusTypeDef HAL_DCMIPP_PIPE_Stop(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
811 {
812 HAL_DCMIPP_PipeStateTypeDef pipe_state;
813
814 assert_param(IS_DCMIPP_PIPE(Pipe));
815
816 /* Check pointer validity */
817 if (hdcmipp == NULL)
818 {
819 return HAL_ERROR;
820 }
821
822 /* Get Pipe State */
823 pipe_state = hdcmipp->PipeState[Pipe];
824
825 /* Check DCMIPP Pipe state */
826 if (pipe_state != HAL_DCMIPP_PIPE_STATE_RESET)
827 {
828 if (DCMIPP_Stop(hdcmipp, Pipe) != HAL_OK)
829 {
830 return HAL_ERROR;
831 }
832
833 /* Update the DCMIPP pipe State */
834 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_READY;
835 }
836 else
837 {
838 return HAL_ERROR;
839 }
840
841 return HAL_OK;
842 }
843
844 /**
845 * @brief Suspend DCMIPP capture on the specified pipe
846 * @param hdcmipp Pointer to DCMIPP handle
847 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
848 * @retval HAL status
849 */
HAL_DCMIPP_PIPE_Suspend(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)850 HAL_StatusTypeDef HAL_DCMIPP_PIPE_Suspend(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
851 {
852 HAL_DCMIPP_PipeStateTypeDef pipe_state;
853 uint32_t tickstart;
854
855 assert_param(IS_DCMIPP_PIPE(Pipe));
856
857 if (hdcmipp == NULL)
858 {
859 /* Return Function Status */
860 return HAL_ERROR;
861 }
862
863 pipe_state = hdcmipp->PipeState[Pipe];
864
865 if (Pipe == DCMIPP_PIPE0)
866 {
867 /* Check Pipe0 State */
868 if (pipe_state == HAL_DCMIPP_PIPE_STATE_BUSY)
869 {
870 /* Disable Capture Request */
871 CLEAR_BIT(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTREQ);
872
873 /* Change Pipe State */
874 hdcmipp->PipeState[0] = HAL_DCMIPP_PIPE_STATE_SUSPEND;
875
876 /* Poll CPTACT status till No capture currently active */
877 tickstart = HAL_GetTick();
878 do
879 {
880 if ((HAL_GetTick() - tickstart) > DCMIPP_TIMEOUT)
881 {
882 /* Change Pipe State */
883 hdcmipp->PipeState[Pipe] = HAL_DCMIPP_PIPE_STATE_ERROR;
884
885 return HAL_ERROR;
886 }
887 } while ((hdcmipp->Instance->CMSR1 & DCMIPP_CMSR1_P0CPTACT) != 0U);
888 }
889 else
890 {
891 /* Return Function Status */
892 return HAL_ERROR;
893 }
894 }
895 else
896 {
897 return HAL_ERROR;
898 }
899
900 /* Return Function Status */
901 return HAL_OK;
902 }
903
904 /**
905 * @brief Resume DCMIPP capture on the specified pipe
906 * @param hdcmipp Pointer to DCMIPP handle
907 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
908 * @retval HAL status
909 */
HAL_DCMIPP_PIPE_Resume(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)910 HAL_StatusTypeDef HAL_DCMIPP_PIPE_Resume(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
911 {
912 HAL_DCMIPP_PipeStateTypeDef pipe_state ;
913
914 assert_param(IS_DCMIPP_PIPE(Pipe));
915
916 if (hdcmipp == NULL)
917 {
918 return HAL_ERROR;
919 }
920
921 pipe_state = hdcmipp->PipeState[Pipe];
922
923 if (Pipe == DCMIPP_PIPE0)
924 {
925 /* Check Pipe0 State */
926 if (pipe_state == HAL_DCMIPP_PIPE_STATE_SUSPEND)
927 {
928 /* Enable Capture Request */
929 SET_BIT(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTREQ);
930
931 /* Change Pipe State */
932 hdcmipp->PipeState[0] = HAL_DCMIPP_PIPE_STATE_BUSY;
933 }
934 else
935 {
936 return HAL_ERROR;
937 }
938 }
939 else
940 {
941 return HAL_ERROR;
942 }
943
944 return HAL_OK;
945 }
946
947 /**
948 * @}
949 */
950
951 /** @addtogroup DCMIPP_IRQ_and_Callbacks_Functions DCMIPP IRQ and Callbacks Functions
952 * @brief IRQ and Callbacks functions
953 * @{
954 */
955
956 /** @addtogroup DCMIPP_IRQHandler_Function IRQHandler Function
957 * @{
958 */
959 /**
960 * @brief Handles DCMIPP interrupt request.
961 * @param hdcmipp Pointer to DCMIPP handle
962 * @retval None
963 */
HAL_DCMIPP_IRQHandler(DCMIPP_HandleTypeDef * hdcmipp)964 void HAL_DCMIPP_IRQHandler(DCMIPP_HandleTypeDef *hdcmipp)
965 {
966 uint32_t cmsr2flags = READ_REG(hdcmipp->Instance->CMSR2);
967 uint32_t cmierflags = READ_REG(hdcmipp->Instance->CMIER);
968
969 /* ========================= PIPE0 INTERRUPTS ==================== */
970 /* Limit error on the PIPE0 ********************************************/
971 if ((cmsr2flags & DCMIPP_FLAG_PIPE0_LIMIT) != 0U)
972 {
973 if ((cmierflags & DCMIPP_IT_PIPE0_LIMIT) != 0U)
974 {
975 /* Disable Limit error Interrupt for pipe0 */
976 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_LIMIT);
977
978 /* Update error code */
979 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_PIPE0_LIMIT;
980
981 /* Clear the Limit error flag */
982 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PIPE0_LIMIT);
983
984 /* LIMIT Callback */
985 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
986 hdcmipp->PIPE_LimitEventCallback(hdcmipp, DCMIPP_PIPE0);
987 #else
988 HAL_DCMIPP_PIPE_LimitEventCallback(hdcmipp, DCMIPP_PIPE0);
989 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
990 }
991 }
992
993 /* VSYNC interrupt management **********************************************/
994 if ((cmsr2flags & DCMIPP_FLAG_PIPE0_VSYNC) != 0U)
995 {
996 if ((cmierflags & DCMIPP_IT_PIPE0_VSYNC) != 0U)
997 {
998 /* Clear the VSYNC flag for pipe0 */
999 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PIPE0_VSYNC);
1000
1001 /* VSYNC Callback */
1002 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1003 hdcmipp->PIPE_VsyncEventCallback(hdcmipp, DCMIPP_PIPE0);
1004 #else
1005 HAL_DCMIPP_PIPE_VsyncEventCallback(hdcmipp, DCMIPP_PIPE0);
1006 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1007 }
1008 }
1009
1010 /* FRAME interrupt management ****************************/
1011 if ((cmsr2flags & DCMIPP_FLAG_PIPE0_FRAME) != 0U)
1012 {
1013 if ((cmierflags & DCMIPP_IT_PIPE0_FRAME) != 0U)
1014 {
1015 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
1016 if ((hdcmipp->Instance->P0FCTCR & DCMIPP_P0FCTCR_CPTMODE) == DCMIPP_MODE_SNAPSHOT)
1017 {
1018 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_FRAME | DCMIPP_IT_PIPE0_VSYNC | DCMIPP_IT_PIPE0_OVR);
1019
1020 /* Update Pipe State */
1021 hdcmipp->PipeState[0] = HAL_DCMIPP_PIPE_STATE_READY;
1022 }
1023
1024 /* Clear the End of Frame flag */
1025 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PIPE0_FRAME);
1026
1027 /* Frame Callback */
1028 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1029 hdcmipp->PIPE_FrameEventCallback(hdcmipp, DCMIPP_PIPE0);
1030 #else
1031 HAL_DCMIPP_PIPE_FrameEventCallback(hdcmipp, DCMIPP_PIPE0);
1032 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1033 }
1034 }
1035
1036 /* LINE interrupt management **********************************************/
1037 if ((cmsr2flags & DCMIPP_FLAG_PIPE0_LINE) != 0U)
1038 {
1039 if ((cmierflags & DCMIPP_IT_PIPE0_LINE) != 0U)
1040 {
1041 /* Clear the LINE flag */
1042 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PIPE0_LINE);
1043
1044 /* LINE Callback */
1045 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1046 hdcmipp->PIPE_LineEventCallback(hdcmipp, DCMIPP_PIPE0);
1047 #else
1048 HAL_DCMIPP_PIPE_LineEventCallback(hdcmipp, DCMIPP_PIPE0);
1049 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1050 }
1051 }
1052
1053 /* Overrun error interrupt for Pipe0 ***************************************/
1054 if ((cmsr2flags & DCMIPP_FLAG_PIPE0_OVR) != 0U)
1055 {
1056 if ((cmierflags & DCMIPP_IT_PIPE0_OVR) != 0U)
1057 {
1058 /* Disable Overrun Error Interrupt for pipe0 */
1059 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_OVR);
1060
1061 /* Update error code */
1062 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_PIPE0_OVR;
1063
1064 /* Clear the overrun error flag */
1065 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PIPE0_OVR);
1066
1067 /* Change DCMIPP Pipe state */
1068 hdcmipp->PipeState[0] = HAL_DCMIPP_PIPE_STATE_ERROR;
1069
1070 /* Error Callback */
1071 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1072 hdcmipp->PIPE_ErrorCallback(hdcmipp, DCMIPP_PIPE0);
1073 #else
1074 HAL_DCMIPP_PIPE_ErrorCallback(hdcmipp, DCMIPP_PIPE0);
1075 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1076 }
1077 }
1078
1079
1080 /* Synchronization Error Interrupt on the parallel interface **************/
1081 if ((cmsr2flags & DCMIPP_FLAG_PARALLEL_SYNC_ERROR) != 0U)
1082 {
1083 if ((cmierflags & DCMIPP_IT_PARALLEL_SYNC_ERROR) != 0U)
1084 {
1085 /* Disable Synchronization error interrupt on parallel interface */
1086 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PARALLEL_SYNC_ERROR);
1087
1088 /* Update error code */
1089 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_PARALLEL_SYNC;
1090
1091 /* Clear the synchronization error flag */
1092 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_PARALLEL_SYNC_ERROR);
1093
1094 /* Change DCMIPP state */
1095 hdcmipp->State = HAL_DCMIPP_STATE_ERROR;
1096
1097 /* Error Callback */
1098 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1099 hdcmipp->ErrorCallback(hdcmipp);
1100 #else
1101 HAL_DCMIPP_ErrorCallback(hdcmipp);
1102 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1103 }
1104 }
1105
1106 /* IPPLUG AXI transfer Error Interrupt *********************************/
1107 if ((cmsr2flags & DCMIPP_FLAG_AXI_TRANSFER_ERROR) != 0U)
1108 {
1109 if ((cmierflags & DCMIPP_IT_AXI_TRANSFER_ERROR) != 0U)
1110 {
1111 /* Disable IPPLUG AXI transfer Error Interrupt */
1112 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_AXI_TRANSFER_ERROR);
1113
1114 /* Update error code */
1115 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_AXI_TRANSFER;
1116
1117 /* Clear the AXI transfer error flag */
1118 __HAL_DCMIPP_CLEAR_FLAG(hdcmipp, DCMIPP_FLAG_AXI_TRANSFER_ERROR);
1119
1120 /* Change DCMIPP state */
1121 hdcmipp->State = HAL_DCMIPP_STATE_ERROR;
1122
1123 /* Error Callback */
1124 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1125 hdcmipp->ErrorCallback(hdcmipp);
1126 #else
1127 HAL_DCMIPP_ErrorCallback(hdcmipp);
1128 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1129 }
1130 }
1131 }
1132 /**
1133 * @}
1134 */
1135
1136 /** @addtogroup DCMIPP_Callback_Functions Callback Functions
1137 * @{
1138 */
1139 /**
1140 * @brief Frame Event callback on the pipe
1141 * @param hdcmipp Pointer to DCMIPP handle
1142 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1143 * @retval None
1144 */
HAL_DCMIPP_PIPE_FrameEventCallback(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1145 __weak void HAL_DCMIPP_PIPE_FrameEventCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1146 {
1147 /* NOTE : This function Should not be modified, when the callback is needed,
1148 the HAL_DCMIPP_FrameEventDumpPipeCallback could be implemented in the user file
1149 */
1150 /* Prevent unused argument(s) compilation warning */
1151 UNUSED(Pipe);
1152 UNUSED(hdcmipp);
1153 }
1154
1155 /**
1156 * @brief Vsync Event callback on pipe
1157 * @param hdcmipp Pointer to DCMIPP handle
1158 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1159 * @retval None
1160 */
HAL_DCMIPP_PIPE_VsyncEventCallback(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1161 __weak void HAL_DCMIPP_PIPE_VsyncEventCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1162 {
1163 /* NOTE : This function Should not be modified, when the callback is needed,
1164 the HAL_DCMIPP_VsyncEventDumpPipeCallback could be implemented in the user file
1165 */
1166 /* Prevent unused argument(s) compilation warning */
1167 UNUSED(Pipe);
1168 UNUSED(hdcmipp);
1169 }
1170
1171
1172 /**
1173 * @brief Line Event callback on the pipe
1174 * @param hdcmipp Pointer to DCMIPP handle
1175 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1176 * @retval None
1177 */
HAL_DCMIPP_PIPE_LineEventCallback(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1178 __weak void HAL_DCMIPP_PIPE_LineEventCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1179 {
1180 /* NOTE : This function Should not be modified, when the callback is needed,
1181 the HAL_DCMIPP_LineEventMainPipeCallback could be implemented in the user file
1182 */
1183 /* Prevent unused argument(s) compilation warning */
1184 UNUSED(Pipe);
1185 UNUSED(hdcmipp);
1186 }
1187
1188 /**
1189 * @brief Limit callback on the Pipe
1190 * @param hdcmipp Pointer to DCMIPP handle
1191 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1192 * @retval None
1193 */
HAL_DCMIPP_PIPE_LimitEventCallback(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1194 __weak void HAL_DCMIPP_PIPE_LimitEventCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1195 {
1196 /* NOTE : This function Should not be modified, when the callback is needed,
1197 the HAL_DCMIPP_LimitEventDumpPipeCallback could be implemented in the user file
1198 */
1199 /* Prevent unused argument(s) compilation warning */
1200 UNUSED(Pipe);
1201 UNUSED(hdcmipp);
1202 }
1203
1204 /**
1205 * @brief Error callback on the pipe
1206 * @param hdcmipp Pointer to DCMIPP handle
1207 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1208 * @retval None
1209 */
HAL_DCMIPP_PIPE_ErrorCallback(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1210 __weak void HAL_DCMIPP_PIPE_ErrorCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1211 {
1212 /* NOTE : This function Should not be modified, when the callback is needed,
1213 the HAL_DCMIPP_SyncErrorEventCallback could be implemented in the user file
1214 */
1215 /* Prevent unused argument(s) compilation warning */
1216 UNUSED(Pipe);
1217 UNUSED(hdcmipp);
1218 }
1219
1220
1221 /**
1222 * @brief Error callback on DCMIPP
1223 * @param hdcmipp Pointer to DCMIPP handle
1224 * @retval None
1225 */
HAL_DCMIPP_ErrorCallback(DCMIPP_HandleTypeDef * hdcmipp)1226 __weak void HAL_DCMIPP_ErrorCallback(DCMIPP_HandleTypeDef *hdcmipp)
1227 {
1228 /* NOTE : This function Should not be modified, when the callback is needed,
1229 the HAL_DCMIPP_ErrorCallback could be implemented in the user file
1230 */
1231 /* Prevent unused argument(s) compilation warning */
1232 UNUSED(hdcmipp);
1233 }
1234 /**
1235 * @}
1236 */
1237
1238 /** @addtogroup DCMIPP_RegisterCallback_Functions Register Callback Functions
1239 * @{
1240 */
1241 #if (USE_HAL_DCMIPP_REGISTER_CALLBACKS == 1)
1242 /**
1243 * @brief Register a User DCMIPP Callback
1244 * To be used instead of the weak (surcharged) predefined callback
1245 * @param hdcmipp Pointer to DCMIPP handle
1246 * @param CallbackID ID of the callback to be registered
1247 * This parameter can be one of the following values:
1248 * @arg @ref HAL_DCMIPP_ERROR_CB_ID DCMIPP Error callback ID
1249 * @arg @ref HAL_DCMIPP_MSPINIT_CB_ID DCMIPP MspInit callback ID
1250 * @arg @ref HAL_DCMIPP_MSPDEINIT_CB_ID DCMIPP MspDeInit callback ID
1251 * @param pCallback pointer to the Callback function
1252 * @retval status
1253 */
HAL_DCMIPP_RegisterCallback(DCMIPP_HandleTypeDef * hdcmipp,HAL_DCMIPP_CallbackIDTypeDef CallbackID,pDCMIPP_CallbackTypeDef pCallback)1254 HAL_StatusTypeDef HAL_DCMIPP_RegisterCallback(DCMIPP_HandleTypeDef *hdcmipp, HAL_DCMIPP_CallbackIDTypeDef CallbackID,
1255 pDCMIPP_CallbackTypeDef pCallback)
1256 {
1257
1258 HAL_StatusTypeDef status = HAL_OK;
1259
1260 if (pCallback == NULL)
1261 {
1262 /* Update the error code */
1263 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1264 return HAL_ERROR;
1265 }
1266
1267 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1268 {
1269 switch (CallbackID)
1270 {
1271 case HAL_DCMIPP_MSPINIT_CB_ID :
1272 hdcmipp->MspInitCallback = pCallback;
1273 break;
1274
1275 case HAL_DCMIPP_MSPDEINIT_CB_ID :
1276 hdcmipp->MspDeInitCallback = pCallback;
1277 break;
1278
1279 case HAL_DCMIPP_ERROR_CB_ID :
1280 hdcmipp->ErrorCallback = pCallback;
1281 break;
1282
1283 default :
1284 /* Update the error code */
1285 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1286 /* update return status */
1287 status = HAL_ERROR;
1288 break;
1289 }
1290 }
1291 else if (hdcmipp->State == HAL_DCMIPP_STATE_RESET)
1292 {
1293 switch (CallbackID)
1294 {
1295 case HAL_DCMIPP_MSPINIT_CB_ID :
1296 hdcmipp->MspInitCallback = pCallback;
1297 break;
1298
1299 case HAL_DCMIPP_MSPDEINIT_CB_ID :
1300 hdcmipp->MspDeInitCallback = pCallback;
1301 break;
1302
1303 default :
1304 /* Update the error code */
1305 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1306 /* update return status */
1307 status = HAL_ERROR;
1308 break;
1309 }
1310 }
1311 else
1312 {
1313 /* Update the error code */
1314 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1315 /* update return status */
1316 status = HAL_ERROR;
1317 }
1318
1319 return status;
1320 }
1321
1322 /**
1323 * @brief Unregister a User DCMIPP Callback
1324 * DCMIPP Callback is redirected to the weak (surcharged) predefined callback
1325 * @param hdcmipp Pointer to DCMIPP handle
1326 * @param CallbackID ID of the callback to be unregistered
1327 * This parameter can be one of the following values:
1328 * @arg @ref HAL_DCMIPP_ERROR_CB_ID DCMIPP Error callback ID
1329 * @arg @ref HAL_DCMIPP_MSPINIT_CB_ID DCMIPP MspInit callback ID
1330 * @arg @ref HAL_DCMIPP_MSPDEINIT_CB_ID DCMIPP MspDeInit callback ID
1331 * @retval status
1332 */
HAL_DCMIPP_UnRegisterCallback(DCMIPP_HandleTypeDef * hdcmipp,HAL_DCMIPP_CallbackIDTypeDef CallbackID)1333 HAL_StatusTypeDef HAL_DCMIPP_UnRegisterCallback(DCMIPP_HandleTypeDef *hdcmipp, HAL_DCMIPP_CallbackIDTypeDef CallbackID)
1334 {
1335 HAL_StatusTypeDef status = HAL_OK;
1336
1337 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1338 {
1339 switch (CallbackID)
1340 {
1341 case HAL_DCMIPP_MSPINIT_CB_ID :
1342 hdcmipp->MspInitCallback = HAL_DCMIPP_MspInit; /* Legacy weak (surcharged) Msp Init */
1343 break;
1344
1345 case HAL_DCMIPP_MSPDEINIT_CB_ID :
1346 hdcmipp->MspDeInitCallback = HAL_DCMIPP_MspDeInit; /* Legacy weak (surcharged) Msp DeInit */
1347 break;
1348
1349 default :
1350 /* Update the error code */
1351 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1352 /* update return status */
1353 status = HAL_ERROR;
1354 break;
1355 }
1356 }
1357 else if (hdcmipp->State == HAL_DCMIPP_STATE_RESET)
1358 {
1359 switch (CallbackID)
1360 {
1361 case HAL_DCMIPP_MSPINIT_CB_ID :
1362 hdcmipp->MspInitCallback = HAL_DCMIPP_MspInit; /* Legacy weak (surcharged) Msp Init */
1363 break;
1364
1365 case HAL_DCMIPP_MSPDEINIT_CB_ID :
1366 hdcmipp->MspDeInitCallback = HAL_DCMIPP_MspDeInit; /* Legacy weak (surcharged) Msp DeInit */
1367 break;
1368
1369 default :
1370 /* Update the error code */
1371 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1372 /* update return status */
1373 status = HAL_ERROR;
1374 break;
1375 }
1376 }
1377 else
1378 {
1379 /* Update the error code */
1380 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1381 /* update return status */
1382 status = HAL_ERROR;
1383 }
1384
1385 return status;
1386 }
1387
1388 /**
1389 * @brief Register a User DCMIPP Pipe Callback
1390 * To be used instead of the weak (surcharged) predefined callback
1391 * @param hdcmipp Pointer to DCMIPP handle
1392 * @param CallbackID ID of the callback to be registered
1393 * This parameter can be one of the following values:
1394 * @arg @ref HAL_DCMIPP_PIPE_FRAME_EVENT_CB_ID DCMIPP Pipe Frame event callback ID
1395 * @arg @ref HAL_DCMIPP_PIPE_VSYNC_EVENT_CB_ID DCMIPP Pipe Vsync event callback ID
1396 * @arg @ref HAL_DCMIPP_PIPE_LINE_EVENT_CB_ID DCMIPP Pipe Line event callback ID
1397 * @arg @ref HAL_DCMIPP_PIPE_LIMIT_EVENT_CB_ID DCMIPP Pipe Limit event callback ID
1398 * @arg @ref HAL_DCMIPP_PIPE_ERROR_CB_ID DCMIPP Pipe Error callback ID
1399 * @param pCallback pointer to the Pipe Callback function
1400 * @retval status
1401 */
HAL_DCMIPP_PIPE_RegisterCallback(DCMIPP_HandleTypeDef * hdcmipp,HAL_DCMIPP_PIPE_CallbackIDTypeDef CallbackID,pDCMIPP_PIPE_CallbackTypeDef pCallback)1402 HAL_StatusTypeDef HAL_DCMIPP_PIPE_RegisterCallback(DCMIPP_HandleTypeDef *hdcmipp,
1403 HAL_DCMIPP_PIPE_CallbackIDTypeDef CallbackID,
1404 pDCMIPP_PIPE_CallbackTypeDef pCallback)
1405 {
1406 HAL_StatusTypeDef status = HAL_OK;
1407
1408 if (pCallback == NULL)
1409 {
1410 /* Update the error code */
1411 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1412 return HAL_ERROR;
1413 }
1414
1415 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1416 {
1417 switch (CallbackID)
1418 {
1419 case HAL_DCMIPP_PIPE_FRAME_EVENT_CB_ID :
1420 hdcmipp->PIPE_FrameEventCallback = pCallback;
1421 break;
1422
1423 case HAL_DCMIPP_PIPE_VSYNC_EVENT_CB_ID :
1424 hdcmipp->PIPE_VsyncEventCallback = pCallback;
1425 break;
1426
1427 case HAL_DCMIPP_PIPE_LINE_EVENT_CB_ID :
1428 hdcmipp->PIPE_LineEventCallback = pCallback;
1429 break;
1430
1431 case HAL_DCMIPP_PIPE_LIMIT_EVENT_CB_ID :
1432 hdcmipp->PIPE_LimitEventCallback = pCallback;
1433 break;
1434
1435 case HAL_DCMIPP_PIPE_ERROR_CB_ID :
1436 hdcmipp->PIPE_ErrorCallback = pCallback;
1437 break;
1438
1439 default :
1440 /* Update the error code */
1441 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1442 /* update return status */
1443 status = HAL_ERROR;
1444 break;
1445 }
1446 }
1447 else
1448 {
1449 /* Update the error code */
1450 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1451 /* update return status */
1452 status = HAL_ERROR;
1453 }
1454
1455 return status;
1456 }
1457
1458 /**
1459 * @brief UnRegister a User DCMIPP Pipe Callback
1460 * DCMIPP Callback is redirected to the weak (surcharged) predefined callback
1461 * @param hdcmipp Pointer to DCMIPP handle
1462 * @param CallbackID ID of the callback to be unregistered
1463 * This parameter can be one of the following values:
1464 * @arg @ref HAL_DCMIPP_PIPE_FRAME_EVENT_CB_ID DCMIPP Pipe Frame event callback ID
1465 * @arg @ref HAL_DCMIPP_PIPE_VSYNC_EVENT_CB_ID DCMIPP Pipe Vsync event callback ID
1466 * @arg @ref HAL_DCMIPP_PIPE_LINE_EVENT_CB_ID DCMIPP Pipe Line event callback ID
1467 * @arg @ref HAL_DCMIPP_PIPE_LIMIT_EVENT_CB_ID DCMIPP Pipe Limit event callback ID
1468 * @arg @ref HAL_DCMIPP_PIPE_ERROR_CB_ID DCMIPP Pipe Error callback ID
1469 * @retval status
1470 */
HAL_DCMIPP_PIPE_UnRegisterCallback(DCMIPP_HandleTypeDef * hdcmipp,HAL_DCMIPP_PIPE_CallbackIDTypeDef CallbackID)1471 HAL_StatusTypeDef HAL_DCMIPP_PIPE_UnRegisterCallback(DCMIPP_HandleTypeDef *hdcmipp,
1472 HAL_DCMIPP_PIPE_CallbackIDTypeDef CallbackID)
1473 {
1474 HAL_StatusTypeDef status = HAL_OK;
1475
1476 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1477 {
1478 switch (CallbackID)
1479 {
1480 case HAL_DCMIPP_PIPE_FRAME_EVENT_CB_ID :
1481 hdcmipp->PIPE_FrameEventCallback = HAL_DCMIPP_PIPE_FrameEventCallback;
1482 break;
1483
1484 case HAL_DCMIPP_PIPE_VSYNC_EVENT_CB_ID :
1485 hdcmipp->PIPE_VsyncEventCallback = HAL_DCMIPP_PIPE_VsyncEventCallback;
1486 break;
1487
1488 case HAL_DCMIPP_PIPE_LINE_EVENT_CB_ID :
1489 hdcmipp->PIPE_LineEventCallback = HAL_DCMIPP_PIPE_LineEventCallback;
1490 break;
1491
1492 case HAL_DCMIPP_PIPE_LIMIT_EVENT_CB_ID :
1493 hdcmipp->PIPE_LimitEventCallback = HAL_DCMIPP_PIPE_LimitEventCallback;
1494 break;
1495
1496 case HAL_DCMIPP_PIPE_ERROR_CB_ID :
1497 hdcmipp->PIPE_ErrorCallback = HAL_DCMIPP_PIPE_ErrorCallback;
1498 break;
1499
1500 default :
1501 /* Update the error code */
1502 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1503 /* update return status */
1504 status = HAL_ERROR;
1505 break;
1506 }
1507 }
1508 else
1509 {
1510 /* Update the error code */
1511 hdcmipp->ErrorCode |= HAL_DCMIPP_ERROR_INVALID_CALLBACK;
1512 /* update return status */
1513 status = HAL_ERROR;
1514 }
1515
1516 return status;
1517 }
1518 #endif /* USE_HAL_DCMIPP_REGISTER_CALLBACKS */
1519 /**
1520 * @}
1521 */
1522 /**
1523 * @}
1524 */
1525 /** @defgroup DCMIPP_Crop_Functions DCMIPP Crop Functions
1526 * @{
1527 */
1528 /**
1529 * @brief Configures cropping for the specified DCMIPP pipe according to the user parameters
1530 * @param hdcmipp Pointer to DCMIPP handle
1531 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1532 * @param pCropConfig pointer to DCMIPP_CropConfTypeDef structure that contains
1533 * the configuration information for Crop.
1534 * @retval HAL status
1535 */
HAL_DCMIPP_PIPE_SetCropConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,const DCMIPP_CropConfTypeDef * pCropConfig)1536 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetCropConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
1537 const DCMIPP_CropConfTypeDef *pCropConfig)
1538 {
1539 uint32_t tmp;
1540
1541 /* Check handle validity */
1542 if ((hdcmipp == NULL) || (pCropConfig == NULL))
1543 {
1544 return HAL_ERROR;
1545 }
1546
1547 assert_param(IS_DCMIPP_PIPE(Pipe));
1548 assert_param(IS_DCMIPP_PIPE_CROP_AREA(pCropConfig->PipeArea));
1549 assert_param(IS_DCMIPP_PIPE_CROP_HSTART(pCropConfig->HStart));
1550 assert_param(IS_DCMIPP_PIPE_CROP_HSIZE(pCropConfig->HSize));
1551 assert_param(IS_DCMIPP_PIPE_CROP_VSIZE(pCropConfig->VSize));
1552 assert_param(IS_DCMIPP_PIPE_CROP_VSTART(pCropConfig->VStart));
1553
1554 /* Check the DCMIPP State */
1555 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1556 {
1557
1558 if (Pipe == DCMIPP_PIPE0)
1559 {
1560 tmp = READ_REG(hdcmipp->Instance->PRCR);
1561
1562 /* Verify for parallel mode with jpeg format , no Line Crop enable */
1563 if (((tmp & DCMIPP_PRCR_ENABLE) == DCMIPP_PRCR_ENABLE) && ((tmp & DCMIPP_PRCR_FORMAT) == DCMIPP_FORMAT_BYTE))
1564 {
1565 return HAL_ERROR;
1566 }
1567 else
1568 {
1569 /* Set Cropping horizontal and vertical start for Pipe0 */
1570 MODIFY_REG(hdcmipp->Instance->P0SCSTR, DCMIPP_P0SCSTR_HSTART | DCMIPP_P0SCSTR_VSTART,
1571 (pCropConfig->HStart << DCMIPP_P0SCSTR_HSTART_Pos) |
1572 (pCropConfig->VStart << DCMIPP_P0SCSTR_VSTART_Pos));
1573
1574 /* Set Cropping horizontal and vertical width for Pipe0 */
1575 /* Set crop Area (Inner or outer) for Pipe0 */
1576 MODIFY_REG(hdcmipp->Instance->P0SCSZR, DCMIPP_P0SCSZR_HSIZE | DCMIPP_P0SCSZR_VSIZE | DCMIPP_P0SCSZR_POSNEG,
1577 (pCropConfig->HSize << DCMIPP_P0SCSZR_HSIZE_Pos) | (pCropConfig->VSize << DCMIPP_P0SCSZR_VSIZE_Pos) |
1578 (pCropConfig->PipeArea));
1579 }
1580 }
1581 else
1582 {
1583 return HAL_ERROR;
1584 }
1585 }
1586 else
1587 {
1588 return HAL_ERROR;
1589 }
1590
1591 return HAL_OK;
1592 }
1593
1594 /**
1595 * @brief Enables the cropping for the specified DCMIPP pipe.
1596 * @param hdcmipp Pointer to DCMIPP handle
1597 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1598 * @note Cropping cannot be enabled in parallel mode with JPEG Format
1599 * @retval HAL status
1600 */
HAL_DCMIPP_PIPE_EnableCrop(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1601 HAL_StatusTypeDef HAL_DCMIPP_PIPE_EnableCrop(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1602 {
1603 uint32_t tmp;
1604
1605 assert_param(IS_DCMIPP_PIPE(Pipe));
1606
1607 /* Check handle validity */
1608 if (hdcmipp == NULL)
1609 {
1610 return HAL_ERROR;
1611 }
1612
1613 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
1614 {
1615 if (Pipe == DCMIPP_PIPE0)
1616 {
1617 /* This bit must be kept cleared if the input format is JPEG */
1618 /* Verify for parallel mode with jpeg format , no Line Crop enable */
1619
1620 tmp = READ_REG(hdcmipp->Instance->PRCR);
1621
1622 if (((tmp & DCMIPP_PRCR_ENABLE) == DCMIPP_PRCR_ENABLE) && ((tmp & DCMIPP_PRCR_FORMAT) == DCMIPP_FORMAT_BYTE))
1623 {
1624 return HAL_ERROR;
1625 }
1626 else
1627 {
1628 SET_BIT(hdcmipp->Instance->P0SCSZR, DCMIPP_P0SCSZR_ENABLE);
1629 }
1630 }
1631 else
1632 {
1633 return HAL_ERROR;
1634 }
1635 }
1636 else
1637 {
1638 return HAL_ERROR;
1639 }
1640
1641 return HAL_OK;
1642 }
1643
1644 /**
1645 * @brief Disable the cropping for the specified DCMIPP pipe.
1646 * @param hdcmipp Pointer to DCMIPP handle
1647 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1648 * @retval HAL status
1649 */
HAL_DCMIPP_PIPE_DisableCrop(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1650 HAL_StatusTypeDef HAL_DCMIPP_PIPE_DisableCrop(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1651 {
1652 assert_param(IS_DCMIPP_PIPE(Pipe));
1653
1654 /* Check handle validity */
1655 if (hdcmipp == NULL)
1656 {
1657 return HAL_ERROR;
1658 }
1659
1660 if (Pipe == DCMIPP_PIPE0)
1661 {
1662 CLEAR_BIT(hdcmipp->Instance->P0SCSZR, DCMIPP_P0SCSZR_ENABLE);
1663 }
1664 else
1665 {
1666 return HAL_ERROR;
1667 }
1668
1669 return HAL_OK;
1670 }
1671 /**
1672 * @}
1673 */
1674
1675 /** @defgroup DCMIPP_Decimation_Functions DCMIPP Decimation Functions
1676 * @{
1677 */
1678 /**
1679 * @brief Configure the Bytes decimation for the selected Pipe.
1680 * @param hdcmipp Pointer to DCMIPP handle
1681 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1682 * @param SelectStart can a be value from @ref DCMIPP_Byte_Start_Mode
1683 * @param SelectMode can be a value from @ref DCMIPP_Byte_Select_Mode
1684 * @retval HAL status
1685 */
HAL_DCMIPP_PIPE_SetBytesDecimationConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t SelectStart,uint32_t SelectMode)1686 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetBytesDecimationConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
1687 uint32_t SelectStart, uint32_t SelectMode)
1688 {
1689 uint32_t tmp;
1690
1691 assert_param(IS_DCMIPP_PIPE(Pipe));
1692 assert_param(IS_DCMIPP_BYTE_SELECT_START(SelectStart));
1693 assert_param(IS_DCMIPP_BYTE_SELECT_MODE(SelectMode));
1694
1695 /* Check handle validity */
1696 if (hdcmipp == NULL)
1697 {
1698 return HAL_ERROR;
1699 }
1700
1701 if (Pipe == DCMIPP_PIPE0)
1702 {
1703 /* OEBS : This bit works in conjunction with BSM field (BSM != 00) */
1704 /* Modes 10 and 11 work only with EDM [2:0] = 000 into the DCMIPP_PRCR */
1705 tmp = (hdcmipp->Instance->PRCR & DCMIPP_PRCR_EDM);
1706
1707 if (((SelectStart == DCMIPP_OEBS_EVEN) && (SelectMode > DCMIPP_BSM_ALL)) || \
1708 ((SelectMode > DCMIPP_BSM_DATA_OUT_2) && (tmp != DCMIPP_INTERFACE_8BITS)))
1709 {
1710 return HAL_ERROR;
1711 }
1712 else
1713 {
1714 /* Set Bytes select Start and Bytes select Mode */
1715 MODIFY_REG(hdcmipp->Instance->P0PPCR, DCMIPP_P0PPCR_BSM | DCMIPP_P0PPCR_OEBS, (SelectStart | SelectMode));
1716 }
1717 }
1718 else
1719 {
1720 return HAL_ERROR;
1721 }
1722
1723 return HAL_OK;
1724 }
1725
1726 /**
1727 * @brief Configure the Lines decimation for the selected Pipe.
1728 * @param hdcmipp Pointer to DCMIPP handle
1729 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1730 * @param SelectStart can a be value from @ref DCMIPP_Line_Start_Mode
1731 * @param SelectMode can be a value from @ref DCMIPP_Line_Select_Mode
1732 * @retval HAL status
1733 */
HAL_DCMIPP_PIPE_SetLinesDecimationConfig(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t SelectStart,uint32_t SelectMode)1734 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetLinesDecimationConfig(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
1735 uint32_t SelectStart, uint32_t SelectMode)
1736 {
1737 assert_param(IS_DCMIPP_PIPE(Pipe));
1738 assert_param(IS_DCMIPP_LINE_SELECT_MODE(SelectMode));
1739 assert_param(IS_DCMIPP_LINE_SELECT_START(SelectStart));
1740
1741 /* Check handle validity */
1742 if (hdcmipp == NULL)
1743 {
1744 return HAL_ERROR;
1745 }
1746
1747 if (Pipe == DCMIPP_PIPE0)
1748 {
1749 /* This bit works in conjunction with LSM field (LSM = 1) */
1750 if ((SelectStart == DCMIPP_OELS_EVEN) && (SelectMode == DCMIPP_LSM_ALTERNATE_2))
1751 {
1752 return HAL_ERROR;
1753 }
1754 else
1755 {
1756 /* Set Lines select Start and Bytes select Mode */
1757 MODIFY_REG(hdcmipp->Instance->P0PPCR, DCMIPP_P0PPCR_LSM | DCMIPP_P0PPCR_OELS, (SelectStart | SelectMode));
1758 }
1759 }
1760 else
1761 {
1762 return HAL_ERROR;
1763 }
1764 return HAL_OK;
1765 }
1766 /**
1767 * @}
1768 */
1769
1770 /** @defgroup DCMIPP_LimitEvent_Functions DCMIPP Limit Event Functions
1771 * @{
1772 */
1773 /**
1774 * @brief Define the Data dump limit for the selected Pipe.
1775 * @param hdcmipp Pointer to DCMIPP handle
1776 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1777 * @param Limit Data dump Limit.
1778 * @retval HAL status
1779 */
HAL_DCMIPP_PIPE_EnableLimitEvent(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t Limit)1780 HAL_StatusTypeDef HAL_DCMIPP_PIPE_EnableLimitEvent(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t Limit)
1781 {
1782 assert_param(IS_DCMIPP_PIPE(Pipe));
1783 assert_param(IS_DCMIPP_DATA_LIMIT(Limit));
1784
1785 /* Check Parameters */
1786 if (hdcmipp == NULL)
1787 {
1788 return HAL_ERROR;
1789 }
1790
1791 if (Pipe == DCMIPP_PIPE0)
1792 {
1793 /* Set and enable data limit on Pipe 0 */
1794 WRITE_REG(hdcmipp->Instance->P0DCLMTR, (Limit << DCMIPP_P0DCLMTR_LIMIT_Pos) | DCMIPP_P0DCLMTR_ENABLE);
1795
1796 /* Enable Limit Interrupt for pipe0 */
1797 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_LIMIT);
1798 }
1799 else
1800 {
1801 return HAL_ERROR;
1802 }
1803
1804 return HAL_OK;
1805 }
1806
1807 /**
1808 * @brief Disable the the Limit interrupt.
1809 * @param hdcmipp Pointer to DCMIPP handle
1810 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1811 * @retval HAL status
1812 */
HAL_DCMIPP_PIPE_DisableLimitEvent(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1813 HAL_StatusTypeDef HAL_DCMIPP_PIPE_DisableLimitEvent(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1814 {
1815 assert_param(IS_DCMIPP_PIPE(Pipe));
1816
1817 /* Check Parameters */
1818 if (hdcmipp == NULL)
1819 {
1820 return HAL_ERROR;
1821 }
1822
1823 if (Pipe == DCMIPP_PIPE0)
1824 {
1825 /* Disable data limit on Pipe 0 */
1826 CLEAR_BIT(hdcmipp->Instance->P0DCLMTR, DCMIPP_P0DCLMTR_ENABLE);
1827
1828 /* Disable Limit Interrupt for pipe0 */
1829 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_LIMIT);
1830 }
1831 else
1832 {
1833 return HAL_ERROR;
1834 }
1835
1836 return HAL_OK;
1837 }
1838
1839 /**
1840 * @}
1841 */
1842 /** @defgroup DCMIPP_PeripheralControl_Functions DCMIPP Peripheral Control Functions
1843 * @{
1844 */
1845 /**
1846 * @brief Reconfigure the Frame Rate for the selected pipe
1847 * @param hdcmipp Pointer to DCMIPP handle
1848 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1849 * @param FrameRate the new Frame Rate, can be a value from @ref DCMIPP_Frame_Rates
1850 * @retval HAL status
1851 */
HAL_DCMIPP_PIPE_SetFrameRate(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t FrameRate)1852 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetFrameRate(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t FrameRate)
1853 {
1854 /* Check Parameters */
1855 if (hdcmipp == NULL)
1856 {
1857 return HAL_ERROR;
1858 }
1859
1860 /* Check parameters */
1861 assert_param(IS_DCMIPP_PIPE(Pipe));
1862 assert_param(IS_DCMIPP_FRAME_RATE(FrameRate));
1863
1864 /* Set Frame Rate for the Pipe */
1865 if (Pipe == DCMIPP_PIPE0)
1866 {
1867 MODIFY_REG(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_FRATE, FrameRate);
1868 }
1869 else
1870 {
1871 return HAL_ERROR;
1872 }
1873
1874 return HAL_OK;
1875 }
1876 /**
1877 * @brief Reconfigure Capture Mode for the selected pipe
1878 * @param hdcmipp Pointer to DCMIPP handle
1879 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1880 * @param CaptureMode the new Capture Mode, can be a value from @ref DCMIPP_Capture_Mode
1881 * @retval HAL status
1882 */
HAL_DCMIPP_PIPE_SetCaptureMode(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t CaptureMode)1883 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetCaptureMode(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t CaptureMode)
1884 {
1885 /* Check Parameters */
1886 if (hdcmipp == NULL)
1887 {
1888 return HAL_ERROR;
1889 }
1890
1891 assert_param(IS_DCMIPP_PIPE(Pipe));
1892 assert_param(IS_DCMIPP_CAPTURE_MODE(CaptureMode));
1893
1894
1895 /* Set Capture Mode */
1896 if (Pipe == DCMIPP_PIPE0)
1897 {
1898 MODIFY_REG(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTMODE, CaptureMode);
1899 }
1900 else
1901 {
1902 return HAL_ERROR;
1903 }
1904
1905 return HAL_OK;
1906 }
1907 /**
1908 * @brief Re-Enable Capture for the selected pipe
1909 * @param hdcmipp Pointer to DCMIPP handle
1910 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1911 * @retval HAL status
1912 */
HAL_DCMIPP_PIPE_EnableCapture(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)1913 HAL_StatusTypeDef HAL_DCMIPP_PIPE_EnableCapture(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
1914 {
1915 /* Check Parameters */
1916 if (hdcmipp == NULL)
1917 {
1918 return HAL_ERROR;
1919 }
1920
1921 /* Request Capture for the chosen Pipe */
1922
1923 if (Pipe == DCMIPP_PIPE0)
1924 {
1925 SET_BIT(hdcmipp->Instance->P0FCTCR, DCMIPP_P0FCTCR_CPTREQ);
1926 }
1927 else
1928 {
1929 return HAL_ERROR;
1930 }
1931
1932 return HAL_OK;
1933 }
1934 /**
1935 * @brief Reconfigure the destination memory address for the selected pipe
1936 * @param hdcmipp Pointer to DCMIPP handle
1937 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1938 * @param Memory the destination address to be changed can be value from @ref DCMIPP_Memory.
1939 * @param DstAddress the new destination address
1940 * @retval HAL status
1941 */
HAL_DCMIPP_PIPE_SetMemoryAddress(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t Memory,uint32_t DstAddress)1942 HAL_StatusTypeDef HAL_DCMIPP_PIPE_SetMemoryAddress(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t Memory,
1943 uint32_t DstAddress)
1944 {
1945 /* Check Parameters */
1946 if (hdcmipp == NULL)
1947 {
1948 return HAL_ERROR;
1949 }
1950
1951 assert_param(IS_DCMIPP_PIPE(Pipe));
1952 assert_param(IS_DCMIPP_MEMORY_ADDRESS(Memory));
1953
1954 /* Request Capture for the chosen Pipe */
1955
1956 if (Pipe == DCMIPP_PIPE0)
1957 {
1958 if (Memory == DCMIPP_MEMORY_ADDRESS_0)
1959 {
1960 /* Set Memory0 destination addresses for pipe0 */
1961 WRITE_REG(hdcmipp->Instance->P0PPM0AR1, DstAddress);
1962 }
1963 else
1964 {
1965 if ((hdcmipp->Instance->P0PPCR & DCMIPP_P0PPCR_DBM) == DCMIPP_P0PPCR_DBM)
1966 {
1967 /* Set Memory1 destination addresses for pipe0 */
1968 WRITE_REG(hdcmipp->Instance->P0PPM0AR2, DstAddress);
1969 }
1970 else
1971 {
1972 return HAL_ERROR;
1973 }
1974 }
1975 }
1976 else
1977 {
1978 return HAL_ERROR;
1979 }
1980
1981 return HAL_OK;
1982
1983 }
1984 /**
1985 * @brief Reconfigure the input pixel format for the selected pipe
1986 * @param hdcmipp Pointer to DCMIPP handle
1987 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
1988 * @param InputPixelFormat new pixel format, can be a value from @ref DCMIPP_Format
1989 * @retval HAL status
1990 */
HAL_DCMIPP_PIPE_PARALLEL_SetInputPixelFormat(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t InputPixelFormat)1991 HAL_StatusTypeDef HAL_DCMIPP_PIPE_PARALLEL_SetInputPixelFormat(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
1992 uint32_t InputPixelFormat)
1993 {
1994 assert_param(IS_DCMIPP_PIPE(Pipe));
1995 assert_param(IS_DCMIPP_FORMAT(InputPixelFormat));
1996
1997 if (hdcmipp == NULL)
1998 {
1999 return HAL_ERROR;
2000 }
2001
2002 if (Pipe == DCMIPP_PIPE0)
2003 {
2004 /* Set Frame Rate */
2005 MODIFY_REG(hdcmipp->Instance->PRCR, DCMIPP_PRCR_FORMAT, InputPixelFormat);
2006 }
2007 else
2008 {
2009 return HAL_ERROR;
2010 }
2011
2012 return HAL_OK;
2013 }
2014 /**
2015 * @brief Set embedded synchronization delimiters unmasks.
2016 * @param hdcmipp Pointer to DCMIPP handle
2017 * @param SyncUnmask Pointer to a DCMIPP_EmbeddedSyncUnmaskTypeDef structure that contains
2018 * the embedded synchronization delimiters unmasks.
2019 * @retval HAL status
2020 */
HAL_DCMIPP_PARALLEL_SetSyncUnmask(DCMIPP_HandleTypeDef * hdcmipp,const DCMIPP_EmbeddedSyncUnmaskTypeDef * SyncUnmask)2021 HAL_StatusTypeDef HAL_DCMIPP_PARALLEL_SetSyncUnmask(DCMIPP_HandleTypeDef *hdcmipp,
2022 const DCMIPP_EmbeddedSyncUnmaskTypeDef *SyncUnmask)
2023 {
2024 uint32_t presur_reg;
2025 uint32_t prcr_reg;
2026
2027 /* Check pointer validity */
2028 if ((hdcmipp == NULL) || (SyncUnmask == NULL))
2029 {
2030 return HAL_ERROR;
2031 }
2032
2033 /* Check the DCMIPP State */
2034 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
2035 {
2036 prcr_reg = hdcmipp->Instance->PRCR;
2037 /* Check that Embedded synchronisation mode is configured */
2038 if ((prcr_reg & DCMIPP_PRCR_ESS) == DCMIPP_SYNCHRO_EMBEDDED)
2039 {
2040 /* Configure DCMIPP embedded synchronization unmask register */
2041 presur_reg = (((uint32_t)SyncUnmask->FrameStartUnmask << DCMIPP_PRESUR_FSU_Pos) | \
2042 ((uint32_t)SyncUnmask->LineStartUnmask << DCMIPP_PRESUR_LSU_Pos) | \
2043 ((uint32_t)SyncUnmask->LineEndUnmask << DCMIPP_PRESUR_LEU_Pos) | \
2044 ((uint32_t)SyncUnmask->FrameEndUnmask << DCMIPP_PRESUR_FEU_Pos));
2045
2046 WRITE_REG(hdcmipp->Instance->PRESUR, presur_reg);
2047 }
2048 else
2049 {
2050 return HAL_ERROR;
2051 }
2052 }
2053 else
2054 {
2055 return HAL_ERROR;
2056 }
2057
2058 return HAL_OK;
2059 }
2060 /**
2061 * @}
2062 */
2063 /** @defgroup DCMIPP_Line_Event_Functions DCMIPP Line Event Functions
2064 * @{
2065 */
2066 /**
2067 * @brief Configures the position of the line interrupt.
2068 * @param hdcmipp Pointer to DCMIPP handle
2069 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2070 * @param Line Line Interrupt Position.
2071 * @retval HAL status
2072 */
HAL_DCMIPP_PIPE_EnableLineEvent(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t Line)2073 HAL_StatusTypeDef HAL_DCMIPP_PIPE_EnableLineEvent(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe, uint32_t Line)
2074 {
2075 assert_param(IS_DCMIPP_PIPE(Pipe));
2076 assert_param(IS_DCMIPP_PIPE_MULTILINE(Line));
2077
2078 if (Pipe == DCMIPP_PIPE0)
2079 {
2080 /* Set MultiLine configuration */
2081 MODIFY_REG(hdcmipp->Instance->P0PPCR, DCMIPP_P0PPCR_LINEMULT, Line);
2082
2083 /* Enable Multiline Interrupt */
2084 __HAL_DCMIPP_ENABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_LINE);
2085 }
2086 else
2087 {
2088 return HAL_ERROR;
2089 }
2090
2091 return HAL_OK;
2092 }
2093 /**
2094 * @brief Disable the the line event interrupt.
2095 * @param hdcmipp Pointer to DCMIPP handle
2096 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2097 * @retval HAL status
2098 */
HAL_DCMIPP_PIPE_DisableLineEvent(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)2099 HAL_StatusTypeDef HAL_DCMIPP_PIPE_DisableLineEvent(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
2100 {
2101 assert_param(IS_DCMIPP_PIPE(Pipe));
2102
2103 /* Disable Multiline Interrupt */
2104 if (Pipe == DCMIPP_PIPE0)
2105 {
2106 __HAL_DCMIPP_DISABLE_IT(hdcmipp, DCMIPP_IT_PIPE0_LINE);
2107 }
2108 else
2109 {
2110 return HAL_ERROR;
2111 }
2112
2113 return HAL_OK;
2114 }
2115 /**
2116 * @}
2117 */
2118 /** @defgroup DCMIPP_Frame_Counter_Functions DCMIPP Frame Counter Functions
2119 * @{
2120 */
2121 /**
2122 * @brief Reset the DCMIPP Pipe frame counter
2123 * @param hdcmipp Pointer to DCMIPP handle
2124 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2125 * @retval HAL status
2126 */
HAL_DCMIPP_PIPE_ResetFrameCounter(DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)2127 HAL_StatusTypeDef HAL_DCMIPP_PIPE_ResetFrameCounter(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
2128 {
2129
2130 /* Check pointer validity */
2131 if (hdcmipp == NULL)
2132 {
2133 return HAL_ERROR;
2134 }
2135
2136 /* Prevent unused argument(s) compilation warning */
2137 UNUSED(Pipe);
2138 /* Check parameters */
2139 assert_param(IS_DCMIPP_PIPE(Pipe));
2140
2141 /* Check the DCMIPP State */
2142 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
2143 {
2144 /* Clear Frame counter */
2145 SET_BIT(hdcmipp->Instance->CMCR, DCMIPP_CMCR_CFC);
2146 }
2147 else
2148 {
2149 return HAL_ERROR;
2150 }
2151
2152 return HAL_OK;
2153 }
2154 /**
2155 * @brief Read the DCMIPP frame counter
2156 * @param hdcmipp Pointer to DCMIPP handle
2157 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2158 * @param pCounter pointer to store the value of the frame counter
2159 * @retval HAL status
2160 */
HAL_DCMIPP_PIPE_ReadFrameCounter(const DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t * pCounter)2161 HAL_StatusTypeDef HAL_DCMIPP_PIPE_ReadFrameCounter(const DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
2162 uint32_t *pCounter)
2163 {
2164
2165 /* Check parameters */
2166 assert_param(IS_DCMIPP_PIPE(Pipe));
2167
2168 /* Prevent unused argument(s) compilation warning */
2169 UNUSED(Pipe);
2170 /* Check pointer validity */
2171 if ((hdcmipp == NULL) || (pCounter == NULL))
2172 {
2173 return HAL_ERROR;
2174 }
2175
2176 /* Check the DCMIPP State */
2177 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
2178 {
2179 /* Read frame counter */
2180 *pCounter = READ_REG(hdcmipp->Instance->CMFRCR);
2181 }
2182 else
2183 {
2184 return HAL_ERROR;
2185 }
2186
2187 return HAL_OK;
2188 }
2189 /**
2190 * @}
2191 */
2192
2193 /** @defgroup DCMIPP_Data_Counter_Functions DCMIPP Data Counter Functions
2194 * @{
2195 */
2196 /**
2197 * @brief Read Number of data dumped during the frame.
2198 * @param hdcmipp Pointer to DCMIPP handle
2199 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2200 * @param pCounter pointer to amount of word transferred
2201 * @note Data Counter is available only on DCMIPP_PIPE0. The counter saturates at 0x3FFFFFF.
2202 * @note Granularity is 32-bit for all the formats except for the
2203 * byte stream formats (e.g. JPEG) having byte granularity
2204 * @retval Status
2205 */
HAL_DCMIPP_PIPE_GetDataCounter(const DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe,uint32_t * pCounter)2206 HAL_StatusTypeDef HAL_DCMIPP_PIPE_GetDataCounter(const DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe,
2207 uint32_t *pCounter)
2208 {
2209 /* Check parameters */
2210 assert_param(IS_DCMIPP_PIPE(Pipe));
2211
2212 /* Prevent unused argument(s) compilation warning */
2213 UNUSED(Pipe);
2214 /* Check pointer validity */
2215 if ((hdcmipp == NULL) || (pCounter == NULL))
2216 {
2217 return HAL_ERROR;
2218 }
2219
2220 /* Check the DCMIPP State */
2221 if (hdcmipp->State == HAL_DCMIPP_STATE_READY)
2222 {
2223 /* Read Pipe0 dump counter register */
2224 *pCounter = READ_REG(hdcmipp->Instance->P0DCCNTR);
2225 }
2226 else
2227 {
2228 return HAL_ERROR;
2229 }
2230
2231 return HAL_OK;
2232 }
2233 /**
2234 * @}
2235 */
2236
2237 /** @defgroup DCMIPP_State_and_Error_Functions DCMIPP State and Error Functions
2238 * @{
2239 */
2240
2241 /**
2242 * @brief Return the DCMIPP state
2243 * @param hdcmipp Pointer to DCMIPP handle
2244 * @retval HAL state
2245 */
HAL_DCMIPP_GetState(const DCMIPP_HandleTypeDef * hdcmipp)2246 HAL_DCMIPP_StateTypeDef HAL_DCMIPP_GetState(const DCMIPP_HandleTypeDef *hdcmipp)
2247 {
2248 return hdcmipp->State;
2249 }
2250 /**
2251 * @brief Return the DCMIPP error code
2252 * @param hdcmipp Pointer to DCMIPP handle
2253 * @retval DCMIPP Error Code
2254 */
HAL_DCMIPP_GetError(const DCMIPP_HandleTypeDef * hdcmipp)2255 uint32_t HAL_DCMIPP_GetError(const DCMIPP_HandleTypeDef *hdcmipp)
2256 {
2257 return hdcmipp->ErrorCode;
2258 }
2259 /**
2260 * @brief Return the DCMIPP state
2261 * @param hdcmipp Pointer to DCMIPP handle
2262 * @param Pipe Specifies the DCMIPP pipe, can be a value from @ref DCMIPP_Pipes
2263 * @retval HAL state
2264 */
HAL_DCMIPP_PIPE_GetState(const DCMIPP_HandleTypeDef * hdcmipp,uint32_t Pipe)2265 HAL_DCMIPP_PipeStateTypeDef HAL_DCMIPP_PIPE_GetState(const DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
2266 {
2267 /* Check Parameters */
2268 assert_param(IS_DCMIPP_PIPE(Pipe));
2269
2270 return hdcmipp->PipeState[Pipe];
2271 }
2272
2273 /**
2274 * @}
2275 */
2276
2277 /**
2278 * @}
2279 */
2280
2281 /**
2282 * @}
2283 */
2284
2285 /**
2286 * @}
2287 */
2288 #endif /* DCMIPP */
2289 #endif /* HAL_DCMIPP_MODULE_ENABLED */
2290