source: trunk/fw_g473rct/USBPD/Target/usbpd_pwr_user.c@ 63

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

Added more USBPD-stack files.

File size: 24.1 KB
Line 
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file usbpd_pwr_user.c
5 * @author MCD Application Team
6 * @brief USBPD PWR user code
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/* Includes ------------------------------------------------------------------*/
22#include "usbpd_pwr_user.h"
23#include "stm32g4xx_hal.h"
24#if defined(_TRACE)
25#include "usbpd_core.h"
26#include "usbpd_trace.h"
27#endif /* _TRACE */
28
29/* USER CODE BEGIN include */
30
31/* USER CODE END include */
32
33/** @addtogroup BSP
34 * @{
35 */
36
37/** @addtogroup POWER
38 * @{
39 */
40/** @defgroup POWER_Private_Typedef Private Typedef
41 * @{
42 */
43/* USER CODE BEGIN POWER_Private_Typedef */
44
45/* USER CODE END POWER_Private_Typedef */
46/**
47 * @}
48 */
49
50/** @defgroup POWER_Private_Constants Private Constants
51* @{
52*/
53/* USER CODE BEGIN POWER_Private_Constants */
54
55/* USER CODE END POWER_Private_Constants */
56/**
57 * @}
58 */
59
60/** @defgroup POWER_Private_Macros Private Macros
61 * @{
62 */
63#if defined(_TRACE)
64#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (_PORT_), 0u, (uint8_t*)(__MESSAGE__), sizeof(__MESSAGE__) - 1u)
65#else
66#define PWR_DEBUG_TRACE(_PORT_, __MESSAGE__)
67#endif /* _TRACE */
68/* USER CODE BEGIN POWER_Private_Macros */
69
70/* USER CODE END POWER_Private_Macros */
71/**
72 * @}
73 */
74
75/** @defgroup POWER_Private_Variables Private Variables
76 * @{
77 */
78/* USER CODE BEGIN POWER_Private_Variables */
79
80/* USER CODE END POWER_Private_Variables */
81/**
82 * @}
83 */
84
85/** @defgroup POWER_Private_Functions Private Functions
86 * @{
87 */
88/* USER CODE BEGIN POWER_Private_Prototypes */
89
90/* USER CODE END POWER_Private_Prototypes */
91/**
92 * @}
93 */
94
95/** @defgroup POWER_Exported_Variables Exported Variables
96 * @{
97 */
98/* USER CODE BEGIN POWER_Exported_Variables */
99
100/* USER CODE END POWER_Exported_Variables */
101/**
102 * @}
103 */
104
105/** @addtogroup POWER_Exported_Functions
106 * @{
107 */
108/**
109 * @brief Global initialization of PWR resource used by USB-PD
110 * @param Instance Type-C port identifier
111 * This parameter can be take one of the following values:
112 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
113 * @retval BSP status
114 */
115__weak int32_t BSP_USBPD_PWR_Init(uint32_t Instance)
116{
117 /* USER CODE BEGIN BSP_USBPD_PWR_Init */
118 /* Check if instance is valid */
119 int32_t ret = BSP_ERROR_NONE;
120
121 if (Instance >= USBPD_PWR_INSTANCES_NBR)
122 {
123 ret = BSP_ERROR_WRONG_PARAM;
124 }
125 return ret;
126 /* USER CODE END BSP_USBPD_PWR_Init */
127}
128
129/**
130 * @brief Global de-initialization of PWR resource used by USB-PD
131 * @param Instance Type-C port identifier
132 * This parameter can be take one of the following values:
133 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
134 * @retval BSP status
135 */
136__weak int32_t BSP_USBPD_PWR_Deinit(uint32_t Instance)
137{
138 /* USER CODE BEGIN BSP_USBPD_PWR_Deinit */
139 /* Check if instance is valid */
140 int32_t ret = BSP_ERROR_NONE;
141
142 if (Instance >= USBPD_PWR_INSTANCES_NBR)
143 {
144 ret = BSP_ERROR_WRONG_PARAM;
145 }
146 else
147 {
148 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_Deinit");
149 }
150
151 return ret;
152 /* USER CODE END BSP_USBPD_PWR_Deinit */
153}
154
155/**
156 * @brief Assign Power role for current Port (Source or Sink)
157 * @param Instance Type-C port identifier
158 * This parameter can be take one of the following values:
159 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
160 * @param Role Type-C port role
161 * This parameter can be take one of the following values:
162 * @arg @ref POWER_ROLE_SOURCE
163 * @arg @ref POWER_ROLE_SINK
164 * @retval BSP status
165 */
166__weak int32_t BSP_USBPD_PWR_SetRole(uint32_t Instance, USBPD_PWR_PowerRoleTypeDef Role)
167{
168 /* USER CODE BEGIN BSP_USBPD_PWR_SetRole */
169 /* Check if instance is valid */
170 int32_t ret = BSP_ERROR_NONE;
171
172 if (Instance >= USBPD_PWR_INSTANCES_NBR)
173 {
174 ret = BSP_ERROR_WRONG_PARAM;
175 }
176 else
177 {
178 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetRole");
179 }
180
181 return ret;
182 /* USER CODE END BSP_USBPD_PWR_SetRole */
183}
184
185/**
186 * @brief Set operating mode of Port regarding power saving constraints
187 * @param Instance Type-C port identifier
188 * This parameter can be take one of the following values:
189 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
190 * @param PwrMode Type-C port power saving mode
191 * This parameter can be take one of the following values:
192 * @arg @ref USBPD_PWR_MODE_OFF
193 * @arg @ref USBPD_PWR_MODE_HIBERNATE
194 * @arg @ref USBPD_PWR_MODE_LOWPOWER
195 * @arg @ref USBPD_PWR_MODE_NORMAL
196 * @retval BSP status
197 */
198__weak int32_t BSP_USBPD_PWR_SetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef PwrMode)
199{
200 /* USER CODE BEGIN BSP_USBPD_PWR_SetPowerMode */
201 /* Check if instance is valid */
202 int32_t ret = BSP_ERROR_NONE;
203
204 if (Instance >= USBPD_PWR_INSTANCES_NBR)
205 {
206 ret = BSP_ERROR_WRONG_PARAM;
207 }
208 else
209 {
210 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_SetPowerMode");
211 }
212
213 return ret;
214 /* USER CODE END BSP_USBPD_PWR_SetPowerMode */
215}
216
217/**
218 * @brief Get operating mode of Port regarding power saving constraints
219 * @param Instance Type-C port identifier
220 * This parameter can be take one of the following values:
221 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
222 * @param PwrMode Pointer on current Type-C port power saving mode value
223 * Following values are available :
224 * @arg @ref USBPD_PWR_MODE_OFF
225 * @arg @ref USBPD_PWR_MODE_HIBERNATE
226 * @arg @ref USBPD_PWR_MODE_LOWPOWER
227 * @arg @ref USBPD_PWR_MODE_NORMAL
228 * @retval BSP status
229 */
230__weak int32_t BSP_USBPD_PWR_GetPowerMode(uint32_t Instance, USBPD_PWR_PowerModeTypeDef *PwrMode)
231{
232 /* USER CODE BEGIN BSP_USBPD_PWR_GetPowerMode */
233 /* Check if instance is valid */
234 int32_t ret = BSP_ERROR_NONE;
235
236 if (Instance >= USBPD_PWR_INSTANCES_NBR)
237 {
238 ret = BSP_ERROR_WRONG_PARAM;
239 }
240 else
241 {
242 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_GetPowerMode");
243 }
244 return ret;
245 /* USER CODE END BSP_USBPD_PWR_GetPowerMode */
246}
247
248/**
249 * @brief Initialize the hardware resources used by the Type-C power delivery (PD)
250 * controller.
251 * @param Instance Type-C port identifier
252 * This parameter can be take one of the following values:
253 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
254 * @retval BSP status
255 */
256__weak int32_t BSP_USBPD_PWR_VBUSInit(uint32_t Instance)
257{
258 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSInit */
259 /* Check if instance is valid */
260 int32_t ret = BSP_ERROR_NONE;
261
262 if (Instance >= USBPD_PWR_INSTANCES_NBR)
263 {
264 ret = BSP_ERROR_WRONG_PARAM;
265 }
266 else
267 {
268 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSInit");
269 }
270
271 return ret;
272 /* USER CODE END BSP_USBPD_PWR_VBUSInit */
273}
274
275/**
276 * @brief Release the hardware resources used by the Type-C power delivery (PD)
277 * controller.
278 * @param Instance Type-C port identifier
279 * This parameter can be take one of the following values:
280 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
281 * @retval BSP status
282 */
283__weak int32_t BSP_USBPD_PWR_VBUSDeInit(uint32_t Instance)
284{
285 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSDeInit */
286 /* Check if instance is valid */
287 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
288
289 if (Instance >= USBPD_PWR_INSTANCES_NBR)
290 {
291 ret = BSP_ERROR_WRONG_PARAM;
292 }
293 return ret;
294 /* USER CODE END BSP_USBPD_PWR_VBUSDeInit */
295}
296
297/**
298 * @brief Enable power supply over VBUS.
299 * @param Instance Type-C port identifier
300 * This parameter can be take one of the following values:
301 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
302 * @retval BSP status
303 */
304__weak int32_t BSP_USBPD_PWR_VBUSOn(uint32_t Instance)
305{
306 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOn */
307 /* Check if instance is valid */
308 int32_t ret;
309
310 if (Instance >= USBPD_PWR_INSTANCES_NBR)
311 {
312 ret = BSP_ERROR_WRONG_PARAM;
313 }
314 else
315 {
316 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
317 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSOn");
318 }
319 return ret;
320 /* USER CODE END BSP_USBPD_PWR_VBUSOn */
321}
322
323/**
324 * @brief Disable power supply over VBUS.
325 * @param Instance Type-C port identifier
326 * This parameter can be take one of the following values:
327 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
328 * @retval BSP status
329 */
330__weak int32_t BSP_USBPD_PWR_VBUSOff(uint32_t Instance)
331{
332 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSOff */
333 /* Check if instance is valid */
334 int32_t ret;
335
336 if (Instance >= USBPD_PWR_INSTANCES_NBR)
337 {
338 ret = BSP_ERROR_WRONG_PARAM;
339 }
340 else
341 {
342 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
343 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSOff");
344 }
345 return ret;
346 /* USER CODE END BSP_USBPD_PWR_VBUSOff */
347}
348
349/**
350 * @brief Set a fixed/variable PDO and manage the power control.
351 * @param Instance Type-C port identifier
352 * This parameter can be take one of the following values:
353 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
354 * @param VbusTargetInmv the vbus Target (in mV)
355 * @param OperatingCurrent the Operating Current (in mA)
356 * @param MaxOperatingCurrent the Max Operating Current (in mA)
357 * @retval BSP status
358 */
359__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Fixed(uint32_t Instance,
360 uint32_t VbusTargetInmv,
361 uint32_t OperatingCurrent,
362 uint32_t MaxOperatingCurrent)
363{
364 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
365 /* Check if instance is valid */
366 int32_t ret = BSP_ERROR_NONE;
367
368 if (Instance >= USBPD_PWR_INSTANCES_NBR)
369 {
370 ret = BSP_ERROR_WRONG_PARAM;
371 }
372 return ret;
373 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Fixed */
374}
375
376/**
377 * @brief Set a fixed/variable PDO and manage the power control.
378 * @param Instance Type-C port identifier
379 * This parameter can be take one of the following values:
380 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
381 * @param VbusTargetMinInmv the vbus Target min (in mV)
382 * @param VbusTargetMaxInmv the vbus Target max (in mV)
383 * @param OperatingCurrent the Operating Current (in mA)
384 * @param MaxOperatingCurrent the Max Operating Current (in mA)
385 * @retval BSP status
386 */
387__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Variable(uint32_t Instance,
388 uint32_t VbusTargetMinInmv,
389 uint32_t VbusTargetMaxInmv,
390 uint32_t OperatingCurrent,
391 uint32_t MaxOperatingCurrent)
392{
393 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Variable */
394 /* Check if instance is valid */
395 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
396
397 if (Instance >= USBPD_PWR_INSTANCES_NBR)
398 {
399 ret = BSP_ERROR_WRONG_PARAM;
400 }
401 return ret;
402 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Variable */
403}
404
405/**
406 * @brief Set a Battery PDO and manage the power control.
407 * @param Instance Type-C port identifier
408 * This parameter can be take one of the following values:
409 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
410 * @param VbusTargetMin the vbus Target min (in mV)
411 * @param VbusTargetMax the vbus Target max (in mV)
412 * @param OperatingPower the Operating Power (in mW)
413 * @param MaxOperatingPower the Max Operating Power (in mW)
414 * @retval BSP status
415 */
416__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_Battery(uint32_t Instance,
417 uint32_t VbusTargetMin,
418 uint32_t VbusTargetMax,
419 uint32_t OperatingPower,
420 uint32_t MaxOperatingPower)
421{
422 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_Battery */
423 /* Check if instance is valid */
424 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
425
426 if (Instance >= USBPD_PWR_INSTANCES_NBR)
427 {
428 ret = BSP_ERROR_WRONG_PARAM;
429 }
430 return ret;
431 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_Battery */
432}
433
434/**
435 * @brief Set a APDO and manage the power control.
436 * @param Instance Type-C port identifier
437 * This parameter can be take one of the following values:
438 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
439 * @param VbusTargetInmv the vbus Target (in mV)
440 * @param OperatingCurrent the Operating current (in mA)
441 * @param Delta Delta between with previous APDO (in mV), 0 means APDO start
442 * @retval BSP status
443 */
444__weak int32_t BSP_USBPD_PWR_VBUSSetVoltage_APDO(uint32_t Instance,
445 uint32_t VbusTargetInmv,
446 uint32_t OperatingCurrent,
447 int32_t Delta)
448{
449 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSSetVoltage_APDO */
450 /* Check if instance is valid */
451 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
452
453 if (Instance >= USBPD_PWR_INSTANCES_NBR)
454 {
455 ret = BSP_ERROR_WRONG_PARAM;
456 }
457 return ret;
458 /* USER CODE END BSP_USBPD_PWR_VBUSSetVoltage_APDO */
459}
460
461/**
462 * @brief Get actual voltage level measured on the VBUS line.
463 * @param Instance Type-C port identifier
464 * This parameter can be take one of the following values:
465 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
466 * @param pVoltage Pointer on measured voltage level (in mV)
467 * @retval BSP status
468 */
469__weak int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage)
470{
471 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetVoltage */
472 /* Check if instance is valid */
473 int32_t ret;
474 uint32_t val = 0U;
475
476 if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pVoltage))
477 {
478 ret = BSP_ERROR_WRONG_PARAM;
479 }
480 else
481 {
482 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
483 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSGetVoltage");
484 }
485 *pVoltage = val;
486 return ret;
487 /* USER CODE END BSP_USBPD_PWR_VBUSGetVoltage */
488}
489
490/**
491 * @brief Get actual current level measured on the VBUS line.
492 * @param Instance Type-C port identifier
493 * This parameter can be take one of the following values:
494 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
495 * @param pCurrent Pointer on measured current level (in mA)
496 * @retval BSP status
497 */
498__weak int32_t BSP_USBPD_PWR_VBUSGetCurrent(uint32_t Instance, int32_t *pCurrent)
499{
500 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetCurrent */
501 /* Check if instance is valid */
502 int32_t ret;
503
504 if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pCurrent))
505 {
506 ret = BSP_ERROR_WRONG_PARAM;
507 }
508 else
509 {
510 *pCurrent = 0;
511 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
512 }
513 return ret;
514 /* USER CODE END BSP_USBPD_PWR_VBUSGetCurrent */
515}
516
517/**
518 * @brief Initialize VCONN sourcing.
519 * @param Instance Type-C port identifier
520 * This parameter can be take one of the following values:
521 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
522 * @param CCPinId Type-C CC pin identifier
523 * This parameter can be take one of the following values:
524 * @arg @ref USBPD_PWR_TYPE_C_CC1
525 * @arg @ref USBPD_PWR_TYPE_C_CC2
526 * @retval BSP status
527 */
528__weak int32_t BSP_USBPD_PWR_VCONNInit(uint32_t Instance,
529 uint32_t CCPinId)
530{
531 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNInit */
532 /* Check if instance is valid */
533 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
534
535 if (Instance >= USBPD_PWR_INSTANCES_NBR)
536 {
537 ret = BSP_ERROR_WRONG_PARAM;
538 }
539 return ret;
540 /* USER CODE END BSP_USBPD_PWR_VCONNInit */
541}
542
543/**
544 * @brief Un-Initialize VCONN sourcing.
545 * @param Instance Type-C port identifier
546 * This parameter can be take one of the following values:
547 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
548 * @param CCPinId Type-C CC pin identifier
549 * This parameter can be take one of the following values:
550 * @arg @ref USBPD_PWR_TYPE_C_CC1
551 * @arg @ref USBPD_PWR_TYPE_C_CC2
552 * @retval BSP status
553 */
554__weak int32_t BSP_USBPD_PWR_VCONNDeInit(uint32_t Instance,
555 uint32_t CCPinId)
556{
557 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNDeInit */
558 /* Check if instance is valid */
559 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
560
561 if (Instance >= USBPD_PWR_INSTANCES_NBR)
562 {
563 ret = BSP_ERROR_WRONG_PARAM;
564 }
565 return ret;
566 /* USER CODE END BSP_USBPD_PWR_VCONNDeInit */
567}
568
569/**
570 * @brief Enable VCONN sourcing.
571 * @param Instance Type-C port identifier
572 * This parameter can be take one of the following values:
573 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
574 * @param CCPinId Type-C CC pin identifier
575 * This parameter can be take one of the following values:
576 * @arg @ref USBPD_PWR_TYPE_C_CC1
577 * @arg @ref USBPD_PWR_TYPE_C_CC2
578 * @retval BSP status
579 */
580__weak int32_t BSP_USBPD_PWR_VCONNOn(uint32_t Instance,
581 uint32_t CCPinId)
582{
583 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNOn */
584 /* Check if instance is valid */
585 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
586
587 if (Instance >= USBPD_PWR_INSTANCES_NBR)
588 {
589 ret = BSP_ERROR_WRONG_PARAM;
590 }
591 return ret;
592 /* USER CODE END BSP_USBPD_PWR_VCONNOn */
593}
594
595/**
596 * @brief Disable VCONN sourcing.
597 * @param Instance Type-C port identifier
598 * This parameter can be take one of the following values:
599 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
600 * @param CCPinId CC pin identifier
601 * This parameter can be take one of the following values:
602 * @arg @ref USBPD_PWR_TYPE_C_CC1
603 * @arg @ref USBPD_PWR_TYPE_C_CC2
604 * @retval BSP status
605 */
606__weak int32_t BSP_USBPD_PWR_VCONNOff(uint32_t Instance,
607 uint32_t CCPinId)
608{
609 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNOff */
610 /* Check if instance is valid */
611 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
612
613 if (Instance >= USBPD_PWR_INSTANCES_NBR)
614 {
615 ret = BSP_ERROR_WRONG_PARAM;
616 }
617 return ret;
618 /* USER CODE END BSP_USBPD_PWR_VCONNOff */
619}
620
621/**
622 * @brief Get actual VCONN status.
623 * @param Instance Type-C port identifier
624 * This parameter can be take one of the following values:
625 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
626 * @param CCPinId Type-C CC pin identifier
627 * This parameter can be take one of the following values:
628 * @arg @ref USBPD_PWR_TYPE_C_CC1
629 * @arg @ref USBPD_PWR_TYPE_C_CC2
630 * @param pState VCONN status (1: On, 0: Off)
631 * @retval BSP status
632 */
633__weak int32_t BSP_USBPD_PWR_VCONNIsOn(uint32_t Instance,
634 uint32_t CCPinId, uint8_t *pState)
635{
636 /* USER CODE BEGIN BSP_USBPD_PWR_VCONNIsOn */
637 /* Check if instance is valid */
638 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
639
640 if (Instance >= USBPD_PWR_INSTANCES_NBR)
641 {
642 ret = BSP_ERROR_WRONG_PARAM;
643 }
644 *pState = 0u;
645 return ret;
646 /* USER CODE END BSP_USBPD_PWR_VCONNIsOn */
647}
648
649/**
650 * @brief Set the VBUS disconnection voltage threshold.
651 * @note Callback function registered through BSP_USBPD_PWR_RegisterVBUSDetectCallback
652 * function call is invoked when VBUS falls below programmed threshold.
653 * @note By default VBUS disconnection threshold is set to 3.3V
654 * @param Instance Type-C port identifier
655 * This parameter can be take one of the following values:
656 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
657 * @param VoltageThreshold VBUS disconnection voltage threshold (in mV)
658 * @retval BSP status
659 */
660__weak int32_t BSP_USBPD_PWR_SetVBUSDisconnectionThreshold(uint32_t Instance,
661 uint32_t VoltageThreshold)
662{
663 /* USER CODE BEGIN BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
664 /* Check if instance is valid */
665 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
666
667 if (Instance >= USBPD_PWR_INSTANCES_NBR)
668 {
669 ret = BSP_ERROR_WRONG_PARAM;
670 }
671 return ret;
672 /* USER CODE END BSP_USBPD_PWR_SetVBUSDisconnectionThreshold */
673}
674
675/**
676 * @brief Register USB Type-C Current callback function.
677 * @note Callback function invoked when VBUS rises above 4V (VBUS present) or
678 * when VBUS falls below programmed threshold (VBUS absent).
679 * @note Callback function is un-registered when callback function pointer
680 * argument is NULL.
681 * @param Instance Type-C port identifier
682 * This parameter can be take one of the following values:
683 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
684 * @param pfnVBUSDetectCallback callback function pointer
685 * @retval BSP status
686 */
687__weak int32_t BSP_USBPD_PWR_RegisterVBUSDetectCallback(uint32_t Instance,
688 USBPD_PWR_VBUSDetectCallbackFunc *pfnVBUSDetectCallback)
689{
690 /* USER CODE BEGIN BSP_USBPD_PWR_RegisterVBUSDetectCallback */
691 /* Check if instance is valid */
692 int32_t ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
693
694 if (Instance >= USBPD_PWR_INSTANCES_NBR)
695 {
696 ret = BSP_ERROR_WRONG_PARAM;
697 }
698 return ret;
699 /* USER CODE END BSP_USBPD_PWR_RegisterVBUSDetectCallback */
700}
701
702/**
703 * @brief Get actual VBUS status.
704 * @param Instance Type-C port identifier
705 * This parameter can be take one of the following values:
706 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
707 * @param pState VBUS status (1: On, 0: Off)
708 * @retval BSP status
709 */
710__weak int32_t BSP_USBPD_PWR_VBUSIsOn(uint32_t Instance, uint8_t *pState)
711{
712 /* USER CODE BEGIN BSP_USBPD_PWR_VBUSIsOn */
713 /* Check if instance is valid */
714 int32_t ret;
715 uint8_t state = 0U;
716
717 if (Instance >= USBPD_PWR_INSTANCES_NBR)
718 {
719 ret = BSP_ERROR_WRONG_PARAM;
720 }
721 else
722 {
723 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
724 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VBUSIsOn");
725 }
726 *pState = state;
727 return ret;
728 /* USER CODE END BSP_USBPD_PWR_VBUSIsOn */
729}
730
731/**
732 * @brief Set state of VCC (specific functions)
733 * @param Instance Type-C port identifier
734 * This parameter can be take one of the following values:
735 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
736 * @param State VCC state
737 * @retval BSP status
738 */
739__weak int32_t BSP_USBPD_PWR_VCCSetState(uint32_t Instance, uint32_t State)
740{
741 /* USER CODE BEGIN BSP_USBPD_PWR_VCCSetState */
742 /* Check if instance is valid */
743 int32_t ret = BSP_ERROR_NONE;
744
745 if (Instance >= USBPD_PWR_INSTANCES_NBR)
746 {
747 ret = BSP_ERROR_WRONG_PARAM;
748 }
749 else
750 {
751 ret = BSP_ERROR_FEATURE_NOT_SUPPORTED;
752 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_VCCSetState");
753 }
754 return ret;
755 /* USER CODE END BSP_USBPD_PWR_VCCSetState */
756}
757
758/**
759 * @brief USBPD PWR callback used to notify a asynchronous PWR event.
760 * (This callback caould be called fromp an IT routine, associated to
761 * any PWR related event detection mechanism)
762 * @param Instance Type-C port identifier
763 * This parameter can be take one of the following values:
764 * @arg @ref USBPD_PWR_TYPE_C_PORT_1
765 * @retval None
766 */
767__weak void BSP_USBPD_PWR_EventCallback(uint32_t Instance)
768{
769 /* USER CODE BEGIN BSP_USBPD_PWR_EventCallback */
770 PWR_DEBUG_TRACE(Instance, "ADVICE: Update BSP_USBPD_PWR_EventCallback");
771 /* USER CODE END BSP_USBPD_PWR_EventCallback */
772}
773
774/**
775 * @}
776 */
777
778/** @addtogroup POWER_Private_Functions
779 * @{
780 */
781
782/* USER CODE BEGIN POWER_Private_Functions */
783
784/* USER CODE END POWER_Private_Functions */
785
786/**
787 * @}
788 */
789
790/**
791 * @}
792 */
793
794/**
795 * @}
796 */
797
798/**
799 * @}
800 */
801
Note: See TracBrowser for help on using the repository browser.