////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// THIS IS AUTO-GENERATED CODE.  PLEASE DO NOT EDIT (File bug reports against tools).
///
/// Auto-generated by: Parameter Parser V5.5.1 (2411131018)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxsensorcommon.cpp
/// @brief Auto-generated Chromatix parameter file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "camxsensorcommon.h"
#include "parametersetmanager.h"

CAMX_NAMESPACE_BEGIN

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// SetValue/GetValue Functions
/// Gets or sets the requested value
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_I2CFrequencyMode(
    ParameterFileSymbolTableEntry* const entry,
    I2CFrequencyMode& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(I2CFrequencyMode::STANDARD):
            enumValue = I2CFrequencyMode::STANDARD;
            result    = true;
            break;
        case static_cast<UINT32>(I2CFrequencyMode::FAST):
            enumValue = I2CFrequencyMode::FAST;
            result    = true;
            break;
        case static_cast<UINT32>(I2CFrequencyMode::CUSTOM):
            enumValue = I2CFrequencyMode::CUSTOM;
            result    = true;
            break;
        case static_cast<UINT32>(I2CFrequencyMode::FAST_PLUS):
            enumValue = I2CFrequencyMode::FAST_PLUS;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to I2CFrequencyMode", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_OperationType(
    ParameterFileSymbolTableEntry* const entry,
    OperationType& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(OperationType::WRITE):
            enumValue = OperationType::WRITE;
            result    = true;
            break;
        case static_cast<UINT32>(OperationType::WRITE_BURST):
            enumValue = OperationType::WRITE_BURST;
            result    = true;
            break;
        case static_cast<UINT32>(OperationType::WRITE_SEQUENTIAL):
            enumValue = OperationType::WRITE_SEQUENTIAL;
            result    = true;
            break;
        case static_cast<UINT32>(OperationType::READ):
            enumValue = OperationType::READ;
            result    = true;
            break;
        case static_cast<UINT32>(OperationType::POLL):
            enumValue = OperationType::POLL;
            result    = true;
            break;
        case static_cast<UINT32>(OperationType::MAX):
            enumValue = OperationType::MAX;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to OperationType", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_PowerConfigurationType(
    ParameterFileSymbolTableEntry* const entry,
    PowerConfigurationType& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(PowerConfigurationType::MCLK):
            enumValue = PowerConfigurationType::MCLK;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::VANA):
            enumValue = PowerConfigurationType::VANA;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::VDIG):
            enumValue = PowerConfigurationType::VDIG;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::VIO):
            enumValue = PowerConfigurationType::VIO;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::VAF):
            enumValue = PowerConfigurationType::VAF;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::VAF_PWDN):
            enumValue = PowerConfigurationType::VAF_PWDN;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::CUSTOM_REG1):
            enumValue = PowerConfigurationType::CUSTOM_REG1;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::CUSTOM_REG2):
            enumValue = PowerConfigurationType::CUSTOM_REG2;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::RESET):
            enumValue = PowerConfigurationType::RESET;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::STANDBY):
            enumValue = PowerConfigurationType::STANDBY;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::CUSTOM_GPIO1):
            enumValue = PowerConfigurationType::CUSTOM_GPIO1;
            result    = true;
            break;
        case static_cast<UINT32>(PowerConfigurationType::CUSTOM_GPIO2):
            enumValue = PowerConfigurationType::CUSTOM_GPIO2;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to PowerConfigurationType", uintValue);
            break;
        }
    }
    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Read enum value
