| 1 | /**
|
|---|
| 2 | ******************************************************************************
|
|---|
| 3 | * @file stm32g0xx_ll_ucpd.c
|
|---|
| 4 | * @author MCD Application Team
|
|---|
| 5 | * @brief UCPD LL module driver.
|
|---|
| 6 | ******************************************************************************
|
|---|
| 7 | * @attention
|
|---|
| 8 | *
|
|---|
| 9 | * <h2><center>© Copyright (c) 2018 STMicroelectronics.
|
|---|
| 10 | * All rights reserved.</center></h2>
|
|---|
| 11 | *
|
|---|
| 12 | * This software component is licensed by ST under BSD 3-Clause license,
|
|---|
| 13 | * the "License"; You may not use this file except in compliance with the
|
|---|
| 14 | * License. You may obtain a copy of the License at:
|
|---|
| 15 | * opensource.org/licenses/BSD-3-Clause
|
|---|
| 16 | *
|
|---|
| 17 | ******************************************************************************
|
|---|
| 18 | */
|
|---|
| 19 | #if defined(USE_FULL_LL_DRIVER)
|
|---|
| 20 |
|
|---|
| 21 | /* Includes ------------------------------------------------------------------*/
|
|---|
| 22 | #include "stm32g0xx_ll_ucpd.h"
|
|---|
| 23 | #include "stm32g0xx_ll_bus.h"
|
|---|
| 24 | #include "stm32g0xx_ll_rcc.h"
|
|---|
| 25 |
|
|---|
| 26 | #ifdef USE_FULL_ASSERT
|
|---|
| 27 | #include "stm32_assert.h"
|
|---|
| 28 | #else
|
|---|
| 29 | #define assert_param(expr) ((void)0U)
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | /** @addtogroup STM32G0xx_LL_Driver
|
|---|
| 33 | * @{
|
|---|
| 34 | */
|
|---|
| 35 | #if defined (UCPD1) || defined (UCPD2)
|
|---|
| 36 | /** @addtogroup UCPD_LL
|
|---|
| 37 | * @{
|
|---|
| 38 | */
|
|---|
| 39 |
|
|---|
| 40 | /* Private types -------------------------------------------------------------*/
|
|---|
| 41 | /* Private variables ---------------------------------------------------------*/
|
|---|
| 42 |
|
|---|
| 43 | /* Private constants ---------------------------------------------------------*/
|
|---|
| 44 | /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants
|
|---|
| 45 | * @{
|
|---|
| 46 | */
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * @}
|
|---|
| 50 | */
|
|---|
| 51 |
|
|---|
| 52 | /* Private macros ------------------------------------------------------------*/
|
|---|
| 53 | /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros
|
|---|
| 54 | * @{
|
|---|
| 55 | */
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | /**
|
|---|
| 59 | * @}
|
|---|
| 60 | */
|
|---|
| 61 |
|
|---|
| 62 | /* Private function prototypes -----------------------------------------------*/
|
|---|
| 63 |
|
|---|
| 64 | /* Exported functions --------------------------------------------------------*/
|
|---|
| 65 | /** @addtogroup UCPD_LL_Exported_Functions
|
|---|
| 66 | * @{
|
|---|
| 67 | */
|
|---|
| 68 |
|
|---|
| 69 | /** @addtogroup UCPD_LL_EF_Init
|
|---|
| 70 | * @{
|
|---|
| 71 | */
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * @brief De-initialize the UCPD registers to their default reset values.
|
|---|
| 75 | * @param UCPDx ucpd Instance
|
|---|
| 76 | * @retval An ErrorStatus enumeration value:
|
|---|
| 77 | * - SUCCESS: ucpd registers are de-initialized
|
|---|
| 78 | * - ERROR: ucpd registers are not de-initialized
|
|---|
| 79 | */
|
|---|
| 80 | ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx)
|
|---|
| 81 | {
|
|---|
| 82 | ErrorStatus status = ERROR;
|
|---|
| 83 |
|
|---|
| 84 | /* Check the parameters */
|
|---|
| 85 | assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
|
|---|
| 86 |
|
|---|
| 87 | LL_UCPD_Disable(UCPDx);
|
|---|
| 88 |
|
|---|
| 89 | if (UCPD1 == UCPDx)
|
|---|
| 90 | {
|
|---|
| 91 | /* Force reset of ucpd clock */
|
|---|
| 92 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD1);
|
|---|
| 93 |
|
|---|
| 94 | /* Release reset of ucpd clock */
|
|---|
| 95 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD1);
|
|---|
| 96 |
|
|---|
| 97 | /* Disbale ucpd clock */
|
|---|
| 98 | LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD1);
|
|---|
| 99 |
|
|---|
| 100 | status = SUCCESS;
|
|---|
| 101 | }
|
|---|
| 102 | if (UCPD2 == UCPDx)
|
|---|
| 103 | {
|
|---|
| 104 | /* Force reset of ucpd clock */
|
|---|
| 105 | LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UCPD2);
|
|---|
| 106 |
|
|---|
| 107 | /* Release reset of ucpd clock */
|
|---|
| 108 | LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UCPD2);
|
|---|
| 109 |
|
|---|
| 110 | /* Disbale ucpd clock */
|
|---|
| 111 | LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UCPD2);
|
|---|
| 112 |
|
|---|
| 113 | status = SUCCESS;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | return status;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
|
|---|
| 121 | * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled (ucpd_CR1_SPE bit =0),
|
|---|
| 122 | * UCPD peripheral should be in disabled state prior calling this function. 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 | */
|
|---|
| 128 | ErrorStatus 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 | */
|
|---|
| 160 | void 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_DIV1;
|
|---|
| 164 | UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
|
|---|
| 165 | UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
|
|---|
| 166 | UCPD_InitStruct->HbitClockDiv = 0x19; /* Divide by 26 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 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|---|