stm32f7xx_hal_dcmi.c 26 KB

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