342 lines
10 KiB
C
342 lines
10 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file usbpd_pwr_if.c
|
|
* @author MCD Application Team
|
|
* @brief This file contains power interface control functions.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* This software component is licensed by ST under Ultimate Liberty license
|
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at:
|
|
* www.st.com/SLA0044
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
#define __USBPD_PWR_IF_C
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "usbpd_pwr_if.h"
|
|
#include "usbpd_hw_if.h"
|
|
#include "usbpd_pwr_if.h"
|
|
#include "usbpd_dpm_core.h"
|
|
#include "usbpd_dpm_conf.h"
|
|
#include "usbpd_pdo_defs.h"
|
|
#include "usbpd_core.h"
|
|
#include "usbpd_trace.h"
|
|
|
|
/* USER CODE BEGIN Include */
|
|
|
|
/* USER CODE END Include */
|
|
|
|
/** @addtogroup STM32_USBPD_APPLICATION
|
|
* @{
|
|
*/
|
|
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF
|
|
* @{
|
|
*/
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Private_Typedef */
|
|
|
|
/* USER CODE END Private_Typedef */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Defines
|
|
* @{
|
|
*/
|
|
/* USER CODE BEGIN Private_Define */
|
|
|
|
/* USER CODE END Private_Define */
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/* Private macros ------------------------------------------------------------*/
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Macros
|
|
* @{
|
|
*/
|
|
/* USER CODE BEGIN Private_Macro */
|
|
|
|
/* USER CODE END Private_Macro */
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Variables
|
|
* @{
|
|
*/
|
|
/* USER CODE BEGIN Private_Variables */
|
|
|
|
/* USER CODE END Private_Variables */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Functions
|
|
* @{
|
|
*/
|
|
|
|
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
|
|
|
/* Functions to initialize Source PDOs */
|
|
uint32_t _PWR_SRCFixedPDO(float _C_, float _V_,
|
|
USBPD_CORE_PDO_PeakCurr_TypeDef _PK_,
|
|
USBPD_CORE_PDO_DRDataSupport_TypeDef DRDSupport,
|
|
USBPD_CORE_PDO_USBCommCapable_TypeDef UsbCommCapable,
|
|
USBPD_CORE_PDO_ExtPowered_TypeDef ExtPower,
|
|
USBPD_CORE_PDO_USBSuspendSupport_TypeDef UsbSuspendSupport,
|
|
USBPD_CORE_PDO_DRPowerSupport_TypeDef DRPSupport);
|
|
|
|
uint32_t _PWR_SRCVariablePDO(float _MAXV_, float _MINV_, float _C_);
|
|
|
|
uint32_t _PWR_SRCBatteryPDO(float _MAXV_,float _MINV_,float _PWR_);
|
|
/* Functions to initialize Sink PDOs */
|
|
|
|
uint32_t _PWR_SNKFixedPDO(float _C_, float _V_,
|
|
USBPD_CORE_PDO_DRDataSupport_TypeDef DRDSupport,
|
|
USBPD_CORE_PDO_USBCommCapable_TypeDef UsbCommCapable,
|
|
USBPD_CORE_PDO_ExtPowered_TypeDef ExtPower,
|
|
USBPD_CORE_PDO_HigherCapability_TypeDef HigherCapab,
|
|
USBPD_CORE_PDO_DRPowerSupport_TypeDef DRPSupport);
|
|
|
|
uint32_t _PWR_SNKVariablePDO(float _MAXV_,float _MINV_,float _C_);
|
|
|
|
uint32_t _PWR_SNKBatteryPDO(float _MAXV_,float _MINV_,float _PWR_);
|
|
|
|
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Exported_Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Initialize structures and variables related to power board profiles
|
|
* used by Sink and Source, for all available ports.
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_Init(void)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_Init */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_Init */
|
|
}
|
|
|
|
/**
|
|
* @brief Sets the required power profile, now it works only with Fixed ones
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_SetProfile */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_SetProfile */
|
|
}
|
|
|
|
/**
|
|
* @brief Resets the Power Board
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_PowerResetGlobal(void)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_PowerResetGlobal */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_PowerResetGlobal */
|
|
}
|
|
|
|
/**
|
|
* @brief Resets the Power on a specified port
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_PowerReset(uint8_t PortNum)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_PowerReset */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_PowerReset */
|
|
}
|
|
|
|
/**
|
|
* @brief Checks if the power on a specified port is ready
|
|
* @param PortNum Port number
|
|
* @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_SupplyReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_SupplyReady */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_SupplyReady */
|
|
}
|
|
|
|
/**
|
|
* @brief Enables VBUS power on a specified port
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_VBUSEnable */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_VBUSEnable */
|
|
}
|
|
|
|
/**
|
|
* @brief Disbale VBUS/VCONN the power on a specified port
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_VBUSDisable */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_VBUSDisable */
|
|
}
|
|
|
|
/**
|
|
* @brief Disable the SNK to stop current consumption
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_SNKDisable(uint8_t PortNum)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_SNKDisable */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_SNKDisable */
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize power on a specified port
|
|
* @param PortNum Port number
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_InitPower(uint8_t PortNum)
|
|
{
|
|
return USBPD_OK;
|
|
}
|
|
|
|
/**
|
|
* @brief Checks if the power on a specified port is enabled
|
|
* @param PortNum Port number
|
|
* @retval USBPD_ENABLE or USBPD_DISABLE
|
|
*/
|
|
USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum)
|
|
{
|
|
/* Get the Status of the port */
|
|
return USBPD_PORT_IsValid(PortNum) ? (USBPD_FunctionalState)HW_IF_PWR_VBUSIsEnabled(PortNum) : USBPD_DISABLE;
|
|
}
|
|
|
|
/**
|
|
* @brief Reads the voltage and the current on a specified port
|
|
* @param PortNum Port number
|
|
* @param pVoltage: The Voltage in mV
|
|
* @param pCurrent: The Current in mA
|
|
* @retval USBPD_ERROR or USBPD_OK
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_ReadVA(uint8_t PortNum, uint16_t *pVoltage, uint16_t *pCurrent)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_ReadVA */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_ReadVA */
|
|
}
|
|
|
|
/**
|
|
* @brief Enables the VConn on the port.
|
|
* @param PortNum Port number
|
|
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_Enable_VConn(uint8_t PortNum, CCxPin_TypeDef CC)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_Enable_VConn */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_Enable_VConn */
|
|
}
|
|
|
|
/**
|
|
* @brief Disable the VConn on the port.
|
|
* @param PortNum Port number
|
|
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
|
|
* @retval USBPD status
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_Disable_VConn(uint8_t PortNum, CCxPin_TypeDef CC)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_Disable_VConn */
|
|
return USBPD_ERROR;
|
|
/* USER CODE END USBPD_PWR_IF_Disable_VConn */
|
|
}
|
|
|
|
/**
|
|
* @brief Allow PDO data reading from PWR_IF storage.
|
|
* @param PortNum Port number
|
|
* @param DataId Type of data to be read from PWR_IF
|
|
* This parameter can be one of the following values:
|
|
* @arg @ref USBPD_CORE_DATATYPE_SRC_PDO Source PDO reading requested
|
|
* @arg @ref USBPD_CORE_DATATYPE_SNK_PDO Sink PDO reading requested
|
|
* @param Ptr Pointer on address where PDO values should be written (u8 pointer)
|
|
* @param Size Pointer on nb of u32 written by PWR_IF (nb of PDOs)
|
|
* @retval None
|
|
*/
|
|
void USBPD_PWR_IF_GetPortPDOs(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_GetPortPDOs */
|
|
|
|
/* USER CODE END USBPD_PWR_IF_GetPortPDOs */
|
|
}
|
|
|
|
/**
|
|
* @brief Find out SRC PDO pointed out by a position provided in a Request DO (from Sink).
|
|
* @param PortNum Port number
|
|
* @param RdoPosition RDO Position in list of provided PDO
|
|
* @param Pdo Pointer on PDO value pointed out by RDO position (u32 pointer)
|
|
* @retval Status of search
|
|
* USBPD_OK : Src PDO found for requested DO position (output Pdo parameter is set)
|
|
* USBPD_FAIL : Position is not compliant with current Src PDO for this port (no corresponding PDO value)
|
|
*/
|
|
USBPD_StatusTypeDef USBPD_PWR_IF_SearchRequestedPDO(uint8_t PortNum, uint32_t RdoPosition, uint32_t *Pdo)
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_SearchRequestedPDO */
|
|
return USBPD_FAIL;
|
|
/* USER CODE END USBPD_PWR_IF_SearchRequestedPDO */
|
|
}
|
|
|
|
/**
|
|
* @brief the function is called in case of critical issue is detected to switch in safety mode.
|
|
* @retval None
|
|
*/
|
|
void USBPD_PWR_IF_Alarm()
|
|
{
|
|
/* USER CODE BEGIN USBPD_PWR_IF_Alarm */
|
|
|
|
/* USER CODE END USBPD_PWR_IF_Alarm */
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|