/**
 * @file hv_drv_TypecPortable.c
 * @brief  This source file contains soc driver globals and functions.
 * @details This file provides the following functions: \n
 *          (1) \n
 *          (2) \n
 *          (3) \n
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-25
 * @copyright Copyright(c),2022-8, Hiview Software. All rights reserved.
 * @par History:
 * <table>
 * <tr><th>Author                         <th>Date         <th>Change Description
 * <tr><td>Hiview SoC Software Team       <td>2022-08-25   <td>init
 * </table>
*/

#include "hv_comm_DataType.h"
#include "hv_comm_Event.h"
#include "hv_comm_Assert.h"
#include "hv_vos_Comm.h"
#include "hv_vos_Irq.h"
#include "hv_mw_SystemManager.h"
#include "hv_chip_Irq.h"
#include "hv_chip_Debug.h"
#include "hv_drv_Gpio.h"
#include "hv_cal_I2c.h"
#include "hv_drv_GpioSimI2c.h"
#include "hv_vos_Cache.h"
#include "HV_REGS_HT7315.h"
#include "FreeRTOS.h"
#include "task.h"
#include "BoardConfig.h"
#include "hv_drv_TypecStdInc.h"

#define MAX_DISCHARGE_TIME_10MS 65  // 符合规范的最大放电时间650ms
static HvCalI2c *self;
/*****************************************************************************/
/*****************************************************************************/
/*********************************SPI Driver APIs*****************************/
/*****************************************************************************/

void Hv_Drv_Typec_VBusInitial(void)
{
    Hv_Drv_Typec_PinInit();
#if((HV_BOARD_CONFIG_PMIC_MODE == PMIC_I2CM0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
    Hv_Drv_Typec_I2CMstInitial();
#elif((HV_BOARD_CONFIG_PMIC_MODE == PMIC_SIMI2C0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
    Hv_Drv_Typec_SimI2CMstInitial();
#else

#endif
}

USHORT16 Hv_Drv_Typec_GetVBusVal(void)
{
    USHORT16 u16VbusReg;
#if defined(HV_BOARD_YM_TMP) || defined(HV_BOARD_VIEWSONIC)
    if (GPIO_LEVEL_HIGH == Hv_Drv_Gpio_GetPinLevel(HV_BOARD_CONFIG_GPIO_VBUS_DETECT))
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_0V;
    }
    else
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_5V;
    }
#elif defined(HV_BOARD_CHANGSHI)
    if (GPIO_LEVEL_HIGH == Hv_Drv_Gpio_GetPinLevel(HV_BOARD_CONFIG_GPIO_C_IO))
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_0V;
    }
    else
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_5V;
    }
#else
    HV_R32_DECL_VAR();
    u16VbusReg = (USHORT16)HV_R32_FIELD(STANDBY_STANDBY_PERI_REG_STBY_ADC3, regr_adc1_data);
    if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_0V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_0V))
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_0V;
    }
    else if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_5V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_5V)) 
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_5V;
    }
    else if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_9V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_9V)) 
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_9V;
    }
    else if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_12V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_12V)) 
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_12V;
    }    
    else if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_15V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_15V)) 
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_15V;
    }
    else if((u16VbusReg >= HV_TYPEC_CONFIG_VBUS_THR_MIN_20V) && (u16VbusReg <= HV_TYPEC_CONFIG_VBUS_THR_MAX_20V)) 
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_20V;
    }
    else
    {
        u16VbusReg = TYPEC_VBUS_THR_VAL_UNDEF;
    }
#endif
    return u16VbusReg;
}

#if((HV_BOARD_CONFIG_PMIC_MODE == PMIC_I2CM0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
UCHAR8 Hv_Drv_Typec_I2CMstInitial(void)
{
    I2cInitParam initParam;
    
    initParam.enPort = (I2cPort)I2C_PORT_0;
    initParam.enMode = I2C_MODE_MASTER;
    initParam.enSpeed = I2C_SPEED_100K;
    initParam.enAddressingMode = I2C_ADDR_7BIT;
    
    self = Hv_Cal_I2C_Init(&initParam);

    return HV_TRUE;
}
#endif

