/**
 * @file hv_cal_Tlc5971.h
 * @brief Header file of tlc5971 led driver cal module.
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-12-16
 */
#ifndef _HV_CAL_TLC5971_H_
#define _HV_CAL_TLC5971_H_
#include "hv_cal_LedComm.h"

/** Number of supported colors */
#define TLC5971_NUMBER_OF_COLORS    3

/**
 * @brief Number of RGB pixels per TLC5791 device
 *
 * The TLC5971 has 4x RGB outputs per device, where each RGB group constitues a pixel from this
 * drivers point of view.
 */
#define TLC5971_PIXELS_PER_DEVICE   4

/* Length in bytes of data packet per TLC5791 device */
#define TLC5971_PACKET_LEN 28

/**
 * @brief Maximum value for global brightness control, i.e 100% brightness
 */
#define TLC5971_GLOBAL_BRIGHTNESS_CONTROL_MAX 127

/* Global Config of TLC5791 device */
typedef struct _Tlc5971Config 
{
    UCHAR8 ucInitFlag;
    UCHAR8 aucColorMapping[TLC5971_NUMBER_OF_COLORS];
    UCHAR8 ucPixelsNum;/*1 pixel = RGB*/
    UCHAR8 ucColorNum;
    Status (*pfSendData)(UCHAR8* pucData, UINT32 data_len);
} Tlc5971Config;

/* Global data of TLC5791 device */
typedef struct _Tlc5971Data
{
    UCHAR8 *pucDataBuffer; /*All Tlc5971 devices data buffer*/
    LedColor *pstPixels;   /*All Tlc5971 devices pixels*/
    UCHAR8 ucGbcColor1;
    UCHAR8 ucGbcColor2;
    UCHAR8 ucGbcColor3;
    UCHAR8 ucControlData;
} Tlc5971Data;

/* Description of TLC5791 device */
typedef struct _Tlc5971Dev 
{
   Tlc5971Config stConfig;
   Tlc5971Data stData;
} Tlc5971Dev;

/**
 * @brief Fill GS Data Api for TLC5971
 * @param pstDev device pointer
 * @param uiDevId TLC5971 device id of daisy chain
 * @param enChId TLC5971 channel id
 * @param pstPixel pixel RGB data for daisy chain
 */
Status Hv_Cal_Led_Tlc5971_FillGsPixels(Tlc5971Dev *pstDev, LedDeviceId enDevId, LedChannelId enChId, LedColor *pstPixel);

/**
 * @brief Clear GS Data Api for TLC5971
 * @param pstDev device pointer
 */
Status Hv_Cal_Led_Tlc5971_ClearAllGsPixels(Tlc5971Dev *pstDev);

/**
 * @brief dump serialize control data and pixel data for device daisy chain
 * the serializer only supports "full" devices, meaning each device is expected
 * to be mounted with all 4 LEDs.
 * @param pstDev device pointer
 */
VOID Hv_Cal_Led_Tlc5971_Dump_Data_Buffer(Tlc5971Dev *pstDev);

/**
 * @brief Set serialize global brightness for device daisy chain
 * @param pstDev device pointer
 * @param pstPixel pixel RGB data for daisy chain
 */
Status Hv_Cal_Led_Tlc5971_SetGlobalBrightness(Tlc5971Dev *pstDev, LedGlBc *pstGbc);

/**
 * @brief Update serialize pixel data for device daisy chain
 * @param pstDev device pointer
 */
Status Hv_Cal_Led_Tlc5971_UpdateColor(Tlc5971Dev *pstDev);

/**
 * @brief Initialize serialize device daisy chain
 * @param pstDev device pointer
 * @param pvParams paramas for init
 */
Status Hv_Cal_Led_Tlc5971_Init(Tlc5971Dev *pstDev, VOID* pvParams);
#endif /* _HV_CAL_TLC5971_H_ */