/**
 * @file hv_drv_Od.h
 * @brief Header file of od module.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 *
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 0.0.0
 * @date 2022-04-17
 */

#ifndef _HV_DRV_OD_H_
#define _HV_DRV_OD_H_

#include "hv_comm_DataType.h"


/**
 * @brief OD LUT表的大小
 */
typedef enum _ODLutSize
{
    OD_LUT_SIZE_33x33 = 0,
    OD_LUT_SIZE_17x17 = 1,
    OD_LUT_SIZE_MAX
} ODLutSize;

typedef enum _ODCompressRatio
{
    OD_CPR_5_83 = 0,
    OD_CPR_4_23,
} ODCompressRatio;

typedef enum _ODLutSel
{
    OD_SEL_LUT0      = 0,
    OD_SEL_LUT1      = 1,
    OD_SEL_LUT0_LUT1 = 3,
    OD_SEL_MAX
} ODLutSel;

typedef enum _ODLutAccessMode
{
    OD_ACCESS_RGB       = 0,
    OD_ACCESS_SYNC      = 1,
} ODLutAccessMode;

typedef enum _ODResolution
{
    OD_UHD      = 0,
    OD_QHD      = 1,
    OD_FHD      = 2,
} ODResolution;

typedef struct _HvDrvODInitParams
{
    UCHAR8          ucODLutMode;        //0:only lut0; 1:only lut1; 3:lut0&lut1
    UCHAR8          ucODMatrixSize;     //0:33x33; 1:17x17
    UCHAR8          ucODRGBMode;        //0:RGB mode, 1:Sync mode
    UCHAR8          ucCprRatio;         //0-5.83x, 1-4.23x
    UINT32          uiCprDmaAddr;       //ODCPR ddr start address
    const UINT32    *puiODLut0Addr;     //OD lut for lower framerate
    const UINT32    *puiODLut1Addr;     //OD lut for upper framerate
    USHORT16        usHact;             //Hactive from panel
    USHORT16        usVact;             //Vactive from panel
} HvDrvODInitParams;



/**
 * @brief OD使能控制.
 * @param[in] bEnable 控制标志，HV_TRUE-enable od，HV_FALSE-disable od
 * @return None
 */
VOID Hv_Drv_OD_Enable(BOOL bEnable);

/**
 * @brief ODCPR使能控制.
 * @param[in] bEnable 控制标志，HV_TRUE-enable od，HV_FALSE-disable od
 * @return None
 */
VOID Hv_Drv_ODCPR_Enable(BOOL bEnable);

/**
 * @brief 获取当前OD功能是否使能，用于判断以避免重复使能.
 * @return HV_TRUE: 当OD和ODCPR都已经使能时返回，HV_FALSE: 当OD和ODCPRR任一未使能时返回
 */
BOOL Hv_Drv_OD_GetEnableStatus(VOID);

/**
 * @brief OD初始化，包括寄存器设定和lut表载入.
 * @param[in] pstODInitParam point to od init params structure
 * @return None
 */
VOID Hv_Drv_OD_Init(HvDrvODInitParams *pstODInitParam);

/**
 * @brief OD强度控制，根据od的级别刷入对应的lut表.
 * @param[in] ucLevel OD级别, 默认0为关
 * @return None
 */
VOID Hv_Drv_OD_SetLevel(UCHAR8 ucLevel);

/**
 * @brief 设置延迟开OD的标记，当在配置OD使能时需调用本接口，会先开启ODCPR待有缓存帧后再开启OD，以避免画面闪烁
 * @param[in] None
 * @return None
 */
VOID Hv_Drv_OD_SetOdOpenDelayFlag(VOID);

/**
 * @brief 清除延迟开OD的标记，当在帧中断中打开OD后要调用本接口
 * @param[in] None
 * @return None
 */
VOID Hv_Drv_OD_ClearOdOpenDelayFlag(VOID);

/**
 * @brief 获取延迟开OD的标记，在帧中断处理中会读取本标记来决定是否开启OD
 * @param[in] None
 * @return bool
 */
BOOL Hv_Drv_OD_GetOdOpenDelayFlag(VOID);


/**
 * @brief OD 动态CRC校验.
 * @param[in] bEnable flag of TRUE or FALSE.
 * @return None
 */
VOID Hv_Drv_OD_DynamicCrcEnable(BOOL bEnable);

/**
 * @brief OD 动态CRC校验标志位.
 * @return flag
 */
BOOL Hv_Drv_OD_GetDynamicCrcFailFlag(VOID);

/**
 * @brief 获取ODCPR CRC是否已经工作，延迟1-2帧再去获取crc状态
 * @param[in] None
 * @return bool
 */
BOOL Hv_Drv_OD_GetDynamicCrcWorkStatus(void);

/**
 * @brief OD axi reset.
 * @param[in] bRst flag of TRUE or FALSE.
 * @return None
 */
VOID Hv_Drv_OD_OdAxiRst(BOOL bRst);


/**
 * @brief Write OD table
 * @param[in] pucOdTable Pointer of od lut table.
 * @param[in] usTableSize Length of od lut table.
 * @param[in] ucWhichLut Indicates lut0 or lut1.
 * @return None
 */
Status Hv_Drv_OD_SetTable(UCHAR8 *pucOdTable, USHORT16 usTableSize, UCHAR8 ucWhichLut);

VOID Hv_Drv_OD_GatingBypass(BOOL bEn);
#endif
