训练营PLSR题目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

183 行
7.5 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. ******************************************************************************
  11. * @attention
  12. *
  13. * Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file in
  17. * the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. ******************************************************************************
  20. @verbatim
  21. ==============================================================================
  22. ##### DCMI peripheral extension features #####
  23. ==============================================================================
  24. [..] Comparing to other previous devices, the DCMI interface for STM32F446xx
  25. devices contains the following additional features :
  26. (+) Support of Black and White cameras
  27. ##### How to use this driver #####
  28. ==============================================================================
  29. [..] This driver provides functions to manage the Black and White feature
  30. @endverbatim
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32f4xx_hal.h"
  35. /** @addtogroup STM32F4xx_HAL_Driver
  36. * @{
  37. */
  38. /** @defgroup DCMIEx DCMIEx
  39. * @brief DCMI Extended HAL module driver
  40. * @{
  41. */
  42. #ifdef HAL_DCMI_MODULE_ENABLED
  43. #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\
  44. defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* Private define ------------------------------------------------------------*/
  47. /* Private macro -------------------------------------------------------------*/
  48. /* Private variables ---------------------------------------------------------*/
  49. /* Private function prototypes -----------------------------------------------*/
  50. /* Exported functions --------------------------------------------------------*/
  51. /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions
  52. * @{
  53. */
  54. /**
  55. * @}
  56. */
  57. /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions
  58. * @{
  59. */
  60. /**
  61. * @brief Initializes the DCMI according to the specified
  62. * parameters in the DCMI_InitTypeDef and create the associated handle.
  63. * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains
  64. * the configuration information for DCMI.
  65. * @retval HAL status
  66. */
  67. HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi)
  68. {
  69. /* Check the DCMI peripheral state */
  70. if(hdcmi == NULL)
  71. {
  72. return HAL_ERROR;
  73. }
  74. /* Check function parameters */
  75. assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance));
  76. assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity));
  77. assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity));
  78. assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity));
  79. assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode));
  80. assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate));
  81. assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode));
  82. assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode));
  83. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  84. assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode));
  85. assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart));
  86. assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode));
  87. assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart));
  88. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  89. if(hdcmi->State == HAL_DCMI_STATE_RESET)
  90. {
  91. /* Allocate lock resource and initialize it */
  92. hdcmi->Lock = HAL_UNLOCKED;
  93. /* Init the low level hardware */
  94. /* Init the DCMI Callback settings */
  95. #if (USE_HAL_DCMI_REGISTER_CALLBACKS == 1)
  96. hdcmi->FrameEventCallback = HAL_DCMI_FrameEventCallback; /* Legacy weak FrameEventCallback */
  97. hdcmi->VsyncEventCallback = HAL_DCMI_VsyncEventCallback; /* Legacy weak VsyncEventCallback */
  98. hdcmi->LineEventCallback = HAL_DCMI_LineEventCallback; /* Legacy weak LineEventCallback */
  99. hdcmi->ErrorCallback = HAL_DCMI_ErrorCallback; /* Legacy weak ErrorCallback */
  100. if(hdcmi->MspInitCallback == NULL)
  101. {
  102. /* Legacy weak MspInit Callback */
  103. hdcmi->MspInitCallback = HAL_DCMI_MspInit;
  104. }
  105. /* Initialize the low level hardware (MSP) */
  106. hdcmi->MspInitCallback(hdcmi);
  107. #else
  108. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  109. HAL_DCMI_MspInit(hdcmi);
  110. #endif /* (USE_HAL_DCMI_REGISTER_CALLBACKS) */
  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. */