#if ((HV_BOARD_CONFIG_PMIC_MODE == PMIC_SIMI2C0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
UCHAR8 Hv_Drv_Typec_SimI2CMstInitial(void)
{
    GpioSimI2c stGpioSimi2c = {INVALID_PARAM_UHCAR8, INVALID_PARAM_UHCAR8};

    stGpioSimi2c.ucSdaPin = PMIC_SIMI2C_SDA;
    stGpioSimi2c.ucSclPin = PMIC_SIMI2C_SCL;

    Hv_Drv_GpioSimI2c_Init(HV_BOARD_CONFIG_PMIC_SIMI2C, &stGpioSimi2c);

    return HV_TRUE;
}
#endif

void Hv_Drv_Typec_SetVBusOutVal(UCHAR8 u8PortNum, USHORT16 u16Voltage, USHORT16 u16Current)
{
#ifdef HV_BOARD_YM_TMP
    return;
#endif
#if((HV_BOARD_CONFIG_PMIC_MODE == PMIC_I2CM0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
    UCHAR8 u8SubAddr[1] = { 0 };
    UCHAR8 u8WriteVal[2] = { 0 };
    I2cFuncParam stI2cParamter;

    if (u16Current != 0)
    {
        u16Current += 500;
    }

    if (u16Voltage != 0)
    {
        u16Voltage += 300;
    }

    u8SubAddr[0] = 0x00;
    u8WriteVal[0] = (UCHAR8)((u16Voltage / 10) & 0x03);        /* VOUT_L D[2:0]   in 10mv */
    u8WriteVal[1] = (UCHAR8)((u16Voltage / 10) >> 3);          /* VOUT_H D[7:0] */
    //IICMst_WriteEx(0xC0, u8SubAddr, 1, u8WriteVal, 2);
    stI2cParamter.usDevAddress     = HV_BOARD_CONFIG_PMIC_ADDR;  /* 0x60 */
    stI2cParamter.pucCmdAddr       = u8SubAddr;
    stI2cParamter.usCmdAddrSize    = 1;
    stI2cParamter.pucData          = u8WriteVal;
    stI2cParamter.usDataSize       = 2;
    Hv_Cal_I2C_MasterPollingTransmit(self, &stI2cParamter, 1000);

    u8SubAddr[0] = 0x03;
    u8WriteVal[0] = (UCHAR8)(u16Current / 50);                 /* IOUT_LIM D[2:0]   in 50mv */
    //IICMst_WriteEx(0xC0, u8SubAddr, 1, u8WriteVal, 2);
    stI2cParamter.usDevAddress     = HV_BOARD_CONFIG_PMIC_ADDR;  /* 0x60 */
    stI2cParamter.pucCmdAddr       = &u8SubAddr[0];
    stI2cParamter.usCmdAddrSize    = 1;
    stI2cParamter.pucData          = &u8WriteVal[0];
    stI2cParamter.usDataSize       = 1;
    Hv_Cal_I2C_MasterPollingTransmit(self, &stI2cParamter, 1000);

    u8SubAddr[0] = 0x02;
    u8WriteVal[0] = 0x01;
    stI2cParamter.usDevAddress     = HV_BOARD_CONFIG_PMIC_ADDR;  /* 0x60 */
    stI2cParamter.pucCmdAddr       = &u8SubAddr[0];
    stI2cParamter.usCmdAddrSize    = 1;
    stI2cParamter.pucData          = &u8WriteVal[0];
    stI2cParamter.usDataSize       = 1;
    Hv_Cal_I2C_MasterPollingTransmit(self, &stI2cParamter, 1000);
#elif((HV_BOARD_CONFIG_PMIC_MODE == PMIC_SIMI2C0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
    UCHAR8 u8SubAddr[1] = { 0 };
    UCHAR8 u8WriteVal[2] = { 0 };
    I2cFuncParam stI2cParamter;

    if (u16Current != 0)
    {
        u16Current += 500;
    }

    if (u16Voltage != 0)
    {
        u16Voltage += 300;
    }

    u8SubAddr[0] = 0x00;
    u8WriteVal[0] = (UCHAR8)((u16Voltage / 10) & 0x03);        /* VOUT_L D[2:0]   in 10mv */
    u8WriteVal[1] = (UCHAR8)((u16Voltage / 10) >> 3);          /* VOUT_H D[7:0] */
    Hv_Drv_GpioSimI2c_SendData(HV_BOARD_CONFIG_PMIC_SIMI2C, HV_BOARD_CONFIG_PMIC_ADDR, u8SubAddr, 1, u8WriteVal, 2);

    u8SubAddr[0] = 0x03;
    u8WriteVal[0] = (UCHAR8)(u16Current / 50);                /* IOUT_LIM D[2:0]   in 50mv */
    Hv_Drv_GpioSimI2c_SendData(HV_BOARD_CONFIG_PMIC_SIMI2C, HV_BOARD_CONFIG_PMIC_ADDR, &u8SubAddr[0], 1, &u8WriteVal[0], 1);

    u8SubAddr[0] = 0x02;
    u8WriteVal[0] = 0x01;
    Hv_Drv_GpioSimI2c_SendData(HV_BOARD_CONFIG_PMIC_SIMI2C, HV_BOARD_CONFIG_PMIC_ADDR, &u8SubAddr[0], 1, &u8WriteVal[0], 1);
#elif((HV_BOARD_CONFIG_PMIC_MODE == PMIC_GPIO) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
#ifdef HV_BOARD_SHIJINGDA
    switch(u16Voltage)
    {
        case TYPEC_VBUS_THR_VAL_5V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_9V:
        case TYPEC_VBUS_THR_VAL_15V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
            break;
        default:
            break;
    }

#elif defined(HV_BOARD_CHANGSHI)
    switch(u16Voltage)
    {
        case TYPEC_VBUS_THR_VAL_5V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);
            break;
        case TYPEC_VBUS_THR_VAL_9V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);
            break;
        case TYPEC_VBUS_THR_VAL_12V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);
            break;
        case TYPEC_VBUS_THR_VAL_15V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);
            break;
        case TYPEC_VBUS_THR_VAL_20V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_LOW);
            break;
        default:
            break;
    }
