You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1228 lines
39 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_dcmi.c
  4. * @author MCD Application Team
  5. * @brief DCMI HAL module driver
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Digital Camera Interface (DCMI) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Error functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### How to use this driver #####
  16. ==============================================================================
  17. [..]
  18. The sequence below describes how to use this driver to capture image
  19. from a camera module connected to the DCMI Interface.
  20. This sequence does not take into account the configuration of the
  21. camera module, which should be made before to configure and enable
  22. the DCMI to capture images.
  23. (#) Program the required configuration through following parameters:
  24. horizontal and vertical polarity, pixel clock polarity, Capture Rate,
  25. Synchronization Mode, code of the frame delimiter and data width
  26. using HAL_DCMI_Init() function.
  27. (#) Configure the selected DMA stream to transfer Data from DCMI DR
  28. register to the destination memory buffer.
  29. (#) Program the required configuration through following parameters:
  30. DCMI mode, destination memory Buffer address and the data length
  31. and enable capture using HAL_DCMI_Start_DMA() function.
  32. (#) Optionally, configure and Enable the CROP feature to select a rectangular
  33. window from the received image using HAL_DCMI_ConfigCrop()
  34. and HAL_DCMI_EnableCrop() functions
  35. (#) The capture can be stopped using HAL_DCMI_Stop() function.
  36. (#) To control DCMI state you can use the function HAL_DCMI_GetState().
  37. *** Callback registration ***
  38. =============================================
  39. The compilation flag USE_HAL_DCMI_REGISTER_CALLBACKS when set to 1
  40. allows the user to configure dynamically the driver callbacks.
  41. Use Functions HAL_DCMI_RegisterCallback() to register an interrupt callback.
  42. Function HAL_DCMI_RegisterCallback() allows to register following callbacks:
  43. (+) LineEventCallback : callback for DCMI line event.
  44. (+) FrameEventCallback : callback for DCMI Frame event.
  45. (+) VsyncEventCallback : callback for DCMI Vsync event.
  46. (+) ErrorCallback : callback for error detection.
  47. (+) MspInitCallback : callback for Msp Init.
  48. (+) MspDeInitCallback : callback for Msp DeInit.
  49. This function takes as parameters the HAL peripheral handle, the Callback ID
  50. and a pointer to the user callback function.
  51. Use function HAL_DCMI_UnRegisterCallback to reset a callback to the default weak function.
  52. HAL_DCMI_UnRegisterCallback takes as parameters the HAL peripheral handle and the Callback ID.
  53. This function allows to reset following callbacks:
  54. (+) LineEventCallback : callback for DCMI line event.
  55. (+) FrameEventCallback : callback for DCMI Frame event.
  56. (+) VsyncEventCallback : callback for DCMI Vsync event.
  57. (+) ErrorCallback : callback for error detection.
  58. (+) MspInitCallback : callback for Msp Init.
  59. (+) MspDeInitCallback : callback for Msp DeInit.
  60. By default, after the HAL_DCMI_Init() and when the state is HAL_DCMI_STATE_RESET
  61. all callbacks are set to the corresponding weak functions:
  62. examples HAL_DCMI_LineEventCallback(), HAL_DCMI_FrameEventCallback().
  63. Exception done for MspInit and MspDeInit functions that are
  64. reset to the legacy weak functions in the HAL_DCMI_Init()/ HAL_DCMI_DeInit() only when
  65. these callbacks are null (not registered beforehand).
  66. If MspInit or MspDeInit are not null, the HAL_DCMI_Init()/ HAL_DCMI_DeInit()
  67. keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
  68. Callbacks can be registered/unregistered in HAL_DCMI_STATE_READY state only.
  69. Exception done MspInit/MspDeInit functions that can be registered/unregistered
  70. in HAL_DCMI_STATE_READY or HAL_DCMI_STATE_RESET state,
  71. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  72. In that case first register the MspInit/MspDeInit user callbacks
  73. using HAL_DCMI_RegisterCallback() before calling HAL_DCMI_DeInit() or HAL_DCMI_Init() function.
  74. When the compilation flag USE_HAL_DCMI_REGISTER_CALLBACKS is set to 0 or
  75. not defined, the callback registration feature is not available and all callbacks
  76. are set to the corresponding weak functions.
  77. *** DCMI HAL driver macros list ***
  78. =============================================
  79. [..]
  80. Below the list of most used macros in DCMI HAL driver.
  81. (+) __HAL_DCMI_ENABLE: Enable the DCMI peripheral.
  82. (+) __HAL_DCMI_DISABLE: Disable the DCMI peripheral.
  83. (+) __HAL_DCMI_GET_FLAG: Get the DCMI pending flags.
  84. (+) __HAL_DCMI_CLEAR_FLAG: Clear the DCMI pending flags.
  85. (+) __HAL_DCMI_ENABLE_IT: Enable the specified DCMI interrupts.
  86. (+) __HAL_DCMI_DISABLE_IT: Disable the specified DCMI interrupts.
  87. (+) __HAL_DCMI_GET_IT_SOURCE: Check whether the specified DCMI interrupt has occurred or not.
  88. [..]
  89. (@) You can refer to the DCMI HAL driver header file for more useful macros
  90. @endverbatim
  91. ******************************************************************************
  92. * @attention
  93. *
  94. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  95. * All rights reserved.</center></h2>
  96. *
  97. * This software component is licensed by ST under BSD 3-Clause license,
  98. * the "License"; You may not use this file except in compliance with the
  99. * License. You may obtain a copy of the License at:
  100. * opensource.org/licenses/BSD-3-Clause
  101. *
  102. ******************************************************************************
  103. */
  104. /* Includes ------------------------------------------------------------------*/
  105. #include "stm32h7xx_hal.h"
  106. /** @addtogroup STM32H7xx_HAL_Driver
  107. * @{
  108. */
  109. /** @defgroup DCMI DCMI
  110. * @brief DCMI HAL module driver
  111. * @{
  112. */
  113. #ifdef HAL_DCMI_MODULE_ENABLED
  114. #if defined (DCMI)
  115. /* Private typedef -----------------------------------------------------------*/
  116. /* Private define ------------------------------------------------------------*/
  117. #define HAL_TIMEOUT_DCMI_STOP ((uint32_t)1000) /* Set timeout to 1s */
  118. /* Private macro -------------------------------------------------------------*/
  119. /* Private variables ---------------------------------------------------------*/
  120. /* Private function prototypes -----------------------------------------------*/
  121. static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma);
  122. static void DCMI_DMAError(DMA_HandleTypeDef *hdma);
  123. /* Exported functions --------------------------------------------------------*/
  124. /** @defgroup DCMI_Exported_Functions DCMI Exported Functions
  125. * @{
  126. */
  127. /** @defgroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
  128. * @brief Initialization and Configuration functions
  129. *
  130. @verbatim
  131. ===============================================================================
  132. ##### Initialization and Configuration functions #####
  133. ===============================================================================
  134. [..] This section provides functions allowing to:
  135. (+) Initialize and configure the DCMI
  136. (+) De-initialize the DCMI
  137. @endverbatim
  138. * @{
  139. */
  140. /**
  141. * @brief Initializes the DCMI according to the specified
  142. * parameters in the DCMI_InitTypeDef and create the associated handle.
  143. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  144. * the configuration information for DCMI.
  145. * @retval HAL status
  146. */
  147. HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  148. {
  149. /* Check the DCMI peripheral state */
  150. if (hdcmi == NULL)
  151. {
  152. return HAL_ERROR;
  153. }
  154. /* Check function parameters */
  155. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  156. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  157. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  158. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  159. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  160. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  161. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  162. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  163. assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
  164. assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
  165. assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
  166. assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
  167. if (hdcmi->State == HAL_DCMI_STATE_RESET)
  168. {
  169. /* Init the DCMI Callback settings */
  170. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  171. /* Reset callback pointers to the weak predefined callbacks */
  172. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  173. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  174. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  175. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  176. if (hdcmi->MspInitCallback == NULL)
  177. {
  178. /* Legacy weak MspInit Callback */
  179. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  180. }
  181. /* Initialize the low level hardware (MSP) */
  182. hdcmi->MspInitCallback(hdcmi);
  183. #else
  184. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  185. HAL_DCMI_MspInit(hdcmi);
  186. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  187. }
  188. /* Change the DCMI state */
  189. hdcmi->State = HAL_DCMI_STATE_BUSY;
  190. if (hdcmi->Init.ExtendedDataMode != DCMI_EXTEND_DATA_8B)
  191. {
  192. /* Byte select mode must be programmed to the reset value if the extended mode
  193. is not set to 8-bit data capture on every pixel clock */
  194. hdcmi->Init.ByteSelectMode = DCMI_BSM_ALL;
  195. }
  196. /* Configures the HS, VS, DE and PC polarity */
  197. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 | \
  198. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG | \
  199. DCMI_CR_ESS | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS | \
  200. DCMI_CR_LSM | DCMI_CR_OELS);
  201. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate | \
  202. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity | \
  203. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode | \
  204. hdcmi->Init.JPEGMode | hdcmi->Init.ByteSelectMode | \
  205. hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode | \
  206. hdcmi->Init.LineSelectStart);
  207. if (hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  208. {
  209. hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | \
  210. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_ESCR_LSC_Pos) | \
  211. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_ESCR_LEC_Pos) | \
  212. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_ESCR_FEC_Pos));
  213. }
  214. /* Enable the Line, Vsync, Error and Overrun interrupts */
  215. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  216. /* Update error code */
  217. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  218. /* Initialize the DCMI state*/
  219. hdcmi->State = HAL_DCMI_STATE_READY;
  220. return HAL_OK;
  221. }
  222. /**
  223. * @brief Deinitializes the DCMI peripheral registers to their default reset
  224. * values.
  225. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  226. * the configuration information for DCMI.
  227. * @retval HAL status
  228. */
  229. HAL_StatusTypeDef HAL_DCMI_DeInit(DCMI_HandleTypeDef *hdcmi)
  230. {
  231. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  232. if (hdcmi->MspDeInitCallback == NULL)
  233. {
  234. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  235. }
  236. /* De-Initialize the low level hardware (MSP) */
  237. hdcmi->MspDeInitCallback(hdcmi);
  238. #else
  239. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  240. HAL_DCMI_MspDeInit(hdcmi);
  241. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  242. /* Update error code */
  243. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  244. /* Initialize the DCMI state*/
  245. hdcmi->State = HAL_DCMI_STATE_RESET;
  246. /* Release Lock */
  247. __HAL_UNLOCK(hdcmi);
  248. return HAL_OK;
  249. }
  250. /**
  251. * @brief Initializes the DCMI MSP.
  252. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  253. * the configuration information for DCMI.
  254. * @retval None
  255. */
  256. __weak void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi)
  257. {
  258. /* Prevent unused argument(s) compilation warning */
  259. UNUSED(hdcmi);
  260. /* NOTE : This function Should not be modified, when the callback is needed,
  261. the HAL_DCMI_MspInit could be implemented in the user file
  262. */
  263. }
  264. /**
  265. * @brief DeInitializes the DCMI MSP.
  266. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  267. * the configuration information for DCMI.
  268. * @retval None
  269. */
  270. __weak void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef *hdcmi)
  271. {
  272. /* Prevent unused argument(s) compilation warning */
  273. UNUSED(hdcmi);
  274. /* NOTE : This function Should not be modified, when the callback is needed,
  275. the HAL_DCMI_MspDeInit could be implemented in the user file
  276. */
  277. }
  278. /**
  279. * @}
  280. */
  281. /** @defgroup DCMI_Exported_Functions_Group2 IO operation functions
  282. * @brief IO operation functions
  283. *
  284. @verbatim
  285. ===============================================================================
  286. ##### IO operation functions #####
  287. ===============================================================================
  288. [..] This section provides functions allowing to:
  289. (+) Configure destination address and data length and
  290. Enables DCMI DMA request and enables DCMI capture
  291. (+) Stop the DCMI capture.
  292. (+) Handles DCMI interrupt request.
  293. @endverbatim
  294. * @{
  295. */
  296. /**
  297. * @brief Enables DCMI DMA request and enables DCMI capture
  298. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  299. * the configuration information for DCMI.
  300. * @param DCMI_Mode DCMI capture mode snapshot or continuous grab.
  301. * @param pData The destination memory Buffer address (LCD Frame buffer).
  302. * @param Length The length of capture to be transferred.
  303. * @retval HAL status
  304. */
  305. HAL_StatusTypeDef HAL_DCMI_Start_DMA(DCMI_HandleTypeDef *hdcmi, uint32_t DCMI_Mode, uint32_t pData, uint32_t Length)
  306. {
  307. /* Initialize the second memory address */
  308. uint32_t SecondMemAddress;
  309. /* Check function parameters */
  310. assert_param(IS_DCMI_CAPTURE_MODE(DCMI_Mode));
  311. /* Process Locked */
  312. __HAL_LOCK(hdcmi);
  313. /* Lock the DCMI peripheral state */
  314. hdcmi->State = HAL_DCMI_STATE_BUSY;
  315. /* Enable DCMI by setting DCMIEN bit */
  316. __HAL_DCMI_ENABLE(hdcmi);
  317. /* Configure the DCMI Mode */
  318. hdcmi->Instance->CR &= ~(DCMI_CR_CM);
  319. hdcmi->Instance->CR |= (uint32_t)(DCMI_Mode);
  320. /* Set the DMA memory0 conversion complete callback */
  321. hdcmi->DMA_Handle->XferCpltCallback = DCMI_DMAXferCplt;
  322. /* Set the DMA error callback */
  323. hdcmi->DMA_Handle->XferErrorCallback = DCMI_DMAError;
  324. /* Set the dma abort callback */
  325. hdcmi->DMA_Handle->XferAbortCallback = NULL;
  326. /* Reset transfer counters value */
  327. hdcmi->XferCount = 0;
  328. hdcmi->XferTransferNumber = 0;
  329. hdcmi->XferSize = 0;
  330. hdcmi->pBuffPtr = 0;
  331. if (Length <= 0xFFFFU)
  332. {
  333. /* Enable the DMA Stream */
  334. if (HAL_DMA_Start_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, Length) != HAL_OK)
  335. {
  336. /* Set Error Code */
  337. hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA;
  338. /* Change DCMI state */
  339. hdcmi->State = HAL_DCMI_STATE_READY;
  340. /* Release Lock */
  341. __HAL_UNLOCK(hdcmi);
  342. /* Return function status */
  343. return HAL_ERROR;
  344. }
  345. }
  346. else /* DCMI_DOUBLE_BUFFER Mode */
  347. {
  348. /* Set the DMA memory1 conversion complete callback */
  349. hdcmi->DMA_Handle->XferM1CpltCallback = DCMI_DMAXferCplt;
  350. /* Initialize transfer parameters */
  351. hdcmi->XferCount = 1;
  352. hdcmi->XferSize = Length;
  353. hdcmi->pBuffPtr = pData;
  354. /* Get the number of buffer */
  355. while (hdcmi->XferSize > 0xFFFFU)
  356. {
  357. hdcmi->XferSize = (hdcmi->XferSize / 2U);
  358. hdcmi->XferCount = hdcmi->XferCount * 2U;
  359. }
  360. /* Update DCMI counter and transfer number*/
  361. hdcmi->XferCount = (hdcmi->XferCount - 2U);
  362. hdcmi->XferTransferNumber = hdcmi->XferCount;
  363. /* Update second memory address */
  364. SecondMemAddress = (uint32_t)(pData + (4U * hdcmi->XferSize));
  365. /* Start DMA multi buffer transfer */
  366. if (HAL_DMAEx_MultiBufferStart_IT(hdcmi->DMA_Handle, (uint32_t)&hdcmi->Instance->DR, (uint32_t)pData, SecondMemAddress, hdcmi->XferSize) != HAL_OK)
  367. {
  368. /* Set Error Code */
  369. hdcmi->ErrorCode = HAL_DCMI_ERROR_DMA;
  370. /* Change DCMI state */
  371. hdcmi->State = HAL_DCMI_STATE_READY;
  372. /* Release Lock */
  373. __HAL_UNLOCK(hdcmi);
  374. /* Return function status */
  375. return HAL_ERROR;
  376. }
  377. }
  378. /* Enable Capture */
  379. hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
  380. /* Release Lock */
  381. __HAL_UNLOCK(hdcmi);
  382. /* Return function status */
  383. return HAL_OK;
  384. }
  385. /**
  386. * @brief Disable DCMI DMA request and Disable DCMI capture
  387. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  388. * the configuration information for DCMI.
  389. * @retval HAL status
  390. */
  391. HAL_StatusTypeDef HAL_DCMI_Stop(DCMI_HandleTypeDef *hdcmi)
  392. {
  393. register uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U);
  394. HAL_StatusTypeDef status = HAL_OK;
  395. /* Process locked */
  396. __HAL_LOCK(hdcmi);
  397. /* Lock the DCMI peripheral state */
  398. hdcmi->State = HAL_DCMI_STATE_BUSY;
  399. /* Disable Capture */
  400. hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
  401. /* Check if the DCMI capture effectively disabled */
  402. do
  403. {
  404. count-- ;
  405. if (count == 0U)
  406. {
  407. /* Update error code */
  408. hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
  409. status = HAL_TIMEOUT;
  410. break;
  411. }
  412. }
  413. while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
  414. /* Disable the DCMI */
  415. __HAL_DCMI_DISABLE(hdcmi);
  416. /* Disable the DMA */
  417. (void)HAL_DMA_Abort(hdcmi->DMA_Handle);
  418. /* Update error code */
  419. hdcmi->ErrorCode |= HAL_DCMI_ERROR_NONE;
  420. /* Change DCMI state */
  421. hdcmi->State = HAL_DCMI_STATE_READY;
  422. /* Process Unlocked */
  423. __HAL_UNLOCK(hdcmi);
  424. /* Return function status */
  425. return status;
  426. }
  427. /**
  428. * @brief Suspend DCMI capture
  429. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  430. * the configuration information for DCMI.
  431. * @retval HAL status
  432. */
  433. HAL_StatusTypeDef HAL_DCMI_Suspend(DCMI_HandleTypeDef *hdcmi)
  434. {
  435. register uint32_t count = HAL_TIMEOUT_DCMI_STOP * (SystemCoreClock / 8U / 1000U);
  436. HAL_StatusTypeDef status = HAL_OK;
  437. /* Process locked */
  438. __HAL_LOCK(hdcmi);
  439. if (hdcmi->State == HAL_DCMI_STATE_BUSY)
  440. {
  441. /* Change DCMI state */
  442. hdcmi->State = HAL_DCMI_STATE_SUSPENDED;
  443. /* Disable Capture */
  444. hdcmi->Instance->CR &= ~(DCMI_CR_CAPTURE);
  445. /* Check if the DCMI capture effectively disabled */
  446. do
  447. {
  448. count-- ;
  449. if (count == 0U)
  450. {
  451. /* Update error code */
  452. hdcmi->ErrorCode |= HAL_DCMI_ERROR_TIMEOUT;
  453. /* Change DCMI state */
  454. hdcmi->State = HAL_DCMI_STATE_READY;
  455. status = HAL_TIMEOUT;
  456. break;
  457. }
  458. }
  459. while ((hdcmi->Instance->CR & DCMI_CR_CAPTURE) != 0U);
  460. }
  461. /* Process Unlocked */
  462. __HAL_UNLOCK(hdcmi);
  463. /* Return function status */
  464. return status;
  465. }
  466. /**
  467. * @brief Resume DCMI capture
  468. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  469. * the configuration information for DCMI.
  470. * @retval HAL status
  471. */
  472. HAL_StatusTypeDef HAL_DCMI_Resume(DCMI_HandleTypeDef *hdcmi)
  473. {
  474. /* Process locked */
  475. __HAL_LOCK(hdcmi);
  476. if (hdcmi->State == HAL_DCMI_STATE_SUSPENDED)
  477. {
  478. /* Change DCMI state */
  479. hdcmi->State = HAL_DCMI_STATE_BUSY;
  480. /* Disable Capture */
  481. hdcmi->Instance->CR |= DCMI_CR_CAPTURE;
  482. }
  483. /* Process Unlocked */
  484. __HAL_UNLOCK(hdcmi);
  485. /* Return function status */
  486. return HAL_OK;
  487. }
  488. /**
  489. * @brief Handles DCMI interrupt request.
  490. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  491. * the configuration information for the DCMI.
  492. * @retval None
  493. */
  494. void HAL_DCMI_IRQHandler(DCMI_HandleTypeDef *hdcmi)
  495. {
  496. uint32_t isr_value = READ_REG(hdcmi->Instance->MISR);
  497. /* Synchronization error interrupt management *******************************/
  498. if ((isr_value & DCMI_FLAG_ERRRI) == DCMI_FLAG_ERRRI)
  499. {
  500. /* Clear the Synchronization error flag */
  501. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_ERRRI);
  502. /* Update error code */
  503. hdcmi->ErrorCode |= HAL_DCMI_ERROR_SYNC;
  504. /* Change DCMI state */
  505. hdcmi->State = HAL_DCMI_STATE_ERROR;
  506. /* Set the synchronization error callback */
  507. hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
  508. /* Abort the DMA Transfer */
  509. (void)HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
  510. }
  511. /* Overflow interrupt management ********************************************/
  512. if ((isr_value & DCMI_FLAG_OVRRI) == DCMI_FLAG_OVRRI)
  513. {
  514. /* Clear the Overflow flag */
  515. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_OVRRI);
  516. /* Update error code */
  517. hdcmi->ErrorCode |= HAL_DCMI_ERROR_OVR;
  518. /* Change DCMI state */
  519. hdcmi->State = HAL_DCMI_STATE_ERROR;
  520. /* Set the overflow callback */
  521. hdcmi->DMA_Handle->XferAbortCallback = DCMI_DMAError;
  522. /* Abort the DMA Transfer */
  523. (void)HAL_DMA_Abort_IT(hdcmi->DMA_Handle);
  524. }
  525. /* Line Interrupt management ************************************************/
  526. if ((isr_value & DCMI_FLAG_LINERI) == DCMI_FLAG_LINERI)
  527. {
  528. /* Clear the Line interrupt flag */
  529. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_LINERI);
  530. /* Line interrupt Callback */
  531. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  532. /*Call registered DCMI line event callback*/
  533. hdcmi->LineEventCallback(hdcmi);
  534. #else
  535. HAL_DCMI_LineEventCallback(hdcmi);
  536. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  537. }
  538. /* VSYNC interrupt management ***********************************************/
  539. if ((isr_value & DCMI_FLAG_VSYNCRI) == DCMI_FLAG_VSYNCRI)
  540. {
  541. /* Clear the VSYNC flag */
  542. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_VSYNCRI);
  543. /* VSYNC Callback */
  544. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  545. /*Call registered DCMI vsync event callback*/
  546. hdcmi->VsyncEventCallback(hdcmi);
  547. #else
  548. HAL_DCMI_VsyncEventCallback(hdcmi);
  549. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  550. }
  551. /* FRAME interrupt management ***********************************************/
  552. if ((isr_value & DCMI_FLAG_FRAMERI) == DCMI_FLAG_FRAMERI)
  553. {
  554. /* When snapshot mode, disable Vsync, Error and Overrun interrupts */
  555. if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
  556. {
  557. /* Disable the Line, Vsync, Error and Overrun interrupts */
  558. __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  559. }
  560. /* Disable the Frame interrupt */
  561. __HAL_DCMI_DISABLE_IT(hdcmi, DCMI_IT_FRAME);
  562. /* Clear the End of Frame flag */
  563. __HAL_DCMI_CLEAR_FLAG(hdcmi, DCMI_FLAG_FRAMERI);
  564. /* Frame Callback */
  565. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  566. /*Call registered DCMI frame event callback*/
  567. hdcmi->FrameEventCallback(hdcmi);
  568. #else
  569. HAL_DCMI_FrameEventCallback(hdcmi);
  570. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  571. }
  572. }
  573. /**
  574. * @brief Error DCMI callback.
  575. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  576. * the configuration information for DCMI.
  577. * @retval None
  578. */
  579. __weak void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi)
  580. {
  581. /* Prevent unused argument(s) compilation warning */
  582. UNUSED(hdcmi);
  583. /* NOTE : This function Should not be modified, when the callback is needed,
  584. the HAL_DCMI_ErrorCallback could be implemented in the user file
  585. */
  586. }
  587. /**
  588. * @brief Line Event callback.
  589. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  590. * the configuration information for DCMI.
  591. * @retval None
  592. */
  593. __weak void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi)
  594. {
  595. /* Prevent unused argument(s) compilation warning */
  596. UNUSED(hdcmi);
  597. /* NOTE : This function Should not be modified, when the callback is needed,
  598. the HAL_DCMI_LineEventCallback could be implemented in the user file
  599. */
  600. }
  601. /**
  602. * @brief VSYNC Event callback.
  603. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  604. * the configuration information for DCMI.
  605. * @retval None
  606. */
  607. __weak void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi)
  608. {
  609. /* Prevent unused argument(s) compilation warning */
  610. UNUSED(hdcmi);
  611. /* NOTE : This function Should not be modified, when the callback is needed,
  612. the HAL_DCMI_VsyncEventCallback could be implemented in the user file
  613. */
  614. }
  615. /**
  616. * @brief Frame Event callback.
  617. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  618. * the configuration information for DCMI.
  619. * @retval None
  620. */
  621. __weak void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
  622. {
  623. /* Prevent unused argument(s) compilation warning */
  624. UNUSED(hdcmi);
  625. /* NOTE : This function Should not be modified, when the callback is needed,
  626. the HAL_DCMI_FrameEventCallback could be implemented in the user file
  627. */
  628. }
  629. /**
  630. * @}
  631. */
  632. /** @defgroup DCMI_Exported_Functions_Group3 Peripheral Control functions
  633. * @brief Peripheral Control functions
  634. *
  635. @verbatim
  636. ===============================================================================
  637. ##### Peripheral Control functions #####
  638. ===============================================================================
  639. [..] This section provides functions allowing to:
  640. (+) Configure the CROP feature.
  641. (+) Enable/Disable the CROP feature.
  642. (+) Set embedded synchronization delimiters unmasks.
  643. @endverbatim
  644. * @{
  645. */
  646. /**
  647. * @brief Configure the DCMI CROP coordinate.
  648. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  649. * the configuration information for DCMI.
  650. * @param YSize DCMI Line number
  651. * @param XSize DCMI Pixel per line
  652. * @param X0 DCMI window X offset
  653. * @param Y0 DCMI window Y offset
  654. * @retval HAL status
  655. */
  656. HAL_StatusTypeDef HAL_DCMI_ConfigCrop(DCMI_HandleTypeDef *hdcmi, uint32_t X0, uint32_t Y0, uint32_t XSize, uint32_t YSize)
  657. {
  658. /* Process Locked */
  659. __HAL_LOCK(hdcmi);
  660. /* Lock the DCMI peripheral state */
  661. hdcmi->State = HAL_DCMI_STATE_BUSY;
  662. /* Check the parameters */
  663. assert_param(IS_DCMI_WINDOW_COORDINATE(X0));
  664. assert_param(IS_DCMI_WINDOW_HEIGHT(Y0));
  665. assert_param(IS_DCMI_WINDOW_COORDINATE(XSize));
  666. assert_param(IS_DCMI_WINDOW_COORDINATE(YSize));
  667. /* Configure CROP */
  668. hdcmi->Instance->CWSIZER = (XSize | (YSize << DCMI_CWSIZE_VLINE_Pos));
  669. hdcmi->Instance->CWSTRTR = (X0 | (Y0 << DCMI_CWSTRT_VST_Pos));
  670. /* Initialize the DCMI state*/
  671. hdcmi->State = HAL_DCMI_STATE_READY;
  672. /* Process Unlocked */
  673. __HAL_UNLOCK(hdcmi);
  674. return HAL_OK;
  675. }
  676. /**
  677. * @brief Disable the Crop feature.
  678. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  679. * the configuration information for DCMI.
  680. * @retval HAL status
  681. */
  682. HAL_StatusTypeDef HAL_DCMI_DisableCrop(DCMI_HandleTypeDef *hdcmi)
  683. {
  684. /* Process Locked */
  685. __HAL_LOCK(hdcmi);
  686. /* Lock the DCMI peripheral state */
  687. hdcmi->State = HAL_DCMI_STATE_BUSY;
  688. /* Disable DCMI Crop feature */
  689. hdcmi->Instance->CR &= ~(uint32_t)DCMI_CR_CROP;
  690. /* Change the DCMI state*/
  691. hdcmi->State = HAL_DCMI_STATE_READY;
  692. /* Process Unlocked */
  693. __HAL_UNLOCK(hdcmi);
  694. return HAL_OK;
  695. }
  696. /**
  697. * @brief Enable the Crop feature.
  698. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  699. * the configuration information for DCMI.
  700. * @retval HAL status
  701. */
  702. HAL_StatusTypeDef HAL_DCMI_EnableCrop(DCMI_HandleTypeDef *hdcmi)
  703. {
  704. /* Process Locked */
  705. __HAL_LOCK(hdcmi);
  706. /* Lock the DCMI peripheral state */
  707. hdcmi->State = HAL_DCMI_STATE_BUSY;
  708. /* Enable DCMI Crop feature */
  709. hdcmi->Instance->CR |= (uint32_t)DCMI_CR_CROP;
  710. /* Change the DCMI state*/
  711. hdcmi->State = HAL_DCMI_STATE_READY;
  712. /* Process Unlocked */
  713. __HAL_UNLOCK(hdcmi);
  714. return HAL_OK;
  715. }
  716. /**
  717. * @brief Set embedded synchronization delimiters unmasks.
  718. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  719. * the configuration information for DCMI.
  720. * @param SyncUnmask pointer to a DCMI_SyncUnmaskTypeDef structure that contains
  721. * the embedded synchronization delimiters unmasks.
  722. * @retval HAL status
  723. */
  724. HAL_StatusTypeDef HAL_DCMI_ConfigSyncUnmask(DCMI_HandleTypeDef *hdcmi, DCMI_SyncUnmaskTypeDef *SyncUnmask)
  725. {
  726. /* Process Locked */
  727. __HAL_LOCK(hdcmi);
  728. /* Lock the DCMI peripheral state */
  729. hdcmi->State = HAL_DCMI_STATE_BUSY;
  730. /* Write DCMI embedded synchronization unmask register */
  731. hdcmi->Instance->ESUR = (((uint32_t)SyncUnmask->FrameStartUnmask) | \
  732. ((uint32_t)SyncUnmask->LineStartUnmask << DCMI_ESUR_LSU_Pos) | \
  733. ((uint32_t)SyncUnmask->LineEndUnmask << DCMI_ESUR_LEU_Pos) | \
  734. ((uint32_t)SyncUnmask->FrameEndUnmask << DCMI_ESUR_FEU_Pos));
  735. /* Change the DCMI state*/
  736. hdcmi->State = HAL_DCMI_STATE_READY;
  737. /* Process Unlocked */
  738. __HAL_UNLOCK(hdcmi);
  739. return HAL_OK;
  740. }
  741. /**
  742. * @}
  743. */
  744. /** @defgroup DCMI_Exported_Functions_Group4 Peripheral State functions
  745. * @brief Peripheral State functions
  746. *
  747. @verbatim
  748. ===============================================================================
  749. ##### Peripheral State and Errors functions #####
  750. ===============================================================================
  751. [..]
  752. This subsection provides functions allowing to
  753. (+) Check the DCMI state.
  754. (+) Get the specific DCMI error flag.
  755. @endverbatim
  756. * @{
  757. */
  758. /**
  759. * @brief Return the DCMI state
  760. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  761. * the configuration information for DCMI.
  762. * @retval HAL state
  763. */
  764. HAL_DCMI_StateTypeDef HAL_DCMI_GetState(DCMI_HandleTypeDef *hdcmi)
  765. {
  766. return hdcmi->State;
  767. }
  768. /**
  769. * @brief Return the DCMI error code
  770. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  771. * the configuration information for DCMI.
  772. * @retval DCMI Error Code
  773. */
  774. uint32_t HAL_DCMI_GetError(DCMI_HandleTypeDef *hdcmi)
  775. {
  776. return hdcmi->ErrorCode;
  777. }
  778. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  779. /**
  780. * @brief Register a User DCMI Callback
  781. * To be used instead of the weak predefined callback
  782. * @param hdcmi DCMI handle
  783. * @param CallbackID ID of the callback to be registered
  784. * This parameter can be one of the following values:
  785. * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID
  786. * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID
  787. * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID
  788. * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID
  789. * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID
  790. * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID
  791. * @param pCallback pointer to the Callback function
  792. * @retval HAL status
  793. */
  794. HAL_StatusTypeDef HAL_DCMI_RegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID, pDCMI_CallbackTypeDef pCallback)
  795. {
  796. HAL_StatusTypeDef status = HAL_OK;
  797. if (pCallback == NULL)
  798. {
  799. /* update the error code */
  800. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  801. /* update return status */
  802. status = HAL_ERROR;
  803. }
  804. else
  805. {
  806. if (hdcmi->State == HAL_DCMI_STATE_READY)
  807. {
  808. switch (CallbackID)
  809. {
  810. case HAL_DCMI_FRAME_EVENT_CB_ID :
  811. hdcmi->FrameEventCallback = pCallback;
  812. break;
  813. case HAL_DCMI_VSYNC_EVENT_CB_ID :
  814. hdcmi->VsyncEventCallback = pCallback;
  815. break;
  816. case HAL_DCMI_LINE_EVENT_CB_ID :
  817. hdcmi->LineEventCallback = pCallback;
  818. break;
  819. case HAL_DCMI_ERROR_CB_ID :
  820. hdcmi->ErrorCallback = pCallback;
  821. break;
  822. case HAL_DCMI_MSPINIT_CB_ID :
  823. hdcmi->MspInitCallback = pCallback;
  824. break;
  825. case HAL_DCMI_MSPDEINIT_CB_ID :
  826. hdcmi->MspDeInitCallback = pCallback;
  827. break;
  828. default :
  829. /* Return error status */
  830. status = HAL_ERROR;
  831. break;
  832. }
  833. }
  834. else if (hdcmi->State == HAL_DCMI_STATE_RESET)
  835. {
  836. switch (CallbackID)
  837. {
  838. case HAL_DCMI_MSPINIT_CB_ID :
  839. hdcmi->MspInitCallback = pCallback;
  840. break;
  841. case HAL_DCMI_MSPDEINIT_CB_ID :
  842. hdcmi->MspDeInitCallback = pCallback;
  843. break;
  844. default :
  845. /* update the error code */
  846. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  847. /* update return status */
  848. status = HAL_ERROR;
  849. break;
  850. }
  851. }
  852. else
  853. {
  854. /* update the error code */
  855. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  856. /* update return status */
  857. status = HAL_ERROR;
  858. }
  859. }
  860. return status;
  861. }
  862. /**
  863. * @brief Unregister a DCMI Callback
  864. * DCMI callabck is redirected to the weak predefined callback
  865. * @param hdcmi DCMI handle
  866. * @param CallbackID ID of the callback to be registered
  867. * This parameter can be one of the following values:
  868. * @arg @ref HAL_DCMI_LINE_EVENT_CB_ID Line Event callback ID
  869. * @arg @ref HAL_DCMI_FRAME_EVENT_CB_ID Frame Event callback ID
  870. * @arg @ref HAL_DCMI_VSYNC_EVENT_CB_ID Vsync Event callback ID
  871. * @arg @ref HAL_DCMI_ERROR_CB_ID Error callback ID
  872. * @arg @ref HAL_DCMI_MSPINIT_CB_ID MspInit callback ID
  873. * @arg @ref HAL_DCMI_MSPDEINIT_CB_ID MspDeInit callback ID
  874. * @retval HAL status
  875. */
  876. HAL_StatusTypeDef HAL_DCMI_UnRegisterCallback(DCMI_HandleTypeDef *hdcmi, HAL_DCMI_CallbackIDTypeDef CallbackID)
  877. {
  878. HAL_StatusTypeDef status = HAL_OK;
  879. if (hdcmi->State == HAL_DCMI_STATE_READY)
  880. {
  881. switch (CallbackID)
  882. {
  883. case HAL_DCMI_FRAME_EVENT_CB_ID :
  884. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  885. break;
  886. case HAL_DCMI_VSYNC_EVENT_CB_ID :
  887. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  888. break;
  889. case HAL_DCMI_LINE_EVENT_CB_ID :
  890. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  891. break;
  892. case HAL_DCMI_ERROR_CB_ID :
  893. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  894. break;
  895. case HAL_DCMI_MSPINIT_CB_ID :
  896. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  897. break;
  898. case HAL_DCMI_MSPDEINIT_CB_ID :
  899. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  900. break;
  901. default :
  902. /* update the error code */
  903. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  904. /* update return status */
  905. status = HAL_ERROR;
  906. break;
  907. }
  908. }
  909. else if (hdcmi->State == HAL_DCMI_STATE_RESET)
  910. {
  911. switch (CallbackID)
  912. {
  913. case HAL_DCMI_MSPINIT_CB_ID :
  914. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  915. break;
  916. case HAL_DCMI_MSPDEINIT_CB_ID :
  917. hdcmi->MspDeInitCallback = HAL_DCMI_MspDeInit;
  918. break;
  919. default :
  920. /* update the error code */
  921. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  922. /* update return status */
  923. status = HAL_ERROR;
  924. break;
  925. }
  926. }
  927. else
  928. {
  929. /* update the error code */
  930. hdcmi->ErrorCode |= HAL_DCMI_ERROR_INVALID_CALLBACK;
  931. /* update return status */
  932. status = HAL_ERROR;
  933. }
  934. return status;
  935. }
  936. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  937. /**
  938. * @}
  939. */
  940. /* Private functions ---------------------------------------------------------*/
  941. /** @defgroup DCMI_Private_Functions DCMI Private Functions
  942. * @{
  943. */
  944. /**
  945. * @brief DMA conversion complete callback.
  946. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  947. * the configuration information for the specified DMA module.
  948. * @retval None
  949. */
  950. static void DCMI_DMAXferCplt(DMA_HandleTypeDef *hdma)
  951. {
  952. uint32_t tmp ;
  953. DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  954. if (hdcmi->XferCount != 0U)
  955. {
  956. /* Update memory 0 address location */
  957. tmp = ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR) & DMA_SxCR_CT);
  958. if (((hdcmi->XferCount % 2U) == 0U) && (tmp != 0U))
  959. {
  960. tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR;
  961. (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY0);
  962. hdcmi->XferCount--;
  963. }
  964. /* Update memory 1 address location */
  965. else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U)
  966. {
  967. tmp = ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR;
  968. (void)HAL_DMAEx_ChangeMemory(hdcmi->DMA_Handle, (tmp + (8U * hdcmi->XferSize)), MEMORY1);
  969. hdcmi->XferCount--;
  970. }
  971. else
  972. {
  973. /* Nothing to do */
  974. }
  975. }
  976. /* Update memory 0 address location */
  977. else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) != 0U)
  978. {
  979. ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M0AR = hdcmi->pBuffPtr;
  980. }
  981. /* Update memory 1 address location */
  982. else if ((((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->CR & DMA_SxCR_CT) == 0U)
  983. {
  984. tmp = hdcmi->pBuffPtr;
  985. ((DMA_Stream_TypeDef *)(hdcmi->DMA_Handle->Instance))->M1AR = (tmp + (4U * hdcmi->XferSize));
  986. hdcmi->XferCount = hdcmi->XferTransferNumber;
  987. }
  988. else
  989. {
  990. /* Nothing to do */
  991. }
  992. /* Check if the frame is transferred */
  993. if (hdcmi->XferCount == hdcmi->XferTransferNumber)
  994. {
  995. /* Enable the Frame interrupt */
  996. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
  997. /* When snapshot mode, set dcmi state to ready */
  998. if ((hdcmi->Instance->CR & DCMI_CR_CM) == DCMI_MODE_SNAPSHOT)
  999. {
  1000. hdcmi->State = HAL_DCMI_STATE_READY;
  1001. }
  1002. }
  1003. }
  1004. /**
  1005. * @brief DMA error callback
  1006. * @param hdma pointer to a DMA_HandleTypeDef structure that contains
  1007. * the configuration information for the specified DMA module.
  1008. * @retval None
  1009. */
  1010. static void DCMI_DMAError(DMA_HandleTypeDef *hdma)
  1011. {
  1012. DCMI_HandleTypeDef *hdcmi = (DCMI_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
  1013. if (hdcmi->DMA_Handle->ErrorCode != HAL_DMA_ERROR_FE)
  1014. {
  1015. /* Initialize the DCMI state*/
  1016. hdcmi->State = HAL_DCMI_STATE_READY;
  1017. /* Set DCMI Error Code */
  1018. hdcmi->ErrorCode |= HAL_DCMI_ERROR_DMA;
  1019. }
  1020. /* DCMI error Callback */
  1021. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  1022. /*Call registered DCMI error callback*/
  1023. hdcmi->ErrorCallback(hdcmi);
  1024. #else
  1025. HAL_DCMI_ErrorCallback(hdcmi);
  1026. #endif /* USE_HAL_DCMI_REGISTER_CALLBACKS */
  1027. }
  1028. /**
  1029. * @}
  1030. */
  1031. /**
  1032. * @}
  1033. */
  1034. #endif /* DCMI */
  1035. #endif /* HAL_DCMI_MODULE_ENABLED */
  1036. /**
  1037. * @}
  1038. */
  1039. /**
  1040. * @}
  1041. */
  1042. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/