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.
 
 
 

184 lines
7.9 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_dcmi_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  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) 2017 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 DCMIEx DCMIEx
  58. * @brief DCMI Extended HAL module driver
  59. * @{
  60. */
  61. #ifdef HAL_DCMI_MODULE_ENABLED
  62. #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\
  63. defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  64. /* Private typedef -----------------------------------------------------------*/
  65. /* Private define ------------------------------------------------------------*/
  66. /* Private macro -------------------------------------------------------------*/
  67. /* Private variables ---------------------------------------------------------*/
  68. /* Private function prototypes -----------------------------------------------*/
  69. /* Exported functions --------------------------------------------------------*/
  70. /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
  71. * @{
  72. */
  73. /**
  74. * @}
  75. */
  76. /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
  77. * @{
  78. */
  79. /**
  80. * @brief Initializes the DCMI according to the specified
  81. * parameters in the DCMI_InitTypeDef and create the associated handle.
  82. * @param hdcmi: pointer to a DCMI_HandleTypeDef structure that contains
  83. * the configuration information for DCMI.
  84. * @retval HAL status
  85. */
  86. HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  87. {
  88. /* Check the DCMI peripheral state */
  89. if(hdcmi == NULL)
  90. {
  91. return HAL_ERROR;
  92. }
  93. /* Check function parameters */
  94. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  95. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  96. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  97. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  98. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  99. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  100. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  101. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  102. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  103. assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
  104. assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
  105. assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
  106. assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
  107. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  108. if(hdcmi->State == HAL_DCMI_STATE_RESET)
  109. {
  110. /* Init the low level hardware */
  111. HAL_DCMI_MspInit(hdcmi);
  112. }
  113. /* Change the DCMI state */
  114. hdcmi->State = HAL_DCMI_STATE_BUSY;
  115. /* Configures the HS, VS, DE and PC polarity */
  116. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
  117. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
  118. DCMI_CR_ESS
  119. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  120. | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
  121. DCMI_CR_LSM | DCMI_CR_OELS
  122. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  123. );
  124. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
  125. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
  126. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
  127. hdcmi->Init.JPEGMode
  128. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  129. | hdcmi->Init.ByteSelectMode |\
  130. hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
  131. hdcmi->Init.LineSelectStart
  132. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  133. );
  134. if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  135. {
  136. hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
  137. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
  138. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
  139. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
  140. }
  141. /* Enable the Line, Vsync, Error and Overrun interrupts */
  142. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  143. /* Update error code */
  144. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  145. /* Initialize the DCMI state*/
  146. hdcmi->State = HAL_DCMI_STATE_READY;
  147. return HAL_OK;
  148. }
  149. /**
  150. * @}
  151. */
  152. #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\
  153. STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  154. #endif /* HAL_DCMI_MODULE_ENABLED */
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @}
  160. */
  161. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/