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