stm32f4xx_hal_dcmi_ex.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dcmi_ex.c
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 09-March-2015
  7. * @brief DCMI Extension HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of DCMI extension peripheral:
  10. * + Extension features functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### DCMI peripheral extension features #####
  15. ==============================================================================
  16. [..] Comparing to other previous devices, the DCMI interface for STM32F446xx
  17. devices contains the following additional features :
  18. (+) Support of Black and White cameras
  19. ##### How to use this driver #####
  20. ==============================================================================
  21. [..] This driver provides functions to manage the Black and White feature
  22. @endverbatim
  23. ******************************************************************************
  24. * @attention
  25. *
  26. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  27. *
  28. * Redistribution and use in source and binary forms, with or without modification,
  29. * are permitted provided that the following conditions are met:
  30. * 1. Redistributions of source code must retain the above copyright notice,
  31. * this list of conditions and the following disclaimer.
  32. * 2. Redistributions in binary form must reproduce the above copyright notice,
  33. * this list of conditions and the following disclaimer in the documentation
  34. * and/or other materials provided with the distribution.
  35. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  36. * may be used to endorse or promote products derived from this software
  37. * without specific prior written permission.
  38. *
  39. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  40. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  41. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  42. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  43. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  44. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  45. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  46. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  47. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. ******************************************************************************
  51. */
  52. /* Includes ------------------------------------------------------------------*/
  53. #include "stm32f4xx_hal.h"
  54. /** @addtogroup STM32F4xx_HAL_Driver
  55. * @{
  56. */
  57. /** @defgroup DCMI DCMI
  58. * @brief DCMI HAL module driver
  59. * @{
  60. */
  61. #ifdef HAL_DCMI_MODULE_ENABLED
  62. #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx)
  63. /* Private typedef -----------------------------------------------------------*/
  64. /* Private define ------------------------------------------------------------*/
  65. /* Private macro -------------------------------------------------------------*/
  66. /* Private variables ---------------------------------------------------------*/
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* Exported functions --------------------------------------------------------*/
  69. /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
  70. * @{
  71. */
  72. /** @defgroup DCMIEx_Exported_Functions_Group1 Initialization and Configuration functions
  73. * @brief Initialization and Configuration functions
  74. *
  75. @verbatim
  76. ===============================================================================
  77. ##### Initialization and Configuration functions #####
  78. ===============================================================================
  79. [..] This section provides functions allowing to:
  80. (+) Initialize and configure the DCMI
  81. (+) De-initialize the DCMI
  82. @endverbatim
  83. * @{
  84. */
  85. /**
  86. * @brief Initializes the DCMI according to the specified
  87. * parameters in the DCMI_InitTypeDef and create the associated handle.
  88. * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
  89. * the configuration information for DCMI.
  90. * @retval HAL status
  91. */
  92. HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  93. {
  94. /* Check the DCMI peripheral state */
  95. if(hdcmi == NULL)
  96. {
  97. return HAL_ERROR;
  98. }
  99. /* Check function parameters */
  100. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  101. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  102. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  103. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  104. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  105. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  106. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  107. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  108. #if defined(STM32F446xx)
  109. assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
  110. assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
  111. assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
  112. assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
  113. #endif
  114. if(hdcmi->State == HAL_DCMI_STATE_RESET)
  115. {
  116. /* Init the low level hardware */
  117. HAL_DCMI_MspInit(hdcmi);
  118. }
  119. /* Change the DCMI state */
  120. hdcmi->State = HAL_DCMI_STATE_BUSY;
  121. /* Configures the HS, VS, DE and PC polarity */
  122. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
  123. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
  124. DCMI_CR_ESS
  125. #if defined(STM32F446xx)
  126. | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
  127. DCMI_CR_LSM | DCMI_CR_OELS
  128. #endif
  129. );
  130. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
  131. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
  132. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
  133. hdcmi->Init.JPEGMode
  134. #if defined(STM32F446xx)
  135. | hdcmi->Init.ByteSelectMode |\
  136. hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
  137. hdcmi->Init.LineSelectStart
  138. #endif
  139. );
  140. if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  141. {
  142. DCMI->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
  143. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << 8)|
  144. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << 16) |
  145. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << 24));
  146. }
  147. /* Enable the Line interrupt */
  148. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE);
  149. /* Enable the VSYNC interrupt */
  150. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_VSYNC);
  151. /* Enable the Frame capture complete interrupt */
  152. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_FRAME);
  153. /* Enable the Synchronization error interrupt */
  154. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_ERR);
  155. /* Enable the Overflow interrupt */
  156. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_OVF);
  157. /* Enable DCMI by setting DCMIEN bit */
  158. __HAL_DCMI_ENABLE(hdcmi);
  159. /* Update error code */
  160. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  161. /* Initialize the DCMI state*/
  162. hdcmi->State = HAL_DCMI_STATE_READY;
  163. return HAL_OK;
  164. }
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx */
  175. #endif /* HAL_DCMI_MODULE_ENABLED */
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/