/*******************************************************************************
*
*
* File:         tau_dsi_datatype.h
* Description:  mipi dsi 通用头文件
* Version:      V0.1
* Date:         2021-01-13
* Author:       lzy
 *******************************************************************************/

#ifndef __MIPI_DSI_COMMON_H__
#define __MIPI_DSI_COMMON_H__

/*******************************************************************************
* 1.Included files
*******************************************************************************/
#include "tau_common.h"

/*******************************************************************************
* 2.Global constant and macro definitions using #define
*******************************************************************************/
#define DSC_PPS_SIZE 128

/*******************************************************************************
* 3.Global structures, unions and enumerations using typedef
*******************************************************************************/
/**
* @brief  Data Types for Peripheral-sourced Packets,From Mipi DSI Spec
*/
typedef enum
{
    DSI_ACK_DT_ERROR                 = 0x02,
    DSI_ACK_DT_EOTP                  = 0x08,
    DSI_ACK_DT_GEN_SHORT_RESPONSE_1B = 0x11,
    DSI_ACK_DT_GEN_SHORT_RESPONSE_2B = 0x12,
    DSI_ACK_DT_GEN_LONG_RESPONSE     = 0x1A,
    DSI_ACK_DT_DSC_LONG_RESPONSE     = 0x1C,
    DSI_ACK_DT_DSC_SHORT_RESPONSE_1B = 0x21,
    DSI_ACK_DT_DSC_SHORT_RESPONSE_2B = 0x22,
    DSI_ACK_DT_MAX
} dsi_ack_data_type_e;

/**
* @brief Software handle data types
*/
typedef enum
{
    DSI_RECV_DT_PPS                   = 0x0A,   //Picture Parameter Set
    DSI_RECV_DT_GEN_WRITE_1B          = 0x13,   //Generic Short WRITE, 1 parameter
    DSI_RECV_DT_GEN_WRITE_2B          = 0x23,   //Generic Short WRITE, 2 parameters
    DSI_RECV_DT_GEN_READ_0B           = 0x04,   //Generic READ, no parameters
    DSI_RECV_DT_GEN_READ_1B           = 0x14,   //Generic READ, 1 parameter
    DSI_RECV_DT_GEN_READ_2B           = 0x24,   //Generic READ, 2 parameters
    DSI_RECV_DT_DCS_WRITE_0B          = 0x05,   //DCS Short WRITE, no parameters
    DSI_RECV_DT_DCS_WRITE_1B          = 0x15,   //DCS Short WRITE, 1 parameter
    DSI_RECV_DT_DCS_READ_0B           = 0x06,   //DCS READ, no parameters
    DSI_RECV_DT_GEN_WRITE_LONG        = 0x29,   //Generic Long Write
    DSI_RECV_DT_DCS_WRITE_LONG        = 0x39,   //DCS Long Write/write_LUT Command Packet
    DSI_RECV_DT_MAX
} dsi_data_type_e;

typedef enum
{
    DCS_ENTER_IDLE_MODE       = 0x39,
    DCS_ENTER_INVERT_MODE     = 0x21,
    DCS_ENTER_NORMAL_MODE     = 0x13,
    DCS_ENTER_PARTIAL_MODE    = 0x12,
    DCS_ENTER_SLEEP_MODE      = 0x10,
    DCS_EXIT_IDLE_MODE        = 0x38,
    DCS_EXIT_INVERT_MODE      = 0x20,
    DCS_EXIT_SLEEP_MODE       = 0x11,
    DCS_GET_3D_CONTROL        = 0x3F,
    DCS_GET_ADDRESS_MODE      = 0x0B,
    DCS_GET_BLUE_CHANNEL      = 0x08,
    DCS_GET_COMPRESSION_MODE  = 0x03,
    DCS_GET_DIAGNOSTIC_RESULT = 0x0F,
    DCS_GET_DISPLAY_MODE      = 0x0D,
    DCS_GET_GREEN_CHANNEL     = 0x07,
    DCS_GET_PIXEL_FORMAT      = 0x0C,
    DCS_GET_POWER_MODE        = 0x0A,
    DCS_GET_RED_CHANNEL       = 0x06,
    DCS_GET_SCANLINE          = 0x45,
    DCS_GET_SIGNAL_MODE       = 0x0E,
    DCS_NOP                   = 0x00,
    DCS_READ_DDB_CONTINUE     = 0xA8,
    DCS_READ_DDB_START        = 0xA1,
    DCS_READ_MEMORY_CONTINUE  = 0x3E,
    DCS_READ_MEMORY_START     = 0x2E,
    DCS_SET_3D_CONTROL        = 0x3D,
    DCS_SET_ADDRESS_MODE      = 0x36,
    DCS_SET_COLUMN_ADDRESS    = 0x2A,
    DCS_SET_DISPLAY_OFF       = 0x28,
    DCS_SET_DISPLAY_ON        = 0x29,
    DCS_SET_GAMMA_CURVE       = 0x26,
    DCS_SET_PAGE_ADDRESS      = 0x2B,
    DCS_SET_PARTIAL_COLUMNS   = 0x31,
    DCS_SET_PARTIAL_ROWS      = 0x30,
    DCS_SET_PIXEL_FORMAT      = 0x3A,
    DCS_SET_SCROLL_AREA       = 0x33,
    DCS_SET_SCROLL_START      = 0x37,
    DCS_SET_TEAR_OFF          = 0x34,
    DCS_SET_TEAR_ON           = 0x35,
    DCS_SET_TEAR_SCANLINE     = 0x44,
    DCS_SET_VSYNC_TIMING      = 0x40,
    DCS_SOFT_RESET            = 0x01,
    DCS_WRITE_LUT             = 0x2D,
    DCS_WRITE_MEMORY_CONTINUE = 0x3C,
    DCS_WRITE_MEMORY_START    = 0x2C
} dsi_dcs_cmd_type_e;

