/**
 * @file hv_cal_OsdIndex.h
 * @brief Osd Cal layer index interface.
 * @verbatim
 * ==============================================================================
 *                        ##### How to use this driver #####
 * ==============================================================================
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 2022-08-22
 */


#ifndef _HV_CAL_OSDINDEX_H
#define _HV_CAL_OSDINDEX_H

#include "hv_comm_DataType.h"

#define OSD_INDEX_ROW_SIZE 4 /* in bytes */
#define OSD_INDEX_COLUMN_SIZE 3 // in bytes

//#define INDEX_USING_UNCACHED_MEMORY 1
#ifdef INDEX_USING_UNCACHED_MEMORY
#define INDEXROW(addr) ((OsdIndexRow*)((UINT32)(addr) | 0xA0000000))
#define INDEXCOLUMN(addr) ((OsdIndexColumn*)((UINT32)(addr) | 0xA0000000))
#else
#define INDEXROW(addr) ((OsdIndexRow*)(addr))
#define INDEXCOLUMN(addr) ((OsdIndexColumn*)(addr))
#endif

typedef enum _OsdPaletteType
{
    OSD_PALETTE_TYPE_FONT = 0,
    OSD_PALETTE_TYPE_BMP,
} OsdPaletteType;

typedef enum _OsdRowType
{
    OSD_ROW_FONT = 0,
    OSD_ROW_BMP,
    OSD_ROW_EMPTY,
} OsdRowType;

typedef enum _OsdColumnType
{
    OSD_COLUMN_BLANK = 0,
    OSD_COLUMN_FONT,
    OSD_COLUMN_BMP,
} OsdColumnType;

typedef struct _OsdIndexRow
{
    /*
    * 0: Normal row
    * 1: End row
    */
    UINT32 rowAttr                          : 1; /* [00:00] */
    /*
    * 0: Row enable
    * 1: Row disable
    */
    UINT32 rowDisable                       : 1; /* [01:01] */
    /*
    * 0: Font Row
    * 1: BMP  Row
    */
    UINT32 rowType                          : 1; /* [02:02] */
    /*
    * 0: Background of characters is transparent
    * 1: Background of characters from regs
    */
    UINT32 fontBgEn                         : 1; /* [03:03] */
    /*
    * 0: Blink disable
    * 1: Blink enable
    */
    UINT32 blinkEnable                      : 1; /* [04:04] */
    /*
    * 0: Single pixel char clock enable
    * 1: Double pixel char clock enable
    */
    UINT32 dbPixelEn                        : 1; /* [05:05] */
    /*
    * 0: Single scan line enable
    * 1: Double scan line enable
    */
    UINT32 dbScnEn                          : 1; /* [06:06] */
    /*
    * font select [9]
    */
    UINT32 fontCurIdx                       : 1; /* [07:07] */
    /*
    * Horizontal space between Character  :0~15 pixel
    */
    UINT32 curHspcNum                       : 4; /* [11:08] */
    /*
    * Row space according to the upper row:0~15 lines
    */
    UINT32 curVspcNum                       : 4; /* [15:12] */
    /*
    * character number per row
    */
    UINT32 rowLen                           : 8; /* [23:16] */
    /*
    * font reg select
    * 000: 43[15: 0]
    * 001: 43[31:16]
    * 010: 44[15: 0]
    * 011: 44[31:16]
    * 100: 45[15: 0]
    * 101: 45[31:16]
    * 110: 46[15: 0]
    * 111: 46[31:16]
    *
    */
    UINT32 attrHsz                          : 3; /* [26:24] */
    /*
    * FONT INDEX FORMAT, NOT FOR THIS REGISTED
    * [8:0] font_cur_idx font select [8:0]
    * [9]     blank_font_en "Blank Font Enable
    *            0:normal character
    *            1: blank  character"
    * [17:10] fgc_idx Foreground color index
    * [23:18] attr_detla
    *             0: 0 ~ -31 pixels,decrease
    *             1: 0 ~  31 pixels,increase
    */
    UINT32 Reserved                         : 2; /* [28:27] */
    /*
    * font type
    * 000:  1-bit font/bmp;
    * 001:  2-bit font/bmp;
    * 010:  4-bit font/bmp;
    * 011:  6-bit bmp;
    * 100:  8-bit bmp;
    *
    */
    UINT32 fontType                         : 3; /* [31:29] */
} __attribute__((packed)) OsdIndexRow;

typedef struct _OsdIndexColumn
{
    UINT32 fontCurIdx                       : 9; /* [8:0] */
    UINT32 blankFontEn                      : 1; /* [9:9] */
    UINT32 fgcIdx                           : 8; /* [17:10] */
    UINT32 deltaValue                       : 5; /* [22:18] */
    UINT32 deltaDir                         : 1; /* [23:23] */
} __attribute__((packed)) OsdIndexColumn;

/**
 * @brief set row attribute
 * @param[in] pstRow row structure
 * @param[in] bIsNormalRow 1 for normal row, 0 for end row
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowAttr(OsdIndexRow *pstRow, BOOL bIsNormalRow);

/**
 * @brief get row enable/disable status
 * @param[in] pstRow row structure
 * @return HV_TRUE for enable, HV_FALSE for disable
 */
