Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32G4 / Drivers / STM32G4xx_HAL_Driver / Src / stm32g4xx_ll_ucpd.c
blob6b21f7a4cd630dfdf10ba1a6fa929f132c83cf7d
1 /**
2 ******************************************************************************
3 * @file stm32g4xx_ll_ucpd.c
4 * @author MCD Application Team
5 * @brief UCPD LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32g4xx_ll_ucpd.h"
23 #include "stm32g4xx_ll_bus.h"
24 #include "stm32g4xx_ll_rcc.h"
26 #ifdef USE_FULL_ASSERT
27 #include "stm32_assert.h"
28 #else
29 #define assert_param(expr) ((void)0U)
30 #endif
32 /** @addtogroup STM32G4xx_LL_Driver
33 * @{
35 #if defined (UCPD1)
36 /** @addtogroup UCPD_LL
37 * @{
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants
45 * @{
48 /**
49 * @}
52 /* Private macros ------------------------------------------------------------*/
53 /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros
54 * @{
58 /**
59 * @}
62 /* Private function prototypes -----------------------------------------------*/
64 /* Exported functions --------------------------------------------------------*/
65 /** @addtogroup UCPD_LL_Exported_Functions
66 * @{
69 /** @addtogroup UCPD_LL_EF_Init
70 * @{
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
80 ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx)
82 ErrorStatus status = ERROR;
84 /* Check the parameters */
85 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
87 LL_UCPD_Disable(UCPDx);
89 if (UCPD1 == UCPDx)
91 /* Force reset of ucpd clock */
92 LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1);
94 /* Release reset of ucpd clock */
95 LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1);
97 /* Disbale ucpd clock */
98 LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1);
100 status = SUCCESS;
103 return status;
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)
115 ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, LL_UCPD_InitTypeDef *UCPD_InitStruct)
117 /* Check the ucpd Instance UCPDx*/
118 assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
120 if(UCPD1 == UCPDx)
122 LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
126 LL_UCPD_Disable(UCPDx);
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);
134 return SUCCESS;
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
143 void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct)
145 /* Set UCPD_InitStruct fields to default values */
146 UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV1;
147 UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
148 UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
149 UCPD_InitStruct->HbitClockDiv = 0x1A; /* Divide by 27 to produce HBITCLK */
153 * @}
157 * @}
161 * @}
163 #endif /* defined (UCPD1) */
165 * @}
168 #endif /* USE_FULL_LL_DRIVER */
170 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/