/**
* @brief  video data transfer mode
*/
typedef enum
{
    DSI_DATA_VIDEO_MODE = 0,
    DSI_DATA_CMD_MODE   = 1,
    DSI_DATA_MODE_MAX
} dsi_video_data_mode_e;

/**
* @brief  dsi virtual channel
*/
typedef enum
{
    DSI_VC_0 = 0,
    DSI_VC_1 = 1,
    DSI_VC_2 = 2,
    DSI_VC_3 = 3,
    DSI_VC_MAX
} dsi_virtual_channel_e;

/**
* @brief  video data mode
*/
typedef enum
{
    DSI_FRAME_RATE_60HZ  = 0,
    DSI_FRAME_RATE_90HZ  = 1,
    DSI_FRAME_RATE_120HZ = 2,
    DSI_FRAME_RATE_144HZ = 3,
    DSI_FRAME_RATE_160HZ = 4,
    DSI_FRAME_RATE_MAX
} dsi_video_frame_rate_e;

/**
* @brief  dsi rx color coding
*/
typedef enum
{
    DSI_RGB565               = 1,
    DSI_RGB666               = 2,    /*!< 18 bbp(18bits per pixel) */
    DSI_RGB666_LOOSELY       = 3,    /*!< 24 bbp(24bits per pixel) */
    DSI_RGB888               = 4,    /*!< 24 bbp(24bits per pixel) */
    DSI_RGB10_10_10          = 5,
    DSI_RGB12_12_12          = 6,
    DSI_YCbCr422_16          = 7,
    DSI_PENTILE_16           = DSI_YCbCr422_16,
    DSI_YCbCr422_20_LOOSELY  = 8,
    DSI_YCbCr422_24          = 9,
    DSI_YCbCr420_12          = 10,
    DSI_COLOR_CODE_MAX
} dsi_color_code_e;

/**
* @brief  dpi endianness type
*/
typedef enum
{
    DPI_ENDIAN_RGB = 0,
    DPI_ENDIAN_BGR
} dpi_endianness_type_e;

/**
* @brief  dpi polarity type
*/
typedef enum
{
    DPI_SIG_ACTIVE_HIGH = 0,
    DPI_SIG_ACTIVE_LOW  = 1
} dpi_polarity_e;

/**
* @brief  mipi lane number
*/
typedef enum
{
    DSI_LANE_1 = 1,
    DSI_LANE_2 = 2,
    DSI_LANE_3 = 3,
    DSI_LANE_4 = 4,
    DSI_LANE_NUME_MAX
} dsi_lane_nume_e;

/**
* @brief video mode
*/
typedef enum
{
    DSI_NONBURST_PULSE = 0,
    DSI_NONBURST_EVENT = 1,
    DSI_BURST_MODE     = 2,
    DSI_VIDEO_MODE_MAX
} dsi_video_mode_type_e;

/**
* @brief panel init cmd transfer type
*/
typedef enum
{
    DSI_CMD_TX_HS = 0,
    DSI_CMD_TX_LP = 1
} dsi_tx_cmd_tx_type_e;

/**
* @brief  dpi tx vpg style
*/
typedef enum
{
    TX_VPG_V_COLOR     = 0,
    TX_VPG_H_COLOR     = 1,
    TX_VPG_V_BER       = 2,
    TX_VPG_FLICKER     = 3,
    TX_VPG_CHESSBOARD  = 4,
    TX_VPG_MAX
} dsi_tx_vpg_style_e;

#if defined(ISP_568) || defined(ISP_368)
/**
* @brief  angle of rotation
*/
typedef enum
{
    VIDOE_ROT_ANGLE_0    = 0, /* 不旋转       */
    VIDOE_ROT_ANGLE_90   = 1, /* 旋转90度     */
    VIDOE_ROT_ANGLE_180  = 2, /* 旋转180度 */
    VIDOE_ROT_ANGLE_270  = 3, /* 转转270度 */
    VIDOE_ROT_ANGLE_MAX
} video_rotate_angle_e;