/// @param entry [in] Symbol table entry
/// @param enumValue [out] Enum value to read
/// @param alignment [in] Symbol table byte alignment
/// @return true if successful
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ReadEnum_ExposureType(
    ParameterFileSymbolTableEntry* const entry,
    ExposureType& enumValue,
    BYTE const alignment)
{
    bool result {false};

    UINT32 uintValue {entry->ReadEnum(&result, alignment)};

    if (result)
    {
        switch (uintValue)
        {
        case static_cast<UINT32>(ExposureType::DEFAULT):
            enumValue = ExposureType::DEFAULT;
            result    = true;
            break;
        case static_cast<UINT32>(ExposureType::SHORT):
            enumValue = ExposureType::SHORT;
            result    = true;
            break;
        case static_cast<UINT32>(ExposureType::MIDDLE):
            enumValue = ExposureType::MIDDLE;
            result    = true;
            break;
        default:
            PARAMETER_LOG_ERROR(entry->SetManager, "Invalid value(% u) converting UINT32 to ExposureType", uintValue);
            break;
        }
    }
    return result;
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load RegisterSetting
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool RegisterSetting::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(slaveAddrExists);
    PARAMETER_INITIALIZE(slaveAddr);
    PARAMETER_INITIALIZE(registerAddr);
    PARAMETER_INITIALIZE(registerData);
    PARAMETER_INITIALIZE(regAddrType);
    PARAMETER_INITIALIZE(regDataType);
    PARAMETER_INITIALIZE(operation);
    PARAMETER_INITIALIZE(delayUsExists);
    PARAMETER_INITIALIZE(delayUs);


    // Reading Optional parameter slaveAddr from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, slaveAddrExists, alignment)
        slaveAddrID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && slaveAddrExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, slaveAddr, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(slaveAddr);
        }
    }
    SYMBOL_TABLE_ENTRY_READ(entry, result, registerAddr, alignment)

    // Reading Array registerData from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        registerDataCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, registerDataCount, alignment)
        constexpr const CHAR* const file {__FILE__};
        constexpr INT32 line {LINE_CONST};
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }

        if (result)
        {
            registerDataID = pointerEntry->ID;
            DupObjInfo* registerDataDupInfo = pointerEntry->GetDupObject(registerDataCount, file, line);
            if (registerDataDupInfo != nullptr && registerDataDupInfo->Object != nullptr)
            {
                registerData = (UINT32*)registerDataDupInfo->Object;
                if (registerData == nullptr)
                {
                    if (registerDataDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "registerData duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            registerDataDupInfo->File, registerDataDupInfo->Line, registerDataDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "registerData duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            registerDataDupInfo->Line, registerDataDupInfo->RefCount);
                    }
                }
            }

            if (registerData == nullptr)
            {
                if (result && registerDataCount > 0)
                {
                    registerData = pointerEntry->ReadArray<UINT32>(registerDataCount, alignment);
                    result = registerData != nullptr;
                }
                if (!result || registerData == nullptr)
                {
                    if (registerDataCount > 0)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "Failed to allocate registerData\n");
                    }
                    registerDataCount = 0;
                }
            }
        }
        if (registerData == nullptr)
        {
            registerDataCount = 0;
        }
    }
    SYMBOL_TABLE_ENTRY_READ(entry, result, regAddrType, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, regDataType, alignment)
    if (result)
    {
        result = ReadEnum_OperationType(entry, operation, alignment);
    }

    // Reading Optional parameter delayUs from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, delayUsExists, alignment)
        delayUsID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && delayUsExists)
        {
            SYMBOL_TABLE_ENTRY_READ(pointerEntry, result, delayUs, alignment)
        }
        else
        {
            PARAMETER_INITIALIZE(delayUs);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load SettingsInfo
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool SettingsInfo::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(regSetting);


    // Reading Array regSetting from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        regSettingCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, regSettingCount, alignment)
        constexpr const CHAR* const file {__FILE__};
        constexpr INT32 line {LINE_CONST};
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }

        if (result)
        {
            regSettingID = pointerEntry->ID;
            DupObjInfo* regSettingDupInfo = pointerEntry->GetDupObject(regSettingCount, file, line);
            if (regSettingDupInfo != nullptr && regSettingDupInfo->Object != nullptr)
            {
                regSetting = (RegisterSetting*)regSettingDupInfo->Object;
                if (regSetting == nullptr)
                {
                    if (regSettingDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "regSetting duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            regSettingDupInfo->File, regSettingDupInfo->Line, regSettingDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "regSetting duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            regSettingDupInfo->Line, regSettingDupInfo->RefCount);
                    }
                }
            }

            if (regSetting == nullptr)
            {
                if (result && regSettingCount > 0)
                {
                    regSetting = PARAMETER_NEW RegisterSetting[regSettingCount];
                    (void)pointerEntry->SetDupObject(regSetting, regSettingCount, file, line);
                }
                if (!result || regSetting == nullptr)
                {
                    if (regSettingCount > 0)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "Failed to allocate regSetting\n");
                    }
                    regSettingCount = 0;
                }
                for (UINT32 i = 0; result && i < regSettingCount; i++)
                {
                    result = regSetting[i].Load(pointerEntry, alignment);
                }
            }
        }
        if (regSetting == nullptr)
        {
            regSettingCount = 0;
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PowerSetting
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PowerSetting::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(configType);
    PARAMETER_INITIALIZE(configValue);
    PARAMETER_INITIALIZE(delayMs);

    result = ReadEnum_PowerConfigurationType(entry, configType, alignment);
    SYMBOL_TABLE_ENTRY_READ(entry, result, configValue, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, delayMs, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load PowerSequenceInfo
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool PowerSequenceInfo::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(powerSetting);
    PARAMETER_INITIALIZE(powerRegisterSettingsExists);
    PARAMETER_INITIALIZE(powerRegisterSettings);


    // Reading Array powerSetting from symbol table
    // Do not check result value here because the count value needs to be initialized in this block
    {
        powerSettingCount = 0;
        SYMBOL_TABLE_ENTRY_READ(entry, result, powerSettingCount, alignment)
        constexpr const CHAR* const file {__FILE__};
        constexpr INT32 line {LINE_CONST};
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }

        if (result)
        {
            powerSettingID = pointerEntry->ID;
            DupObjInfo* powerSettingDupInfo = pointerEntry->GetDupObject(powerSettingCount, file, line);
            if (powerSettingDupInfo != nullptr && powerSettingDupInfo->Object != nullptr)
            {
                powerSetting = (PowerSetting*)powerSettingDupInfo->Object;
                if (powerSetting == nullptr)
                {
                    if (powerSettingDupInfo->File != nullptr)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "powerSetting duplicate found but object is nullptr: %s:%d, RefCount: %d\n",
                            powerSettingDupInfo->File, powerSettingDupInfo->Line, powerSettingDupInfo->RefCount);
                    }
                    else
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "powerSetting duplicate found but Object is nullptr: <nullptr file ptr>:%d, RefCount: %d\n",
                            powerSettingDupInfo->Line, powerSettingDupInfo->RefCount);
                    }
                }
            }

            if (powerSetting == nullptr)
            {
                if (result && powerSettingCount > 0)
                {
                    powerSetting = PARAMETER_NEW PowerSetting[powerSettingCount];
                    (void)pointerEntry->SetDupObject(powerSetting, powerSettingCount, file, line);
                }
                if (!result || powerSetting == nullptr)
                {
                    if (powerSettingCount > 0)
                    {
                        PARAMETER_LOG_ERROR(entry->SetManager, "Failed to allocate powerSetting\n");
                    }
                    powerSettingCount = 0;
                }
                for (UINT32 i = 0; result && i < powerSettingCount; i++)
                {
                    result = powerSetting[i].Load(pointerEntry, alignment);
                }
            }
        }
        if (powerSetting == nullptr)
        {
            powerSettingCount = 0;
        }
    }

    // Reading Optional parameter powerRegisterSettings from symbol table
    {
        SYMBOL_TABLE_ENTRY_READ(entry, result, powerRegisterSettingsExists, alignment)
        powerRegisterSettingsID = entry->ID;
        ParameterFileSymbolTableEntry  pointerEntryCls;
        ParameterFileSymbolTableEntry* const pointerEntry = &pointerEntryCls;
        if (result)
        {
            result = entry->Table->ReadPointerEntry(pointerEntryCls, entry, alignment);
        }
        if (result && powerRegisterSettingsExists)
        {
            if (result)
            {
                result = powerRegisterSettings.Load(pointerEntry, alignment);
            }
        }
        else
        {
            PARAMETER_INITIALIZE(powerRegisterSettings);
        }
    }

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load FrameDimension
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool FrameDimension::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(xStart);
    PARAMETER_INITIALIZE(yStart);
    PARAMETER_INITIALIZE(width);
    PARAMETER_INITIALIZE(height);

    SYMBOL_TABLE_ENTRY_READ(entry, result, xStart, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, yStart, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, width, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, height, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load Dimension
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Dimension::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(width);
    PARAMETER_INITIALIZE(height);

    SYMBOL_TABLE_ENTRY_READ(entry, result, width, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, height, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Load Position
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Position::Load(
    ParameterFileSymbolTableEntry* const entry,
    BYTE const alignment)
{
    bool result = true;

    PARAMETER_INITIALIZE(x);
    PARAMETER_INITIALIZE(y);

    SYMBOL_TABLE_ENTRY_READ(entry, result, x, alignment)
    SYMBOL_TABLE_ENTRY_READ(entry, result, y, alignment)

    return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload RegisterSetting
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void RegisterSetting::Unload(ParameterFileSymbolTable* const __table)
{
    if (__table != nullptr && __table->ReleaseDupObject(registerData))
    {
        PARAMETER_DELETE[] registerData;
    }
    registerData = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload SettingsInfo
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SettingsInfo::Unload(ParameterFileSymbolTable* const __table)
{
    for (UINT32 i = 0; i < regSettingCount; i++)
    {
        regSetting[i].Unload(__table);
    }
    if (__table != nullptr && __table->ReleaseDupObject(regSetting))
    {
        PARAMETER_DELETE[] regSetting;
    }
    regSetting = nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Unload PowerSequenceInfo
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PowerSequenceInfo::Unload(ParameterFileSymbolTable* const __table)
{
    if (__table != nullptr && __table->ReleaseDupObject(powerSetting))
    {
        PARAMETER_DELETE[] powerSetting;
    }
    powerSetting = nullptr;
    powerRegisterSettings.Unload(__table);
}
CAMX_NAMESPACE_END
