#ifndef __BL2101_PWM_H__
#define __BL2101_PWM_H__

#include "BL2101.h"


typedef struct {
	uint8_t  clkdiv;		     //PWM_CLKDIV_4、PWM_CLKDIV_8、... ...
	uint32_t period;		     //周期,12位
	uint32_t high;			     //占空比，高电平时长，12位
	uint8_t  Inv;                //输出信号电平翻转
	uint8_t  HEndIE;		     //高电平结束中断使能
	uint8_t  OvfIE;		         //周期溢出中断使能
} PWM_InitTypeDef;


#define PWM_CLKDIV_4	0        //PWM时钟4分频
#define PWM_CLKDIV_8	1        //PWM时钟8分频
#define PWM_CLKDIV_16	2        //PWM时钟16分频
#define PWM_CLKDIV_32	3        //PWM时钟32分频
#define PWM_CLKDIV_64	4        //PWM时钟64分频
#define PWM_CLKDIV_128	5        //PWM时钟128分频
#define PWM_CLKDIV_256	6        //PWM时钟256分频
#define PWM_CLKDIV_512	7        //PWM时钟512分频


void PWM_Init(PWM_TypeDef * PWMx, PWM_InitTypeDef * PWM_InitStruct);      //PWM初始化
void PWM_Start(PWM_TypeDef * PWMx);                                       //启动PWM，开始PWM输出
void PWM_Stop(PWM_TypeDef * PWMx);                                        //关闭PWM，停止PWM输出

void PWM_SetClkDiv(uint8_t clk_div);                                      //设置预分频系数
 
void PWM_SetOutInv(PWM_TypeDef * PWMx);                                   //PWM输出信号翻转
void PWM_ReSetOutInv(PWM_TypeDef * PWMx);                                 //PWM输出信号不翻转

void PWM_SetPeriod(PWM_TypeDef * PWMx, uint32_t period);                  //设置周期                  
uint32_t PWM_GetPeriod(PWM_TypeDef * PWMx);                               //获取周期
void PWM_SetHigh(PWM_TypeDef * PWMx, uint32_t high);                      //设置高电平时长
uint32_t PWM_GetHigh(PWM_TypeDef * PWMx);                                 //获取高电平时长

void PWM_IntHendEn(PWM_TypeDef * PWMx);                                   //高电平结束中断使能
void PWM_IntHendDis(PWM_TypeDef * PWMx);                                  //高电平结束中断禁能
void PWM_IntHendClr(PWM_TypeDef * PWMx);                                  //高电平结束中断标志清除
uint8_t PWM_IntHendStat(PWM_TypeDef * PWMx);                              //高电平结束中断是否发生

void PWM_IntOvfEn(PWM_TypeDef * PWMx);                                    //周期溢出中断使能
void PWM_IntOvfDis(PWM_TypeDef * PWMx);                                   //周期溢出中断禁能
void PWM_IntOvfClr(PWM_TypeDef * PWMx);                                   //周期溢出中断标志清除
uint8_t PWM_IntOvfStat(PWM_TypeDef * PWMx);                               //周期溢出中断是否发生

	

#endif //__BL2101_PWM_H__
