////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2023 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxhwltuningdump.h
/// @brief Tuning dump definitions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef CAMXHWLTUNINGDUMP_H
#define CAMXHWLTUNINGDUMP_H


CAMX_NAMESPACE_BEGIN

CAMX_BEGIN_PACKED

/// @brief IQ OEM Costom tuning data
const UINT32 IQOEMTuningDataValues      = 256;

/// @brief: CAMX node information, useful for multi-pass usecase
struct IQNodeInformation
{
    UINT32  instanceId;
    UINT64  requestId;
    UINT32  isRealTime;
    UINT32  profileId;
    UINT32  processingType;
} CAMX_PACKED;

/// @brief: CAMX node information, useful for multi-pass usecase
struct IQNodeInformationV2
{
    UINT32  instanceId;
    UINT64  requestId;
    UINT32  isRealTime;
    UINT32  profileId;
    UINT32  processingType;
    UINT16  passID;                 // Pass identification number
    UINT16  isMainPass;             // Flag indicating main pass
    UINT8   passDescription[128];   // Pass string description
} CAMX_PACKED;

/// @brief Structure encapsulating Trigger data
struct IFETuningTriggerData
{
    FLOAT       AECexposureGainRatio;       ///< Input trigger value:  AEC exposure/gain ratio
    FLOAT       AECexposureTime;            ///< Input trigger value:  AEC exposure time
    FLOAT       AECSensitivity;             ///< Input trigger value:  AEC sensitivity data
    FLOAT       AECGain;                    ///< Input trigger value:  AEC Gain Value
    FLOAT       AECLuxIndex;                ///< Input trigger value:  Lux index
    FLOAT       AWBleftGGainWB;             ///< Input trigger value:  AWB G channel gain
    FLOAT       AWBleftBGainWB;             ///< Input trigger value:  AWB B channel gain
    FLOAT       AWBleftRGainWB;             ///< Input trigger value:  AWB R channel gain
    FLOAT       AWBColorTemperature;        ///< Input Trigger value:  AWB CCT value
    FLOAT       DRCGain;                    ///< Input trigger value:  DRCGain
    FLOAT       DRCGainDark;                ///< Input trigger value:  DRCGainDark
    FLOAT       lensPosition;               ///< Input trigger value:  Lens position
    FLOAT       lensZoom;                   ///< Input trigger value:  Lens Zoom
    FLOAT       postScaleRatio;             ///< Input trigger value:  Post scale ratio
    FLOAT       preScaleRatio;              ///< Input trigger value:  Pre scale ratio
    UINT32      sensorImageWidth;           ///< Current Sensor Image Output Width
    UINT32      sensorImageHeight;          ///< Current Sensor Image Output Height
    UINT32      CAMIFWidth;                 ///< Width of CAMIF Output
    UINT32      CAMIFHeight;                ///< Height of CAMIF Output
    UINT16      numberOfLED;                ///< Number of LED
    INT32       LEDSensitivity;             ///< LED Sensitivity
    UINT32      bayerPattern;               ///< Bayer pattern
    UINT32      sensorOffsetX;              ///< Current Sensor Image Output horizontal offset
    UINT32      sensorOffsetY;              ///< Current Sensor Image Output vertical offset
    UINT32      blackLevelOffset;           ///< Black level offset
} CAMX_PACKED;

