Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

186 lignes
7.6 KiB

  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.
  25. * All rights reserved.</center></h2>
  26. *
  27. * This software component is licensed by ST under BSD 3-Clause license,
  28. * the "License"; You may not use this file except in compliance with the
  29. * License. You may obtain a copy of the License at:
  30. * opensource.org/licenses/BSD-3-Clause
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f4xx_hal.h"
  36. /** @addtogroup STM32F4xx_HAL_Driver
  37. * @{
  38. */
  39. /** @defgroup DCMIEx DCMIEx
  40. * @brief DCMI Extended HAL module driver
  41. * @{
  42. */
  43. #ifdef HAL_DCMI_MODULE_ENABLED
  44. #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\
  45. defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macro -------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. /* Exported functions --------------------------------------------------------*/
  52. /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
  53. * @{
  54. */
  55. /**
  56. * @}
  57. */
  58. /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
  59. * @{
  60. */
  61. /**
  62. * @brief Initializes the DCMI according to the specified
  63. * parameters in the DCMI_InitTypeDef and create the associated handle.
  64. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  65. * the configuration information for DCMI.
  66. * @retval HAL status
  67. */
  68. HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  69. {
  70. /* Check the DCMI peripheral state */
  71. if(hdcmi == NULL)
  72. {
  73. return HAL_ERROR;
  74. }
  75. /* Check function parameters */
  76. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  77. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  78. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  79. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  80. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  81. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  82. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  83. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  84. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  85. assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
  86. assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
  87. assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
  88. assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
  89. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  90. if(hdcmi->State == HAL_DCMI_STATE_RESET)
  91. {
  92. /* Allocate lock resource and initialize it */
  93. hdcmi->Lock = HAL_UNLOCKED;
  94. /* Init the low level hardware */
  95. /* Init the DCMI Callback settings */
  96. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  97. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  98. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  99. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  100. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  101. if(hdcmi->MspInitCallback == NULL)
  102. {
  103. /* Legacy weak MspInit Callback */
  104. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  105. }
  106. /* Initialize the low level hardware (MSP) */
  107. hdcmi->MspInitCallback(hdcmi);
  108. #else
  109. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  110. HAL_DCMI_MspInit(hdcmi);
  111. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  112. HAL_DCMI_MspInit(hdcmi);
  113. }
  114. /* Change the DCMI state */
  115. hdcmi->State = HAL_DCMI_STATE_BUSY;
  116. /* Configures the HS, VS, DE and PC polarity */
  117. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
  118. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
  119. DCMI_CR_ESS
  120. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  121. | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
  122. DCMI_CR_LSM | DCMI_CR_OELS
  123. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  124. );
  125. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
  126. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
  127. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
  128. hdcmi->Init.JPEGMode
  129. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  130. | hdcmi->Init.ByteSelectMode |\
  131. hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
  132. hdcmi->Init.LineSelectStart
  133. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  134. );
  135. if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  136. {
  137. hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
  138. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
  139. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
  140. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
  141. }
  142. /* Enable the Line, Vsync, Error and Overrun interrupts */
  143. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  144. /* Update error code */
  145. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  146. /* Initialize the DCMI state*/
  147. hdcmi->State = HAL_DCMI_STATE_READY;
  148. return HAL_OK;
  149. }
  150. /**
  151. * @}
  152. */
  153. #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\
  154. STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  155. #endif /* HAL_DCMI_MODULE_ENABLED */
  156. /**
  157. * @}
  158. */
  159. /**
  160. * @}
  161. */
  162. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/