stm32f4xx_hal_dcmi_ex.c 8.0 KB

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