#ifndef __HDMI_EARC_IF_H
#define __HDMI_EARC_IF_H
#include "x_typedef.h"
#include "x_gpio.h"
#include "drv_hdmi2.h"
#include "drv_earc.h"


#define MTK_INTERNEL_EARC_IC 1


typedef void (*x_earc_drv_nfy_machine_state) (EARC_TX_STATE_E eEarcMachineState);

//typedef struct{
    
//    pfnEARCEventCallback pCallback;
//    EARCEvent_t eEventType;
//}CBEventStruct;


enum {
    RET_SUCCESS = 0x00,
    RET_FAIL    = 0x01
};

/*
 * HDMI earc event type. 
 */
typedef enum
{
    HDMI_EARC_NOT_ENABLED = 0,
    HDMI_EARC_WAITING  = 1,
    HDMI_EARC_ENABLED  = 2,
}EARCStatus_t;

enum
{
    HDMI_EARC_NOT_CONNECT = 0,
    HDMI_EARC_CONNECT  = 1,
};

typedef enum
{
    EARC_EVENT_CONNECT_CHG_TO_CEC = 0,
    EARC_EVENT_CONNECT_CHG_TO_AUDIO,
    EARC_EVENT_CONNECT_CHG_TO_APP,
    EARC_EVENT_HBRA_MODE,
    EARC_EVENT_MAX,
}EARCEvent_t;

typedef struct
{
    EARCStatus_t eStatus;
    UINT32 u4PortId;
}EARCPortStatus_t;

typedef struct
{
    BOOL bEARCConnect;
    UINT8 u1Capability;
}EARCAudioStatus_t;

typedef struct
{
    UINT8 u1Status[5];
    UINT8 u1Length;         //5
}EARCChannelStatus_t;

typedef struct
{
    UINT8 u1Info[10];
    UINT8 u1Length;         //10
}EARCAudioInfoFrame_t;

#ifndef EARCEDIDINFO_T
#define EARCEDIDINFO_T
typedef struct
{
    UINT8 u1DataBlock[256];
    BOOL bEARCConnect;   
    UINT8 u1DDP;
    UINT8 u1EAC3;
}EARCEDIDInfo_t;
#endif

typedef struct
{
    UINT8 u1HPDStatus;
    UINT8 u15VStatus;
    BOOL bEnable;
    BOOL bTVStatus;
    BOOL bBtHpStatus;
}EARCInitInfo_t;

typedef void (*pfnEARCEventCallback)(void *pArg);

typedef struct
{
    UINT8 (*pfnSetChannelStatus)(EARCChannelStatus_t *eStatus);
    UINT8 (*pfnSetAudioInfoFrame)(EARCAudioInfoFrame_t *eInfoFrame);
    UINT8 (*pfnSetValidityBit)(BOOL bValidity);
    UINT8 (*pfnSetHPDStatus)(UINT8 u1HpdStatus);
    UINT8 (*pfnSet5VStatus)(UINT8 u15VStatus);
    UINT8 (*pfnSetHBRAInputStatus)(BOOL bHbr);
    UINT8 (*pfnSetLayoutBit)(BOOL bLayout);
    UINT8 (*pfnSetArcStatus)(BOOL bOnOff);
    UINT8 (*pfnSetAudioPath)(BOOL bPath);
    UINT8 (*pfnSetAudioLatency)(INT16 i2Ms);
    UINT8 (*pfnSetTVStatus)(BOOL bTVStatus);
    UINT8 (*pfnSetBtHpStatus)(BOOL bConnect);
    UINT8 (*pfnSetEnable)(BOOL bEn);
    UINT8 (*pfnSetHdmiMute)(BOOL bMute);
    UINT8 (*pfnSetAudioMute)(BOOL bMute);
    EARCStatus_t (*pfnGetEARCStatus)(UINT32 u4PortId);
    UINT8 (*pfnGetEARCAudioStatus)(EARCAudioStatus_t* eStatus);
}EARCFuncTable_t;

