source: trunk/fw_g473rct/USBPD/Target/usbpd_pwr_user.h

Last change on this file was 59, checked in by f.jahn, 5 weeks ago

Added more USBPD-stack files.

File size: 7.7 KB
RevLine 
[59]1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file usbpd_pwr_user.h
5 * @author MCD Application Team
6 * @brief Header file for usbpd_pwr_user.c file
7 ******************************************************************************
8 * @attention
9 *
10 * Copyright (c) 2026 STMicroelectronics.
11 * All rights reserved.
12 *
13 * This software is licensed under terms that can be found in the LICENSE file
14 * in the root directory of this software component.
15 * If no LICENSE file comes with this software, it is provided AS-IS.
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20
21/* Define to prevent recursive inclusion -------------------------------------*/
22#ifndef USBPD_PWR_USER_H_
23#define USBPD_PWR_USER_H_
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* Includes ------------------------------------------------------------------*/
30#include "stm32g4xx.h"
31
32/** @addtogroup BSP
33 * @{
34 */
35
36/** @addtogroup POWER
37 * @{
38 */
39
40/** @defgroup POWER_Exported_Types Exported Types
41 * @{
42 */
43
44/**
45 * @brief Power role
46 */
47typedef enum
48{
49 POWER_ROLE_SOURCE = 0,
50 POWER_ROLE_SINK,
51 POWER_ROLE_DUAL
52} USBPD_PWR_PowerRoleTypeDef;
53
54/**
55 * @brief Voltage control mode
56 */
57typedef enum
58{
59 DCDC_CTRL_MODE_UNKNOWN = 0,
60 DCDC_CTRL_MODE_GPIO,
61 DCDC_CTRL_MODE_PWM,
62} USBPD_PWR_DCDCCtrlModeTypeDef;
63
64/**
65 * @brief Low Power Mode of TypeC ports
66 */
67typedef enum
68{
69 USBPD_PWR_MODE_OFF = 0,
70 USBPD_PWR_MODE_HIBERNATE,
71 USBPD_PWR_MODE_LOWPOWER,
72 USBPD_PWR_MODE_NORMAL
73} USBPD_PWR_PowerModeTypeDef;
74
75/**
76 * @brief VBUS connection status
77 */
78typedef enum
79{
80 VBUS_CONNECTED = 0,
81 VBUS_NOT_CONNECTED
82} USBPD_PWR_VBUSConnectionStatusTypeDef;
83
84/**
85 * @brief VBUS Detection Callback
86 */
87typedef void USBPD_PWR_VBUSDetectCallbackFunc(uint32_t Instance,
88 USBPD_PWR_VBUSConnectionStatusTypeDef VBUSConnectionStatus);
89
90/**
91 * @}
92 */
93
94/** @defgroup POWER_Exported_Constants Exported Constants
95 * @{
96 */
97/* Common Error codes */
98#define BSP_ERROR_NONE 0
99#define BSP_ERROR_NO_INIT -1
100#define BSP_ERROR_WRONG_PARAM -2
101#define BSP_ERROR_BUSY -3
102#define BSP_ERROR_PERIPH_FAILURE -4
103#define BSP_ERROR_COMPONENT_FAILURE -5
104#define BSP_ERROR_UNKNOWN_FAILURE -6
105#define BSP_ERROR_UNKNOWN_COMPONENT -7
106#define BSP_ERROR_BUS_FAILURE -8
107#define BSP_ERROR_CLOCK_FAILURE -9
108#define BSP_ERROR_MSP_FAILURE -10
109#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
110
111/**
112 * @brief Number of TypeC ports
113 */
114#define USBPD_PWR_INSTANCES_NBR (1U)
115
116/**
117 * @brief Type-C port identifier
118 */
119#define USBPD_PWR_TYPE_C_PORT_1 (0U)
120
121/**
122 * @brief CC pin identifier
123 */
124#define USBPD_PWR_TYPE_C_CC1 (1U)
125#define USBPD_PWR_TYPE_C_CC2 (2U)
126
127/**
128 * @brief VBUS disconnection threshold values (in mV)
129 */
130#define USBPD_PWR_HIGH_VBUS_THRESHOLD (2800U)
131#define USBPD_PWR_LOW_VBUS_THRESHOLD (750U)
132#define USBPD_PWR_VBUS_THRESHOLD_5V (2150U)
133#define USBPD_PWR_VBUS_THRESHOLD_9V (7000U)
134#define USBPD_PWR_VBUS_THRESHOLD_15V (12500U)
135#define USBPD_PWR_VBUS_THRESHOLD_20V (17000U)
136#define USBPD_PWR_VBUS_THRESHOLD_APDO (2150U)
137
138/**
139 * @brief VBUS discharge parameters
140 */
141#define USBPD_PWR_DISCHARGE_MARGIN (500U)
142#define USBPD_PWR_DISCHARGE_TIME (6U)
143
144/**
145 * @brief Calibration settings
146 */
147#define USBPD_PWR_DCDC_PRECISION (40U) /* DCDC output precision set to 40mV (Noise)*/
148#define USBPD_PWR_CALIBRATION_ENABLED (1U)
149#define USBPD_PWR_CALIBRATION_DISABLED (0U)
150
151/**
152 * @brief Standard VBUS voltage levels
153 */
154#define USBPD_PWR_VBUS_5V 5000U
155#define USBPD_PWR_VBUS_9V 9000U
156#define USBPD_PWR_VBUS_15V 15000U
157
158/**
159 * @brief power timeout
160 */
161#define USBPD_PWR_TIMEOUT_PDO 250U /* Timeout for PDO to PDO or PDO to APDO at 250ms*/
162#define USBPD_PWR_TIMEOUT_APDO 25U /* Timeout for APDO to APDO at 25ms*/
163
164/**
165 * @brief Invalid value set during issue with voltage setting
166 */
167#define USBPD_PWR_INVALID_VALUE 0xFFFFFFFFU
168
169/**
170 * @}
171 */
172
173/** @defgroup POWER_Exported_Functions Exported Functions
174 * @{
175 */
176/* Common functions */
177int32_t BSP_USBPD_PWR_Init(uint32_t Instance);
178
179int32_t BSP_USBPD_PWR_Deinit(uint32_t Instance);
180
181int32_t BSP_USBPD_PWR_SetRole(uint32_t Instance, USBPD_PWR_PowerRoleTypeDef Role);
182
183int32_t BSP_USBPD_PWR_SetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef PwrMode);
184
185int32_t BSP_USBPD_PWR_GetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef *PwrMode);
186
187int32_t BSP_USBPD_PWR_VBUSInit(uint32_t Instance);
188
189int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t Instance);
190
191int32_t BSP_USBPD_PWR_VBUSOn(uint32_t Instance);
192
193int32_t BSP_USBPD_PWR_VBUSOff(uint32_t Instance);
194
195int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t Instance,
196 uint32_t VbusTargetInmv,
197 uint32_t OperatingCurrent,
198 uint32_t MaxOperatingCurrent);
199
200int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t Instance,
201 uint32_t VbusTargetMaxInmv,
202 uint32_t VbusTargetMinInmv,
203 uint32_t OperatingCurrent,
204 uint32_t MaxOperatingCurrent);
205
206int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t Instance,
207 uint32_t VbusTargetMin,
208 uint32_t VbusTargetMax,
209 uint32_t OperatingPower,
210 uint32_t MaxOperatingPower);
211
212int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t Instance,
213 uint32_t VbusTargetInmv,
214 uint32_t OperatingCurrent,
215 int32_t Delta);
216
217int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage);
218
219int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent);
220
221int32_t BSP_USBPD_PWR_VCONNInit(uint32_t Instance,
222 uint32_t CCPinId);
223
224int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t Instance,
225 uint32_t CCPinId);
226
227int32_t BSP_USBPD_PWR_VCONNOn(uint32_t Instance,
228 uint32_t CCPinId);
229
230int32_t BSP_USBPD_PWR_VCONNOff(uint32_t Instance,
231 uint32_t CCPinId);
232
233int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t Instance,
234 uint32_t VoltageThreshold);
235
236int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t Instance,
237 USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback);
238
239int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t Instance, uint8_t *pState);
240
241int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t Instance,
242 uint32_t CCPinId, uint8_t *pState);
243
244int32_t BSP_USBPD_PWR_VCCSetState(uint32_t Instance, uint32_t State);
245
246void BSP_USBPD_PWR_EventCallback(uint32_t Instance);
247
248/**
249 * @}
250 */
251
252/**
253 * @}
254 */
255
256/**
257 * @}
258 */
259
260/**
261 * @}
262 */
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif /* USBPD_PWR_USER_H_ */
269
Note: See TracBrowser for help on using the repository browser.