/**
 * @file hv_mw_Ddcci.c
 * @brief ddcci middlware c file.
 * @details This file provides the following functions: \n
 *          (1) Init function \n
 *          (2) Msg queue management \n
 *          (3) Msg send function \n
 *          (4) Msg Handler function \n
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-01-31
 * @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>2023-01-31      <td>init
 * </table>
 */


#include "hv_comm_Assert.h"
#include "hv_comm_Log.h"
#include "hv_comm_Assert.h"
#include "hv_mw_Video.h"
#include "hv_mw_Hdmi.h"
#include "hv_mw_Ddcci.h"
#include "hv_mw_PQ.h"
#include "hv_mw_SystemManager.h"
#include "hv_cal_I2c.h"
#include "hv_drv_DisplayPort.h"
#include "hv_drv_HdmiRx.h"
#include "hv_comm_DataBase.h"
#include "hv_app_PQ.h"
#include "hv_drv_Mprt.h"
#include "hv_mw_Factory.h"
#include "hv_drv_Ddcci.h"


//****************************************************************************
// VARIABLE DECLARATIONS
//****************************************************************************
static DdcciManager s_stDdcciManager;
static UINT32 s_guiFacAddr = 0;

//****************************************************************************
// FUNCTION DECLARATIONS
//****************************************************************************
static DdcciManager* Hv_Mw_Ddcci_CreateDdcciManager(VOID);

static VOID Hv_MW_Ddcci_ProcPQTool(VOID);
static VOID QueueReset(DdcciInnerMsgQueue *pstQueue);
static QueueStatus QueueRead(DdcciInnerMsgQueue *pstQueue, DdcciEvent *pstData);
static QueueStatus QueueWrite(DdcciInnerMsgQueue *pstQueue, const DdcciEvent *pstdata);
static BOOL QueueIsFull(DdcciInnerMsgQueue *pstQueue);
static BOOL QueueIsEmpty(DdcciInnerMsgQueue *pstQueue);
static BOOL PullOneMsgFromDdcciInnerMsgQueue(DdcciInnerMsgQueue* pstDdcciInnerMsgQueue, DdcciEvent* pstEvent);
#ifdef HV_BOARD_CONFIG_AT
static HvCalI2c *s_pstDDCI2C = NULL;
static VOID Hv_Mw_Ddcci_I2cInit(VOID);
static Status Hv_Mw_Ddcci_SendI2c(UCHAR8 *pucData, USHORT16 usSize);
#endif
//****************************************************************************
// FUNCTION DEFINITIONS
//****************************************************************************

/* FIFO复位 */
static VOID QueueReset(DdcciInnerMsgQueue *pstQueue)
{
    pstQueue->usWriteAddr = 0;
    pstQueue->usReadAddr = 0;
    for(USHORT16 usIndex = 0; usIndex < MAX_DDCCI_QUEUE_SIZE; usIndex++)
    {
        HV_MEMSET(&pstQueue->astFifo[usIndex], 0 , sizeof(pstQueue->astFifo[usIndex]));
    }
    return;
}

/* FIFO写入数据 */
static QueueStatus QueueWrite(DdcciInnerMsgQueue *pstQueue, const DdcciEvent *pstData)
{
    if (QueueIsFull(pstQueue))
    {
        HV_LOG_ERROR(DEFAULT,"Write failed, queue is full");
        return QUEUE_FULL;
    }
    HV_MEMCPY(&pstQueue->astFifo[pstQueue->usWriteAddr], pstData, sizeof(DdcciEvent));
    pstQueue->usWriteAddr = (pstQueue->usWriteAddr + 1) % MAX_DDCCI_QUEUE_SIZE;
    return QUEUE_OK;
}

/* FIFO读出数据 */
static QueueStatus QueueRead(DdcciInnerMsgQueue *pstQueue, DdcciEvent *pstdata)
{
    if (QueueIsEmpty(pstQueue))
    {
        return QUEUE_EMPTY;
    }
    HV_MEMCPY(pstdata, &pstQueue->astFifo[pstQueue->usReadAddr], sizeof(DdcciEvent));
    pstQueue->usReadAddr = (pstQueue->usReadAddr + 1) % MAX_DDCCI_QUEUE_SIZE;

    return QUEUE_OK;
}

/* FIFO是否为空 */
static BOOL QueueIsEmpty(DdcciInnerMsgQueue *pstQueue)
{
    return (pstQueue->usWriteAddr == pstQueue->usReadAddr);
}

/* FIFO是否为满 */
static BOOL QueueIsFull(DdcciInnerMsgQueue *pstQueue)
{
    return ((pstQueue->usWriteAddr + 1) % MAX_DDCCI_QUEUE_SIZE == pstQueue->usReadAddr);
}

static BOOL PullOneMsgFromDdcciInnerMsgQueue(DdcciInnerMsgQueue* pstDdcciInnerMsgQueue, DdcciEvent* pstEvent)
{
    if (QUEUE_OK == QueueRead(pstDdcciInnerMsgQueue, pstEvent))
    {
        return HV_TRUE;
    }
    return HV_FALSE;
}

Status Hv_Mw_Ddcci_SendInnerMsg(const DdcciEvent* pstDdcciEvent)
{
    HV_ASSERT_TRUE(QUEUE_OK == QueueWrite(&s_stDdcciManager.stDdcciInnerMsgQueue, pstDdcciEvent));
    return HV_SUCCESS;
}