#elif defined(HV_BOARD_VIEWSONIC)
    switch(u16Voltage)
    {
        case TYPEC_VBUS_THR_VAL_5V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_9V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_12V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_15V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_20V:
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);
            break;
        default:
            break;
    }
#else
    switch(u16Voltage)
    {
        case TYPEC_VBUS_THR_VAL_5V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_9V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_12V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
            break;
        case TYPEC_VBUS_THR_VAL_15V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            break;
        case TYPEC_VBUS_THR_VAL_20V:
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_LOW);
            Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_LOW);
            break;
        default:
            break;
    }
#endif
#else
    /* do nothing */
#endif
}

void Hv_Drv_Typec_PinInit(void)
{
    UCHAR8 ucPinIdx = 0;

#if((HV_BOARD_CONFIG_PMIC_MODE == PMIC_I2CM0) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
    HV_W32_FIELD_EX(RX_SH08_TOP_RX_CTRL_38, 0x00, reg_i2cs0_scl_io_ctrl, 0xD9);
    HV_W32_FIELD_EX(RX_SH08_TOP_RX_CTRL_38, 0x00, reg_i2cs0_sda_io_ctrl, 0xD9);
#endif
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    {
        /* VBUS_DISCHA */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             EVB     3      211    GPIO3
             DEMO    3      211    GPIO3
             JRY     3      211    GPIO3
         */
        ucPinIdx = HV_BOARD_CONFIG_GPIO_VBUS_DISCHA;
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_0, reg_gpio3_func_sel, 0x0);
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_30, reg_gpio3_io_ctrl, 0x29);
        Hv_Drv_Gpio_SetDirection(ucPinIdx, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, HV_TYPEC_CONFIG_GPIO_VBUS_DISCHA_DEFAULT);
    }
    {
        /* VBUS_PMU_EN */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             EVB     4      213    GPIO4
             DEMO    4      213    GPIO4
             JRY     5      214    GPIO5
         */
        ucPinIdx = HV_BOARD_CONFIG_GPIO_VBUS_PMU_EN;
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_0, reg_gpio4_func_sel, 0x0);
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_34, reg_gpio4_io_ctrl, 0x29);
        Hv_Drv_Gpio_SetDirection(ucPinIdx, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, HV_TYPEC_CONFIG_GPIO_VBUS_PMU_EN_DEFAULT);
    }
    {
        /* GP_PD_PW_S */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             EVB     5      214    GPIO5
             DEMO    5      214    GPIO5
             JRY     17     63     GPIO22
         */
        ucPinIdx = HV_BOARD_CONFIG_GPIO_GP_PD_PW_S;
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_4, reg_gpio5_func_sel, 0x0);
        //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_34, reg_gpio5_io_ctrl, 0x29);
        Hv_Drv_Gpio_SetDirection(ucPinIdx, GPIO_DIR_OUTPUT);
