blob: 2ce3477fbdaafb47438f5edb8dc08585dc4f2f82 [file] [log] [blame]
Eya8a83a682020-01-29 12:42:18 +01001/**
2 ******************************************************************************
3 * @file stm32f7xx_hal_dcmi.c
4 * @author MCD Application Team
5 * @brief DCMI HAL module driver
Ali Labbene243e61a2020-03-12 16:07:28 +01006 * This file provides firmware functions to manage the following
Eya8a83a682020-01-29 12:42:18 +01007 * functionalities of the Digital Camera Interface (DCMI) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
Ali Labbene243e61a2020-03-12 16:07:28 +010010 * + Peripheral Control functions
11 * + Peripheral State and Error functions
12 *
rihab kouki27458ea2021-12-14 11:01:06 +010013 ******************************************************************************
14 * @attention
15 *
16 * Copyright (c) 2017 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 ******************************************************************************
Eya8a83a682020-01-29 12:42:18 +010024 @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 DCMI 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 DCMI to capture images.
34
35 (#) Program the required configuration through following parameters:
36 horizontal and vertical polarity, pixel clock polarity, Capture Rate,
Ali Labbene243e61a2020-03-12 16:07:28 +010037 Synchronization Mode, code of the frame delimiter and data width
Eya8a83a682020-01-29 12:42:18 +010038 using HAL_DCMI_Init() function.
39
Tasnim2e3aac42024-05-27 13:47:18 +010040 (#) Configure the selected DMA stream to transfer Data from DCMI DR
Eya8a83a682020-01-29 12:42:18 +010041 register to the destination memory buffer.
42
43 (#) Program the required configuration through following parameters:
Ali Labbene243e61a2020-03-12 16:07:28 +010044 DCMI mode, destination memory Buffer address and the data length
Eya8a83a682020-01-29 12:42:18 +010045 and enable capture using HAL_DCMI_Start_DMA() function.
46
47 (#) Optionally, configure and Enable the CROP feature to select a rectangular
Ali Labbene243e61a2020-03-12 16:07:28 +010048 window from the received image using HAL_DCMI_ConfigCrop()
Tasnim2e3aac42024-05-27 13:47:18 +010049 and HAL_DCMI_EnableCrop() functions
Eya8a83a682020-01-29 12:42:18 +010050
51 (#) The capture can be stopped using HAL_DCMI_Stop() function.
52
53 (#) To control DCMI state you can use the function HAL_DCMI_GetState().
54
55 *** DCMI HAL driver macros list ***
Ali Labbene243e61a2020-03-12 16:07:28 +010056 =============================================
Eya8a83a682020-01-29 12:42:18 +010057 [..]
58 Below the list of most used macros in DCMI HAL driver.
Ali Labbene243e61a2020-03-12 16:07:28 +010059
Eya8a83a682020-01-29 12:42:18 +010060 (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
61 (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
62 (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
63 (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
64 (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
65 (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
66 (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
Ali Labbene243e61a2020-03-12 16:07:28 +010067
68 [..]
Eya8a83a682020-01-29 12:42:18 +010069 (@) You can refer to the DCMI HAL driver header file for more useful macros
Ali Labbene243e61a2020-03-12 16:07:28 +010070
Eya8a83a682020-01-29 12:42:18 +010071 *** Callback registration ***
72 =============================
73
74 The compilation define USE_HAL_DCMI_REGISTER_CALLBACKS when set to 1
75 allows the user to configure dynamically the driver callbacks.
rihab kouki27458ea2021-12-14 11:01:06 +010076 Use functions HAL_DCMI_RegisterCallback() to register a user callback.
Eya8a83a682020-01-29 12:42:18 +010077
rihab kouki27458ea2021-12-14 11:01:06 +010078 Function HAL_DCMI_RegisterCallback() allows to register following callbacks:
Tasnim2e3aac42024-05-27 13:47:18 +010079 (+) FrameEventCallback : callback for DCMI Frame Event.
80 (+) VsyncEventCallback : callback for DCMI Vsync Event.
81 (+) LineEventCallback : callback for DCMI Line Event.
82 (+) ErrorCallback : callback for DCMI error detection.
83 (+) MspInitCallback : callback for DCMI MspInit.
84 (+) MspDeInitCallback : callback for DCMI MspDeInit.
85 This function takes as parameters the HAL peripheral handle, the Callback ID
Eya8a83a682020-01-29 12:42:18 +010086 and a pointer to the user callback function.
87
rihab kouki27458ea2021-12-14 11:01:06 +010088 Use function HAL_DCMI_UnRegisterCallback() to reset a callback to the default
Eya8a83a682020-01-29 12:42:18 +010089 weak (surcharged) function.
rihab kouki27458ea2021-12-14 11:01:06 +010090 HAL_DCMI_UnRegisterCallback() takes as parameters the HAL peripheral handle,
Eya8a83a682020-01-29 12:42:18 +010091 and the callback ID.
92 This function allows to reset following callbacks:
Tasnim2e3aac42024-05-27 13:47:18 +010093 (+) FrameEventCallback : callback for DCMI Frame Event.
94 (+) VsyncEventCallback : callback for DCMI Vsync Event.
95 (+) LineEventCallback : callback for DCMI Line Event.
96 (+) ErrorCallback : callback for DCMI error.
97 (+) MspInitCallback : callback for DCMI MspInit.
98 (+) MspDeInitCallback : callback for DCMI MspDeInit.
Eya8a83a682020-01-29 12:42:18 +010099
rihab kouki27458ea2021-12-14 11:01:06 +0100100 By default, after the HAL_DCMI_Init and if the state is HAL_DCMI_STATE_RESET
Eya8a83a682020-01-29 12:42:18 +0100101 all callbacks are reset to the corresponding legacy weak (surcharged) functions:
rihab kouki27458ea2021-12-14 11:01:06 +0100102 examples FrameEventCallback(), HAL_DCMI_ErrorCallback().
Eya8a83a682020-01-29 12:42:18 +0100103 Exception done for MspInit and MspDeInit callbacks that are respectively
rihab kouki27458ea2021-12-14 11:01:06 +0100104 reset to the legacy weak (surcharged) functions in the HAL_DCMI_Init
Tasnim2e3aac42024-05-27 13:47:18 +0100105 and HAL_DCMI_DeInit only when these callbacks are null (not registered beforehand).
rihab kouki27458ea2021-12-14 11:01:06 +0100106 If not, MspInit or MspDeInit are not null, the HAL_DCMI_Init and HAL_DCMI_DeInit
Eya8a83a682020-01-29 12:42:18 +0100107 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
108
109 Callbacks can be registered/unregistered in READY state only.
110 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
111 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
112 during the Init/DeInit.
113 In that case first register the MspInit/MspDeInit user callbacks
rihab kouki27458ea2021-12-14 11:01:06 +0100114 using HAL_DCMI_RegisterCallback before calling HAL_DCMI_DeInit
115 or HAL_DCMI_Init function.
Eya8a83a682020-01-29 12:42:18 +0100116
117 When the compilation define USE_HAL_DCMI_REGISTER_CALLBACKS is set to 0 or
118 not defined, the callback registering feature is not available
119 and weak (surcharged) callbacks are used.
Ali Labbene243e61a2020-03-12 16:07:28 +0100120
Eya8a83a682020-01-29 12:42:18 +0100121 @endverbatim
122 ******************************************************************************
Eya8a83a682020-01-29 12:42:18 +0100123 */
124
125/* Includes ------------------------------------------------------------------*/
126#include "stm32f7xx_hal.h"
Tasnim2e3aac42024-05-27 13:47:18 +0100127#ifdef HAL_DCMI_MODULE_ENABLED
128#if defined (DCMI)
Eya8a83a682020-01-29 12:42:18 +0100129
130/** @addtogroup STM32F7xx_HAL_Driver
131 * @{
132 */
133/** @defgroup DCMI DCMI
134 * @brief DCMI HAL module driver
135 * @{
136 */
137
Eya8a83a682020-01-29 12:42:18 +0100138/* Private typedef -----------------------------------------------------------*/
139/* Private define ------------------------------------------------------------*/
Tasnim2e3aac42024-05-27 13:47:18 +0100140/** @defgroup DCMI_Private_Constants DCMI Private Constants
141 * @{
142 */
Eya8a83a682020-01-29 12:42:18 +0100143
Tasnim2e3aac42024-05-27 13:47:18 +0100144/** @defgroup DCMI_Stop_TimeOut DCMI Stop Time Out
145 * @{
146 */
147#define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* Set timeout to 1s */
148/**
149 * @}
150 */
151
152/**
153 * @}
154 */
Eya8a83a682020-01-29 12:42:18 +0100155/* Private macro -------------------------------------------------------------*/
156/* Private variables ---------------------------------------------------------*/
157/* Private function prototypes -----------------------------------------------*/
Tasnim2e3aac42024-05-27 13:47:18 +0100158/** @addtogroup DCMI_Private_Functions DCMI Private Functions
159 * @{
160 */
Eya8a83a682020-01-29 12:42:18 +0100161static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
162static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
163
Tasnim2e3aac42024-05-27 13:47:18 +0100164/**
165 * @}
166 */
Eya8a83a682020-01-29 12:42:18 +0100167/* Exported functions --------------------------------------------------------*/
168
169/** @defgroup DCMI_Exported_Functions DCMI Exported Functions
170 * @{
171 */
172
173/** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
Tasnim2e3aac42024-05-27 13:47:18 +0100174 * @brief Initialization and Configuration functions
175 *
Ali Labbene243e61a2020-03-12 16:07:28 +0100176@verbatim
Eya8a83a682020-01-29 12:42:18 +0100177 ===============================================================================
178 ##### Initialization and Configuration functions #####
Ali Labbene243e61a2020-03-12 16:07:28 +0100179 ===============================================================================
Eya8a83a682020-01-29 12:42:18 +0100180 [..] This section provides functions allowing to:
181 (+) Initialize and configure the DCMI
Ali Labbene243e61a2020-03-12 16:07:28 +0100182 (+) De-initialize the DCMI
Eya8a83a682020-01-29 12:42:18 +0100183
184@endverbatim
185 * @{
186 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100187
Eya8a83a682020-01-29 12:42:18 +0100188/**
189 * @brief Initializes the DCMI according to the specified
190 * parameters in the DCMI_InitTypeDef and create the associated handle.
191 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
192 * the configuration information for DCMI.
193 * @retval HAL status
194 */
195HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
Ali Labbene243e61a2020-03-12 16:07:28 +0100196{
Eya8a83a682020-01-29 12:42:18 +0100197 /* Check the DCMI peripheral state */
Ali Labbene243e61a2020-03-12 16:07:28 +0100198 if (hdcmi == NULL)
Eya8a83a682020-01-29 12:42:18 +0100199 {
Ali Labbene243e61a2020-03-12 16:07:28 +0100200 return HAL_ERROR;
Eya8a83a682020-01-29 12:42:18 +0100201 }
Ali Labbene243e61a2020-03-12 16:07:28 +0100202
Eya8a83a682020-01-29 12:42:18 +0100203 /* Check function parameters */
204 assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
205 assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
206 assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
207 assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
208 assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
209 assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
210 assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
211 assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
212
Ali Labbene243e61a2020-03-12 16:07:28 +0100213#ifdef DCMI_CR_BSM
Eya8a83a682020-01-29 12:42:18 +0100214 assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
215 assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
216 assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
217 assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
Ali Labbene243e61a2020-03-12 16:07:28 +0100218#endif
219
220 if (hdcmi->State == HAL_DCMI_STATE_RESET)
Eya8a83a682020-01-29 12:42:18 +0100221 {
Ali Labbene243e61a2020-03-12 16:07:28 +0100222 /* Init the DCMI Callback settings */
Eya8a83a682020-01-29 12:42:18 +0100223#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
Tasnim2e3aac42024-05-27 13:47:18 +0100224 /* Reset callback pointers to the weak predefined callbacks */
Ali Labbene243e61a2020-03-12 16:07:28 +0100225 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
226 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
227 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
228 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
229
230 if (hdcmi->MspInitCallback == NULL)
Eya8a83a682020-01-29 12:42:18 +0100231 {
232 /* Legacy weak MspInit Callback */
233 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
234 }
235 /* Initialize the low level hardware (MSP) */
236 hdcmi->MspInitCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100237#else
Eya8a83a682020-01-29 12:42:18 +0100238 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
239 HAL_DCMI_MspInit(hdcmi);
240#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
Ali Labbene243e61a2020-03-12 16:07:28 +0100241 }
242
Eya8a83a682020-01-29 12:42:18 +0100243 /* Change the DCMI state */
Ali Labbene243e61a2020-03-12 16:07:28 +0100244 hdcmi->State = HAL_DCMI_STATE_BUSY;
245
246#ifdef DCMI_CR_BSM
247 if (hdcmi->Init.ExtendedDataMode != DCMI_EXTEND_DATA_8B)
248 {
249 /* Byte select mode must be programmed to the reset value if the extended mode
250 is not set to 8-bit data capture on every pixel clock */
251 hdcmi->Init.ByteSelectMode = DCMI_BSM_ALL;
252 }
253#endif
254 /* Configures the HS, VS, DE and PC polarity */
255#ifdef DCMI_CR_BSM
256 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | \
257 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | \
258 DCMI_CR_ESS | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS | \
Eya8a83a682020-01-29 12:42:18 +0100259 DCMI_CR_LSM | DCMI_CR_OELS);
260
Ali Labbene243e61a2020-03-12 16:07:28 +0100261 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
262 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
263 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
264 hdcmi->Init.JPEGMode | hdcmi->Init.ByteSelectMode | \
265 hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode | \
266 hdcmi->Init.LineSelectStart);
267#else
268 hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | \
269 DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG);
270
271 hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
272 hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
273 hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
274 hdcmi->Init.JPEGMode);
275#endif
276
277 if (hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
Eya8a83a682020-01-29 12:42:18 +0100278 {
Ali Labbene243e61a2020-03-12 16:07:28 +0100279 hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | \
280 ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_ESCR_LSC_Pos) | \
281 ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_ESCR_LEC_Pos) | \
Eya8a83a682020-01-29 12:42:18 +0100282 ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_ESCR_FEC_Pos));
283
284 }
285
286 /* Enable the Line, Vsync, Error and Overrun interrupts */
287 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
288
289 /* Update error code */
290 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
Ali Labbene243e61a2020-03-12 16:07:28 +0100291
Eya8a83a682020-01-29 12:42:18 +0100292 /* Initialize the DCMI state*/
293 hdcmi->State = HAL_DCMI_STATE_READY;
294
295 return HAL_OK;
296}
297
298/**
299 * @brief Deinitializes the DCMI peripheral registers to their default reset
300 * values.
301 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
302 * the configuration information for DCMI.
303 * @retval HAL status
304 */
305
306HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
307{
Ali Labbene243e61a2020-03-12 16:07:28 +0100308#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
309 if (hdcmi->MspDeInitCallback == NULL)
Eya8a83a682020-01-29 12:42:18 +0100310 {
311 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
312 }
313 /* De-Initialize the low level hardware (MSP) */
314 hdcmi->MspDeInitCallback(hdcmi);
315#else
316 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
317 HAL_DCMI_MspDeInit(hdcmi);
318#endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
319
320 /* Update error code */
321 hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
322
323 /* Initialize the DCMI state*/
324 hdcmi->State = HAL_DCMI_STATE_RESET;
325
326 /* Release Lock */
327 __HAL_UNLOCK(hdcmi);
328
329 return HAL_OK;
330}
331
332/**
333 * @brief Initializes the DCMI MSP.
334 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
335 * the configuration information for DCMI.
336 * @retval None
337 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100338__weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100339{
340 /* Prevent unused argument(s) compilation warning */
341 UNUSED(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100342
Eya8a83a682020-01-29 12:42:18 +0100343 /* NOTE : This function Should not be modified, when the callback is needed,
344 the HAL_DCMI_MspInit could be implemented in the user file
Ali Labbene243e61a2020-03-12 16:07:28 +0100345 */
Eya8a83a682020-01-29 12:42:18 +0100346}
347
348/**
349 * @brief DeInitializes the DCMI MSP.
350 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
351 * the configuration information for DCMI.
352 * @retval None
353 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100354__weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100355{
356 /* Prevent unused argument(s) compilation warning */
357 UNUSED(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100358
Eya8a83a682020-01-29 12:42:18 +0100359 /* NOTE : This function Should not be modified, when the callback is needed,
360 the HAL_DCMI_MspDeInit could be implemented in the user file
361 */
362}
363
364/**
365 * @}
366 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100367/** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
Tasnim2e3aac42024-05-27 13:47:18 +0100368 * @brief IO operation functions
369 *
Ali Labbene243e61a2020-03-12 16:07:28 +0100370@verbatim
Eya8a83a682020-01-29 12:42:18 +0100371 ===============================================================================
372 ##### IO operation functions #####
Ali Labbene243e61a2020-03-12 16:07:28 +0100373 ===============================================================================
Eya8a83a682020-01-29 12:42:18 +0100374 [..] This section provides functions allowing to:
Ali Labbene243e61a2020-03-12 16:07:28 +0100375 (+) Configure destination address and data length and
Eya8a83a682020-01-29 12:42:18 +0100376 Enables DCMI DMA request and enables DCMI capture
377 (+) Stop the DCMI capture.
378 (+) Handles DCMI interrupt request.
379
380@endverbatim
381 * @{
382 */
383
384/**
Ali Labbene243e61a2020-03-12 16:07:28 +0100385 * @brief Enables DCMI DMA request and enables DCMI capture
Eya8a83a682020-01-29 12:42:18 +0100386 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
387 * the configuration information for DCMI.
388 * @param DCMI_Mode DCMI capture mode snapshot or continuous grab.
389 * @param pData The destination memory Buffer address (LCD Frame buffer).
390 * @param Length The length of capture to be transferred.
391 * @retval HAL status
392 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100393HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef *hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
394{
Tasnim2e3aac42024-05-27 13:47:18 +0100395 uint32_t tmp_length = Length;
Eya8a83a682020-01-29 12:42:18 +0100396 /* Initialize the second memory address */
Tasnim2e3aac42024-05-27 13:47:18 +0100397 uint32_t SecondMemAddress;
Eya8a83a682020-01-29 12:42:18 +0100398
399 /* Check function parameters */
400 assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
401
402 /* Process Locked */
403 __HAL_LOCK(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100404
Eya8a83a682020-01-29 12:42:18 +0100405 /* Lock the DCMI peripheral state */
406 hdcmi->State = HAL_DCMI_STATE_BUSY;
407
408 /* Enable DCMI by setting DCMIEN bit */
409 __HAL_DCMI_ENABLE(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100410
Eya8a83a682020-01-29 12:42:18 +0100411 /* Configure the DCMI Mode */
412 hdcmi->Instance->CR &= ~(DCMI_CR_CM);
Ali Labbene243e61a2020-03-12 16:07:28 +0100413 hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
Eya8a83a682020-01-29 12:42:18 +0100414
415 /* Set the DMA memory0 conversion complete callback */
416 hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
417
418 /* Set the DMA error callback */
419 hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
420
421 /* Set the dma abort callback */
422 hdcmi->DMA_Handle->XferAbortCallback = NULL;
423
Ali Labbene243e61a2020-03-12 16:07:28 +0100424 /* Reset transfer counters value */
Eya8a83a682020-01-29 12:42:18 +0100425 hdcmi->XferCount = 0;
426 hdcmi->XferTransferNumber = 0;
Ali Labbene243e61a2020-03-12 16:07:28 +0100427 hdcmi->XferSize = 0;
428 hdcmi->pBuffPtr = 0;
429
Tasnim2e3aac42024-05-27 13:47:18 +0100430 if (tmp_length <= 0xFFFFU)
Eya8a83a682020-01-29 12:42:18 +0100431 {
432 /* Enable the DMA Stream */
Tasnim2e3aac42024-05-27 13:47:18 +0100433 if (HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, tmp_length) != HAL_OK)
Ali Labbene243e61a2020-03-12 16:07:28 +0100434 {
Tasnim2e3aac42024-05-27 13:47:18 +0100435 /* Set Error Code */
436 hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA;
437 /* Change DCMI state */
438 hdcmi->State = HAL_DCMI_STATE_READY;
439 /* Release Lock */
440 __HAL_UNLOCK(hdcmi);
441 /* Return function status */
Ali Labbene243e61a2020-03-12 16:07:28 +0100442 return HAL_ERROR;
443 }
Eya8a83a682020-01-29 12:42:18 +0100444 }
445 else /* DCMI_DOUBLE_BUFFER Mode */
446 {
447 /* Set the DMA memory1 conversion complete callback */
Ali Labbene243e61a2020-03-12 16:07:28 +0100448 hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
Eya8a83a682020-01-29 12:42:18 +0100449
450 /* Initialize transfer parameters */
451 hdcmi->XferCount = 1;
Tasnim2e3aac42024-05-27 13:47:18 +0100452 hdcmi->XferSize = tmp_length;
Eya8a83a682020-01-29 12:42:18 +0100453 hdcmi->pBuffPtr = pData;
Ali Labbene243e61a2020-03-12 16:07:28 +0100454
Eya8a83a682020-01-29 12:42:18 +0100455 /* Get the number of buffer */
Ali Labbene243e61a2020-03-12 16:07:28 +0100456 while (hdcmi->XferSize > 0xFFFFU)
Eya8a83a682020-01-29 12:42:18 +0100457 {
Ali Labbene243e61a2020-03-12 16:07:28 +0100458 hdcmi->XferSize = (hdcmi->XferSize / 2U);
459 hdcmi->XferCount = hdcmi->XferCount * 2U;
Eya8a83a682020-01-29 12:42:18 +0100460 }
461
462 /* Update DCMI counter and transfer number*/
Ali Labbene243e61a2020-03-12 16:07:28 +0100463 hdcmi->XferCount = (hdcmi->XferCount - 2U);
Eya8a83a682020-01-29 12:42:18 +0100464 hdcmi->XferTransferNumber = hdcmi->XferCount;
465
466 /* Update second memory address */
Tasnim2e3aac42024-05-27 13:47:18 +0100467 SecondMemAddress = (uint32_t)(pData + (4U * hdcmi->XferSize));
Eya8a83a682020-01-29 12:42:18 +0100468
469 /* Start DMA multi buffer transfer */
Ali Labbene243e61a2020-03-12 16:07:28 +0100470 if (HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize) != HAL_OK)
471 {
Tasnim2e3aac42024-05-27 13:47:18 +0100472 /* Set Error Code */
473 hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA;
474 /* Change DCMI state */
475 hdcmi->State = HAL_DCMI_STATE_READY;
476 /* Release Lock */
477 __HAL_UNLOCK(hdcmi);
478 /* Return function status */
Ali Labbene243e61a2020-03-12 16:07:28 +0100479 return HAL_ERROR;
480 }
Eya8a83a682020-01-29 12:42:18 +0100481 }
Ali Labbene243e61a2020-03-12 16:07:28 +0100482
Eya8a83a682020-01-29 12:42:18 +0100483 /* Enable Capture */
484 hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
485
486 /* Release Lock */
487 __HAL_UNLOCK(hdcmi);
488
489 /* Return function status */
490 return HAL_OK;
491}
492
493/**
Ali Labbene243e61a2020-03-12 16:07:28 +0100494 * @brief Disable DCMI DMA request and Disable DCMI capture
Eya8a83a682020-01-29 12:42:18 +0100495 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
Ali Labbene243e61a2020-03-12 16:07:28 +0100496 * the configuration information for DCMI.
497 * @retval HAL status
Eya8a83a682020-01-29 12:42:18 +0100498 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100499HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100500{
Tasnim2e3aac42024-05-27 13:47:18 +0100501 uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U);
Eya8a83a682020-01-29 12:42:18 +0100502 HAL_StatusTypeDef status = HAL_OK;
503
504 /* Process locked */
505 __HAL_LOCK(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100506
Eya8a83a682020-01-29 12:42:18 +0100507 /* Lock the DCMI peripheral state */
508 hdcmi->State = HAL_DCMI_STATE_BUSY;
509
510 /* Disable Capture */
511 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
512
513 /* Check if the DCMI capture effectively disabled */
514 do
515 {
Tasnim2e3aac42024-05-27 13:47:18 +0100516 count-- ;
517 if (count == 0U)
Eya8a83a682020-01-29 12:42:18 +0100518 {
519 /* Update error code */
520 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
Ali Labbene243e61a2020-03-12 16:07:28 +0100521
Eya8a83a682020-01-29 12:42:18 +0100522 status = HAL_TIMEOUT;
523 break;
Ali Labbene243e61a2020-03-12 16:07:28 +0100524 }
Tasnim2e3aac42024-05-27 13:47:18 +0100525 } while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
Eya8a83a682020-01-29 12:42:18 +0100526
527 /* Disable the DCMI */
528 __HAL_DCMI_DISABLE(hdcmi);
529
530 /* Disable the DMA */
Ali Labbene243e61a2020-03-12 16:07:28 +0100531 (void)HAL_DMA_Abort(hdcmi->DMA_Handle);
Eya8a83a682020-01-29 12:42:18 +0100532
533 /* Update error code */
534 hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
535
536 /* Change DCMI state */
537 hdcmi->State = HAL_DCMI_STATE_READY;
538
539 /* Process Unlocked */
540 __HAL_UNLOCK(hdcmi);
541
542 /* Return function status */
543 return status;
544}
545
546/**
Ali Labbene243e61a2020-03-12 16:07:28 +0100547 * @brief Suspend DCMI capture
Eya8a83a682020-01-29 12:42:18 +0100548 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
Ali Labbene243e61a2020-03-12 16:07:28 +0100549 * the configuration information for DCMI.
550 * @retval HAL status
Eya8a83a682020-01-29 12:42:18 +0100551 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100552HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100553{
Tasnim2e3aac42024-05-27 13:47:18 +0100554 uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U);
Eya8a83a682020-01-29 12:42:18 +0100555 HAL_StatusTypeDef status = HAL_OK;
556
557 /* Process locked */
558 __HAL_LOCK(hdcmi);
559
Ali Labbene243e61a2020-03-12 16:07:28 +0100560 if (hdcmi->State == HAL_DCMI_STATE_BUSY)
Eya8a83a682020-01-29 12:42:18 +0100561 {
562 /* Change DCMI state */
563 hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
564
565 /* Disable Capture */
566 hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
567
568 /* Check if the DCMI capture effectively disabled */
569 do
570 {
Tasnim2e3aac42024-05-27 13:47:18 +0100571 count-- ;
572 if (count == 0U)
Ali Labbene243e61a2020-03-12 16:07:28 +0100573 {
Eya8a83a682020-01-29 12:42:18 +0100574 /* Update error code */
575 hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
Ali Labbene243e61a2020-03-12 16:07:28 +0100576
Eya8a83a682020-01-29 12:42:18 +0100577 /* Change DCMI state */
578 hdcmi->State = HAL_DCMI_STATE_READY;
Ali Labbene243e61a2020-03-12 16:07:28 +0100579
Eya8a83a682020-01-29 12:42:18 +0100580 status = HAL_TIMEOUT;
581 break;
582 }
Tasnim2e3aac42024-05-27 13:47:18 +0100583 } while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
Ali Labbene243e61a2020-03-12 16:07:28 +0100584 }
Eya8a83a682020-01-29 12:42:18 +0100585 /* Process Unlocked */
586 __HAL_UNLOCK(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100587
Eya8a83a682020-01-29 12:42:18 +0100588 /* Return function status */
589 return status;
590}
591
592/**
Ali Labbene243e61a2020-03-12 16:07:28 +0100593 * @brief Resume DCMI capture
Eya8a83a682020-01-29 12:42:18 +0100594 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
Ali Labbene243e61a2020-03-12 16:07:28 +0100595 * the configuration information for DCMI.
596 * @retval HAL status
Eya8a83a682020-01-29 12:42:18 +0100597 */
Ali Labbene243e61a2020-03-12 16:07:28 +0100598HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100599{
600 /* Process locked */
601 __HAL_LOCK(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100602
603 if (hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
Eya8a83a682020-01-29 12:42:18 +0100604 {
605 /* Change DCMI state */
606 hdcmi->State = HAL_DCMI_STATE_BUSY;
Ali Labbene243e61a2020-03-12 16:07:28 +0100607
Tasnim2e3aac42024-05-27 13:47:18 +0100608 /* Enable Capture */
Eya8a83a682020-01-29 12:42:18 +0100609 hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
Ali Labbene243e61a2020-03-12 16:07:28 +0100610 }
Eya8a83a682020-01-29 12:42:18 +0100611 /* Process Unlocked */
612 __HAL_UNLOCK(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100613
Eya8a83a682020-01-29 12:42:18 +0100614 /* Return function status */
615 return HAL_OK;
616}
617
618/**
619 * @brief Handles DCMI interrupt request.
620 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
621 * the configuration information for the DCMI.
622 * @retval None
623 */
624void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
Ali Labbene243e61a2020-03-12 16:07:28 +0100625{
Eya8a83a682020-01-29 12:42:18 +0100626 uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
Ali Labbene243e61a2020-03-12 16:07:28 +0100627
Eya8a83a682020-01-29 12:42:18 +0100628 /* Synchronization error interrupt management *******************************/
Ali Labbene243e61a2020-03-12 16:07:28 +0100629 if ((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
Eya8a83a682020-01-29 12:42:18 +0100630 {
631 /* Clear the Synchronization error flag */
632 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
Ali Labbene243e61a2020-03-12 16:07:28 +0100633
Eya8a83a682020-01-29 12:42:18 +0100634 /* Update error code */
635 hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
Ali Labbene243e61a2020-03-12 16:07:28 +0100636
Eya8a83a682020-01-29 12:42:18 +0100637 /* Change DCMI state */
638 hdcmi->State = HAL_DCMI_STATE_ERROR;
Ali Labbene243e61a2020-03-12 16:07:28 +0100639
Eya8a83a682020-01-29 12:42:18 +0100640 /* Set the synchronization error callback */
641 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
Ali Labbene243e61a2020-03-12 16:07:28 +0100642
Eya8a83a682020-01-29 12:42:18 +0100643 /* Abort the DMA Transfer */
Tasnim2e3aac42024-05-27 13:47:18 +0100644 if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
645 {
646 DCMI_DMAError(hdcmi->DMA_Handle);
647 }
Eya8a83a682020-01-29 12:42:18 +0100648 }
649 /* Overflow interrupt management ********************************************/
Ali Labbene243e61a2020-03-12 16:07:28 +0100650 if ((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
Eya8a83a682020-01-29 12:42:18 +0100651 {
652 /* Clear the Overflow flag */
653 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
Ali Labbene243e61a2020-03-12 16:07:28 +0100654
Eya8a83a682020-01-29 12:42:18 +0100655 /* Update error code */
656 hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
Ali Labbene243e61a2020-03-12 16:07:28 +0100657
Eya8a83a682020-01-29 12:42:18 +0100658 /* Change DCMI state */
659 hdcmi->State = HAL_DCMI_STATE_ERROR;
Ali Labbene243e61a2020-03-12 16:07:28 +0100660
Eya8a83a682020-01-29 12:42:18 +0100661 /* Set the overflow callback */
662 hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
Ali Labbene243e61a2020-03-12 16:07:28 +0100663
Eya8a83a682020-01-29 12:42:18 +0100664 /* Abort the DMA Transfer */
Ali Labbene243e61a2020-03-12 16:07:28 +0100665 if (HAL_DMA_Abort_IT(hdcmi->DMA_Handle) != HAL_OK)
666 {
667 DCMI_DMAError(hdcmi->DMA_Handle);
668 }
Eya8a83a682020-01-29 12:42:18 +0100669 }
670 /* Line Interrupt management ************************************************/
Ali Labbene243e61a2020-03-12 16:07:28 +0100671 if ((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
Eya8a83a682020-01-29 12:42:18 +0100672 {
Ali Labbene243e61a2020-03-12 16:07:28 +0100673 /* Clear the Line interrupt flag */
Eya8a83a682020-01-29 12:42:18 +0100674 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
Ali Labbene243e61a2020-03-12 16:07:28 +0100675
Eya8a83a682020-01-29 12:42:18 +0100676 /* Line interrupt Callback */
677#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
678 /*Call registered DCMI line event callback*/
679 hdcmi->LineEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100680#else
Eya8a83a682020-01-29 12:42:18 +0100681 HAL_DCMI_LineEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100682#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
Eya8a83a682020-01-29 12:42:18 +0100683 }
684 /* VSYNC interrupt management ***********************************************/
Ali Labbene243e61a2020-03-12 16:07:28 +0100685 if ((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
Eya8a83a682020-01-29 12:42:18 +0100686 {
687 /* Clear the VSYNC flag */
688 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
Ali Labbene243e61a2020-03-12 16:07:28 +0100689
Eya8a83a682020-01-29 12:42:18 +0100690 /* VSYNC Callback */
691#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
692 /*Call registered DCMI vsync event callback*/
693 hdcmi->VsyncEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100694#else
Eya8a83a682020-01-29 12:42:18 +0100695 HAL_DCMI_VsyncEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100696#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
Eya8a83a682020-01-29 12:42:18 +0100697 }
698 /* FRAME interrupt management ***********************************************/
Ali Labbene243e61a2020-03-12 16:07:28 +0100699 if ((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
Eya8a83a682020-01-29 12:42:18 +0100700 {
701 /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
Ali Labbene243e61a2020-03-12 16:07:28 +0100702 if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
703 {
Eya8a83a682020-01-29 12:42:18 +0100704 /* Disable the Line, Vsync, Error and Overrun interrupts */
705 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
706 }
Ali Labbene243e61a2020-03-12 16:07:28 +0100707
Eya8a83a682020-01-29 12:42:18 +0100708 /* Disable the Frame interrupt */
709 __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
Ali Labbene243e61a2020-03-12 16:07:28 +0100710
Eya8a83a682020-01-29 12:42:18 +0100711 /* Clear the End of Frame flag */
712 __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
Ali Labbene243e61a2020-03-12 16:07:28 +0100713
Eya8a83a682020-01-29 12:42:18 +0100714 /* Frame Callback */
715#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
716 /*Call registered DCMI frame event callback*/
717 hdcmi->FrameEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100718#else
Eya8a83a682020-01-29 12:42:18 +0100719 HAL_DCMI_FrameEventCallback(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100720#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
Eya8a83a682020-01-29 12:42:18 +0100721 }
722}
723
724/**
725 * @brief Error DCMI callback.
726 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
727 * the configuration information for DCMI.
728 * @retval None
729 */
730__weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
731{
732 /* Prevent unused argument(s) compilation warning */
733 UNUSED(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100734
Eya8a83a682020-01-29 12:42:18 +0100735 /* NOTE : This function Should not be modified, when the callback is needed,
736 the HAL_DCMI_ErrorCallback could be implemented in the user file
737 */
738}
739
740/**
741 * @brief Line Event callback.
742 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
743 * the configuration information for DCMI.
744 * @retval None
745 */
746__weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
747{
Tasnim2e3aac42024-05-27 13:47:18 +0100748 /* Prevent unused argument(s) compilation warning */
749 UNUSED(hdcmi);
Eya8a83a682020-01-29 12:42:18 +0100750 /* NOTE : This function Should not be modified, when the callback is needed,
751 the HAL_DCMI_LineEventCallback could be implemented in the user file
752 */
753}
754
755/**
756 * @brief VSYNC Event callback.
757 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
758 * the configuration information for DCMI.
759 * @retval None
760 */
761__weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
762{
763 /* Prevent unused argument(s) compilation warning */
764 UNUSED(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100765
Eya8a83a682020-01-29 12:42:18 +0100766 /* NOTE : This function Should not be modified, when the callback is needed,
767 the HAL_DCMI_VsyncEventCallback could be implemented in the user file
768 */
769}
770
771/**
772 * @brief Frame Event callback.
773 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
774 * the configuration information for DCMI.
775 * @retval None
776 */
777__weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
778{
779 /* Prevent unused argument(s) compilation warning */
780 UNUSED(hdcmi);
Ali Labbene243e61a2020-03-12 16:07:28 +0100781
Eya8a83a682020-01-29 12:42:18 +0100782 /* NOTE : This function Should not be modified, when the callback is needed,
783 the HAL_DCMI_FrameEventCallback could be implemented in the user file
784 */
785}
786
787/**
788 * @}
789 */
790
791/** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
Tasnim2e3aac42024-05-27 13:47:18 +0100792 * @brief Peripheral Control functions
793 *
Ali Labbene243e61a2020-03-12 16:07:28 +0100794@verbatim
Eya8a83a682020-01-29 12:42:18 +0100795 ===============================================================================
796 ##### Peripheral Control functions #####
Ali Labbene243e61a2020-03-12 16:07:28 +0100797 ===============================================================================
Eya8a83a682020-01-29 12:42:18 +0100798[..] This section provides functions allowing to:
799 (+) Configure the CROP feature.
800 (+) Enable/Disable the CROP feature.
801 (+) Set embedded synchronization delimiters unmasks.
802
803@endverbatim
804 * @{
805 */
806
807/**
808 * @brief Configure the DCMI CROP coordinate.
809 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
810 * the configuration information for DCMI.
811 * @param YSize DCMI Line number
812 * @param XSize DCMI Pixel per line
813 * @param X0 DCMI window X offset
814 * @param Y0 DCMI window Y offset
815 * @retval HAL status
816 */
Tasnim2e3aac42024-05-27 13:47:18 +0100817HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize,
818 uint32_t YSize)
Eya8a83a682020-01-29 12:42:18 +0100819{
820 /* Process Locked */
821 __HAL_LOCK(hdcmi);
822
823 /* Lock the DCMI peripheral state */
824 hdcmi->State = HAL_DCMI_STATE_BUSY;
825
826 /* Check the parameters */
827 assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
828 assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
829 assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
830 assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
Ali Labbene243e61a2020-03-12 16:07:28 +0100831
Eya8a83a682020-01-29 12:42:18 +0100832 /* Configure CROP */
833 hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_CWSIZE_VLINE_Pos));
834 hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_CWSTRT_VST_Pos));
835
836 /* Initialize the DCMI state*/
837 hdcmi->State = HAL_DCMI_STATE_READY;
838
839 /* Process Unlocked */
840 __HAL_UNLOCK(hdcmi);
841
842 return HAL_OK;
843}
844
845/**
846 * @brief Disable the Crop feature.
847 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
848 * the configuration information for DCMI.
849 * @retval HAL status
850 */
851HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
852{
853 /* Process Locked */
854 __HAL_LOCK(hdcmi);
855
856 /* Lock the DCMI peripheral state */
857 hdcmi->State = HAL_DCMI_STATE_BUSY;
858
859 /* Disable DCMI Crop feature */
Ali Labbene243e61a2020-03-12 16:07:28 +0100860 hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
Eya8a83a682020-01-29 12:42:18 +0100861
862 /* Change the DCMI state*/
Ali Labbene243e61a2020-03-12 16:07:28 +0100863 hdcmi->State = HAL_DCMI_STATE_READY;
Eya8a83a682020-01-29 12:42:18 +0100864
865 /* Process Unlocked */
866 __HAL_UNLOCK(hdcmi);
867
Ali Labbene243e61a2020-03-12 16:07:28 +0100868 return HAL_OK;
Eya8a83a682020-01-29 12:42:18 +0100869}
870
871/**
872 * @brief Enable the Crop feature.
873 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
874 * the configuration information for DCMI.
875 * @retval HAL status
876 */
877HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
878{
879 /* Process Locked */
880 __HAL_LOCK(hdcmi);
881
882 /* Lock the DCMI peripheral state */
883 hdcmi->State = HAL_DCMI_STATE_BUSY;
884
885 /* Enable DCMI Crop feature */
886 hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
887
888 /* Change the DCMI state*/
889 hdcmi->State = HAL_DCMI_STATE_READY;
890
891 /* Process Unlocked */
892 __HAL_UNLOCK(hdcmi);
893
Ali Labbene243e61a2020-03-12 16:07:28 +0100894 return HAL_OK;
895}
896
897/**
898 * @brief Set embedded synchronization delimiters unmasks.
899 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
900 * the configuration information for DCMI.
901 * @param SyncUnmask pointer to a DCMI_SyncUnmaskTypeDef structure that contains
902 * the embedded synchronization delimiters unmasks.
903 * @retval HAL status
904 */
905HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
906{
907 /* Process Locked */
908 __HAL_LOCK(hdcmi);
909
910 /* Lock the DCMI peripheral state */
911 hdcmi->State = HAL_DCMI_STATE_BUSY;
912
913 /* Write DCMI embedded synchronization unmask register */
914 hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) | \
915 ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos) | \
916 ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos) | \
917 ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
918
919 /* Change the DCMI state*/
920 hdcmi->State = HAL_DCMI_STATE_READY;
921
922 /* Process Unlocked */
923 __HAL_UNLOCK(hdcmi);
924
925 return HAL_OK;
Eya8a83a682020-01-29 12:42:18 +0100926}
927
928/**
929 * @}
930 */
931
932/** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
Tasnim2e3aac42024-05-27 13:47:18 +0100933 * @brief Peripheral State functions
934 *
Ali Labbene243e61a2020-03-12 16:07:28 +0100935@verbatim
Eya8a83a682020-01-29 12:42:18 +0100936 ===============================================================================
937 ##### Peripheral State and Errors functions #####
Ali Labbene243e61a2020-03-12 16:07:28 +0100938 ===============================================================================
Eya8a83a682020-01-29 12:42:18 +0100939 [..]
940 This subsection provides functions allowing to
941 (+) Check the DCMI state.
Ali Labbene243e61a2020-03-12 16:07:28 +0100942 (+) Get the specific DCMI error flag.
Eya8a83a682020-01-29 12:42:18 +0100943
944@endverbatim
945 * @{
Ali Labbene243e61a2020-03-12 16:07:28 +0100946 */
Eya8a83a682020-01-29 12:42:18 +0100947
948/**
949 * @brief Return the DCMI state
950 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
951 * the configuration information for DCMI.
952 * @retval HAL state
953 */
Tasnim2e3aac42024-05-27 13:47:18 +0100954HAL_DCMI_StateTypeDef HAL_DCMI_GetState(const DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100955{
956 return hdcmi->State;
957}
958
959/**
Tasnim2e3aac42024-05-27 13:47:18 +0100960 * @brief Return the DCMI error code
961 * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
Eya8a83a682020-01-29 12:42:18 +0100962 * the configuration information for DCMI.
Tasnim2e3aac42024-05-27 13:47:18 +0100963 * @retval DCMI Error Code
964 */
965uint32_t HAL_DCMI_GetError(const DCMI_HandleTypeDef *hdcmi)
Eya8a83a682020-01-29 12:42:18 +0100966{
967 return hdcmi->ErrorCode;
968}
969
970#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
971/**
Tasnim2e3aac42024-05-27 13:47:18 +0100972 * @brief Register a User DCMI Callback
973 * To be used instead of the weak predefined callback
974 * @param hdcmi DCMI handle
975 * @param CallbackID ID of the callback to be registered
976 * This parameter can be one of the following values:
977 * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID
978 * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID
979 * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID
980 * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID
981 * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID
982 * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID
983 * @param pCallback pointer to the Callback function
984 * @retval HAL status
Eya8a83a682020-01-29 12:42:18 +0100985 */
Tasnim2e3aac42024-05-27 13:47:18 +0100986HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID,
987 pDCMI_CallbackTypeDef pCallback)
Eya8a83a682020-01-29 12:42:18 +0100988{
989 HAL_StatusTypeDef status = HAL_OK;
Ali Labbene243e61a2020-03-12 16:07:28 +0100990
991 if (pCallback == NULL)
Eya8a83a682020-01-29 12:42:18 +0100992 {
993 /* update the error code */
Ali Labbene243e61a2020-03-12 16:07:28 +0100994 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
Eya8a83a682020-01-29 12:42:18 +0100995 /* update return status */
996 status = HAL_ERROR;
997 }
998 else
999 {
Ali Labbene243e61a2020-03-12 16:07:28 +01001000 if (hdcmi->State == HAL_DCMI_STATE_READY)
Eya8a83a682020-01-29 12:42:18 +01001001 {
1002 switch (CallbackID)
1003 {
Ali Labbene243e61a2020-03-12 16:07:28 +01001004 case HAL_DCMI_FRAME_EVENT_CB_ID :
1005 hdcmi->FrameEventCallback = pCallback;
1006 break;
1007
1008 case HAL_DCMI_VSYNC_EVENT_CB_ID :
1009 hdcmi->VsyncEventCallback = pCallback;
1010 break;
1011
1012 case HAL_DCMI_LINE_EVENT_CB_ID :
1013 hdcmi->LineEventCallback = pCallback;
1014 break;
1015
1016 case HAL_DCMI_ERROR_CB_ID :
1017 hdcmi->ErrorCallback = pCallback;
1018 break;
1019
1020 case HAL_DCMI_MSPINIT_CB_ID :
1021 hdcmi->MspInitCallback = pCallback;
1022 break;
1023
1024 case HAL_DCMI_MSPDEINIT_CB_ID :
1025 hdcmi->MspDeInitCallback = pCallback;
1026 break;
1027
1028 default :
1029 /* Return error status */
1030 status = HAL_ERROR;
1031 break;
Eya8a83a682020-01-29 12:42:18 +01001032 }
1033 }
Ali Labbene243e61a2020-03-12 16:07:28 +01001034 else if (hdcmi->State == HAL_DCMI_STATE_RESET)
Eya8a83a682020-01-29 12:42:18 +01001035 {
1036 switch (CallbackID)
1037 {
Ali Labbene243e61a2020-03-12 16:07:28 +01001038 case HAL_DCMI_MSPINIT_CB_ID :
1039 hdcmi->MspInitCallback = pCallback;
1040 break;
1041
1042 case HAL_DCMI_MSPDEINIT_CB_ID :
1043 hdcmi->MspDeInitCallback = pCallback;
1044 break;
1045
1046 default :
1047 /* update the error code */
1048 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1049 /* update return status */
1050 status = HAL_ERROR;
1051 break;
1052 }
1053 }
Eya8a83a682020-01-29 12:42:18 +01001054 else
1055 {
1056 /* update the error code */
1057 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1058 /* update return status */
1059 status = HAL_ERROR;
1060 }
1061 }
Ali Labbene243e61a2020-03-12 16:07:28 +01001062
Eya8a83a682020-01-29 12:42:18 +01001063 return status;
1064}
1065
1066/**
Tasnim2e3aac42024-05-27 13:47:18 +01001067 * @brief Unregister a DCMI Callback
1068 * DCMI callback is redirected to the weak predefined callback
1069 * @param hdcmi DCMI handle
1070 * @param CallbackID ID of the callback to be registered
1071 * This parameter can be one of the following values:
1072 * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID
1073 * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID
1074 * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID
1075 * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID
1076 * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID
1077 * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID
1078 * @retval HAL status
Eya8a83a682020-01-29 12:42:18 +01001079 */
1080HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
1081{
1082 HAL_StatusTypeDef status = HAL_OK;
Ali Labbene243e61a2020-03-12 16:07:28 +01001083
1084 if (hdcmi->State == HAL_DCMI_STATE_READY)
Eya8a83a682020-01-29 12:42:18 +01001085 {
1086 switch (CallbackID)
1087 {
Ali Labbene243e61a2020-03-12 16:07:28 +01001088 case HAL_DCMI_FRAME_EVENT_CB_ID :
1089 hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
1090 break;
1091
1092 case HAL_DCMI_VSYNC_EVENT_CB_ID :
Tasnim2e3aac42024-05-27 13:47:18 +01001093 hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
Ali Labbene243e61a2020-03-12 16:07:28 +01001094 break;
1095
1096 case HAL_DCMI_LINE_EVENT_CB_ID :
Tasnim2e3aac42024-05-27 13:47:18 +01001097 hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
Ali Labbene243e61a2020-03-12 16:07:28 +01001098 break;
1099
1100 case HAL_DCMI_ERROR_CB_ID :
Tasnim2e3aac42024-05-27 13:47:18 +01001101 hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
Ali Labbene243e61a2020-03-12 16:07:28 +01001102 break;
1103
1104 case HAL_DCMI_MSPINIT_CB_ID :
1105 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1106 break;
1107
1108 case HAL_DCMI_MSPDEINIT_CB_ID :
1109 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1110 break;
1111
1112 default :
1113 /* update the error code */
1114 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1115 /* update return status */
1116 status = HAL_ERROR;
1117 break;
Eya8a83a682020-01-29 12:42:18 +01001118 }
1119 }
Ali Labbene243e61a2020-03-12 16:07:28 +01001120 else if (hdcmi->State == HAL_DCMI_STATE_RESET)
Eya8a83a682020-01-29 12:42:18 +01001121 {
1122 switch (CallbackID)
1123 {
Ali Labbene243e61a2020-03-12 16:07:28 +01001124 case HAL_DCMI_MSPINIT_CB_ID :
1125 hdcmi->MspInitCallback = HAL_DCMI_MspInit;
1126 break;
1127
1128 case HAL_DCMI_MSPDEINIT_CB_ID :
1129 hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
1130 break;
1131
1132 default :
1133 /* update the error code */
1134 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1135 /* update return status */
1136 status = HAL_ERROR;
1137 break;
1138 }
1139 }
Eya8a83a682020-01-29 12:42:18 +01001140 else
1141 {
1142 /* update the error code */
1143 hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
1144 /* update return status */
1145 status = HAL_ERROR;
1146 }
Ali Labbene243e61a2020-03-12 16:07:28 +01001147
Eya8a83a682020-01-29 12:42:18 +01001148 return status;
1149}
1150#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
1151
1152/**
1153 * @}
1154 */
Tasnim2e3aac42024-05-27 13:47:18 +01001155
1156/**
1157 * @}
1158 */
1159
Eya8a83a682020-01-29 12:42:18 +01001160/* Private functions ---------------------------------------------------------*/
1161/** @defgroup DCMI_Private_Functions DCMI Private Functions
1162 * @{
1163 */
Ali Labbene243e61a2020-03-12 16:07:28 +01001164/**
Tasnim2e3aac42024-05-27 13:47:18 +01001165 * @brief DMA conversion complete callback.
1166 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1167 * the configuration information for the specified DMA module.
1168 * @retval None
1169 */
Eya8a83a682020-01-29 12:42:18 +01001170static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
1171{
Tasnim2e3aac42024-05-27 13:47:18 +01001172 uint32_t tmp ;
Eya8a83a682020-01-29 12:42:18 +01001173
Ali Labbene243e61a2020-03-12 16:07:28 +01001174 DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
Eya8a83a682020-01-29 12:42:18 +01001175
Tasnim2e3aac42024-05-27 13:47:18 +01001176 if (hdcmi->XferCount != 0U)
Eya8a83a682020-01-29 12:42:18 +01001177 {
1178 /* Update memory 0 address location */
Tasnim2e3aac42024-05-27 13:47:18 +01001179 tmp = ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR) & DMA_SxCR_CT);
1180 if (((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
Eya8a83a682020-01-29 12:42:18 +01001181 {
Tasnim2e3aac42024-05-27 13:47:18 +01001182 tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR;
1183 (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY0);
Eya8a83a682020-01-29 12:42:18 +01001184 hdcmi->XferCount--;
1185 }
1186 /* Update memory 1 address location */
Tasnim2e3aac42024-05-27 13:47:18 +01001187 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U)
Eya8a83a682020-01-29 12:42:18 +01001188 {
Tasnim2e3aac42024-05-27 13:47:18 +01001189 tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR;
1190 (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY1);
Eya8a83a682020-01-29 12:42:18 +01001191 hdcmi->XferCount--;
1192 }
Tasnim2e3aac42024-05-27 13:47:18 +01001193 else
1194 {
1195 /* Nothing to do */
1196 }
Eya8a83a682020-01-29 12:42:18 +01001197 }
1198 /* Update memory 0 address location */
Tasnim2e3aac42024-05-27 13:47:18 +01001199 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) != 0U)
Eya8a83a682020-01-29 12:42:18 +01001200 {
Tasnim2e3aac42024-05-27 13:47:18 +01001201 ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR = hdcmi->pBuffPtr;
Eya8a83a682020-01-29 12:42:18 +01001202 }
1203 /* Update memory 1 address location */
Tasnim2e3aac42024-05-27 13:47:18 +01001204 else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U)
Eya8a83a682020-01-29 12:42:18 +01001205 {
1206 tmp = hdcmi->pBuffPtr;
Tasnim2e3aac42024-05-27 13:47:18 +01001207 ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR = (tmp + (4U * hdcmi->XferSize));
Eya8a83a682020-01-29 12:42:18 +01001208 hdcmi->XferCount = hdcmi->XferTransferNumber;
1209 }
Tasnim2e3aac42024-05-27 13:47:18 +01001210 else
1211 {
1212 /* Nothing to do */
1213 }
Eya8a83a682020-01-29 12:42:18 +01001214
1215 /* Check if the frame is transferred */
Ali Labbene243e61a2020-03-12 16:07:28 +01001216 if (hdcmi->XferCount == hdcmi->XferTransferNumber)
Eya8a83a682020-01-29 12:42:18 +01001217 {
1218 /* Enable the Frame interrupt */
1219 __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
Ali Labbene243e61a2020-03-12 16:07:28 +01001220
Eya8a83a682020-01-29 12:42:18 +01001221 /* When snapshot mode, set dcmi state to ready */
Ali Labbene243e61a2020-03-12 16:07:28 +01001222 if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
1223 {
1224 hdcmi->State = HAL_DCMI_STATE_READY;
Eya8a83a682020-01-29 12:42:18 +01001225 }
Ali Labbene243e61a2020-03-12 16:07:28 +01001226 }
Eya8a83a682020-01-29 12:42:18 +01001227}
1228
1229/**
Ali Labbene243e61a2020-03-12 16:07:28 +01001230 * @brief DMA error callback
Eya8a83a682020-01-29 12:42:18 +01001231 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1232 * the configuration information for the specified DMA module.
1233 * @retval None
1234 */
1235static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
1236{
Ali Labbene243e61a2020-03-12 16:07:28 +01001237 DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
1238
1239 if (hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
Eya8a83a682020-01-29 12:42:18 +01001240 {
1241 /* Initialize the DCMI state*/
1242 hdcmi->State = HAL_DCMI_STATE_READY;
Ali Labbene243e61a2020-03-12 16:07:28 +01001243
Eya8a83a682020-01-29 12:42:18 +01001244 /* Set DCMI Error Code */
1245 hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
1246 }
1247
1248 /* DCMI error Callback */
1249#if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
Ali Labbene243e61a2020-03-12 16:07:28 +01001250 /*Call registered DCMI error callback*/
1251 hdcmi->ErrorCallback(hdcmi);
1252#else
1253 HAL_DCMI_ErrorCallback(hdcmi);
1254#endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
Eya8a83a682020-01-29 12:42:18 +01001255
1256}
1257
1258/**
1259 * @}
1260 */
Eya8a83a682020-01-29 12:42:18 +01001261#endif /* DCMI */
1262#endif /* HAL_DCMI_MODULE_ENABLED */
1263/**
1264 * @}
1265 */
1266
1267/**
1268 * @}
1269 */