/*********************************************************
*Copyright (C), 2024-2030
*文件名:	Pwm.h
*版  本:	Ver1.00
*日  期:	2025/04/30
*描  述:	Pwm配置
*备  注:	
**********************************************************/
#ifndef   __Pwm_H__
#define   __Pwm_H__
#include "common.h"

#define PWM_PDIV_MAX   0x0F

#define CLR_BIT(value,n) ((value)&=~(1<<(n))) 
#define SET_BIT(value,n) ((value)|= (1<<(n))) 

#define GET_BIT(value,n) ((value)&(1<<(n)))  
#define CPL_BIT(value,n) ((value)^=(1<<(n)))

/* 自动清零模式 */
#define __CLR_MODE__ 

typedef enum
{
	PWM0 = 0,
	PWM1,
	PWM2,
	PWM3,
	PWM4,
	PWM5,
	PWM6,
	PWM7,
	PWM_TOTAL
}PWM_NUM_ENUM;

typedef enum
{
	PWM0_1 = 0, 
	PWM2_3 = 2, 
	PWM4_5 = 4, 
	PWM6_7 = 6,
	PWM_PDIV_TOTAL
}PWM_N_ENUM;

typedef enum
{
	PWM_MODE_INDP, /* 独立输出 */
	PWM_MODE_COMP, /* 互补输出 */
	PWM_MODE_TOTAL
}PWM_MODE_ENUM;

typedef enum
{
	PWM_CLK_SYS,
	PWM_CLK_HRC,
	PWM_CLK_LRC,
	PWM_CLK_LOSC,
	PWM_CLK_MODE_TOTAL
}PWM_CLK_ENUM;

typedef enum
{
	PWM_IO_P00 = 0x00,
	PWM_IO_P01 = 0x01,
	PWM_IO_P02 = 0x02,
	PWM_IO_P03 = 0x03,
	PWM_IO_P04 = 0x04,
	PWM_IO_P05 = 0x05,
	PWM_IO_P06 = 0x06,
	PWM_IO_P07 = 0x07,

	PWM_IO_P10 = 0x08,
	PWM_IO_P11 = 0x09,
	PWM_IO_P12 = 0x0A,
	PWM_IO_P13 = 0x0B,
	PWM_IO_P14 = 0x0C,
	PWM_IO_P15 = 0x0D,
	PWM_IO_P16 = 0x0E,
	PWM_IO_P17 = 0x0F,

	PWM_IO_P20 = 0x10,
	PWM_IO_P21 = 0x11,
	PWM_IO_P22 = 0x12,
	PWM_IO_P23 = 0x13,
	PWM_IO_P24 = 0x14,
	PWM_IO_P25 = 0x15,
	PWM_IO_P26 = 0x16,
	PWM_IO_P27 = 0x17,

	PWM_IO_P30 = 0x18,
	PWM_IO_P31 = 0x19,
	PWM_IO_TOTAL
}ENUM_PWM_IO;	

typedef struct
{
	ENUM_PWM_IO io;
	char *name;
	
}PWM_IO_STRUCT;


/*  PWM API  */
void pwm_enable(PWM_NUM_ENUM num);
void pwm_disable(PWM_NUM_ENUM num);
void pwm_ie_enable(PWM_NUM_ENUM num);
void pwm_ie_disable(PWM_NUM_ENUM num);
char pwm_get_flag(PWM_NUM_ENUM num);
void pwm_set_index(PWM_NUM_ENUM num);
void pwm_set_ps(PWM_NUM_ENUM num, ENUM_PWM_IO io);
void pwm_pdiv(PWM_NUM_ENUM num, char pdiv);
void pwm_set_div(PWM_NUM_ENUM num, int div);
void pwm_set_duty(PWM_NUM_ENUM num, int duty);
void pwm_set_source_clk(PWM_NUM_ENUM num, PWM_CLK_ENUM clk );
void pwm_set_out_mode(PWM_NUM_ENUM num, PWM_MODE_ENUM mode);
void pwm_set_dt(PWM_NUM_ENUM num, int dt);
void PWM_INIT(void);


#endif