/**
 * @file hv_mw_Ddcci.h
 * @brief Header file of ddcci module.
 * 
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+)  
 * 
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-10
 */

#ifndef __SDK_MIDDLEWARE_DDCCI_H__
#define __SDK_MIDDLEWARE_DDCCI_H__

#include "hv_comm_DataType.h"
#include "hv_comm_Define.h"
#include "hv_comm_Event.h"
#include "hv_vos_Comm.h"
#include "hv_comm_LinkedList.h"

//PQ Tool Start-->
#define PQTOOL_MODIFYFLAG_HDCP2X    (1<<0)
#define PQTOOL_MODIFYFLAG_HDMIEDID  (1<<1)
#define PQTOOL_MODIFYFLAG_GAMMA     (1<<2)
#define PQTOOL_MODIFYFLAG_COLORTEMP (1<<3)
#define PQTOOL_MODIFYFLAG_GAMUT     (1<<4)
#define PQTOOL_MODIFYFLAG_HDCP1X    (1<<5)
#define PQTOOL_MODIFYFLAG_EXITFAC   (1<<6)
#define PQTOOL_MODIFYFLAG_DPEDID    (1<<7)
#define PQTOOL_MODIFYFLAG_HDMI1EDID (1<<8)
#define PQTOOL_MODIFYFLAG_DP1EDID   (1<<9)
#define PQTOOL_MODIFYFLAG_USERDATA  (1<<10)
//End of PQ Tool

/**
 * @brief Ddcci通道的枚举定义
 * @details MiddleWare层在收到ddcci消息时，要配置相应的port到ddcci事件结构体中.
 */
typedef enum _DdcciPortEnum
{
    DDCCI_PORT_HDMI0 = 0,   /**< HDMI Port0 */
    DDCCI_PORT_HDMI1,       /**< HDMI Port1 */
    DDCCI_PORT_DP0,         /**< DP Port0 */
    DDCCI_PORT_DP1,         /**< DP Port1 */
    DDCCI_PORT_PQTOOL,      /**< PQ Tool */
    DDCCI_PORT_I2C,         /**< I2C */
    DDCCI_PORT_MAX,
}DdcciPortEnum;

/**
 * @brief PQ工具通信协议指令Item
 * @details 获取PQ协议时判断具体指令的模块.
 */
