1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #ifndef __HW_PWM_H__
- #define __HW_PWM_H__
- #include "st_sys.h"
- #include "hw_pin.h"
- #define HW_PWM_1 0
- #define HW_PWM_2 1
- #define HW_PWM_3 2
- #define HW_PWM_4 3
- #define HW_PWM_NUMBER 3
- extern uint16_t * hw_pwm_period_registers[];
- extern uint16_t * hw_pwm_dutycycle_registers[];
- extern uint16_t * hw_pwm_cr_registers[];
- extern uint16_t * hw_pwm_egr_registers[HW_PWM_NUMBER];
- //方向管脚读写表
- extern hw_pin_readwrite_t hw_pwm_dir_rw_map[];
- //使能管脚读写表
- extern hw_pin_readwrite_t hw_pwm_en_rw_map[];
- typedef void (* pwm_handle) (void *);
- //直接获取或者设置周期
- #define HW_PWM_PERIOD(no) *(hw_pwm_period_registers[no])
- //直接获取或者设置占空比
- #define HW_PWM_DUTYCYCLE(no) *(hw_pwm_dutycycle_registers[no])
- #define HW_PWM_SET_PERIOD(no,val) HW_PWM_PERIOD(no) = val;HW_PWM_DUTYCYCLE(no) = (val >> 1); *(hw_pwm_egr_registers[no]) |= 0x01
- //#define HW_PWM_ON(no) *(hw_pwm_egr_registers[no]) |= 0x01;*(hw_pwm_cr_registers[no]) |= 0x01
- #define HW_PWM_ON(no) *(hw_pwm_cr_registers[no]) |= 0x01
- #define HW_PWM_OFF(no) *(hw_pwm_cr_registers[no]) &= ~0x01
- #define HW_PWM_IS_ON(no) (*(hw_pwm_cr_registers[no]) & 0x01)
- #define HW_PWM_GET_DIR(no) ((hw_pwm_dir_rw_map[no].idr & hw_pwm_dir_rw_map[no].pin) == hw_pwm_dir_rw_map[no].pin)
- #define HW_PWM_SET_DIR(no,sta) hw_pwm_dir_rw_map[no].odr[1 - sta] = hw_pwm_dir_rw_map[no].pin
-
- #define HW_PWM_GET_EN(no) ((hw_pwm_en_rw_map[no].idr & hw_pwm_en_rw_map[no].pin) == hw_pwm_dir_rw_map[no].pin)
- #define HW_PWM_SET_EN(no,sta) hw_pwm_en_rw_map[no].odr[1 - sta] = hw_pwm_en_rw_map[no].pin
- void hw_pwm_set_dir(unsigned char no, int dir);
- int hw_pwm_get_dir(unsigned char no);
- void hw_pwm_set_enable(unsigned char no, int en);
- int hw_pwm_get_enable(unsigned char no);
- void hw_pwm_start(unsigned char no);
- void hw_pwm_set_period(unsigned char no, int value);
- void hw_pwm_stop(unsigned char no);
- int hw_pwm_get_clk(unsigned char no);
- void hw_pwm_init(int clk);
- void hw_pwm_it_register(unsigned char no, pwm_handle handle, void * para);
- void hw_pwm_close_all(void);
- int hw_pwm_get_alr(unsigned char no);
- int hw_pwm_get_tarr(unsigned char no);
- void hw_pwm_set_clr(unsigned char no, int en);
- void hw_pwm_set_tmode(unsigned char no, int en);
- #endif
|