#if (HV_TYPEC_CONFIG_GPIO_GP_PD_PW_S_OFF == TYPEC_LEVEL_LOW)
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, HV_TYPEC_CONFIG_GPIO_GP_PD_PW_S_DEFAULT); /* 0: Off 1: On */
#else
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, HV_TYPEC_CONFIG_GPIO_GP_PD_PW_S_DEFAULT); /* 0: On 1: Off */
#endif
        
    }
    {   
        /* reg_dp_rx0_hpd_io_ctrl */
        HV_W32_FIELD(STANDBY_SH08_TOP_STBY_CTRL_8, reg_dp_rx0_hpd_io_ctrl, 0x29);
#ifdef HV_BOARD_SHIJINGDA
#elif defined(HV_BOARD_VIEWSONIC)
        /* cc1 vconn off */
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, GPIO_LEVEL_LOW);
        /* cc2 vconn off */
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(ucPinIdx, GPIO_LEVEL_LOW);
#elif defined(HV_BOARD_CHANGSHI)
        /* cc1 vconn off */
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_DIR_INPUT);
        /* cc2 vconn off */
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_DIR_INPUT);
#else
		/* cc1 vconn off */
        HV_W32_FIELD_EX(STANDBY_SH08_TOP_STBY_CTRL_8, 0x00, reg_dp_rx0_cable_io_ctrl, 0x18);
        /* cc2 vconn off */
#if (HV_TYPEC_CONFIG_GPIO_VCONN_CC2_SW_OFF == TYPEC_LEVEL_LOW)
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x2);
#else
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x0);
#endif
#endif
    }
#endif
#if (HV_TYPEC_CONFIG_CC_RD_CTL_EN == TYPEC_FUNCTION_ON)
        {
            /* CC_Rd_CTL */
            /* Vendor GPIO.No  Pin.No  PAD.Name
                 EVB    7       216    GPIO7
                 DEMO   7       216    GPIO7
                 JRY    N/A     N/A    N/A
             */
            ucPinIdx = HV_BOARD_CONFIG_GPIO_CC_RD_CTL;
            //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_4, reg_gpio7_func_sel, 0x0);
            //HV_W32_FIELD(RX_SH08_TOP_RX_CTRL_34, reg_gpio7_io_ctrl, 0x29);
            Hv_Drv_Gpio_SetDirection(ucPinIdx, GPIO_DIR_OUTPUT);
            Hv_Drv_Gpio_SetPinLevel(ucPinIdx, HV_TYPEC_CONFIG_GPIO_CC_RD_CTL_DEFAULT);
        }
#endif
#if (HV_TYPEC_CONFIG_SSPWD_EN == TYPEC_FUNCTION_ON)
    {
        /* RX_AP_EN */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             EVB            162    STBY_GP1
             DEMO           162    STBY_GP1
             JRY    GP3     164    STBY_GP3/UART2_TX
         */
        /* solution for Samsung mobile phone's waterdrop issue */
        HV_W32_FIELD(STANDBY_STANDBY_PERI_REG_STBY_AUX0, reg_dprx0_ana_aux_pwd, 0x1);
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_RX_AP_EN, HV_TYPEC_CONFIG_GPIO_RX_AP_EN_DEFAULT);
    }