typedef enum _PQToolCmdItem
{
    PQTOOL_CMD_GAMMAT               = 0x00,
    PQTOOL_CMD_HDCP                 = 0x01,
    PQTOOL_CMD_SN                   = 0x02,
    PQTOOL_CMD_FACWEEK              = 0x03,
    PQTOOL_CMD_FACYEAR              = 0x04,

    PQTOOL_CMD_HDMIEDID             = 0x05,
    PQTOOL_CMD_HDMI1EDID            = 0x06,
    PQTOOL_CMD_DPEDID               = 0x07,
    PQTOOL_CMD_DP1EDID              = 0x08,

    PQTOOL_CMD_COLORTEMP_COOL       = 0x09,
    PQTOOL_CMD_COLORTEMP_WARM       = 0x0A,
    PQTOOL_CMD_COLORTEMP_STANDARD   = 0x0B,
    PQTOOL_CMD_COLORTEMP_P3         = 0x0C,
    PQTOOL_CMD_COLORTEMP_SRGB       = 0x0D,
    PQTOOL_CMD_COLORTEMP_EYECARE    = 0x0E,

    PQTOOL_CMD_GAMUT_NATIVE         = 0x0F,
    PQTOOL_CMD_GAMUT_SRGB           = 0x10,
    PQTOOL_CMD_GAMUT_709            = 0x11,
    PQTOOL_CMD_GAMUT_P3             = 0x12,
    PQTOOL_CMD_GAMUT_HDR            = 0x13,
    PQTOOL_CMD_GAMUT_ADOBE          = 0x14,

    PQTOOL_CMD_FACBRIGHTNESS        = 0x15,
    PQTOOL_CMD_FACCONTRAST          = 0x16,
    PQTOOL_CMD_ENERGY               = 0x17,
    PQTOOL_CMD_DEFAULT_LANG         = 0x18,
    PQTOOL_CMD_SHARPNESS            = 0x19,
    PQTOOL_CMD_DATABASE_SYNC        = 0x1A,
    PQTOOL_CMD_CM64                 = 0x1B,
    PQTOOL_CMD_GMACOMPRESS          = 0x1C,
    PQTOOL_CMD_HDCP_ALL             = 0x1D,
    PQTOOL_CMD_GAMUT_DISPLAY_P3     = 0x1E,
    PQTOOL_CMD_GAMUT_USER0          = 0x1F,
    PQTOOL_CMD_GAMUT_USER1          = 0x20,
    PQTOOL_CMD_GAMUT_USER2          = 0x21,

    PQTOOL_CMD_HUE                  = 0x200,
    PQTOOL_CMD_SATURATION           = 0x201,
    PQTOOL_CMD_CONTRAST             = 0x202,
    PQTOOL_CMD_DLC                  = 0x203,
    PQTOOL_CMD_DCR                  = 0x204,
    PQTOOL_CMD_COLORSPACE           = 0x205,

    PQTOOL_CMD_RGAIN                = 0x206,
    PQTOOL_CMD_GGAIN                = 0x207,
    PQTOOL_CMD_BGAIN                = 0x208,
    PQTOOL_CMD_ROFFSET              = 0x209,
    PQTOOL_CMD_GOFFSET              = 0x20A,
    PQTOOL_CMD_BOFFSET              = 0x20B,

    PQTOOL_CMD_RED_HUE              = 0x20C,
    PQTOOL_CMD_RED_SAT              = 0x20D,
    PQTOOL_CMD_RED_LUM              = 0x20E,
    PQTOOL_CMD_GREEN_HUE            = 0x20F,
    PQTOOL_CMD_GREEN_SAT            = 0x210,
    PQTOOL_CMD_GREEN_LUM            = 0x211,
    PQTOOL_CMD_BLUE_HUE             = 0x212,
    PQTOOL_CMD_BLUE_SAT             = 0x213,
    PQTOOL_CMD_BLUE_LUM             = 0x214,
    PQTOOL_CMD_CYAN_HUE             = 0x215,
    PQTOOL_CMD_CYAN_SAT             = 0x216,
    PQTOOL_CMD_CYAN_LUM             = 0x217,
    PQTOOL_CMD_YELLOW_HUE           = 0x218,
    PQTOOL_CMD_YELLOW_SAT           = 0x219,
    PQTOOL_CMD_YELLOW_LUM           = 0x21A,
    PQTOOL_CMD_MAGENTA_HUE          = 0x21B,
    PQTOOL_CMD_MAGENTA_SAT          = 0x21C,
    PQTOOL_CMD_MAGENTA_LUM          = 0x21D,

    PQTOOL_CMD_PWM                  = 0x21E,
    PQTOOL_CMD_SET_FR               = 0x21F,

    PQTOOL_CMD_SIMKEY0              = 0x220,
    PQTOOL_CMD_SIMKEY1              = 0x221,
    PQTOOL_CMD_SIMKEY2              = 0x222,
    PQTOOL_CMD_SIMKEY3              = 0x223,
    PQTOOL_CMD_SIMKEY4              = 0x224,
    PQTOOL_CMD_GAMMA_MEA            = 0x225,
    PQTOOL_CMD_DELTAE_MEA           = 0x226,
    PQTOOL_CMD_DYNAMICPANEL         = 0x227,
    PQTOOL_CMD_FACTORYMODE          = 0x228,

    PQTOOL_CMD_LUTINIT              = 0x229,

    PQTOOL_CMD_BRIGHTNESS           = 0x22A,
    PQTOOL_CMD_BRIGHTNESS_NIT       = 0x22B,
    PQTOOL_CMD_WCG_3D_LUT           = 0x22C,
    PQTOOL_CMD_SETBURNOSD           = 0x22D,
    PQTOOL_CMD_SETEDIDSN            = 0x22E,
}PQToolCmdItem;

/**
 * @brief PQ工具通信协议指令type
 * @details 获取PQ协议时判断具体指令的类型.
 */
typedef enum _PQToolCmdType
{
    PQTOOL_CMDTYPE_WRITE,
    PQTOOL_CMDTYPE_READ,
    PQTOOL_CMDTYPE_UPPERMSG,
    PQTOOL_CMDTYPE_LOWERMSG,
}PQToolCmdType;

/**
 * @brief Ddcci PQ工具指令执行
 */
typedef struct _DdcciPQTool
{
    PQToolCmdItem    enCmdItem;
    void             (*pfActionHandle)(UCHAR8 ucCmdType);
}DdcciPQTool;

/**
 * @brief Ddcci事件的结构体定义
 */
 typedef struct _DdcciEvent
{
    UCHAR8              ucLen;       /**< 定义每个事件的数据长度 */
    UCHAR8              ucPort;      /**< 定义每个事件来自于哪个通道，参考枚举值 DdcciPortEnum*/
    UCHAR8              aucData[24]; /**< 对应到事件的具体数据内容 ,HDMI-max 24B,DP-max 16B*/
}DdcciEvent;


