1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_ll_ucpd.c 4 * @author MCD Application Team 5 * @brief UCPD LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 "stm32h5xx_ll_ucpd.h" 22 #include "stm32h5xx_ll_bus.h" 23 #include "stm32h5xx_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 STM32H5xx_LL_Driver 32 * @{ 33 */ 34 #if defined (UCPD1) 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_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1); 92 93 /* Release reset of ucpd clock */ 94 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1); 95 96 /* Disable ucpd clock */ 97 LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1); 98 99 status = SUCCESS; 100 } 101 102 return status; 103 } 104 105 /** 106 * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct. 107 * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled 108 * (ucpd_CR1_SPE bit =0), UCPD peripheral should be in disabled state prior calling this function. 109 * Otherwise, ERROR result will be returned. 110 * @param UCPDx UCPD Instance 111 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains 112 * the configuration information for the UCPD peripheral. 113 * @retval An ErrorStatus enumeration value. (Return always SUCCESS) 114 */ LL_UCPD_Init(UCPD_TypeDef * UCPDx,LL_UCPD_InitTypeDef * UCPD_InitStruct)115ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, LL_UCPD_InitTypeDef *UCPD_InitStruct) 116 { 117 /* Check the ucpd Instance UCPDx*/ 118 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx)); 119 120 if (UCPD1 == UCPDx) 121 { 122 LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1); 123 } 124 125 126 LL_UCPD_Disable(UCPDx); 127 128 /*---------------------------- UCPDx CFG1 Configuration ------------------------*/ 129 MODIFY_REG(UCPDx->CFG1, 130 UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV, 131 UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) | 132 (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv); 133 134 return SUCCESS; 135 } 136 137 /** 138 * @brief Set each @ref LL_UCPD_InitTypeDef field to default value. 139 * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure 140 * whose fields will be set to default values. 141 * @retval None 142 */ LL_UCPD_StructInit(LL_UCPD_InitTypeDef * UCPD_InitStruct)143void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct) 144 { 145 /* Set UCPD_InitStruct fields to default values */ 146 UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2; 147 UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */ 148 UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */ 149 UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */ 150 } 151 152 /** 153 * @} 154 */ 155 156 /** 157 * @} 158 */ 159 160 /** 161 * @} 162 */ 163 #endif /* defined (UCPD1) */ 164 /** 165 * @} 166 */ 167 168 #endif /* USE_FULL_LL_DRIVER */ 169