stm32g0xx_ll_ucpd.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_ucpd.c
  4. * @author MCD Application Team
  5. * @brief UCPD LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32g0xx_ll_ucpd.h"
  21. #include "stm32g0xx_ll_bus.h"
  22. #include "stm32g0xx_ll_rcc.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif /* USE_FULL_ASSERT */
  28. /** @addtogroup STM32G0xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (UCPD1) || defined (UCPD2)
  32. /** @addtogroup UCPD_LL
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants
  39. * @{
  40. */
  41. /**
  42. * @}
  43. */
  44. /* Private macros ------------------------------------------------------------*/
  45. /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /* Private function prototypes -----------------------------------------------*/
  52. /* Exported functions --------------------------------------------------------*/
  53. /** @addtogroup UCPD_LL_Exported_Functions
  54. * @{
  55. */
  56. /** @addtogroup UCPD_LL_EF_Init
  57. * @{
  58. */
  59. /**
  60. * @brief De-initialize the UCPD registers to their default reset values.
  61. * @param UCPDx ucpd Instance
  62. * @retval An ErrorStatus enumeration value:
  63. * - SUCCESS: ucpd registers are de-initialized
  64. * - ERROR: ucpd registers are not de-initialized
  65. */
  66. ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx)
  67. {
  68. ErrorStatus status = ERROR;
  69. /* Check the parameters */
  70. assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
  71. LL_UCPD_Disable(UCPDx);
  72. if (UCPD1 == UCPDx)
  73. {
  74. /* Force reset of ucpd clock */
  75. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD1);
  76. /* Release reset of ucpd clock */
  77. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD1);
  78. /* Disable ucpd clock */
  79. LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD1);
  80. status = SUCCESS;
  81. }
  82. if (UCPD2 == UCPDx)
  83. {
  84. /* Force reset of ucpd clock */
  85. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD2);
  86. /* Release reset of ucpd clock */
  87. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD2);
  88. /* Disable ucpd clock */
  89. LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD2);
  90. status = SUCCESS;
  91. }
  92. return status;
  93. }
  94. /**
  95. * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
  96. * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled
  97. * (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function.
  98. * Otherwise, ERROR result will be returned.
  99. * @param UCPDx UCPD Instance
  100. * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains
  101. * the configuration information for the UCPD peripheral.
  102. * @retval An ErrorStatus enumeration value. (Return always SUCCESS)
  103. */
  104. ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, LL_UCPD_InitTypeDef *UCPD_InitStruct)
  105. {
  106. /* Check the ucpd Instance UCPDx*/
  107. assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
  108. if (UCPD1 == UCPDx)
  109. {
  110. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UCPD1);
  111. }
  112. if (UCPD2 == UCPDx)
  113. {
  114. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UCPD2);
  115. }
  116. LL_UCPD_Disable(UCPDx);
  117. /*---------------------------- UCPDx CFG1 Configuration ------------------------*/
  118. MODIFY_REG(UCPDx->CFG1,
  119. UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV,
  120. UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) |
  121. (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv);
  122. return SUCCESS;
  123. }
  124. /**
  125. * @brief Set each @ref LL_UCPD_InitTypeDef field to default value.
  126. * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure
  127. * whose fields will be set to default values.
  128. * @retval None
  129. */
  130. void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct)
  131. {
  132. /* Set UCPD_InitStruct fields to default values */
  133. UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2;
  134. UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
  135. UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
  136. UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */
  137. }
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @}
  146. */
  147. #endif /* defined (UCPD1) || defined (UCPD2) */
  148. /**
  149. * @}
  150. */
  151. #endif /* USE_FULL_LL_DRIVER */