/**
 * @file hv_drv_Led.c
 * @brief led driver layer file.
 * @details This file provides the following functions: \n
 *          (1) led driver init \n
 *          (2) set global brightness control data \n
 *          (3) update led color \n
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-12-16
 * @copyright Copyright(c),2023-12, Hiview Software. All rights reserved.
 * @par History:
  */
#include "Common/Assert/hv_comm_Assert.h"
#include "hv_drv_GpioSimSWire.h"
#include "hv_drv_Led.h"
#include "hv_drv_Tlc5971.h"
static LedDriverId s_enDrvId = LED_DRIVER_ID_MAX;

/**
 * @brief Get led driver id
 * @return led driver id
 */
static inline LedDriverId Hv_Drv_Led_GetId(VOID)
{
    s_enDrvId = LED_DRIVER_ID_TLC5971;
    return s_enDrvId;
}

/**
 * @brief Set serialize global brightness for device daisy chain
 * @param pstPixel pixel RGB data for daisy chain
 */
Status Hv_Drv_Led_SetGlobalBrightness(LedGlBc *pstGbc)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        return Hv_Drv_Led_Tlc5971_SetGlobalBrightness(pstGbc);
    }
    return HV_SUCCESS;
}

/**
 * @brief Set serialize global brightness ratio for device daisy chain by J/K
 * @param ucJ:Numerator
 * @param ucK:Denominator
 */
VOID Hv_Drv_Led_SetGlobalBrightnessRatio(UCHAR8 ucJ, UCHAR8 ucK)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
          Hv_Drv_Led_Tlc5971_SetGlobalBrightnessRatio(ucJ, ucK);
    }
    return;
}

/**
 * @brief Enable/Disable Color Adjust for Led devices
 * @param bEnable enable/disable
 */
VOID Hv_Drv_Led_AdjustColorEnable(BOOL bEnable)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        Hv_Drv_Led_Tlc5971_AdjustColorEnable(bEnable);
    }
    return;
}

/**
 * @brief Update serialize pixel data for device daisy chain
 */
Status Hv_Drv_Led_UpdateColor(VOID)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        return Hv_Drv_Led_Tlc5971_UpdateColor();
    }
    return HV_SUCCESS;
}

/**
 * @brief Fill GS Data Api for Led devices
 * @param uiDevId TLC5971 device id of daisy chain
 * @param enChId TLC5971 channel id
 * @param pstPixel pixel RGB data for daisy chain
 */
Status Hv_Drv_Led_FillColorData(LedDeviceId enDevId, LedChannelId enChId, LedColor *pstPixel)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        return Hv_Drv_Led_Tlc5971_FillColorData(enDevId, enChId, pstPixel);
    }
    return HV_SUCCESS;
}

/**
 * @brief Clear GS Data Api for Led devices
 */
Status Hv_Drv_Led_ClearColorData(VOID)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        return Hv_Drv_Led_Tlc5971_ClearColorData();
    }
    return HV_SUCCESS;
}

/**
 * @brief Dump Data Api for Led devices
 */
Status Hv_Drv_Led_DumpDataBuffer(VOID)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        Hv_Drv_Led_Tlc5971_DumpDataBuffer();
    }
    return HV_SUCCESS;
}

/**
 * @brief Initialize serialize device daisy chain
 * @return Status
 */
Status Hv_Drv_Led_Init(VOID)
{
    if (Hv_Drv_Led_GetId() == LED_DRIVER_ID_TLC5971)
    {
        Hv_Drv_Led_Tlc5971_init();
    }
    return HV_SUCCESS;
}
