1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_ll_ucpd.c
4   * @author  MCD Application Team
5   * @brief   UCPD LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 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 "stm32l5xx_ll_ucpd.h"
23 #include "stm32l5xx_ll_bus.h"
24 #include "stm32l5xx_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 STM32L5xx_LL_Driver
33   * @{
34   */
35 #if defined (UCPD1)
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   */
LL_UCPD_DeInit(UCPD_TypeDef * UCPDx)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_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1);
93 
94     /* Release reset of ucpd clock */
95     LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1);
96 
97     /* Disable ucpd clock */
98     LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1);
99 
100     status = SUCCESS;
101   }
102 
103   return status;
104 }
105 
106 /**
107   * @brief  Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
108   * @note   As some bits in ucpd configuration registers can only be written when the ucpd is disabled (ucpd_CR1_SPE bit =0),
109   *         UCPD peripheral should be in disabled state prior calling this function. 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)115 ErrorStatus 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)143 void 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 
170 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
171