/**
* @brief mipi rx lane swap
*/
typedef enum
{
    RX_LANE_ORDER_DEFAULT = 0x0,
    RX_LANE_ORDER_3012 = RX_LANE_ORDER_DEFAULT,
    RX_LANE_ORDER_3210 = 0x1,
    RX_LANE_ORDER_MAX
} dsi_rx_lane_swap_e;

/**
* @brief LTPO mode
*/
typedef enum
{
    LTPO_MODE_NONE  = 0,
    LTPO_MODE_1  = 1,
    LTPO_MODE_2  = 2,
    LTPO_MODE_MAX
} ltpo_mode_e;

/**
* @brief  transform 基本信息
*/
typedef struct
{
    ltpo_mode_e     ltpo;                /* ltpo 模式 */
    bool     mirror_en;                  /* 对video 做水平镜像标志位 */
    video_rotate_angle_e   rot_angle;    /* 对video 做旋转的角度 */
    dsi_video_data_mode_e  dst_mode;     /* mipi tx 输出video 数据传输模式(video/cmd mode) */
    dsi_rx_lane_swap_e     rx_lane_swap; /* rx lane swap */
} dsi_base_extra_info_t;
#endif

/**
* @brief mipi P/N lane swap flag
* eg: pn_swap = RX_LANE_0_PN_SWAP | RX_LANE_CLK_PN_SWAP;
* 表示 lane0 与 CLK 的P跟N交换，其他lane不变
*/
typedef enum
{
    RX_LANE_0_PN_SWAP = 0x1,
    RX_LANE_1_PN_SWAP = 0x2,
    RX_LANE_2_PN_SWAP = 0x4,
    RX_LANE_3_PN_SWAP = 0x8,
    RX_LANE_CLK_PN_SWAP = 0x10
} dsi_rx_lane_pn_swap_e;

/**
* @brief error processing level
*/
typedef enum
{
    ERR_HANDLE_NONE  = 0,
    ERR_HANDLE_L1  = 1,
    ERR_HANDLE_L2  = 2,
    ERR_HANDLE_L3  = 3,
    ERR_HANDLE_MAX
} hal_err_handle_level_e;

/**
* @brief  transform 基本信息
*/
typedef struct
{
    uint32_t src_w;                     /* mipi rx 接收的 width        */
    uint32_t src_h;                     /* mipi rx 接收的 height       */
    uint32_t dst_w;                     /* mipi tx 发送的 width        */
    uint32_t dst_h;                     /* mipi tx 发送的 height       */
    dsi_video_frame_rate_e src_frate;   /* mipi rx 接收的frame rate */
    dsi_video_data_mode_e  src_mode;    /* mipi rx 接收video 数据传输模式(video/cmd mode) */
    uint16_t pn_swap;                   /* mipi rx P/N swap标志位    */
#if defined(ISP_568) || defined(ISP_368)
    dsi_base_extra_info_t  extra_info;  /* ISP_568/ISP_368 新增功能配置 */
#endif
} dsi_base_trans_info_t;

/**
* @brief  ccm系数
*/
typedef struct
{
    uint32_t coef_c00;
    uint32_t coef_c01;
    uint32_t coef_c02;
    uint32_t coef_c10;
    uint32_t coef_c11;
    uint32_t coef_c12;
    uint32_t coef_c20;
    uint32_t coef_c21;
    uint32_t coef_c22;
} ccm_coef_t;

/**
* @brief  video mode display timing
*/
typedef struct
{
    uint32_t    vsa;
    uint32_t    vbp;
    uint32_t    vact;
    uint32_t    vfp;
    uint32_t    hsa;
    uint32_t    hbp;
    uint32_t    hact;
    uint32_t    hfp;
} vid_disp_timing_t;

/**
* @brief  dpi极性配置
*/
typedef struct
{
    dpi_polarity_e   vsync_active_level;    //vsync极性
    dpi_polarity_e   hsync_active_level;    //hsync极性
    dpi_polarity_e   dataen_active_level;   //dataen极性
    dpi_polarity_e   shutdown_active_level; //shutdown极性
    dpi_polarity_e   colorm_active_level;   //colorm极性
} dpi_polarity_t;

/**
* @brief hight performan mode level
*/
typedef enum
{
    HIGHT_PERFORMAN_NONE  = 0,
    HIGHT_PERFORMAN_L1  = 1,
    HIGHT_PERFORMAN_L2  = 2,
    HIGHT_PERFORMAN_MAX
} hight_performan_mode_e;


#endif //__MIPI_DSI_COMMON_H__