/// @brief Structure encapsulating Trigger data
struct BPSTuningTriggerData
{
    FLOAT       AECexposureTime;            ///< Input trigger value:  exposure time
    FLOAT       AECSensitivity;             ///< Input trigger value:  AEC sensitivity data
    FLOAT       AECGain;                    ///< Input trigger value:  AEC Gain Value
    FLOAT       AECLuxIndex;                ///< Input trigger value:  Lux index
    FLOAT       AWBleftGGainWB;             ///< Input trigger value:  AWB G channel gain
    FLOAT       AWBleftBGainWB;             ///< Input trigger value:  AWB B channel gain
    FLOAT       AWBleftRGainWB;             ///< Input trigger value:  AWB R channel gain
    FLOAT       AWBColorTemperature;        ///< Input Trigger value:  AWB CCT value
    FLOAT       DRCGain;                    ///< Input trigger value:  DRCGain
    FLOAT       DRCGainDark;                ///< Input trigger value:  DRCGainDark
    FLOAT       lensPosition;               ///< Input trigger value:  Lens position
    FLOAT       lensZoom;                   ///< Input trigger value:  Lens Zoom
    FLOAT       postScaleRatio;             ///< Input trigger value:  Post scale ratio
    FLOAT       preScaleRatio;              ///< Input trigger value:  Pre scale ratio
    UINT32      sensorImageWidth;           ///< Current Sensor Image Output Width
    UINT32      sensorImageHeight;          ///< Current Sensor Image Output Height
    UINT32      CAMIFWidth;                 ///< Width of CAMIF Output
    UINT32      CAMIFHeight;                ///< Height of CAMIF Output
    UINT16      numberOfLED;                ///< Number of LED
    INT32       LEDSensitivity;             ///< LED Sensitivity
    UINT32      bayerPattern;               ///< Bayer pattern
    UINT32      sensorOffsetX;              ///< Current Sensor Image Output horizontal offset
    UINT32      sensorOffsetY;              ///< Current Sensor Image Output vertical offset
    UINT32      blackLevelOffset;           ///< Black level offset
} CAMX_PACKED;

/// @brief IFE Unified HDR data, TuningIFEUnifiedHDRData
struct IFEUnifiedHDRData
{
    DebugDataHeaderV1   header;         ///< DebugData header
    UINT32              numExposures;   ///< Number of exposures
    UINT32              numSubRequests; ///< Number of sub-request
    UINT32              contextType;    ///< Exposure context type
    UINT32              hdrMode;        ///< HDR mode
    UINT32              exposureIndex;  ///< Exposure index, used
    UINT32              reserved[3];    ///< Reserved for additional feature data
} CAMX_PACKED;

/// @brief Structure to encapsulate Sensor data
struct SensorTuningData
{
    PixelFormat         format;            ///< Pixel format
    UINT                numPixelsPerLine;  ///< Number of pixels per line (lineLengthPclk)
    UINT                numLinesPerFrame;  ///< Number of lines per frame (frameLengthLines)
    UINT                maxLineCount;      ///< Max line count
    SensorResolution    resolution;        ///< Sensor output resolution for this mode
    SensorCropInfo      cropInfo;          ///< Crop info for this modes
    UINT                binningTypeH;      ///< Binning horizontal
    UINT                binningTypeV;      ///< Binning vertical
} CAMX_PACKED;

/// @brief Structure encapsulating Sensor configuration data
struct IFEBPSSensorConfigData
{
    INT32                           isBayer;            ///< Flag to indicate Bayer sensor
    INT32                           format;             ///< Image Format
    FLOAT                           digitalGain;        ///< Digital Gain Value
    UINT32                          ZZHDRColorPattern;  ///< ZZHDR Color Pattern Information
    ZZHDRFirstExposurePattern       ZZHDRFirstExposure; ///< ZZHDR First Exposure Pattern
} CAMX_PACKED;

/// @brief: Gamma LUT channels, place holder for tuning-metadata only
enum GammaLUTChannel
{
    GammaLUTChannelR = 0,   ///< R channel
    GammaLUTChannelG = 1,   ///< G channel
    GammaLUTChannelB = 2,   ///< B channel
    GammaMaxChannel  = 3,   ///< Max LUTs
};

/// @brief TMC trigger data
struct TMCTriggerData
{
    DebugDataHeaderV1   header;
    FLOAT               overrideDarkBoostOffset;    ///< Override dark boost offset for user control
    FLOAT               overrideFourthToneAnchor;   ///< Override fourth tone anchor for user control
} CAMX_PACKED;