typedef struct
{
    BOOL bSupported;            //Hardware support
    BOOL bEnable;                 //Software enable
    BOOL bMWReady;
    BOOL bTVStatus;               //0:TV Speaker, 1:Audio System
    BOOL bBtHpStatus;          //btheadphone status
    BOOL bHbrInputStatus;
    BOOL bValidity;
    BOOL bLayout;
    BOOL bPath;                     //0:spdif 1:i2s
    BOOL bHdmiMute;
    BOOL bAudioMute;
    UINT8 u1DDPOut;             //0:DDP_OUT_OFF, 1:DDP_OUT_AUTO
    UINT8 u1DDPCap;             //0:NOT_CAPABLE, 1:DDP_CAPABLE, 2:ATMOS_CAPABLE
    UINT8 u1DDPeARC;         //
    UINT8 u1HPDStatus;
    UINT8 u15VStatus;
    UINT8 u1ARCStatus;          //0:cec disable arc 1:cec enable arc
    UINT8 u1eARCStatus;
    INT16 i2Latency;                //-250ms ~ 250ms
    pfnEARCEventCallback pfnCallback[EARC_EVENT_MAX];
    EARCFuncTable_t *pFuncTable;
    EARCChannelStatus_t eChStatus;
    EARCAudioInfoFrame_t eAudInfoFrame;
    EARCEDIDInfo_t eEDIDInfo;
    EARC_TX_STATE_E eEarcMachineState;
}EARCObject_t;



/**
 * @brief        Init eARC system
*/
extern void vHDMIEARCSystemInit(void);
/**
 * @brief        Get HBR Input Status
 * @param        pHbr---- pointer, 0:No HBR 1:HBR input
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCIsHBRInput(BOOL *pHbr);

/**
 * @brief        Set Audio Path
 * @param        bPath----0:SPDIF 1:I2S
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCSetAudioPath(BOOL bPath);
/**
 * @brief        Set Audio Latency
 * @param        i2Ms----- 250msec~250msec
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCSetAudioLatency(INT16 i2Ms);
/**
 * @brief        Set TV Status
 * @param        bTVStatus----- 0:TV speaker 1:Audio system
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCMenuSetTVStatus(BOOL bTVStatus);
/**
 * @brief        Set btheadphone Status
 * @param        bConnect----- 0:disconnected 1:connected
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCSetBtHpStatus(BOOL bConnect);
/**
 * @brief        Set ddp Status
 * @param        u1DDPCap-----0:NOT_CAPABLE, 
 *                                                  1:DDP_CAPABLE, 
 *                                                  2:ATMOS_CAPABLE
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCMenuSetDDPCap(UINT8 u1DDPCap);
/**
 * @brief        Set ddp Status
 * @param        u1DDPOut-----0:DDP_OUT_OFF, 1:DDP_OUT_AUTO
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCMenuSetDDPOut(UINT8 u1DDPOut);
/**
 * @brief        Set eARC enable
 * @param        bEn----- 0:disable 1:enable
 * @retval      0 for success, 1 for fail
*/
extern UINT8 u1HDMIEARCSetEnable(BOOL bEn);
/**
 * @brief        JNI to get eARC Audio status(Connection and DD+ capability) for Android App
*/
extern UINT8 u1HDMIEARCGetAudioStatus(EARCAudioStatus_t* eStatus);

/**
 * @brief       
 * @param        
 * @retval      
*/
void vHDMIEARCGetSupported(UINT8 *pu1Info);

/**
 * @brief        
 * @param       
 * @retval      
*/
void vHDMIEARCGetEnable(UINT8 *pu1Info);


BOOL bHDMIEARC_EarcInit(void);

BOOL bHDMIEARC_ArcInit(void);

BOOL bHDMIEARC_GetEarcRxLatency(UINT8* pEarcRxLatency);

EARC_TX_STATE_E eHDMIEARC_GetStateMachine(void);

UINT8 u1HDMISetEARCReady(UINT8 Arg);

void vEARCGetStateCallback(x_earc_drv_nfy_machine_state pfMsNfy,void *pvArg);

void EARC_GetMachineStateCallback(x_earc_drv_nfy_machine_state nfyfp,void *arg);

UINT8  u1HDMI2GetEarcCapabilities(HDMI_IF_SAD_SET_DATA *psaddata);
UINT8 u1HDMIEARCRegFuncTable(EARCFuncTable_t *pFuncTable);

extern BOOL fgHDMIEARCIsSupported(void);
extern UINT8 u1SetMtkHBRAInputStatus(BOOL bHbr);
extern UINT8 u1SetMtkAudioPath(BOOL bPath);
extern UINT8 u1SetMtkAudioLatency(INT16 i2Ms);
extern UINT8 u1SetMtkTVStatus(BOOL bTVStatus);
extern UINT8 u1SetMtkBtHpStatus(BOOL bConnect);
extern UINT8 u1SetMtkEnable(BOOL bEn);
extern UINT8 u1SetMtkAudioMute(BOOL bMute);
extern EARCStatus_t eGetMtkEARCStatus(UINT32 u4PortId);

#endif
