/******************************************************************************
;  *   	@MCU				 : MC51F003A4
;  *   	@Create Date         : 2021.10.11
;  *   	@Author/Corporation  : Martin/SinoMCU
;  *   	@晟矽微技术支持QQ 	 : 2048615934
;  *    @晟矽微官网		     : http://www.sinomcu.com/
;  *   	@Copyright           : 2020 SINOMCU Corporation,All Rights Reserved.
;  *----------------------Abstract Description---------------------------------
;  *			          定义                              		
******************************************************************************/

#ifndef PWM1_LIB_H__
#define PWM1_LIB_H__

#include "MC51F003A4_COMMON.h"

#define PWM1_EN         0x80
#define PWM1_CB         0x80
#define PWM1_IE_ADDR    0x04
#define PWM1_FBIE_ADDR  0x20
//PWM1刹车极性
#define PWM1_FB_POL_UP     0
#define PWM1_FB_POL_DOWN   0x02
//PWM1刹车IO
#define PWM1_FB_OE_DISABLE   0
#define PWM1_FB_OE_ENABLE   0x01
//PWM1IO输出比较通道
#define PWM1_OUT_CMP_CH0    0x01
#define PWM1_OUT_CMP_CH1    0x02
#define PWM1_OUT_CMP_CH2    0x04
#define PWM1_OUT_CMP_CH3    0x08
#define PWM1_OUT_CMP_CH4    0x10
#define PWM1_OUT_CMP_CH5    0x20
#define PWM1_OUT_CMP_ALL    0x3F
#define PWM1_OUT_CMP_MAX    0x3F
//PWM1时钟来源
#define PWM1_CLK_FSYS   0
#define PWM1_CLK_FHIRC  0x80
//PWM1模式选择
#define PWM1_MODE_COMPLEMENTARY_45  0
#define PWM1_MODE_COMPLEMENTARY_23  0
#define PWM1_MODE_COMPLEMENTARY_01  0
#define PWM1_MODE_INDEPENDENT_45    0x40
#define PWM1_MODE_INDEPENDENT_23    0x20 
#define PWM1_MODE_INDEPENDENT_01    0x10
//PWM1分频
#define PWM1_CLK_DIV_1      0
#define PWM1_CLK_DIV_2    0x01
#define PWM1_CLK_DIV_4    0x02
#define PWM1_CLK_DIV_8    0x03
#define PWM1_CLK_DIV_16   0x04
#define PWM1_CLK_DIV_32   0x05
#define PWM1_CLK_DIV_64   0x06
#define PWM1_CLK_DIV_128  0x07
//PWM1自动装载
#define PWM1_AUTO_LOAD_ENABLE   0x80
#define PWM1_AUTO_LOAD_DISABLE  0
//PWM1死区使能控制
#define PWM1_DEAT_OE_DISABLE_45 0
#define PWM1_DEAT_OE_DISABLE_23 0 
#define PWM1_DEAT_OE_DISABLE_01 0 
#define PWM1_DEAT_OE_ENABLE_45  0x40
#define PWM1_DEAT_OE_ENABLE_23  0x20
#define PWM1_DEAT_OE_ENABLE_01  0x10
//PWM1极性选择
#define PWM1_POL_HIGH_45   0
#define PWM1_POL_HIGH_23   0
#define PWM1_POL_HIGH_01   0
#define PWM1_POL_LOW_45    0x04
#define PWM1_POL_LOW_23    0x02
#define PWM1_POL_LOW_01    0x01



typedef struct
{
    uint8_t PWM1_FB_polarity;           //刹车信号极性选择
    uint8_t PWM1_FB_OE;                 //刹车IO有效选择
    uint8_t PWM1_out_cmp_chx;           //PWM1x  PWM1输出、比较使能
    uint8_t PWM1_clock_source;          //PWM1时钟源
    uint8_t PWM1_mode;                  //PWM1工作模式
    uint8_t PWM1_clock_division;        //PWM1时钟分频
    uint8_t PWM1_auto_load;             //自动装载使能
    uint8_t PWM1_deat_oe;               //互补模式死区使能
    uint8_t PWM1_polarity;              //pwm极性选择
//    uint8_t PWM1_cmp_chx;               //比较通道使能
    uint8_t PWM1_interrupt;             //PWM1中断
    uint8_t PWM1_interrupt_priority;    //PWM1中断优先级
    uint8_t PWM1_FB_interrupt;          //刹车中断
    uint8_t PWM1_FB_interrupt_priority; //刹车中断优先级
} PWM1_InitTypeDef;

void PWM1_Init(PWM1_InitTypeDef *PWM1);
void PWM1_Out_Bit_Set(uint8_t state,uint8_t chx);
void PWM1_T_Set(uint16_t num);
void PWM1_D0_Set(uint16_t num);
void PWM1_D1_Set(uint16_t num);
void PWM1_D2_Set(uint16_t num);
void PWM1_D3_Set(uint16_t num);
void PWM1_D4_Set(uint16_t num);
void PWM1_D5_Set(uint16_t num);
void PWM1_Deat_Time01_Set(uint8_t num);
void PWM1_Deat_Time23_Set(uint8_t num);
void PWM1_Deat_Time45_Set(uint8_t num);

#endif

/**************************** end of file *********************************************/