/**
 * @brief Ddcci内部消息的结构体定义
 */
typedef struct _DdcciInnerMsg
{
    struct LinkedList   stEntry;        /**< 消息的链表 */
    DdcciEvent          stDdcciEvent;   /**< 对消息数据的封装 */
    BOOL                bUsedFlag;      /**< 该位置的消息是否被使用的标志 */
}__attribute__((aligned(4)))DdcciInnerMsg;


/**
 * @brief Ddcci缓存Queue的个数
 */
#define MAX_DDCCI_QUEUE_SIZE         (5)


/**
 * @brief Ddcci内部消息池的结构体定义
 */
typedef struct _DdcciInnerMsgQueue
{
    USHORT16   usWriteAddr;           /* 写地址 */
    USHORT16   usReadAddr;            /* 读地址 */
    DdcciEvent astFifo[MAX_DDCCI_QUEUE_SIZE];
}__attribute__((aligned(4)))DdcciInnerMsgQueue;


/**
 * @brief 对App层的handler的回调函数
 */
typedef Status (*DdcciAppCallback)(DdcciEvent *pstDdcEvt);


/**
 * @brief 顶层对RX收到数据的回调处理函数， Add for CVTE.
 */
typedef void (*DdcciRx_Callback)(UCHAR8 *pBuf, USHORT16 ucLen);

/**
 * @brief Ddcci handle Structure definition
 */
typedef struct _DdcciManager
{
    DdcciInnerMsgQueue      stDdcciInnerMsgQueue;/*内部消息队列用于缓存挂在SystemTask其他模块发给Ddcci模块的消息*/
    DdcciAppCallback        DdcciAppCB;
    DdcciRx_Callback        DdcciRxCB;           /* For cvt plat */
}__attribute__((aligned(4)))DdcciManager;


/**
 * @brief Ddcci模块初始化.
 * @param[in] None.
 * @return Status  初始化成功后返回HV_SUCCESS.
 */
Status Hv_Mw_Ddcci_Init(VOID);


/**
 * @brief Ddcci模块发送数据接口.
 * @param[in] enDdcciPort 表明要通过哪个端口发送.
 * @param[in] pucWriteArray 指向数据的指针.
 * @param[in] uiLen 数据长度.
 * @return None.
 */
VOID   Hv_Mw_Ddcci_SendData(DdcciPortEnum enDdcciPort, UCHAR8 *pucWriteArray, UINT32 uiLen);

/**
 * @brief 处理SystemQueue中对Ddcci的消息.
 * @param[in] pstSystemEvent System事件封装，其中包含了ddcci或pqtool的消息格式数据.
 * @return Status  初始化成功后返回HV_SUCCESS.
 */
Status Hv_Mw_Ddcci_ProcSystemQueueMsg(const SystemEvent* pstSystemEvent);

/**
 * @brief Ddcci模块发送数据接口.
 * @param[in] None.
 * @return BOOL 如果队列非空则返回true(1).
 */
BOOL   Hv_Mw_Ddcci_HasInnerMsgs(VOID);

/**
 * @brief Ddcci模块对数据的处理接口，包含对消息的解析和处理.
 * @param[in] None.
 * @return Status  消息处理成功后返回HV_SUCCESS.
 */
Status Hv_Mw_Ddcci_ProcInnerMsgs(VOID);


/**
 * @brief 设置App层对ddcci通道上消息的处理函数.
 * @param[in] CbFunc Indicates the function of app layer.
 * @return NONE
 */
VOID Hv_Mw_Ddcci_SetAppCallback(void *CbFunc);


/**
 * @brief 设置App层对ddcci通道上RX消息的回调函数, Add for CVTE.
 * @param[in] CbFunc Indicates the function of app layer.
 * @return NONE
 */
VOID Hv_Mw_Ddcci_SetAppRxCallback(void *CbFunc);

/**
 * @brief Set DDCCI run state.
 * @param[in] ucDdcRun Indicates what state you want the DDCCI to be in. 0:ddcci is not running.
 * @return VOID
 */
VOID Hv_Mw_Ddcci_SetRunState(UCHAR8 ucDdcRun);

/**
 * @brief Get DDCCI run state.
 * @return UCHAR8 0:ddcci is not running
 */
UCHAR8 Hv_Mw_Ddcci_GetRunState(VOID);

#endif

