Changeset 65 for trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c
- Timestamp:
- Apr 2, 2026, 3:56:21 PM (5 weeks ago)
- File:
-
- 1 edited
-
trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/USBPD/Target/usbpd_dpm_user.c
r59 r65 36 36 #endif /* _TRACE */ 37 37 /* USER CODE BEGIN Includes */ 38 38 #ifdef DEBUG 39 #include <stdio.h> 40 #endif 39 41 /* USER CODE END Includes */ 40 42 … … 182 184 void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State) 183 185 { 184 /* USER CODE BEGIN USBPD_DPM_UserCableDetection */ 185 DPM_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 */ 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 */ 212 229 } 213 230 … … 241 258 { 242 259 /* 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 } 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 } 282 284 /* USER CODE END USBPD_DPM_Notification */ 283 285 } … … 295 297 DPM_USER_DEBUG_TRACE(PortNum, "ADVICE: update USBPD_DPM_HardReset"); 296 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 */ 297 311 } 298 312 … … 308 322 { 309 323 /* 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 } 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 } 335 351 /* USER CODE END USBPD_DPM_GetDataInfo */ 336 352 } … … 383 399 384 400 /** 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 */ 391 void 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 */ 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 */ 396 420 } 397 421 … … 827 851 USBPD_StatusTypeDef USBPD_DPM_RequestGetSinkCapabilityExt(uint8_t PortNum) 828 852 { 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; 853 DPM_USER_ERROR_TRACE(PortNum, USBPD_ERROR, "GET_SINK_CAPA_EXT not accepted by the stack"); 854 return USBPD_ERROR; 832 855 } 833 856
Note:
See TracChangeset
for help on using the changeset viewer.
