source: trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c@ 64

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

Added more USBPD-stack files.

File size: 35.3 KB
Line 
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file usbpd_dpm_user.c
5 * @author MCD Application Team
6 * @brief USBPD DPM 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#define USBPD_DPM_USER_C
22/* Includes ------------------------------------------------------------------*/
23#include "main.h"
24#include "usbpd_core.h"
25#include "usbpd_dpm_user.h"
26#include "usbpd_pdo_defs.h"
27#include "usbpd_dpm_core.h"
28#include "usbpd_dpm_conf.h"
29#include "usbpd_vdm_user.h"
30#include "usbpd_pwr_if.h"
31#include "usbpd_pwr_user.h"
32#if defined(_TRACE)
33#include "usbpd_trace.h"
34#include "string.h"
35#include "stdio.h"
36#endif /* _TRACE */
37/* USER CODE BEGIN Includes */
38
39/* USER CODE END Includes */
40
41/** @addtogroup STM32_USBPD_APPLICATION
42 * @{
43 */
44
45/** @addtogroup STM32_USBPD_APPLICATION_DPM_USER
46 * @{
47 */
48
49/* Private typedef -----------------------------------------------------------*/
50/* USER CODE BEGIN Private_Typedef */
51
52/* USER CODE END Private_Typedef */
53
54/* Private define ------------------------------------------------------------*/
55/** @defgroup USBPD_USER_PRIVATE_DEFINES USBPD USER Private Defines
56 * @{
57 */
58/* USER CODE BEGIN Private_Define */
59
60/* USER CODE END Private_Define */
61
62/**
63 * @}
64 */
65
66/* Private macro -------------------------------------------------------------*/
67/** @defgroup USBPD_USER_PRIVATE_MACROS USBPD USER Private Macros
68 * @{
69 */
70#if defined(_TRACE)
71#define DPM_USER_DEBUG_TRACE_SIZE 50u
72#define DPM_USER_DEBUG_TRACE(_PORT_, ...) do { \
73 char _str[DPM_USER_DEBUG_TRACE_SIZE]; \
74 uint8_t _size = snprintf(_str, DPM_USER_DEBUG_TRACE_SIZE, __VA_ARGS__); \
75 if (_size < DPM_USER_DEBUG_TRACE_SIZE) \
76 USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, strlen(_str)); \
77 else \
78 USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, DPM_USER_DEBUG_TRACE_SIZE); \
79 } while(0)
80
81#define DPM_USER_ERROR_TRACE(_PORT_, _STATUS_, ...) do { \
82 if (USBPD_OK != _STATUS_) { \
83 char _str[DPM_USER_DEBUG_TRACE_SIZE]; \
84 uint8_t _size = snprintf(_str, DPM_USER_DEBUG_TRACE_SIZE, __VA_ARGS__); \
85 if (_size < DPM_USER_DEBUG_TRACE_SIZE) \
86 USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, strlen(_str)); \
87 else \
88 USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (uint8_t)(_PORT_), 0, (uint8_t*)_str, DPM_USER_DEBUG_TRACE_SIZE); \
89 } \
90 } while(0)
91#else
92#define DPM_USER_DEBUG_TRACE(_PORT_, ...)
93#define DPM_USER_ERROR_TRACE(_PORT_, _STATUS_, ...)
94#endif /* _TRACE */
95/* USER CODE BEGIN Private_Macro */
96
97/* USER CODE END Private_Macro */
98/**
99 * @}
100 */
101
102/* Private variables ---------------------------------------------------------*/
103/** @defgroup USBPD_USER_PRIVATE_VARIABLES USBPD USER Private Variables
104 * @{
105 */
106
107/* USER CODE BEGIN Private_Variables */
108
109/* USER CODE END Private_Variables */
110/**
111 * @}
112 */
113
114/* Private function prototypes -----------------------------------------------*/
115/** @defgroup USBPD_USER_PRIVATE_FUNCTIONS USBPD USER Private Functions
116 * @{
117 */
118/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
119
120/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
121/**
122 * @}
123 */
124
125/* Exported functions ------- ------------------------------------------------*/
126/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS USBPD USER Exported Functions
127 * @{
128 */
129/* USER CODE BEGIN USBPD_USER_EXPORTED_FUNCTIONS */
130
131void USBPD_PE_SNK_EvaluateCapabilities(uint8_t PortNum, uint32_t* RequestData, USBPD_CORE_PDO_Type_TypeDef* PtrPowerObject){ }
132void USBPD_PE_PowerRoleSwap(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_PRS_Status_TypeDef Status) {}
133
134/* USER CODE END USBPD_USER_EXPORTED_FUNCTIONS */
135
136/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 USBPD USER Exported Functions called by DPM CORE
137 * @{
138 */
139/* USER CODE BEGIN USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 */
140
141/* USER CODE END USBPD_USER_EXPORTED_FUNCTIONS_GROUP1 */
142
143/**
144 * @brief Initialize DPM (port power role, PWR_IF, CAD and PE Init procedures)
145 * @retval USBPD Status
146 */
147USBPD_StatusTypeDef USBPD_DPM_UserInit(void)
148{
149/* USER CODE BEGIN USBPD_DPM_UserInit */
150 return USBPD_OK;
151/* USER CODE END USBPD_DPM_UserInit */
152}
153
154/**
155 * @brief User delay implementation which is OS dependent
156 * @param Time time in ms
157 * @retval None
158 */
159void USBPD_DPM_WaitForTime(uint32_t Time)
160{
161 HAL_Delay(Time);
162}
163
164/**
165 * @brief User processing time, it is recommended to avoid blocking task for long time
166 * @param argument DPM User event
167 * @retval None
168 */
169void USBPD_DPM_UserExecute(void const *argument)
170{
171/* USER CODE BEGIN USBPD_DPM_UserExecute */
172
173/* USER CODE END USBPD_DPM_UserExecute */
174}
175
176/**
177 * @brief UserCableDetection reporting events on a specified port from CAD layer.
178 * @param PortNum The handle of the port
179 * @param State CAD state
180 * @retval None
181 */
182void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State)
183{
184/* USER CODE BEGIN USBPD_DPM_UserCableDetection */
185DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_UserCableDetection");
186 // switch(State)
187 // {
188 // case USBPD_CAD_EVENT_ATTACHED:
189 // case USBPD_CAD_EVENT_ATTEMC:
190 // {
191 // if (USBPD_OK != USBPD_PWR_IF_VBUSEnable(PortNum))
192 // {
193 // /* Should not occur */
194 // HAL_Delay(6000);
195 // NVIC_SystemReset();
196 // }
197 // break;
198 // }
199 // case USBPD_CAD_EVENT_DETACHED :
200 // case USBPD_CAD_EVENT_EMC :
201 // default :
202 // {
203 // if (USBPD_OK != USBPD_PWR_IF_VBUSDisable(PortNum))
204 // {
205 // /* Should not occur */
206 // while(1);
207 // }
208 // break;
209 // }
210 // }
211/* USER CODE END USBPD_DPM_UserCableDetection */
212}
213
214/**
215 * @brief function used to manage user timer.
216 * @param PortNum Port number
217 * @retval None
218 */
219void USBPD_DPM_UserTimerCounter(uint8_t PortNum)
220{
221/* USER CODE BEGIN USBPD_DPM_UserTimerCounter */
222
223/* USER CODE END USBPD_DPM_UserTimerCounter */
224}
225
226/**
227 * @}
228 */
229
230/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP2 USBPD USER Exported Callbacks functions called by PE
231 * @{
232 */
233
234/**
235 * @brief Callback function called by PE to inform DPM about PE event.
236 * @param PortNum The current port number
237 * @param EventVal @ref USBPD_NotifyEventValue_TypeDef
238 * @retval None
239 */
240void USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal)
241{
242/* USER CODE BEGIN USBPD_DPM_Notification */
243 /* Manage event notified by the stack? */
244 switch(EventVal)
245 {
246// case USBPD_NOTIFY_POWER_EXPLICIT_CONTRACT :
247// break;
248// case USBPD_NOTIFY_REQUEST_ACCEPTED:
249// break;
250// case USBPD_NOTIFY_REQUEST_REJECTED:
251// case USBPD_NOTIFY_REQUEST_WAIT:
252// break;
253// case USBPD_NOTIFY_POWER_SWAP_TO_SNK_DONE:
254// break;
255// case USBPD_NOTIFY_STATE_SNK_READY:
256// break;
257// case USBPD_NOTIFY_HARDRESET_RX:
258// case USBPD_NOTIFY_HARDRESET_TX:
259// break;
260// case USBPD_NOTIFY_STATE_SRC_DISABLED:
261// break;
262// case USBPD_NOTIFY_ALERT_RECEIVED :
263// break;
264// case USBPD_NOTIFY_CABLERESET_REQUESTED :
265// break;
266// case USBPD_NOTIFY_MSG_NOT_SUPPORTED :
267// break;
268// case USBPD_NOTIFY_PE_DISABLED :
269// break;
270// case USBPD_NOTIFY_USBSTACK_START:
271// break;
272// case USBPD_NOTIFY_USBSTACK_STOP:
273// break;
274// case USBPD_NOTIFY_DATAROLESWAP_DFP :
275// break;
276// case USBPD_NOTIFY_DATAROLESWAP_UFP :
277// break;
278 default:
279 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: USBPD_DPM_Notification:%d", EventVal);
280 break;
281 }
282/* USER CODE END USBPD_DPM_Notification */
283}
284
285/**
286 * @brief Callback function called by PE layer when HardReset message received from PRL
287 * @param PortNum The current port number
288 * @param CurrentRole the current role
289 * @param Status status on hard reset event
290 * @retval None
291 */
292void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status)
293{
294/* USER CODE BEGIN USBPD_DPM_HardReset */
295 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_HardReset");
296/* USER CODE END USBPD_DPM_HardReset */
297}
298
299/**
300 * @brief DPM callback to allow PE to retrieve information from DPM/PWR_IF.
301 * @param PortNum Port number
302 * @param DataId Type of data to be updated in DPM based on @ref USBPD_CORE_DataInfoType_TypeDef
303 * @param Ptr Pointer on address where DPM data should be written (u8 pointer)
304 * @param Size Pointer on nb of u8 written by DPM
305 * @retval None
306 */
307void USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size)
308{
309/* USER CODE BEGIN USBPD_DPM_GetDataInfo */
310 /* Check type of information targeted by request */
311 switch(DataId)
312 {
313// case USBPD_CORE_DATATYPE_REQ_VOLTAGE: /*!< Get voltage value requested for BIST tests, expect 5V*/
314// *Size = 4;
315// (void)memcpy((uint8_t *)Ptr, (uint8_t *)&DPM_Ports[PortNum].DPM_RequestedVoltage, *Size);
316 // break;
317// case USBPD_CORE_DATATYPE_SRC_PDO: /*!< Handling of port Source PDO */
318 // break;
319// case USBPD_CORE_PPS_STATUS: /*!< PPS Status message content */
320 // break;
321// case USBPD_CORE_SNK_EXTENDED_CAPA: /*!< Retrieve of Sink Extended capability message content*/
322 // break;
323// case USBPD_CORE_INFO_STATUS: /*!< Information status message content */
324 // break;
325// case USBPD_CORE_MANUFACTURER_INFO: /*!< Retrieve of Manufacturer info message content */
326 // break;
327// case USBPD_CORE_BATTERY_STATUS: /*!< Retrieve of Battery status message content */
328 // break;
329// case USBPD_CORE_BATTERY_CAPABILITY: /*!< Retrieve of Battery capability message content */
330 // break;
331 default:
332 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_GetDataInfo:%d", DataId);
333 break;
334 }
335/* USER CODE END USBPD_DPM_GetDataInfo */
336}
337
338/**
339 * @brief DPM callback to allow PE to update information in DPM/PWR_IF.
340 * @param PortNum Port number
341 * @param DataId Type of data to be updated in DPM based on @ref USBPD_CORE_DataInfoType_TypeDef
342 * @param Ptr Pointer on the data
343 * @param Size Nb of bytes to be updated in DPM
344 * @retval None
345 */
346void USBPD_DPM_SetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t Size)
347{
348/* USER CODE BEGIN USBPD_DPM_SetDataInfo */
349 /* Check type of information targeted by request */
350 switch(DataId)
351 {
352// case USBPD_CORE_DATATYPE_RDO_POSITION: /*!< Reset the PDO position selected by the sink only */
353 // break;
354// case USBPD_CORE_DATATYPE_RCV_SRC_PDO: /*!< Storage of Received Source PDO values */
355 // break;
356// case USBPD_CORE_DATATYPE_RCV_SNK_PDO: /*!< Storage of Received Sink PDO values */
357 // break;
358 // case USBPD_CORE_DATATYPE_RCV_REQ_PDO : /*!< Storage of Received Sink Request PDO value */
359 // if (Size == 4)
360 // {
361 // memcpy((uint8_t *)&DPM_Ports[PortNum].DPM_RcvRequestDOMsg, Ptr, 4);
362 // }
363 // break;
364// case USBPD_CORE_INFO_STATUS: /*!< Information status message content */
365 // break;
366// case USBPD_CORE_ALERT: /*!< Storing of received Alert message content */
367 // break;
368// case USBPD_CORE_GET_MANUFACTURER_INFO: /*!< Storing of received Get Manufacturer info message content */
369 // break;
370// case USBPD_CORE_GET_BATTERY_STATUS: /*!< Storing of received Get Battery status message content */
371 // break;
372// case USBPD_CORE_GET_BATTERY_CAPABILITY: /*!< Storing of received Get Battery capability message content*/
373 // break;
374// case USBPD_CORE_SNK_EXTENDED_CAPA: /*!< Storing of Sink Extended capability message content */
375 // break;
376 default:
377 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_SetDataInfo:%d", DataId);
378 break;
379 }
380/* USER CODE END USBPD_DPM_SetDataInfo */
381
382}
383
384/**
385 * @brief Evaluate received Capabilities Message from Source port and prepare the request message
386 * @param PortNum Port number
387 * @param PtrRequestData Pointer on selected request data object
388 * @param PtrPowerObjectType Pointer on the power data object
389 * @retval None
390 */
391void USBPD_DPM_SNK_EvaluateCapabilities(uint8_t PortNum, uint32_t *PtrRequestData, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObjectType)
392{
393/* USER CODE BEGIN USBPD_DPM_SNK_EvaluateCapabilities */
394 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_SNK_EvaluateCapabilities");
395/* USER CODE END USBPD_DPM_SNK_EvaluateCapabilities */
396}
397
398/**
399 * @brief Callback to be used by PE to evaluate a Vconn swap
400 * @param PortNum Port number
401 * @retval USBPD_ACCEPT, USBPD_REJECT, USBPD_WAIT
402 */
403USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum)
404{
405/* USER CODE BEGIN USBPD_DPM_EvaluateVconnSwap */
406 USBPD_StatusTypeDef status = USBPD_REJECT;
407 if (USBPD_TRUE == DPM_USER_Settings[PortNum].PE_VconnSwap)
408 {
409 status = USBPD_ACCEPT;
410 }
411
412 return status;
413/* USER CODE END USBPD_DPM_EvaluateVconnSwap */
414}
415
416/**
417 * @brief Callback to be used by PE to manage VConn
418 * @param PortNum Port number
419 * @param State Enable or Disable VConn on CC lines
420 * @retval USBPD_ACCEPT, USBPD_REJECT
421 */
422USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State)
423{
424/* USER CODE BEGIN USBPD_DPM_PE_VconnPwr */
425 return USBPD_ERROR;
426/* USER CODE END USBPD_DPM_PE_VconnPwr */
427}
428
429/**
430 * @brief DPM callback to allow PE to forward extended message information.
431 * @param PortNum Port number
432 * @param MsgType Type of message to be handled in DPM
433 * This parameter can be one of the following values:
434 * @arg @ref USBPD_EXT_SECURITY_REQUEST Security Request extended message
435 * @arg @ref USBPD_EXT_SECURITY_RESPONSE Security Response extended message
436 * @param ptrData Pointer on address Extended Message data could be read (u8 pointer)
437 * @param DataSize Nb of u8 that compose Extended message
438 * @retval None
439 */
440void USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize)
441{
442/* USER CODE BEGIN USBPD_DPM_ExtendedMessageReceived */
443
444/* USER CODE END USBPD_DPM_ExtendedMessageReceived */
445}
446
447/**
448 * @brief DPM callback to allow PE to enter ERROR_RECOVERY state.
449 * @param PortNum Port number
450 * @retval None
451 */
452void USBPD_DPM_EnterErrorRecovery(uint8_t PortNum)
453{
454/* USER CODE BEGIN USBPD_DPM_EnterErrorRecovery */
455 /* Inform CAD to enter recovery mode */
456 USBPD_CAD_EnterErrorRecovery(PortNum);
457/* USER CODE END USBPD_DPM_EnterErrorRecovery */
458}
459
460/**
461 * @brief Callback used to ask application the reply status for a DataRoleSwap request
462 * @note if the callback is not set (ie NULL) the stack will automatically reject the request
463 * @param PortNum Port number
464 * @retval Returned values are:
465 @ref USBPD_ACCEPT if DRS can be accepted
466 @ref USBPD_REJECT if DRS is not accepted in one data role (DFP or UFP) or in PD2.0 config
467 @ref USBPD_NOTSUPPORTED if DRS is not supported at all by the application (in both data roles) - P3.0 only
468 */
469USBPD_StatusTypeDef USBPD_DPM_EvaluateDataRoleSwap(uint8_t PortNum)
470{
471/* USER CODE BEGIN USBPD_DPM_EvaluateDataRoleSwap */
472 USBPD_StatusTypeDef status = USBPD_REJECT;
473 /* Sent NOT_SUPPORTED if DRS is not supported at all by the application (in both data roles) - P3.0 only */
474 if ((USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DataSwap)
475 || ((USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_DFP)
476 && (USBPD_FALSE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_UFP)))
477 {
478 status = USBPD_NOTSUPPORTED;
479 }
480 else
481 {
482 /* ACCEPT DRS if at least supported by 1 data role */
483 if (((USBPD_TRUE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_DFP) && (USBPD_PORTDATAROLE_UFP == DPM_Params[PortNum].PE_DataRole))
484 || ((USBPD_TRUE == DPM_USER_Settings[PortNum].PE_DR_Swap_To_UFP) && (USBPD_PORTDATAROLE_DFP == DPM_Params[PortNum].PE_DataRole)))
485 {
486 status = USBPD_ACCEPT;
487 }
488 }
489 return status;
490/* USER CODE END USBPD_DPM_EvaluateDataRoleSwap */
491}
492
493/**
494 * @brief Callback to be used by PE to check is VBUS is ready or present
495 * @param PortNum Port number
496 * @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
497 * @retval USBPD_DISABLE or USBPD_ENABLE
498 */
499USBPD_FunctionalState USBPD_DPM_IsPowerReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe)
500{
501/* USER CODE BEGIN USBPD_DPM_IsPowerReady */
502 return ((USBPD_OK == USBPD_PWR_IF_SupplyReady(PortNum, Vsafe)) ? USBPD_ENABLE : USBPD_DISABLE);
503/* USER CODE END USBPD_DPM_IsPowerReady */
504}
505
506/**
507 * @}
508 */
509
510/** @defgroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP3 USBPD USER Functions PD messages requests
511 * @{
512 */
513
514/**
515 * @brief Request the PE to send a hard reset
516 * @param PortNum The current port number
517 * @retval USBPD Status
518 */
519USBPD_StatusTypeDef USBPD_DPM_RequestHardReset(uint8_t PortNum)
520{
521 USBPD_StatusTypeDef _status = USBPD_PE_Request_HardReset(PortNum);
522 DPM_USER_ERROR_TRACE(PortNum, _status, "HARD RESET not accepted by the stack");
523 return _status;
524}
525
526/**
527 * @brief Request the PE to send a cable reset.
528 * @note Only a DFP Shall generate Cable Reset Signaling. A DFP Shall only generate Cable Reset Signaling within an Explicit Contract.
529 The DFP has to be supplying VCONN prior to a Cable Reset
530 * @param PortNum The current port number
531 * @retval USBPD Status
532 */
533USBPD_StatusTypeDef USBPD_DPM_RequestCableReset(uint8_t PortNum)
534{
535 USBPD_StatusTypeDef _status = USBPD_PE_Request_CableReset(PortNum);
536 DPM_USER_ERROR_TRACE(PortNum, _status, "CABLE RESET not accepted by the stack");
537 return _status;
538}
539
540/**
541 * @brief Request the PE to send a GOTOMIN message
542 * @param PortNum The current port number
543 * @retval USBPD Status
544 */
545USBPD_StatusTypeDef USBPD_DPM_RequestGotoMin(uint8_t PortNum)
546{
547 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GOTOMIN, USBPD_SOPTYPE_SOP);
548 DPM_USER_ERROR_TRACE(PortNum, _status, "GOTOMIN not accepted by the stack");
549 return _status;
550}
551
552/**
553 * @brief Request the PE to send a PING message
554 * @note In USB-PD stack, only ping management for P3.0 is implemented.
555 * If PD2.0 is used, PING timer needs to be implemented on user side.
556 * @param PortNum The current port number
557 * @retval USBPD Status
558 */
559USBPD_StatusTypeDef USBPD_DPM_RequestPing(uint8_t PortNum)
560{
561 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_PING, USBPD_SOPTYPE_SOP);
562 DPM_USER_ERROR_TRACE(PortNum, _status, "PING not accepted by the stack");
563 return _status;
564}
565
566/**
567 * @brief Request the PE to send a request message.
568 * @param PortNum The current port number
569 * @param IndexSrcPDO Index on the selected SRC PDO (value between 1 to 7)
570 * @param RequestedVoltage Requested voltage (in MV and use mainly for APDO)
571 * @retval USBPD Status
572 */
573USBPD_StatusTypeDef USBPD_DPM_RequestMessageRequest(uint8_t PortNum, uint8_t IndexSrcPDO, uint16_t RequestedVoltage)
574{
575 USBPD_StatusTypeDef _status = USBPD_ERROR;
576/* USER CODE BEGIN USBPD_DPM_RequestMessageRequest */
577 /* To be adapted to call the PE function */
578 /* _status = USBPD_PE_Send_Request(PortNum, rdo.d32, pdo_object);*/
579 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_RequestMessageRequest");
580/* USER CODE END USBPD_DPM_RequestMessageRequest */
581 DPM_USER_ERROR_TRACE(PortNum, _status, "REQUEST not accepted by the stack");
582 return _status;
583}
584
585/**
586 * @brief Request the PE to send a GET_SRC_CAPA message
587 * @param PortNum The current port number
588 * @retval USBPD Status
589 */
590USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapability(uint8_t PortNum)
591{
592 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SRC_CAP, USBPD_SOPTYPE_SOP);
593 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SRC_CAPA not accepted by the stack");
594 return _status;
595}
596
597/**
598 * @brief Request the PE to send a GET_SNK_CAPA message
599 * @param PortNum The current port number
600 * @retval USBPD Status
601 */
602USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapability(uint8_t PortNum)
603{
604 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SNK_CAP, USBPD_SOPTYPE_SOP);
605 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SINK_CAPA not accepted by the stack");
606 return _status;
607}
608
609/**
610 * @brief Request the PE to perform a Data Role Swap.
611 * @param PortNum The current port number
612 * @retval USBPD Status
613 */
614USBPD_StatusTypeDef USBPD_DPM_RequestDataRoleSwap(uint8_t PortNum)
615{
616 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_DR_SWAP, USBPD_SOPTYPE_SOP);
617 DPM_USER_ERROR_TRACE(PortNum, _status, "DRS not accepted by the stack");
618 return _status;
619}
620
621/**
622 * @brief Request the PE to perform a Power Role Swap.
623 * @param PortNum The current port number
624 * @retval USBPD Status
625 */
626USBPD_StatusTypeDef USBPD_DPM_RequestPowerRoleSwap(uint8_t PortNum)
627{
628 DPM_USER_ERROR_TRACE(PortNum, USBPD_ERROR, "PRS not accepted by the stack");
629 return USBPD_ERROR;
630}
631
632/**
633 * @brief Request the PE to perform a VCONN Swap.
634 * @param PortNum The current port number
635 * @retval USBPD Status
636 */
637USBPD_StatusTypeDef USBPD_DPM_RequestVconnSwap(uint8_t PortNum)
638{
639 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_VCONN_SWAP, USBPD_SOPTYPE_SOP);
640 DPM_USER_ERROR_TRACE(PortNum, _status, "VCS not accepted by the stack");
641 return _status;
642}
643
644/**
645 * @brief Request the PE to send a soft reset
646 * @param PortNum The current port number
647 * @param SOPType SOP Type based on @ref USBPD_SOPType_TypeDef
648 * @retval USBPD Status
649 */
650USBPD_StatusTypeDef USBPD_DPM_RequestSoftReset(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
651{
652 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_SOFT_RESET, SOPType);
653 DPM_USER_ERROR_TRACE(PortNum, _status, "SOFT_RESET not accepted by the stack");
654 return _status;
655}
656
657/**
658 * @brief Request the PE to send a Source Capability message.
659 * @param PortNum The current port number
660 * @retval USBPD Status
661 */
662USBPD_StatusTypeDef USBPD_DPM_RequestSourceCapability(uint8_t PortNum)
663{
664 /* PE will directly get the PDO saved in structure @ref PWR_Port_PDO_Storage */
665 USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_SRC_CAPABILITIES, NULL);
666 DPM_USER_ERROR_TRACE(PortNum, _status, "SRC_CAPA not accepted by the stack");
667 return _status;
668}
669
670/**
671 * @brief Request the PE to send a VDM discovery identity
672 * @param PortNum The current port number
673 * @param SOPType SOP Type
674 * @retval USBPD Status
675 */
676USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryIdentify(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
677{
678 USBPD_StatusTypeDef _status = USBPD_ERROR;
679/* USER CODE BEGIN USBPD_DPM_RequestVDM_DiscoveryIdentify */
680 if (USBPD_SOPTYPE_SOP == SOPType)
681 {
682 _status = USBPD_PE_SVDM_RequestIdentity(PortNum, SOPType);
683 }
684/* USER CODE END USBPD_DPM_RequestVDM_DiscoveryIdentify */
685 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM Discovery Ident not accepted by the stack");
686 return _status;
687}
688
689/**
690 * @brief Request the PE to send a VDM discovery SVID
691 * @param PortNum The current port number
692 * @param SOPType SOP Type
693 * @retval USBPD Status
694 */
695USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoverySVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType)
696{
697 USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestSVID(PortNum, SOPType);
698 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM discovery SVID not accepted by the stack");
699 return _status;
700}
701
702/**
703 * @brief Request the PE to perform a VDM Discovery mode message on one SVID.
704 * @param PortNum The current port number
705 * @param SOPType SOP Type
706 * @param SVID SVID used for discovery mode message
707 * @retval USBPD Status
708 */
709USBPD_StatusTypeDef USBPD_DPM_RequestVDM_DiscoveryMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID)
710{
711 USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestMode(PortNum, SOPType, SVID);
712 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM Discovery mode not accepted by the stack");
713 return _status;
714}
715
716/**
717 * @brief Request the PE to perform a VDM mode enter.
718 * @param PortNum The current port number
719 * @param SOPType SOP Type
720 * @param SVID SVID used for discovery mode message
721 * @param ModeIndex Index of the mode to be entered
722 * @retval USBPD Status
723 */
724USBPD_StatusTypeDef USBPD_DPM_RequestVDM_EnterMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex)
725{
726 USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestModeEnter(PortNum, SOPType, SVID, ModeIndex);
727 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM mode enter not accepted by the stack");
728 return _status;
729}
730
731/**
732 * @brief Request the PE to perform a VDM mode exit.
733 * @param PortNum The current port number
734 * @param SOPType SOP Type
735 * @param SVID SVID used for discovery mode message
736 * @param ModeIndex Index of the mode to be exit
737 * @retval USBPD Status
738 */
739USBPD_StatusTypeDef USBPD_DPM_RequestVDM_ExitMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint8_t ModeIndex)
740{
741 USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestModeExit(PortNum, SOPType, SVID, ModeIndex);
742 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM mode exit not accepted by the stack");
743 return _status;
744}
745
746/**
747 * @brief Request the PE to send a Display Port status
748 * @param PortNum The current port number
749 * @param SOPType SOP Type
750 * @param SVID Used SVID
751 * @param pDPStatus Pointer on DP Status data (32 bit)
752 * @retval USBPD Status
753 */
754USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortStatus(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPStatus)
755{
756 USBPD_StatusTypeDef _status;
757/* USER CODE BEGIN USBPD_DPM_RequestDisplayPortStatus */
758 /*USBPD_VDM_FillDPStatus(PortNum, (USBPD_DPStatus_TypeDef*)pDPStatus);*/
759/* USER CODE END USBPD_DPM_RequestDisplayPortStatus */
760 _status = USBPD_PE_SVDM_RequestSpecific(PortNum, SOPType, SVDM_SPECIFIC_1, SVID);
761 DPM_USER_ERROR_TRACE(PortNum, _status, "Display Port status not accepted by the stack");
762 return _status;
763}
764/**
765 * @brief Request the PE to send a Display Port Config
766 * @param PortNum The current port number
767 * @param SOPType SOP Type
768 * @param SVID Used SVID
769 * @param pDPConfig Pointer on DP Config data (32 bit)
770 * @retval USBPD Status
771 */
772USBPD_StatusTypeDef USBPD_DPM_RequestDisplayPortConfig(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID, uint32_t *pDPConfig)
773{
774 USBPD_StatusTypeDef _status;
775/* USER CODE BEGIN USBPD_DPM_RequestDisplayPortConfig */
776 /*USBPD_VDM_FillDPConfig(PortNum, (USBPD_DPConfig_TypeDef*)pDPConfig);*/
777/* USER CODE END USBPD_DPM_RequestDisplayPortConfig */
778 _status = USBPD_PE_SVDM_RequestSpecific(PortNum, SOPType, SVDM_SPECIFIC_2, SVID);
779 DPM_USER_ERROR_TRACE(PortNum, _status, "Display Port Config not accepted by the stack");
780 return _status;
781}
782
783/**
784 * @brief Request the PE to perform a VDM Attention.
785 * @param PortNum The current port number
786 * @param SOPType SOP Type
787 * @param SVID Used SVID
788 * @retval USBPD Status
789 */
790USBPD_StatusTypeDef USBPD_DPM_RequestAttention(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint16_t SVID)
791{
792 USBPD_StatusTypeDef _status = USBPD_PE_SVDM_RequestAttention(PortNum, SOPType, SVID);
793 DPM_USER_ERROR_TRACE(PortNum, _status, "VDM ATTENTION not accepted by the stack");
794 return _status;
795}
796
797/**
798 * @brief Request the PE to send an ALERT to port partner
799 * @param PortNum The current port number
800 * @param Alert Alert based on @ref USBPD_ADO_TypeDef
801 * @retval USBPD Status
802 */
803USBPD_StatusTypeDef USBPD_DPM_RequestAlert(uint8_t PortNum, USBPD_ADO_TypeDef Alert)
804{
805 USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_ALERT, (uint32_t*)&Alert.d32);
806 DPM_USER_ERROR_TRACE(PortNum, _status, "ALERT not accepted by the stack");
807 return _status;
808}
809
810/**
811 * @brief Request the PE to get a source capability extended
812 * @param PortNum The current port number
813 * @retval USBPD Status
814 */
815USBPD_StatusTypeDef USBPD_DPM_RequestGetSourceCapabilityExt(uint8_t PortNum)
816{
817 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SRC_CAPEXT, USBPD_SOPTYPE_SOP);
818 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SRC_CAPA_EXT not accepted by the stack");
819 return _status;
820}
821
822/**
823 * @brief Request the PE to get a sink capability extended
824 * @param PortNum The current port number
825 * @retval USBPD Status
826 */
827USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum)
828{
829 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_SNK_CAPEXT, USBPD_SOPTYPE_SOP);
830 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_SINK_CAPA_EXT not accepted by the stack");
831 return _status;
832}
833
834/**
835 * @brief Request the PE to get a manufacturer info
836 * @param PortNum The current port number
837 * @param SOPType SOP Type
838 * @param pManuInfoData Pointer on manufacturer info based on @ref USBPD_GMIDB_TypeDef
839 * @retval USBPD Status
840 */
841USBPD_StatusTypeDef USBPD_DPM_RequestGetManufacturerInfo(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, uint8_t* pManuInfoData)
842{
843 USBPD_StatusTypeDef _status = USBPD_ERROR;
844 if (USBPD_SOPTYPE_SOP == SOPType)
845 {
846 _status = USBPD_PE_SendExtendedMessage(PortNum, SOPType, USBPD_EXT_GET_MANUFACTURER_INFO, (uint8_t*)pManuInfoData, sizeof(USBPD_GMIDB_TypeDef));
847 }
848 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_MANU_INFO not accepted by the stack");
849 return _status;
850}
851
852/**
853 * @brief Request the PE to request a GET_PPS_STATUS
854 * @param PortNum The current port number
855 * @retval USBPD Status
856 */
857USBPD_StatusTypeDef USBPD_DPM_RequestGetPPS_Status(uint8_t PortNum)
858{
859 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_PPS_STATUS, USBPD_SOPTYPE_SOP);
860 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_PPS_STATUS not accepted by the stack");
861 return _status;
862}
863
864/**
865 * @brief Request the PE to request a GET_STATUS
866 * @param PortNum The current port number
867 * @retval USBPD Status
868 */
869USBPD_StatusTypeDef USBPD_DPM_RequestGetStatus(uint8_t PortNum)
870{
871 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_STATUS, USBPD_SOPTYPE_SOP);
872 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_STATUS not accepted by the stack");
873 return _status;
874}
875
876/**
877 * @brief Request the PE to perform a Fast Role Swap.
878 * @param PortNum The current port number
879 * @retval USBPD Status
880 */
881USBPD_StatusTypeDef USBPD_DPM_RequestFastRoleSwap(uint8_t PortNum)
882{
883 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_FR_SWAP, USBPD_SOPTYPE_SOP);
884 DPM_USER_ERROR_TRACE(PortNum, _status, "FRS not accepted by the stack");
885 return _status;
886}
887
888/**
889 * @brief Request the PE to send a GET_COUNTRY_CODES message
890 * @param PortNum The current port number
891 * @retval USBPD Status
892 */
893USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryCodes(uint8_t PortNum)
894{
895 USBPD_StatusTypeDef _status = USBPD_PE_Request_CtrlMessage(PortNum, USBPD_CONTROLMSG_GET_COUNTRY_CODES, USBPD_SOPTYPE_SOP);
896 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_COUNTRY_CODES not accepted by the stack");
897 return _status;
898}
899
900/**
901 * @brief Request the PE to send a GET_COUNTRY_INFO message
902 * @param PortNum The current port number
903 * @param CountryCode Country code (1st character and 2nd of the Alpha-2 Country)
904 * @retval USBPD Status
905 */
906USBPD_StatusTypeDef USBPD_DPM_RequestGetCountryInfo(uint8_t PortNum, uint16_t CountryCode)
907{
908 USBPD_StatusTypeDef _status = USBPD_PE_Request_DataMessage(PortNum, USBPD_DATAMSG_GET_COUNTRY_INFO, (uint32_t*)&CountryCode);
909 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_COUNTRY_INFO not accepted by the stack");
910 return _status;
911}
912
913/**
914 * @brief Request the PE to send a GET_BATTERY_CAPA
915 * @param PortNum The current port number
916 * @param pBatteryCapRef Pointer on the Battery Capability reference
917 * @retval USBPD Status
918 */
919USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryCapability(uint8_t PortNum, uint8_t *pBatteryCapRef)
920{
921 USBPD_StatusTypeDef _status = USBPD_PE_SendExtendedMessage(PortNum, USBPD_SOPTYPE_SOP, USBPD_EXT_GET_BATTERY_CAP, (uint8_t*)pBatteryCapRef, 1);
922 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_BATTERY_CAPA not accepted by the stack");
923 return _status;
924}
925
926/**
927 * @brief Request the PE to send a GET_BATTERY_STATUS
928 * @param PortNum The current port number
929 * @param pBatteryStatusRef Pointer on the Battery Status reference
930 * @retval USBPD Status
931 */
932USBPD_StatusTypeDef USBPD_DPM_RequestGetBatteryStatus(uint8_t PortNum, uint8_t *pBatteryStatusRef)
933{
934 USBPD_StatusTypeDef _status = USBPD_PE_SendExtendedMessage(PortNum, USBPD_SOPTYPE_SOP, USBPD_EXT_GET_BATTERY_STATUS, (uint8_t*)pBatteryStatusRef, 1);
935 DPM_USER_ERROR_TRACE(PortNum, _status, "GET_BATTERY_STATUS not accepted by the stack");
936 return _status;
937}
938
939/**
940 * @brief Request the PE to send a SECURITY_REQUEST
941 * @param PortNum The current port number
942 * @retval USBPD Status
943 */
944USBPD_StatusTypeDef USBPD_DPM_RequestSecurityRequest(uint8_t PortNum)
945{
946 USBPD_StatusTypeDef _status = USBPD_ERROR;
947 DPM_USER_ERROR_TRACE(PortNum, _status, "SECURITY_REQUEST not accepted by the stack");
948 return _status;
949}
950
951/**
952 * @}
953 */
954
955/** @addtogroup USBPD_USER_PRIVATE_FUNCTIONS
956 * @{
957 */
958
959/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS */
960
961/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS */
962
963/**
964 * @}
965 */
966
967/**
968 * @}
969 */
970
971/**
972 * @}
973 */
974
975/**
976 * @}
977 */
Note: See TracBrowser for help on using the repository browser.