/*
 * @file hv_pm51_driver_PWM.h
 * @brief Header file of PWM driver.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */

#ifndef __HV_PM51_DRIVER_PWM_H__
#define __HV_PM51_DRIVER_PWM_H__

#include "hv_pm51_Base.h"

#define PWM_PRESCALER_DEFAULT       (2048)
#define PWM_COUNTS_PER_SEC_DEFAULT  (C51_CLK_FREQ/PWM_PRESCALER_DEFAULT)

typedef enum _PwmPol
{
    E_PWM_POL_LOW = 0,
    E_PWM_POL_HIGH = 1
} PwmPol;

typedef enum _PwmCntMode
{
    E_PWM_CNT_MODE_UP = 0,
    E_PWM_CNT_MODE_UP_DOWN = 1
} PwmCntMode;

typedef struct _PwmParam
{
    UCHAR8         ucPrescaler;      /* PWM clock prescaler */
    PwmPol         enPol;            /* PWM output polarity */   
    PwmCntMode     enCntMode;        /* PWM counter mode, 1: up-down mode, 0: up mode */
    USHORT16       ucCntTopVal;        /* PWM counter top value */
    USHORT16       usCmpStartVal;    /* PWM compare start value */
    USHORT16       usCmpEndVal;        /* PWM compare end value */
    USHORT16       usCmpStepVal;    /* PWM compare step value */
}PwmParam;

/**
 * @brief PWM initialization.
 * @param[in] pstParam: Pointer to an initialized structure for PWM. 
 * @return None.
 */
void Hv_PM51_Pwm_Init(PwmParam *pstParam);

/**
 * @brief Start the PWM.
 * @return None.
 */
void Hv_PM51_Pwm_Start(void);

/**
 * @brief Stop PWM.
 * @return None.
 */
void Hv_PM51_Pwm_Stop(void);

/**
 * @brief Set clock prescaler of PWM.
 * @return None.
 */
void Hv_PM51_Pwm_SetPrescaler(UCHAR8 ucPrescaler);

/**
 * @brief Set polarity of PWM.
 * @return None.
 */
void Hv_PM51_Pwm_SetPol(PwmPol enPol);

/**
 * @brief Set counter mode of PWM.
 * @param[in] ucMode: E_PWM_CNT_MODE_UP or E_PWM_CNT_MODE_UP_DOWN. 
 * @return None.
 */
void Hv_PM51_Pwm_SetCntMode(UCHAR8 ucMode);

/**
 * @brief Set counter top value of PWM.
 * @param[in] usTopVal: counter top value. 
 * @return None.
 */
void Hv_PM51_Pwm_SetCntTopVal(USHORT16 usTopVal);

/**
 * @brief Set output enable of PWM.
 * @return None.
 */
void Hv_PM51_Pwm_SetOutputEnable(void);

/**
 * @brief Set output disable of PWM.
 * @return None.
 */
void Hv_PM51_Pwm_SetOutputDisable(void);

/**
 * @brief Set compare start value of PWM.
 * @param[in] usStartVal: compare start value. 
 * @return None.
 */
void Hv_PM51_Pwm_SetCmpStartVal(USHORT16 usStartVal);

/**
 * @brief Set compare stop value of PWM.
 * @param[in] usStartVal: compare stop value. 
 * @return None.
 */
void Hv_PM51_Pwm_SetCmpEndVal(USHORT16 usEndVal);

/**
 * @brief Set step value of PWM.
 * @param[in] usStartVal: step value. 
 * @return None.
 */
void Hv_PM51_Pwm_SetStepVal(USHORT16 usStepVal);

/**
 * @brief Set cycle number of PWM, and after this cycle, generate an interrupt.
 * @param[in] usVal: PWM cycle value. 
 * @return None.
 */
void Hv_PM51_Pwm_SetCycleNum(USHORT16 usVal);

#endif