static VOID PQToolCmdGammatHandler(UCHAR8 ucCmdType)
{
    UINT32 uiGmaAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 返回地址 */
        uiGmaAddr = (UINT32)(Hv_Common_Db_GetGammaDataDBRegionPtr());
        uiGmaAddr &= 0x7FFFFFFF;
        Hv_Drv_Ddcci_SetPQToolInfo(uiGmaAddr + OFFSET_OF(GammaDataDBRegion, ucGmaNum));
        HV_LOG_DEBUG(DDCCI,"gamma return addr 0x%x", uiGmaAddr + OFFSET_OF(GammaDataDBRegion, ucGmaNum));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdHdcpHandler(UCHAR8 ucCmdType)
{
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(((UINT32)(Hv_Common_Db_GetHDCPDataDBRegionPtr()) & 0x7FFFFFFF) + OFFSET_OF(HDCPDataDBRegion, stKey));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdSNHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, acProductSn));

        HV_LOG_DEBUG(PQ, "SSSSSSSSSSSSn %x\n", s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, acProductSn));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdFacWeekHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactWeek));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdFacYearHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactYear));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdHdmiEdidHandler(UCHAR8 ucCmdType)
{
    UINT32 uiEdidAddr = 0;
    UCHAR8 ucEdidNum = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        uiEdidAddr = (UINT32)(Hv_Common_Db_GetHdmiEdidDBRegionPtr());
        uiEdidAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(uiEdidAddr + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucEdidNum = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Common_Db_GetHdmiEdidDBRegionPtr()->ucNumber  = ucEdidNum;
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        HV_LOG_INFO(DDCCI,"write hdmi edidnum  %d", ucEdidNum);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }

    return;
}

static VOID PQToolCmdHdmi1EdidHandler(UCHAR8 ucCmdType)
{
    UINT32 uiEdidAddr = 0;
    UCHAR8 ucEdidNum = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        uiEdidAddr = (UINT32)(Hv_Common_Db_GetHdmi1EdidDBRegionPtr());
        uiEdidAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(uiEdidAddr + OFFSET_OF(HdmiEdidDBRegion, astHdmiEdid));

    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucEdidNum = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Common_Db_GetHdmi1EdidDBRegionPtr()->ucNumber  = ucEdidNum;
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        HV_LOG_INFO(DDCCI,"write hdmi1 edidnum  %d", ucEdidNum);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }

    return;
}

static VOID PQToolCmdDpEdidHandler(UCHAR8 ucCmdType)
{
    UINT32 uiEdidAddr = 0;
    UCHAR8 ucEdidNum = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        uiEdidAddr = (UINT32)(Hv_Common_Db_GetDpEdidDBRegionPtr());
        uiEdidAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(uiEdidAddr + OFFSET_OF(DpEdidDBRegion, astDpEdid));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucEdidNum = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Common_Db_GetDpEdidDBRegionPtr()->ucNumber  = ucEdidNum;
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        HV_LOG_INFO(DDCCI,"write dp edidnum  %d", ucEdidNum);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }

    return;
}

static VOID PQToolCmdDp1EdidHandler(UCHAR8 ucCmdType)
{
    UINT32 uiEdidAddr = 0;
    UCHAR8 ucEdidNum = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        uiEdidAddr = (UINT32)(Hv_Common_Db_GetDp1EdidDBRegionPtr());
        uiEdidAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(uiEdidAddr + OFFSET_OF(DpEdidDBRegion, astDpEdid));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucEdidNum = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Common_Db_GetDp1EdidDBRegionPtr()->ucNumber  = ucEdidNum;
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        HV_LOG_INFO(DDCCI,"write dp1 edidnum  %d", ucEdidNum);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }

    return;
}

static VOID PQToolCmdColorTempCoolHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempCool));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdColorTempWarmHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempWarm));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdColorTempStandardHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        ///uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempStandard));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdColorTempP3Handler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempP3));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdColorTempSrgbHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempSrgb));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdColorTempEyeCareHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stColTempEyeCare));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamutNativeHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamutNative));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamutSrgbHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamutSrgb));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamut709Handler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamut709));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamutP3Handler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamutP3));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamutHDRHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamutHdr));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdGamutAdobeHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, stGamutAdobe));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdFacBrightnessHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactoryBrightness));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdFacContrastHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactoryContrast));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdEnergyHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactoryEnergy));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdDefaultLangHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucDefaultLanguage));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
}

static VOID PQToolCmdSharpnessHandler(UCHAR8 ucCmdType)
{
    //UINT32 uiFacAddr = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, ucFactorySharpness));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        /* 工具写入完成成功后，更新flag，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    return;
}

static VOID PQToolCmdDatabaseSyncHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucRet = 0;
    UINT32 uiVal = 0;

    uiVal = Hv_Drv_Ddcci_GetPQToolInfo();

    if (ucCmdType == PQTOOL_CMDTYPE_UPPERMSG)
    {
        HV_LOG_INFO(DDCCI,"PQTOOL SYNC flag %x", uiVal);

        /* EDID Update Factory info etc used the DB. */
        Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr()->bModifyFlag = HV_TRUE;
        Hv_Vos_VolatileMemcpy(Hv_Common_Db_GetFactoryDataDBRegionPtr(),
            Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr(), sizeof(FactoryDataDBRegion));

        /*HDCP modified*/
        if(uiVal & PQTOOL_MODIFYFLAG_HDCP1X)
        {
            HV_Common_SetHdcpStatus(HV_TRUE);
            HV_Common_SetHdcp1Valid(HV_TRUE);
            Hv_Common_Db_GetFactoryDataDBRegionPtr()->ucUseSeperatorHDCPKey = HV_TRUE;
            Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp1XValid = HV_TRUE;
            ucRet |= Hv_Mw_DataBase_SyncHdcp();
            HV_LOG_INFO(PQ, " hdcp %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_HDCP2X)
        {
            HV_Common_SetHdcpStatus(HV_TRUE);
            HV_Common_SetHdcp2Valid(HV_TRUE);
            Hv_Common_Db_GetFactoryDataDBRegionPtr()->ucUseSeperatorHDCPKey = HV_TRUE;
            Hv_Common_Db_GetHDCPDataDBRegionPtr()->bHdcp2XValid = HV_TRUE;
            ucRet |= Hv_Mw_DataBase_Sync();
            HV_LOG_INFO(PQ, " hdcp2 %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_HDMIEDID)
        {
            HV_LOG_INFO(DDCCI,"HDM0");
            HV_Common_SetHdmiEdidStatus(HV_TRUE);
            ucRet |= Hv_Mw_DataBase_SyncHdmiEdid();
            HV_LOG_INFO(PQ, " hdmi0 %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_HDMI1EDID)
        {
            HV_LOG_INFO(DDCCI,"HDMI1");
            HV_Common_SetHdmi1EdidStatus(HV_TRUE);
            ucRet |= Hv_Mw_DataBase_SyncHdmi1Edid();
            HV_LOG_INFO(PQ, " hdmi1 %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_DPEDID)
        {
            HV_LOG_INFO(DDCCI,"DP");
            HV_Common_SetDpEdidStatus(HV_TRUE);
            ucRet |= Hv_Mw_DataBase_Sync();
            HV_LOG_INFO(PQ, " dp0 %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_DP1EDID)
        {
            HV_LOG_INFO(DDCCI,"DP1");
            HV_Common_SetDp1EdidStatus(HV_TRUE);
            ucRet |= Hv_Mw_DataBase_Sync();
            HV_LOG_INFO(PQ, " dp1 %d", ucRet);
        }
        if(uiVal & PQTOOL_MODIFYFLAG_GAMMA)
        {
            HV_LOG_INFO(DDCCI,"Gamma");
            HV_Common_SetGammaStatus(HV_TRUE);
            ucRet |= Hv_Mw_DataBase_Sync();
            HV_LOG_INFO(PQ, " gamma %d", ucRet);
        }

        /* Factory Data Update Without Any Flag. It is a mandantory selection */
        //if((uiVal & PQTOOL_MODIFYFLAG_COLORTEMP)||(uiVal & PQTOOL_MODIFYFLAG_GAMUT))
        {
            ucRet |= Hv_Mw_DataBase_SyncFactory();
            HV_LOG_INFO(PQ, " factory %d", ucRet);
        }

        /*Data Write to flash based on the above items*/
        //if(HV_FAILURE == Hv_Mw_DataBase_Sync())
        if(ucRet != 0)
        {
            ucRet = HV_FALSE;
        }
        else
        {
            /*write succeed*/
            if(uiVal & PQTOOL_MODIFYFLAG_EXITFAC)/*exit factory mode*/
            {
                /* exit factory mode */
                HV_VOS_QUEUE_S *pOsdQueue = Hv_Mw_System_GetOsdQueue();
                HV_ASSERT_VALID_PTR_VOID(pOsdQueue);
                OsdEvent stOsdEvent;
                HV_MEMSET(&stOsdEvent, 0 ,sizeof(stOsdEvent));
                stOsdEvent.usEventId = OSD_EVENT_FACTORY_EXIT;
                stOsdEvent.usValue = 0;
                HV_ASSERT_TRUE_VOID(Hv_Vos_QueueSend(pOsdQueue, &stOsdEvent));
                HV_LOG_DEBUG(DDCCI,"FAC bright %d contrast %d",HV_COMMON_DATABASE_GET(FactoryData, ucFactoryBrightness),\
                HV_COMMON_DATABASE_GET(FactoryData, ucFactoryContrast));
            }
            ucRet = HV_TRUE;
        }
        Hv_Drv_Ddcci_SetPQToolStatus(ucRet);
        Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    }
    return;
}



static VOID PQToolCmdHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucHue = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucHue = Hv_Mw_PQ_GetHue();
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucHue);
        HV_LOG_DEBUG(DDCCI,"read Hue %d", ucHue);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucHue = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetHue(ucHue);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write Hue %d", ucHue);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucSat = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucSat = Hv_Mw_PQ_GetSaturation();
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucSat);
        HV_LOG_DEBUG(DDCCI,"read Sat %d", ucSat);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucSat = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetSaturation(ucSat);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write Sat %d", ucSat);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID  PQToolCmdSetBurnOsdHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucMode = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        ucMode = HV_COMMON_DATABASE_GET(SystemData, bBurnInEnable);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucMode);
        HV_LOG_DEBUG(DDCCI,"read Mode %d", ucMode);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucMode = Hv_Drv_Ddcci_GetPQToolStatus();
        HV_COMMON_DATABASE_SET(SystemData, bBurnInEnable, ucMode);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write Mode %d", ucMode);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID  PQToolCmdSetEdidSnHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucMode = 0;
    //UINT32 uiFacAddr = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        //uiFacAddr = (UINT32)(Hv_Common_Db_GetFactoryDataDBRegionPtr());
        //uiFacAddr &= 0x7FFFFFFF;
        /* 返回地址 */
        Hv_Drv_Ddcci_SetPQToolInfo(s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, acDescSn));

        HV_LOG_INFO(PQ, "SN addr %x", s_guiFacAddr + OFFSET_OF(FactoryDataDBRegion, acDescSn));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        if (Hv_Drv_Ddcci_GetPQToolStatus() == HV_TRUE)
        {
            Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
        }
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }

    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);

    return;
}

static VOID PQToolCmdWcg3DLutHandler(UCHAR8 ucCmdType)
{

    return;
}
static VOID PQToolCmdDefaultBrightnessNitHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucBrightness = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        ucBrightness = Hv_App_PQ_GetBrightness();
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucBrightness);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        /*PQ tools -> 7315, range 0-100
          0-100 mapping to PWM, save to DiagData
          save real pwm to usFactoryDefaultNits*/
        ucBrightness = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetBrightness(ucBrightness);
        // Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr()->usFactoryDefaultNits = HV_PQ_DATABASE_GET(DiagData, usDBBrightness);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}


static VOID PQToolCmdBrightnessHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucBrightness = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucBrightness = Hv_App_PQ_GetBrightness();
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucBrightness);
        HV_LOG_DEBUG(DDCCI,"read Contrast %d", ucBrightness);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucBrightness = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetBrightness(ucBrightness);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write brightness %d", ucBrightness);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}
static VOID PQToolCmdContrastHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucContrast = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucContrast = Hv_Mw_PQ_GetContrastDB();
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucContrast);
        HV_LOG_DEBUG(DDCCI,"read Contrast %d", ucContrast);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucContrast = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetContrast(ucContrast);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write Contrast %d", ucContrast);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdDlcHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;
    /* reserve */
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal =  HV_PQ_DATABASE_GET(DiagData, ucDBGcMode);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_GcModeSwitch(ucVal, 0); 
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdDcrHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, ucDBBrightRange);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetBrightRange(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdColorspaceHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, ucDBColorSpace);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetColorSpace(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdRGainHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBRGain);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
        HV_LOG_DEBUG(DDCCI,"read RGain %d", ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetRGain(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write RGain %d", ucVal);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGGainHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBGGain);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
        HV_LOG_DEBUG(DDCCI,"read GGain %d", ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetGGain(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write GGain %d", ucVal);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdBGainHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBBGain);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
        HV_LOG_DEBUG(DDCCI,"read BGain %d", ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetBGain(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        HV_LOG_DEBUG(DDCCI,"write BGain %d", ucVal);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdROffsetHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBROffset);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetROffset(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGOffsetHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBGOffset);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetGOffset(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdBOffsetHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = HV_PQ_DATABASE_GET(DiagData, usDBBOffset);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_App_PQ_SetBOffset(ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdRedHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_R);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_R, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdRedSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_R);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_R, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdRedLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_R);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_R, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGreenHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_G);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_G, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGreenSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_G);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_G, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGreenLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_G);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_G, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdBlueHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_B);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_B, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdBlueSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_B);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_B, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdBlueLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_B);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_B, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdCyanHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_C);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_C, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdCyanSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_C);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_C, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdCyanLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_C);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_C, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdYellowHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_Y);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_Y, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdYellowSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_Y);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_Y, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdYellowLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_Y);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_Y, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdMagentaHueHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetHue(PQ_CM_M);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetHue(PQ_CM_M, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdMagentaSatHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetSat(PQ_CM_M);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetSat(PQ_CM_M, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdMagentaLumHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取数值 */
        ucVal = Hv_Mw_PQ_CMGetLum(PQ_CM_M);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_PQ_CMSetLum(PQ_CM_M, ucVal);  
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdPwmHandler(UCHAR8 ucCmdType)
{
    UINT32 uiVal = 0;
    UCHAR8 ucPwmId = HV_PROJECT_CONFIG_MPRT_HIGHT_PORT;

    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 读取对应 pwm id的数值 */
        uiVal = HV_R32(TX_HSTX_TOP_34 + ucPwmId / 2 * 4);
        uiVal = (uiVal >> ((ucPwmId % 2) * 16)) & 0xFFFF;
        Hv_Drv_Ddcci_SetPQToolInfo(uiVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        uiVal = Hv_Drv_Ddcci_GetPQToolInfo();
        Hv_Drv_MPRT_SetOutHighFreqPwmDuty(HV_PROJECT_CONFIG_MPRT_HIGHT_PORT, HV_PROJECT_CONFIG_MPRT_HIGHT_FREQ_PWM_TOTAL - uiVal , uiVal);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdSetFrHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_Video_SetPqCalibrateFrameRate(ucVal);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdSimKey0Handler(UCHAR8 ucCmdType)
{
    /* reserve */
    return;
}

static VOID PQToolCmdSimKey1Handler(UCHAR8 ucCmdType)
{
    /* reserve */
    return;
}
static VOID PQToolCmdSimKey2Handler(UCHAR8 ucCmdType)
{
    /* reserve */
    return;
}
static VOID PQToolCmdSimKey3Handler(UCHAR8 ucCmdType)
{
    /* reserve */
    return;
}
static VOID PQToolCmdSimKey4Handler(UCHAR8 ucCmdType)
{
    /* reserve */
    return;
}

static VOID PQToolCmdCM64Handler(UCHAR8 ucCmdType)
{
    UINT32 uiCM64Addr = 0;
    UCHAR8 ucVal = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /* 返回地址 */
        uiCM64Addr = (UINT32)(Hv_Common_Db_GetDiagDataDBRegionPtr());
        uiCM64Addr &= 0x7FFFFFFF;
        Hv_Drv_Ddcci_SetPQToolInfo(uiCM64Addr + OFFSET_OF(DiagDataDBRegion, ucDBHueAll));
        HV_LOG_INFO(DDCCI,"CM64 return addr 0x%x", uiCM64Addr + OFFSET_OF(DiagDataDBRegion, ucDBHueAll));
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        ucVal = Hv_Drv_Ddcci_GetPQToolStatus();
        if(ucVal == 192)/*Write all 192 number to Silicon*/
        {
            Hv_Mw_PQ_CM64SetAll();
        }
        else/*write only 1 number to Silicon*/
        {
            if(ucVal/64 == 0)//hue
            {
                Hv_Mw_PQ_CM64AxisSetHue(ucVal);
            }
            else if(ucVal/64 == 1)//sat
            {
                Hv_Mw_PQ_CM64AxisSetSat(ucVal - 64);
            }
            else if(ucVal/64 == 2)//lum
            {
                Hv_Mw_PQ_CM64AxisSetLum(ucVal - 128);
            }
            else
            {
                HV_LOG_INFO(DDCCI,"InputError");
            }
        }
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdGmaCompressHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        /*return data*/
        ucVal = HV_PQ_DATABASE_GET(GammaData, ucGammaCompress);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    HV_LOG_INFO(DDCCI, "GMA compress %d\n", ucVal);
    return;
}

static VOID PQToolCmdDynamicPanelHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucSubCmd = 0;
    UCHAR8 ucPanelEn = 0;
    UCHAR8 ucPanelNum = 0;
    UCHAR8 ucPanelId = 0;
    UINT32 uiVal = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        ucSubCmd = Hv_Drv_Ddcci_GetPQToolStatus();
        Hv_Mw_Factory_GetDynamicPanelInfo(&ucPanelEn, &ucPanelId, &ucPanelNum);
        if (ucSubCmd == 0)
        {
            Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucPanelEn);
        }
        else if (ucSubCmd == 1)
        {
            Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucPanelNum);
        }
        else
        {
            Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucPanelId);
        }
        HV_LOG_DEBUG(DDCCI,"Dynamic Panel read cmd %d", ucSubCmd);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {
        /* 写入数值，返回OK */
        uiVal = Hv_Drv_Ddcci_GetPQToolInfo();
        ucPanelEn = U32_BYTE0(uiVal);
        ucPanelId = U32_BYTE2(uiVal);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
        if (ucPanelEn)
        {
            Hv_Mw_Factory_SetDynamicPanelIndex(ucPanelId);
        }
        Hv_Mw_Factory_SetDynamicPanelEn(ucPanelEn);
        HV_LOG_DEBUG(DDCCI,"Dynamic Panel write cmd %d index %d", ucPanelEn, ucPanelId);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static VOID PQToolCmdFactoryModeHandler(UCHAR8 ucCmdType)
{
    UCHAR8 ucVal = 0;
    if (ucCmdType == PQTOOL_CMDTYPE_READ)
    {
        ucVal = HV_COMMON_DATABASE_GET(SystemData, bFactoryMode);
        Hv_Drv_Ddcci_SetPQToolInfo((UINT32)ucVal);
    }
    else if (ucCmdType == PQTOOL_CMDTYPE_WRITE)
    {

        HV_COMMON_DATABASE_SET(SystemData, bFactoryMode, ucVal);
        Hv_Drv_Ddcci_SetPQToolStatus(HV_TRUE);
    }
    else
    {
        Hv_Drv_Ddcci_SetPQToolStatus(HV_FALSE);
    }
    Hv_Drv_Ddcci_SetPQToolCmd(PQTOOL_CMDTYPE_LOWERMSG);
    return;
}

static const DdcciPQTool s_astDdcciPQTool[] = 
{
    {PQTOOL_CMD_GAMMAT,             PQToolCmdGammatHandler},
    {PQTOOL_CMD_HDCP,               PQToolCmdHdcpHandler},
    {PQTOOL_CMD_SN,                 PQToolCmdSNHandler},
    {PQTOOL_CMD_FACWEEK,            PQToolCmdFacWeekHandler},
    {PQTOOL_CMD_FACYEAR,            PQToolCmdFacYearHandler},
    {PQTOOL_CMD_HDMIEDID,           PQToolCmdHdmiEdidHandler},
    {PQTOOL_CMD_HDMI1EDID,          PQToolCmdHdmi1EdidHandler},
    {PQTOOL_CMD_DPEDID,             PQToolCmdDpEdidHandler},
    {PQTOOL_CMD_DP1EDID,            PQToolCmdDp1EdidHandler},
    {PQTOOL_CMD_COLORTEMP_COOL,     PQToolCmdColorTempCoolHandler},
    {PQTOOL_CMD_COLORTEMP_WARM,     PQToolCmdColorTempWarmHandler},
    {PQTOOL_CMD_COLORTEMP_STANDARD, PQToolCmdColorTempStandardHandler},
    {PQTOOL_CMD_COLORTEMP_P3,       PQToolCmdColorTempP3Handler},
    {PQTOOL_CMD_COLORTEMP_SRGB,     PQToolCmdColorTempSrgbHandler},
    {PQTOOL_CMD_COLORTEMP_EYECARE,  PQToolCmdColorTempEyeCareHandler},
    {PQTOOL_CMD_GAMUT_NATIVE,       PQToolCmdGamutNativeHandler},
    {PQTOOL_CMD_GAMUT_SRGB,         PQToolCmdGamutSrgbHandler},
    {PQTOOL_CMD_GAMUT_709,          PQToolCmdGamut709Handler},
    {PQTOOL_CMD_GAMUT_P3,           PQToolCmdGamutP3Handler},
    {PQTOOL_CMD_GAMUT_HDR,          PQToolCmdGamutHDRHandler},
    {PQTOOL_CMD_GAMUT_ADOBE,        PQToolCmdGamutAdobeHandler},
    {PQTOOL_CMD_FACBRIGHTNESS,      PQToolCmdFacBrightnessHandler},
    {PQTOOL_CMD_FACCONTRAST,        PQToolCmdFacContrastHandler},
    {PQTOOL_CMD_ENERGY,             PQToolCmdEnergyHandler},
    {PQTOOL_CMD_DEFAULT_LANG,       PQToolCmdDefaultLangHandler},
    {PQTOOL_CMD_SHARPNESS,          PQToolCmdSharpnessHandler},
    {PQTOOL_CMD_DATABASE_SYNC,      PQToolCmdDatabaseSyncHandler},
    {PQTOOL_CMD_CM64,               PQToolCmdCM64Handler},
    {PQTOOL_CMD_GMACOMPRESS,        PQToolCmdGmaCompressHandler},

    {PQTOOL_CMD_HUE,                PQToolCmdHueHandler},
    {PQTOOL_CMD_SATURATION,         PQToolCmdSatHandler},
    {PQTOOL_CMD_CONTRAST,           PQToolCmdContrastHandler},
    {PQTOOL_CMD_DLC,                PQToolCmdDlcHandler},/* reserve */
    {PQTOOL_CMD_DCR,                PQToolCmdDcrHandler},/* reserve */
    {PQTOOL_CMD_COLORSPACE,         PQToolCmdColorspaceHandler},
    {PQTOOL_CMD_RGAIN,              PQToolCmdRGainHandler},
    {PQTOOL_CMD_GGAIN,              PQToolCmdGGainHandler},
    {PQTOOL_CMD_BGAIN,              PQToolCmdBGainHandler},
    {PQTOOL_CMD_ROFFSET,            PQToolCmdROffsetHandler},
    {PQTOOL_CMD_GOFFSET,            PQToolCmdGOffsetHandler},
    {PQTOOL_CMD_BOFFSET,            PQToolCmdBOffsetHandler},
    {PQTOOL_CMD_RED_HUE,            PQToolCmdRedHueHandler},
    {PQTOOL_CMD_RED_SAT,            PQToolCmdRedSatHandler},
    {PQTOOL_CMD_RED_LUM,            PQToolCmdRedLumHandler},
    {PQTOOL_CMD_GREEN_HUE,          PQToolCmdGreenHueHandler},
    {PQTOOL_CMD_GREEN_SAT,          PQToolCmdGreenSatHandler},
    {PQTOOL_CMD_GREEN_LUM,          PQToolCmdGreenLumHandler},
    {PQTOOL_CMD_BLUE_HUE,           PQToolCmdBlueHueHandler},
    {PQTOOL_CMD_BLUE_SAT,           PQToolCmdBlueSatHandler},
    {PQTOOL_CMD_BLUE_LUM,           PQToolCmdBlueLumHandler},
    {PQTOOL_CMD_CYAN_HUE,           PQToolCmdCyanHueHandler},
    {PQTOOL_CMD_CYAN_SAT,           PQToolCmdCyanSatHandler},
    {PQTOOL_CMD_CYAN_LUM,           PQToolCmdCyanLumHandler},
    {PQTOOL_CMD_YELLOW_HUE,         PQToolCmdYellowHueHandler},
    {PQTOOL_CMD_YELLOW_SAT,         PQToolCmdYellowSatHandler},
    {PQTOOL_CMD_YELLOW_LUM,         PQToolCmdYellowLumHandler},
    {PQTOOL_CMD_MAGENTA_HUE,        PQToolCmdMagentaHueHandler},
    {PQTOOL_CMD_MAGENTA_SAT,        PQToolCmdMagentaSatHandler},
    {PQTOOL_CMD_MAGENTA_LUM,        PQToolCmdMagentaLumHandler},
    {PQTOOL_CMD_PWM,                PQToolCmdPwmHandler},
    {PQTOOL_CMD_SET_FR,             PQToolCmdSetFrHandler},/* reserve */
    {PQTOOL_CMD_SIMKEY0,            PQToolCmdSimKey0Handler},/* reserve */
    {PQTOOL_CMD_SIMKEY1,            PQToolCmdSimKey1Handler},/* reserve */
    {PQTOOL_CMD_SIMKEY2,            PQToolCmdSimKey2Handler},/* reserve */
    {PQTOOL_CMD_SIMKEY3,            PQToolCmdSimKey3Handler},/* reserve */
    {PQTOOL_CMD_SIMKEY4,            PQToolCmdSimKey4Handler},//* reserve */
    {PQTOOL_CMD_DYNAMICPANEL,       PQToolCmdDynamicPanelHandler},
    {PQTOOL_CMD_FACTORYMODE,        PQToolCmdFactoryModeHandler},
    {PQTOOL_CMD_BRIGHTNESS,         PQToolCmdBrightnessHandler},
    {PQTOOL_CMD_WCG_3D_LUT,         PQToolCmdWcg3DLutHandler},
    {PQTOOL_CMD_BRIGHTNESS_NIT,     PQToolCmdDefaultBrightnessNitHandler},
    {PQTOOL_CMD_SETBURNOSD,         PQToolCmdSetBurnOsdHandler},
    {PQTOOL_CMD_SETEDIDSN,          PQToolCmdSetEdidSnHandler}
};


static VOID Hv_MW_Ddcci_ProcPQTool(VOID)
{
    UINT32 uiCmdItem = 0;
    UCHAR8 ucCmdType = 0;

    uiCmdItem = Hv_Drv_Ddcci_GetPQToolItem();
    ucCmdType = Hv_Drv_Ddcci_GetPQToolCmd();
    HV_LOG_DEBUG(DDCCI,"cmd Item %x Type %d", uiCmdItem, ucCmdType);
    for (UCHAR8 ucIndex = 0; ucIndex < ARRAY_SIZE(s_astDdcciPQTool); ++ucIndex)
    {
        if (uiCmdItem == s_astDdcciPQTool[ucIndex].enCmdItem)
        {
            s_astDdcciPQTool[ucIndex].pfActionHandle(ucCmdType);
        }
    }
    return;
}


Status Hv_Mw_Ddcci_Init(VOID)
{
    QueueReset(&s_stDdcciManager.stDdcciInnerMsgQueue);
    #ifdef HV_BOARD_CONFIG_AT
    if (HV_TRUE == HV_COMMON_DATABASE_GET(SystemData, bFactoryMode))
    {
        Hv_Mw_Ddcci_I2cInit();
    }
    #endif

    if (Hv_Mw_Ddcci_GetRunState())
    {
        // hdmi
        Hv_Cal_HdmiRx_DdcciEnable(0, HV_TRUE); // DDCCI_PORT_HDMI0
        Hv_Cal_HdmiRx_DdcciEnable(1, HV_TRUE); // DDCCI_PORT_HDMI1

        // dp
        Hv_Cal_DpRx_MccsEnable(0, HV_TRUE);
        Hv_Cal_DpRx_MccsEnable(1, HV_TRUE);
    }
    else
    {
        Hv_Cal_HdmiRx_DdcciEnable(0, HV_FALSE);
        Hv_Cal_HdmiRx_DdcciEnable(1, HV_FALSE);

        Hv_Cal_DpRx_MccsEnable(0, HV_FALSE);
        Hv_Cal_DpRx_MccsEnable(1, HV_FALSE);
    }

    s_guiFacAddr = ((UINT32)(Hv_Common_Db_GetDefaultFactoryDataDBRegionPtr())) & 0x7FFFFFFF;
    return HV_SUCCESS;
}

VOID Hv_Mw_Ddcci_SendData(DdcciPortEnum enDdcciPort, UCHAR8 *pucWriteArray, UINT32 uiLen)
{
    switch(enDdcciPort)
    {
        case DDCCI_PORT_HDMI0:
        case DDCCI_PORT_HDMI1:
        {
            Hv_Mw_HdmiRx_DdcciSend(enDdcciPort, pucWriteArray, uiLen, HV_FALSE);
            break;
        }

        case DDCCI_PORT_DP0:
        {
            Hv_Drv_DpRx_MccsReply(0, pucWriteArray, uiLen);
            break;
        }

        case DDCCI_PORT_DP1:
        {
            Hv_Drv_DpRx_MccsReply(1, pucWriteArray, uiLen);
            break;
        }
#ifdef HV_BOARD_CONFIG_AT
        case DDCCI_PORT_I2C:
        {
            Hv_Mw_Ddcci_SendI2c(pucWriteArray, uiLen);
            break;
        }
#endif
        default:
        {
            break;
        }
    }
    return;
}
#ifdef HV_BOARD_CONFIG_AT
Status fI2CBack(I2cTransType enTransType, VOID *pvArg)
{
    HvCalI2c *pstSelf = (HvCalI2c*)pvArg;
    if (I2C_SLAVE_RECEIVE == enTransType)
    {

        SystemEvent stSystemEvent = {0};
        HV_VOS_QUEUE_S* pstSysQueue = Hv_Mw_System_GetSystemQueue();
        HV_ASSERT_VALID_PTR_RET_NO_LOG(pstSysQueue, HV_VOS_ISR_NOT_HANDLED);

        stSystemEvent.buffer = Hv_Vos_Malloc(pstSelf->usRxferCount);


        stSystemEvent.enEventType = SYSTEM_REV_EVENT_TYPE_DDCCI;
        stSystemEvent.usEventId = DDCCI_EVENT_RCV;
        stSystemEvent.ucPortIndex = DDCCI_PORT_I2C;
        Hv_Vos_QueueSendFromISR(pstSysQueue, &stSystemEvent);
        Hv_Cal_I2C_SlaveIntReceiveEnable(HV_BOARD_CONFIG_AT);
    }
    return HV_SUCCESS;

}

static VOID Hv_Mw_Ddcci_I2cInit(VOID)
{
    I2cFuncParam   enI2cParam;
    I2cInitParam  stInitParam;

    if (NULL == s_pstDDCI2C)
    {
        Hv_Cal_I2C_InitPin(I2C_MODE_SLAVE, CONFIG_AT_I2C_PORT);
        stInitParam.enPort  = CONFIG_AT_I2C_PORT;
        stInitParam.enMode  = I2C_MODE_SLAVE;
        stInitParam.enSpeed = I2C_SPEED_100K;
        stInitParam.enAddressingMode = I2C_ADDR_7BIT;
        stInitParam.bNewInterface = HV_TRUE;
        stInitParam.fI2cCpltCallback = fI2CBack;
        s_pstDDCI2C = Hv_Cal_I2C_Init(&stInitParam);
        Hv_Cal_I2C_SlaveIntReceiveEnable(CONFIG_AT_I2C_PORT);
    }
    return;
}
static Status Hv_Mw_Ddcci_SendI2c(UCHAR8 *pucData, USHORT16 usSize)
{
    return Hv_Cal_I2C_SlaveTransmit(CONFIG_AT_I2C_PORT, pucData, usSize);
}
#endif

BOOL Hv_Mw_Ddcci_HasInnerMsgs(VOID)
{
    BOOL bHasMsgToProc = QueueIsEmpty(&s_stDdcciManager.stDdcciInnerMsgQueue);
    return !bHasMsgToProc;
}


Status Hv_Mw_Ddcci_ProcInnerMsgs(VOID)
{
    DdcciEvent stDdcciEvent = {0};
    BOOL bHasMsg = HV_FALSE;
    do   
    {
        bHasMsg = PullOneMsgFromDdcciInnerMsgQueue(&s_stDdcciManager.stDdcciInnerMsgQueue, &stDdcciEvent);

        if (HV_TRUE == bHasMsg)
        {
            if(DDCCI_PORT_PQTOOL == stDdcciEvent.ucPort)
            {
                Hv_MW_Ddcci_ProcPQTool();
            }
            else
            {
                if(Hv_Mw_Ddcci_GetRunState())
                {
                    if(s_stDdcciManager.DdcciAppCB != NULL)
                    {
                        s_stDdcciManager.DdcciAppCB(&stDdcciEvent); 
                    }
                }
                else
                {
                    HV_LOG_INFO(DEFAULT,"DDC DISABLE");
                }
            }
        }

    }while ( bHasMsg );

    return HV_SUCCESS;
}


VOID Hv_Mw_Ddcci_SetAppCallback(VOID *CbFunc)
{
    if (CbFunc != NULL)
    {
        s_stDdcciManager.DdcciAppCB = (DdcciAppCallback)CbFunc;
    }
    return;
}

VOID Hv_Mw_Ddcci_SetAppRxCallback(VOID *CbFunc)
{
    if (CbFunc != NULL)
    {
        s_stDdcciManager.DdcciRxCB = (DdcciRx_Callback)CbFunc;
    }
}

Status Hv_Mw_Ddcci_ProcSystemQueueMsg(const SystemEvent* pstSystemEvent)
{
    DdcciEvent stDdcEvent = {0};

    stDdcEvent.ucPort = pstSystemEvent->ucPortIndex;
    if(DDCCI_PORT_PQTOOL == stDdcEvent.ucPort)
    {
        stDdcEvent.aucData[0] = U32_BYTE3(pstSystemEvent->uiValue);
        stDdcEvent.aucData[1] = U32_BYTE2(pstSystemEvent->uiValue);
        stDdcEvent.aucData[2] = U32_BYTE1(pstSystemEvent->uiValue);
        stDdcEvent.aucData[3] = U32_BYTE0(pstSystemEvent->uiValue);
        HV_LOG_DEBUG(DDCCI, "coming pq tool msg, uiValue=0x%03x\n", pstSystemEvent->uiValue);
    }
    else
    {
        HV_LOG_DEBUG(DDCCI, "coming ddcci msg\n");
        if(stDdcEvent.ucPort <= DDCCI_PORT_HDMI1)
        {
            stDdcEvent.ucLen = pstSystemEvent->uiValue;
        }
        else
        {
            stDdcEvent.ucLen = DP_MCCS_CMD_LENGTH;
        }
        HV_MEMCPY(stDdcEvent.aucData, pstSystemEvent->buffer, stDdcEvent.ucLen);

        if(s_stDdcciManager.DdcciRxCB != NULL)
        {
            s_stDdcciManager.DdcciRxCB(stDdcEvent.aucData, stDdcEvent.ucLen);
        }
    }

    return Hv_Mw_Ddcci_SendInnerMsg(&stDdcEvent);
}

VOID Hv_Mw_Ddcci_SetRunState(UCHAR8 ucDdcRun)
{
    HV_COMMON_DATABASE_SET(UserData, ucDDCCI, ucDdcRun);

    if (ucDdcRun)
    {
        Hv_Cal_HdmiRx_DdcciEnable(0, HV_TRUE);
        Hv_Cal_HdmiRx_DdcciEnable(1, HV_TRUE);

        Hv_Cal_DpRx_MccsEnable(0, HV_TRUE);
        Hv_Cal_DpRx_MccsEnable(1, HV_TRUE);
    }
    else
    {
        Hv_Cal_HdmiRx_DdcciEnable(0, HV_FALSE);
        Hv_Cal_HdmiRx_DdcciEnable(1, HV_FALSE);

        Hv_Cal_DpRx_MccsEnable(0, HV_FALSE);
        Hv_Cal_DpRx_MccsEnable(1, HV_FALSE);
    }
}

UCHAR8 Hv_Mw_Ddcci_GetRunState(VOID)
{
    return HV_COMMON_DATABASE_GET(UserData, ucDDCCI);
}

