```html
|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_ll_ucpd.c 00004 * @author MCD Application Team 00005 * @brief UCPD LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2019 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 #if defined(USE_FULL_LL_DRIVER) 00019 00020 /* Includes ------------------------------------------------------------------*/ 00021 #include "stm32g4xx_ll_ucpd.h" 00022 #include "stm32g4xx_ll_bus.h" 00023 #include "stm32g4xx_ll_rcc.h" 00024 00025 #ifdef USE_FULL_ASSERT 00026 #include "stm32_assert.h" 00027 #else 00028 #define assert_param(expr) ((void)0U) 00029 #endif /* USE_FULL_ASSERT */ 00030 00031 /** @addtogroup STM32G4xx_LL_Driver 00032 * @{ 00033 */ 00034 #if defined (UCPD1) 00035 /** @addtogroup UCPD_LL 00036 * @{ 00037 */ 00038 00039 /* Private types -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 00042 /* Private constants ---------------------------------------------------------*/ 00043 /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants 00044 * @{ 00045 */ 00046 00047 /** 00048 * @} 00049 */ 00050 00051 /* Private macros ------------------------------------------------------------*/ 00052 /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros 00053 * @{ 00054 */ 00055 00056 00057 /** 00058 * @} 00059 */ 00060 00061 /* Private function prototypes -----------------------------------------------*/ 00062 00063 /* Exported functions --------------------------------------------------------*/ 00064 /** @addtogroup UCPD_LL_Exported_Functions 00065 * @{ 00066 */ 00067 00068 /** @addtogroup UCPD_LL_EF_Init 00069 * @{ 00070 */ 00071 00072 /** 00073 * @brief De-initialize the UCPD registers to their default reset values. 00074 * @param UCPDx ucpd Instance 00075 * @retval An ErrorStatus enumeration value: 00076 * - SUCCESS: ucpd registers are de-initialized 00077 * - ERROR: ucpd registers are not de-initialized 00078 */ 00079 ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx) 00080 { 00081 ErrorStatus status = ERROR; 00082 00083 /* Check the parameters */ 00084 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx)); 00085 00086 LL_UCPD_Disable(UCPDx); 00087 00088 if (UCPD1 == UCPDx) 00089 { 00090 /* Force reset of ucpd clock */ 00091 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1); 00092 00093 /* Release reset of ucpd clock */ 00094 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1); 00095 00096 /* Disable ucpd clock */ 00097 LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1); 00098 00099 status = SUCCESS; 00100 } 00100 00102 return status; 00103 } 00104 00105 /** 00106 * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct. 00107 * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled 00108 * (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function. 00109 * Otherwise, ERROR result will be returned. 00110 * @param UCPDx UCPD Instance 00111 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains 00112 * the configuration information for the UCPD peripheral. 00113 * @retval An ErrorStatus enumeration value. (Return always SUCCESS) 00114 */ 00115 ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, const LL_UCPD_InitTypeDef *UCPD_InitStruct) 00116 { 00117 /* Check the ucpd Instance UCPDx*/ 00118 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx)); 00119 00120 if (UCPD1 == UCPDx) 00121 { 00122 LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1); 00123 } 00124 00125 00126 LL_UCPD_Disable(UCPDx); 00127 00128 /*---------------------------- UCPDx CFG1 Configuration ------------------------*/ 00129 MODIFY_REG(UCPDx->CFG1, 00130 UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV, 00131 UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) | 00132 (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv); 00133 00134 return SUCCESS; 00135 } 00136 00137 /** 00138 * @brief Set each @ref LL_UCPD_InitTypeDef field to default value. 00139 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure 00140 * whose fields will be set to default values. 00141 * @retval None 00142 */ 00143 void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct) 00144 { 00145 /* Set UCPD_InitStruct fields to default values */ 00146 UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2; 00147 UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */ 00148 UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */ 00149 UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */ 00150 } 00151 00152 /** 00153 * @} 00154 */ 00155 00156 /** 00157 * @} 00158 */ 00159 00160 /** 00161 * @} 00162 */ 00163 #endif /* defined (UCPD1) */ 00164 /** 00165 * @} 00166 */ 00167 00168 #endif /* USE_FULL_LL_DRIVER */ 00169
1.7.6.1
```