#else
#ifdef HV_BOARD_CHANGSHI
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_DIR_INPUT);
#endif
#ifdef HV_BOARD_VIEWSONIC
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_LEVEL_HIGH);
#endif
#endif
#if((HV_BOARD_CONFIG_PMIC_MODE == PMIC_GPIO) && (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK))
#ifdef HV_BOARD_SHIJINGDA
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_LOW);
#elif defined(HV_BOARD_CHANGSHI)
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_LEVEL_HIGH);
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_LEVEL_HIGH);
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_LEVEL_HIGH);
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_3VCC, GPIO_LEVEL_HIGH);

    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_C_IO, GPIO_DIR_INPUT);
#else
    {
        /* VSEL1 */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             JRY    21       60     GPIO26
         */
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1, HV_TYPEC_CONFIG_GPIO_VSEL1_DEFAULT);
        
        /* VSEL2 */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             JRY    4       213     GPIO4
         */
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL2, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL2, HV_TYPEC_CONFIG_GPIO_VSEL2_DEFAULT);

        /* VSEL1_1/2VCC */
        /* Vendor GPIO.No  Pin.No  PAD.Name
             JRY    6       215     GPIO6
         */
        Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, GPIO_DIR_OUTPUT);
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VSEL1_1_2VCC, HV_TYPEC_CONFIG_GPIO_VSEL1_1_2VCC_DEFAULT);
    }
#endif
#endif
#if defined(HV_BOARD_YM_TMP) || defined(HV_BOARD_VIEWSONIC)
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_VBUS_DETECT, GPIO_DIR_INPUT);
#endif
}

void Hv_Drv_Typec_SetPortPowerONOFF(UCHAR8 u8PortNum, UCHAR8 u8PwrSet)
{
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VBUS_PMU_EN, u8PwrSet);

    if (u8PwrSet == 0)
    {
        Hv_Drv_Typec_ConfigVBUSDischarge(u8PortNum, 1);
    }

    #if (HV_TYPEC_CONFIG_GPIO_GP_PD_PW_S_OFF == TYPEC_LEVEL_LOW)
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_GP_PD_PW_S, u8PwrSet);
    #else
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_GP_PD_PW_S, (u8PwrSet == HV_TRUE?HV_FALSE:HV_TRUE));
    #endif
#endif
}

void Hv_Drv_Typec_ConfigVBUSDischarge(UCHAR8 u8PortNum, UCHAR8 u8DischargeSet)
{
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)

    static unsigned int cnt_discharge = 0;
    if(u8DischargeSet)
    {
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VBUS_DISCHA, 1);

        // 使用超时机制，防止无限循环
        while(cnt_discharge < MAX_DISCHARGE_TIME_10MS)
        {
            if (HV_PSF_HOOK_POLLING_READ_VBUS() == TYPEC_VBUS_0V)
            {
                break;
            }
            Hv_Vos_MSleep(10);
            cnt_discharge++;
        }
        if (cnt_discharge > 4)
        {
            HV_LOG_INFO("typec", "VBUS discharge time more than %dms", cnt_discharge*10);//650
        }
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VBUS_DISCHA, 0);
    }
    else
    {
        Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_VBUS_DISCHA, 0);
    }
    cnt_discharge = 0;
#endif
}

void Hv_Drv_Typec_SetVconnCC1ONOFF(UCHAR8 u8PortNum, UCHAR8 u8PwrSet)
{
#ifdef HV_BOARD_SHIJINGDA
    return;
#elif defined(HV_BOARD_VIEWSONIC)
    if(u8PwrSet)
    {
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_LEVEL_HIGH);
    }
    else
    {
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_LEVEL_LOW);
    }
#elif defined(HV_BOARD_CHANGSHI)
    if(u8PwrSet)
    {
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_DIR_OUTPUT);
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_LEVEL_LOW);
    }
    else
    {
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC1_SW_CTL, GPIO_DIR_INPUT);
    }