BOOL Hv_Cal_OsdIndex_GetRowEnable(OsdIndexRow *pstRow);

/**
 * @brief set row enable/disable status
 * @param[in] pstRow row structure
 * @param[in] bEnable 1 for enable, 0 for disable
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowEnable(OsdIndexRow *pstRow, BOOL bEnable);

/**
 * @brief set row type
 * @param[in] pstRow row structure
 * @param[in] enType row type OSD_ROW_FONT: font row
 *                            OSD_ROW_BMP: bmp row
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowType(OsdIndexRow *pstRow, OsdRowType enType);

/**
 * @brief set column count of row
 * @param[in] pstRow row structure
 * @param[in] ucRowLen column count
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowLen(OsdIndexRow *pstRow, UCHAR8 ucRowLen);

/**
 * @brief set row blink enable/disable status
 * @param[in] pstRow row structure
 * @param[in] bEnable 0 for enable, 1 for disable
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowBlinkEnable(OsdIndexRow *pstRow, BOOL bEnable);

/**
 * @brief select which half of 1024 resource for row
 * @param[in] pstRow row structure
 * @param[in] bSelect which half, 0 for 0~511, 1 for 512~1023
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowFontLibSel(OsdIndexRow *pstRow, BOOL bSelect);

/**
 * @brief set H space between columns
 * @param[in] pstRow row structure to set hspace
 * @param[in] ucNum space number, 0~15
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowHSpace(OsdIndexRow *pstRow, UCHAR8 ucNum);

/**
 * @brief set V space between row
 * @param[in] pstRow row structure to set vspace
 * @param[in] ucNum space number, 0~15
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowVSpace(OsdIndexRow *pstRow, UCHAR8 ucNum);

/**
 * @brief set resource bit of row
 * @param[in] pstRow row structure
 * @param[in] enType resource bit
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowFontType(OsdIndexRow *pstRow, OsdResourceType enType);

/**
 * @brief select resource for row
 * @param[in] pstRow row structure
 * @param[in] ucIndex resource index in window resource settings
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetRowFontLibIndex(OsdIndexRow *pstRow, UCHAR8 ucIndex);

/**
 * @brief get font index of column
 * @param[in] pstCol column structure
 * @return index value
 */
USHORT16 Hv_Cal_OsdIndex_GetColIndex(OsdIndexColumn *pstCol);

/**
 * @brief select font for column
 * @param[in] pstCol column structure
 * @param[in] usIndex index value, 0~511
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetColIndex(OsdIndexColumn *pstCol, USHORT16 usIndex);

/**
 * @brief check if column is blank
 * @param[in] pstCol column structure
 * @return HV_TRUE if column is blank, otherwise HV_FALSE
 */
BOOL Hv_Cal_OsdIndex_IsBlankColumn(OsdIndexColumn *pstCol);

OsdColumnType Hv_Cal_OsdIndex_GetColType(OsdIndexColumn *pstCol);
/**
 * @brief set column type
 * @param[in] pstCol column structure
 * @param[in] enType column type OSD_COLUMN_BLANK: blank column
 *                               OSD_COLUMN_FONT: font column
 *                               OSD_COLUMN_BMP: bmp column
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetColType(OsdIndexColumn *pstCol, OsdColumnType enType);

/**
 * @brief set width of blank column
 * @param[in] pstCol column structure
 * @param[in] usBlankWidth blank width
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetColBlankWidth(OsdIndexColumn *pstCol, USHORT16 usBlankWidth);

/**
 * @brief set color index of Font column
 * @param[in] pstCol column structure
 * @param[in] usColorIndex color index, 0~255
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetFontColColorIndex(OsdIndexColumn *pstCol, USHORT16 usColorIndex);

USHORT16 Hv_Cal_OsdIndex_GetBMPColColorIndex(OsdIndexColumn *pstCol);
/**
 * @brief set color index of BMP column
 * @param[in] pstCol column structure
 * @param[in] usColorIndex color index, 0~511
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetBMPColColorIndex(OsdIndexColumn *pstCol, USHORT16 usColorIndex);

/**
 * @brief select palette for BMP
 * @param[in] pstCol column structure
 * @param[in] enType palette type OSD_PALETTE_TYPE_FONT: font palette
 *                                OSD_PALETTE_TYPE_BMP: bmp palette
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetBmpstColPaletteSel(OsdIndexColumn *pstCol, OsdPaletteType enType);

/**
 * @brief get delta direction
 * @param[in] pstCol column structure
 * @return HV_TRUE for increase, otherwise HV_FALSE
 */
BOOL Hv_Cal_OsdIndex_DeltaIsIncrease(const OsdIndexColumn *pstCol);

/**
 * @brief get delta of column
 * @param[in] pstCol column structure
 * @return delta value, without direction
 */
UCHAR8 Hv_Cal_OsdIndex_GetColDelta(const OsdIndexColumn *pstCol);

/**
 * @brief set delta of column
 * @param[in] pstCol column structure
 * @param[in] bIsIncrease delta direction, 1 to increase space, 0 to decrease
 * @param[in] ucDelta delta value
 * @return VOID without return
 */
VOID Hv_Cal_OsdIndex_SetColDelta(OsdIndexColumn *pstCol, BOOL bIsIncrease,  UCHAR8 ucDelta);

#endif
