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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxflashdriverapi.h
/// @brief Flash Driver function declarations
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXFLASHDRIVERAPI_H
#define CAMXFLASHDRIVERAPI_H

#include "camxcommondriverapi.h"

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// RegisterSettingFlash
/// Comments:      Register setting configuration
///                Contains: register address, register data, register address type, register data type,
///                operation and delay in micro seconds
///                 element for slaveAddr
///                 element for registerAddr
///                 element for registerData
///                 element for regAddrType
///                 element for regDataType
///                 element for operation
///                 element for delayUs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct RegisterSettingFlash
{
    /// Slave address to communicate with the device
    UINT32             slaveAddrExists;
    UINT32             slaveAddrID;
    UINT16             slaveAddr;
    /// Register address that is accessed
    UINT32             registerAddr;
    /// List of data items in bytes seperated by space as delimiter.
    /// Data may be written to an I2C slave in burst mode.
    /// If operation is WRITE, a single registerData item is to be written into location specified by registerAddr.
    /// For operation WRITE_BURST, a list of 1 or more registerData items will be written serially starting
    /// at the location specified by registerAddr, and the I2C slave will internally increment the address for each
    /// registerData item.
    /// For operation WRITE_SEQUENTIAL, a list of 1 or more registerData items will be written serially starting
    /// at the location specified by registerAddr, but the address is explicitly generated by the driver for each
    /// registerData item in the list.
    /// If operation is READ, registerData is the number of bytes to be read from the specified register address
    UINT32             registerDataCount;
    UINT32             registerDataID;
    RegisterData*      registerData;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// regAddrType
    ///
    /// Range:         [1,4]
    /// Comments:      Register address / data size in bytes
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    I2CRegAddrDataType regAddrType;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// regDataType
    ///
    /// Range:         [1,4]
    /// Comments:      Register address / data size in bytes
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    I2CRegAddrDataType regDataType;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// operation
    /// Default Value: WRITE
    /// Comments:      Type of I2C operation
    ///                Valid values are: WRITE, WRITE_BURST, WRITE_SEQUENTIAL, READ, POLL
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    OperationType operation;
    /// Delay in micro seconds. Delay is 0 if not explicitly provided
    /// For operation WRITE, the delay value is applied at the end of the single register data item.
    /// For operation WRITE_BURST, WRITE_SEQUENTIAL, the delay value is applied at the end of the burst sequence.
    UINT32             delayUsExists;
    UINT32             delayUsID;
    UINT32             delayUs;
};

/// @brief Brightness register settings information
typedef struct BrightnessRegInfo
{
    UINT                   brightnessFlashLED1Addr;        ///< Register address to program brightness for Flash LED1
    UINT                   brightnessFlashLED2Addr;        ///< Register address to program brightness for Flash LED2
    UINT                   brightnessTorchLED1Addr;        ///< Register address to program brightness for Torch LED1
    UINT                   brightnessTorchLED2Addr;        ///< Register address to program brightness for Torch LED2
} BrightnessRegInfo;

typedef struct FlashLibraryAPI
{
    UINT  size;         ///< Size of flash library API structure
    UINT  majorVersion; ///< Major version of the Library API
    UINT  minorVersion; ///< Minor version of the Library API

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillBrightnessSettingsFlash
    ///
    /// @brief  Fill the brightness settings for FLash
    ///
    /// @param  pSettings                         pointer to flash register settings to be filled
    /// @param  pRegAddress                       pointer to flash LED brightness registers settings to be filled
    /// @param  settingsCount                     Total register count of flash
    /// @param  LEDCurrents[LEDSettingCount]      LED current to fill in register
    ///
    /// @return TRUE if successful else FALSE
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL (*pFillBrightnessSettingsFlash)(
        RegisterSettingFlash* pSettings,
        BrightnessRegInfo* pRegAddress,
        UINT settingsCount,
        UINT highCurrent1,
        UINT highCurrent2);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// FillBrightnessSettingsTorch
    ///
    /// @brief  Fill the brightness settings for Torch
    ///
    /// @param  pSettings                         pointer to Torch register settings to be filled
    /// @param  pRegAddress                       pointer to Torch LED brightness registers settings to be filled
    /// @param  settingsCount                     Total register count of Torch
    /// @param  LEDCurrents[LEDSettingCount]      LED current to fill in register
    ///
    /// @return TRUE if successful else FALSE
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL (*pFillBrightnessSettingsTorch)(
        RegisterSettingFlash* pSettings,
        BrightnessRegInfo* pRegAddress,
        UINT settingsCount,
        UINT lowCurrent1,
        UINT lowCurrent2);

} FlashLibraryAPI;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// GetFlashLibraryAPIs
///
/// @brief Returns the Flash library API structure
///
/// @param pFlashLibraryAPI pointer to the Flash library API structure.
///
/// This function is the entry point for the library. CamX will query the shared library for this method by name.
///
/// @return None
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CDK_VISIBILITY_PUBLIC void GetFlashLibraryAPIs(
    FlashLibraryAPI* pFlashLibraryAPI);

#ifdef __cplusplus
} // CamX Namespace
#endif // __cplusplus

#endif // CAMXFLASHDRIVERAPI_H

