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.
 
 

166 lines
6.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. /* Init the low level hardware */
  93. HAL_DCMI_MspInit(hdcmi);
  94. }
  95. /* Change the DCMI state */
  96. hdcmi->State = HAL_DCMI_STATE_BUSY;
  97. /* Configures the HS, VS, DE and PC polarity */
  98. hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\
  99. DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\
  100. DCMI_CR_ESS
  101. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  102. | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\
  103. DCMI_CR_LSM | DCMI_CR_OELS
  104. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  105. );
  106. hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\
  107. hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\
  108. hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\
  109. hdcmi->Init.JPEGMode
  110. #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
  111. | hdcmi->Init.ByteSelectMode |\
  112. hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\
  113. hdcmi->Init.LineSelectStart
  114. #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
  115. );
  116. if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED)
  117. {
  118. hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) |
  119. ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)|
  120. ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) |
  121. ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC));
  122. }
  123. /* Enable the Line, Vsync, Error and Overrun interrupts */
  124. __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR);
  125. /* Update error code */
  126. hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE;
  127. /* Initialize the DCMI state*/
  128. hdcmi->State = HAL_DCMI_STATE_READY;
  129. return HAL_OK;
  130. }
  131. /**
  132. * @}
  133. */
  134. #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\
  135. STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
  136. #endif /* HAL_DCMI_MODULE_ENABLED */
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/