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 20 /* Includes ------------------------------------------------------------------*/ 21 #include "stm32g0xx_ll_ucpd.h" 22 #include "stm32g0xx_ll_bus.h" 23 #include "stm32g0xx_ll_rcc.h" 24 25 #ifdef USE_FULL_ASSERT 26 #include "stm32_assert.h" 27 #else 28 #define assert_param(expr) ((void)0U) 29 #endif /* USE_FULL_ASSERT */ 30 31 /** @addtogroup STM32G0xx_LL_Driver 32 * @{ 33 */ 34 #if defined (UCPD1) || defined (UCPD2) 35 /** @addtogroup UCPD_LL 36 * @{ 37 */ 38 39 /* Private types -------------------------------------------------------------*/ 40 /* Private variables ---------------------------------------------------------*/ 41 42 /* Private constants ---------------------------------------------------------*/ 43 /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants 44 * @{ 45 */ 46 47 /** 48 * @} 49 */ 50 51 /* Private macros ------------------------------------------------------------*/ 52 /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros 53 * @{ 54 */ 55 56 57 /** 58 * @} 59 */ 60 61 /* Private function prototypes -----------------------------------------------*/ 62 63 /* Exported functions --------------------------------------------------------*/ 64 /** @addtogroup UCPD_LL_Exported_Functions 65 * @{ 66 */ 67 68 /** @addtogroup UCPD_LL_EF_Init 69 * @{ 70 */ 71 72 /** 73 * @brief De-initialize the UCPD registers to their default reset values. 74 * @param UCPDx ucpd Instance 75 * @retval An ErrorStatus enumeration value: 76 * - SUCCESS: ucpd registers are de-initialized 77 * - ERROR: ucpd registers are not de-initialized 78 */ LL_UCPD_DeInit(UCPD_TypeDef * UCPDx)79ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx) 80 { 81 ErrorStatus status = ERROR; 82 83 /* Check the parameters */ 84 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx)); 85 86 LL_UCPD_Disable(UCPDx); 87 88 if (UCPD1 == UCPDx) 89 { 90 /* Force reset of ucpd clock */ 91 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD1); 92 93 /* Release reset of ucpd clock */ 94 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD1); 95 96 /* Disable ucpd clock */ 97 LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD1); 98 99 status = SUCCESS; 100 } 101 if (UCPD2 == UCPDx) 102 { 103 /* Force reset of ucpd clock */ 104 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD2); 105 106 /* Release reset of ucpd clock */ 107 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD2); 108 109 /* Disable ucpd clock */ 110 LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD2); 111 112 status = SUCCESS; 113 } 114 115 return status; 116 } 117 118 /** 119 * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct. 120 * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled 121 * (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function. 122 * Otherwise, ERROR result will be returned. 123 * @param UCPDx UCPD Instance 124 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains 125 * the configuration information for the UCPD peripheral. 126 * @retval An ErrorStatus enumeration value. (Return always SUCCESS) 127 */ LL_UCPD_Init(UCPD_TypeDef * UCPDx,LL_UCPD_InitTypeDef * UCPD_InitStruct)128ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, LL_UCPD_InitTypeDef *UCPD_InitStruct) 129 { 130 /* Check the ucpd Instance UCPDx*/ 131 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx)); 132 133 if (UCPD1 == UCPDx) 134 { 135 LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UCPD1); 136 } 137 138 if (UCPD2 == UCPDx) 139 { 140 LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UCPD2); 141 } 142 143 LL_UCPD_Disable(UCPDx); 144 145 /*---------------------------- UCPDx CFG1 Configuration ------------------------*/ 146 MODIFY_REG(UCPDx->CFG1, 147 UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV, 148 UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) | 149 (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv); 150 151 return SUCCESS; 152 } 153 154 /** 155 * @brief Set each @ref LL_UCPD_InitTypeDef field to default value. 156 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure 157 * whose fields will be set to default values. 158 * @retval None 159 */ LL_UCPD_StructInit(LL_UCPD_InitTypeDef * UCPD_InitStruct)160void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct) 161 { 162 /* Set UCPD_InitStruct fields to default values */ 163 UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2; 164 UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */ 165 UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */ 166 UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */ 167 } 168 169 /** 170 * @} 171 */ 172 173 /** 174 * @} 175 */ 176 177 /** 178 * @} 179 */ 180 #endif /* defined (UCPD1) || defined (UCPD2) */ 181 /** 182 * @} 183 */ 184 185 #endif /* USE_FULL_LL_DRIVER */ 186 187