stm32g4xx_ll_ucpd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_ll_ucpd.c
  4. * @author MCD Application Team
  5. * @brief UCPD LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 "stm32g4xx_ll_ucpd.h"
  21. #include "stm32g4xx_ll_bus.h"
  22. #include "stm32g4xx_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 STM32G4xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (UCPD1)
  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_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1);
  76. /* Release reset of ucpd clock */
  77. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1);
  78. /* Disable ucpd clock */
  79. LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1);
  80. status = SUCCESS;
  81. }
  82. return status;
  83. }
  84. /**
  85. * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
  86. * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled
  87. * (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function.
  88. * Otherwise, ERROR result will be returned.
  89. * @param UCPDx UCPD Instance
  90. * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains
  91. * the configuration information for the UCPD peripheral.
  92. * @retval An ErrorStatus enumeration value. (Return always SUCCESS)
  93. */
  94. ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, const LL_UCPD_InitTypeDef *UCPD_InitStruct)
  95. {
  96. /* Check the ucpd Instance UCPDx*/
  97. assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
  98. if (UCPD1 == UCPDx)
  99. {
  100. LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
  101. }
  102. LL_UCPD_Disable(UCPDx);
  103. /*---------------------------- UCPDx CFG1 Configuration ------------------------*/
  104. MODIFY_REG(UCPDx->CFG1,
  105. UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV,
  106. UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) |
  107. (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv);
  108. return SUCCESS;
  109. }
  110. /**
  111. * @brief Set each @ref LL_UCPD_InitTypeDef field to default value.
  112. * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure
  113. * whose fields will be set to default values.
  114. * @retval None
  115. */
  116. void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct)
  117. {
  118. /* Set UCPD_InitStruct fields to default values */
  119. UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2;
  120. UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
  121. UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
  122. UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */
  123. }
  124. /**
  125. * @}
  126. */
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. #endif /* defined (UCPD1) */
  134. /**
  135. * @}
  136. */
  137. #endif /* USE_FULL_LL_DRIVER */