#else
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    if(u8PwrSet)
    {
        HV_W32_FIELD_EX(STANDBY_SH08_TOP_STBY_CTRL_8, 0x00, reg_dp_rx0_cable_io_ctrl, 0x19);
    }
    else
    {
        HV_W32_FIELD_EX(STANDBY_SH08_TOP_STBY_CTRL_8, 0x00, reg_dp_rx0_cable_io_ctrl, 0x18);
    }
#endif
#endif
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_cc1_vconn_sel, u8PwrSet == HV_TRUE?HV_FALSE:HV_TRUE);
}

void Hv_Drv_Typec_SetVconnCC2ONOFF(UCHAR8 u8PortNum, UCHAR8 u8PwrSet)
{
#ifdef HV_BOARD_SHIJINGDA
    return;
#elif defined(HV_BOARD_VIEWSONIC)
    if(u8PwrSet)
    {
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_LEVEL_HIGH);
    }
    else
    {
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_LEVEL_LOW);
    }
#else
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    TypecPlatformCB *s_pstTypecPlatformCB = Hv_Drv_Typec_GetFlatformCbPointer();
    HV_ASSERT_VALID_PTR_VOID(s_pstTypecPlatformCB);
    HV_ASSERT_VALID_PTR_VOID(s_pstTypecPlatformCB->DpRxReset);
    s_pstTypecPlatformCB->DpRxReset(HV_BOARD_CONFIG_TYPEC0_TO_DP);
    Hv_Vos_Delayus(500);
	
#ifdef HV_BOARD_CHANGSHI
    if(u8PwrSet)
    {
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_DIR_OUTPUT);
        Hv_Cal_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_LEVEL_LOW);
    }
    else
    {
        Hv_Cal_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_CC2_SW_CTL, GPIO_DIR_INPUT);
    }
#else

#if (HV_TYPEC_CONFIG_GPIO_VCONN_CC2_SW_OFF == TYPEC_LEVEL_LOW)
    if(u8PwrSet)
    {
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x0);
    }
    else
    {
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x2);
    }
#else
    if(u8PwrSet)
    {
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x2);
    }
    else
    {
        HV_W32_FIELD_EX(RX_EDP_RX_MAC_WR_REG_00_50, 0x00, reg_00_dprx_sw_irqhpd_set, 0x0);
    }
#endif
#endif
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_cc2_vconn_sel, u8PwrSet == HV_TRUE?HV_FALSE:HV_TRUE);
#endif
#endif
}

void Hv_Drv_Typec_VconnCC1Discharge(UCHAR8 u8PortNum, UCHAR8 u8DischargeSet)
{
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_sw_ctrl_rd_en, 1);
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_cc1_rd_en, u8DischargeSet);
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_sw_ctrl_rd_en, 0);
#endif
}

void Hv_Drv_Typec_VconnCC2Discharge(UCHAR8 u8PortNum, UCHAR8 u8DischargeSet)
{
#if (HV_TYPEC_CONFIG_TYPEC_MODE != TYPEC_MODE_SINK)
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_sw_ctrl_rd_en, 1);
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_cc2_rd_en, u8DischargeSet);
    HV_W32_FIELD_EX(STANDBY_USB_TYPEC_TOP_00_04, 0x00, reg_00_sw_ctrl_rd_en, 0);
#endif
}

void Hv_Drv_Typec_DpAuxPowerOff(void)
{
#if (HV_TYPEC_CONFIG_SSPWD_EN == TYPEC_FUNCTION_ON)
    HV_W32_FIELD(STANDBY_STANDBY_PERI_REG_STBY_AUX0, reg_dprx0_ana_aux_pwd, 0x1);
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_DIR_INPUT);
#endif
}

void Hv_Drv_Typec_DpAuxPowerOn(void)
{
#if (HV_TYPEC_CONFIG_SSPWD_EN == TYPEC_FUNCTION_ON)
    HV_W32_FIELD(STANDBY_STANDBY_PERI_REG_STBY_AUX0, reg_dprx0_ana_aux_pwd, 0x0);
    Hv_Drv_Gpio_SetDirection(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_DIR_OUTPUT);
    Hv_Drv_Gpio_SetPinLevel(HV_BOARD_CONFIG_GPIO_RX_AP_EN, GPIO_LEVEL_HIGH);
#endif
}