/// @brief Structure to encapsulate AWB Frame Control
struct TuningAWBFrameControl
{
    FLOAT   AWBGains[RGBChannelCount];          ///< R/G/B gains
    UINT32  colorTemperature;                   ///< Color temperature
    UINT8   isCCMOverrideEnabled;               ///< Flag indicates if CCM override is enabled.
    FLOAT   CCMOffset[AWBNumCCMRows];           ///< The offsets for color correction matrix
    FLOAT   CCM[AWBNumCCMRows][AWBNumCCMCols]; ///< The color correction matrix
} CAMX_PACKED;

/// @brief Structure to encapsulate BHist output
struct TuningBHistStatsOutput
{
    UINT8     ColorChannel;                       ///< the channel type
    UINT32    numBins;                            ///< Num of bins containing valid data
    UINT32    BHistogramStats[MaxBHistBinNum];    ///< Array containing the histogram values
    UINT64    requestID;                          ///< frame for which stats were generated
    UINT8     uniform;                            ///< Select bin uniformity
} CAMX_PACKED;

struct TuningBHistStatsOutputHeader
{
    DebugDataHeaderV1        header;
    TuningBHistStatsOutput   bHistStatsOutput;
} CAMX_PACKED;

struct TuningIHistStatsOutput
{
    UINT16 YCCHistogram[NumIHistBins];      ///< Array containing the either the Y, Cb or Cr histogram values
    UINT16 greenHistogram[NumIHistBins];    ///< Array containing the green histogram values
    UINT16 blueHistogram[NumIHistBins];     ///< Array containing the blue histogram values
    UINT16 redHistogram[NumIHistBins];      ///< Array containing the red histogram values
    UINT32              numBins;            ///< Number of bins per channel
    UINT64              requestID;          ///< frame for which stats were generated
} CAMX_PACKED;

struct TuningIHistStatsOutputHeader
{
    DebugDataHeaderV1        header;
    TuningIHistStatsOutput   iHistStatsOutput;
} CAMX_PACKED;

/// @brief Defines the exposure parameters to control the frame exposure setting to sensor and ISP
struct TuningAECExposureData
{
    UINT64  exposureTime;         ///< The exposure time in nanoseconds used by sensor
    FLOAT   linearGain;           ///< The total gain consumed by sensor only
    FLOAT   sensitivity;          ///< The total exposure including exposure time and gain
    FLOAT   deltaEVFromTarget;    ///< The current exposure delta compared with the desired target
} CAMX_PACKED;

/// @brief Structure to encapsulate AEC Frame Control
struct TuningAECFrameControl
{
    TuningAECExposureData   exposureInfo[ExposureIndexCount];    ///< Exposure info including gain and exposure time
    FLOAT                   luxIndex;                            ///< Future frame lux index,  consumed by ISP
    UINT8                   flashInfo;                           ///< Flash information if it is main or preflash
    UINT8                   preFlashState;                       ///< Preflash state from AEC, consumed by Sensor
    UINT32                  LEDCurrents[LEDSettingCount];        ///< The LED currents value for the use case of LED snapshot
} CAMX_PACKED;

/// @brief Structure to encapsulate custom OEM data from IQ modules
struct IQOEMTuningMetadata
{
    FLOAT   IQOEMTuningData[IQOEMTuningDataValues];
} CAMX_PACKED;

/// @brief MIPI Port information
struct RawMIPIPortConfig
{
    DebugDataHeaderV1   header;
    UINT32              port;
    UINT32              width;
    UINT32              height;
    UINT32              format;
    UINT32              bitsPerPixel;
    UINT32              stride;
    UINT32              sliceHeight;
    UINT32              colorFilterPattern;
    UINT32              padding;
} CAMX_PACKED;

///< @brief Image dimentions with header V1
struct DebugDataHeaderV1ImageDimensions
{
    DebugDataHeaderV1      header;
    UINT32                 width;
    UINT32                 height;
} CAMX_PACKED;

CAMX_END_PACKED

CAMX_NAMESPACE_END
#endif // CAMXHWLTUNINGDUMP_H
